Merge "Prevents deletion of ports for active nodes"
This commit is contained in:
commit
64e21b9a4e
ironic
releasenotes/notes
@ -2166,7 +2166,8 @@ class ConductorManager(base_manager.BaseConductorManager):
|
|||||||
|
|
||||||
@METRICS.timer('ConductorManager.destroy_port')
|
@METRICS.timer('ConductorManager.destroy_port')
|
||||||
@messaging.expected_exceptions(exception.NodeLocked,
|
@messaging.expected_exceptions(exception.NodeLocked,
|
||||||
exception.NodeNotFound)
|
exception.NodeNotFound,
|
||||||
|
exception.InvalidState)
|
||||||
def destroy_port(self, context, port):
|
def destroy_port(self, context, port):
|
||||||
"""Delete a port.
|
"""Delete a port.
|
||||||
|
|
||||||
@ -2181,6 +2182,14 @@ class ConductorManager(base_manager.BaseConductorManager):
|
|||||||
{'port': port.uuid})
|
{'port': port.uuid})
|
||||||
with task_manager.acquire(context, port.node_id,
|
with task_manager.acquire(context, port.node_id,
|
||||||
purpose='port deletion') as task:
|
purpose='port deletion') as task:
|
||||||
|
node = task.node
|
||||||
|
if ((node.provision_state == states.ACTIVE or node.instance_uuid)
|
||||||
|
and not node.maintenance):
|
||||||
|
msg = _("Cannot delete the port %(port)s as node "
|
||||||
|
"%(node)s is active or has "
|
||||||
|
"instance UUID assigned")
|
||||||
|
raise exception.InvalidState(msg % {'node': node.uuid,
|
||||||
|
'port': port.uuid})
|
||||||
port.destroy()
|
port.destroy()
|
||||||
LOG.info('Successfully deleted port %(port)s. '
|
LOG.info('Successfully deleted port %(port)s. '
|
||||||
'The node associated with the port was %(node)s',
|
'The node associated with the port was %(node)s',
|
||||||
|
@ -7418,6 +7418,45 @@ class DestroyPortTestCase(mgr_utils.ServiceSetUpMixin, db_base.DbTestCase):
|
|||||||
# Compare true exception hidden by @messaging.expected_exceptions
|
# Compare true exception hidden by @messaging.expected_exceptions
|
||||||
self.assertEqual(exception.NodeLocked, exc.exc_info[0])
|
self.assertEqual(exception.NodeLocked, exc.exc_info[0])
|
||||||
|
|
||||||
|
def test_destroy_port_node_active_state(self):
|
||||||
|
instance_uuid = uuidutils.generate_uuid()
|
||||||
|
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
|
||||||
|
instance_uuid=instance_uuid,
|
||||||
|
provision_state='active')
|
||||||
|
port = obj_utils.create_test_port(self.context,
|
||||||
|
node_id=node.id,
|
||||||
|
extra={'vif_port_id': 'fake-id'})
|
||||||
|
exc = self.assertRaises(messaging.rpc.ExpectedException,
|
||||||
|
self.service.destroy_port,
|
||||||
|
self.context, port)
|
||||||
|
self.assertEqual(exception.InvalidState, exc.exc_info[0])
|
||||||
|
|
||||||
|
def test_destroy_port_node_active_and_maintenance(self):
|
||||||
|
instance_uuid = uuidutils.generate_uuid()
|
||||||
|
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
|
||||||
|
instance_uuid=instance_uuid,
|
||||||
|
provision_state='active',
|
||||||
|
maintenance=True)
|
||||||
|
port = obj_utils.create_test_port(self.context,
|
||||||
|
node_id=node.id,
|
||||||
|
extra={'vif_port_id': 'fake-id'})
|
||||||
|
self.service.destroy_port(self.context, port)
|
||||||
|
self.assertRaises(exception.PortNotFound,
|
||||||
|
self.dbapi.get_port_by_uuid,
|
||||||
|
port.uuid)
|
||||||
|
|
||||||
|
def test_destroy_port_with_instance_not_in_active(self):
|
||||||
|
instance_uuid = uuidutils.generate_uuid()
|
||||||
|
node = obj_utils.create_test_node(self.context, driver='fake-hardware',
|
||||||
|
instance_uuid=instance_uuid,
|
||||||
|
provision_state='deploy failed')
|
||||||
|
port = obj_utils.create_test_port(self.context,
|
||||||
|
node_id=node.id)
|
||||||
|
exc = self.assertRaises(messaging.rpc.ExpectedException,
|
||||||
|
self.service.destroy_port,
|
||||||
|
self.context, port)
|
||||||
|
self.assertEqual(exception.InvalidState, exc.exc_info[0])
|
||||||
|
|
||||||
|
|
||||||
@mgr_utils.mock_record_keepalive
|
@mgr_utils.mock_record_keepalive
|
||||||
class DestroyPortgroupTestCase(mgr_utils.ServiceSetUpMixin,
|
class DestroyPortgroupTestCase(mgr_utils.ServiceSetUpMixin,
|
||||||
|
5
releasenotes/notes/port_delete-6628b736a1b556f6.yaml
Normal file
5
releasenotes/notes/port_delete-6628b736a1b556f6.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Prevents deletion of ports for active nodes. It is still possible to
|
||||||
|
delete them after putting the node in the maintenance mode.
|
Loading…
x
Reference in New Issue
Block a user