-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration tests for DBus Register Call
- Loading branch information
Showing
12 changed files
with
466 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Integration Test for subscription-manager | ||
|
||
There are integration tests for all parts of subscription-manager | ||
in this directory. | ||
|
||
DBus tests are presented currently - they verify DBus api of *rhsm.service* | ||
see [DBus objects](https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html) | ||
|
||
The tests use pytest ecosystem. | ||
|
||
## Installation | ||
|
||
1) Run local candlepin | ||
|
||
```shell | ||
podman run -d --name canlepin -p 8080:8080 -p 8443:8443 --hostname candlepin.local ghcr.io/ptoscano/candlepin-unofficial:latest | ||
``` | ||
|
||
2) Create additional testing data in candlepin | ||
|
||
Environments for *donaldduck* organization | ||
|
||
``` | ||
curl --stderr /dev/null --insecure --user admin:admin --request POST \ | ||
--data '{"id": "env-id-1", "name": "env-name-1", "description": "Testing environment num. 1"}' \ | ||
--header 'accept: application/json' --header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/donaldduck/environments | ||
curl --stderr /dev/null --insecure --user admin:admin --request POST \ | ||
--data '{"id": "env-id-2", "name": "env-name-2", "description": "Testing environment num. 2"}' \ | ||
--header 'accept: application/json' --header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/donaldduck/environments | ||
``` | ||
|
||
Activation keys for *donaldduck* organization | ||
|
||
```shell | ||
curl -k --request POST --user {{ username }}:{{ password }} --data '{"name":"{{ item }}"}' --header 'accept: application/json' --header 'content-type: application/json' https://localhost:8443/candlepin/owners/donaldduck/activation_keys | ||
``` | ||
|
||
## Configuration | ||
|
||
Tests use [Dynaconf](https://www.dynaconf.com/) to load config | ||
values. | ||
|
||
They are stored in a file in this directory *settings.toml* | ||
|
||
Config values for _testing_ environment | ||
|
||
```yaml | ||
[testing] | ||
candlepin.host = "localhost" | ||
candlepin.port = 8443 | ||
candlepin.insecure = true | ||
candlepin.prefix = "/candlepin" | ||
candlepin.username = "duey" | ||
candlepin.password = "password" | ||
candlepin.org = "donaldduck" | ||
candlepin.activation_keys = ["act-key-01","act-key-02"] | ||
candlepin.environment.names = ["env-name-01","env-name-02"] | ||
candlepin.environment.ids = ["env-id-01","env-id-02"] | ||
|
||
insights.legacy_upload = false | ||
console.host = "cert.console.redhat.com" | ||
|
||
auth_proxy.host = | ||
auth_proxy.port = 3127 | ||
auth_proxy.username = "redhat" | ||
auth_proxy.password = "redhat" | ||
|
||
noauth_proxy.host = | ||
noauth_proxy.port = 3129 | ||
|
||
insights.hbi_host = "cert.console.redhat.com" | ||
``` | ||
|
||
Configuration for pytest | ||
|
||
> There is a file pytest.ini in the main directory of this repo. | ||
> It has nothing to do with integration-tests. It is a confiuration | ||
> for unittests. | ||
*integration-tests/pytest.ini* | ||
|
||
```ini | ||
[pytest] | ||
addopts = "-srxv --capture=sys" | ||
testpaths = "./" | ||
log_cli = true | ||
log_level = INFO | ||
``` | ||
|
||
## Environment for testing | ||
|
||
```shell | ||
cd integration-tests | ||
python3 -mvenv venv | ||
source venv | ||
pip install -r requirements.txt | ||
deactivate | ||
``` | ||
|
||
|
||
## Running the tests | ||
|
||
```shell | ||
cd integration-tests | ||
source venv | ||
pytest | ||
deativate | ||
``` | ||
|
||
> There is a nice help for pytest in [Testing](../TESTING.md). It is | ||
> full of interesting hits to run just a few tests, to increase output | ||
> of a test run ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
import subprocess | ||
import logging | ||
import os | ||
|
||
from dasbus.connection import MessageBus | ||
from gi.repository import Gio | ||
|
||
import gi | ||
|
||
gi.require_version("Gio", "2.0") | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def install_katello_rpm(test_config): | ||
if "satellite" in test_config.environment: | ||
# install katello rpm before register system against Satellite | ||
satellite_hostname = test_config.get("candlepin", "host") | ||
cmd = [ | ||
"rpm", | ||
"-Uvh", | ||
"http://%s/pub/katello-ca-consumer-latest.noarch.rpm" % satellite_hostname, | ||
] | ||
subprocess.check_call(cmd) | ||
yield | ||
if "satellite" in test_config.environment: | ||
cmd = "rpm -qa 'katello-ca-consumer*' | xargs rpm -e" | ||
subprocess.check_call(cmd, shell=True) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def register_subman(external_candlepin, install_katello_rpm, subman_session, test_config): | ||
if "satellite" in test_config.environment: | ||
subman_session.register( | ||
activationkey=test_config.get("candlepin", "activation_keys"), | ||
org=test_config.get("candlepin", "org"), | ||
) | ||
else: | ||
subman_session.register( | ||
username=test_config.get("candlepin", "username"), | ||
password=test_config.get("candlepin", "password"), | ||
) | ||
yield subman_session | ||
|
||
|
||
class RHSMPrivateBus(MessageBus): | ||
"""Representation of RHSM private bus connection that can be used as a context manager.""" | ||
|
||
def __init__(self, rhsm_register_server_proxy, *args, **kwargs): | ||
"""Representation of RHSM private bus connection that can be used as a context manager. | ||
:param rhsm_register_server_proxy: DBus proxy for the RHSM RegisterServer object | ||
""" | ||
super().__init__(*args, **kwargs) | ||
self._rhsm_register_server_proxy = rhsm_register_server_proxy | ||
self._private_bus_address = None | ||
|
||
def __enter__(self): | ||
logger.debug("subscription: starting RHSM private DBus session") | ||
locale = os.environ.get("LANG", "") | ||
self._private_bus_address = self._rhsm_register_server_proxy.Start(locale) | ||
logger.debug("subscription: RHSM private DBus session has been started") | ||
return self | ||
|
||
def __exit__(self, _exc_type, _exc_value, _exc_traceback): | ||
logger.debug("subscription: shutting down the RHSM private DBus session") | ||
self.disconnect() | ||
locale = os.environ.get("LANG", "") | ||
self._rhsm_register_server_proxy.Stop(locale) | ||
logger.debug("subscription: RHSM private DBus session has been shutdown") | ||
|
||
def _get_connection(self): | ||
"""Get a connection to RHSM private DBus session.""" | ||
# the RHSM private bus address is potentially sensitive | ||
# so we will not log it | ||
logger.info("Connecting to the RHSM private DBus session.") | ||
return self._provider.get_addressed_bus_connection( | ||
bus_address=self._private_bus_address, flags=Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dasbus.identifier import DBusObjectIdentifier, DBusServiceIdentifier | ||
from dasbus.connection import SystemMessageBus | ||
|
||
|
||
HOST_DETAILS: str = "/var/lib/insights/host-details.json" | ||
MACHINE_ID_FILE: str = "/etc/insights-client/machine-id" | ||
RHSM_CONFIG_FILE_PATH: str = "/etc/rhsm/rhsm.conf" | ||
|
||
RHSM_NAMESPACE = ("com", "redhat", "RHSM1") | ||
|
||
RHSM = DBusServiceIdentifier(namespace=RHSM_NAMESPACE, message_bus=SystemMessageBus()) | ||
|
||
RHSM_CONFIG = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Config") | ||
|
||
RHSM_REGISTER_SERVER = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="RegisterServer") | ||
|
||
RHSM_REGISTER = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Register") | ||
|
||
RHSM_UNREGISTER = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Unregister") | ||
|
||
RHSM_ENTITLEMENT = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Entitlement") | ||
|
||
RHSM_SYSPURPOSE = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Syspurpose") | ||
|
||
RHSM_CONSUMER = DBusObjectIdentifier(namespace=RHSM_NAMESPACE, basename="Consumer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
addopts = "-srxv -vvv --capture=sys" | ||
testpaths = "./" | ||
log_cli = true | ||
log_level = DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
# the version of black is specified also in the stylish.yml github workflow; | ||
# please update the version there in case it is bumped here | ||
black==24.3.0 | ||
flake8 | ||
git+https://github.com/ptoscano/pytest-client-tools@main | ||
pytest | ||
pyyaml | ||
pytest-randomly | ||
pytest-timeout | ||
simplejson | ||
dasbus | ||
pycairo | ||
PyGObject | ||
sh | ||
iniparse | ||
funcy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
USERNAME=duey | ||
PASSWORD=password | ||
ORG=donaldduck | ||
|
||
curl -k --request POST --user ${USERNAME}:${PASSWORD} \ | ||
--data '{"name":"act-key-01"}' \ | ||
--header 'accept: application/json' \ | ||
--header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/${ORG}/activation_keys | ||
|
||
|
||
curl -k --request POST --user ${USERNAME}:${PASSWORD} \ | ||
--data '{"name":"act-key-02"}' \ | ||
--header 'accept: application/json' \ | ||
--header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/${ORG}/activation_keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
USERNAME=admin | ||
PASSWORD=admin | ||
ORG=donaldduck | ||
|
||
curl -k --request POST --user ${USERNAME}:${PASSWORD} \ | ||
--data '{"id": "env-id-01", "name": "env-name-01", "description": "Testing environment num. 1"}' \ | ||
--header 'accept: application/json' \ | ||
--header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/${ORG}/environments | ||
|
||
curl -k --request POST --user ${USERNAME}:${PASSWORD} \ | ||
--data '{"id": "env-id-02", "name": "env-name-02", "description": "Testing environment num. 2"}' \ | ||
--header 'accept: application/json' \ | ||
--header 'content-type: application/json' \ | ||
https://localhost:8443/candlepin/owners/${ORG}/environments | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
podman run -d --name candlepin -p 8080:8080 -p 8443:8443 --hostname candlepin.local ghcr.io/ptoscano/candlepin-unofficial:latest |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.