Merge "Port compute unit tests to Python 3"

This commit is contained in:
Jenkins
2016-12-24 13:55:37 +00:00
committed by Gerrit Code Review
3 changed files with 14 additions and 11 deletions

View File

@@ -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()

View File

@@ -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'),
]

View File

@@ -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