From acfa739e69b4679c72536f948931d545e316eaf4 Mon Sep 17 00:00:00 2001 From: ianballou Date: Mon, 14 Aug 2023 16:25:36 -0400 Subject: [PATCH] Use REX for bats testing in Katello 4.10+ --- ...s => fb-katello-client-katello-agent.bats} | 13 ++- bats/fb-katello-client-rex.bats | 86 +++++++++++++++++++ bats/fb-katello-container.bats | 15 ++++ bats/foreman_helper.bash | 5 ++ roles/bats/defaults/main.yml | 4 +- 5 files changed, 115 insertions(+), 8 deletions(-) rename bats/{fb-katello-client.bats => fb-katello-client-katello-agent.bats} (90%) create mode 100644 bats/fb-katello-client-rex.bats create mode 100644 bats/fb-katello-container.bats diff --git a/bats/fb-katello-client.bats b/bats/fb-katello-client-katello-agent.bats similarity index 90% rename from bats/fb-katello-client.bats rename to bats/fb-katello-client-katello-agent.bats index 191bf9010..f2f9dba8e 100755 --- a/bats/fb-katello-client.bats +++ b/bats/fb-katello-client-katello-agent.bats @@ -7,6 +7,12 @@ load os_helper load foreman_helper load fixtures/content +setup() { + if tIsKatelloAgentRemoved; then + skip "katello-agent is no longer supported as of Katello 4.10" + fi +} + @test "enable katello-agent" { foreman-installer --foreman-proxy-content-enable-katello-agent true foreman-maintain packages unlock -y @@ -75,13 +81,6 @@ load fixtures/content done } -@test "try fetching container content" { - tPackageExists podman || tPackageInstall podman - podman login "${HOSTNAME}" -u admin -p changeme - CONTAINER_PULL_LABEL=$(echo "${ORGANIZATION_LABEL}-${PRODUCT_LABEL}-${CONTAINER_REPOSITORY_LABEL}"| tr '[:upper:]' '[:lower:]') - podman pull "${HOSTNAME}/${CONTAINER_PULL_LABEL}" -} - @test "install katello-agent" { tPackageInstall katello-agent && tPackageExists katello-agent } diff --git a/bats/fb-katello-client-rex.bats b/bats/fb-katello-client-rex.bats new file mode 100644 index 000000000..3868396ef --- /dev/null +++ b/bats/fb-katello-client-rex.bats @@ -0,0 +1,86 @@ +#!/usr/bin/env bats +# vim: ft=sh:sw=2:et + +set -o pipefail + +load os_helper +load foreman_helper +load fixtures/content + +@test "enable remote execution" { + foreman-installer --enable-foreman-plugin-remote-execution --enable-foreman-proxy-plugin-remote-execution-script --foreman-proxy-plugin-remote-execution-script-install-key=true + foreman-maintain packages unlock -y +} + +@test "disable puppet agent to prevent checkin from registering host to another org" { + systemctl is-active puppet || skip "Puppet is not active" + systemctl stop puppet +} + +@test "delete host if present" { + hammer host delete --name="${HOSTNAME}" || echo "Could not delete host" +} + +@test "register subscription manager with username and password" { + cleanSubscriptionManager + + run yum erase -y 'katello-ca-consumer-*' + echo "rc=${status}" + echo "${output}" + tPackageInstall http://localhost/pub/katello-ca-consumer-latest.noarch.rpm + echo "rc=${status}" + echo "${output}" + subscription-manager register --force --org="${ORGANIZATION_LABEL}" --username=admin --password=changeme --env=Library +} + +@test "register subscription manager with activation key" { + cleanSubscriptionManager + + run subscription-manager register --force --org="${ORGANIZATION_LABEL}" --activationkey="${ACTIVATION_KEY}" + echo "rc=${status}" + echo "${output}" + tSubscribedProductOrSCA "${PRODUCT}" +} + +@test "start puppet again" { + systemctl is-enabled puppet || skip "Puppet isn't enabled" + systemctl start puppet +} + +@test "check content host is registered" { + hammer host info --name "${HOSTNAME}" +} + +@test "enable content view repo" { + subscription-manager repos --enable="${ORGANIZATION_LABEL}_${PRODUCT_LABEL}_${YUM_REPOSITORY_LABEL}" | grep -q "is enabled for this system" +} + +@test "install package remotely" { + run yum -y remove walrus-0.71 + timeout 300 hammer job-invocation create --feature katello_package_install --inputs 'package=walrus-0.71' --search-query "name = ${HOSTNAME}" + tPackageExists walrus-0.71 +} + +@test "check available errata" { + local next_wait_time=0 + until hammer host errata list --host "${HOSTNAME}" | grep 'RHEA-2012:0055'; do + if [ $next_wait_time -eq 14 ]; then + # make one last try, also makes the error nice + hammer host errata list --host "${HOSTNAME}" | grep 'RHEA-2012:0055' + fi + sleep $(( next_wait_time++ )) + done +} + +@test "install errata remotely" { + timeout 300 hammer job-invocation create --feature katello_errata_install --inputs 'errata=RHEA-2012:0055' --search-query "name = ${HOSTNAME}" + tPackageExists walrus-5.21 +} + +@test "remove package remotely" { + timeout 300 hammer job-invocation create --feature katello_package_remove --inputs 'package=walrus' --search-query "name = ${HOSTNAME}" +} + +@test "clean up subscription-manager after content tests" { + cleanSubscriptionManager +} diff --git a/bats/fb-katello-container.bats b/bats/fb-katello-container.bats new file mode 100644 index 000000000..1882cd7a7 --- /dev/null +++ b/bats/fb-katello-container.bats @@ -0,0 +1,15 @@ +#!/usr/bin/env bats +# vim: ft=sh:sw=2:et + +set -o pipefail + +load os_helper +load foreman_helper +load fixtures/content + +@test "try fetching container content" { + tPackageExists podman || tPackageInstall podman + podman login "${HOSTNAME}" -u admin -p changeme + CONTAINER_PULL_LABEL=$(echo "${ORGANIZATION_LABEL}-${PRODUCT_LABEL}-${CONTAINER_REPOSITORY_LABEL}"| tr '[:upper:]' '[:lower:]') + podman pull "${HOSTNAME}/${CONTAINER_PULL_LABEL}" +} diff --git a/bats/foreman_helper.bash b/bats/foreman_helper.bash index 509f3a98d..746966749 100644 --- a/bats/foreman_helper.bash +++ b/bats/foreman_helper.bash @@ -34,6 +34,11 @@ tIsVersionNewer() { [[ $(printf "%s\n%s" "${GIVEN_VERSION}" "${WANTED_VERSION}" | sort --version-sort | tail -n 1) == "${GIVEN_VERSION}" ]] } +tIsKatelloAgentRemoved() { + KATELLO_VERSION=$(tKatelloVersion) + tIsVersionNewer "${KATELLO_VERSION}" 4.10 +} + tSkipIfOlderThan43() { KATELLO_VERSION=$(tKatelloVersion) if ! tIsVersionNewer "${KATELLO_VERSION}" 4.3; then diff --git a/roles/bats/defaults/main.yml b/roles/bats/defaults/main.yml index 7bd1544d8..fa6bc5037 100644 --- a/roles/bats/defaults/main.yml +++ b/roles/bats/defaults/main.yml @@ -16,7 +16,9 @@ bats_tests: - "fb-verify-packages.bats" - "fb-test-foreman.bats" - "fb-katello-content.bats" - - "fb-katello-client.bats" + - "fb-katello-container.bats" + - "fb-katello-client-katello-agent.bats" + - "fb-katello-client-rex.bats" - "fb-katello-client-global-registration.bats" - "fb-test-puppet.bats" - "fb-test-backup.bats"