Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global registration bats tests for Katello clients #1391

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions bats/fb-katello-client-global-registration.bats
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that so that the GR command can install it again?

Doesn't this break pulp3 on EL8 where this might kill python3-rhsm (or whatever the right pkg name is)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope not. I did not see any breaks with my testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you ran it on EL8 and it did not make pulp-certguard go belly up, we're good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good:

==========================================================================================================================================================================================================================================================================================
 Package                                                                              Architecture                                                Version                                                              Repository                                                    Size
==========================================================================================================================================================================================================================================================================================
Removing:
 subscription-manager                                                                 x86_64                                                      1.28.13-3.el8_4                                                      @baseos                                                      4.3 M
Removing unused dependencies:
 dnf-plugin-subscription-manager                                                      x86_64                                                      1.28.13-3.el8_4                                                      @baseos                                                       87 k
 python3-dmidecode                                                                    x86_64                                                      3.12.2-15.el8                                                        @baseos                                                      308 k
 python3-ethtool                                                                      x86_64                                                      0.14-3.el8                                                           @baseos                                                       92 k
 python3-inotify                                                                      noarch                                                      0.9.6-13.el8                                                         @baseos                                                      243 k
 python3-librepo                                                                      x86_64                                                      1.12.0-3.el8                                                         @baseos                                                      172 k
 usermode                                                                             x86_64                                                      1.113-1.el8                                                          @baseos                                                      837 k

Transaction Summary
==========================================================================================================================================================================================================================================================================================
Remove  7 Packages

}

@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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this duplicates the original content tests -- might want to move it to a helper later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, can do, as I have another test suite in mind that would do the same thing.

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
}
11 changes: 11 additions & 0 deletions bats/os_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions roles/bats/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bats_tests:
- "fb-test-katello.bats"
- "fb-katello-content.bats"
- "fb-katello-client.bats"
- "fb-katello-client-global-registration.bats"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably need to not include this for some versions of Foreman and Katello we currently support. What those would be, I am not presently sure of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.0+ I believe

bats_tests_additional: []
bats_teardown:
- "fb-destroy-organization.bats"