From 59cf6d34897e9bd4699e89b1e68c04ae5bb4e578 Mon Sep 17 00:00:00 2001 From: David Lanning Date: Thu, 14 Nov 2024 22:03:05 +0000 Subject: [PATCH] Add a CI pipeline to validate elevate with cloudlinux Case RE-941: Add a CI pipeline to validate elevate with cloudlinux - change trigger event structure - update directory layout for multiple OS Changelog: --- .../{openstack.yml => openstack-centos-7.yml} | 113 ++-- .github/workflows/openstack-cloudlinux-7.yml | 640 ++++++++++++++++++ .../{terraform => centos-7}/cloud-config.yaml | 0 .../{terraform => centos-7}/cloud-init.yml | 0 .../openstack/{terraform => centos-7}/main.tf | 0 .../{terraform => centos-7}/outputs.tf | 0 .../{terraform => centos-7}/variables.tf | 2 +- .../openstack/cloudlinux-7/cloud-config.yaml | 5 + .../openstack/cloudlinux-7/cloud-init.yml | 6 + .../workflows/openstack/cloudlinux-7/main.tf | 82 +++ .../openstack/cloudlinux-7/outputs.tf | 7 + .../openstack/cloudlinux-7/variables.tf | 55 ++ .github/workflows/openstack/reboot_watch | 41 +- .github/workflows/openstack/ssh_retry | 4 +- .github/workflows/openstack/status_marker | 6 +- .github/workflows/testsuite.yml | 7 +- .../centos7-to-almalinux8/complete.t | 19 + .../cloudlinux7-to-cloudlinux8/complete.t | 19 + t/integration/complete.t | 69 +- 19 files changed, 945 insertions(+), 130 deletions(-) rename .github/workflows/{openstack.yml => openstack-centos-7.yml} (86%) create mode 100644 .github/workflows/openstack-cloudlinux-7.yml rename .github/workflows/openstack/{terraform => centos-7}/cloud-config.yaml (100%) rename .github/workflows/openstack/{terraform => centos-7}/cloud-init.yml (100%) rename .github/workflows/openstack/{terraform => centos-7}/main.tf (100%) rename .github/workflows/openstack/{terraform => centos-7}/outputs.tf (100%) rename .github/workflows/openstack/{terraform => centos-7}/variables.tf (99%) create mode 100644 .github/workflows/openstack/cloudlinux-7/cloud-config.yaml create mode 100644 .github/workflows/openstack/cloudlinux-7/cloud-init.yml create mode 100644 .github/workflows/openstack/cloudlinux-7/main.tf create mode 100644 .github/workflows/openstack/cloudlinux-7/outputs.tf create mode 100644 .github/workflows/openstack/cloudlinux-7/variables.tf create mode 100644 t/integration/centos7-to-almalinux8/complete.t create mode 100644 t/integration/cloudlinux7-to-cloudlinux8/complete.t diff --git a/.github/workflows/openstack.yml b/.github/workflows/openstack-centos-7.yml similarity index 86% rename from .github/workflows/openstack.yml rename to .github/workflows/openstack-centos-7.yml index 54a9e6bd..5d4a861f 100644 --- a/.github/workflows/openstack.yml +++ b/.github/workflows/openstack-centos-7.yml @@ -1,4 +1,4 @@ -name: Openstack Test Run +name: "Test Run: centos-7" on: push: @@ -11,7 +11,7 @@ on: workflow_dispatch: concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-openstack + group: ${{ github.workflow }}-${{ github.ref }}-openstack-centos-7 cancel-in-progress: true env: @@ -29,7 +29,7 @@ env: TF_VAR_os_project_name: ${{ secrets.OS_PROJECT_NAME }} TF_VAR_os_region_name: ${{ secrets.OS_REGION_NAME }} TF_VAR_os_username: ${{ secrets.OS_USERNAME }} - tf_working_directory: "./.github/workflows/openstack/terraform" + tf_working_directory: "${{ github.workspace }}/.github/workflows/openstack/centos-7" jobs: testsuite: @@ -39,7 +39,7 @@ jobs: runs-on: self-hosted defaults: run: - working-directory: "./.github/workflows/openstack/terraform" + working-directory: "${{ github.workspace }}/.github/workflows/openstack/centos-7" steps: - uses: actions/checkout@v4 - name: Terraform fmt @@ -48,11 +48,6 @@ jobs: terraform fmt -check continue-on-error: true - - name: DEBUGVAR - id: debugvar - run: | - env | awk 'tolower($0)~/auth|project_name/' - - name: Terraform Init id: init run: | @@ -66,7 +61,16 @@ jobs: - name: Terraform Apply id: apply run: | + pwd terraform apply -no-color -auto-approve + mv -v .terraform.lock.hcl terraform.lock.hcl + find $PWD + + - name: Upload Terraform State File as Artifact + uses: actions/upload-artifact@v4.4.3 + with: + name: ${{ github.run_id }}-terraform.tfstate + path: "${{ github.workspace }}/.github/workflows/openstack/centos-7" - name: Terraform Output File Create run: | @@ -77,18 +81,11 @@ jobs: run: | echo "$(jq -r '.address.value' ${{ github.run_id }}-tf.out.json)" > ${{ github.workspace }}/${{ github.run_id }}-vm_ip - - name: Upload JSON Output - uses: actions/upload-artifact@v4 - with: - name: ${{ github.run_id }}-tf.out.json - path: ${{ github.workspace }}/ - overwrite: true - - name: Upload VM Output - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v4.4.3 with: name: ${{ github.run_id }}-vm_ip - path: ${{ github.workspace }}/ + path: ${{ github.workspace }}/${{ github.run_id }}-vm_ip overwrite: true clone_elevate_repo: @@ -98,7 +95,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -151,7 +148,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -186,7 +183,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -217,8 +214,9 @@ jobs: cp -pv /opt/${REPODIR}/.github/workflows/openstack/status_marker /scripts/status_marker cp -pv /opt/${REPODIR}/.github/workflows/openstack/reboot_watch /scripts/reboot_watch chmod -v +x /scripts/elevate-cpanel - /usr/local/cpanel/cpkeyclt + until /usr/local/cpanel/cpkeyclt; do echo "Retrying /usr/local/cpanel/cpkeyct until it passes..."; sleep 5; done /scripts/elevate-cpanel --non-interactive --skip-cpanel-version-check --start & + exit 0 wait_for_stage_1_reboot: runs-on: self-hosted @@ -227,7 +225,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -254,7 +252,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -281,8 +279,8 @@ jobs: debug: true script: | /scripts/status_marker 1 - /scripts/elevate-cpanel --log & - sleep 1.5 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep .5 REBOOT_STRING="Rebooting into stage 2 of 5" RETVAL=1 /scripts/reboot_watch wait_for_stage_2_reboot: @@ -292,7 +290,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -319,7 +317,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -346,8 +344,8 @@ jobs: debug: true script: | /scripts/status_marker 2 - /scripts/elevate-cpanel --log & - sleep 1.5 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep .5 REBOOT_STRING="Rebooting into stage 3 of 5" RETVAL=1 /scripts/reboot_watch wait_for_stage_3_reboot: @@ -357,7 +355,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -384,7 +382,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -410,8 +408,8 @@ jobs: command_timeout: 30m script: | /scripts/status_marker 3 - /scripts/elevate-cpanel --log & - sleep 1.5 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep .5 REBOOT_STRING="Rebooting into stage 4 of 5" RETVAL=1 /scripts/reboot_watch wait_for_stage_4_reboot: @@ -421,7 +419,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -448,7 +446,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -474,8 +472,8 @@ jobs: command_timeout: 35m script: | /scripts/status_marker 4 - /scripts/elevate-cpanel --log & - sleep 1.5 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep .5 REBOOT_STRING="Rebooting into stage 5 of 5" RETVAL=1 /scripts/reboot_watch wait_for_stage_5_reboot: @@ -485,7 +483,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -512,7 +510,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -538,8 +536,8 @@ jobs: command_timeout: 35m script: | /scripts/status_marker 5 - /scripts/elevate-cpanel --log & - sleep 1.5 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep 2.5 SKIP_PID_CHECK=1 REBOOT_STRING="Doing final reboot" RETVAL=1 /scripts/reboot_watch wait_for_final_reboot: @@ -549,7 +547,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -576,7 +574,7 @@ jobs: VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} steps: - name: Download VM IP - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v4.1.8 with: name: ${{ github.run_id }}-vm_ip path: ${{ github.workspace }}/ @@ -603,18 +601,31 @@ jobs: script: | REPODIR=$(echo ${{ github.repository }} | cut -d / -f2) /usr/local/cpanel/3rdparty/bin/prove -lvm /opt/${REPODIR}/t/integration/*.t + /usr/local/cpanel/3rdparty/bin/prove -lvm /opt/${REPODIR}/t/integration/centos7-to-almalinux8/*.t terraform_openstack_destroy: runs-on: self-hosted needs: verify_upgraded_os defaults: run: - working-directory: "./.github/workflows/openstack/terraform" + working-directory: "${{ github.workspace }}/.github/workflows/openstack/centos-7" steps: - - name: Download Terraform Output JSON - uses: actions/download-artifact@v4 + - name: Download Terraform State + uses: actions/download-artifact@v4.1.8 with: - name: ${{ github.run_id }}-tf.out.json - path: ${{ github.workspace }}/tf.out.json - - name: Destroy OpenStack VM - run: terraform destroy -no-color -auto-approve + name: ${{ github.run_id }}-terraform.tfstate + path: "${{ github.workspace }}/.github/workflows/openstack/centos-7/terraform" + + + - name: Stage Files & Show Artifact Paths + run: | + cd ${{ github.workspace }}/.github/workflows/openstack/centos-7/terraform/ + mv -v terraform.lock.hcl .terraform.lock.hcl + find ${{ github.workspace }}/.github/workflows/openstack/centos-7/ + + - name: Initialize Terraform & Destroy + run: | + cd ${{ github.workspace }}/.github/workflows/openstack/centos-7/terraform/ + rm -Rfv .terraform || true + terraform init + terraform destroy -no-color -auto-approve diff --git a/.github/workflows/openstack-cloudlinux-7.yml b/.github/workflows/openstack-cloudlinux-7.yml new file mode 100644 index 00000000..70d7b1e6 --- /dev/null +++ b/.github/workflows/openstack-cloudlinux-7.yml @@ -0,0 +1,640 @@ +name: "Test Run: cloudlinux-7" + +on: + push: + branches: + - "main" + - '!docs' + tags-ignore: + - "*" + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-openstack-cloudlinux-7 + cancel-in-progress: true + +env: + TF_VAR_application_credential_id: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }} + TF_VAR_application_credential_secret: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }} + TF_VAR_ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + TF_VAR_ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }} + TF_VAR_os_auth_region: ${{ secrets.OS_AUTH_REGION }} + TF_VAR_os_auth_url: ${{ secrets.OS_AUTH_URL }} + TF_VAR_os_interface: ${{ secrets.OS_INTERFACE }} + TF_VAR_os_project_domain_name: ${{ secrets.OS_PROJECT_DOMAIN_NAME }} + TF_VAR_os_password: ${{ secrets.OS_PASSWORD }} + TF_VAR_os_project_id: ${{ secrets.OS_PROJECT_ID }} + TF_VAR_os_project_domain_id: ${{ secrets.OS_PROJECT_DOMAIN_ID }} + TF_VAR_os_project_name: ${{ secrets.OS_PROJECT_NAME }} + TF_VAR_os_region_name: ${{ secrets.OS_REGION_NAME }} + TF_VAR_os_username: ${{ secrets.OS_USERNAME }} + tf_working_directory: "${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7" + +jobs: + testsuite: + uses: ./.github/workflows/testsuite.yml + terraform_openstack_create: + needs: [testsuite] + runs-on: self-hosted + defaults: + run: + working-directory: "${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7" + steps: + - uses: actions/checkout@v4 + - name: Terraform fmt + id: fmt + run: | + terraform fmt -check + continue-on-error: true + + - name: Terraform Init + id: init + run: | + terraform init + + - name: Terraform Plan + id: plan + run: | + terraform plan -no-color + + - name: Terraform Apply + id: apply + run: | + pwd + terraform apply -no-color -auto-approve + mv -v .terraform.lock.hcl terraform.lock.hcl + find $PWD + + - name: Upload Terraform State File as Artifact + uses: actions/upload-artifact@v4.4.3 + with: + name: ${{ github.run_id }}-terraform.tfstate + path: "${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7" + + - name: Terraform Output File Create + run: | + terraform output -json > ${{ github.run_id }}-tf.out.json + + - name: Make vm_ip file from Terraform Output File + id: get_vm_ip + run: | + echo "$(jq -r '.address.value' ${{ github.run_id }}-tf.out.json)" > ${{ github.workspace }}/${{ github.run_id }}-vm_ip + + - name: Upload VM Output + uses: actions/upload-artifact@v4.4.3 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/${{ github.run_id }}-vm_ip + overwrite: true + + clone_elevate_repo: + runs-on: self-hosted + needs: terraform_openstack_create + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Checkout Repo and Commit + if: github.event_name != 'pull_request' + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + script: | + cd /opt + echo "## [INFO]: ${{ github.ref }}" + echo "## [INFO]: ${{ github.ref_name }}" + echo "## [INFO}: ${{ github.repository }}" + git clone --depth 1 --branch ${{ github.ref_name }} https://github.com/${{ github.repository }}.git + hostname && pwd && ls -la + cd /opt/$(echo ${{ github.repository }} | cut -d / -f2) + git status + + - name: Checking out Repo and Pull Request + if: github.event_name == 'pull_request' + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + script: | + cd /opt + echo "[DEBUG]: ${{ github.ref }}" + echo "[DEBUG]: ${{ github.head_ref }}" + echo "## [INFO}: ${{ github.repository }}" + git clone --depth 1 --branch ${{ github.head_ref }} https://github.com/${{ github.repository }}.git + cd /opt/$(echo ${{ github.repository }} | cut -d / -f2) + git status + + setup_integration_checks: + runs-on: self-hosted + needs: clone_elevate_repo + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + + - name: Setup for Integration Checks Prior to Running Elevate + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + script: | + REPODIR=$(echo ${{ github.repository }} | cut -d / -f2) + chmod -v +x /opt/${REPODIR}/t/integration/setup + /opt/${REPODIR}/t/integration/setup + + start_elevate: + runs-on: self-hosted + needs: setup_integration_checks + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + + - name: Starting Elevate + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 30m + command_timeout: 30m + script: | + REPODIR=$(echo ${{ github.repository }} | cut -d / -f2) + cp -pv /opt/${REPODIR}/elevate-cpanel /scripts/elevate-cpanel + chmod -v +x /scripts/elevate-cpanel + cp -pv /opt/${REPODIR}/.github/workflows/openstack/status_marker /scripts/status_marker + cp -pv /opt/${REPODIR}/.github/workflows/openstack/reboot_watch /scripts/reboot_watch + /usr/sbin/rhnreg_ks --activationkey=${{ secrets.CLOUDLINUX_LICENSE_KEY }} --force + /usr/bin/cldetect --update-license + /usr/bin/cldetect --check-license + /usr/bin/yum erase -y awscli + echo "yum reinstall -y `yum list installed | awk '$3~/cloudlinux-x86_64-server/{printf "%s ", $1}'` --disablerepo=cloudlinux-x86_64-server --enablerepo=cloudlinux-base --enablerepo=cloudlinux-updates" | sh + mv -v /etc/yum.repos.d/clmirror.repo /root/ + /usr/bin/yum clean all + echo "## [INFO]: Removing /etc/yum/pluginconf.d/rhnplugin.conf" && rm -fv /etc/yum/pluginconf.d/rhnplugin.conf + until /usr/local/cpanel/cpkeyclt; do echo "Retrying /usr/local/cpanel/cpkeyct until it passes..."; sleep 5; done + /usr/bin/yum makecache + /scripts/elevate-cpanel --non-interactive --skip-cpanel-version-check --start & + + wait_for_stage_1_reboot: + runs-on: self-hosted + needs: start_elevate + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Initial Reboot + working-directory: "./.github/workflows/openstack/" + run: | + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + watch_for_stage_2_reboot: + runs-on: self-hosted + needs: wait_for_stage_1_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Monitor Elevate for Reboot from Stage 1 into Stage 2 + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 60m + command_timeout: 30m + debug: true + script: | + /scripts/status_marker 1 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep 1.5 + REBOOT_STRING="Rebooting into stage 2 of 5" RETVAL=1 /scripts/reboot_watch + + wait_for_stage_2_reboot: + runs-on: self-hosted + needs: watch_for_stage_2_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Stage 2 Reboot + working-directory: "./.github/workflows/openstack/" + run: | + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + watch_for_stage_3_reboot: + runs-on: self-hosted + needs: wait_for_stage_2_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Monitor Elevate for Stage 3 Reboot + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 60m + command_timeout: 30m + debug: true + script: | + /scripts/status_marker 2 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep 1.5 + REBOOT_STRING="Rebooting into stage 3 of 5" RETVAL=1 /scripts/reboot_watch + + wait_for_stage_3_reboot: + runs-on: self-hosted + needs: watch_for_stage_3_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Stage 3 Reboot + working-directory: "./.github/workflows/openstack/" + run: | + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + watch_for_stage_4_reboot: + runs-on: self-hosted + needs: wait_for_stage_3_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Monitor Elevate for Stage 4 Reboot + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 60m + command_timeout: 50m + script: | + /scripts/status_marker 3 + yum makecache + tail -n40 -F /var/log/elevate-cpanel.log& + sleep 1.5 + REBOOT_STRING="Rebooting into stage 4 of 5" RETVAL=1 /scripts/reboot_watch + + wait_for_stage_4_reboot: + runs-on: self-hosted + needs: watch_for_stage_4_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Stage 4 Reboot + working-directory: "./.github/workflows/openstack/" + run: | + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + watch_for_stage_5_reboot: + runs-on: self-hosted + needs: wait_for_stage_4_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Monitor Elevate for Stage 5 Reboot + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 45m + command_timeout: 35m + script: | + /scripts/status_marker 4 + tail -n40 -F /var/log/elevate-cpanel.log& + sleep 300 + REBOOT_STRING="cPanel & WHM updates are disabled via cron because they are set to" /scripts/reboot_watch + + wait_for_stage_5_reboot: + runs-on: self-hosted + needs: watch_for_stage_5_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Stage 5 Reboot + working-directory: "./.github/workflows/openstack/" + run: | + echo "## [INFO]: Sleeping 37 seconds to try and slam the timing on this tricky reboot sequence." + sleep 37 + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + watch_for_final_reboot: + runs-on: self-hosted + needs: wait_for_stage_5_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Monitor Elevate for Final Reboot + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 45m + command_timeout: 35m + script: | + /scripts/status_marker 5 + tail -n40 -F /var/log/elevate-cpanel.log& + SKIP_PID_CHECK=1 REBOOT_STRING="Doing final reboot" RETVAL=1 /scripts/reboot_watch + + wait_for_final_reboot: + runs-on: self-hosted + needs: watch_for_final_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Wait For VM to Come Back From Final Reboot + working-directory: "./.github/workflows/openstack/" + run: | + ./ssh_retry ${{ steps.VM_IP.outputs.VM_IP }} + + verify_upgraded_os: + runs-on: self-hosted + needs: wait_for_final_reboot + outputs: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + steps: + - name: Download VM IP + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-vm_ip + path: ${{ github.workspace }}/ + + - name: Get VM IP from Artifact + id: VM_IP + run: | + echo "VM_IP=$(cat ${{ github.run_id }}-vm_ip)" >> "$GITHUB_OUTPUT" + cat ${{ github.run_id }}-vm_ip > VM_IP + + - name: Export VM_IP to env + env: + VM_IP: ${{ steps.VM_IP.outputs.VM_IP }} + run: echo "VM_IP is ${{ steps.VM_IP.outputs.VM_IP }}" + - name: Verify End Result Integration Tests + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ steps.VM_IP.outputs.VM_IP }} + username: 'root' + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: '22' + timeout: 5m + command_timeout: 1m + script: | + REPODIR=$(echo ${{ github.repository }} | cut -d / -f2) + /usr/local/cpanel/3rdparty/bin/prove -lvm /opt/${REPODIR}/t/integration/*.t + /usr/local/cpanel/3rdparty/bin/prove -lvm /opt/${REPODIR}/t/integration/cloudlinux7-to-cloudlinux8/*.t + + terraform_openstack_destroy: + runs-on: self-hosted + needs: verify_upgraded_os + defaults: + run: + working-directory: "${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7" + steps: + - name: Download Terraform State + uses: actions/download-artifact@v4.1.8 + with: + name: ${{ github.run_id }}-terraform.tfstate + path: "${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7/terraform" + + - name: Stage Files & Show Artifact Paths + run: | + cd ${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7/terraform/ + mv -v terraform.lock.hcl .terraform.lock.hcl + find ${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7/ + + - name: Initialize Terraform & Destroy + run: | + cd ${{ github.workspace }}/.github/workflows/openstack/cloudlinux-7/terraform/ + rm -Rfv .terraform || true + terraform init + terraform destroy -no-color -auto-approve diff --git a/.github/workflows/openstack/terraform/cloud-config.yaml b/.github/workflows/openstack/centos-7/cloud-config.yaml similarity index 100% rename from .github/workflows/openstack/terraform/cloud-config.yaml rename to .github/workflows/openstack/centos-7/cloud-config.yaml diff --git a/.github/workflows/openstack/terraform/cloud-init.yml b/.github/workflows/openstack/centos-7/cloud-init.yml similarity index 100% rename from .github/workflows/openstack/terraform/cloud-init.yml rename to .github/workflows/openstack/centos-7/cloud-init.yml diff --git a/.github/workflows/openstack/terraform/main.tf b/.github/workflows/openstack/centos-7/main.tf similarity index 100% rename from .github/workflows/openstack/terraform/main.tf rename to .github/workflows/openstack/centos-7/main.tf diff --git a/.github/workflows/openstack/terraform/outputs.tf b/.github/workflows/openstack/centos-7/outputs.tf similarity index 100% rename from .github/workflows/openstack/terraform/outputs.tf rename to .github/workflows/openstack/centos-7/outputs.tf diff --git a/.github/workflows/openstack/terraform/variables.tf b/.github/workflows/openstack/centos-7/variables.tf similarity index 99% rename from .github/workflows/openstack/terraform/variables.tf rename to .github/workflows/openstack/centos-7/variables.tf index e55b66a3..7806ea96 100644 --- a/.github/workflows/openstack/terraform/variables.tf +++ b/.github/workflows/openstack/centos-7/variables.tf @@ -52,4 +52,4 @@ variable "cpanel_release_version" { variable "flavor_name" { type = string default = "c2.d20.r2048" -} \ No newline at end of file +} diff --git a/.github/workflows/openstack/cloudlinux-7/cloud-config.yaml b/.github/workflows/openstack/cloudlinux-7/cloud-config.yaml new file mode 100644 index 00000000..0445e91b --- /dev/null +++ b/.github/workflows/openstack/cloudlinux-7/cloud-config.yaml @@ -0,0 +1,5 @@ +--- + users: + - name: root + lock_passwd: false + disable_root: false \ No newline at end of file diff --git a/.github/workflows/openstack/cloudlinux-7/cloud-init.yml b/.github/workflows/openstack/cloudlinux-7/cloud-init.yml new file mode 100644 index 00000000..1602682e --- /dev/null +++ b/.github/workflows/openstack/cloudlinux-7/cloud-init.yml @@ -0,0 +1,6 @@ +#cloud-config +disable_root: false +ssh_pwauth: true +hostname: host +fqdn: host.domain.tbd +prefer_fqdn_over_hostname: true diff --git a/.github/workflows/openstack/cloudlinux-7/main.tf b/.github/workflows/openstack/cloudlinux-7/main.tf new file mode 100644 index 00000000..22f1cedd --- /dev/null +++ b/.github/workflows/openstack/cloudlinux-7/main.tf @@ -0,0 +1,82 @@ +# Define required providers +terraform { + required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.54.1" + } + } +} + +# Configure the OpenStack Provider +provider "openstack" { + user_name = var.user + application_credential_id = var.application_credential_id + application_credential_secret = var.application_credential_secret + auth_url = "https://keystone.hou-01.cloud.prod.cpanel.net:5000/v3" + region = var.os_auth_region +} + +data "openstack_images_image_ids_v2" "images" { + name_regex = var.image_name + sort = "updated_at" +} + +data "template_cloudinit_config" "config" { + gzip = true + base64_encode = true + + part { + content_type = "text/cloud-config" + content = "cloud-config.yaml" + } +} + +resource "tls_private_key" "ssh" { + algorithm = "ECDSA" + ecdsa_curve = "P384" +} + +resource "random_string" "keyname" { + length = 22 + special = false +} + +resource "openstack_compute_keypair_v2" "tf_remote_key" { + name = "${random_string.keyname.result}-deletethis" + public_key = tls_private_key.ssh.public_key_openssh +} + +resource "openstack_compute_instance_v2" "elevatevm" { + name = "elevate.github.cpanel.net" + image_id = data.openstack_images_image_ids_v2.images.ids[0] + flavor_name = var.flavor_name + key_pair = openstack_compute_keypair_v2.tf_remote_key.name + user_data = data.template_cloudinit_config.config.rendered + network { + name = "hou-prod-external" + } + + provisioner "remote-exec" { + inline = [<> /root/.ssh/id_ed25519 + echo "${var.ssh_public_key}" >> /root/.ssh/authorized_keys + echo 'waiting on cloud-init...' + cloud-init status --wait > /dev/null || true + EOF + ] + connection { + type = "ssh" + agent = "false" + host = self.access_ip_v4 + user = "root" + script_path = "/root/elevate_bootstrap" + private_key = tls_private_key.ssh.private_key_pem + } + } +} + diff --git a/.github/workflows/openstack/cloudlinux-7/outputs.tf b/.github/workflows/openstack/cloudlinux-7/outputs.tf new file mode 100644 index 00000000..396221f0 --- /dev/null +++ b/.github/workflows/openstack/cloudlinux-7/outputs.tf @@ -0,0 +1,7 @@ +output "address" { + value = openstack_compute_instance_v2.elevatevm.access_ip_v4 +} + +output "id" { + value = openstack_compute_instance_v2.elevatevm.id +} \ No newline at end of file diff --git a/.github/workflows/openstack/cloudlinux-7/variables.tf b/.github/workflows/openstack/cloudlinux-7/variables.tf new file mode 100644 index 00000000..c9df47af --- /dev/null +++ b/.github/workflows/openstack/cloudlinux-7/variables.tf @@ -0,0 +1,55 @@ +variable "user" { + type = string + default = "resu" +} + +variable "application_credential_id" { + type = string +} + +variable "application_credential_secret" { + type = string +} + +variable "os_password" { + type = string +} + +variable "os_auth_region" { + type = string +} + +variable "os_auth_url" { + type = string +} + +variable "os_project_domain_name" { + type = string +} + +variable "ssh_private_key" { + type = string + description = "SSH private key matching the public key added to the VMs /root/.ssh/authorized_keys file to allow user access." + sensitive = true +} + +variable "ssh_public_key" { + type = string + description = "SSH public key matching the public key added to the VMs /root/.ssh/authorized_keys file to allow user access." + sensitive = true +} + +variable "image_name" { + type = string + default = "11.110.0.* on CloudLinux 7" +} + +variable "cpanel_release_version" { + type = string + default = "110" +} + +variable "flavor_name" { + type = string + default = "c2.d20.r2048" +} \ No newline at end of file diff --git a/.github/workflows/openstack/reboot_watch b/.github/workflows/openstack/reboot_watch index d2bb0b63..a4d21e3d 100755 --- a/.github/workflows/openstack/reboot_watch +++ b/.github/workflows/openstack/reboot_watch @@ -1,7 +1,7 @@ #!/usr/local/cpanel/3rdparty/bin/perl use constant ELEVATE_LOG_PATH => '/var/log/elevate-cpanel.log'; -use constant ELEVATE_PID => '/var/run/elevate-cpanel.pid'; +use constant ELEVATE_PID_PATH => '/var/run/elevate-cpanel.pid'; use File::Tail; use POSIX; @@ -19,7 +19,7 @@ open( my $elevate_log_fh, '<', ELEVATE_LOG_PATH ) or die "## [ERROR][reboot_watc while ( my $line = readline $elevate_log_fh ) { if ( index( $line, $ENV{REBOOT_STRING} ) >= 0 ) { - close $elevate_log; + close $elevate_log_fh; _pre_success_message(); _exit_with_haste_(0); } @@ -35,16 +35,32 @@ while ( $RETVAL != 0 ) { sub _check_elevate_log_for_REBOOT_STRING { my ( $filepath, $REBOOT_STRING, $RETRIES ) = @_; - $file = File::Tail->new( name => $filepath, maxinterval => 1, adjustafter => 5, interval => 1 ); + $file = File::Tail->new( name => $filepath, maxinterval => 0.1, adjustafter => 0.1, interval => 0.1, tail => -1 ); while ( defined( $line = $file->read ) ) { _pid_check() unless $ENV{SKIP_PID_CHECK}; if ( index( $line, $ENV{REBOOT_STRING} ) >= 0 ) { _success_message(); _exit_with_haste(0); } + + # The idea is that below here we can include conditionals of BAD phrases to exit 1 on so the pipelines don't hand longer than they need to. + if ( index( $line, "[FATAL]" ) >= 0 ) { + _fail_message(); + _exit_with_haste(1); + } + if ( index( $line, "command failed. Fix it and run command" ) >= 0 ) { + _fail_message(); + _exit_with_haste(1); + } } } +sub _fail_message { + my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime ); + print "## [$time] [INFO]: FAILURE: FATAL error encountered ( /FATAL/ ) found in /var/log/elevate-cpanel.log ##\n"; + _exit_with_haste(1); +} + sub _pre_success_message { my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime ); print "## [$time] [INFO][PRE-TAIL]: SUCCESS: Reboot REBOOT_STRING ( $ENV{REBOOT_STRING} ) already exists in /var/log/elevate-cpanel.log prior to tail. Timings may be off ##\n"; @@ -66,9 +82,22 @@ sub _exit_with_haste { } sub _pid_check { - ## Make sure the PID is in place before we continue parsing through. This can prevent the timeout from being hit when we miss elevate has already died. - if ( !-s ELEVATE_PID ) { - print "## [ERROR]: NO PID for elevate-cpanel detected. Exiting. ##\n"; + if ( !-s ELEVATE_PID_PATH ) { + print "## [DEBUG]: PID file not found at " . ELEVATE_PID_PATH . "\n"; + my $runout = `ls -la /var/run/`; + print "## [DEBUG]: contents of /var/run: $lsout\n"; + open my $PID_FH, '<', ELEVATE_PID_PATH or die "Can't open file $!"; + my $file_content = do { local $/; <$PID_FH> }; + print "## [DEBUG]: PID exists: " . ELEVATE_PID_PATH . "\n"; + print "## [DEBUG]: $file_content"; + my $psout = `pstree | grep elevate-bcl`; + print "## [DEBUG]: $psout\n"; + my $pidout = `pstree $file_content`; + print "## [DEBUG]: $pidout\n"; + print "## [DEBUG]: Dumping last 2000 lines of /var/log/elevate-cpanel.log ...\n"; + my $loglines = `tail -n 2000 /var/log/elevate-cpanel.log`; + print "## [DEBUG]: $loglines"; + print "## [ERROR]: NO PID for elevate-cpanel detected. Exiting. ##\n"; _exit_with_haste(1); } return 0; diff --git a/.github/workflows/openstack/ssh_retry b/.github/workflows/openstack/ssh_retry index a32ecb38..08065c7a 100755 --- a/.github/workflows/openstack/ssh_retry +++ b/.github/workflows/openstack/ssh_retry @@ -6,12 +6,12 @@ my $HOST = $ARGV[0]; my $PORT = $ARGV[1] // 22; my $RETVAL = 1; my $RETRIES = 0; -my $RETRY = $ARGV[2] // 900; +my $RETRY = $ARGV[2] // 1200; # Bumping this to 20 minutes per cloudlinux Stage 4 averaging right at 15 mins return unless defined $HOST; while ( $RETVAL != 0 ) { - my $cmd = qq{ /usr/bin/nc -z -w 3 $HOST $PORT }; + my $cmd = qq{ /usr/bin/nc -z -w 1 $HOST $PORT }; my $output = `$cmd`; my $time = POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime ); diff --git a/.github/workflows/openstack/status_marker b/.github/workflows/openstack/status_marker index f26776ab..0da481e2 100755 --- a/.github/workflows/openstack/status_marker +++ b/.github/workflows/openstack/status_marker @@ -6,7 +6,7 @@ my $CPANEL_VERSION = `cat /usr/local/cpanel/version`; use strict; -print "######################################\n"; +print "###################################\n"; sub main { my @arr = ( @@ -16,7 +16,7 @@ sub main { for my $row (@arr) { format STDOUT = -@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<< +@<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<< @$row . write; @@ -26,4 +26,4 @@ sub main { main(); -print "######################################\n"; +print "###################################\n"; diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index 6e607608..a0b6d409 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -2,12 +2,11 @@ name: testsuite on: push: - branches: - - "*" - - '!docs' tags-ignore: - - "*" + - "*" # Exclude all tags pull_request: + branches-ignore: + - "main" # Exclude main for PRs as well workflow_dispatch: workflow_call: diff --git a/t/integration/centos7-to-almalinux8/complete.t b/t/integration/centos7-to-almalinux8/complete.t new file mode 100644 index 00000000..ea02d222 --- /dev/null +++ b/t/integration/centos7-to-almalinux8/complete.t @@ -0,0 +1,19 @@ +#!/usr/local/cpanel/3rdparty/bin/perl + +# Copyright 2024 WebPros International, LLC +# All rights reserved. +# copyright@cpanel.net http://cpanel.net +# This code is subject to the cPanel license. Unauthorized copying is prohibited. + +use lib '/usr/local/cpanel/'; + +use Cpanel::OS (); +use Cpanel::SafeRun::Simple (); + +use Test::More tests => 2; + +use Data::Dumper; + +is( Cpanel::OS->distro(), 'almalinux', 'System is Almalinux after upgrade.' ); +is( Cpanel::OS->major(), '8', 'Verson 8 of OS.' ); + diff --git a/t/integration/cloudlinux7-to-cloudlinux8/complete.t b/t/integration/cloudlinux7-to-cloudlinux8/complete.t new file mode 100644 index 00000000..747dac1d --- /dev/null +++ b/t/integration/cloudlinux7-to-cloudlinux8/complete.t @@ -0,0 +1,19 @@ +#!/usr/local/cpanel/3rdparty/bin/perl + +# Copyright 2024 WebPros International, LLC +# All rights reserved. +# copyright@cpanel.net http://cpanel.net +# This code is subject to the cPanel license. Unauthorized copying is prohibited. + +use lib '/usr/local/cpanel/'; + +use Cpanel::OS (); +use Cpanel::SafeRun::Simple (); + +use Test::More tests => 2; + +use Data::Dumper; + +is( Cpanel::OS->distro(), 'cloudlinux', 'System is Almalinux after upgrade.' ); +is( Cpanel::OS->major(), '8', 'Verson 8 of OS.' ); + diff --git a/t/integration/complete.t b/t/integration/complete.t index 94c9b941..0a6f96fb 100644 --- a/t/integration/complete.t +++ b/t/integration/complete.t @@ -8,73 +8,16 @@ use lib '/usr/local/cpanel/'; use Cpanel::OS (); -use Cpanel::JSON (); use Cpanel::SafeRun::Simple (); -use Test::More; +use Test::More tests => 7; -# "Poor man's" FailWarnings -$SIG{'__WARN__'} = sub { fail("Warning detected: $_[0]"); }; +use Data::Dumper; is( Cpanel::OS->distro(), 'almalinux', 'System is Almalinux after upgrade.' ); is( Cpanel::OS->major(), '8', 'Verson 8 of OS.' ); is( -e '/var/log/elevate-cpanel.log', 1, 'Elevate log exists.' ); - -note "Gather service status..."; -my $svcstatus = run_api(qw{whmapi1 servicestatus}); -if ( ref $svcstatus->{'data'}{'service'} eq 'ARRAY' ) { - foreach my $svc_info ( $svcstatus->{'data'}{'service'}->@* ) { - next if !$svc_info->{'enabled'} || $svc_info->{'name'} eq 'mailman' || $svc_info->{'name'} eq 'tailwatchd' || $svc_info->{'name'} eq 'imunify360'; - ok( $svc_info->{'running'}, "$svc_info->{'name'} is running" ); - } -} -ok( run(qw{pgrep elevate}) eq '', 'No instance of elevate-cpanel currently running.' ); - -# Do some basic checks for other things -# Sadly, we don't ship anything useful for login checks, so just use curl -my $login_url = run('/usr/sbin/whmlogin'); -my $content = curl($login_url); -like( $content, qr/WHM/, "WHM is able to be logged into" ); - -like( run( qw{/usr/bin/bash -c}, 'echo "SHOW DATABASES" | mysql' ), qr/information_schema/, "MySQL seems OK" ); - -# XXX TODO randomize this, I really wish I had t/qa tools here. Also need to set allowunreg, etc. ;_; -note "Creating an account for testing..."; -run_api( qw{whmapi1 set_tweaksetting value=1}, "key=$_" ) for qw{allowunregistereddomains allowremotedomains}; -my $user = run_api(qw{whmapi1 createacct domain=azurediamond.test user=azurediamond pass=H4nt3r2_Als0_B1FF_R00LZ}); -note "Waiting on taskqueue..."; -run(qw{/usr/local/cpanel/3rdparty/bin/servers_queue run}); -$login_url = run_api(qw{whmapi1 create_user_session user=azurediamond service=cpaneld})->{'data'}{'url'}; -$content = curl($login_url); -like( $content, qr/<title>cPanel/, "cPanel is able to be logged into with newly created user" ); - -# Delete the account. Possibly should be done in an END block but meh. -# VM will get whacked after pipeline runs, so *for now* this should be fine. -note "Deleting created account..."; -run_api(qw{whmapi1 removeacct user=azurediamond}); - -done_testing(); - -# Less typing, it all needs the chomp -sub run { - my $out = Cpanel::SafeRun::Simple::saferun(@_); - chomp $out; - return $out; -} - -sub curl { - return run( qw{curl -s -k -L}, @_ ); -} - -# Returns HASHREF. For "script only opts" like --user, etc., use `--` to separate after API args. -sub run_api { - my ( $api, @call_args ) = @_; - my $out = {}; - { - local $@; - $out = eval { Cpanel::JSON::Load( run( "/usr/local/cpanel/bin/$api", '--output=json', @call_args ) ) }; - warn $@ if $@; - } - warn "$api @call_args failed: $out->{'metadata'}{'reason'}" if !$out->{'metadata'}{'result'}; - return $out; -} +like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_httpd --status' ), qr/is running as root/, 'Apache is up and accepting connections.' ); +like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_cpsrvd --status' ), qr/is running as root/, 'Chksrvd is up and accepting connections.' ); +like( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', '/scripts/restartsrv_named --status' ), qr/is running as named/, 'Nameserver is up and accepting connections.' ); +ok( Cpanel::SafeRun::Simple::saferun( '/bin/sh', '-c', 'pgrep elevate' ) eq '', 'No instance of elevate-cpanel currently running.' );