From e929254f93ed3c91e587c3fe281ac4b8bbd06aed Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Wed, 29 Jul 2015 15:11:33 -0400 Subject: [PATCH] Test script to drive image testing Support to enable building an IPA image for testing and script to leverage testing image building. Change-Id: I31263909d2cb275491e57d7ed8c3f08a86462699 --- README.rst | 13 ++++ playbooks/install.yaml | 1 + playbooks/inventory/group_vars/localhost | 3 + .../bifrost-ironic-install/defaults/main.yml | 2 + .../bifrost-ironic-install/tasks/main.yml | 1 + playbooks/test-bifrost-dynamic.yaml | 4 ++ scripts/test-bifrost-build-images.sh | 64 +++++++++++++++++++ 7 files changed, 88 insertions(+) create mode 100755 scripts/test-bifrost-build-images.sh diff --git a/README.rst b/README.rst index 85a9ffd53..104e67296 100644 --- a/README.rst +++ b/README.rst @@ -375,3 +375,16 @@ and thus will not automatically grow the root partition. Due to the nature of the design, it would be relatively easy for a user to import automatic growth or reconfiguration steps either in the image to be deployed, or in post-deployment steps via custom Ansible playbooks. + +Custom IPA Images +================= + +Bifrost supports the ability for a user to build a custom IPA ramdisk +utilizing the diskimage-builder element "ironic-agent". In order to utilize +this feature, the download_ipa setting must be set to "false" and the +create_ipa_image must be set to "true". By default, the playbook will build +a Debian based IPA image, if a pre-existing IPA image is not present on disk. + +If you wish to include an extra element into the IPA disk image, such as a +custom hardware manager, you can pass the variable "ipa_extra_dib_elements" +as a space separated list of elements. This defaults to an emtpy string. diff --git a/playbooks/install.yaml b/playbooks/install.yaml index c9af0edf4..39b0427e0 100644 --- a/playbooks/install.yaml +++ b/playbooks/install.yaml @@ -7,6 +7,7 @@ roles: - { role: bifrost-prep-for-install, when: skip_install is not defined } - bifrost-ironic-install + - { role: bifrost-create-dib-image, dib_imagename: "{{ http_boot_folder }}/ipa", build_ramdisk: false, dib_os_element: "{{ ipa_dib_os_element|default('debian') }}", dib_elements: "ironic-agent {{ ipa_extra_dib_elements | default('') }}", when: create_ipa_image | bool == true } - { role: bifrost-create-dib-image, dib_imagename: "{{ deploy_image }}", dib_imagetype: "qcow2", dib_os_element: "{{ dib_os_element|default('debian') }}", dib_elements: "vm serial-console simple-init {{ extra_dib_elements|default('') }}", dib_packages: "{{ dib_packages|default('') }}", when: create_image_via_dib == true and transform_boot_image == false } environment: http_proxy: "{{ lookup('env','http_proxy') }}" diff --git a/playbooks/inventory/group_vars/localhost b/playbooks/inventory/group_vars/localhost index b4fa9b157..4a5d1217c 100644 --- a/playbooks/inventory/group_vars/localhost +++ b/playbooks/inventory/group_vars/localhost @@ -54,3 +54,6 @@ create_image_via_dib: true # Transform boot image is intended for use with the Ubuntu trusty image. It makes the image bootable by installing Grub. # Setting to prepend a partition image with a boot sector and partition table. transform_boot_image: false + +# Create IPA image instead of downloading an pre-made CoreOS IPA image. +create_ipa_image: false diff --git a/playbooks/roles/bifrost-ironic-install/defaults/main.yml b/playbooks/roles/bifrost-ironic-install/defaults/main.yml index 7af24639f..2f352b28e 100644 --- a/playbooks/roles/bifrost-ironic-install/defaults/main.yml +++ b/playbooks/roles/bifrost-ironic-install/defaults/main.yml @@ -24,6 +24,8 @@ deploy_image_filename: "deployment_image.qcow2" deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" # Use cirros instead of building an image via diskimage-builder use_cirros: false +# Download IPA by default +download_ipa: true cirros_deploy_image_upstream_url: http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img # By default Bifrost will deploy dnsmasq to utilize as an integrated DHCP # server. If you already have a DHCP server, you will need to disable diff --git a/playbooks/roles/bifrost-ironic-install/tasks/main.yml b/playbooks/roles/bifrost-ironic-install/tasks/main.yml index 866495f99..ad29e1506 100644 --- a/playbooks/roles/bifrost-ironic-install/tasks/main.yml +++ b/playbooks/roles/bifrost-ironic-install/tasks/main.yml @@ -224,6 +224,7 @@ when: "{{include_dhcp_server|bool}}" - name: "Download Ironic Python Agent kernel & image" include: download_ipa_image.yml + when: download_ipa | bool == true - name: "Download cirros to use for deployment if requested" get_url: url={{ cirros_deploy_image_upstream_url }} dest="{{ deploy_image }}" when: "{{use_cirros|bool}}" diff --git a/playbooks/test-bifrost-dynamic.yaml b/playbooks/test-bifrost-dynamic.yaml index 41acf92ab..f8f4e3396 100644 --- a/playbooks/test-bifrost-dynamic.yaml +++ b/playbooks/test-bifrost-dynamic.yaml @@ -51,6 +51,10 @@ - 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_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: "{{ dib_os_element|default('debian') }}", dib_elements: "vm serial-console simple-init {{ extra_dib_elements|default('') }}", dib_packages: "{{ dib_packages|default('') }}", when: create_image_via_dib == true and transform_boot_image == false } environment: http_proxy: "{{ lookup('env','http_proxy') }}" diff --git a/scripts/test-bifrost-build-images.sh b/scripts/test-bifrost-build-images.sh new file mode 100755 index 000000000..87a92812c --- /dev/null +++ b/scripts/test-bifrost-build-images.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -eux +set -o pipefail +export PYTHONUNBUFFERED=1 + +SCRIPT_HOME=$(dirname $0) +BIFROST_HOME=$SCRIPT_HOME/.. +# Install Ansible +$SCRIPT_HOME/env-setup.sh + +# Source Ansible +# NOTE(TheJulia): Ansible stable-1.9 source method tosses an error deep +# under the hood which -x will detect, so for this step, we need to suspend +# and then re-enable the feature. +set +x +source /opt/stack/ansible/hacking/env-setup +set -x + +# Change working directory +cd $BIFROST_HOME/playbooks + +# Syntax check of dynamic inventory test path +ansible-playbook -vvvv -i inventory/localhost test-bifrost-create-vm.yaml --syntax-check --list-tasks +ansible-playbook -vvvv -i inventory/localhost test-bifrost-dynamic.yaml --syntax-check --list-tasks + +# Create the test VM +ansible-playbook -vvvv -i inventory/localhost test-bifrost-create-vm.yaml + +set +e + +# Set BIFROST_INVENTORY_SOURCE +export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv + +# Execute the installation and VM startup test. +# NOTE(TheJulia): The variables defined on the command line are to +# drive the use of Cirros as the deployed operating system, and +# as such sets the test user to cirros, and writes a debian style +# interfaces file out to the configuration drive as cirros does +# not support the network_info.json format file placed in the +# configuration drive. +ansible-playbook -vvvv -i inventory/bifrost_inventory.py \ + test-bifrost-dynamic.yaml \ + -e testing_user=root \ + -e download_ipa=false \ + -e create_ipa_image=true +EXITCODE=$? + +if [ $EXITCODE != 0 ]; then + echo "****************************" + echo "Test failed. See logs folder" + echo "****************************" +fi +echo "Making logs directory and collecting logs." +mkdir ../logs +sudo cp /var/log/libvirt/baremetal_logs/testvm1_console.log ../logs/ +sudo chown $USER ../logs/testvm1_console.log +dmesg &> ../logs/dmesg.log +sudo netstat -apn &> ../logs/netstat.log +sudo iptables -L -n -v &> ../logs/iptables.log +sudo cp /var/log/upstart/ironic-api.log ../logs/ +sudo chown $USER ../logs/ironic-api.log +sudo cp /var/log/upstart/ironic-conductor.log ../logs/ +sudo chown $USER ../logs/ironic-conductor.log +exit $EXITCODE