Add changes to *_prep also #1
This file contains 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
# This is a generic workflow for Puppet module acceptance operations. | ||
name: "Module Acceptance Prep" | ||
on: | ||
workflow_call: | ||
inputs: | ||
runs_on: | ||
description: "The operating system used for the runner." | ||
required: false | ||
default: "ubuntu-latest" | ||
type: "string" | ||
flags: | ||
description: "Additional flags to pass to matrix_from_metadata_v2." | ||
required: false | ||
default: '' | ||
type: "string" | ||
kernel_modules: | ||
description: "Volume map host kernel /lib/modules into docker container" | ||
default: true | ||
type: boolean | ||
disable_apparmor: | ||
description: "Disable and stop apparmor" | ||
default: false | ||
type: boolean | ||
continuewithownsetupsteps: | ||
description: "Running Extra Setup Steps module_acceptance" | ||
required: false | ||
default: true | ||
type: boolean | ||
continueintooriginalsteps: | ||
description: "Continue the run into the Steps from the original module_acceptance" | ||
required: false | ||
default: false | ||
type: boolean | ||
# Proposed Steps | ||
continueintoproposedsteps: | ||
description: "Continue the run into the Steps from the proposed module_acceptance" | ||
required: false | ||
default: false | ||
type: boolean | ||
provision_environment__task: | ||
description: "Rake Task to Provision the Environment" | ||
required: false | ||
default: '' | ||
type: "string" | ||
install_agent__task: | ||
description: "Rake Task to install the Agent" | ||
required: false | ||
default: '' | ||
type: "string" | ||
install_module__task: | ||
description: "Rake Task to install the Modules" | ||
required: false | ||
default: '' | ||
type: "string" | ||
acceptance__task: | ||
description: "Rake Task to Run the Acceptance Tests" | ||
required: false | ||
default: '' | ||
type: "string" | ||
tear_down__task: | ||
description: "Rake Task to Run the Tear Down the test environments" | ||
required: false | ||
default: '' | ||
type: "string" | ||
matrix_from_metadata: | ||
description: 'Commands to run to get the test matrix' | ||
default: 'matrix_from_metadata_v2' | ||
type: "string" | ||
# Start of the Debugging Parameters | ||
prepcommand1: | ||
description: "Additional PrepCommand to run as a preparation Part 1" | ||
required: false | ||
default: 'echo' | ||
type: "string" | ||
prepcommand2: | ||
description: "Additional PrepCommand to run as a preparation Part 2" | ||
required: false | ||
default: 'echo' | ||
type: "string" | ||
command: | ||
description: "Additional Command to run as a preparation/test" | ||
required: false | ||
default: 'echo' | ||
type: "string" | ||
postcommand: | ||
description: "Additional Command to run as cleanup" | ||
required: false | ||
default: 'echo' | ||
type: "string" | ||
preinstallpecommands: | ||
description: "Additional Commands to install or config PE, running before the installation" | ||
required: false | ||
default: 'echo Before Install PE ;' | ||
type: "string" | ||
installpecommands: | ||
description: "Additional Commands to install or config PE, running after the installation" | ||
required: false | ||
default: 'echo Install PE done ;' | ||
type: "string" | ||
deploy_petargetinv: | ||
description: "Path to Inventory to use to run deploy_pe for PE installation. It must contain the target deploy_petarget." | ||
required: false | ||
default: 'inventory.yaml' | ||
type: "string" | ||
deploy_petarget: | ||
description: "Target to run run deploy_pe for PE installation" | ||
required: false | ||
default: 'localhost' | ||
type: "string" | ||
deploy_peversion: | ||
description: "P.E. version to install for deploy_pe" | ||
required: false | ||
default: '-' | ||
type: "string" | ||
peadm_peversion: | ||
description: "P.E. version to install for peadm" | ||
required: false | ||
default: '-' | ||
type: "string" | ||
opensourcepuppetversion: | ||
description: "Open Source Puppet version to install, Default as empty to install Puppet Enterprise instead, and set 'L' for latest " | ||
required: false | ||
default: '' | ||
type: "string" | ||
jobs: | ||
setup_matrix: | ||
name: "Setup Test Matrix" | ||
runs-on: ${{ inputs.runs_on }} | ||
outputs: | ||
acceptance_matrix: ${{ steps.get-matrix.outputs.spec_matrix }} | ||
acceptance__matrix: ${{ steps.get-matrix.outputs.matrix }} | ||
ruby_version: ${{ steps.get-puppet_ruby_version.outputs.ruby_version }} | ||
puppet_version: ${{ steps.get-puppet_ruby_version.outputs.puppet_version }} | ||
env: | ||
BUNDLE_WITHOUT: release_prep | ||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: "Setup ruby" | ||
uses: "ruby/setup-ruby@v1" | ||
with: | ||
ruby-version: "2.7" | ||
bundler-cache: true | ||
- name: "Bundle environment" | ||
run: | | ||
echo ::group::bundler environment | ||
bundle env | ||
echo ::endgroup:: | ||
- name: Setup Test Matrix | ||
id: get-matrix | ||
run: | | ||
bundle exec ${{ inputs.matrix_from_metadata }} ${{ inputs.flags }} | ||
- name: Setup Ruby Version and Setup Puppet Version | ||
id: get-puppet_ruby_version | ||
run: | | ||
echo ${{ toJSON(steps.get-matrix.outputs.spec_matrix ) }} | jq -r '.include | .[0] | to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_OUTPUT | ||
acceptance: | ||
name: "Acceptance tests (${{matrix.platforms.label}}, ${{matrix.collection}}) - ruby: ${{needs.setup_matrix.outputs.ruby_version}} puppet: ${{needs.setup_matrix.outputs.puppet_version}} " | ||
needs: "setup_matrix" | ||
runs-on: ${{ inputs.runs_on }} | ||
timeout-minutes: 180 | ||
strategy: | ||
fail-fast: false | ||
matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance__matrix ) }} | ||
# matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance_matrix ) }} | ||
# spec_matrix: ${{ fromJson( needs.setup_matrix.outputs.acceptance__matrix ) }} | ||
env: | ||
BUNDLE_WITHOUT: release_prep | ||
PUPPET_GEM_VERSION: ${{needs.setup_matrix.outputs.puppet_version}} | ||
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set? | ||
steps: | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: "Disable Apparmor" | ||
if: ${{ inputs.disable_apparmor }} | ||
run: | | ||
if command -v apparmor_parser >/dev/null ; then | ||
sudo find /etc/apparmor.d/ -maxdepth 1 -type f -exec ln -sf {} /etc/apparmor.d/disable/ \; | ||
sudo apparmor_parser -R /etc/apparmor.d/disable/* || true | ||
sudo systemctl disable apparmor | ||
sudo systemctl stop apparmor | ||
fi | ||
- name: "Setup ruby" | ||
uses: "ruby/setup-ruby@v1" | ||
with: | ||
ruby-version: ${{needs.setup_matrix.outputs.ruby_version}} | ||
bundler-cache: true | ||
- name: "Bundle environment" | ||
run: | | ||
echo ::group::bundler environment | ||
bundle env | ||
echo ::endgroup:: | ||
- name: modify sudo settings | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
sudo sed -i 's/Defaults env_reset//' /etc/sudoers | ||
- name: Create the fixtures directory | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
bundle exec rake spec_prep | ||
- name: install actual bolt | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
wget https://apt.puppet.com/puppet-tools-release-jammy.deb | ||
sudo -E dpkg -i puppet-tools-release-jammy.deb | ||
sudo -E apt-get update | ||
sudo -E apt-get -y install puppet-bolt | ||
sudo -E apt-get -y install curl || sudo -E yum install -y curl || apt-get -y install curl || yum install -y curl | ||
sudo -E apt-get -y install cron | ||
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show | ||
- name: install bolt modules | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
sudo -E mkdir -p spec/fixtures/modules | ||
sudo -E echo ln -s spec/fixtures/modules .modules | ||
sudo -E /usr/local/bin/bolt project init my_project --modules jarretlavallee-deploy_pe,puppetlabs-peadm,aursu-puppet | ||
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules module add jarretlavallee-deploy_pe | ||
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules module add puppetlabs-peadm | ||
sudo -E chmod a+rw ./inventory.yaml | ||
- name: "Run Commands to Check or Cover Pre- PE Installation aka preinstallpecommands" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.preinstallpecommands }} | ||
- name: install pe or opensource puppet | ||
if: ${{ inputs.continuewithownsetupsteps && ( inputs.deploy_peversion != '-' || inputs.opensourcepuppetversion != '' ) }} | ||
run: | | ||
echo "==deploy_peversion=${{ inputs.deploy_peversion }}" ; | ||
echo "==opensourcepuppetversion=${{ inputs.opensourcepuppetversion }}" ; | ||
if [ -z "${{ inputs.opensourcepuppetversion }}" ] ; then | ||
if [ ! "${{ inputs.deploy_petargetinv }}" = "inventory.yaml" -a -e "${{ inputs.deploy_petargetinv }}" ] ; then | ||
cat "${{ inputs.deploy_petargetinv }}" > inventory.yaml || echo "Same files cannot update." ; | ||
elif [ -z "`grep -v '^[ ]*$' ${{ inputs.deploy_petargetinv }}`" ] ; then | ||
echo -e 'groups:\n - name: pe\n targets:\n - uri: localhost\n vars:\n roles:\n - pe' > inventory.yaml ; | ||
fi ; | ||
[ ! -e ./spec/fixtures/litmus_inventory.yaml ] || grep -H -n -v -E 'AALINEAANUMBER' ./spec/fixtures/litmus_inventory.yaml ; | ||
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show | ||
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run facts targets=${{ inputs.deploy_petarget }} | ||
[ "-" = "${{ inputs.deploy_peversion }}" ] || sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run deploy_pe::provision_master targets=${{ inputs.deploy_petarget }} version=${{ inputs.deploy_peversion }} || echo "==Install PE deploy_pe failed==" ; | ||
else | ||
curl -q "https://raw.githubusercontent.com/sooyean-hoo/pe_curl_requests/feature/SYInstallerEnhance/installer/download_pe_tarball.sh" > /tmp/download_pe_tarball.sh ; | ||
export opensourcepuppetversion="${{ inputs.opensourcepuppetversion }}" ; | ||
source /tmp/download_pe_tarball.sh > /tmp/ops.log || echo ; | ||
tail -10 /tmp/ops.log | grep -H -n -v -E 'AALINEAANUMBER' ; | ||
pkg2installOSpuppet=$( cat /tmp/ops.log | grep '====OPENSOURCEPUPPET=pkgurl=' | sed -E 's/====OPENSOURCEPUPPET=pkgurl=//' ) ; | ||
echo "Installing..... ${pkg2installOSpuppet} " ; | ||
installPkg ${pkg2installOSpuppet} || echo ; | ||
upgradePkg || echo ; | ||
for p in puppetserver puppet-agent ; do | ||
installPkg $p || installPkg $p --nobest --skip-broken || echo ; | ||
done ; | ||
puppet --help > /dev/null 2> /dev/null || { | ||
tarfile=`ls -1 ./puppet*tar.gz | head -n 1` ; | ||
tar -zxvf $tarfile ; | ||
cd ${tarfile/.tar.gz/} ; | ||
onepkg=`find -iname 'puppet-agent*' | grep -E 'rpm|deb'| head -1 ` ; | ||
cd `dirname ${onepkg}` ; | ||
ext=${onepkg/*./} | ||
sudocmd=`which sudo` || echo a ; | ||
if [ "$ext" = "rpm" ] ; then | ||
${sudocmd} rpm -i ./pe-puppetserver-* ./puppet-agent-* ./pe-puppet-enterprise-release-* ./pe-java*.rpm ./pe-bouncy-castle-jars-* ; | ||
else | ||
installPkg net-tools ; | ||
${sudocmd} dpkg -i ./pe-puppetserver* ./puppet-agent* ./pe-puppet-enterprise-release* ./pe-java* ./pe-bouncy-castle-jars* ; | ||
installPkg puppet-agent puppetmaster ; | ||
fi; | ||
} || echo "Minimum Puppet Installation using Tar Failed" ; | ||
fi ; | ||
- name: "Run Commands to Check or Cover Post PE Installation aka installpecommands" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.installpecommands }} | ||
- name: "Run prepCommand Part 1 aka prepcommand1" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.prepcommand1 }} | ||
- name: "Run prepCommand Part 2 aka prepcommand2" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.prepcommand2 }} | ||
- name: "Run Command aka command" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.command }} | ||
- name: "Run Commands after the command aka postcommand" | ||
if: ${{ inputs.continuewithownsetupsteps }} | ||
run: | | ||
${{ inputs.postcommand }} | ||
# Proposed Steps from the module_acceptance | ||
- name: "Provision environment" | ||
if: ${{ inputs.continueintoproposedsteps }} | ||
run: | | ||
if [ "${{ inputs.provision_environment__task }}" = "litmus:provision" ] ; then | ||
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then | ||
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}" | ||
else | ||
DOCKER_RUN_OPTS='' | ||
fi | ||
bundle exec rake "litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]" | ||
# Redact password | ||
FILE='spec/fixtures/litmus_inventory.yaml' | ||
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true | ||
else | ||
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then | ||
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}" | ||
else | ||
DOCKER_RUN_OPTS='' | ||
fi | ||
if [ ! -z "${{ inputs.provision_environment__task }}" ] ; then | ||
echo ===cat ${GITHUB_OUTPUT} ; ls -l ${GITHUB_OUTPUT} ; cat ${GITHUB_OUTPUT} || echo "No file ${GITHUB_OUTPUT}"; | ||
source ${GITHUB_OUTPUT} ; echo "from file: ${matrix}" ; echo "inGitHub: ${{matrix}}" ; | ||
echo "spec_matrix: ${{ needs.setup_matrix.outputs.acceptance_matrix }}" ; | ||
echo "matrix: ${{ needs.setup_matrix.outputs.acceptance__matrix }}" ; | ||
echo "============================"; | ||
platformsprovider="${{matrix.platforms.provider}}" | ||
platformsimage="${{ matrix.platforms.image }}" | ||
bundle exec rake "${{ inputs.provision_environment__task }}[${platformsprovider:-},${platformsimage:-},$DOCKER_RUN_OPTS]" ; | ||
fi | ||
fi; | ||
- name: "Install Puppet agent" | ||
if: ${{ inputs.continueintoproposedsteps }} | ||
run: | | ||
[ -z "${{ inputs.install_agent__task }}" ] || bundle exec rake '${{ inputs.install_agent__task }}[${{ matrix.collection }}]' | ||
- name: "Install module" | ||
if: ${{ inputs.continueintoproposedsteps }} | ||
run: | | ||
[ -z "${{ inputs.install_module__task }}" ] || bundle exec rake '${{ inputs.install_module__task }}' | ||
- name: "Run acceptance tests" | ||
if: ${{ inputs.continueintoproposedsteps }} | ||
run: | | ||
[ -z "${{ inputs.acceptance__task }}" ] || bundle exec rake '${{ inputs.acceptance__task }}' | ||
- name: "Remove test environment" | ||
if: ${{ inputs.continueintoproposedsteps }} | ||
continue-on-error: true | ||
run: | | ||
if [[ -f spec/fixtures/litmus_inventory.yaml ]]; then | ||
[ -z "${{ inputs.tear_down__task }}" ] || bundle exec rake '${{ inputs.tear_down__task }}' | ||
fi | ||
# Same Steps from the module_acceptance | ||
- name: "Provision environment" | ||
if: ${{ inputs.continueintooriginalsteps }} | ||
run: | | ||
if [[ "${{ inputs.kernel_modules }}" == "true" ]] && [[ "${{matrix.platforms.provider}}" =~ docker* ]] ; then | ||
DOCKER_RUN_OPTS="docker_run_opts: {'--volume': '/lib/modules/$(uname -r):/lib/modules/$(uname -r)'}" | ||
else | ||
DOCKER_RUN_OPTS='' | ||
fi | ||
bundle exec rake "litmus:provision[${{matrix.platforms.provider}},${{ matrix.platforms.image }},$DOCKER_RUN_OPTS]" | ||
# Redact password | ||
FILE='spec/fixtures/litmus_inventory.yaml' | ||
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true | ||
- name: "Install Puppet agent" | ||
if: ${{ inputs.continueintooriginalsteps }} | ||
run: | | ||
bundle exec rake 'litmus:install_agent[${{ matrix.collection }}]' | ||
- name: "Install module" | ||
if: ${{ inputs.continueintooriginalsteps }} | ||
run: | | ||
bundle exec rake 'litmus:install_module' | ||
- name: "Run acceptance tests" | ||
if: ${{ inputs.continueintooriginalsteps }} | ||
run: | | ||
bundle exec rake 'litmus:acceptance:parallel' | ||
- name: "Remove test environment" | ||
if: ${{ inputs.continueintooriginalsteps }} | ||
continue-on-error: true | ||
run: | | ||
if [[ -f spec/fixtures/litmus_inventory.yaml ]]; then | ||
bundle exec rake 'litmus:tear_down' | ||
fi |