Skip to content

Commit f210115

Browse files
juliakregerjayofdoom
authored andcommitted
Ignore plug_vifs on the ironic driver
When the nova-compute service starts, by default it attempts to startup instance configuration states for aspects such as networking. This is fine in most cases, and makes a lot of sense if the nova-compute service is just managing virtual machines on a hypervisor. This is done, one instance at a time. However, when the compute driver is ironic, the networking is managed as part of the physical machine lifecycle potentially all the way into committed switch configurations. As such, there is no need to attempt to call ``plug_vifs`` on every single instance managed by the nova-compute process which is backed by Ironic. Additionally, using ironic tends to manage far more physical machines per nova-compute service instance then when when operating co-installed with a hypervisor. Often this means a cluster of a thousand machines, with three controllers, will see thousands of un-needed API calls upon service start, which elongates the entire process and negatively impacts operations. In essence, nova.virt.ironic's plug_vifs call now does nothing, and merely issues a debug LOG entry when called. Closes-Bug: #1777608 Change-Id: Iba87cef50238c5b02ab313f2311b826081d5b4ab (cherry picked from commit 7f81cf2) (cherry picked from commit eb6d70f)
1 parent 2f7f4cc commit f210115

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,17 +2016,12 @@ def test_plug_vifs_with_port(self, mock_vatt):
20162016
@mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs')
20172017
def test_plug_vifs(self, mock__plug_vifs):
20182018
node_id = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
2019-
node = _get_cached_node(id=node_id)
2020-
2021-
self.mock_conn.get_node.return_value = node
20222019
instance = fake_instance.fake_instance_obj(self.ctx,
20232020
node=node_id)
20242021
network_info = utils.get_test_network_info()
20252022
self.driver.plug_vifs(instance, network_info)
20262023

2027-
self.mock_conn.get_node.assert_called_once_with(
2028-
node_id, fields=ironic_driver._NODE_FIELDS)
2029-
mock__plug_vifs.assert_called_once_with(node, instance, network_info)
2024+
mock__plug_vifs.assert_not_called()
20302025

20312026
@mock.patch.object(FAKE_CLIENT.node, 'vif_attach')
20322027
def test_plug_vifs_multiple_ports(self, mock_vatt):
@@ -2160,11 +2155,17 @@ def test_unplug_vifs_no_network_info(self, mock_vdet):
21602155
self.driver.unplug_vifs(instance, network_info)
21612156
self.assertFalse(mock_vdet.called)
21622157

