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
This commit is contained in:
Mark Goddard 2018-11-22 16:50:08 +00:00
parent 6545bf3fa2
commit 6a2fb44a78
8 changed files with 51 additions and 50 deletions

View File

@ -156,8 +156,9 @@ class ActionModule(ActionBase):
# to count as an 'instance' of the spec. # to count as an 'instance' of the spec.
MATCHING_ATTRS = {'type', 'ironic_config'} MATCHING_ATTRS = {'type', 'ironic_config'}
for spec in specs: for spec in specs:
if ((all(spec[attr] == node[attr] for attr in MATCHING_ATTRS) and if (all(spec.get(attr) == node.get(attr)
spec['count'] > 0)): for attr in MATCHING_ATTRS)
and spec['count'] > 0):
spec['count'] -= 1 spec['count'] -= 1
return True return True
return False return False

View File

@ -10,3 +10,4 @@
{{ python_upper_constraints_url }} {{ python_upper_constraints_url }}
flavors: "{{ nova_flavors }}" flavors: "{{ nova_flavors }}"
flavors_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" flavors_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}"
when: flavors | length > 0

View File

@ -5,13 +5,6 @@
file: "{{ state_file_path }}" file: "{{ state_file_path }}"
name: tenks_state 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 - name: Perform Ironic enrolment for each hypervisor's nodes
include_role: include_role:
name: ironic-enrolment name: ironic-enrolment
@ -26,3 +19,4 @@
loop: "{{ query('dict', tenks_state) }}" loop: "{{ query('dict', tenks_state) }}"
loop_control: loop_control:
loop_var: alloc loop_var: alloc
when: ironic_nodes | selectattr('ironic_config', 'defined') | list | length > 0

View File

@ -15,11 +15,13 @@
include_role: include_role:
name: veth-pair name: veth-pair
vars: vars:
veth_pair_ovs_bridge: "{{ item.1 | bridge_name }}" veth_pair_ovs_bridge: "{{ physnet.1 | bridge_name }}"
veth_pair_ovs_link_name: "{{ item.0 | ovs_link_name(item.1) }}" veth_pair_ovs_link_name: "{{ physnet.0 | ovs_link_name(physnet.1) }}"
veth_pair_source_link_name: "{{ item.0 | source_link_name(item.1) }}" veth_pair_source_link_name: "{{ physnet.0 | source_link_name(physnet.1) }}"
veth_pair_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" veth_pair_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}"
# Loop over each physical network for each node allocated to this host. # Loop over each physical network for each node allocated to this host.
# Allocations are stored in localhost's vars. # Allocations are stored in localhost's vars.
loop: >- loop: >-
{{ nodes | subelements('physical_networks') }} {{ nodes | subelements('physical_networks') }}
loop_control:
loop_var: physnet

View File

@ -1,38 +1,38 @@
--- ---
- hosts: localhost - hosts: localhost
tasks: tasks:
- name: Check that OpenStack credentials exist in the environment - name: Set default value for expected resources
fail: set_fact:
msg: > tenks_expected_resources: []
$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: Gather list of OpenStack services - name: Build list of expected resources
command: >- # takes the form: [{ resource_class: CUSTOM_TEST_RC, amount: 2, traits: [] }, ]
{{ virtualenv_path }}/bin/openstack service list -f json vars:
register: service_list_output resource:
changed_when: false 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: - block:
- name: Set default value for expected resources - name: Check that OpenStack credentials exist in the environment
set_fact: fail:
tenks_expected_resources: [] 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 - name: Gather list of OpenStack services
# takes the form: [{ resource_class: CUSTOM_TEST_RC, amount: 2, traits: [] }, ] command: >-
vars: {{ virtualenv_path }}/bin/openstack service list -f json
resource: register: service_list_output
amount: "{{ spec.count | int }}" # this gets converted back to a string changed_when: false
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: Include the wait-for-resources role - name: Include the wait-for-resources role
include_role: include_role:
@ -42,5 +42,6 @@
wait_for_resources_venv: "{{ virtualenv_path }}" wait_for_resources_venv: "{{ virtualenv_path }}"
wait_for_resources_python_upper_constraints_url: >- wait_for_resources_python_upper_constraints_url: >-
{{ python_upper_constraints_url }} {{ python_upper_constraints_url }}
# Only attempt to wait for resources when the placement service is running # 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: service_list_output.stdout | from_json | selectattr('Type', 'equalto', 'placement') | list | length >= 1
when: tenks_expected_resources | length > 0

View File

@ -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. # This is useful to get a uniquely generated temporary path.
- name: Create temporary file for pip requirements - name: Create temporary file for pip requirements
tempfile: tempfile:

View File

@ -9,7 +9,7 @@
- name: Deploy tenks cluster - name: Deploy tenks cluster
shell: shell:
cmd: >- cmd: >-
{{ ansible_playbook_bin }} -vvv --skip-tags openstack {{ ansible_playbook_bin }} -vvv
--inventory ansible/inventory --inventory ansible/inventory
--extra-vars=@{{ tenks_overrides_path }} --extra-vars=@{{ tenks_overrides_path }}
ansible/deploy.yml > {{ logs_dir }}/ansible/tenks-deploy ansible/deploy.yml > {{ logs_dir }}/ansible/tenks-deploy
@ -25,7 +25,7 @@
- name: Teardown tenks cluster - name: Teardown tenks cluster
shell: shell:
cmd: >- cmd: >-
{{ ansible_playbook_bin }} -vvv --skip-tags openstack {{ ansible_playbook_bin }} -vvv
--inventory ansible/inventory --inventory ansible/inventory
--extra-vars=@{{ tenks_overrides_path }} --extra-vars=@{{ tenks_overrides_path }}
ansible/teardown.yml > {{ logs_dir }}/ansible/tenks-teardown ansible/teardown.yml > {{ logs_dir }}/ansible/tenks-teardown

View File

@ -17,13 +17,8 @@ node_types:
specs: specs:
- type: type0 - type: type0
count: 2 count: 2
ironic_config:
resource_class: test-rc
network_interface: flat
nova_flavors: nova_flavors: []
- resource_class: test-rc
node_type: type0
physnet_mappings: physnet_mappings:
physnet1: breth1 physnet1: breth1