Fixes python 3 unit tests
Fixes unit tests related to incomparable types. Fixes unit tests related to writing / reading bytes in / from files or response bodies. Fixes console websocketproxy unit tests. Fixes consoleauth unit tests. Fixes db unit tests. Fixes image unit tests. Fixes virt/block_devices unit tests. Fixes virt/configdrive unit tests. Fixes virt_drivers unit tests. Fixes xenapi agent, vmops and volume_utils unit tests. Fixes wsgi unit tests. Enables some python3 unit tests. Partially Implements: blueprint goal-python35 Change-Id: Ie98e968740d1015eae3278edeb93d4ba08155169
This commit is contained in:
parent
c40b5fbc1d
commit
8e989bd9d5
@ -37,4 +37,4 @@ class RequestIdTest(test.NoDBTestCase):
|
||||
|
||||
res_id = res.headers.get(compute_req_id.HTTP_RESP_HEADER_REQUEST_ID)
|
||||
self.assertThat(res_id, matchers.StartsWith('req-'))
|
||||
self.assertEqual(res_id, res.body)
|
||||
self.assertEqual(res_id.encode('utf-8'), res.body)
|
||||
|
@ -35,11 +35,11 @@ class Test(test.NoDBTestCase):
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
start_response("200", [("X-Test", "checking")])
|
||||
return ['Test result']
|
||||
return [b'Test result']
|
||||
|
||||
application = wsgi.Debug(Application())
|
||||
result = webob.Request.blank('/').get_response(application)
|
||||
self.assertEqual(result.body, "Test result")
|
||||
self.assertEqual(result.body, b"Test result")
|
||||
|
||||
def test_router(self):
|
||||
|
||||
|
@ -206,11 +206,11 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
|
||||
self.wh.new_websocket_client)
|
||||
check_token.assert_called_with(mock.ANY, token="123-456-789")
|
||||
|
||||
@mock.patch('sys.version_info')
|
||||
@mock.patch.object(websocketproxy, 'sys')
|
||||
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
|
||||
def test_new_websocket_client_py273_good_scheme(
|
||||
self, check_token, version_info):
|
||||
version_info.return_value = (2, 7, 3)
|
||||
self, check_token, mock_sys):
|
||||
mock_sys.version_info.return_value = (2, 7, 3)
|
||||
check_token.return_value = {
|
||||
'host': 'node1',
|
||||
'port': '10000',
|
||||
@ -227,11 +227,11 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
|
||||
self.wh.socket.assert_called_with('node1', 10000, connect=True)
|
||||
self.wh.do_proxy.assert_called_with('<socket>')
|
||||
|
||||
@mock.patch('sys.version_info')
|
||||
@mock.patch.object(websocketproxy, 'sys')
|
||||
@mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token')
|
||||
def test_new_websocket_client_py273_special_scheme(
|
||||
self, check_token, version_info):
|
||||
version_info.return_value = (2, 7, 3)
|
||||
self, check_token, mock_sys):
|
||||
mock_sys.version_info = (2, 7, 3)
|
||||
check_token.return_value = {
|
||||
'host': 'node1',
|
||||
'port': '10000',
|
||||
@ -248,8 +248,8 @@ class NovaProxyRequestHandlerBaseTestCase(test.NoDBTestCase):
|
||||
def test_address_string_doesnt_do_reverse_dns_lookup(self, getfqdn):
|
||||
request_mock = mock.MagicMock()
|
||||
request_mock.makefile().readline.side_effect = [
|
||||
'GET /vnc.html?token=123-456-789 HTTP/1.1\r\n',
|
||||
''
|
||||
b'GET /vnc.html?token=123-456-789 HTTP/1.1\r\n',
|
||||
b''
|
||||
]
|
||||
server_mock = mock.MagicMock()
|
||||
client_address = ('8.8.8.8', 54321)
|
||||
|
@ -21,6 +21,7 @@ Tests for Consoleauth Code.
|
||||
import mock
|
||||
from mox3 import mox
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from nova.consoleauth import manager
|
||||
from nova import context
|
||||
@ -170,15 +171,15 @@ class ControlauthMemcacheEncodingTestCase(test.NoDBTestCase):
|
||||
self.manager.authorize_console(self.context, self.u_token,
|
||||
'novnc', '127.0.0.1', '8080',
|
||||
'host', self.u_instance)
|
||||
mock_set.assert_has_calls([mock.call('token', mock.ANY)])
|
||||
mock_instance_get.assert_has_calls([mock.call('instance')])
|
||||
mock_get_multi.assert_has_calls([mock.call(['token'])])
|
||||
mock_set.assert_has_calls([mock.call(b'token', mock.ANY)])
|
||||
mock_instance_get.assert_has_calls([mock.call(b'instance')])
|
||||
mock_get_multi.assert_has_calls([mock.call([b'token'])])
|
||||
mock_instance_set.assert_has_calls(
|
||||
[mock.call('instance', mock.ANY)])
|
||||
[mock.call(b'instance', mock.ANY)])
|
||||
|
||||
def test_check_token_encoding(self):
|
||||
self.mox.StubOutWithMock(self.manager.mc, "get")
|
||||
self.manager.mc.get(mox.IsA(str)).AndReturn(None)
|
||||
self.manager.mc.get(mox.IsA(six.binary_type)).AndReturn(None)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -201,9 +202,9 @@ class ControlauthMemcacheEncodingTestCase(test.NoDBTestCase):
|
||||
mock_delete_multi):
|
||||
self.manager.delete_tokens_for_instance(self.context,
|
||||
self.u_instance)
|
||||
mock_instance_get.assert_has_calls([mock.call('instance')])
|
||||
mock_instance_delete.assert_has_calls([mock.call('instance')])
|
||||
mock_delete_multi.assert_has_calls([mock.call(['token'])])
|
||||
mock_instance_get.assert_has_calls([mock.call(b'instance')])
|
||||
mock_instance_delete.assert_has_calls([mock.call(b'instance')])
|
||||
mock_delete_multi.assert_has_calls([mock.call([b'token'])])
|
||||
|
||||
|
||||
class CellsConsoleauthTestCase(ConsoleauthTestCase):
|
||||
|
@ -168,13 +168,13 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
|
||||
272, # NOOP migration due to revert
|
||||
]
|
||||
|
||||
havana_placeholders = range(217, 227)
|
||||
icehouse_placeholders = range(235, 244)
|
||||
juno_placeholders = range(255, 265)
|
||||
kilo_placeholders = range(281, 291)
|
||||
liberty_placeholders = range(303, 313)
|
||||
mitaka_placeholders = range(320, 330)
|
||||
newton_placeholders = range(335, 345)
|
||||
havana_placeholders = list(range(217, 227))
|
||||
icehouse_placeholders = list(range(235, 244))
|
||||
juno_placeholders = list(range(255, 265))
|
||||
kilo_placeholders = list(range(281, 291))
|
||||
liberty_placeholders = list(range(303, 313))
|
||||
mitaka_placeholders = list(range(320, 330))
|
||||
newton_placeholders = list(range(335, 345))
|
||||
|
||||
return (special +
|
||||
havana_placeholders +
|
||||
|
@ -158,7 +158,7 @@ class _FakeImageService(object):
|
||||
# TODO(bcwaldon): implement optional kwargs such as limit, sort_dir
|
||||
def detail(self, context, **kwargs):
|
||||
"""Return list of detailed image information."""
|
||||
return copy.deepcopy(self.images.values())
|
||||
return copy.deepcopy(list(self.images.values()))
|
||||
|
||||
def download(self, context, image_id, dst_path=None, data=None):
|
||||
self.show(context, image_id)
|
||||
|
@ -34,6 +34,7 @@ CONF = cfg.CONF
|
||||
class FakeInstanceMD(object):
|
||||
def metadata_for_config_drive(self):
|
||||
yield ('this/is/a/path/hello', 'This is some content')
|
||||
yield ('this/is/a/path/hi', b'This is some other content')
|
||||
|
||||
|
||||
class ConfigDriveTestCase(test.NoDBTestCase):
|
||||
|
@ -330,8 +330,8 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||
def test_inject_file(self):
|
||||
instance_ref, network_info = self._get_running_instance()
|
||||
self.connection.inject_file(instance_ref,
|
||||
base64.b64encode('/testfile'),
|
||||
base64.b64encode('testcontents'))
|
||||
base64.b64encode(b'/testfile'),
|
||||
base64.b64encode(b'testcontents'))
|
||||
|
||||
@catch_notimplementederror
|
||||
def test_resume_state_on_host_boot(self):
|
||||
|
@ -165,8 +165,8 @@ class FileInjectionTestCase(AgentTestCaseBase):
|
||||
instance = _get_fake_instance()
|
||||
agent = self._create_agent(instance)
|
||||
|
||||
b64_path = base64.b64encode('path')
|
||||
b64_contents = base64.b64encode('contents')
|
||||
b64_path = base64.b64encode(b'path')
|
||||
b64_contents = base64.b64encode(b'contents')
|
||||
|
||||
agent.inject_file("path", "contents")
|
||||
mock_call_agent.assert_called_once_with('inject_file',
|
||||
|
@ -256,7 +256,8 @@ class GetConsoleOutputTestCase(VMOpsTestBase):
|
||||
self.vmops._get_last_dom_id(instance, check_rescue=True).AndReturn(42)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.assertEqual("dom_id: 42", self.vmops.get_console_output(instance))
|
||||
self.assertEqual(b"dom_id: 42",
|
||||
self.vmops.get_console_output(instance))
|
||||
|
||||
def test_get_console_output_not_available(self):
|
||||
self.mox.StubOutWithMock(self.vmops, '_get_last_dom_id')
|
||||
|
@ -20,6 +20,7 @@ import shutil
|
||||
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import units
|
||||
import six
|
||||
|
||||
import nova.conf
|
||||
from nova import exception
|
||||
@ -59,6 +60,10 @@ class ConfigDriveBuilder(object):
|
||||
dirname = os.path.dirname(filepath)
|
||||
fileutils.ensure_tree(dirname)
|
||||
with open(filepath, 'wb') as f:
|
||||
# the given data can be either text or bytes. we can only write
|
||||
# bytes into files.
|
||||
if isinstance(data, six.text_type):
|
||||
data = data.encode('utf-8')
|
||||
f.write(data)
|
||||
|
||||
def add_instance_metadata(self, instance_md):
|
||||
|
@ -475,7 +475,7 @@ def default_device_names(virt_type, context, instance, block_device_info,
|
||||
|
||||
def get_default_ephemeral_info(instance, disk_bus, block_device_info, mapping):
|
||||
ephemerals = driver.block_device_info_get_ephemerals(block_device_info)
|
||||
if instance.ephemeral_gb <= 0 or ephemerals:
|
||||
if not instance.ephemeral_gb or instance.ephemeral_gb <= 0 or ephemerals:
|
||||
return None
|
||||
else:
|
||||
info = get_next_disk_info(mapping, disk_bus)
|
||||
|
@ -2756,7 +2756,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
# Check is the write allowed with 512 byte alignment
|
||||
align_size = 512
|
||||
m = mmap.mmap(-1, align_size)
|
||||
m.write(r"x" * align_size)
|
||||
m.write(b"x" * align_size)
|
||||
os.write(fd, m)
|
||||
LOG.debug("Path '%(path)s' supports direct I/O",
|
||||
{'path': dirpath})
|
||||
|
@ -316,8 +316,8 @@ class XenAPIBasedAgent(object):
|
||||
LOG.debug('Injecting file path: %r', path, instance=self.instance)
|
||||
|
||||
# Files/paths must be base64-encoded for transmission to agent
|
||||
b64_path = base64.b64encode(path)
|
||||
b64_contents = base64.b64encode(contents)
|
||||
b64_path = base64.b64encode(path.encode('utf-8'))
|
||||
b64_contents = base64.b64encode(contents.encode('utf-8'))
|
||||
|
||||
args = {'b64_path': b64_path, 'b64_contents': b64_contents}
|
||||
return self._call_agent('inject_file', args)
|
||||
|
@ -776,7 +776,8 @@ class SessionBase(object):
|
||||
dom_id = args["dom_id"]
|
||||
if dom_id == 0:
|
||||
raise Failure('Guest does not have a console')
|
||||
return base64.b64encode(zlib.compress("dom_id: %s" % dom_id))
|
||||
return base64.b64encode(
|
||||
zlib.compress(("dom_id: %s" % dom_id).encode('utf-8')))
|
||||
|
||||
def _plugin_nova_plugin_version_get_version(self, method, args):
|
||||
return pickle.dumps("1.8")
|
||||
|
@ -19,7 +19,6 @@ and storage repositories
|
||||
"""
|
||||
|
||||
import re
|
||||
import string
|
||||
import uuid
|
||||
|
||||
from eventlet import greenthread
|
||||
@ -290,7 +289,7 @@ def _mountpoint_to_number(mountpoint):
|
||||
elif re.match('^x?vd[a-p]$', mountpoint):
|
||||
return (ord(mountpoint[-1]) - ord('a'))
|
||||
elif re.match('^[0-9]+$', mountpoint):
|
||||
return string.atoi(mountpoint, 10)
|
||||
return int(mountpoint, 10)
|
||||
else:
|
||||
LOG.warning(_LW('Mountpoint cannot be translated: %s'), mountpoint)
|
||||
return -1
|
||||
|
@ -399,7 +399,7 @@ class Debug(Middleware):
|
||||
"""Iterator that prints the contents of a wrapper string."""
|
||||
print(('*' * 40) + ' BODY')
|
||||
for part in app_iter:
|
||||
sys.stdout.write(part)
|
||||
sys.stdout.write(six.text_type(part))
|
||||
sys.stdout.flush()
|
||||
yield part
|
||||
print()
|
||||
|
@ -32,7 +32,6 @@ nova.tests.unit.api.openstack.compute.test_versions.VersionsTestV21WithV2Compati
|
||||
nova.tests.unit.api.openstack.compute.test_volumes.BootFromVolumeTest
|
||||
nova.tests.unit.api.openstack.compute.test_volumes.VolumeApiTestV21
|
||||
nova.tests.unit.api.test_compute_req_id.RequestIdTest
|
||||
nova.tests.unit.api.test_wsgi.Test
|
||||
nova.tests.unit.compute.test_compute.ComputeAPITestCase.test_create_with_base64_user_data
|
||||
nova.tests.unit.compute.test_compute.ComputeTestCase.test_finish_resize_with_volumes
|
||||
nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_boot_volume_serial
|
||||
@ -42,16 +41,10 @@ nova.tests.unit.compute.test_compute.ComputeVolumeTestCase.test_prep_block_devic
|
||||
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.console.test_websocketproxy.NovaProxyRequestHandlerBaseTestCase
|
||||
nova.tests.unit.consoleauth.test_consoleauth.ControlauthMemcacheEncodingTestCase
|
||||
nova.tests.unit.db.test_migrations.TestNovaMigrationsMySQL
|
||||
nova.tests.unit.db.test_migrations.TestNovaMigrationsPostgreSQL
|
||||
nova.tests.unit.db.test_migrations.TestNovaMigrationsSQLite
|
||||
nova.tests.unit.image.test_fake.FakeImageServiceTestCase
|
||||
nova.tests.unit.network.test_manager.LdapDNSTestCase
|
||||
nova.tests.unit.test_bdm.BlockDeviceMappingEc2CloudTestCase
|
||||
nova.tests.unit.test_configdrive2.ConfigDriveTestCase
|
||||
nova.tests.unit.test_matchers.TestDictMatches
|
||||
nova.tests.unit.test_matchers.TestDictMatches.test__str__
|
||||
nova.tests.unit.test_metadata.MetadataHandlerTestCase
|
||||
nova.tests.unit.test_metadata.MetadataPasswordTestCase
|
||||
nova.tests.unit.test_metadata.MetadataTestCase
|
||||
@ -81,16 +74,11 @@ nova.tests.unit.virt.test_virt_drivers.FakeConnectionTestCase
|
||||
nova.tests.unit.virt.test_virt_drivers.LibvirtConnTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_images.VMwareImagesTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_read_write_util.ReadWriteUtilTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vmops.VMwareVMOpsTestCase
|
||||
nova.tests.unit.virt.vmwareapi.test_vmops.VMwareVMOpsTestCase.test_spawn_mask_block_device_info_password
|
||||
nova.tests.unit.virt.xenapi.client.test_session.CallPluginTestCase
|
||||
nova.tests.unit.virt.xenapi.image.test_utils.RawTGZTestCase
|
||||
nova.tests.unit.virt.xenapi.image.test_vdi_through_dev.TestTarGzProducer
|
||||
nova.tests.unit.virt.xenapi.test_agent.FileInjectionTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.ResizeFunctionTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.ScanSrTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vm_utils.UnplugVbdTestCase
|
||||
nova.tests.unit.virt.xenapi.test_vmops.GetConsoleOutputTestCase
|
||||
nova.tests.unit.virt.xenapi.test_volume_utils.ParseVolumeInfoTestCase
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.HypervisorPoolTestCase
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPIDiffieHellmanTestCase
|
||||
nova.tests.unit.virt.xenapi.test_xenapi.XenAPIDom0IptablesFirewallTestCase
|
||||
|
Loading…
x
Reference in New Issue
Block a user