---
- name: Cloning tempest from redhat-openstack repository
  git:
    repo: 'https://github.com/redhat-openstack/tempest.git'
    dest: '{{ working_dir }}/tempest_git'
    version: '{{ tempest_version }}'
  when: release == 'newton'

- name: Cloning tempest from openstack repository
  git:
    repo: 'https://git.openstack.org/openstack/tempest'
    dest: '{{ working_dir }}/tempest_git'
    version: '{{ tempest_version }}'
  when: release != 'newton'

- name: Cloning python-tempestconf
  git:
    repo: 'https://git.openstack.org/openstack/python-tempestconf'
    dest: '{{ working_dir }}/tempestconf_git'
    version: '{{ tempest_conf_version }}'
  when: release != 'newton'

- name: Check if virtualenv is in the system
  shell: "{{ python_cmd }} -m virtualenv --version"
  register: virtualenv_exist
  failed_when: false
  changed_when: false

- when: virtualenv_exist.rc != 0
  name: Install virtualenv
  package:
    state: present
    name: >
        {% if ansible_python.version.major == 3 %}
        python3-virtualenv
        {% else %}
        python-virtualenv
        {% endif %}

- name: Clone tempest plugins
  git:
    repo: "{{ item }}"
    dest: "{{ working_dir }}/{{ item.split('/')[-1] }}"
    version: master
  with_items: "{{ tempest_plugins_git }}"
  when:
    - tempest_format == 'venv'

- name: Install packages required for create venv
  package:
    state: present
    name:
      - gcc
      - libffi-devel
      - openssl-devel

- name: Set tempest init command
  set_fact:
    tempest_init: "{{ working_dir }}/tempest_git/tools/{% if release == 'newton' %}configure-tempest-directory{% else %}with_venv.sh tempest init{% endif %}"

- name: Set tempestconf call
  set_fact:
    tempestconf: >
      {% if release == 'newton' %}{{ working_dir }}/tools/config_tempest.py{% else %}{{ working_dir }}/tempest_git/tools/with_venv.sh discover-tempest-config{% endif %}
