- name: "OpenStack integration (Yoga)"
  run:
    when: "${FORCE_RUN} or change_in(['/metadata.mk', '/lib.Makefile', '/networking-calico/', '/.semaphore/semaphore.yml.d/blocks/40-openstack.yml'], {pipeline_file: 'ignore'})"
  dependencies:
    - Prerequisites
  task:
    agent:
      machine:
        type: f1-standard-2
        os_image: ubuntu2204
    prologue:
      commands:
        - cd networking-calico
    jobs:
      - name: "OpenStack: Unit and FV tests (tox) on Yoga"
        commands:
          - ../.semaphore/run-and-monitor tox.log make tox-yoga
      - name: "OpenStack: Mainline ST (DevStack + Tempest) on Yoga"
        commands:
          # For some reason python3-wrapt is pre-installed on a Semaphore ubuntu2004 node, but with
          # a version (1.11.2) that is different from the version that OpenStack needs (1.13.3), and
          # this was causing the DevStack setup to fail, because pip doesn't know how to uninstall
          # or replace the existing version.  Happily we do know that, so let's do it upfront here.
          - sudo apt-get remove -y python3-wrapt || true
          # Install all the packages that would trigger an initramfs update using a workaround
          # for limited /boot partition space in the ubuntu2004 image
          - sudo apt update
          - sudo rsync -av /boot/ /boot2/
          - sudo mount --bind /boot2 /boot
          - sudo apt install -y cryptsetup lsscsi open-iscsi thin-provisioning-tools
          - sudo umount /boot
          - sudo rsync -av /boot2/ /boot/ --exclude "*.new" --exclude "*.dpkg-bak" --delete --inplace
          - sudo rm -rf /boot2/
          # Set NC_PLUGIN_REPO and NC_PLUGIN_REF so that DevStack will use the networking-calico
          # code from the current PR or branch.  The following checkout is to make sure of having a
          # local ref that we can specify.
          - git checkout -b devstack-test
          - export NC_PLUGIN_REPO=$(dirname $(pwd))
          - export NC_PLUGIN_REF=$(git rev-parse --abbrev-ref HEAD)
          - sudo git config --system --add safe.directory ${NC_PLUGIN_REPO}/.git
          # The BIRD config in our DevStack setup is thoroughly broken and generates loads of errors
          # in the log.  But we don't need it for a single node setup anyway, so let's disable it.
          - export CALICO_BGP_MODE=none
          - TEMPEST=true OPENSTACK_RELEASE=yoga ./devstack/bootstrap.sh
    epilogue:
      on_fail:
        commands:
          - mkdir logs
          - sudo journalctl > logs/journalctl.txt
          - artifact push job logs

- name: "OpenStack integration (Caracal)"
  run:
    when: "${FORCE_RUN} or change_in(['/metadata.mk', '/lib.Makefile', '/networking-calico/', '/.semaphore/semaphore.yml.d/blocks/40-openstack.yml'], {pipeline_file: 'ignore'})"
  dependencies:
    - Prerequisites
  task:
    agent:
      machine:
        type: f1-standard-2
        os_image: ubuntu2204
    prologue:
      commands:
        - cd networking-calico
    jobs:
      - name: "OpenStack: Unit and FV tests (tox) on Caracal"
        commands:
          - ../.semaphore/run-and-monitor tox.log make tox-caracal
      - name: "OpenStack: Mainline ST (DevStack + Tempest) on Caracal"
        commands:
          # For some reason python3-wrapt is pre-installed on a Semaphore ubuntu2004 node, but with
          # a version (1.11.2) that is different from the version that OpenStack needs (1.13.3), and
          # this was causing the DevStack setup to fail, because pip doesn't know how to uninstall
          # or replace the existing version.  Happily we do know that, so let's do it upfront here.
          - sudo apt-get remove -y python3-wrapt || true
          # Set NC_PLUGIN_REPO and NC_PLUGIN_REF so that DevStack will use the networking-calico
          # code from the current PR or branch.  The following checkout is to make sure of having a
          # local ref that we can specify.
          - git checkout -b devstack-test
          - export NC_PLUGIN_REPO=$(dirname $(pwd))
          - export NC_PLUGIN_REF=$(git rev-parse --abbrev-ref HEAD)
          - sudo git config --system --add safe.directory ${NC_PLUGIN_REPO}/.git
          # The BIRD config in our DevStack setup is thoroughly broken and generates loads of errors
          # in the log.  But we don't need it for a single node setup anyway, so let's disable it.
          - export CALICO_BGP_MODE=none
          - TEMPEST=true OPENSTACK_RELEASE=caracal ./devstack/bootstrap.sh
    epilogue:
      always:
        commands:
          - mkdir logs
          - sudo journalctl > logs/journalctl.txt
          - artifact push job logs
