diff --git a/nova/tests/compute/monitors/test_cpu_monitor.py b/nova/tests/compute/monitors/test_cpu_monitor.py index c1997239f374..3717e9498a1d 100644 --- a/nova/tests/compute/monitors/test_cpu_monitor.py +++ b/nova/tests/compute/monitors/test_cpu_monitor.py @@ -51,7 +51,7 @@ class ComputeDriverCPUMonitorTestCase(test.TestCase): def test_get_metric_names(self): names = self.monitor.get_metric_names() - self.assertEquals(10, len(names)) + self.assertEqual(10, len(names)) self.assertIn("cpu.frequency", names) self.assertIn("cpu.user.time", names) self.assertIn("cpu.kernel.time", names) diff --git a/nova/tests/compute/monitors/test_monitors.py b/nova/tests/compute/monitors/test_monitors.py index 1100ff87296d..616972ccf138 100644 --- a/nova/tests/compute/monitors/test_monitors.py +++ b/nova/tests/compute/monitors/test_monitors.py @@ -40,7 +40,7 @@ class ResourceMonitorBaseTestCase(test.TestCase): def test_get_metric_names(self): names = self.monitor.get_metric_names() - self.assertEquals(2, len(names)) + self.assertEqual(2, len(names)) self.assertIn("foo.metric1", names) self.assertIn("foo.metric2", names) @@ -52,8 +52,8 @@ class ResourceMonitorBaseTestCase(test.TestCase): self.assertIn(metric['name'], names) metrics[metric['name']] = metric['value'] - self.assertEquals(metrics["foo.metric1"], '1000') - self.assertEquals(metrics["foo.metric2"], '99.999') + self.assertEqual(metrics["foo.metric1"], '1000') + self.assertEqual(metrics["foo.metric2"], '99.999') class ResourceMonitorsTestCase(test.TestCase): diff --git a/nova/tests/image/test_glance.py b/nova/tests/image/test_glance.py index ba57a10f61b3..80be48f4cb50 100644 --- a/nova/tests/image/test_glance.py +++ b/nova/tests/image/test_glance.py @@ -26,7 +26,7 @@ import time import sys import testtools -from mock import patch +import mock import mox import glanceclient.exc @@ -35,7 +35,6 @@ from oslo.config import cfg from nova import context from nova import exception from nova.image import glance -from nova.image.glance import GlanceClientWrapper from nova import test from nova.tests.api.openstack import fakes from nova.tests.glance import stubs as glance_stubs @@ -307,7 +306,7 @@ class TestGlanceImageService(test.NoDBTestCase): self.assertEqual(len(image_metas), 5) def test_page_size(self): - with patch.object(GlanceClientWrapper, 'call') as a_mock: + with mock.patch.object(glance.GlanceClientWrapper, 'call') as a_mock: self.service.detail(self.context, page_size=5) self.assertEqual(a_mock.called, True) a_mock.assert_called_with(self.context, 1, 'list', diff --git a/nova/tests/network/security_group/test_neutron_driver.py b/nova/tests/network/security_group/test_neutron_driver.py index a8fc365ef1e8..7bafa2c67972 100644 --- a/nova/tests/network/security_group/test_neutron_driver.py +++ b/nova/tests/network/security_group/test_neutron_driver.py @@ -111,7 +111,7 @@ class TestNeutronDriver(test.NoDBTestCase): sg_api = neutron_driver.SecurityGroupAPI() result = sg_api.get_instances_security_groups_bindings( self.context, servers) - self.assertEquals(result, sg_bindings) + self.assertEqual(result, sg_bindings) def _test_instances_security_group_bindings_scale(self, num_servers): max_query = 150 @@ -146,7 +146,7 @@ class TestNeutronDriver(test.NoDBTestCase): sg_api = neutron_driver.SecurityGroupAPI() result = sg_api.get_instances_security_groups_bindings( self.context, servers) - self.assertEquals(result, sg_bindings) + self.assertEqual(result, sg_bindings) def test_instances_security_group_bindings_less_than_max(self): self._test_instances_security_group_bindings_scale(100) @@ -178,4 +178,4 @@ class TestNeutronDriver(test.NoDBTestCase): sg_api = neutron_driver.SecurityGroupAPI() result = sg_api.get_instances_security_groups_bindings( self.context, servers) - self.assertEquals(result, sg_bindings) + self.assertEqual(result, sg_bindings) diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index f522ec95d3f8..00a5d6990902 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -29,8 +29,8 @@ from nova import exception from nova import network from nova.network import api from nova.network import floating_ips +from nova.network import model as network_model from nova.network import rpcapi as network_rpcapi -from nova.network.model import NetworkInfo, VIF from nova import policy from nova import test from nova import utils @@ -295,7 +295,8 @@ class TestUpdateInstanceCache(test.TestCase): self.context = context.get_admin_context() self.instance = {'uuid': FAKE_UUID} self.impl = self.mox.CreateMock(api.API) - self.nw_info = NetworkInfo([VIF(id='super_vif')]) + vifs = [network_model.VIF(id='super_vif')] + self.nw_info = network_model.NetworkInfo(vifs) self.is_nw_info = mox.Func(lambda d: 'super_vif' in d['network_info']) def expect_cache_update(self, nw_info): @@ -322,12 +323,13 @@ class TestUpdateInstanceCache(test.TestCase): self.expect_cache_update({'network_info': '[]'}) self.mox.ReplayAll() api.update_instance_cache_with_nw_info(self.impl, self.context, - self.instance, NetworkInfo([])) + self.instance, + network_model.NetworkInfo([])) def test_decorator_return_object(self): @api.refresh_cache def func(self, context, instance): - return NetworkInfo([]) + return network_model.NetworkInfo([]) self.expect_cache_update({'network_info': '[]'}) self.mox.ReplayAll() func(self.impl, self.context, self.instance) diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py index 31621bff0649..ca6f3888985f 100644 --- a/nova/tests/test_quota.py +++ b/nova/tests/test_quota.py @@ -82,7 +82,7 @@ class QuotaIntegrationTestCase(test.TestCase): try: compute.API().create(self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid) - except exception.QuotaError, e: + except exception.QuotaError as e: expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1, 'used': 4, 'allowed': 4, 'overs': 'cores,instances'} self.assertEqual(e.kwargs, expected_kwargs) @@ -98,7 +98,7 @@ class QuotaIntegrationTestCase(test.TestCase): try: compute.API().create(self.context, min_count=1, max_count=1, instance_type=inst_type, image_href=image_uuid) - except exception.QuotaError, e: + except exception.QuotaError as e: expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1, 'used': 4, 'allowed': 4, 'overs': 'cores'} self.assertEqual(e.kwargs, expected_kwargs) @@ -2332,7 +2332,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase): try: sqa_api.quota_reserve(context, self.resources, self.quotas, self.quotas, self.deltas, self.expire, 0, 0) - except exception.OverQuota, e: + except exception.OverQuota as e: expected_kwargs = {'code': 500, 'usages': {'instances': {'reserved': 0, 'in_use': 4}, 'ram': {'reserved': 0, 'in_use': 10240}, diff --git a/nova/tests/virt/libvirt/test_imagebackend.py b/nova/tests/virt/libvirt/test_imagebackend.py index d5d5e3555e24..2db677eec920 100644 --- a/nova/tests/virt/libvirt/test_imagebackend.py +++ b/nova/tests/virt/libvirt/test_imagebackend.py @@ -20,7 +20,7 @@ import os import fixtures from oslo.config import cfg -from inspect import getargspec +import inspect from nova import exception from nova.openstack.common import uuidutils @@ -644,8 +644,8 @@ class RbdTestCase(_ImageTestCase, test.NoDBTestCase): self.assertEqual(fake_processutils.fake_execute_get_log(), []) def test_parent_compatible(self): - self.assertEqual(getargspec(imagebackend.Image.libvirt_info), - getargspec(self.image_class.libvirt_info)) + self.assertEqual(inspect.getargspec(imagebackend.Image.libvirt_info), + inspect.getargspec(self.image_class.libvirt_info)) class BackendTestCase(test.NoDBTestCase): diff --git a/nova/tests/virt/test_virt_disk.py b/nova/tests/virt/test_virt_disk.py index 0edf37787573..59d666e4cc2d 100644 --- a/nova/tests/virt/test_virt_disk.py +++ b/nova/tests/virt/test_virt_disk.py @@ -18,7 +18,7 @@ import fixtures import os import sys -from posix import stat_result +import posix from nova import exception from nova import test @@ -40,10 +40,10 @@ class VirtDiskTest(test.NoDBTestCase): def fake_stat(arg): if arg == '/some/file': # fake success - return stat_result((16877, 2, 2049L, - 23, 0, 0, - 4096, 1381787843, - 1381635971, 1381635971)) + return posix.stat_result((16877, 2, 2049L, + 23, 0, 0, + 4096, 1381787843, + 1381635971, 1381635971)) else: return orig_os_stat(arg) diff --git a/nova/tests/virt/test_virt_drivers.py b/nova/tests/virt/test_virt_drivers.py index 86680b967c01..5a0b0407f3aa 100644 --- a/nova/tests/virt/test_virt_drivers.py +++ b/nova/tests/virt/test_virt_drivers.py @@ -19,7 +19,7 @@ import fixtures import sys import traceback -from mock import MagicMock +import mock import netaddr import six @@ -708,7 +708,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): self.driver_module = 'nova.virt.libvirt.LibvirtDriver' super(LibvirtConnTestCase, self).setUp() self.stubs.Set(self.connection, - 'set_host_enabled', MagicMock()) + 'set_host_enabled', mock.MagicMock()) self.useFixture(fixtures.MonkeyPatch( 'nova.context.get_admin_context', self._fake_admin_context)) @@ -727,7 +727,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): def test_set_host_enabled(self): self.mox.UnsetStubs() - service_mock = MagicMock() + service_mock = mock.MagicMock() # Previous status of the service: disabled: False # service_mock.__getitem__.return_value = False @@ -745,7 +745,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): def test_set_host_enabled_when_auto_disabled(self): self.mox.UnsetStubs() - service_mock = MagicMock() + service_mock = mock.MagicMock() # Previous status of the service: disabled: True, 'AUTO: ERROR' service_mock.configure_mock(disabled_reason='AUTO: ERROR', @@ -762,7 +762,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): def test_set_host_enabled_when_manually_disabled(self): self.mox.UnsetStubs() - service_mock = MagicMock() + service_mock = mock.MagicMock() # Previous status of the service: disabled: True, 'Manually disabled' service_mock.configure_mock(disabled_reason='Manually disabled', @@ -779,7 +779,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): def test_set_host_enabled_dont_override_manually_disabled(self): self.mox.UnsetStubs() - service_mock = MagicMock() + service_mock = mock.MagicMock() # Previous status of the service: disabled: True, 'Manually disabled' service_mock.configure_mock(disabled_reason='Manually disabled', diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index 72c2941e78f5..f555e7cd8f9c 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -4009,7 +4009,6 @@ class XenAPISessionTestCase(test.NoDBTestCase): with open(path) as plugin_file: for line in plugin_file: if "PLUGIN_VERSION = " in line: - print line plugin_version = line.strip()[17:].strip('"') self.assertEqual(session.PLUGIN_REQUIRED_VERSION, diff --git a/smoketests/test_sysadmin.py b/smoketests/test_sysadmin.py index b10d936cc8bb..e3c58ea31a1a 100644 --- a/smoketests/test_sysadmin.py +++ b/smoketests/test_sysadmin.py @@ -64,7 +64,7 @@ class ImageTests(base.UserSmokeTestCase): def test_003_can_register_image(self): image_id = self.conn.register_image('%s/%s.manifest.xml' % (TEST_BUCKET, FLAGS.bundle_image)) - self.assert_(image_id is not None) + self.assertTrue(image_id is not None) self.data['image_id'] = image_id def test_004_can_bundle_kernel(self): @@ -76,7 +76,7 @@ class ImageTests(base.UserSmokeTestCase): def test_006_can_register_kernel(self): kernel_id = self.conn.register_image('%s/%s.manifest.xml' % (TEST_BUCKET, FLAGS.bundle_kernel)) - self.assert_(kernel_id is not None) + self.assertTrue(kernel_id is not None) self.data['kernel_id'] = kernel_id def test_007_images_are_available_within_10_seconds(self): @@ -86,8 +86,8 @@ class ImageTests(base.UserSmokeTestCase): break time.sleep(1) else: - self.assert_(False) # wasn't available within 10 seconds - self.assert_(image.type == 'machine') + self.assertTrue(False) # wasn't available within 10 seconds + self.assertTrue(image.type == 'machine') for i in xrange(10): kernel = self.conn.get_image(self.data['kernel_id']) @@ -95,13 +95,13 @@ class ImageTests(base.UserSmokeTestCase): break time.sleep(1) else: - self.assert_(False) # wasn't available within 10 seconds - self.assert_(kernel.type == 'kernel') + self.assertTrue(False) # wasn't available within 10 seconds + self.assertTrue(kernel.type == 'kernel') def test_008_can_describe_image_attribute(self): attrs = self.conn.get_image_attribute(self.data['image_id'], 'launchPermission') - self.assert_(attrs.name, 'launch_permission') + self.assertTrue(attrs.name, 'launch_permission') def test_009_can_add_image_launch_permission(self): image = self.conn.get_image(self.data['image_id'])