Dettaching instance_uuid for standalone TC's
For standalone test cases, where delete_node is set as False,
the instance_uuid remains attached with the node even after test
case execution.
This affects the serial execution of tempest test cases as
instance_uuid is already associated to node which results in
failure of consecutive test cases.
This dettaches instance_uuid of a node while cleanup.
Change-Id: I854c533ef4f76f3abb589dbcc9c39358ebedc194
diff --git a/ironic_tempest_plugin/tests/scenario/baremetal_standalone_manager.py b/ironic_tempest_plugin/tests/scenario/baremetal_standalone_manager.py
index 176f912..32fd5c2 100644
--- a/ironic_tempest_plugin/tests/scenario/baremetal_standalone_manager.py
+++ b/ironic_tempest_plugin/tests/scenario/baremetal_standalone_manager.py
@@ -123,6 +123,16 @@
return body
@classmethod
+ def _disassociate_instance_with_node(cls, node_id):
+ """Disassociate instance_uuid from attached node.
+
+ :param node_id: Name or UUID of the node.
+ """
+ cls.update_node(node_id, [{'op': 'replace',
+ 'path': '/instance_uuid',
+ 'value': None}])
+
+ @classmethod
def get_node_vifs(cls, node_id):
"""Return a list of VIFs for a given node.
@@ -231,6 +241,28 @@
return nodes[0]
@classmethod
+ def unreserve_node(cls, node):
+ """Unreserves node by disassociating instance_uuid attached to node.
+
+ :param node: Ironic node to disassociate instance_uuid from.
+ """
+
+ def _try_to_disassociate_instance():
+ _, node_prop = cls.baremetal_client.show_node(node['uuid'])
+ if node_prop['instance_uuid']:
+ try:
+ cls._disassociate_instance_with_node(node['uuid'])
+ except lib_exc.Conflict:
+ return False
+ return True
+ if (not test_utils.call_until_true(
+ _try_to_disassociate_instance,
+ duration=CONF.baremetal.association_timeout, sleep_for=1)):
+ msg = ('Timed out waiting to disassociate instance from '
+ 'ironic node uuid %s' % node['instance_uuid'])
+ raise lib_exc.TimeoutException(msg)
+
+ @classmethod
def boot_node(cls, image_ref=None, image_checksum=None,
boot_option=None):
"""Boot ironic node.
@@ -568,6 +600,7 @@
except lib_exc.NotFound:
pass
cls.terminate_node(cls.node['uuid'])
+ cls.unreserve_node(cls.node)
base.reset_baremetal_api_microversion()
super(BaremetalStandaloneManager, cls).resource_cleanup()