From dd52a3df190ad677e23654dbba8bf553565a159b Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 3 Oct 2014 13:53:22 +0200 Subject: ansible: incorporate os1 triggers * ansible/dummy-wrapper.yml: Helper playbook to directly invoke "included" playbooks. * ansible/fedora.yml: The "main" playbook (new file). * ansible/include/beakerlib.yml: New file, install beakerlib remotely. * ansible/include/prepare-testenv.yml: Install the test dependencies remotely. * ansible/run_include: Helper script to run included playbooks. * dist: Do not distribute ansible playbooks in tarball. * get_machine: Helper script to obtain openstack machine, not used currently. * lib_pgsql.sh: Assert for PG_VERSION, not for datadir (as it by default exists after postgresql-server installation. * run_remote: Helper script invoking the main ansible playbook. * ansible_helpers/wait-for-ssh: Helper script as 'wait_for' is broken? * README: Document. * .gitignore: Ignore private files. --- .gitignore | 2 + README | 30 +++++++++++-- ansible/dummy-wrapper.yml | 7 +++ ansible/fedora.yml | 61 ++++++++++++++++++++++++++ ansible/include/beakerlib.yml | 1 + ansible/include/prepare-testenv.yml | 3 ++ ansible/run_include | 8 ++++ ansible_helpers/wait-for-ssh | 11 +++++ dist | 2 +- get_machine | 85 +++++++++++++++++++++++++++++++++++++ lib_pgsql.sh | 2 +- run_remote | 4 ++ 12 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 ansible/dummy-wrapper.yml create mode 100644 ansible/fedora.yml create mode 100644 ansible/include/beakerlib.yml create mode 100644 ansible/include/prepare-testenv.yml create mode 100755 ansible/run_include create mode 100755 ansible_helpers/wait-for-ssh create mode 100755 get_machine create mode 100755 run_remote diff --git a/.gitignore b/.gitignore index 335ec95..74fe3dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.tar.gz +ostack.yml +private diff --git a/README b/README index 68b53a9..803aa71 100644 --- a/README +++ b/README @@ -14,12 +14,28 @@ Each file should consist of config.sh and runtest.sh. Both are supposed to be "sourced" into another scripts (so no need to have execute permissions). Each test case should have its own directory. -USAGE -===== +USAGE (locally) +=============== The most simple usage is like `./run`. Script is able to search for available -test-cases and then run them. For more info, run `./run --help`. TODO: The -testsuite is root-only. +test-cases and then run them on local machine. Note that this is not generaly +safe and you should avoid that in most cases. For more info, run +`./run --help`. TODO: The testsuite is root-only. + +REMOTE RUN +========== + +You need to have OpenStack credentials file in ./private/ostack.yml configured. +The file should look like (be sure that only you can read that file): + $ cat ./private/ostack.yml: + --- + os_username: os1username + os_tenant_id: 9df30fc192f5xxxxxxxxxxxxxxxx0110 + os_nova_password: your_os_password + +Then it should be enough to run: + + $ ./run_remote API for config.sh file ====================== @@ -30,3 +46,9 @@ $DTF_TEST_ID - unique ID of task. Without spaces. $DTF_TEST_DESCRIPTION - descriptive info about test, will be used for generating html or otherwise formated result output. + +REQUIREMENTS +============ + +Packages needed to successful run + * ansible (remote running) diff --git a/ansible/dummy-wrapper.yml b/ansible/dummy-wrapper.yml new file mode 100644 index 0000000..b645874 --- /dev/null +++ b/ansible/dummy-wrapper.yml @@ -0,0 +1,7 @@ +- name: "{{ script_name }}" + hosts: "{{ target }}" + remote_user: root + gather_facts: False + + tasks: + - include: "{{ include_file }}" diff --git a/ansible/fedora.yml b/ansible/fedora.yml new file mode 100644 index 0000000..825d7c9 --- /dev/null +++ b/ansible/fedora.yml @@ -0,0 +1,61 @@ +- name: self-standing testsuite + remote_user: root + gather_facts: False + hosts: localhost + vars_files: + - ../private/ostack.yml + + vars: + - keypair: praiskup-test + - instance_type: a4827976-e727-4135-ba59-7d5fdb9ce4e2 + - security_group: praiskup-dbt + - image_id: 5fd723b7-e00d-49d3-b17b-65af842d02ab + - OS_AUTH_URL: http://control.os1.phx2.redhat.com:5000/v2.0 + - OS_TENANT_ID: "{{ os_tenant_id }}" + - OS_USERNAME: "{{ os_username }}" + - OS_PASSWORD: "{{ os_nova_password }}" + - OS_TENANT_NAME: "Developer Experience - Packaging" + + tasks: + - name: generate builder name + local_action: shell echo `dd if=/dev/urandom bs=1k count=10 | md5sum ; echo DBTESTS` + register: vm_name + + - name: spin it up + local_action: nova_compute auth_url={{OS_AUTH_URL}} + flavor_id={{instance_type}} image_id="{{ image_id }}" key_name={{ keypair }} + login_password={{OS_PASSWORD}} login_tenant_name="{{OS_TENANT_NAME}}" + login_username={{OS_USERNAME}} security_groups={{security_group}} + wait=yes name="{{vm_name.stdout}}" + register: nova + + # This is ugly as hell... Hopefully nothing will be changing. + - local_action: command echo "{{ nova.info.addresses["os1-internal-1425"][1].addr }}" + register: machine_ip + + - debug: msg="{{ machine_ip.stdout }}" + + - name: wait for the host to be hot + local_action: wait_for host={{ machine_ip.stdout }} port=22 delay=5 timeout=600 + + - local_action: shell ../ansible_helpers/wait-for-ssh "root@{{ machine_ip.stdout }}" + + - name: add it to the special group + local_action: add_host hostname={{ machine_ip.stdout }} + groupname=temp_group + + - local_action: shell cd .. ; ./dist + +- hosts: temp_group + user: root + gather_facts: False + tasks: + - copy: src=../postgresql-setup-tests.tar.gz + dest=/root/postgresql-setup-tests.tar.gz + + - include: include/beakerlib.yml + + - include: include/prepare-testenv.yml + + - shell: cd /root && tar -xf postgresql-setup-tests.tar.gz && + cd postgresql-setup-tests && ./run diff --git a/ansible/include/beakerlib.yml b/ansible/include/beakerlib.yml new file mode 100644 index 0000000..0461f25 --- /dev/null +++ b/ansible/include/beakerlib.yml @@ -0,0 +1 @@ +- yum: conf_file=https://beaker-project.org/yum/beaker-server-Fedora.repo state=present name=beakerlib diff --git a/ansible/include/prepare-testenv.yml b/ansible/include/prepare-testenv.yml new file mode 100644 index 0000000..a63e51a --- /dev/null +++ b/ansible/include/prepare-testenv.yml @@ -0,0 +1,3 @@ +- yum: state=present name=postgresql-server + +- yum: state=present name=postgresql-upgrade diff --git a/ansible/run_include b/ansible/run_include new file mode 100755 index 0000000..3a47f68 --- /dev/null +++ b/ansible/run_include @@ -0,0 +1,8 @@ +#!/bin/bash + +export ANSIBLE_HOST_KEY_CHECKING=False + +ansible-playbook -i hosts \ + --extra-vars "include_file=$1" \ + --extra-vars "script_name=dummy target=host" \ + ./dummy-wrapper.yml diff --git a/ansible_helpers/wait-for-ssh b/ansible_helpers/wait-for-ssh new file mode 100755 index 0000000..eb3880a --- /dev/null +++ b/ansible_helpers/wait-for-ssh @@ -0,0 +1,11 @@ +#!/bin/bash -x + +where="$1" + +test -z "$where" && echo >&2 "no host specified" && exit 1 + +while [ 1 ]; do + ssh -o StrictHostKeyChecking=no -q $where exit &>/dev/null && exit 0 +done + +exit 1 diff --git a/dist b/dist index ef20bd6..62938db 100755 --- a/dist +++ b/dist @@ -3,7 +3,7 @@ name=postgresql-setup-tests tarball=$name.tar.gz test -e .git || exit 1 -what=`ls -1 | grep -v $tarball` +what=`ls -1 | grep -v $tarball | grep -v ansible` mkdir $name cp $what $name -R tar -czf $tarball $name diff --git a/get_machine b/get_machine new file mode 100755 index 0000000..963cc35 --- /dev/null +++ b/get_machine @@ -0,0 +1,85 @@ +#!/bin/bash + +. ./osrc.sh + +image_f20="db-f20_x86_64-cloud-0.0-2" +flavor="m1.small" + +info() { echo " * $@" ; } + +option_distro="" + +function show_help() +{ +cat <&2 +Usage: $0 OPTION + +Script is aimed to help sysadmin. + +Options: + --distro Distro version, like fedora-20 +EOHELP +test -n "$1" && exit $1 +} + +ARGS=`getopt -o "" -l "help,distro:" -n "$0" -- "$@"` \ + || exit 1 + +eval set -- "$ARGS" + +while true; do + case "$1" in + --distro) + case "$2" in + fedora-*) + option_distro=$2 + ;; + *) + echo "bad distro option $2, use fedora-20, etc." + exit 1 + ;; + esac + shift 2 + ;; + --help) + show_help 0 + ;; + --) + shift + break; + esac +done + +image_var=image_f${option_distro##fedora-} +eval "image=\$$image_var" +test -z "$image" && echo "no such image $image_var" && exit 1 + + +boot() +{ + x=$( + nova boot "$1" --poll --image "$2" --flavor "$3" \ + --security-groups praiskup-dbt \ + --key-name praiskup-test \ + | grep "| id " | cut -d\| -f 3 + ) + echo $x +} + +get_ip() +{ + local id="$1" + ip=$( + nova show "$id" | grep ' network ' \ + | cut -d\| -f 3 | cut -d, -f2 + ) + echo $ip +} + +info "booting machine $option_distro from $image" + +machine=`boot "testing-$image_var" "$image" "$flavor"` +info "machine id: $machine" + +ip=`get_ip $machine` +info "ip: $ip" diff --git a/lib_pgsql.sh b/lib_pgsql.sh index 6997827..9db69d1 100644 --- a/lib_pgsql.sh +++ b/lib_pgsql.sh @@ -33,7 +33,7 @@ dtf_postgresql_checkphase() dtf_postgresql_check_stopped - rlAssertNotExists "/var/lib/pgsql/data" + rlAssertNotExists "/var/lib/pgsql/data/PG_VERSION" rlAssert0 "run under root user" `id -u` diff --git a/run_remote b/run_remote new file mode 100755 index 0000000..7ddab30 --- /dev/null +++ b/run_remote @@ -0,0 +1,4 @@ +#!/bin/bash + +export ANSIBLE_HOST_KEY_CHECKING=False +ansible-playbook ./ansible/fedora.yml -- cgit