Fix updating port.portgroup_uuid for node

Port RPC object doesn't have portgroup_uuid attribute. As result it was
allowed to update portgroup_uuid when node is in ACTIVE/DEPLOYING and other
blocked for updates states.
This patch uses portgroup_id as it is a valid value for RPC object.

Change-Id: I3e849e78dfde9d21fc511cf92270aa7436a535ee
This commit is contained in:
Vasyl Saienko 2016-09-01 09:48:59 +03:00
parent a828e752da
commit 9b649323d1
2 changed files with 39 additions and 1 deletions

View File

@ -1694,7 +1694,7 @@ class ConductorManager(base_manager.BaseConductorManager):
# node should be in MANAGEABLE/INSPECTING/ENROLL provisioning state
# or in maintenance mode.
# Otherwise InvalidState exception is raised.
connectivity_attr = {'portgroup_uuid',
connectivity_attr = {'portgroup_id',
'pxe_enabled',
'local_link_connection'}
allowed_update_states = [states.ENROLL,

View File

@ -2806,6 +2806,44 @@ class UpdatePortTestCase(mgr_utils.ServiceSetUpMixin,
mac_update_mock.assert_called_once_with('fake-id', new_address,
token=self.context.auth_token)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.update_port_address')
def test_update_port_portgroup_active_node(self, mac_update_mock):
node = obj_utils.create_test_node(self.context, driver='fake',
instance_uuid=None,
provision_state='active')
pg1 = obj_utils.create_test_portgroup(self.context, node_id=node.id)
pg2 = obj_utils.create_test_portgroup(
self.context, node_id=node.id, name='bar',
address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid())
port = obj_utils.create_test_port(self.context,
node_id=node.id,
portgroup_id=pg1.id)
port.portgroup_id = pg2.id
exc = self.assertRaises(messaging.rpc.ExpectedException,
self.service.update_port,
self.context, port)
# Compare true exception hidden by @messaging.expected_exceptions
self.assertEqual(exception.InvalidState, exc.exc_info[0])
port.refresh()
self.assertEqual(pg1.id, port.portgroup_id)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.update_port_address')
def test_update_port_portgroup_enroll_node(self, mac_update_mock):
node = obj_utils.create_test_node(self.context, driver='fake',
instance_uuid=None,
provision_state='enroll')
pg1 = obj_utils.create_test_portgroup(self.context, node_id=node.id)
pg2 = obj_utils.create_test_portgroup(
self.context, node_id=node.id, name='bar',
address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid())
port = obj_utils.create_test_port(self.context,
node_id=node.id,
portgroup_id=pg1.id)
port.portgroup_id = pg2.id
self.service.update_port(self.context, port)
port.refresh()
self.assertEqual(pg2.id, port.portgroup_id)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.update_port_dhcp_opts')
def test_update_port_client_id(self, dhcp_update_mock):
node = obj_utils.create_test_node(self.context, driver='fake')