From b07f7d68bd6f57c070b9925397a2233958b9d30e Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Wed, 21 Jul 2021 11:27:06 -0400 Subject: [PATCH] Add global registration bats tests for Katello clients --- ...fb-katello-client-global-registration.bats | 78 +++++++++++++++++++ bats/os_helper.bash | 11 +++ roles/bats/defaults/main.yaml | 1 + 3 files changed, 90 insertions(+) create mode 100644 bats/fb-katello-client-global-registration.bats diff --git a/bats/fb-katello-client-global-registration.bats b/bats/fb-katello-client-global-registration.bats new file mode 100644 index 000000000..2b96259f3 --- /dev/null +++ b/bats/fb-katello-client-global-registration.bats @@ -0,0 +1,78 @@ +#!/usr/bin/env bats +# vim: ft=sh:sw=2:et + +set -o pipefail + +load os_helper +load foreman_helper +load fixtures/content + +@test "remove subscription manager" { + if [ -e "/etc/rhsm/ca/candlepin-local.pem" ]; then + rpm -e `rpm -qf /etc/rhsm/ca/candlepin-local.pem` + fi + + cleanSubscriptionManager + tPackageRemove subscription-manager +} + +@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 with global registration with activation key" { + run yum erase -y 'katello-ca-consumer-*' + echo "rc=${status}" + echo "${output}" + + organization_info=$(hammer --output json organization info --name "${ORGANIZATION}") + organization_id=$(echo $organization_info | ruby -e "require 'json'; puts JSON.load(ARGF.read)['Id']") + + curl_command="curl https://admin:changeme@$HOSTNAME/api/registration_commands -X POST -H 'Content-Type: application/json' -d '{\"activation_key\":\"${ACTIVATION_KEY}\",\"organization_id\":\"${organization_id}\"}'" + registration_json=$(eval $curl_command) + echo "${registration_json}" + + registration_command=$(echo "${registration_json}" | ruby -e "require 'json'; puts JSON.load(ARGF.read).fetch('registration_command')") + eval $registration_command + subscription-manager list --consumed | grep "${PRODUCT}" +} + +@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 locally" { + run yum -y remove walrus + tPackageInstall walrus-0.71 && 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 "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 "cleanup subscription-manager after content tests" { + cleanSubscriptionManager +} diff --git a/bats/os_helper.bash b/bats/os_helper.bash index a417146e8..cc555bc22 100644 --- a/bats/os_helper.bash +++ b/bats/os_helper.bash @@ -107,6 +107,17 @@ tPackageUpgrade() { fi } +tPackageRemove() { + if tIsRedHatCompatible; then + yum -y remove $* + elif tIsDebianCompatible; then + export DEBIAN_FRONTEND=noninteractive + apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" remove $* + else + false # not implemented + fi +} + tPackageVersion() { if tIsRedHatCompatible; then rpm -q --qf "%{VERSION}\n" "$1" diff --git a/roles/bats/defaults/main.yaml b/roles/bats/defaults/main.yaml index c98021722..d41432d57 100644 --- a/roles/bats/defaults/main.yaml +++ b/roles/bats/defaults/main.yaml @@ -17,6 +17,7 @@ bats_tests: - "fb-test-katello.bats" - "fb-katello-content.bats" - "fb-katello-client.bats" + - "fb-katello-client-global-registration.bats" bats_tests_additional: [] bats_teardown: - "fb-destroy-organization.bats"