Skip to content

Commit 5a63174

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "libvirt: move checking CONF.my_ip to init_host()" into stable/stein
2 parents f6d3edf + 560317c commit 5a63174

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

nova/tests/unit/virt/libvirt/fakelibvirt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,8 @@ def setUp(self):
17721772

17731773
self.useFixture(
17741774
fixtures.MockPatch('nova.virt.libvirt.utils.get_fs_info'))
1775+
self.useFixture(
1776+
fixtures.MockPatch('nova.compute.utils.get_machine_ips'))
17751777

17761778
# libvirt driver needs to call out to the filesystem to get the
17771779
# parent_ifname for the SRIOV VFs.

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ def setUp(self):
894894
'resolve_driver_format',
895895
imagebackend.Image._get_driver_format)
896896

897+
self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
898+
897899
self.useFixture(fakelibvirt.FakeLibvirtFixture())
898900
self.test_instance = _create_test_instance()
899901
self.test_image_meta = {
@@ -13801,16 +13803,22 @@ def test_get_host_ip_addr(self):
1380113803

1380213804
@mock.patch.object(libvirt_driver.LOG, 'warning')
1380313805
@mock.patch('nova.compute.utils.get_machine_ips')
13804-
def test_get_host_ip_addr_failure(self, mock_ips, mock_log):
13806+
def test_check_my_ip(self, mock_ips, mock_log):
1380513807
mock_ips.return_value = ['8.8.8.8', '75.75.75.75']
1380613808
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
13807-
drvr.get_host_ip_addr()
13809+
drvr._check_my_ip()
1380813810
mock_log.assert_called_once_with(u'my_ip address (%(my_ip)s) was '
1380913811
u'not found on any of the '
1381013812
u'interfaces: %(ifaces)s',
1381113813
{'ifaces': '8.8.8.8, 75.75.75.75',
1381213814
'my_ip': mock.ANY})
1381313815

13816+
def test_init_host_checks_ip(self):
13817+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
13818+
with mock.patch.object(drvr, '_check_my_ip') as mock_check:
13819+
drvr.init_host('fake-host')
13820+
mock_check.assert_called_once_with()
13821+
1381413822
def test_conn_event_handler(self):
1381513823
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
1381613824
service_mock = mock.MagicMock()
@@ -21546,6 +21554,8 @@ def test_get_existing_mdevs_not_assigned(self, get_all_assigned_mdevs,
2154621554
self.assertEqual(set([uuids.mdev1]),
2154721555
drvr._get_existing_mdevs_not_assigned())
2154821556

21557+
@mock.patch('nova.compute.utils.get_machine_ips',
21558+
new=mock.Mock(return_value=[]))
2154921559
@mock.patch.object(nova.privsep.libvirt, 'create_mdev')
2155021560
@mock.patch.object(libvirt_driver.LibvirtDriver,
2155121561
'_get_mdev_capable_devices')

nova/tests/unit/virt/test_virt_drivers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ def setUp(self):
900900
# will try to execute some commands which hangs tests so let's just
901901
# stub out the unplug call to os-vif since we don't care about it.
902902
self.stub_out('os_vif.unplug', lambda a, kw: None)
903+
self.stub_out('nova.compute.utils.get_machine_ips', lambda: [])
903904

904905
def test_force_hard_reboot(self):
905906
self.flags(wait_soft_reboot_seconds=0, group='libvirt')

nova/virt/libvirt/driver.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def init_host(self, host):
491491

492492
self._check_file_backed_memory_support()
493493

494+
self._check_my_ip()
495+
494496
if (CONF.libvirt.virt_type == 'lxc' and
495497
not (CONF.libvirt.uid_maps and CONF.libvirt.gid_maps)):
496498
LOG.warning("Running libvirt-lxc without user namespaces is "
@@ -643,6 +645,13 @@ def _check_file_backed_memory_support(self):
643645
'Running Nova with file_backed_memory requires '
644646
'ram_allocation_ratio configured to 1.0')
645647

648+
def _check_my_ip(self):
649+
ips = compute_utils.get_machine_ips()
650+
if CONF.my_ip not in ips:
651+
LOG.warning('my_ip address (%(my_ip)s) was not found on '
652+
'any of the interfaces: %(ifaces)s',
653+
{'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
654+
646655
def _prepare_migration_flags(self):
647656
migration_flags = 0
648657

@@ -3279,11 +3288,6 @@ def get_console_output(self, context, instance):
32793288
return self._get_console_output_file(instance, console_path)
32803289

32813290
def get_host_ip_addr(self):
3282-
ips = compute_utils.get_machine_ips()
3283-
if CONF.my_ip not in ips:
3284-
LOG.warning('my_ip address (%(my_ip)s) was not found on '
3285-
'any of the interfaces: %(ifaces)s',
3286-
{'my_ip': CONF.my_ip, 'ifaces': ", ".join(ips)})
32873291
return CONF.my_ip
32883292

32893293
def get_vnc_console(self, context, instance):

0 commit comments

Comments
 (0)