# Changes that run through devstack-tempest are likely to have an impact on
# the devstack part of the job, so we keep devstack in the main play to
# avoid zuul retrying on legitimate failures.
- hosts: all
  roles:
    - run-devstack
    - run-contrail

# We run tests only on one node, regardless how many nodes are in the system
- hosts: tempest
  pre_tasks:
    - set_fact:
        devstack_openrc: "{{ devstack_base_dir }}/devstack/openrc"
        tempest_dir: "{{ devstack_base_dir }}/tempest"
        tempest_conf: "{{ devstack_base_dir }}/tempest/etc/tempest.conf"

    - name: Create Public external network
      # DevStack has been configured to not create default networks while stacking
      # This will cause oslo.config to pass empty string instead of UUID
      # to every test which needs public network.
      shell: |
        set -e
        set -x
        source {{ devstack_openrc }} admin admin; \
        openstack network create --provider-network-type vlan \
                                 --provider-segment 1200 \
                                 --provider-physical-network public \
                                 --external --share --enable --default ext-public
      args:
        executable: /bin/bash

    - name: Create subnet with IPv4 for ext-public network
      shell: |
        set -e
        set -x
        source {{ devstack_openrc }} admin admin; \
                openstack subnet create --subnet-range 192.168.0.0/16 \
                                        --network ext-public \
                                        --ip-version 4 --dhcp ep-subnet
      args:
        executable: /bin/bash

    - name: Verify tempest config and update extensions list
      become: yes
      shell: |
        set -e
        set -x
        tempest verify-config --replace-ext --update --output {{ tempest_conf }}
      args:
        chdir: "{{ tempest_dir }}"
        executable: /bin/bash

    - name: Set ext-public network as tempest public_network_id
      become: yes
      shell: |
        set -e
        set -x
        source {{ devstack_openrc }} admin admin; \
        ext_net_id=$(openstack network list --name ext-public -c ID -f value)
        sed -i "s/^public_network_id.*/public_network_id = $ext_net_id/" {{ tempest_conf }}
      args:
        executable: /bin/bash
  roles:
    - setup-tempest-run-dir
    - setup-tempest-data-dir
    - acl-devstack-files
    - run-tempest
