bifrost/playbooks/test-bifrost.yaml
Riccardo Pittau 68ed2960e3 Set Ansible default version to 2.8
Ansible 2.6 is EOL, we should move to a more recent release that
has better support for Python 3.x and, above all, is maintained
with security and critical bug fixes.

Change-Id: I6aa80b4bc4a0c34ac919951cd940b2fc6b736bdc
2020-01-23 10:05:27 +01:00

200 lines
8.1 KiB
YAML

# Example command line to use:
# Create a VM:
# ansible-playbook -vvvv -i inventory/localhost test-bifrost-create-vm.yaml
# Set BIFROST_INVENTORY_SOURCE
# export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.json
# Execute the installation and VM startup test.
# ansible-playbook -vvvv -i inventory/bifrost_inventory.py test-bifrost.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: 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"
openstacksdk_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/openstacksdk"
shade_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/shade"
dib_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/diskimage-builder"
ironicinspector_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/ironic-inspector"
ironicinspectorclient_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/python-ironic-inspector-client"
keystone_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/keystone"
sushy_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/sushy"
reqs_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/requirements"
staging_drivers_git_url: "{{ lookup('env', 'WORKSPACE') }}/x/ironic-staging-drivers"
ipa_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/ironic-python-agent"
ipa_builder_git_url: "{{ lookup('env', 'WORKSPACE') }}/openstack/ironic-python-agent-builder"
when: lookup('env', 'ZUUL_BRANCH') | 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 and ci_testing_zuul | bool == true }
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
pre_tasks:
- name: "Collect process list if running in a CI System"
command: ps aux
when: ci_testing is defined
- name: "Collect list of listening network sockets if running in a CI system"
shell: netstat -apn|grep LISTEN
when: ci_testing is defined
- name: "Use a cached cirros image"
set_fact:
cirros_deploy_image_upstream_url: file:///opt/cache/files/cirros-0.4.0-x86_64-disk.img
when: ci_testing is defined and ci_testing_zuul is defined and ci_testing_zuul | bool
roles:
- role: bifrost-keystone-install
- 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: "stretch", dib_elements: "ironic-python-agent-ramdisk {{ ipa_extra_dib_elements | default('') }}", dib_packages: "bsdmainutils", when: create_ipa_image | bool }
# NOTE(TheJulia): This creates the guest image.
- { role: bifrost-create-dib-image, dib_imagetype: "qcow2", dib_imagename: "{{deploy_image}}", dib_os_element: "debian", dib_os_release: "stretch", dib_elements: "vm enable-serial-console simple-init {{ extra_dib_elements|default('') }}", when: create_image_via_dib | bool and not transform_boot_image | bool }
- role: bifrost-keystone-client-config
user: "{{ ansible_env.SUDO_USER | default(ansible_user_id) }}"
clouds:
bifrost:
config_username: "{{ ironic.keystone.default_username }}"
config_password: "{{ ironic.keystone.default_password }}"
config_project_name: "baremetal"
config_region_name: "{{ keystone.bootstrap.region_name }}"
config_auth_url: "{{ keystone.bootstrap.public_url }}"
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: not inspect_nodes | default('false') | bool }
- role: bifrost-test-inspection
when: not inspect_nodes | default('false') | bool
- hosts: localhost
name: "Tests the use of openstack clients"
connection: local
tasks:
- name: "List bare metal nodes using openstack client"
command: openstack baremetal node list
environment:
OS_CLOUD: bifrost
PATH: /usr/local/bin:{{ ansible_env.PATH }}
- name: "List introspection rules using openstack client"
command: openstack baremetal introspection rule list
environment:
OS_CLOUD: "{% if enable_keystone | default(false) | bool == true %}bifrost{% else %}bifrost-inspector{% endif %}"
PATH: /usr/local/bin:{{ ansible_env.PATH }}
when: enable_inspector is defined and enable_inspector | bool
- hosts: baremetal
name: "Create configuration drive files and deploy machines"
vars:
multinode_testing: "{{ inventory_dhcp | bool }}"
become: no
connection: local
roles:
- role: bifrost-configdrives-dynamic
- role: bifrost-deploy-nodes-dynamic
- hosts: baremetal
name: "Prepare for deployment verification"
become: no
connection: local
serial: 1
roles:
- 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
- hosts: baremetal
connection: local
name: "Unprovisions the test node"
become: no
gather_facts: no
roles:
- role: bifrost-unprovision-node-dynamic
- role: ironic-delete-dynamic
# The following tasks are intended to test DHCP functionality
- hosts: localhost
connection: local
name: "Start VMs that were not enrolled to ironic"
become: yes
vars:
not_enrolled_data_file: /tmp/baremetal.json.rest
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: "{{item.key}}"
state: running
with_dict: "{{ lookup('file', not_enrolled_data_file) | from_json }}"
ignore_errors: yes
when: inventory_dhcp | bool
- name: Wait 30 seconds
pause:
seconds: 30
when: inventory_dhcp | bool
- hosts: localhost
connection: local
name: "Executes DHCP 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, when: inventory_dhcp | bool }
environment:
http_proxy: "{{ lookup('env','http_proxy') }}"
https_proxy: "{{ lookup('env','https_proxy') }}"