bifrost/playbooks/test-bifrost-dhcp.yaml
Markos Chandras 87a32c6311 Serialize localhost actions during final host deployment
Several tasks in the final playbooks run locally and there is a chance
to encounter race conditions when multiple tasks run in parallel and
all of them access or modify the same local files. We fix this by
splitting the final steps into multiple plays and serializing those
that run locally. Finally, the 'serial' keyword can only be used for
an entire play and not just for a subset of its tasks provided by a
role so previously that keyword did not have any effect.

Change-Id: Ib0a55dcd4b02e070a6be72207f0b99e8138e0e12
2016-10-04 09:45:10 +01:00

155 lines
6.0 KiB
YAML

# Example command line to use:
# Create a VM:
# ansible-playbook -vvvv -i inventory/localhost test-bifrost-dhcp.yaml
# Set BIFROST_INVENTORY_SOURCE
# export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv
# Execute the installation and VM startup test.
# ansible-playbook -vvvv -i inventory/bifrost_inventory.py test-bifrost-dhcp.yaml -e use_cirros=true -e testing_user=cirros
---
- hosts: localhost
connection: local
name: "Setting pre-test conditions"
become: yes
ignore_errors: yes
tasks:
# NOTE(TheJulia): While the test was created to run with five VMs,
# in the interest of keeping the active memory footprint small,
# should stop all of the VMs in advance, so we can proceed with
# install and initial deploy.
- name: Attempt to stop all test VMs
virt:
name: "testvm{{ item }}"
command: "stop"
state: shutdown
with_sequence: start=1 end={{ test_vm_num_nodes | default('5') }}
ignore_errors: yes
- name: Remove pre-existing leases file
file: path=/var/lib/misc/dnsmasq.leases state=absent
- hosts: localhost
connection: local
name: "Executes install, enrollment, and testing in one playbook"
become: no
gather_facts: yes
pre_tasks:
- name: "Set ci_testing_zuul if it appears we are running in upstream OpenStack CI"
set_fact:
ci_testing: true
ci_testing_zuul: true
ironic_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/ironic"
ironicclient_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/python-ironicclient"
shade_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack-infra/shade"
dib_git_url: "/opt/git/openstack/diskimage-builder"
ironicinspector_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/ironic-inspector"
ironicinspectorclient_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/python-ironic-inspector-client"
# TODO(TheJulia) Fix the above paths to be consistent, because the NV job gets the dib
# folder cloned, while the gate job does not. Likely need to work out a semi-hybrid
# solution.
when: lookup('env', 'ZUUL_BRANCH') | length > 0
- name: "Set ci_testing_zuul_changes if ZUUL_CHANGES is set"
set_fact:
ci_testing_zuul_changes: true
when: lookup('env', 'ZUUL_CHANGES') | length > 0
- name: "Override the ipv4_gateway setting"
set_fact:
ipv4_gateway: "192.168.122.1"
roles:
- { role: bifrost-prep-for-install, when: skip_install is not defined }
- { role: bifrost-openstack-ci-prep, when: ci_testing_zuul is defined }
environment:
http_proxy: "{{ lookup('env','http_proxy') }}"
https_proxy: "{{ lookup('env','https_proxy') }}"
- hosts: localhost
connection: local
name: "Executes install, enrollment, and testing in one playbook"
become: yes
gather_facts: yes
vars:
inventory_dhcp: "{{ inventory_dhcp | bool == true }}"
roles:
- role: bifrost-ironic-install
cleaning: false
testing: true
# NOTE(TheJulia): While the next step creates a ramdisk, some elements
# do not support ramdisk-image-create as they invoke steps to cleanup
# the ramdisk which causes ramdisk-image-create to believe it failed.
- { role: bifrost-create-dib-image, dib_imagename: "{{ http_boot_folder }}/ipa", build_ramdisk: false, dib_os_element: "{{ ipa_dib_os_element|default('debian') }}", dib_os_release: "jessie", dib_elements: "ironic-agent {{ ipa_extra_dib_elements | default('') }}", when: create_ipa_image | bool == true }
- { role: bifrost-create-dib-image, dib_imagetype: "qcow2", dib_imagename: "{{deploy_image}}", dib_os_element: "debian", dib_os_release: "jessie", dib_elements: "vm serial-console simple-init {{ extra_dib_elements|default('') }}", when: create_image_via_dib == true and transform_boot_image == false }
environment:
http_proxy: "{{ lookup('env','http_proxy') }}"
https_proxy: "{{ lookup('env','https_proxy') }}"
- hosts: baremetal
name: "Enroll node with Ironic"
become: no
connection: local
roles:
- role: ironic-enroll-dynamic
- { role: ironic-inspect-node, when: inspect_nodes | default('false') | bool == true }
- hosts: baremetal
name: "Create configuration drive files."
become: no
connection: local
roles:
- role: bifrost-configdrives-dynamic
- hosts: baremetal
vars:
inventory_dhcp_static_ip: "{{ inventory_dhcp_static_ip | bool == true }}"
multinode_testing: true
name: "Deploy machines."
become: no
connection: local
serial: 1
roles:
- role: bifrost-deploy-nodes-dynamic
- role: bifrost-prepare-for-test-dynamic
# The testvm Host group is added by bifrost-prepare-for-test based
# on the contents of the CSV file.
- hosts: test
name: "Tests connectivity to the VM"
become: no
gather_facts: no
remote_user: "{{ testing_user }}"
serial: 1
any_errors_fatal: yes
max_fail_percentage: 0
roles:
- { role: bifrost-test-vm, deprecated_test_playbook: true }
- hosts: baremetal
connection: local
name: "Unprovisions the test node"
become: no
gather_facts: no
roles:
- role: bifrost-unprovision-node-dynamic
- role: ironic-delete-dynamic
- hosts: localhost
connection: local
name: "Executes test script"
become: yes
tasks:
# NOTE(TheJulia): Moved the power ON of the excess VMs until after
# the other test VMs have been shutdown, in order to explicitly
# validate that the dhcp config is working as expected and not
# serving these requests.
- name: Power on remaining test VMs
virt:
name: "testvm{{ item }}"
command: "start"
with_sequence: start=4 end={{ test_vm_num_nodes | default('5') }}
ignore_errors: yes
- name: Wait 30 seconds
pause:
seconds: 30
- hosts: localhost
connection: local
name: "Executes test script"
become: yes
gather_facts: yes
vars:
inventory_dhcp: "{{ inventory_dhcp | bool == true }}"
inventory_dhcp_static_ip: "{{ inventory_dhcp_static_ip | bool == true }}"
roles:
- role: bifrost-test-dhcp
environment:
http_proxy: "{{ lookup('env','http_proxy') }}"
https_proxy: "{{ lookup('env','https_proxy') }}"