diff options
author | Zuul <zuul@review.opendev.org> | 2019-08-12 22:16:24 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-08-12 22:16:24 +0000 |
commit | 6212da3f57e3405e4a034e35e6cd6f17e555d5f2 (patch) | |
tree | 50f767d483afd82faebaedc50107d07f6a2c9008 | |
parent | c5b2242483ee54309e03bfb2123934f9a38d9784 (diff) | |
parent | 028a8e949e9b9b5731e7f5f283375533ab6f85fa (diff) | |
download | nova-17.0.12.tar.gz |
Merge "libvirt: move checking CONF.my_ip to init_host()" into stable/queens17.0.12
-rw-r--r-- | nova/tests/unit/virt/libvirt/fakelibvirt.py | 3 | ||||
-rw-r--r-- | nova/tests/unit/virt/libvirt/test_driver.py | 14 | ||||
-rw-r--r-- | nova/tests/unit/virt/test_virt_drivers.py | 1 | ||||
-rw-r--r-- | nova/virt/libvirt/driver.py | 14 |
4 files changed, 25 insertions, 7 deletions
diff --git a/nova/tests/unit/virt/libvirt/fakelibvirt.py b/nova/tests/unit/virt/libvirt/fakelibvirt.py index f4e437e07c..9022bbcdc4 100644 --- a/nova/tests/unit/virt/libvirt/fakelibvirt.py +++ b/nova/tests/unit/virt/libvirt/fakelibvirt.py @@ -1535,6 +1535,9 @@ class FakeLibvirtFixture(fixtures.Fixture): # NOTE(mdbooth): The strange incantation below means 'this module' self.useFixture(fixtures.MonkeyPatch(i, sys.modules[__name__])) + self.useFixture( + fixtures.MockPatch('nova.compute.utils.get_machine_ips')) + disable_event_thread(self) if self.stub_os_vif: diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 036a518e34..bc6a0c230f 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -806,6 +806,8 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.stubs.Set(imagebackend.Image, 'resolve_driver_format', imagebackend.Image._get_driver_format) + self.stub_out('nova.compute.utils.get_machine_ips', lambda: []) + self.useFixture(fakelibvirt.FakeLibvirtFixture()) self.test_instance = _create_test_instance() self.test_image_meta = { @@ -12930,16 +12932,22 @@ class LibvirtConnTestCase(test.NoDBTestCase, @mock.patch.object(libvirt_driver.LOG, 'warning') @mock.patch('nova.compute.utils.get_machine_ips') - def test_get_host_ip_addr_failure(self, mock_ips, mock_log): + def test_check_my_ip(self, mock_ips, mock_log): mock_ips.return_value = ['8.8.8.8', '75.75.75.75'] drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - drvr.get_host_ip_addr() + drvr._check_my_ip() mock_log.assert_called_once_with(u'my_ip address (%(my_ip)s) was ' u'not found on any of the ' u'interfaces: %(ifaces)s', {'ifaces': '8.8.8.8, 75.75.75.75', 'my_ip': mock.ANY}) + def test_init_host_checks_ip(self): + drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + with mock.patch.object(drvr, '_check_my_ip') as mock_check: + drvr.init_host('fake-host') + mock_check.assert_called_once_with() + def test_conn_event_handler(self): self.mox.UnsetStubs() drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) @@ -19940,6 +19948,8 @@ class LibvirtDriverTestCase(test.NoDBTestCase): self.assertEqual(set([uuids.mdev1]), drvr._get_existing_mdevs_not_assigned()) + @mock.patch('nova.compute.utils.get_machine_ips', + new=mock.Mock(return_value=[])) @mock.patch.object(nova.privsep.libvirt, 'create_mdev') @mock.patch.object(libvirt_driver.LibvirtDriver, '_get_mdev_capable_devices') diff --git a/nova/tests/unit/virt/test_virt_drivers.py b/nova/tests/unit/virt/test_virt_drivers.py index c256bec29a..c83ebbfa61 100644 --- a/nova/tests/unit/virt/test_virt_drivers.py +++ b/nova/tests/unit/virt/test_virt_drivers.py @@ -889,6 +889,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase): # will try to execute some commands which hangs tests so let's just # stub out the unplug call to os-vif since we don't care about it. self.stub_out('os_vif.unplug', lambda a, kw: None) + self.stub_out('nova.compute.utils.get_machine_ips', lambda: []) def _fake_admin_context(self, *args, **kwargs): return self.ctxt diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index d52d482219..8045404f3c 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -500,6 +500,8 @@ class LibvirtDriver(driver.ComputeDriver): self._set_multiattach_support() + self._check_my_ip() + if (CONF.libvirt.virt_type == 'lxc' and not (CONF.libvirt.uid_maps and CONF.libvirt.gid_maps)): LOG.warning("Running libvirt-lxc without user namespaces is " @@ -621,6 +623,13 @@ class LibvirtDriver(driver.ComputeDriver): 'versions of QEMU and libvirt. QEMU must be less than ' '2.10 or libvirt must be greater than or equal to 3.10.') + def _check_my_ip(self): + ips = compute_utils.get_machine_ips() + if CONF.my_ip not in ips: + LOG.warning('my_ip address (%(my_ip)s) was not found on ' + 'any of the interfaces: %(ifaces)s', + {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)}) + def _prepare_migration_flags(self): migration_flags = 0 @@ -3226,11 +3235,6 @@ class LibvirtDriver(driver.ComputeDriver): return self._get_console_output_file(instance, console_log) def get_host_ip_addr(self): - ips = compute_utils.get_machine_ips() - if CONF.my_ip not in ips: - LOG.warning('my_ip address (%(my_ip)s) was not found on ' - 'any of the interfaces: %(ifaces)s', - {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)}) return CONF.my_ip def get_vnc_console(self, context, instance): |