---
- hosts: localhost
  remote_user: root

  # The following tasks set up the environment for the avocado_qemu
  pre_tasks:
  - name: Install qemu-kvm and pip3 # This step is to avoid failures when building from a private branch
    package:
      name: "{{ item }}"
      state: latest
    with_items:
      - qemu-kvm
      - python3-pip

  - name: Get N-V-R from qemu-kvm
    shell: "rpm -q {{ item }} qemu-kvm"
    args:
      warn: no
    register: nvr_values
    with_items:
      - '--queryformat=%{NAME}'
      - '--queryformat=%{VERSION}'
      - '--queryformat=%{RELEASE}'

  - set_fact:
      N: "{{ nvr_values.results[0].stdout }}"
      V: "{{ nvr_values.results[1].stdout }}"
      R: "{{ nvr_values.results[2].stdout }}"

  - name: Install qemu-kvm-tests rpm from brewroot URL
    yum:
      name: "http://download.devel.redhat.com/brewroot/packages/{{ N }}/{{ V }}/{{ R }}/x86_64/{{ N }}-tests-{{ V }}-{{ R }}.x86_64.rpm"
      state: present

  - name: Upgrade pip
    pip:
      name: pip
      executable: pip3
      state: latest

  - name: Avocado installation using pip
    pip:
      name: avocado-framework
      executable: pip3
      state: present

  - name: Disable IPv6 in sysctl.conf on OSCI node
    sysctl:
      name: "{{ item }}"
      value: 1
      sysctl_set: yes
      state: present
      reload: yes
    with_items:
      - net.ipv6.conf.all.disable_ipv6
      - net.ipv6.conf.default.disable_ipv6

  roles:
  - role: standard-test-basic
    tags:
    - classic
    tests:
    - avocado_qemu:
       dir: ./
       run: "avocado --show all run -p qemu_bin=/usr/libexec/qemu-kvm /usr/lib64/qemu-kvm/tests-src/tests/acceptance/"
    - qemu_iotests:
       dir: ./
       run: "/bin/bash runtest.sh"
    required_packages:
    - qemu-kvm
    - qemu-kvm-tests