From 7b8a2e0cd2773e15dfa03d0e015f6dc8fa76b3ee Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Wed, 10 Oct 2018 15:07:15 +0200 Subject: [PATCH] cloud: rename with deprecation validate_node -> validate_machine Most of other cloud methods call nodes "machines". The new call also has an ability to only validate the power interface. Change-Id: I35f0521a57342dc888c00790935f20de230d6de5 --- openstack/cloud/openstackcloud.py | 20 +++++- .../tests/unit/cloud/test_baremetal_node.py | 69 ++++++++++++++++--- .../validate-machine-dcf528b8f587e3f0.yaml | 5 ++ 3 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/validate-machine-dcf528b8f587e3f0.yaml diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 37f6494e5..dbe704df9 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -9941,9 +9941,25 @@ class OpenStackCloud(_normalize.Normalizer): vif_ids = self.baremetal.list_node_vifs(machine) return [self.get_port(vif) for vif in vif_ids] + def validate_machine(self, name_or_id, for_deploy=True): + """Validate parameters of the machine. + + :param string name_or_id: The Name or UUID value representing the + baremetal node. + :param bool for_deploy: If ``True``, validate readiness for deployment, + otherwise validate only the power management + properties. + :raises: :exc:`~openstack.exceptions.ValidationException` + """ + if for_deploy: + ifaces = ('boot', 'deploy', 'management', 'power') + else: + ifaces = ('power',) + self.baremetal.validate_node(name_or_id, required=ifaces) + def validate_node(self, uuid): - # TODO(dtantsur): deprecate this short method in favor of a fully - # written validate_machine call. + warnings.warn('validate_node is deprecated, please use ' + 'validate_machine instead', DeprecationWarning) self.baremetal.validate_node(uuid) def node_set_provision_state(self, diff --git a/openstack/tests/unit/cloud/test_baremetal_node.py b/openstack/tests/unit/cloud/test_baremetal_node.py index a89ed5c45..46b427b38 100644 --- a/openstack/tests/unit/cloud/test_baremetal_node.py +++ b/openstack/tests/unit/cloud/test_baremetal_node.py @@ -92,13 +92,64 @@ class TestBaremetalNode(base.IronicTestCase): self.fake_baremetal_node['uuid']) self.assert_calls() - def test_validate_node(self): + def test_validate_machine(self): # NOTE(TheJulia): Note: These are only the interfaces - # that are validated, and both must be true for an + # that are validated, and all must be true for an # exception to not be raised. - # This should be fixed at some point, as some interfaces - # are important in some cases and should be validated, - # such as storage. + validate_return = { + 'boot': { + 'result': True, + }, + 'deploy': { + 'result': True, + }, + 'management': { + 'result': True, + }, + 'power': { + 'result': True, + }, + 'foo': { + 'result': False, + }} + self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + resource='nodes', + append=[self.fake_baremetal_node['uuid'], + 'validate']), + json=validate_return), + ]) + self.cloud.validate_machine(self.fake_baremetal_node['uuid']) + + self.assert_calls() + + def test_validate_machine_not_for_deploy(self): + validate_return = { + 'deploy': { + 'result': False, + 'reason': 'Not ready', + }, + 'power': { + 'result': True, + }, + 'foo': { + 'result': False, + }} + self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + resource='nodes', + append=[self.fake_baremetal_node['uuid'], + 'validate']), + json=validate_return), + ]) + self.cloud.validate_machine(self.fake_baremetal_node['uuid'], + for_deploy=False) + + self.assert_calls() + + def test_deprecated_validate_node(self): validate_return = { 'deploy': { 'result': True, @@ -121,15 +172,15 @@ class TestBaremetalNode(base.IronicTestCase): self.assert_calls() - def test_validate_node_raises_exception(self): + def test_validate_machine_raises_exception(self): validate_return = { 'deploy': { 'result': False, 'reason': 'error!', }, 'power': { - 'result': False, - 'reason': 'meow!', + 'result': True, + 'reason': None, }, 'foo': { 'result': True @@ -144,7 +195,7 @@ class TestBaremetalNode(base.IronicTestCase): ]) self.assertRaises( exceptions.ValidationException, - self.cloud.validate_node, + self.cloud.validate_machine, self.fake_baremetal_node['uuid']) self.assert_calls() diff --git a/releasenotes/notes/validate-machine-dcf528b8f587e3f0.yaml b/releasenotes/notes/validate-machine-dcf528b8f587e3f0.yaml new file mode 100644 index 000000000..0f73ae8d3 --- /dev/null +++ b/releasenotes/notes/validate-machine-dcf528b8f587e3f0.yaml @@ -0,0 +1,5 @@ +--- +deprecations: + - | + The ``OpenStackCloud.validate_node`` call was deprecated in favor of + ``OpenStackCloud.validate_machine``.