Auto tests patches for OpenStack-Ansible with OpenStack
If you have access to an OpenStack cloud that can accept user-data
then spinning up a test node for a given patch is super simple. All you need to do is create a user-data script with the following contents:
#!/bin/bash
OS_REPO="https://git.openstack.org/openstack/openstack-ansible-os_horizon"
OS_REF="refs/changes/96/353596/19"
BASE="$(basename ${OS_REPO})"
if [[ -d "${BASE}" ]];then
rm -rf "${BASE}"
fi
if [[ -f "/etc/apt/sources.list" ]];then
sudo sed -i '/trusty-backports/s|^#\s||g' /etc/apt/sources.list
fi
sudo yum install -y git tmux vim || (sudo apt-get update && sudo apt-get -y install git tmux vim python-all-dev)
tmux new-session -d -s osa-test
tmux select-pane -t 0
tmux send-keys "touch test.log" C-m
tmux send-keys "git clone ${OS_REPO} ${BASE} | tee -a test.log" C-m
tmux send-keys "cd ${BASE}" C-m
tmux send-keys "git fetch ${OS_REPO} ${OS_REF} && git checkout FETCH_HEAD | tee -a test.log" C-m
tmux send-keys "export ANSIBLE_LOG_PATH=test.log" C-m
tmux send-keys "bash -x ./scripts/gate-check-commit.sh || bash -x ./run-tests.sh || bash -x ./run_tests.sh" C-m
tail -f test.log
Save the script somewhere on your file system where you wont loose it. With the script on hand, run the following command to create a temporary script using the repository and patch references as variables.
OS_REPO=xxx OS_REF=yyy envsubst < template-script-file.sh > /tmp/test1
An actual example would look like this.
OS_REPO="https://git.openstack.org/openstack/openstack-ansible-os_keystone" OS_REF="refs/changes/16/320216/31" envsubst < template-script-file.sh > /tmp/centos-keystone-test
Now boot the VM and run the test.
nova boot --image ubuntu-server-14.04 --flavor m2.medium --nic net-id="${NEUTRON_NETWORK_ID}" --key-name "${SPECIALKEYNAME}" --user-data /tmp/test1 "${NODE_NAME}"
Once the VM is online it will create a tmux
session, login to the session and run the test commands. When you're ready to login to the VM and start working on it attach to the existing tmux session at osa-test and carry on.
For a full break down on user-data and deploying OpenStack-Ansible with user-data scripts have a look at the following post which shows how user-data can be used from Horizon and to kick an All in One OpenStack-Ansible environment.