(CAT-2383) PDK update for puppetcore changes #234
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 | |
| # --- New: classify master with the correct pe_repo::platform::<tag> via the Node Classifier API | |
| - name: Classify PE Master with pe_repo::platform (via classifier API) | |
| env: | |
| BOLT_GEM: "1" | |
| 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 (e.g. ubuntu-2204-lts) -> ubuntu-22.04-amd64 -> ubuntu_2204_amd64 | |
| 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 | |
| SUFFIX="${TAG//-/_}" ; SUFFIX="${SUFFIX//./}" # ubuntu_2204_amd64 | |
| CLASS="pe_repo::platform::${SUFFIX}" | |
| echo "Classifying master with: ${CLASS}" | |
| bundle exec bolt command run " | |
| set -euo pipefail | |
| CERT=\$(/opt/puppetlabs/bin/puppet config print hostcert) | |
| KEY=\$(/opt/puppetlabs/bin/puppet config print hostprivkey) | |
| CACERT=/etc/puppetlabs/puppet/ssl/certs/ca.pem | |
| # 1) Find PE Master group id | |
| GROUPS=\$(curl -s --cert \$CERT --key \$KEY --cacert \$CACERT https://localhost:4433/classifier-api/v1/groups) | |
| ID=\$(/opt/puppetlabs/puppet/bin/ruby -rjson -e ' | |
| g = JSON.parse(STDIN.read) | |
| pe = g.find{|x| x[\"name\"]==\"PE Master\"} | |
| abort(\"PE Master group not found\") unless pe | |
| puts pe[\"id\"] | |
| ' <<< \"\$GROUPS\") | |
| echo \"PE Master group id: \$ID\" | |
| # 2) Merge the class into the group's classes and POST | |
| CURR=\$(curl -s --cert \$CERT --key \$KEY --cacert \$CACERT https://localhost:4433/classifier-api/v1/groups/\$ID) | |
| UPDATED=\$(/opt/puppetlabs/puppet/bin/ruby -rjson -e ' | |
| g = JSON.parse(STDIN.read) | |
| g[\"classes\"] ||= {} | |
| g[\"classes\"][\"'"$CLASS"'\"] ||= {} | |
| puts({\"id\"=>g[\"id\"],\"classes\"=>g[\"classes\"]}.to_json) | |
| ' <<< \"\$CURR\") | |
| curl -s -X POST --cert \$CERT --key \$KEY --cacert \$CACERT \ | |
| -H 'Content-Type: application/json' \ | |
| -d \"\$UPDATED\" \ | |
| https://localhost:4433/classifier-api/v1/groups/\$ID >/dev/null | |
| " -i spec/fixtures/litmus_inventory.yaml --targets "$MASTER" | |
| - 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//\'/} | |
| if [[ -z "$MASTER" ]]; then echo "Empty master target"; exit 1; fi | |
| # Run Puppet agent a couple of times to let the master fully classify and settle | |
| for i in 1 2; do | |
| echo "Puppet agent run $i on master..." | |
| bundle exec bolt command run "puppet agent -t || true" \ | |
| -i spec/fixtures/litmus_inventory.yaml \ | |
| --targets "$MASTER" | |
| sleep 10 | |
| done | |
| # 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 \ | |
| "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' |