Merge "Only plug ports with a tenant VIF in configure_tenant_networks"
This commit is contained in:
commit
0a0e8c4b61
3 files changed
+103
-24
No files matched your search
@@ -168,34 +168,33 @@ class NeutronNetwork(common.NeutronVIFPortIDMixin,
|
||||
ports = task.ports
|
||||
LOG.info('Mapping instance ports to %s', node.uuid)
|
||||
|
||||
# TODO(russell_h): this is based on the broken assumption that the
|
||||
# number of Neutron ports will match the number of physical ports.
|
||||
# Instead, we should probably list ports for this instance in
|
||||
# Neutron and update all of those with the appropriate portmap.
|
||||
if not ports:
|
||||
msg = _("No ports are associated with node %s") % node.uuid
|
||||
LOG.error(msg)
|
||||
raise exception.NetworkError(msg)
|
||||
ports = [p for p in ports if not p.portgroup_id]
|
||||
portgroups = task.portgroups
|
||||
|
||||
# Only objects with a tenant VIF recorded in internal_info (set by
|
||||
# vif_attach) are plugged. Every one of them must succeed. Ports
|
||||
# that are members of a portgroup are included so they can be
|
||||
# plugged individually.
|
||||
to_plug = [
|
||||
p for p in ports + portgroups
|
||||
if self._get_vif_id_by_port_like_obj(p)]
|
||||
|
||||
if not to_plug:
|
||||
msg = _("No neutron ports or portgroups are associated with "
|
||||
"node %s") % node.uuid
|
||||
LOG.error(msg)
|
||||
raise exception.NetworkError(msg)
|
||||
|
||||
client = neutron.get_client(context=task.context)
|
||||
try:
|
||||
pobj_without_vif = 0
|
||||
for port_like_obj in ports + portgroups:
|
||||
|
||||
try:
|
||||
common.plug_port_to_tenant_network(task, port_like_obj,
|
||||
client=client)
|
||||
except exception.VifNotAttached:
|
||||
pobj_without_vif += 1
|
||||
continue
|
||||
|
||||
if pobj_without_vif == len(ports + portgroups):
|
||||
msg = _("No neutron ports or portgroups are associated with "
|
||||
"node %s") % node.uuid
|
||||
LOG.error(msg)
|
||||
raise exception.NetworkError(msg)
|
||||
for port_like_obj in to_plug:
|
||||
# NOTE: any failure here (NetworkError) propagates so we
|
||||
# never leave the node with only some tenant VIFs plugged.
|
||||
common.plug_port_to_tenant_network(task, port_like_obj,
|
||||
client=client)
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
@@ -212,9 +211,7 @@ class NeutronNetwork(common.NeutronVIFPortIDMixin,
|
||||
node = task.node
|
||||
LOG.info('Unbinding instance ports from node %s', node.uuid)
|
||||
|
||||
ports = [p for p in task.ports if not p.portgroup_id]
|
||||
portgroups = task.portgroups
|
||||
for port_like_obj in ports + portgroups:
|
||||
for port_like_obj in task.ports + task.portgroups:
|
||||
vif_port_id = NeutronNetwork._get_vif_id_by_port_like_obj(
|
||||
port_like_obj)
|
||||
if not vif_port_id:
|
||||
|
||||
@@ -566,6 +566,19 @@ class NeutronInterfaceTestCase(db_base.DbTestCase):
|
||||
mock.call(pg.internal_info[common.NetType.TENANT.vif_key],
|
||||
context=task.context, reset_mac=False)])
|
||||
|
||||
@mock.patch.object(neutron_common, 'unbind_neutron_port', autospec=True)
|
||||
def test_unconfigure_tenant_networks_portgroup_member_port(
|
||||
self, mock_unbind_port):
|
||||
pg = utils.create_test_portgroup(
|
||||
self.context, node_id=self.node.id, address='ff:54:00:cf:2d:32')
|
||||
self.port.portgroup_id = pg.id
|
||||
self.port.save()
|
||||
with task_manager.acquire(self.context, self.node.id) as task:
|
||||
self.interface.unconfigure_tenant_networks(task)
|
||||
mock_unbind_port.assert_called_once_with(
|
||||
self.port.internal_info[common.NetType.TENANT.vif_key],
|
||||
context=task.context, reset_mac=True)
|
||||
|
||||
def test_configure_tenant_networks_no_ports_for_node(self):
|
||||
n = utils.create_test_node(self.context, network_interface='neutron',
|
||||
uuid=uuidutils.generate_uuid())
|
||||
@@ -587,7 +600,7 @@ class NeutronInterfaceTestCase(db_base.DbTestCase):
|
||||
'associated with node',
|
||||
self.interface.configure_tenant_networks,
|
||||
task)
|
||||
client_mock.assert_called_once_with(context=task.context)
|
||||
client_mock.assert_not_called()
|
||||
upd_mock.assert_not_called()
|
||||
self.assertIn('No neutron ports or portgroups are associated with',
|
||||
log_mock.error.call_args[0][0])
|
||||
@@ -646,6 +659,63 @@ class NeutronInterfaceTestCase(db_base.DbTestCase):
|
||||
exception.NetworkError, 'Binding failed',
|
||||
self.interface.configure_tenant_networks, task)
|
||||
|
||||
@mock.patch.object(neutron_common, 'wait_for_host_agent', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'update_neutron_port', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'wait_for_port_status', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'get_client', autospec=True)
|
||||
def test_configure_tenant_networks_skips_port_without_vif(
|
||||
self, client_mock, wait_mock_status, update_mock,
|
||||
wait_agent_mock):
|
||||
utils.create_test_port(
|
||||
self.context, node_id=self.node.id, address='52:54:00:cf:2d:33',
|
||||
uuid=uuidutils.generate_uuid(), internal_info={})
|
||||
with task_manager.acquire(self.context, self.node.id) as task:
|
||||
self.interface.configure_tenant_networks(task)
|
||||
update_mock.assert_called_once_with(
|
||||
self.context,
|
||||
self.port.internal_info[common.NetType.TENANT.vif_key],
|
||||
mock.ANY)
|
||||
client_mock.return_value.close.assert_called_once()
|
||||
|
||||
@mock.patch.object(neutron_common, 'wait_for_host_agent', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'update_neutron_port', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'wait_for_port_status', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'get_client', autospec=True)
|
||||
def test_configure_tenant_networks_portgroup_member_port(
|
||||
self, client_mock, wait_mock_status, update_mock,
|
||||
wait_agent_mock):
|
||||
pg = utils.create_test_portgroup(
|
||||
self.context, node_id=self.node.id, address='ff:54:00:cf:2d:32')
|
||||
self.port.portgroup_id = pg.id
|
||||
self.port.save()
|
||||
with task_manager.acquire(self.context, self.node.id) as task:
|
||||
self.interface.configure_tenant_networks(task)
|
||||
update_mock.assert_called_once_with(
|
||||
self.context,
|
||||
self.port.internal_info[common.NetType.TENANT.vif_key],
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch.object(neutron_common, 'wait_for_host_agent', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'update_neutron_port', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'wait_for_port_status', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'get_client', autospec=True)
|
||||
def test_configure_tenant_networks_second_port_update_fail(
|
||||
self, client_mock, wait_mock_status, update_mock,
|
||||
wait_agent_mock):
|
||||
utils.create_test_port(
|
||||
self.context, node_id=self.node.id, address='52:54:00:cf:2d:33',
|
||||
uuid=uuidutils.generate_uuid(),
|
||||
internal_info={
|
||||
common.NetType.TENANT.vif_key: uuidutils.generate_uuid()})
|
||||
update_mock.side_effect = [
|
||||
None, openstack_exc.OpenStackCloudException(message='meow')]
|
||||
with task_manager.acquire(self.context, self.node.id) as task:
|
||||
self.assertRaisesRegex(
|
||||
exception.NetworkError, 'Could not add',
|
||||
self.interface.configure_tenant_networks, task)
|
||||
self.assertEqual(2, update_mock.call_count)
|
||||
client_mock.return_value.close.assert_called_once()
|
||||
|
||||
@mock.patch.object(neutron_common, 'wait_for_host_agent', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'update_neutron_port', autospec=True)
|
||||
@mock.patch.object(neutron_common, 'wait_for_port_status', autospec=True)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes an issue where the ``neutron`` network interface could attach
|
||||
only some of the tenant VIFs of a node. Every port or port group with
|
||||
a tenant VIF attached is now plugged when configuring tenant networks,
|
||||
and a failure to plug any one of them fails the operation. Ports that
|
||||
are members of a port group are no longer skipped, so a port group can
|
||||
be defined while its member ports are still plugged individually, and
|
||||
they are likewise unbound when tenant networks are unconfigured. See
|
||||
`bug 2169761 <https://bugs.launchpad.net/ironic/+bug/2169761>`_ for
|
||||
details.
|
||||
Reference in new issue
Block a user