metalsmith_instances module, unprovision by hostname

The node lookup for unprovision first attempts the allocation name
(hostname)[1] but the metalsmith_instances unprovision passes the node
name.

This means in cases where the node naming scheme and the allocation
naming scheme are the same, the wrong node may be unprovisioned.

This change switches to passing the hostname for unprovision, only
passing the node name if the hostname is missing from the instances
entry.

[1] https://opendev.org/openstack/metalsmith/src/branch/master/metalsmith/_provisioner.py#L653

Change-Id: Ie6b989f8d67c03606be37310777175cfb8d9303e
Resolves: rhbz#2092444
This commit is contained in:
Steve Baker 2022-06-20 09:52:44 +12:00
parent e6568a02bd
commit 5459c30ed4
2 changed files with 23 additions and 1 deletions

View File

@ -260,3 +260,24 @@ class TestMetalsmithInstances(unittest.TestCase):
mock.call(1),
mock.call(2)
])
@mock.patch('metalsmith.sources.detect', autospec=True)
@mock.patch('metalsmith.instance_config.CloudInitConfig', autospec=True)
def test_unprovision(self, mock_config, mock_detect):
provisioner = mock.Mock()
instances = [{
'name': 'node-1',
'hostname': 'overcloud-controller-1',
'image': {'href': 'overcloud-full'},
'state': 'absent'
}, {
'name': 'node-2',
'image': {'href': 'overcloud-full'},
'state': 'absent'
}]
self.assertTrue(mi.unprovision(provisioner, instances))
provisioner.unprovision_node.assert_has_calls([
mock.call('overcloud-controller-1'),
mock.call('node-2')
])

View File

@ -375,7 +375,8 @@ def _provision_instance(provisioner, instance, nodes, timeout, wait):
def unprovision(provisioner, instances):
for instance in instances:
provisioner.unprovision_node(instance.get('name'))
provisioner.unprovision_node(instance.get('hostname',
instance.get('name')))
return True