- name: Set OS_TEST_TIMEOUT if requested
  set_fact:
    tempest_tox_environment: "{{ tempest_tox_environment | combine({'OS_TEST_TIMEOUT': tempest_test_timeout}) }}"
  when: tempest_test_timeout != ''

- name: Override target branch
  set_fact:
    target_branch: "{{ zuul.override_checkout }}"
  when: zuul.override_checkout is defined

- name: Set TOX_CONSTRAINTS_FILE
  set_fact:
    # Set TOX_CONSTRAINTS_FILE/UPPER_CONSTRAINTS_FILE to stable constraints only
    # for the EM stable branch where old tempest (not master) is used.
    tempest_tox_environment: "{{ tempest_tox_environment | combine({'UPPER_CONSTRAINTS_FILE': constraints_file}) | combine({'TOX_CONSTRAINTS_FILE': constraints_file}) }}"
  when: target_branch in ["stable/ocata", "stable/pike", "stable/queens", "stable/rocky", "stable/stein", "stable/train", "stable/ussuri", "stable/victoria", "stable/wallaby"]

- name: Allow git to read plugin directories
  become: true
  command: git config --system --add safe.directory {{heat_tempest_plugin}}

- name: Install plugins
  command: tox -evenv-tempest -- pip install -c{{constraints_file}} {{heat_tempest_plugin}}
  become: true
  args:
    chdir: "{{devstack_base_dir}}/tempest"
  environment: "{{ tempest_tox_environment }}"

- name: Run heat tests
  command: tox -evenv-tempest -- stestr --test-path={{devstack_base_dir}}/heat/heat_integrationtests \
            --top-dir={{devstack_base_dir}}/heat \
            --group_regex='heat_tempest_plugin\.tests\.api\.test_heat_api[._]([^_]+)' run
  args:
    chdir: "{{devstack_base_dir}}/tempest"
  become: true
  environment: "{{ tempest_tox_environment }}"