2163-
@mock.patch.object(ironic_driver.IronicDriver, 'plug_vifs')
2158+
@mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs')
21642159
def test_attach_interface(self, mock_pv):
2165-
self.driver.attach_interface('fake_context', 'fake_instance',
2160+
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
2161+
node = _get_cached_node(uuid=node_uuid)
2162+
instance = fake_instance.fake_instance_obj(self.ctx,
2163+
node=node_uuid)
2164+
self.mock_conn.get_node.return_value = node
2165+
2166+
self.driver.attach_interface('fake_context', instance,
21662167
'fake_image_meta', 'fake_vif')
2167-
mock_pv.assert_called_once_with('fake_instance', ['fake_vif'])
2168+
mock_pv.assert_called_once_with(node, instance, ['fake_vif'])
21682169

21692170
@mock.patch.object(ironic_driver.IronicDriver, 'unplug_vifs')
21702171
def test_detach_interface(self, mock_uv):
@@ -2457,25 +2458,31 @@ def test_get_volume_connector_no_ip_without_mac(self):
24572458
def test_get_volume_connector_no_ip_no_fixed_ip(self):
24582459
self._test_get_volume_connector_no_ip(False, no_fixed_ip=True)
24592460

2460-
@mock.patch.object(ironic_driver.IronicDriver, 'plug_vifs')
2461+
@mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs')
24612462
def test_prepare_networks_before_block_device_mapping(self, mock_pvifs):
2463+
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
2464+
node = _get_cached_node(uuid=node_uuid)
2465+
self.mock_conn.get_node.return_value = node
24622466
instance = fake_instance.fake_instance_obj(self.ctx)
24632467
network_info = utils.get_test_network_info()
24642468
self.driver.prepare_networks_before_block_device_mapping(instance,
24652469
network_info)
2466-
mock_pvifs.assert_called_once_with(instance, network_info)
2470+
mock_pvifs.assert_called_once_with(node, instance, network_info)
24672471

2468-
@mock.patch.object(ironic_driver.IronicDriver, 'plug_vifs')
2472+
@mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs')
24692473
def test_prepare_networks_before_block_device_mapping_error(self,
24702474
mock_pvifs):
2475+
node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
2476+
node = _get_cached_node(uuid=node_uuid)
2477+
self.mock_conn.get_node.return_value = node
24712478
instance = fake_instance.fake_instance_obj(self.ctx)
24722479
network_info = utils.get_test_network_info()
24732480
mock_pvifs.side_effect = ironic_exception.BadRequest('fake error')
24742481
self.assertRaises(
24752482
ironic_exception.BadRequest,
24762483
self.driver.prepare_networks_before_block_device_mapping,
24772484
instance, network_info)
2478-
mock_pvifs.assert_called_once_with(instance, network_info)
2485+
mock_pvifs.assert_called_once_with(node, instance, network_info)
24792486

24802487
@mock.patch.object(ironic_driver.IronicDriver, 'unplug_vifs')
24812488
def test_clean_networks_preparation(self, mock_upvifs):

nova/virt/ironic/driver.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,13 +1558,21 @@ def _unplug_vifs(self, node, instance, network_info):
15581558
def plug_vifs(self, instance, network_info):
15591559
"""Plug VIFs into networks.
15601560
1561+
This method is present for compatability. Any call will result
1562+
in a DEBUG log entry being generated, and will otherwise be
1563+
ignored, as Ironic manages VIF attachments through a node
1564+
lifecycle. Please see ``attach_interface``, which is the
1565+
proper and current method to utilize.
1566+
15611567
:param instance: The instance object.
15621568
:param network_info: Instance network information.
15631569
15641570
"""
1565-
# instance.node is the ironic node's UUID.
1566-
node = self._get_node(instance.node)
1567-
self._plug_vifs(node, instance, network_info)
1571+
LOG.debug('VIF plug called for instance %(instance)s on node '
1572+
'%(node)s, however Ironic manages VIF attachments '
1573+
'for nodes.',
1574+
{'instance': instance.uuid,
1575+
'node': instance.node})
15681576

15691577
def unplug_vifs(self, instance, network_info):
15701578
"""Unplug VIFs from networks.
@@ -1595,7 +1603,8 @@ def attach_interface(self, context, instance, image_meta, vif):
15951603
# event from neutron or by _heal_instance_info_cache periodic task. In
15961604
# both cases, this is done asynchronously, so the cache may not be up
15971605
# to date immediately after attachment.
1598-
self.plug_vifs(instance, [vif])
1606+
node = self._get_node(instance.node)
1607+
self._plug_vifs(node, instance, [vif])
15991608

16001609
def detach_interface(self, context, instance, vif):
16011610
"""Use hotunplug to remove a network interface from a running instance.
@@ -1911,7 +1920,9 @@ def prepare_networks_before_block_device_mapping(self, instance,
19111920
"""
19121921

19131922
try:
1914-
self.plug_vifs(instance, network_info)
1923+
node = self._get_node(instance.node)
1924+
self._plug_vifs(node, instance, network_info)
1925+
19151926
except Exception:
19161927
with excutils.save_and_reraise_exception():
19171928
LOG.error("Error preparing deploy for instance "
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes slow compute restart when using the ``nova.virt.ironic`` compute
5+
driver where the driver was previously attempting to attach VIFS on
6+
start-up via the ``plug_vifs`` driver method. This method has grown
7+
otherwise unused since the introduction of the ``attach_interface``
8+
method of attaching VIFs. As Ironic manages the attachment of VIFs to
9+
baremetal nodes in order to align with the security requirements of a
10+
physical baremetal node's lifecycle. The ironic driver now ignores calls
11+
to the ``plug_vifs`` method.

0 commit comments

Comments
 (0)