From e35054cbfb0c9dc2c29a87d7491182cb1225e2a8 Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Fri, 14 Apr 2017 16:02:29 +0300 Subject: [PATCH] Always set host_id when adding neutron ports Previously we didn't update host_id for 'flat' network_interface as we had regression in Neutron which was already fixed. This patch updates add_ports_to_network() method to always set binding:host_id when create neutron ports. Change-Id: I421182494b22b579f55e684c920b72e2168984c7 --- ironic/common/neutron.py | 8 +-- ironic/tests/unit/common/test_neutron.py | 68 ++++-------------------- 2 files changed, 12 insertions(+), 64 deletions(-) diff --git a/ironic/common/neutron.py b/ironic/common/neutron.py index a9918dcb4d..c974d019ce 100644 --- a/ironic/common/neutron.py +++ b/ironic/common/neutron.py @@ -193,18 +193,12 @@ def add_ports_to_network(task, network_uuid, security_groups=None): 'admin_state_up': True, 'binding:vnic_type': 'baremetal', 'device_owner': 'baremetal:none', + 'binding:host_id': node.uuid, } } if security_groups: body['port']['security_groups'] = security_groups - if node.network_interface != 'flat': - # NOTE(vdrok): It seems that change - # I437290affd8eb87177d0626bf7935a165859cbdd to neutron broke the - # possibility to always bind port. Set binding:host_id only in - # case of non flat network. - body['port']['binding:host_id'] = node.uuid - # Since instance_uuid will not be available during cleaning # operations, we need to check that and populate them only when # available diff --git a/ironic/tests/unit/common/test_neutron.py b/ironic/tests/unit/common/test_neutron.py index e1d46fb9fd..c956b3e78a 100644 --- a/ironic/tests/unit/common/test_neutron.py +++ b/ironic/tests/unit/common/test_neutron.py @@ -135,8 +135,8 @@ class TestNeutronNetworkActions(db_base.DbTestCase): patcher.start() self.addCleanup(patcher.stop) - def _test_add_ports_to_vlan_network(self, is_client_id, - security_groups=None): + def _test_add_ports_to_network(self, is_client_id, + security_groups=None): # Ports will be created only if pxe_enabled is True self.node.network_interface = 'neutron' self.node.save() @@ -183,17 +183,17 @@ class TestNeutronNetworkActions(db_base.DbTestCase): self.client_mock.create_port.assert_called_once_with( expected_body) - def test_add_ports_to_vlan_network(self): - self._test_add_ports_to_vlan_network(is_client_id=False, - security_groups=None) + def test_add_ports_to_network(self): + self._test_add_ports_to_network(is_client_id=False, + security_groups=None) @mock.patch.object(neutron, '_verify_security_groups') - def test_add_ports_to_vlan_network_with_sg(self, verify_mock): + def test_add_ports_to_network_with_sg(self, verify_mock): sg_ids = [] for i in range(2): sg_ids.append(uuidutils.generate_uuid()) - self._test_add_ports_to_vlan_network(is_client_id=False, - security_groups=sg_ids) + self._test_add_ports_to_network(is_client_id=False, + security_groups=sg_ids) def test_verify_sec_groups(self): sg_ids = [] @@ -269,57 +269,11 @@ class TestNeutronNetworkActions(db_base.DbTestCase): neutron._verify_security_groups, sg_ids, client) client.list_security_groups.assert_called_once_with() - def test_add_ports_with_client_id_to_vlan_network(self): - self._test_add_ports_to_vlan_network(is_client_id=True) - - def _test_add_ports_to_flat_network(self, is_client_id): - self.node.network_interface = 'flat' - self.node.save() - port = self.ports[0] - if is_client_id: - extra = port.extra - extra['client-id'] = self._CLIENT_ID - port.extra = extra - port.save() - expected_body = { - 'port': { - 'network_id': self.network_uuid, - 'admin_state_up': True, - 'binding:vnic_type': 'baremetal', - 'device_owner': 'baremetal:none', - 'device_id': self.node.uuid, - 'mac_address': port.address, - 'binding:profile': { - 'local_link_information': [port.local_link_connection] - } - } - } - if is_client_id: - expected_body['port']['extra_dhcp_opts'] = ( - [{'opt_name': 'client-id', 'opt_value': self._CLIENT_ID}]) - # Ensure we can create ports - self.client_mock.create_port.return_value = { - 'port': self.neutron_port} - expected = {port.uuid: self.neutron_port['id']} - with task_manager.acquire(self.context, self.node.uuid) as task: - ports = neutron.add_ports_to_network(task, self.network_uuid) - self.assertEqual(expected, ports) - self.client_mock.create_port.assert_called_once_with( - expected_body) - - @mock.patch.object(neutron, 'validate_port_info', autospec=True, - return_value=True) - def test_add_ports_to_flat_network(self, vpi_mock): - self._test_add_ports_to_flat_network(is_client_id=False) - self.assertTrue(vpi_mock.called) - - @mock.patch.object(neutron, 'validate_port_info', autospec=True, - return_value=True) - def test_add_ports_with_client_id_to_flat_network(self, vpi_mock): - self._test_add_ports_to_flat_network(is_client_id=True) + def test_add_ports_with_client_id_to_network(self): + self._test_add_ports_to_network(is_client_id=True) @mock.patch.object(neutron, 'validate_port_info', autospec=True) - def test_add_ports_to_vlan_network_instance_uuid(self, vpi_mock): + def test_add_ports_to_network_instance_uuid(self, vpi_mock): self.node.instance_uuid = uuidutils.generate_uuid() self.node.network_interface = 'neutron' self.node.save()