Debian Codegraph @

test/common/submanlib.py

raw
1 #
2 # Copyright (C) 2025 Red Hat, Inc.
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4
5
6 import os
7
8 import testlib
9 from machine import testvm
10
11
12 class SubscriptionCase(testlib.MachineCase):
13
14 def setup_candlepin_service(self, candlepin_machine: testvm.Machine) -> None:
15 m = self.machine
16
17 # wait for candlepin to be active and verify
18 candlepin_machine.execute("/root/run-candlepin", timeout=360)
19
20 # remove all existing products (RHEL server), as we can't control them
21 m.execute("rm -f /etc/pki/product-default/*.pem /etc/pki/product/*.pem")
22
23 # download product info from the candlepin machine and install it
24 product_file = os.path.join(self.tmpdir, "88888.pem")
25 candlepin_machine.download("/home/admin/candlepin/generated_certs/88888.pem", product_file)
26
27 # upload product info to the test machine
28 m.execute("mkdir -p /etc/pki/product-default")
29 m.upload([product_file], "/etc/pki/product-default")
30
31 # set up CA
32 ca = candlepin_machine.execute("cat /home/admin/candlepin/certs/candlepin-ca.crt")
33 m.write("/etc/pki/ca-trust/source/anchors/candlepin-ca.crt", ca)
34 m.write("/etc/hosts", "10.111.112.100 services.cockpit.lan\n", append=True)
35 m.execute("cp /etc/pki/ca-trust/source/anchors/candlepin-ca.crt /etc/rhsm/ca/candlepin-ca.pem")
36 m.execute("update-ca-trust")
37
38 # Wait for the web service to be accessible
39 m.execute("until curl --fail --silent --show-error https://services.cockpit.lan:8443/candlepin/status; do sleep 1; done")
40
41 # setup the repositories properly using the candlepin RPM GPG key
42 m.execute("curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-candlepin http://services.cockpit.lan:8080/RPM-GPG-KEY-candlepin")
43 m.execute("subscription-manager config --rhsm.baseurl http://services.cockpit.lan:8080")
44
45 # perform the additional configuration of subscription-manager
46 m.execute(
47 "subscription-manager config --server.hostname services.cockpit.lan --server.port 8443 --server.prefix /candlepin")
48
49 def register_with_candlepin(self) -> None:
50 self.machine.execute(
51 "LC_ALL=C.UTF-8 subscription-manager register --org=donaldduck --activationkey=awesome_os_pool")