Browse Source

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

tags/18.2.2
Zuul 1 month ago
parent
commit
fed6ba631b

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

@@ -1553,6 +1553,8 @@ class FakeLibvirtFixture(fixtures.Fixture):
1553 1553
 
1554 1554
         self.useFixture(
1555 1555
             fixtures.MockPatch('nova.virt.libvirt.utils.get_fs_info'))
1556
+        self.useFixture(
1557
+            fixtures.MockPatch('nova.compute.utils.get_machine_ips'))
1556 1558
 
1557 1559
         disable_event_thread(self)
1558 1560
 

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

@@ -898,6 +898,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
898 898
                       'resolve_driver_format',
899 899
                       imagebackend.Image._get_driver_format)
900 900
 
901
+        self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
902
+
901 903
         self.useFixture(fakelibvirt.FakeLibvirtFixture())
902 904
         self.test_instance = _create_test_instance()
903 905
         self.test_image_meta = {
@@ -13643,16 +13645,22 @@ class LibvirtConnTestCase(test.NoDBTestCase,
13643 13645
 
13644 13646
     @mock.patch.object(libvirt_driver.LOG, 'warning')
13645 13647
     @mock.patch('nova.compute.utils.get_machine_ips')
13646
-    def test_get_host_ip_addr_failure(self, mock_ips, mock_log):
13648
+    def test_check_my_ip(self, mock_ips, mock_log):
13647 13649
         mock_ips.return_value = ['8.8.8.8', '75.75.75.75']
13648 13650
         drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
13649
-        drvr.get_host_ip_addr()
13651
+        drvr._check_my_ip()
13650 13652
         mock_log.assert_called_once_with(u'my_ip address (%(my_ip)s) was '
13651 13653
                                          u'not found on any of the '
13652 13654
                                          u'interfaces: %(ifaces)s',
13653 13655
                                          {'ifaces': '8.8.8.8, 75.75.75.75',
13654 13656
                                           'my_ip': mock.ANY})
13655 13657
 
13658
+    def test_init_host_checks_ip(self):
13659
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
13660
+        with mock.patch.object(drvr, '_check_my_ip') as mock_check:
13661
+            drvr.init_host('fake-host')
13662
+            mock_check.assert_called_once_with()
13663
+
13656 13664
     def test_conn_event_handler(self):
13657 13665
         drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
13658 13666
         service_mock = mock.MagicMock()
@@ -20905,6 +20913,8 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
20905 20913
         self.assertEqual(set([uuids.mdev1]),
20906 20914
                          drvr._get_existing_mdevs_not_assigned())
20907 20915
 
20916
+    @mock.patch('nova.compute.utils.get_machine_ips',
20917
+                new=mock.Mock(return_value=[]))
20908 20918
     @mock.patch.object(nova.privsep.libvirt, 'create_mdev')
20909 20919
     @mock.patch.object(libvirt_driver.LibvirtDriver,
20910 20920
                        '_get_mdev_capable_devices')

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

@@ -856,6 +856,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
856 856
         # will try to execute some commands which hangs tests so let's just
857 857
         # stub out the unplug call to os-vif since we don't care about it.
858 858
         self.stub_out('os_vif.unplug', lambda a, kw: None)
859
+        self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
859 860
 
860 861
     def test_force_hard_reboot(self):
861 862
         self.flags(wait_soft_reboot_seconds=0, group='libvirt')

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

@@ -489,6 +489,8 @@ class LibvirtDriver(driver.ComputeDriver):
489 489
 
490 490
         self._check_file_backed_memory_support()
491 491
 
492
+        self._check_my_ip()
493
+
492 494
         if (CONF.libvirt.virt_type == 'lxc' and
493 495
                 not (CONF.libvirt.uid_maps and CONF.libvirt.gid_maps)):
494 496
             LOG.warning("Running libvirt-lxc without user namespaces is "
@@ -623,6 +625,13 @@ class LibvirtDriver(driver.ComputeDriver):
623 625
                     'Running Nova with file_backed_memory requires '
624 626
                     'ram_allocation_ratio configured to 1.0')
625 627
 
628
+    def _check_my_ip(self):
629
+        ips = compute_utils.get_machine_ips()
630
+        if CONF.my_ip not in ips:
631
+            LOG.warning('my_ip address (%(my_ip)s) was not found on '
632
+                        'any of the interfaces: %(ifaces)s',
633
+                        {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
634
+
626 635
     def _prepare_migration_flags(self):
627 636
         migration_flags = 0
628 637
 
@@ -3221,11 +3230,6 @@ class LibvirtDriver(driver.ComputeDriver):
3221 3230
         return self._get_console_output_file(instance, console_log)
3222 3231
 
3223 3232
     def get_host_ip_addr(self):
3224
-        ips = compute_utils.get_machine_ips()
3225
-        if CONF.my_ip not in ips:
3226
-            LOG.warning('my_ip address (%(my_ip)s) was not found on '
3227
-                        'any of the interfaces: %(ifaces)s',
3228
-                        {'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
3229 3233
         return CONF.my_ip
3230 3234
 
3231 3235
     def get_vnc_console(self, context, instance):

Loading…
Cancel
Save