diff --git a/nova/compute/api.py b/nova/compute/api.py index 6cd25fecedf1..552d4c367b59 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -28,6 +28,7 @@ import string from oslo_log import log as logging from oslo_messaging import exceptions as oslo_exceptions +from oslo_serialization import base64 as base64utils from oslo_serialization import jsonutils from oslo_utils import excutils from oslo_utils import strutils @@ -832,7 +833,13 @@ class API(base.Base): length=l, maxsize=MAX_USERDATA_SIZE) try: - base64.decodestring(user_data) + # TODO(gcb): Just use base64utils.decode_as_bytes(user_data) + # when https://review.openstack.org/#/c/410797/ is merged and + # ensure oslo.serialization >=2.15.0 in Nova requirements.txt. + if six.PY3: + base64utils.decode_as_bytes(user_data) + else: + base64.decodestring(user_data) except base64.binascii.Error: raise exception.InstanceUserDataMalformed() diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 605782d1b3ca..292c370fff03 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -17,7 +17,6 @@ # under the License. """Tests for compute service.""" -import base64 import datetime import operator import sys @@ -30,6 +29,7 @@ import mock from neutronclient.common import exceptions as neutron_exceptions from oslo_log import log as logging import oslo_messaging as messaging +from oslo_serialization import base64 from oslo_serialization import jsonutils from oslo_utils import fixture as utils_fixture from oslo_utils import timeutils @@ -2739,7 +2739,7 @@ class ComputeTestCase(BaseTestCase): def test_rebuild_with_injected_files(self): # Ensure instance can be rebuilt with injected files. injected_files = [ - (b'/a/b/c', base64.b64encode(b'foobarbaz')), + (b'/a/b/c', base64.encode_as_bytes(b'foobarbaz')), ] self.decoded_files = [ @@ -7939,7 +7939,7 @@ class ComputeAPITestCase(BaseTestCase): # base64 (refs, resv_id) = self.compute_api.create( self.context, inst_type, self.fake_image['id'], - user_data=base64.encodestring(b'1' * 48510)) + user_data=base64.encode_as_text(b'1' * 48510)) def test_populate_instance_for_create(self, num_instances=1): base_options = {'image_ref': self.fake_image['id'], @@ -11704,8 +11704,8 @@ class ComputeInjectedFilesTestCase(BaseTestCase): def test_injected_success(self): # test with valid b64 encoded content. injected_files = [ - ('/a/b/c', base64.b64encode(b'foobarbaz')), - ('/d/e/f', base64.b64encode(b'seespotrun')), + ('/a/b/c', base64.encode_as_bytes(b'foobarbaz')), + ('/d/e/f', base64.encode_as_bytes(b'seespotrun')), ] decoded_files = [ @@ -11717,7 +11717,7 @@ class ComputeInjectedFilesTestCase(BaseTestCase): def test_injected_invalid(self): # test with invalid b64 encoded content injected_files = [ - ('/a/b/c', base64.b64encode(b'foobarbaz')), + ('/a/b/c', base64.encode_as_bytes(b'foobarbaz')), ('/d/e/f', 'seespotrun'), ] diff --git a/tests-py3.txt b/tests-py3.txt index 412645e88766..388e79994773 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -5,10 +5,6 @@ nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecu 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_user_data.ServersControllerCreateTest -nova.tests.unit.compute.test_compute.ComputeAPITestCase.test_create_with_base64_user_data -nova.tests.unit.compute.test_compute_cells.CellsComputeAPITestCase.test_create_with_base64_user_data -nova.tests.unit.compute.test_compute_mgr.ComputeManagerUnitTestCase.test_run_pending_deletes -nova.tests.unit.compute.test_host_api.ComputeHostAPICellsTestCase nova.tests.unit.test_wsgi.TestWSGIServerWithSSL nova.tests.unit.virt.libvirt.test_firewall.IptablesFirewallTestCase nova.tests.unit.virt.libvirt.test_imagebackend.EncryptedLvmTestCase