- hosts: all
  tasks:

    - name: Ensure legacy workspace directory
      file:
        path: '{{ ansible_user_dir }}/workspace'
        state: directory

    - shell:
        cmd: |
          set -e
          set -x
          cat > clonemap.yaml << EOF
          clonemap:
            - name: openstack-infra/devstack-gate
              dest: devstack-gate
          EOF
          /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml --cache-dir /opt/git \
              https://git.openstack.org \
              openstack-infra/devstack-gate
        executable: /bin/bash
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          set -e
          set -x
          cat << 'EOF' >>"/tmp/dg-local.conf"
          [[local|localrc]]
          enable_plugin monasca-api https://git.openstack.org/openstack/monasca-api
          enable_plugin monasca-log-api https://git.openstack.org/openstack/monasca-log-api
          TEMPEST_PLUGINS+='/opt/stack/new/monasca-tempest-plugin'
          EOF
        executable: /bin/bash
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          set -e
          set -x
          export PYTHONUNBUFFERED=true

          export ENABLED_SERVICES=tempest
          export DEVSTACK_GATE_NEUTRON=1
          export DEVSTACK_GATE_TEMPEST=1
          export DEVSTACK_GATE_EXERCISES=0
          export DEVSTACK_GATE_TEMPEST_REGEX="monasca_tempest_tests.tests.log_api"

          export PROJECTS="openstack/monasca-api $PROJECTS"
          export PROJECTS="openstack/monasca-persister $PROJECTS"
          export PROJECTS="openstack/monasca-common $PROJECTS"
          export PROJECTS="openstack/monasca-agent $PROJECTS"
          export PROJECTS="openstack/monasca-notification $PROJECTS"
          export PROJECTS="openstack/monasca-thresh $PROJECTS"
          export PROJECTS="openstack/monasca-statsd $PROJECTS"
          export PROJECTS="openstack/python-monascaclient $PROJECTS"
          export PROJECTS="openstack/monasca-grafana-datasource $PROJECTS"
          export PROJECTS="openstack/monasca-ui $PROJECTS"
          export PROJECTS="openstack/monasca-log-api $PROJECTS"
          export PROJECTS="openstack/monasca-kibana-plugin $PROJECTS"
          export PROJECTS="openstack/monasca-tempest-plugin $PROJECTS"

          function post_test_hook {
              source $BASE/new/monasca-log-api/contrib/post_test_hook.sh
          }
          export -f post_test_hook

          cp devstack-gate/devstack-vm-gate-wrap.sh ./safe-devstack-vm-gate-wrap.sh
          ./safe-devstack-vm-gate-wrap.sh
        executable: /bin/bash
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

