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.
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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

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.
- name: Create temporary file for pip requirements
tempfile:

View File

@ -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

View File

@ -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