- hosts: all
  name: Autoconverted job legacy-grenade-dsvm-ironic-inspector from old job gate-grenade-dsvm-ironic-inspector-ubuntu-xenial
  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 \
              git://git.openstack.org \
              openstack-infra/devstack-gate
        executable: /bin/bash
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-vars-early
            # Set this early so that we do not have to be as careful with builder ordering in jobs.
          export GRENADE_PLUGINRC="enable_grenade_plugin ironic https://git.openstack.org/openstack/ironic"

          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-extra-vars
            export PROJECTS="openstack-dev/grenade $PROJECTS"
          export DEVSTACK_GATE_GRENADE=pullup
          export DEVSTACK_GATE_OS_TEST_TIMEOUT=2400
          export DEVSTACK_GATE_TEMPEST_BAREMETAL_BUILD_TIMEOUT=1200
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_BUILD_DEPLOY_RAMDISK=False"
          export DEVSTACK_GATE_TLSPROXY=0

          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-extra-vars
            export GRENADE_PLUGINRC+=$'\n'"enable_grenade_plugin ironic-inspector https://git.openstack.org/openstack/ironic-inspector"

          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-extra-vars
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_DEPLOY_DRIVER_ISCSI_WITH_IPA=True"
          # Standardize VM size for each supported ramdisk
          case "tinyipa" in
              'tinyipa')
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_SPECS_RAM=384"
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_RAMDISK_TYPE=tinyipa"
                  ;;
              'tinyipa256')
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_SPECS_RAM=256"
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_RAMDISK_TYPE=tinyipa"
                  ;;
              'coreos')
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_SPECS_RAM=1280"
                  export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_RAMDISK_TYPE=coreos"
                  ;;
          # if using a ramdisk without a known good value, use the devstack
          # default by not exporting any value for IRONIC_VM_SPECS_RAM
          esac

          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-vars-early
            # use tempest plugin
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"TEMPEST_PLUGINS+=' /opt/stack/new/ironic-tempest-plugin'"
            export TEMPEST_CONCURRENCY=1
          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          cat << 'EOF' >> ironic-extra-vars
            export PROJECTS="openstack/ironic-inspector $PROJECTS"
          export PROJECTS="openstack/python-ironic-inspector-client $PROJECTS"
          export DEVSTACK_GATE_IRONIC_INSPECTOR=1

          export DEVSTACK_LOCAL_CONFIG+=$'\n'"enable_plugin ironic-inspector git://git.openstack.org/openstack/ironic-inspector"

          export IRONIC_INSPECTOR_AUTO_DISCOVERY={inspector-auto-discovery}
          if [ "$IRONIC_INSPECTOR_AUTO_DISCOVERY" == "1" ]; then
               # discovery test requires sudo for iptables and virsh
               export DEVSTACK_GATE_REMOVE_STACK_SUDO=0
               # enable enroll hook
               export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_NODE_NOT_FOUND_HOOK=enroll"
               # we are deleting node from ironic for simulate node discovery,
               # so inspector has to sync cache asap
               export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_CLEAN_UP_PERIOD=5"
          fi

          # Make IPXE configuration consistent between Mitaka and Master
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_IPXE_ENABLED=True"
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_RAMDISK_ELEMENT=ironic-agent"
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_DHCP_FILTER=iptables"

          EOF
        chdir: '{{ ansible_user_dir }}/workspace'
      environment: '{{ zuul | zuul_legacy_vars }}'

    - shell:
        cmd: |
          set -e
          set -x
          export PROJECTS="openstack/ironic $PROJECTS"
          export PROJECTS="openstack/ironic-lib $PROJECTS"
          export PROJECTS="openstack/ironic-python-agent $PROJECTS"
          export PROJECTS="openstack/ironic-tempest-plugin $PROJECTS"
          export PROJECTS="openstack/python-ironicclient $PROJECTS"
          export PROJECTS="openstack/pyghmi $PROJECTS"
          export PROJECTS="openstack/virtualbmc $PROJECTS"
          export PYTHONUNBUFFERED=true
          export DEVSTACK_GATE_TEMPEST=1
          export DEVSTACK_GATE_IRONIC=1
          export DEVSTACK_GATE_NEUTRON=1
          export DEVSTACK_GATE_VIRT_DRIVER=ironic
          export DEVSTACK_GATE_CONFIGDRIVE=1
          # TODO(dtantsur): change to ipmi in Rocky
          export DEVSTACK_GATE_IRONIC_DRIVER=pxe_ipmitool
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_DEFAULT_DEPLOY_INTERFACE=iscsi"

          export BRANCH_OVERRIDE="{{ zuul.override_checkout | default('default') }}"
          if [ "$BRANCH_OVERRIDE" != "default" ] ; then
              export OVERRIDE_ZUUL_BRANCH=$BRANCH_OVERRIDE
          fi

          if [[ "$ZUUL_BRANCH" != "stable/ocata" && "$BRANCH_OVERRIDE" != "stable/ocata" ]]; then
              export DEVSTACK_GATE_TLSPROXY=1
          fi

          if [ "partition" == "wholedisk" ] ; then
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_TEMPEST_WHOLE_DISK_IMAGE=True"
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_EPHEMERAL_DISK=0"
          else
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_TEMPEST_WHOLE_DISK_IMAGE=False"
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_EPHEMERAL_DISK=1"
          fi

          if [ -n "" ] ; then
            export DEVSTACK_GATE_IRONIC_BUILD_RAMDISK=1
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_BUILD_RAMDISK=True"
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"USE_SUBNETPOOL=False"
          else
            export DEVSTACK_GATE_IRONIC_BUILD_RAMDISK=0
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_INSPECTOR_BUILD_RAMDISK=False"
          fi

          if [ "bios" == "uefi" ] ; then
            export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_BOOT_MODE=uefi"
          fi

          # NOTE(mgoddard): We cannot test node traits when upgrading from
          # pike, as node traits support was added in queens.
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_DEFAULT_TRAITS=\"\""

          export DEVSTACK_PROJECT_FROM_GIT=""
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_VM_COUNT=7"
          export DEVSTACK_LOCAL_CONFIG+=$'\n'"IRONIC_AUTOMATED_CLEAN_ENABLED=False"

          # Ensure the ironic-vars-EARLY file exists
          touch ironic-vars-early
          # Pull in the EARLY variables injected by the optional builders
          source ironic-vars-early

          export DEVSTACK_LOCAL_CONFIG+=$'\n'"enable_plugin ironic git://git.openstack.org/openstack/ironic"

          # Ensure the ironic-EXTRA-vars file exists
          touch ironic-extra-vars
          # Pull in the EXTRA variables injected by the optional builders
          source ironic-extra-vars

          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 }}'
