(CAT-2383) PDK update for puppetcore changes #238
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Integration Testing" | |
| on: | |
| pull_request: | |
| branches: | |
| - "main" | |
| workflow_call: | |
| workflow_dispatch: | |
| jobs: | |
| setup_matrix: | |
| name: "Setup Test Matrix" | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| matrix: ${{ steps.get-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout Source | |
| uses: actions/checkout@v3 | |
| if: ${{ github.repository_owner == 'puppetlabs' }} | |
| - name: Activate Ruby 3.2 | |
| uses: ruby/setup-ruby@v1 | |
| if: ${{ github.repository_owner == 'puppetlabs' }} | |
| with: | |
| ruby-version: "3.2" | |
| bundler-cache: true | |
| - name: Print bundle environment | |
| if: ${{ github.repository_owner == 'puppetlabs' }} | |
| run: | | |
| echo ::group::bundler environment | |
| bundle env | |
| echo ::endgroup:: | |
| - name: Setup Integration Test Matrix | |
| id: get-matrix | |
| run: | | |
| if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then | |
| echo "matrix={'platform':['ubuntu-2204-lts'],'collection':['puppetcore8-nightly']}" >> $GITHUB_OUTPUT | |
| else | |
| echo "matrix={}" >> $GITHUB_OUTPUT | |
| fi | |
| Integration: | |
| needs: | |
| - setup_matrix | |
| if: ${{ needs.setup_matrix.outputs.matrix != '{}' }} | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.setup_matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout Source | |
| uses: actions/checkout@v3 | |
| - name: Activate Ruby 3.2 | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.2" | |
| bundler-cache: true | |
| - name: Print bundle environment | |
| run: | | |
| echo ::group::bundler environment | |
| bundle env | |
| echo ::endgroup:: | |
| - name: Create the fixtures directory | |
| run: | | |
| bundle exec rake spec_prep | |
| - name: Provision test environment | |
| env: | |
| BOLT_GEM: "1" | |
| run: | | |
| bundle exec bolt --modulepath spec/fixtures/modules plan run ntp::acceptance::provision_integration image=${{ matrix.platform }} | |
| - name: Install PE | |
| env: | |
| BOLT_GEM: "1" | |
| run: | | |
| bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_server | |
| - name: Resolve PE master target | |
| id: pe-master | |
| run: | | |
| ruby -ryaml -e ' | |
| inv = YAML.load_file("spec/fixtures/litmus_inventory.yaml") | |
| targets = inv["groups"].flat_map{|g| g["targets"] rescue []}.compact | |
| t = targets.find{|x| x.dig("vars","role")=="ntpserver"} | |
| abort "No ntpserver target found in inventory" unless t | |
| puts "master_uri=#{t["uri"]}" | |
| ' >> $GITHUB_OUTPUT | |
| # 1) Warm up services BEFORE classification (2 quick runs) | |
| - name: Warm up PE master (first convergence) | |
| env: | |
| BOLT_GEM: "1" | |
| shell: bash | |
| run: | | |
| MASTER='${{ steps.pe-master.outputs.master_uri }}' | |
| MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/} | |
| for i in 1 2; do | |
| echo "puppet agent -t (warm-up run $i) on $MASTER" | |
| bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \ | |
| -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER" | |
| sleep 10 | |
| done | |
| # 2) Classify master with the pe_repo platform using RBAC token | |
| - name: Classify PE Master with pe_repo::platform (via RBAC token) | |
| env: | |
| BOLT_GEM: "1" | |
| # If your install plan sets a different admin password, override here: | |
| PE_ADMIN_PASSWORD: "Puppetlabs123!" | |
| shell: bash | |
| run: | | |
| MASTER='${{ steps.pe-master.outputs.master_uri }}' | |
| MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/} | |
| if [[ -z "$MASTER" ]]; then echo "Empty master target"; exit 1; fi | |
| # Map matrix platform -> PE platform tag -> class suffix | |
| INPUT="${{ matrix.platform }}" # e.g. ubuntu-2204-lts | |
| OS="${INPUT%%-*}" # ubuntu | |
| VER="${INPUT#*-}" ; VER="${VER%-lts}" # 2204 | |
| TAG="${OS}-${VER:0:2}.${VER:2:2}-amd64" # ubuntu-22.04-amd64 | |
| SUFFIX="${TAG//-/_}" ; SUFFIX="${SUFFIX//./}" # ubuntu_2204_amd64 | |
| CLASS="pe_repo::platform::${SUFFIX}" | |
| echo "Classifying master with: ${CLASS} (platform tag: ${TAG})" | |
| # Run remotely under Bash so we can use pipefail and here-strings | |
| bundle exec bolt command run "/bin/bash -lc ' | |
| set -euo pipefail | |
| export PATH=/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin:\$PATH | |
| CACERT=\$(/opt/puppetlabs/bin/puppet config print localcacert) | |
| # Acquire RBAC token via API (retry while services come up) | |
| LOGIN_PAYLOAD=\$(ruby -e \"puts({login: \\\"admin\\\", password: \\\"${PE_ADMIN_PASSWORD}\\\", lifetime: \\\"30m\\\"}.to_json)\") | |
| for i in {1..10}; do | |
| RESP=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \ | |
| -H \"Content-Type: application/json\" \ | |
| -d \"\$LOGIN_PAYLOAD\" \ | |
| https://localhost:4433/rbac-api/v1/auth/token) || true | |
| TOKEN=\$(ruby -rjson -e \"j=STDIN.read; puts(JSON.parse(j)[\\\"token\\\"] rescue '')\" <<< \"\$RESP\") | |
| [[ -n \"\$TOKEN\" ]] && break | |
| echo \"Waiting for RBAC to issue token... (\$i/10)\" >&2 | |
| sleep 6 | |
| done | |
| if [[ -z \"\$TOKEN\" ]]; then | |
| echo \"Failed to obtain RBAC token; last response:\" >&2 | |
| echo \"\$RESP\" >&2 | |
| exit 1 | |
| fi | |
| echo \"RBAC token acquired\" | |
| # Find the PE Master group id | |
| GROUPS=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \ | |
| -H \"X-Authentication: \$TOKEN\" \ | |
| https://localhost:4433/classifier-api/v1/groups) | |
| ID=\$( | |
| ruby -rjson -e \"g=JSON.parse(STDIN.read); pe=g.find{|x| x['name']=='PE Master'} or abort('PE Master group not found'); puts pe['id']\" \ | |
| <<< \"\$GROUPS\" | |
| ) | |
| echo \"PE Master group id: \$ID\" | |
| # Merge the platform class into the group's classes | |
| CURR=\$(curl -sS --fail-with-body --cacert \"\$CACERT\" \ | |
| -H \"X-Authentication: \$TOKEN\" \ | |
| https://localhost:4433/classifier-api/v1/groups/\$ID) | |
| UPDATED=\$( | |
| CLASS=\"${CLASS}\" ruby -rjson -e \"g=JSON.parse(STDIN.read); g['classes']||={}; g['classes'][ENV['CLASS']]||={}; print({id: g['id'], classes: g['classes']}.to_json)\" \ | |
| <<< \"\$CURR\" | |
| ) | |
| # POST the partial update (merge) back to the group | |
| curl -sS --fail-with-body --cacert \"\$CACERT\" \ | |
| -H \"X-Authentication: \$TOKEN\" \ | |
| -H \"Content-Type: application/json\" \ | |
| -X POST -d \"\$UPDATED\" \ | |
| https://localhost:4433/classifier-api/v1/groups/\$ID >/dev/null | |
| echo \"Class ${CLASS} merged into PE Master group\" | |
| '" -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER" | |
| # 3) Converge master again so pe_repo materializes platform content | |
| - name: Converge PE master (stabilize services & pe_repo) | |
| env: | |
| BOLT_GEM: "1" | |
| shell: bash | |
| run: | | |
| MASTER='${{ steps.pe-master.outputs.master_uri }}' | |
| MASTER=${MASTER//\"/}; MASTER=${MASTER//\'/} | |
| echo "puppet agent -t (post-classification) on $MASTER" | |
| bundle exec bolt command run "/opt/puppetlabs/bin/puppet agent -t || true" \ | |
| -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER" | |
| # Verify the agent packages folder exists for your platform | |
| INPUT="${{ matrix.platform }}" # ubuntu-2204-lts | |
| OS="${INPUT%%-*}" # ubuntu | |
| VER="${INPUT#*-}" ; VER="${VER%-lts}" # 2204 | |
| TAG="${OS}-${VER:0:2}.${VER:2:2}-amd64" # ubuntu-22.04-amd64 | |
| bundle exec bolt command run \ | |
| "/bin/bash -lc 'PEV=\$(facter -p pe_server_version 2>/dev/null || echo 2023.8.5); \ | |
| test -d /opt/puppetlabs/server/data/packages/public/\$PEV/${TAG} || \ | |
| (echo Missing pe_repo packages for ${TAG}; ls -ld /opt/puppetlabs/server/data/packages/public/*; exit 1)'" \ | |
| -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER" | |
| - name: Install Agents | |
| env: | |
| BOLT_GEM: "1" | |
| run: | | |
| bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_agent | |
| - name: Install module | |
| run: | | |
| bundle exec rake 'litmus:install_module' | |
| - name: Run integration tests | |
| run: | | |
| bundle exec rake ntp:integration | |
| - name: Remove test environment | |
| if: ${{ always() }} | |
| continue-on-error: true | |
| run: | | |
| bundle exec rake 'litmus:tear_down' |