From d830fd858380aa51a9f1c0393d768643e577d6d8 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Fri, 18 Nov 2016 10:08:09 +0800 Subject: [PATCH] Port test_serversV21 to Python 3 * Use encodeutils from oslo.utils to convert things as needed. * Use base64 module from oslo.serialization to encode text. Partially-Implements: blueprint goal-python35 Change-Id: I489e3b38021c45d7070bd5fae2deec6cab577745 --- .../unit/api/openstack/compute/test_serversV21.py | 10 ++++++---- tests-py3.txt | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 091e84bcda07..2a5a164826e0 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -import base64 import collections import datetime import uuid @@ -24,7 +23,9 @@ import iso8601 import mock from mox3 import mox from oslo_policy import policy as oslo_policy +from oslo_serialization import base64 from oslo_serialization import jsonutils +from oslo_utils import encodeutils from oslo_utils import timeutils import six from six.moves import range @@ -1837,7 +1838,7 @@ class ServersControllerRebuildInstanceTest(ControllerTest): "imageRef": self.image_uuid, "personality": [{ "path": "/path/to/file", - "contents": base64.b64encode("Test String"), + "contents": base64.encode_as_text("Test String"), }] }, } @@ -3038,7 +3039,7 @@ class ServersControllerCreateTest(test.TestCase): self.req.body = jsonutils.dump_as_bytes(self.body) robj = self.controller.create(self.req, body=self.body) - self.assertEqual(robj['Location'], selfhref) + self.assertEqual(encodeutils.safe_decode(robj['Location']), selfhref) def _do_test_create_instance_above_quota(self, resource, allowed, quota, expected_msg): @@ -3313,7 +3314,8 @@ class ServersControllerCreateTest(test.TestCase): @mock.patch.object(compute_api.API, 'create') def test_create_instance_invalid_personality(self, mock_create): codec = 'utf8' - content = 'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA==' + content = encodeutils.safe_encode( + 'b25zLiINCg0KLVJpY2hhcmQgQ$$%QQmFjaA==') start_position = 19 end_position = 20 msg = 'invalid start byte' diff --git a/tests-py3.txt b/tests-py3.txt index 540247a46483..0343758788af 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -18,11 +18,6 @@ nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecu nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecurityGroupDefaultRulesV21 nova.tests.unit.api.openstack.compute.test_security_groups.SecurityGroupsOutputTestV21 nova.tests.unit.api.openstack.compute.test_security_groups.TestSecurityGroupRulesV21 -nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerCreateTest -nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildInstanceTest -nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildTestV219 -nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerTest -nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerTestV29 nova.tests.unit.api.openstack.compute.test_simple_tenant_usage.SimpleTenantUsageTestV21 nova.tests.unit.api.openstack.compute.test_urlmap.UrlmapTest nova.tests.unit.api.openstack.compute.test_user_data.ServersControllerCreateTest