Use node state rather than 'cmd'

There are two cases when we may want to delete things:

1. if a desired node configuration or spec changes, we delete existing node
   resources.
2. if we use the teardown.yml playbook, cmd == teardown, delete
   everything, including global state.

In both cases, Tenks state (state.yml), all nodes to be deleted are given a
'state' of absent'. We should therefore use this rather than the 'cmd' variable
which only works in the latter case.

Change-Id: Icc033340c7fd882e61d90e3d086f7ba4a5b673bf
Story: 2004907
Task: 29257
This commit is contained in:
Mark Goddard 2019-01-31 14:39:00 +00:00
parent dcc25d8524
commit 7ad354c2af
6 changed files with 17 additions and 17 deletions

View File

@ -35,16 +35,15 @@
include_role: include_role:
name: virtualbmc-domain name: virtualbmc-domain
vars: vars:
vbmc_domain: "{{ domain }}" vbmc_domain: "{{ domain.name }}"
vbmc_libvirt_uri: "{{ libvirt_local_uri }}" vbmc_libvirt_uri: "{{ libvirt_local_uri }}"
vbmc_ipmi_address: "{{ ipmi_address }}" vbmc_ipmi_address: "{{ ipmi_address }}"
vbmc_ipmi_username: "{{ ipmi_username }}" vbmc_ipmi_username: "{{ ipmi_username }}"
vbmc_ipmi_password: "{{ ipmi_password }}" vbmc_ipmi_password: "{{ ipmi_password }}"
vbmc_ipmi_port: "{{ ipmi_port_range_start + port_offset }}" vbmc_ipmi_port: "{{ domain.ipmi_port }}"
vbmc_virtualenv_path: "{{ virtualenv_path }}" vbmc_virtualenv_path: "{{ virtualenv_path }}"
vbmc_log_directory: "{{ log_directory }}" vbmc_log_directory: "{{ log_directory }}"
vbmc_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" vbmc_state: "{{ domain.get('state', 'present') }}"
loop: "{{ vbmc_nodes | map(attribute='name') | sort | list }}" loop: "{{ vbmc_nodes | sort(attribute='name') | list }}"
loop_control: loop_control:
loop_var: domain loop_var: domain
index_var: port_offset

View File

@ -23,10 +23,7 @@
# basis to account for existing state, rather than for all nodes # basis to account for existing state, rather than for all nodes
# here. # here.
libvirt_vms: >- libvirt_vms: >-
{{ nodes | map('combine', {{ nodes | map('set_libvirt_interfaces')
{'state': ('absent' if cmd == 'teardown'
else 'present')})
| map('set_libvirt_interfaces')
| map('set_libvirt_volume_pool') | map('set_libvirt_volume_pool')
| map('set_libvirt_start_params') | map('set_libvirt_start_params')
| list }} | list }}

View File

@ -18,7 +18,7 @@
veth_pair_ovs_bridge: "{{ physnet.1 | bridge_name }}" veth_pair_ovs_bridge: "{{ physnet.1 | bridge_name }}"
veth_pair_ovs_link_name: "{{ physnet.0 | ovs_link_name(physnet.1) }}" 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_source_link_name: "{{ physnet.0 | source_link_name(physnet.1) }}"
veth_pair_state: "{{ 'absent' if cmd == 'teardown' else 'present' }}" veth_pair_state: "{{ physnet.0.get('state', '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: >-

View File

@ -94,8 +94,7 @@
include_tasks: node.yml include_tasks: node.yml
vars: vars:
node: "{{ ironic_node }}" node: "{{ ironic_node }}"
ipmi_port: >- ipmi_port: "{{ ironic_node.ipmi_port }}"
{{ hostvars[ironic_hypervisor].ipmi_port_range_start + port_offset }}
ironic_deploy_kernel_uuid: >- ironic_deploy_kernel_uuid: >-
{{ deploy_image_ids.results.0.stdout | default(ironic_deploy_kernel) }} {{ deploy_image_ids.results.0.stdout | default(ironic_deploy_kernel) }}
ironic_deploy_ramdisk_uuid: >- ironic_deploy_ramdisk_uuid: >-
@ -103,7 +102,6 @@
loop: "{{ ironic_nodes | sort(attribute='name') }}" loop: "{{ ironic_nodes | sort(attribute='name') }}"
loop_control: loop_control:
loop_var: ironic_node loop_var: ironic_node
index_var: port_offset
# If no ironic_config options were set, this means that enrolment should not # If no ironic_config options were set, this means that enrolment should not
# be performed. # be performed.
when: "'ironic_config' in ironic_node" when: "'ironic_config' in ironic_node"

View File

@ -7,7 +7,7 @@
'{{ vbmc_virtualenv_path }}/bin/vbmc' '{{ vbmc_virtualenv_path }}/bin/vbmc'
--no-daemon --no-daemon
{% if vbmc_log_directory is not none %} {% if vbmc_log_directory is not none %}
--log-file '{{ vbmc_log_directory }}/vbmc-{{ domain }}.log' --log-file '{{ vbmc_log_directory }}/vbmc-{{ vbmc_domain }}.log'
{% endif %} {% endif %}
# Even if the domain is present in VBMC, we can't guarantee that it's # Even if the domain is present in VBMC, we can't guarantee that it's
@ -15,7 +15,7 @@
# involve minimal downtime. # involve minimal downtime.
- name: Ensure domain is stopped and deleted in VBMC - name: Ensure domain is stopped and deleted in VBMC
command: >- command: >-
{{ vbmc_cmd }} {{ item }} '{{ domain }}' {{ vbmc_cmd }} {{ item }} '{{ vbmc_domain }}'
loop: loop:
- stop - stop
- delete - delete
@ -40,7 +40,7 @@
# the checks. # the checks.
- name: Ensure domain is added to VBMC - name: Ensure domain is added to VBMC
command: >- command: >-
{{ vbmc_cmd }} add '{{ domain }}' {{ vbmc_cmd }} add '{{ vbmc_domain }}'
--port {{ vbmc_ipmi_port }} --port {{ vbmc_ipmi_port }}
--username '{{ vbmc_ipmi_username }}' --username '{{ vbmc_ipmi_username }}'
--password '{{ vbmc_ipmi_password }}' --password '{{ vbmc_ipmi_password }}'
@ -53,7 +53,7 @@
- name: Ensure domain is started in VBMC - name: Ensure domain is started in VBMC
command: > command: >
{{ vbmc_cmd }} start '{{ domain }}' {{ vbmc_cmd }} start '{{ vbmc_domain }}'
register: res register: res
# Retry a few times in case the VBMC daemon has been slow to process the last # Retry a few times in case the VBMC daemon has been slow to process the last
# few commands. # few commands.

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes an issue where VMs, virtual ethernet pairs and virtual BMC state is
not cleaned up on a reconfiguration. See `story 2004907
<https://storyboard.openstack.org/#!/story/2004907>`__ for details.