Merge "Add proper return value for validate_node"

This commit is contained in:
Zuul 2018-03-08 23:09:15 +00:00 committed by Gerrit Code Review
commit d1451d022a
2 changed files with 54 additions and 42 deletions

View File

@ -9384,20 +9384,33 @@ class OpenStackCloud(
)
def validate_node(self, uuid):
# TODO(TheJulia): There are soooooo many other interfaces
# that we can support validating, while these are essential,
# we should support more.
# TODO(TheJulia): Add a doc string :(
"""Returns node validation information
:param string uuid: A UUID value representing the baremetal node.
:raises: OpenStackCloudException on operation error or
if deploy and power informations are not present.
:returns: dict containing validation information for each
interface: boot, console, deploy, inspect, management,
network, power, raid, rescue, storage, ...
"""
msg = ("Failed to query the API for validation status of "
"node {node_id}").format(node_id=uuid)
url = '/nodes/{node_id}/validate'.format(node_id=uuid)
ifaces = self._baremetal_client.get(url, error_message=msg)
if not ifaces['deploy'] or not ifaces['power']:
validate_resp = self._baremetal_client.get(url, error_message=msg)
is_deploy_valid = validate_resp.get(
'deploy', {'result': False}).get('result', False)
is_power_valid = validate_resp.get(
'power', {'result': False}).get('result', False)
if not is_deploy_valid or not is_power_valid:
raise OpenStackCloudException(
"ironic node %s failed to validate. "
"(deploy: %s, power: %s)" % (ifaces['deploy'],
ifaces['power']))
"ironic node {} failed to validate. "
"(deploy: {}, power: {})".format(
uuid,
validate_resp.get('deploy'),
validate_resp.get('power')))
return validate_resp
def node_set_provision_state(self,
name_or_id,

View File

@ -115,40 +115,39 @@ class TestBaremetalNode(base.IronicTestCase):
'validate']),
json=validate_return),
])
self.op_cloud.validate_node(self.fake_baremetal_node['uuid'])
validate_resp = self.op_cloud.validate_node(
self.fake_baremetal_node['uuid'])
self.assertDictEqual(validate_return, validate_resp)
self.assert_calls()
# FIXME(TheJulia): So, this doesn't presently fail, but should fail.
# Placing the test here, so we can sort out the issue in the actual
# method later.
# def test_validate_node_raises_exception(self):
# validate_return = {
# 'deploy': {
# 'result': False,
# 'reason': 'error!',
# },
# 'power': {
# 'result': False,
# 'reason': 'meow!',
# },
# 'foo': {
# 'result': True
# }}
# self.register_uris([
# dict(method='GET',
# uri=self.get_mock_url(
# resource='nodes',
# append=[self.fake_baremetal_node['uuid'],
# 'validate']),
# json=validate_return),
# ])
# self.assertRaises(
# Exception,
# self.op_cloud.validate_node,
# self.fake_baremetal_node['uuid'])
#
# self.assert_calls()
def test_validate_node_raises_exception(self):
validate_return = {
'deploy': {
'result': False,
'reason': 'error!',
},
'power': {
'result': False,
'reason': 'meow!',
},
'foo': {
'result': True
}}
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
resource='nodes',
append=[self.fake_baremetal_node['uuid'],
'validate']),
json=validate_return),
])
self.assertRaisesRegexp(
exc.OpenStackCloudException,
'^ironic node .* failed to validate.*',
self.op_cloud.validate_node,
self.fake_baremetal_node['uuid'])
self.assert_calls()
def test_patch_machine(self):
test_patch = [{