From 6a2fb44a78fdb45c95d9591ececbf6c6de89d64f Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Thu, 22 Nov 2018 16:50:08 +0000 Subject: [PATCH] Fix deploy and teardown without node enrolment If the ironic_config field is not present in a node definition, then that node should not be registered with ironic. In this case we also don't need to query glance for images or wait for resources to appear in placement. If nova_flavors is empty, we do not need to register flavors, so no need to install the client or check for OS_USERNAME. Also fixes an issue in the action plugin where it would fail if ironic_config field is not present in a node definition. Finally, in CI deploy/teardown tests, rather than skipping tasks, we now remove the ironic_config field from the node definition, and set nova_flavors to empty, such that we exercise these code paths. Change-Id: I29b42665f1609c99e80f12ab6f3815d0e0918dae Story: 2004412 Task: 28056 --- ansible/action_plugins/tenks_update_state.py | 5 +- ansible/flavor_registration.yml | 1 + ansible/node_enrolment.yml | 8 +-- ansible/node_networking.yml | 8 ++- ansible/resource_wait.yml | 61 ++++++++++--------- ansible/roles/ironic-enrolment/tasks/main.yml | 7 +++ playbooks/tenks-deploy-teardown/run.yml | 4 +- .../templates/tenks-overrides.yml.j2 | 7 +-- 8 files changed, 51 insertions(+), 50 deletions(-) diff --git a/ansible/action_plugins/tenks_update_state.py b/ansible/action_plugins/tenks_update_state.py index 2f2ef68..1846664 100644 --- a/ansible/action_plugins/tenks_update_state.py +++ b/ansible/action_plugins/tenks_update_state.py @@ -156,8 +156,9 @@ class ActionModule(ActionBase): # to count as an 'instance' of the spec. MATCHING_ATTRS = {'type', 'ironic_config'} for spec in specs: - if ((all(spec[attr] == node[attr] for attr in MATCHING_ATTRS) and - spec['count'] > 0)): + if (all(spec.get(attr) == node.get(attr) + for attr in MATCHING_ATTRS) + and spec['count'] > 0): spec['count'] -= 1 return True return False diff --git a/ansible/flavor_registration.yml b/ansible/flavor_registration.yml index 8ef4167..20ab397 100644 --- a/ansible/flavor_registration.yml +++ b/ansible/flavor_registration.yml @@ -10,3 +10,4 @@ {{ python_upper_constraints_url }} flavors: "{{ nova_flavors }}" flavors_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" + when: flavors | length > 0 diff --git a/ansible/node_enrolment.yml b/ansible/node_enrolment.yml index e5308a7..25fa641 100644 --- a/ansible/node_enrolment.yml +++ b/ansible/node_enrolment.yml @@ -5,13 +5,6 @@ file: "{{ state_file_path }}" name: tenks_state - - name: Check that OpenStack credentials exist in the environment - fail: - msg: > - $OS_USERNAME was not found in the environment. Ensure the OpenStack - credentials exist in your environment, perhaps by sourcing your RC file. - when: not lookup('env', 'OS_USERNAME') - - name: Perform Ironic enrolment for each hypervisor's nodes include_role: name: ironic-enrolment @@ -26,3 +19,4 @@ loop: "{{ query('dict', tenks_state) }}" loop_control: loop_var: alloc + when: ironic_nodes | selectattr('ironic_config', 'defined') | list | length > 0 diff --git a/ansible/node_networking.yml b/ansible/node_networking.yml index 7eafba3..81c6640 100644 --- a/ansible/node_networking.yml +++ b/ansible/node_networking.yml @@ -15,11 +15,13 @@ include_role: name: veth-pair vars: - veth_pair_ovs_bridge: "{{ item.1 | bridge_name }}" - veth_pair_ovs_link_name: "{{ item.0 | ovs_link_name(item.1) }}" - veth_pair_source_link_name: "{{ item.0 | source_link_name(item.1) }}" + veth_pair_ovs_bridge: "{{ physnet.1 | bridge_name }}" + veth_pair_ovs_link_name: "{{ physnet.0 | ovs_link_name(physnet.1) }}" + veth_pair_source_link_name: "{{ physnet.0 | source_link_name(physnet.1) }}" veth_pair_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" # Loop over each physical network for each node allocated to this host. # Allocations are stored in localhost's vars. loop: >- {{ nodes | subelements('physical_networks') }} + loop_control: + loop_var: physnet diff --git a/ansible/resource_wait.yml b/ansible/resource_wait.yml index ea6714b..f3a23d3 100644 --- a/ansible/resource_wait.yml +++ b/ansible/resource_wait.yml @@ -1,38 +1,38 @@ --- - hosts: localhost tasks: - - name: Check that OpenStack credentials exist in the environment - fail: - msg: > - $OS_USERNAME was not found in the environment. Ensure the OpenStack - credentials exist in your environment, perhaps by sourcing your RC file. - when: not lookup('env', 'OS_USERNAME') + - name: Set default value for expected resources + set_fact: + tenks_expected_resources: [] - - name: Gather list of OpenStack services - command: >- - {{ virtualenv_path }}/bin/openstack service list -f json - register: service_list_output - changed_when: false + - name: Build list of expected resources + # takes the form: [{ resource_class: CUSTOM_TEST_RC, amount: 2, traits: [] }, ] + vars: + resource: + amount: "{{ spec.count | int }}" # this gets converted back to a string + resource_class: "{{ 'CUSTOM_' ~ spec.ironic_config.resource_class | upper | replace('-', '_') }}" + traits: "{{ spec.ironic_config.traits | default([])}}" + set_fact: + tenks_expected_resources: >- + {{ tenks_expected_resources + [resource] }} + loop: "{{ specs }}" + when: "'ironic_config' in spec" + loop_control: + loop_var: spec - block: - - name: Set default value for expected resources - set_fact: - tenks_expected_resources: [] + - name: Check that OpenStack credentials exist in the environment + fail: + msg: > + $OS_USERNAME was not found in the environment. Ensure the OpenStack + credentials exist in your environment, perhaps by sourcing your RC file. + when: not lookup('env', 'OS_USERNAME') - - name: Build list of expected resources - # takes the form: [{ resource_class: CUSTOM_TEST_RC, amount: 2, traits: [] }, ] - vars: - resource: - amount: "{{ spec.count | int }}" # this gets converted back to a string - resource_class: "{{ 'CUSTOM_' ~ spec.ironic_config.resource_class | upper | replace('-', '_') }}" - traits: "{{ spec.ironic_config.traits | default([])}}" - set_fact: - tenks_expected_resources: >- - {{ tenks_expected_resources + [resource] }} - loop: "{{ specs }}" - when: "'ironic_config' in spec" - loop_control: - loop_var: spec + - name: Gather list of OpenStack services + command: >- + {{ virtualenv_path }}/bin/openstack service list -f json + register: service_list_output + changed_when: false - name: Include the wait-for-resources role include_role: @@ -42,5 +42,6 @@ wait_for_resources_venv: "{{ virtualenv_path }}" wait_for_resources_python_upper_constraints_url: >- {{ python_upper_constraints_url }} - # Only attempt to wait for resources when the placement service is running - when: service_list_output.stdout | from_json | selectattr('Type', 'equalto', 'placement') | list | length >= 1 + # Only attempt to wait for resources when the placement service is running + when: service_list_output.stdout | from_json | selectattr('Type', 'equalto', 'placement') | list | length >= 1 + when: tenks_expected_resources | length > 0 diff --git a/ansible/roles/ironic-enrolment/tasks/main.yml b/ansible/roles/ironic-enrolment/tasks/main.yml index 01cae03..20f3070 100644 --- a/ansible/roles/ironic-enrolment/tasks/main.yml +++ b/ansible/roles/ironic-enrolment/tasks/main.yml @@ -1,4 +1,11 @@ --- +- name: Check that OpenStack credentials exist in the environment + fail: + msg: > + $OS_USERNAME was not found in the environment. Ensure the OpenStack + credentials exist in your environment, perhaps by sourcing your RC file. + when: not lookup('env', 'OS_USERNAME') + # This is useful to get a uniquely generated temporary path. - name: Create temporary file for pip requirements tempfile: diff --git a/playbooks/tenks-deploy-teardown/run.yml b/playbooks/tenks-deploy-teardown/run.yml index c8dff04..f1b1578 100644 --- a/playbooks/tenks-deploy-teardown/run.yml +++ b/playbooks/tenks-deploy-teardown/run.yml @@ -9,7 +9,7 @@ - name: Deploy tenks cluster shell: cmd: >- - {{ ansible_playbook_bin }} -vvv --skip-tags openstack + {{ ansible_playbook_bin }} -vvv --inventory ansible/inventory --extra-vars=@{{ tenks_overrides_path }} ansible/deploy.yml > {{ logs_dir }}/ansible/tenks-deploy @@ -25,7 +25,7 @@ - name: Teardown tenks cluster shell: cmd: >- - {{ ansible_playbook_bin }} -vvv --skip-tags openstack + {{ ansible_playbook_bin }} -vvv --inventory ansible/inventory --extra-vars=@{{ tenks_overrides_path }} ansible/teardown.yml > {{ logs_dir }}/ansible/tenks-teardown diff --git a/playbooks/tenks-deploy-teardown/templates/tenks-overrides.yml.j2 b/playbooks/tenks-deploy-teardown/templates/tenks-overrides.yml.j2 index 89dba73..09d9bda 100644 --- a/playbooks/tenks-deploy-teardown/templates/tenks-overrides.yml.j2 +++ b/playbooks/tenks-deploy-teardown/templates/tenks-overrides.yml.j2 @@ -17,13 +17,8 @@ node_types: specs: - type: type0 count: 2 - ironic_config: - resource_class: test-rc - network_interface: flat -nova_flavors: - - resource_class: test-rc - node_type: type0 +nova_flavors: [] physnet_mappings: physnet1: breth1