From f661f34c90b747772219f8a68a65128dafe871e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Tue, 25 May 2021 15:12:21 +0200 Subject: [PATCH] Refresh instance after adding allocation When the baremetal deployment workflow does the "Check Existing" task it will create a baremetal allocation for provisioned nodes that does not already hae one. After creating the allocation, refresh the instance to ensure the hostname is correctly represented in the object returned in the list of "found" nodes. Closes-Bug: #1929555 Change-Id: I0d43f42c0d0b092218f78b32ac3bfd198c988de0 --- .../ansible_plugins/module_utils/baremetal_deploy.py | 3 +++ .../tests/plugins/module_utils/test_baremetal_deploy.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py index 46f3a61e4..4057705d3 100644 --- a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py +++ b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py @@ -483,6 +483,9 @@ def check_existing(instances, provisioner, baremetal): node=request['name'] ) + # Refresh the instance after adding the allocation + # See: https://bugs.launchpad.net/tripleo/+bug/1929555 + instance = provisioner.show_instance(instance.uuid) found.append(instance) return found, not_found, unmanaged diff --git a/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py b/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py index 287628234..d97557b11 100644 --- a/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py +++ b/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py @@ -1094,7 +1094,8 @@ class TestCheckExistingInstances(base.TestCase): self.assertEqual([], not_found) self.assertEqual([existing], found) - pr.show_instance.assert_called_once_with('server2') + pr.show_instance.assert_has_calls([mock.call('server2'), + mock.call(existing.uuid)]) def test_hostname_mismatch(self): pr = mock.Mock() @@ -1136,7 +1137,9 @@ class TestCheckExistingInstances(base.TestCase): self.assertEqual([], not_found) self.assertEqual([existing], found) - pr.show_instance.assert_called_once_with('bm_node1') + self.assertEqual(2, pr.show_instance.call_count) + pr.show_instance.assert_has_calls([mock.call('bm_node1'), + mock.call(existing.uuid)]) def test_hostname_mismatch_and_instance_info_display_name_mismatch(self): pr = mock.Mock()