From 967da6836ec403fff4e88e99f44e659b446ac2c1 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 24 Mar 2020 21:28:49 +0000 Subject: [PATCH] Fix population of username, public keys The expand function was failing to add the username and public keys to the instances list. This change treats these arguments like other defaults, and adds tests to confirm they're ending up in the instances list. This change also has a minor fix to the unprovision prompt validation logic. Change-Id: I603623511e4061e782a65d53a3118d211ea6e708 --- .../module_utils/baremetal_deploy.py | 10 ++++---- .../cli-overcloud-node-unprovision.yaml | 4 ++-- .../module_utils/test_baremetal_deploy.py | 23 ++++++++++++++----- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py index 28f530dcc..1d93200bb 100644 --- a/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py +++ b/tripleo_ansible/ansible_plugins/module_utils/baremetal_deploy.py @@ -130,6 +130,11 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None, role['defaults'].setdefault('image', default_image) if default_network: role['defaults'].setdefault('nics', default_network) + if ssh_public_keys: + role['defaults'].setdefault('ssh_public_keys', ssh_public_keys) + if user_name: + role['defaults'].setdefault('user_name', user_name) + for inst in role.get('instances', []): for k, v in role['defaults'].items(): inst.setdefault(k, v) @@ -170,11 +175,6 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None, if inst.get('hostname') in potential_gen_names: hostname_map[inst['hostname']] = inst['hostname'] - if ssh_public_keys: - inst['ssh_public_keys'] = ssh_public_keys - if user_name: - inst['user_name'] = user_name - role_instances.append(inst) # add generated instance entries until the desired count of diff --git a/tripleo_ansible/playbooks/cli-overcloud-node-unprovision.yaml b/tripleo_ansible/playbooks/cli-overcloud-node-unprovision.yaml index 951d7ee77..c9d9006cb 100644 --- a/tripleo_ansible/playbooks/cli-overcloud-node-unprovision.yaml +++ b/tripleo_ansible/playbooks/cli-overcloud-node-unprovision.yaml @@ -36,8 +36,8 @@ msg: unprovision_confirm or unprovision_environment is required when prompt is true when: - prompt - - unprovision_confirm is undefined or - unprovision_environment is undefined + - unprovision_confirm is undefined + - unprovision_environment is undefined tasks: 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 f6fea1198..037ed307c 100644 --- a/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py +++ b/tripleo_ansible/tests/plugins/module_utils/test_baremetal_deploy.py @@ -143,20 +143,31 @@ class TestExpandRoles(base.TestCase): 'hostname_format': 'controller-%index%.example.com' }] instances, environment = bd.expand( - roles, 'overcloud', True, self.default_image + roles, 'overcloud', True, self.default_image, + user_name='heat-admin', ssh_public_keys='aaaa' ) self.assertEqual( [ {'hostname': 'compute-0.example.com', 'profile': 'compute', - 'image': {'href': 'overcloud-full'}}, + 'image': {'href': 'overcloud-full'}, + 'ssh_public_keys': 'aaaa', + 'user_name': 'heat-admin'}, {'hostname': 'compute-1.example.com', 'profile': 'compute', - 'image': {'href': 'overcloud-full'}}, + 'image': {'href': 'overcloud-full'}, + 'ssh_public_keys': 'aaaa', + 'user_name': 'heat-admin'}, {'hostname': 'controller-0.example.com', 'profile': 'control', - 'image': {'href': 'overcloud-full'}}, + 'image': {'href': 'overcloud-full'}, + 'ssh_public_keys': 'aaaa', + 'user_name': 'heat-admin'}, {'hostname': 'controller-1.example.com', 'profile': 'control', - 'image': {'href': 'overcloud-full'}}, + 'image': {'href': 'overcloud-full'}, + 'ssh_public_keys': 'aaaa', + 'user_name': 'heat-admin'}, {'hostname': 'controller-2.example.com', 'profile': 'control', - 'image': {'href': 'overcloud-full'}}, + 'image': {'href': 'overcloud-full'}, + 'ssh_public_keys': 'aaaa', + 'user_name': 'heat-admin'}, ], instances) self.assertEqual(