Browse Source

Merge "libvirt: move checking CONF.my_ip to init_host()" into stable/queens

tags/17.0.12^0
Zuul 1 month ago
parent
commit
6212da3f57

+ 3
- 0
nova/tests/unit/virt/libvirt/fakelibvirt.py View File

@@ -1535,6 +1535,9 @@ class FakeLibvirtFixture(fixtures.Fixture):
1535 1535
             # NOTE(mdbooth): The strange incantation below means 'this module'
1536 1536
             self.useFixture(fixtures.MonkeyPatch(i, sys.modules[__name__]))
1537 1537
 
1538
+        self.useFixture(
1539
+            fixtures.MockPatch('nova.compute.utils.get_machine_ips'))
1540
+
1538 1541
         disable_event_thread(self)
1539 1542
 
1540 1543
         if self.stub_os_vif:

+ 12
- 2
nova/tests/unit/virt/libvirt/test_driver.py View File

@@ -806,6 +806,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
806 806
         self.stubs.Set(imagebackend.Image, 'resolve_driver_format',
807 807
                        imagebackend.Image._get_driver_format)
808 808
 
809
+        self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
810
+
809 811
         self.useFixture(fakelibvirt.FakeLibvirtFixture())
810 812
         self.test_instance = _create_test_instance()
811 813
         self.test_image_meta = {
@@ -12930,16 +12932,22 @@ class LibvirtConnTestCase(test.NoDBTestCase,
12930 12932
 
12931 12933
     @mock.patch.object(libvirt_driver.LOG, 'warning')
12932 12934
     @mock.patch('nova.compute.utils.get_machine_ips')
12933
-    def test_get_host_ip_addr_failure(self, mock_ips, mock_log):
12935
+    def test_check_my_ip(self, mock_ips, mock_log):
12934 12936
         mock_ips.return_value = ['8.8.8.8', '75.75.75.75']
12935 12937
         drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
12936
-        drvr.get_host_ip_addr()
12938
+        drvr._check_my_ip()
12937 12939
         mock_log.assert_called_once_with(u'my_ip address (%(my_ip)s) was '
12938 12940
                                          u'not found on any of the '
12939 12941
                                          u'interfaces: %(ifaces)s',
12940 12942
                                          {'ifaces': '8.8.8.8, 75.75.75.75',
12941 12943
                                           'my_ip': mock.ANY})
12942 12944
 
12945
+    def test_init_host_checks_ip(self):
12946
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
12947
+        with mock.patch.object(drvr, '_check_my_ip') as mock_check:
12948
+            drvr.init_host('fake-host')
12949
+            mock_check.assert_called_once_with()
12950
+
12943 12951
     def test_conn_event_handler(self):
12944 12952
         self.mox.UnsetStubs()
12945 12953
         drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
@@ -19940,6 +19948,8 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
19940 19948
         self.assertEqual(set([uuids.mdev1]),
19941 19949
                          drvr._get_existing_mdevs_not_assigned())
19942 19950
 
19951
+    @mock.patch('nova.compute.utils.get_machine_ips',
19952
+                new=mock.Mock(return_value=[]))
19943 19953
     @mock.patch.object(nova.privsep.libvirt, 'create_mdev')
19944 19954
     @mock.patch.object(libvirt_driver.LibvirtDriver,
19945 19955
                        '_get_mdev_capable_devices')

+ 1
- 0
nova/tests/unit/virt/test_virt_drivers.py View File

@@ -889,6 +889,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
889 889
         # will try to execute some commands which hangs tests so let's just
890 890
         # stub out the unplug call to os-vif since we don't care about it.
891 891
         self.stub_out('os_vif.unplug', lambda a, kw: None)
892
+        self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
892 893
 
893 894
     def _fake_admin_context(self, *args, **kwargs):
894 895
         return self.ctxt

+ 9
- 5
nova/virt/libvirt/driver.py View File

@@ -500,6 +500,8 @@ class LibvirtDriver(driver.ComputeDriver):
500 500
 
501 501
         self._set_multiattach_support()
502 502
 
503
+        self._check_my_ip()
504
+
503 505
         if (CONF.libvirt.virt_type == 'lxc' and
504 506
                 not (CONF.libvirt.uid_maps and CONF.libvirt.gid_maps)):
505 507
             LOG.warning("Running libvirt-lxc without user namespaces is "
@@ -621,6 +623,13 @@ class LibvirtDriver(driver.ComputeDriver):
621 623
                       'versions of QEMU and libvirt. QEMU must be less than '
622 624
                       '2.10 or libvirt must be greater than or equal to 3.10.')
623 625
 
626
+    def _check_my_ip(self):
627
+        ips = compute_utils.get_machine_ips()
628
+        if CONF.my_ip not in ips:
629
+            LOG.warning('my_ip address (%(my_ip)s) was not found on '
630
+                        'any of the interfaces: %(ifaces)s',
631
+                        {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
632
+
624 633
     def _prepare_migration_flags(self):
625 634
         migration_flags = 0
626 635
 
@@ -3226,11 +3235,6 @@ class LibvirtDriver(driver.ComputeDriver):
3226 3235
         return self._get_console_output_file(instance, console_log)
3227 3236
 
3228 3237
     def get_host_ip_addr(self):
3229
-        ips = compute_utils.get_machine_ips()
3230
-        if CONF.my_ip not in ips:
3231
-            LOG.warning('my_ip address (%(my_ip)s) was not found on '
3232
-                        'any of the interfaces: %(ifaces)s',
3233
-                        {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
3234 3238
         return CONF.my_ip
3235 3239
 
3236 3240
     def get_vnc_console(self, context, instance):

Loading…
Cancel
Save