From bd2aacc14fb33631c4f9fb6b2264d46f2f226800 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 15 Jan 2020 17:10:47 +0200 Subject: [PATCH] Handle Python 3 transition and fix tests While dropping Python 2.7 support, the upstream project has been updated, so we'll have to move the templates in-tree. While at it, we're updating the supported Python versions. Some Nova fixtures have been moved to oslo.test, so in order to be able to unblock the gate, we'll have to squash those fixes as well. For the same reason, we'll have to remove nova-network checks, which has been completely dropped. A few options have been moved to a separate config group, which we'll have to take into account. Change-Id: Ibce6b062a81200611bcaac3f2cb90b14b559375b --- .zuul.yaml | 2 ++ compute_hyperv/nova/imagecache.py | 5 +++-- compute_hyperv/nova/vif.py | 6 +----- compute_hyperv/nova/vmops.py | 5 ++--- compute_hyperv/tests/test.py | 16 ++++++---------- compute_hyperv/tests/unit/test_driver.py | 5 ----- compute_hyperv/tests/unit/test_imagecache.py | 3 ++- compute_hyperv/tests/unit/test_vif.py | 15 --------------- compute_hyperv/tests/unit/test_vmops.py | 8 ++------ setup.cfg | 1 + tox.ini | 2 +- 11 files changed, 20 insertions(+), 48 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index 10229cb5..86d00af4 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -8,7 +8,9 @@ - project: templates: + - check-requirements - openstack-lower-constraints-jobs + - openstack-python3-ussuri-jobs check: jobs: - build-openstack-releasenotes diff --git a/compute_hyperv/nova/imagecache.py b/compute_hyperv/nova/imagecache.py index 9d47a6ab..5c979a3a 100644 --- a/compute_hyperv/nova/imagecache.py +++ b/compute_hyperv/nova/imagecache.py @@ -180,7 +180,7 @@ class ImageCache(imagecache.ImageCacheManager): # change the timestamp on the image so as to reflect the last # time it was used self._update_image_timestamp(img) - elif CONF.remove_unused_base_images: + elif CONF.image_cache.remove_unused_base_images: self._remove_if_old_image(img) def _update_image_timestamp(self, image): @@ -205,7 +205,8 @@ class ImageCache(imagecache.ImageCacheManager): def _remove_if_old_image(self, image): backing_files = self._get_image_backing_files(image) - max_age_seconds = CONF.remove_unused_original_minimum_age_seconds + max_age_seconds = ( + CONF.image_cache.remove_unused_original_minimum_age_seconds) for img in backing_files: age_seconds = self._pathutils.get_age_of_file(img) diff --git a/compute_hyperv/nova/vif.py b/compute_hyperv/nova/vif.py index 9bca1686..6714e0ae 100644 --- a/compute_hyperv/nova/vif.py +++ b/compute_hyperv/nova/vif.py @@ -18,7 +18,6 @@ import abc from nova import exception from nova.i18n import _ -import nova.network from nova.network import model from nova.network import os_vif_util import os_vif @@ -74,10 +73,7 @@ class HyperVVIFDriver(object): self._metricsutils = utilsfactory.get_metricsutils() self._netutils = utilsfactory.get_networkutils() self._vmutils = utilsfactory.get_vmutils() - if nova.network.is_neutron(): - self._vif_plugin = HyperVNeutronVIFPlugin() - else: - self._vif_plugin = HyperVNovaNetworkVIFPlugin() + self._vif_plugin = HyperVNeutronVIFPlugin() def plug(self, instance, vif): vif_type = vif['type'] diff --git a/compute_hyperv/nova/vmops.py b/compute_hyperv/nova/vmops.py index 2b8d7629..abc1f292 100644 --- a/compute_hyperv/nova/vmops.py +++ b/compute_hyperv/nova/vmops.py @@ -383,11 +383,10 @@ class VMOps(object): # already up will not undergo that transition, and for # anything that might be stale (cache-wise) assume it's # already up so we don't block on it. - if utils.is_neutron() and CONF.vif_plugging_timeout: + if CONF.vif_plugging_timeout: return [('network-vif-plugged', vif['id']) for vif in network_info if vif.get('active') is False] - else: - return [] + return [] def create_instance(self, context, instance, network_info, block_device_info, vm_gen, image_meta): diff --git a/compute_hyperv/tests/test.py b/compute_hyperv/tests/test.py index 38a9694f..fbcd50a7 100644 --- a/compute_hyperv/tests/test.py +++ b/compute_hyperv/tests/test.py @@ -21,8 +21,6 @@ inline callbacks. """ -import os - import eventlet eventlet.monkey_patch(os=False) @@ -89,17 +87,15 @@ class NoDBTestCase(base.BaseTestCase): def setUp(self): """Run before each test method to initialize test environment.""" - super(NoDBTestCase, self).setUp() - self.useFixture(mock_fixture.MockAutospecFixture()) - self.useFixture(nova_fixtures.Timeout( - os.environ.get('OS_TEST_TIMEOUT', 0), - self.TIMEOUT_SCALING_FACTOR)) + # Ensure BaseTestCase's ConfigureLogging fixture is disabled since + # we're using the one from Nova (StandardLogging). + with fixtures.EnvironmentVariable('OS_LOG_CAPTURE', '0'): + super(NoDBTestCase, self).setUp() + + self.useFixture(mock_fixture.MockAutospecFixture()) - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.TempHomeDir()) self.useFixture(log_fixture.get_logging_handle_error_fixture()) - self.useFixture(nova_fixtures.OutputStreamCapture()) self.useFixture(nova_fixtures.StandardLogging()) self.useFixture(conf_fixture.ConfFixture(CONF)) diff --git a/compute_hyperv/tests/unit/test_driver.py b/compute_hyperv/tests/unit/test_driver.py index ce7ac5f8..408c129a 100644 --- a/compute_hyperv/tests/unit/test_driver.py +++ b/compute_hyperv/tests/unit/test_driver.py @@ -450,11 +450,6 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase): self.driver._vmops.unplug_vifs.assert_called_once_with( mock.sentinel.instance, mock.sentinel.network_info) - def test_refresh_instance_security_rules(self): - self.assertRaises(NotImplementedError, - self.driver.refresh_instance_security_rules, - instance=mock.sentinel.instance) - def test_migrate_disk_and_power_off(self): self.driver.migrate_disk_and_power_off( mock.sentinel.context, mock.sentinel.instance, mock.sentinel.dest, diff --git a/compute_hyperv/tests/unit/test_imagecache.py b/compute_hyperv/tests/unit/test_imagecache.py index 28e6590e..71fd3c64 100644 --- a/compute_hyperv/tests/unit/test_imagecache.py +++ b/compute_hyperv/tests/unit/test_imagecache.py @@ -188,7 +188,8 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase): @ddt.data(True, False) def test_age_and_verify_cached_images(self, remove_unused_base_images): - self.flags(remove_unused_base_images=remove_unused_base_images) + self.flags(remove_unused_base_images=remove_unused_base_images, + group='image_cache') fake_images = [mock.sentinel.FAKE_IMG1, mock.sentinel.FAKE_IMG2] fake_used_images = [mock.sentinel.FAKE_IMG1] diff --git a/compute_hyperv/tests/unit/test_vif.py b/compute_hyperv/tests/unit/test_vif.py index 385161c4..6306b4dc 100644 --- a/compute_hyperv/tests/unit/test_vif.py +++ b/compute_hyperv/tests/unit/test_vif.py @@ -54,21 +54,6 @@ class HyperVVIFDriverTestCase(test_base.HyperVBaseTestCase): self._vmutils = self.vif_driver._vmutils self._metricsutils = self.vif_driver._metricsutils - @mock.patch.object(vif.nova.network, 'is_neutron') - def test_init_neutron(self, mock_is_neutron): - mock_is_neutron.return_value = True - - driver = vif.HyperVVIFDriver() - self.assertIsInstance(driver._vif_plugin, vif.HyperVNeutronVIFPlugin) - - @mock.patch.object(vif.nova.network, 'is_neutron') - def test_init_nova(self, mock_is_neutron): - mock_is_neutron.return_value = False - - driver = vif.HyperVVIFDriver() - self.assertIsInstance(driver._vif_plugin, - vif.HyperVNovaNetworkVIFPlugin) - def test_plug(self): vif = {'type': model.VIF_TYPE_HYPERV} self.vif_driver.plug(mock.sentinel.instance, vif) diff --git a/compute_hyperv/tests/unit/test_vmops.py b/compute_hyperv/tests/unit/test_vmops.py index bf6155dd..edfee5fb 100644 --- a/compute_hyperv/tests/unit/test_vmops.py +++ b/compute_hyperv/tests/unit/test_vmops.py @@ -625,8 +625,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): self._vmops._neutron_failed_callback, mock.sentinel.event_name, mock.sentinel.instance) - @mock.patch.object(vmops.utils, 'is_neutron') - def test_get_neutron_events(self, mock_is_neutron): + def test_get_neutron_events(self): network_info = [{'id': mock.sentinel.vif_id1, 'active': True}, {'id': mock.sentinel.vif_id2, 'active': False}, {'id': mock.sentinel.vif_id3}] @@ -634,16 +633,13 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): events = self._vmops._get_neutron_events(network_info) self.assertEqual([('network-vif-plugged', mock.sentinel.vif_id2)], events) - mock_is_neutron.assert_called_once_with() - @mock.patch.object(vmops.utils, 'is_neutron') - def test_get_neutron_events_no_timeout(self, mock_is_neutron): + def test_get_neutron_events_no_timeout(self): self.flags(vif_plugging_timeout=0) network_info = [{'id': mock.sentinel.vif_id1, 'active': True}] events = self._vmops._get_neutron_events(network_info) self.assertEqual([], events) - mock_is_neutron.assert_called_once_with() @mock.patch.object(vmops.VMOps, 'configure_instance_metrics') @mock.patch.object(vmops.VMOps, 'update_vm_resources') diff --git a/setup.cfg b/setup.cfg index 88b3089c..793196b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,7 @@ classifier = Programming Language :: Python :: 3 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 keywords = openstack nova hyper-v compute [files] diff --git a/tox.ini b/tox.ini index 167c73f9..4c56a75c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 2.0 -envlist = py35,py36,pep8,pip-missing-reqs +envlist = py37,pep8,pip-missing-reqs skipsdist = True [testenv]