From 9a09036197a7547121e0d2625491e83e9802eb2b Mon Sep 17 00:00:00 2001 From: James Slagle Date: Thu, 22 Apr 2021 08:11:09 -0400 Subject: [PATCH] Don't assume Ironic is installed During "overcloud node provision", pre-provisioned nodes can be specified with managed:false, in which case the node provision is just a data transformation process to prepare the inputs for Heat. The ansible modules should not assume that Ironic is installed in this case, as the enable_ironic option has existed for many releases already. Signed-off-by: James Slagle Depends-On: I3657169a3b519869f7f3594c8c6a6072a058e0c8 Change-Id: I2bc8f3d8090b2753f636832600d3bd51424ba7e7 --- .../module_utils/baremetal_deploy.py | 11 +++++++++-- .../modules/tripleo_baremetal_check_existing.py | 12 ++++++++++-- .../plugins/module_utils/test_baremetal_deploy.py | 13 +++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py index fb92ee370..3bedbabdb 100644 --- a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py +++ b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py @@ -406,11 +406,18 @@ def check_existing(instances, provisioner, baremetal): found = [] unmanaged = [] for request in instances: + + ident = request.get('name', request['hostname']) + if not request.get('managed', True): unmanaged.append(request) continue - - ident = request.get('name', request['hostname']) + elif not baremetal: + message = ('Instance %s is not specified as pre-provisioned ' + '(managed: False), and no connection to ' + 'the baremetal service was provided.' + % ident) + raise BaremetalDeployException(message) try: instance = provisioner.show_instance(ident) diff --git a/tripleo_ansible/ansible_plugins/modules/tripleo_baremetal_check_existing.py b/tripleo_ansible/ansible_plugins/modules/tripleo_baremetal_check_existing.py index e64f6939e..ba4e6fd89 100644 --- a/tripleo_ansible/ansible_plugins/modules/tripleo_baremetal_check_existing.py +++ b/tripleo_ansible/ansible_plugins/modules/tripleo_baremetal_check_existing.py @@ -21,6 +21,7 @@ from ansible.module_utils.openstack import openstack_cloud_from_module from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_module_kwargs +import keystoneauth1 import metalsmith import yaml @@ -114,12 +115,19 @@ def main(): provisioner = metalsmith.Provisioner(cloud_region=cloud.config) try: + msg = '' + + try: + baremetal = cloud.baremetal + except keystoneauth1.exceptions.catalog.EndpointNotFound as exc: + msg += str(exc) + baremetal = None + found, not_found, pre_provisioned = bd.check_existing( instances=module.params['instances'], provisioner=provisioner, - baremetal=cloud.baremetal + baremetal=baremetal ) - msg = '' if found: msg += ('Found existing instances: %s. ' % ', '.join([i.uuid for i in found])) 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 92085ed53..87a54fcfa 100644 --- a/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py +++ b/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py @@ -1109,6 +1109,19 @@ class TestCheckExistingInstances(base.TestCase): self.assertIn("hostname host1 was not found", str(exc)) pr.show_instance.assert_called_once_with('host1') + def test_check_existing_no_ironic(self): + pr = mock.Mock() + instances = [ + {'hostname': 'host1', + 'image': {'href': 'overcloud-full'}}, + ] + exc = self.assertRaises( + bd.BaremetalDeployException, bd.check_existing, + instances, pr, None) + + self.assertIn( + "Instance host1 is not specified as pre-provisioned", str(exc)) + def test_unexpected_error(self): pr = mock.Mock() instances = [