Consistent normalization of Machine objects in the cloud layer
Currently some functions call node._to_munch, some - _normalize_machine, some both. When only _normalize_machine is used, the machine's fields are not normalized to their server-side representation, breaking the os_ironic ansible module expecting node['uuid']. This change makes _normalize_machine call _to_munch to ensure that normalization always happens. All cloud calls are changed to use _normalize_machine and not _to_munch. Change-Id: Ic431f1340c017a24eafe07832da6e6c579fb1921
This commit is contained in:
parent
a0e68c318f
commit
5db3323be1
@ -68,7 +68,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||
|
||||
:returns: list of ``munch.Munch`` representing machines.
|
||||
"""
|
||||
return [self._normalize_machine(node._to_munch())
|
||||
return [self._normalize_machine(node)
|
||||
for node in self.baremetal.nodes()]
|
||||
|
||||
def get_machine(self, name_or_id):
|
||||
@ -83,8 +83,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||
nodes are found.
|
||||
"""
|
||||
try:
|
||||
return self._normalize_machine(
|
||||
self.baremetal.get_node(name_or_id)._to_munch())
|
||||
return self._normalize_machine(self.baremetal.get_node(name_or_id))
|
||||
except exc.OpenStackCloudResourceNotFound:
|
||||
return None
|
||||
|
||||
@ -159,7 +158,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||
wait=True,
|
||||
timeout=timeout)
|
||||
|
||||
return node._to_munch()
|
||||
return self._normalize_machine(node)
|
||||
|
||||
def register_machine(self, nics, wait=False, timeout=3600,
|
||||
lock_timeout=600, **kwargs):
|
||||
@ -477,7 +476,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||
change_list = [change['path'] for change in patch]
|
||||
node = self.baremetal.update_node(machine, **attrs)
|
||||
return dict(
|
||||
node=self._normalize_machine(node._to_munch()),
|
||||
node=self._normalize_machine(node),
|
||||
changes=change_list
|
||||
)
|
||||
|
||||
@ -573,7 +572,7 @@ class BaremetalCloudMixin(_normalize.Normalizer):
|
||||
node = self.baremetal.set_node_provision_state(
|
||||
name_or_id, target=state, config_drive=configdrive,
|
||||
wait=wait, timeout=timeout)
|
||||
return node._to_munch()
|
||||
return self._normalize_machine(node)
|
||||
|
||||
def set_machine_maintenance_state(
|
||||
self,
|
||||
|
@ -1172,13 +1172,14 @@ class Normalizer(object):
|
||||
|
||||
def _normalize_machine(self, machine):
|
||||
"""Normalize Ironic Machine"""
|
||||
if isinstance(machine, resource.Resource):
|
||||
machine = machine._to_munch()
|
||||
else:
|
||||
machine = machine.copy()
|
||||
|
||||
# Discard noise
|
||||
self._remove_novaclient_artifacts(machine)
|
||||
|
||||
# TODO(mordred) Normalize this resource
|
||||
|
||||
return machine
|
||||
|
||||
def _normalize_roles(self, roles):
|
||||
|
@ -213,8 +213,9 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||
json=self.fake_baremetal_node,
|
||||
validate=dict(json=test_patch)),
|
||||
])
|
||||
self.cloud.patch_machine(
|
||||
result = self.cloud.patch_machine(
|
||||
self.fake_baremetal_node['uuid'], test_patch)
|
||||
self.assertEqual(self.fake_baremetal_node['uuid'], result['uuid'])
|
||||
|
||||
self.assert_calls()
|
||||
|
||||
@ -759,10 +760,11 @@ class TestBaremetalNode(base.IronicTestCase):
|
||||
append=[self.fake_baremetal_node['uuid']]),
|
||||
json=self.fake_baremetal_node),
|
||||
])
|
||||
self.cloud.node_set_provision_state(
|
||||
result = self.cloud.node_set_provision_state(
|
||||
self.fake_baremetal_node['uuid'],
|
||||
'active',
|
||||
configdrive='http://host/file')
|
||||
self.assertEqual(self.fake_baremetal_node['uuid'], result['uuid'])
|
||||
|
||||
self.assert_calls()
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes normalization of bare metal machines in the ``patch_machine`` call.
|
Loading…
Reference in New Issue
Block a user