From 3e8118c69aa5c39747b6a2cd2e55094529b7a684 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Sep 27 2017 12:42:30 +0000 Subject: Remove obsolete roles: standard-test-selector - test selection should now be done using Ansible tags in test playbooks standard-test-cloud - this should now be done using the Ansible dynamic inventory qcow2 provider standard-test-docker - this should now be done using the Ansible dynamic inventory docker provider --- diff --git a/roles/standard-test-cloud/README.md b/roles/standard-test-cloud/README.md deleted file mode 100644 index 6909eaf..0000000 --- a/roles/standard-test-cloud/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Ansible role for cloud disk image subjects - -Put this role in your test_cloud.yml playbook. You'll need -to have the following variables defined: - - * subjects: A cloud qcow2 or raw image - * artifacts: An artifacts directory - * playbooks: A playbook to run inside of the launched instance - -Set the FEDORA_TEST_DIAGNOSE=1 environment variable to diagnose -the launch instance when it fails. diff --git a/roles/standard-test-cloud/library/qemu_playbook.py b/roles/standard-test-cloud/library/qemu_playbook.py deleted file mode 100644 index 01940b6..0000000 --- a/roles/standard-test-cloud/library/qemu_playbook.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env python - -import os -import shutil -import signal -import subprocess -import sys -import tempfile - -# HACK: Ansible requires this exact string to be here -from ansible.module_utils.basic import * - -# -# Test this module like this -# -# echo '{ "ANSIBLE_MODULE_ARGS": { "subjects": "cloud.qcow2", "playbooks": "test/test_local.yml" } }' \ -# | python tests/library/qemu-playbook.py -# - -WANT_JSON = True - -USER_DATA ="""#cloud-config -user: root -password: foobar -ssh_pwauth: True -chpasswd: - expire: False -disable_root: False -ssh_authorized_keys: - - %s -""" - -INVENTORY = "localhost ansible_ssh_port=2222 ansible_ssh_host=127.0.0.3 ansible_ssh_user=root ansible_ssh_pass=foobar ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'\nexecutor ansible_ssh_host=127.0.0.1 ansible_connection=local" - -def main(argv): - module = AnsibleModule(argument_spec = { - "subjects": { "required": True, "type": "str" }, - "playbooks": { "required": True, "type": "str" }, - "artifacts": { "required": True, "type": "str" }, - "log": { "required": False, "type": "str" }, - }) - - null = open(os.devnull, 'w') - - directory = tempfile.mkdtemp(prefix="launch-cloud") - - privkey = os.path.join(directory, "key") - subprocess.check_call(["/usr/bin/ssh-keygen", "-t", "rsa", - "-N", "", "-f", privkey], stdout=null) - pubkey = privkey + ".pub" - - with open(pubkey, 'r') as f: - sshkey = f.readline().strip() - - metadata = os.path.join(directory, "meta-data") - with open(metadata, 'w') as f: - f.write("") - - userdata = os.path.join(directory, "user-data") - with open(userdata, 'w') as f: - f.write(USER_DATA % sshkey) - - cloudinit = os.path.join(directory, "cloud-init.iso") - subprocess.check_call(["/usr/bin/genisoimage", "-input-charset", "utf-8", - "-volid", "cidata", "-joliet", "-rock", "-quiet", - "-output", cloudinit, userdata, metadata], stdout=null) - - log = module.params.get("log") or os.devnull - - inventory = os.path.join(directory, "inventory") - with open(inventory, 'w') as f: - f.write(INVENTORY) - - pid = os.path.join(directory, "pid") - subprocess.check_call(["/usr/bin/qemu-system-x86_64", "-m", "1024", module.params["subjects"], - "-enable-kvm", "-snapshot", "-cdrom", cloudinit, - "-net", "nic,model=virtio", "-net", "user,hostfwd=tcp:127.0.0.3:2222-:22", - "-device", "isa-serial,chardev=pts2", "-chardev", "file,id=pts2,path=" + log, - "-daemonize", "-display", "none", "-pidfile", pid], stdout=null) - - try: - - # wait for ssh to come up - for tries in range(0, 30): - try: - subprocess.check_call(["/usr/bin/ansible", "-i", inventory, "localhost", "-m", "ping"], - stdout=null, stderr=null) - break - except subprocess.CalledProcessError: - time.sleep(3) - else: - module.fail_json(msg="Couldn't connect to qemu host: {subjects}".format(**module.params)) - return 0 - - cmd = [ - "/usr/bin/ansible-playbook", "-v", "-i", inventory, - "--private-key", privkey, - "--extra-vars", "artifacts=%s" % module.params["artifacts"] - ] - - playbooks = module.params["playbooks"] - if isinstance(playbooks, (list, tuple)): - cmd += playbooks - else: - cmd.append(playbooks) - - new_env = os.environ.copy() - new_env["ANSIBLE_LOG_PATH"] = os.path.join(module.params["artifacts"], "machine-playbook.log") - - proc = subprocess.Popen(cmd, stdin=null, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=new_env) - output, error = proc.communicate() - - if os.getenv("FEDORA_TEST_DIAGNOSE"): - tty = os.open("/dev/tty", os.O_RDWR) - os.write(tty, output + "\n\nDIAGNOSE 'foobar': ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@127.0.0.3\n") - os.read(tty, 100) - finally: - - with open(pid, 'r') as f: - try: - os.kill(int(f.read().strip()), signal.SIGTERM) - except OSError: - pass - - with open(log, "a") as f: - f.write(output) - - if proc.returncode == 0: - shutil.rmtree(directory) - module.exit_json(changed=False) - else: - module.fail_json(msg="The playbook failed on qemu host: {playbooks}".format(**module.params)) - - return 0 - -if __name__ == '__main__': - sys.exit(main(sys.argv)) diff --git a/roles/standard-test-cloud/tasks/main.yml b/roles/standard-test-cloud/tasks/main.yml deleted file mode 100644 index 0cc768b..0000000 --- a/roles/standard-test-cloud/tasks/main.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Install the qemu requirements - package: name={{item}} state=latest - with_items: - - genisoimage - - qemu-system-x86 - -- name: Make artifacts directory - file: path={{ artifacts }} state=directory owner=root mode=755 recurse=yes - -- block: - - name: Run the local playbook in a launched instance - qemu_playbook: - subjects: "{{subjects}}" - playbooks: "{{playbooks}}" - artifacts: "{{artifacts}}" - log: "{{artifacts}}/machine.log" - - always: - - name: Make artifacts directory tree readable by all - file: - path: "{{ artifacts }}" - mode: u=rwX,g=rX,o=rX - recurse: yes diff --git a/roles/standard-test-docker/README.md b/roles/standard-test-docker/README.md deleted file mode 100644 index 213aabd..0000000 --- a/roles/standard-test-docker/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Ansible role for docker image subjects - -Put this role in your test_docker.yml playbook. You'll need -to have the following variables defined: - - * subjects: A docker image name - * artifacts: An artifacts directory - * playbooks: A playbook to run inside of the container - * docker_extra_args: A string containing extra arguments to pass to `docker run ...` (optional) - -Set the FEDORA_TEST_DIAGNOSE=1 environment variable to diagnose -any issues in the docker container. diff --git a/roles/standard-test-docker/defaults/main.yml b/roles/standard-test-docker/defaults/main.yml deleted file mode 100644 index 5b1e4ad..0000000 --- a/roles/standard-test-docker/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" -docker_python_version: 2 -docker_extra_args: null diff --git a/roles/standard-test-docker/files/docker-inventory b/roles/standard-test-docker/files/docker-inventory deleted file mode 100644 index b23a7d0..0000000 --- a/roles/standard-test-docker/files/docker-inventory +++ /dev/null @@ -1,2 +0,0 @@ -localhost ansible_ssh_port=2222 ansible_ssh_host=127.0.0.3 ansible_ssh_user=root ansible_ssh_pass=foobar ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' -executor ansible_ssh_host=127.0.0.1 ansible_connection=local diff --git a/roles/standard-test-docker/files/docker-run-ssh b/roles/standard-test-docker/files/docker-run-ssh deleted file mode 100644 index e5ec652..0000000 --- a/roles/standard-test-docker/files/docker-run-ssh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -authorized_key= -python_version=2 -rootpass=foobar -while [ $# -gt 0 ]; do - case "$1" in - --py3) - python_version=3 - ;; - --authorized-key) - authorized_key="$2" - shift - ;; - esac - shift -done -# install minimum requirements to run ansible -dnf install -y openssh-server python${python_version}-dnf -# configure SSH -ssh-keygen -q -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key -echo "root:$rootpass" | chpasswd -if [ -n "$authorized_key" ]; then - mkdir -p /root/.ssh - echo "$authorized_key" >> /root/.ssh/authorized_keys - chmod 644 /root/.ssh/authorized_keys -fi -# start SSHD in background -/usr/sbin/sshd -echo SSHD READY -# wait forever -tail -f /dev/null diff --git a/roles/standard-test-docker/tasks/main.yml b/roles/standard-test-docker/tasks/main.yml deleted file mode 100644 index 2f6013c..0000000 --- a/roles/standard-test-docker/tasks/main.yml +++ /dev/null @@ -1,98 +0,0 @@ ---- -- name: Install the docker requirements - package: name="{{item}}" state=latest - with_items: - - docker - -- name: Make artifacts directory - file: path={{ artifacts }} state=directory owner=root mode=755 recurse=yes - -- name: Start the docker service - service: - name: docker - state: running - -- name: Initialize docker and ansible playbook extra args variables - set_fact: - my_run_cmd_extra_args: null - my_playbook_extra_args: null - -- name: Configure python version-dependent argument settings - set_fact: - my_playbook_extra_args: "{{my_playbook_extra_args}} -e ansible_python_interpreter='/usr/bin/python{{docker_python_version}}'" - my_run_cmd_extra_args: "{{my_run_cmd_extra_args}} --py{{docker_python_version}}" - when: docker_python_version is defined and docker_python_version != 2 - -- name: Special case - pass along 'rpms' variable to playbook - set_fact: - # note the quoting here: ansible needs to see the single quotes - my_playbook_extra_args: "{{my_playbook_extra_args}} -e \"rpms='{{rpms}}'\"" - when: rpms|default("") != "" - -- name: Create temporary directory - tempfile: - state: directory - suffix: docker - register: my_docker_tempdir - -- name: Create key pair for SSH authentication in container - shell: "/usr/bin/ssh-keygen -t rsa -N '' -f {{ my_docker_tempdir.path + '/key' }}" - -- name: Read contents of generated SSH public key file - set_fact: - my_public_key: "{{ lookup('file', my_docker_tempdir.path + '/key.pub') }}" - -- name: Configure arguments for SSH key based authentication - set_fact: - my_playbook_extra_args: "{{my_playbook_extra_args}} --private-key '{{ my_docker_tempdir.path + \'/key\' }}'" - my_run_cmd_extra_args: "{{my_run_cmd_extra_args}} --authorized-key '{{ my_public_key }}'" - -- name: Start ansible-ready docker container running SSHD - shell: > - docker run -d - -p '{{docker_ssh_port}}:22' - -v '{{role_path}}/files/docker-run-ssh:/run.sh:z' - {{docker_extra_args}} - '{{subjects}}' - /bin/sh -ex /run.sh {{my_run_cmd_extra_args}} - register: docker_run_output - -- name: Capture docker container ID - set_fact: container_id="{{docker_run_output.stdout}}" - -- block: - - name: Wait for container to initialize - wait_for: port="{{docker_ssh_port}}" search_regex=OpenSSH - - - name: Run the playbook in the container - shell: > - ANSIBLE_LOG_PATH='{{artifacts}}/container-playbook.log' - ansible-playbook '{{playbooks}}' - -i '{{role_path}}/files/docker-inventory' - -e artifacts='{{artifacts}}' - {{my_playbook_extra_args}} - register: playbook_output - - - debug: var=playbook_output - - always: - - name: Pause if diagnosing container - pause: - prompt: |- - To diagnose the container, you can use one of the following commands: - ssh -p {{docker_ssh_port}} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@127.0.0.3 # password: foobar - docker exec -it {{ container_id }} /bin/bash - Continue when ready - when: lookup('env','FEDORA_TEST_DIAGNOSE')|bool - - - name: Remove temporary directory - file: - path: "{{ my_docker_tempdir.path }}/" - state: absent - when: my_docker_tempdir is defined - - - name: Save the container log as an artifact - shell: docker logs "{{ container_id }}" >"{{artifacts}}/docker.log" 2>&1 - - - name: Clean up the docker container - shell: docker rm -f "{{ container_id }}" diff --git a/roles/standard-test-docker/vars/main.yml b/roles/standard-test-docker/vars/main.yml deleted file mode 100644 index 00e3f14..0000000 --- a/roles/standard-test-docker/vars/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -log: "{{artifacts}}/docker.log" -subjects: [] -docker_ssh_port: 2222 diff --git a/roles/standard-test-selector/README.md b/roles/standard-test-selector/README.md deleted file mode 100644 index 7edd61a..0000000 --- a/roles/standard-test-selector/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Ansible role for selecting tests to be run - -Put this role in your test_local.yml playbook. - -You'll need to have the following input variables defined: - -* tests_docker: A list of tests to run only in a docker container (optional) -* tests_not_docker: A list of tests to run only when NOT in a docker container (optional) -* tests_atomic: A list of tests to run only on Atomic Host (optional) -* tests_not_atomic: A list of tests to run only when NOT on Atomic Host (optional) -* tests_all: A list of tests to always run (optional) - -When the role is completed, the following variable will be set: - -* selected_tests: The list of selected tests - -Run another role in your playbook after this role to run the list of selected tests. For example, standard-test-rhts. - -```yaml ---- -# This first play always runs on the local staging system -- hosts: localhost - - roles: - - role: standard-test-selector - tests_docker: - - dockertest1 - - dockertest2 - tests_not_docker: - - nondockertest1 - - nondockertest2 - tests_atomic: - - atomictest1 - - atomictest2 - tests_not_atomic: - - nonatomictest1 - - nonatomictest2 - tests_all: - - alltest1 - - alltest2 - - - role: standard-test-beakerlib - tests: "{{ selected_tests }}" - required_packages: - - package1 # alltest1 needs foo command -``` diff --git a/roles/standard-test-selector/defaults/main.yml b/roles/standard-test-selector/defaults/main.yml deleted file mode 100644 index cc533ff..0000000 --- a/roles/standard-test-selector/defaults/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -tests_docker: [] # input: tests to run only in docker container -tests_not_docker: [] # input: tests to run only when not in docker -tests_atomic: [] # input: tests to run only in Atomic Host -tests_not_atomic: [] # input: tests to run only when not in Atomic Host -tests_all: [] # input: tests to always run -selected_tests: [] # output: list of selected tests diff --git a/roles/standard-test-selector/tasks/main.yml b/roles/standard-test-selector/tasks/main.yml deleted file mode 100644 index 92f5cc1..0000000 --- a/roles/standard-test-selector/tasks/main.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -- name: Set initial list of tests to run in all environments - set_fact: - selected_tests: "{{ tests_all }}" - -- name: Check if running in docker container - shell: grep -q /docker /proc/self/cgroup - register: docker_check_result - ignore_errors: True - -- name: Add tests to run only when in docker container - set_fact: - selected_tests: "{{ selected_tests }} + {{ tests_docker }}" - when: docker_check_result|succeeded - -- name: Add tests to run when not in docker container - set_fact: - selected_tests: "{{ selected_tests }} + {{ tests_not_docker }}" - when: docker_check_result|failed - -- name: Check if running in Atomic Host - shell: grep -q -i '^VARIANT.*atomic' /etc/os-release - register: atomic_check_result - ignore_errors: True - -- name: Add tests to run only when in Atomic Host - set_fact: - selected_tests: "{{ selected_tests }} + {{ tests_atomic }}" - when: atomic_check_result|succeeded - -- name: Add tests to run when not in Atomic Host - set_fact: - selected_tests: "{{ selected_tests }} + {{ tests_not_atomic }}" - when: atomic_check_result|failed - -- name: Make sure list of selected tests is unique - set_fact: - selected_tests: "{{ selected_tests | unique }}"