summaryrefslogtreecommitdiff
path: root/ironic/conductor
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-06-18 11:50:29 +0000
committerGerrit Code Review <review@openstack.org>2020-06-18 11:50:29 +0000
commit5822b2fb7d2c7a08dd29580a9ef80bb86d601992 (patch)
treeaad3e89883b13ce33c0b657bb21f510096af9c80 /ironic/conductor
parentaea1c76c3bf9b4e1288e11c8c31c272526abb0a6 (diff)
parent64674bf0ed966c3e8f241d555b772f03e7407951 (diff)
downloadironic-5822b2fb7d2c7a08dd29580a9ef80bb86d601992.tar.gz
Merge "Block port deletions where vif is present"
Diffstat (limited to 'ironic/conductor')
-rw-r--r--ironic/conductor/manager.py20
-rw-r--r--ironic/conductor/utils.py27
2 files changed, 36 insertions, 11 deletions
diff --git a/ironic/conductor/manager.py b/ironic/conductor/manager.py
index b96033641..b63d5412e 100644
--- a/ironic/conductor/manager.py
+++ b/ironic/conductor/manager.py
@@ -2052,23 +2052,21 @@ class ConductorManager(base_manager.BaseConductorManager):
:raises: NodeLocked if node is locked by another conductor.
:raises: NodeNotFound if the node associated with the port does not
exist.
+ :raises: InvalidState if a vif is still attached to the port.
"""
LOG.debug('RPC destroy_port called for port %(port)s',
{'port': port.uuid})
with task_manager.acquire(context, port.node_id,
purpose='port deletion') as task:
- node = task.node
- vif = task.driver.network.get_current_vif(task, port)
- if ((node.provision_state == states.ACTIVE or node.instance_uuid)
- and not node.maintenance and vif):
- msg = _("Cannot delete the port %(port)s as node "
- "%(node)s is active or has "
- "instance UUID assigned or port is bound "
- "to vif %(vif)s")
- raise exception.InvalidState(msg % {'node': node.uuid,
- 'port': port.uuid,
- 'vif': vif})
+ vif, vif_use = utils.get_attached_vif(port)
+ if vif:
+ msg = _("Cannot delete the port %(port)s as it is bound "
+ "to VIF %(vif)s for %(use)s use.")
+ raise exception.InvalidState(
+ msg % {'port': port.uuid,
+ 'vif': vif,
+ 'use': vif_use})
port.destroy()
LOG.info('Successfully deleted port %(port)s. '
'The node associated with the port was %(node)s',
diff --git a/ironic/conductor/utils.py b/ironic/conductor/utils.py
index 836409dad..35e2c94fc 100644
--- a/ironic/conductor/utils.py
+++ b/ironic/conductor/utils.py
@@ -1144,3 +1144,30 @@ def hash_password(password=''):
:param value: Value to be hashed
"""
return crypt.crypt(password, make_salt())
+
+
+def get_attached_vif(port):
+ """Get any attached vif ID for the port
+
+ :param port: The port object upon which to check for a vif
+ record.
+ :returns: Returns a tuple of the vif if found and the use of
+ the vif in the form of a string, 'tenant', 'cleaning'
+ 'provisioning', 'rescuing'.
+ :raises: InvalidState exception upon finding a port with a
+ transient state vif on the port.
+ """
+
+ tenant_vif = port.internal_info.get('tenant_vif_port_id')
+ if tenant_vif:
+ return (tenant_vif, 'tenant')
+ clean_vif = port.internal_info.get('cleaning_vif_port_id')
+ if clean_vif:
+ return (clean_vif, 'cleaning')
+ prov_vif = port.internal_info.get('provisioning_vif_port_id')
+ if prov_vif:
+ return (prov_vif, 'provisioning')
+ rescue_vif = port.internal_info.get('rescuing_vif_port_id')
+ if rescue_vif:
+ return (rescue_vif, 'rescuing')
+ return (None, None)