From ef6a1ce27a3db462f458c1d8e177424605f1e7be Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 12 Nov 2024 17:17:24 +0100 Subject: [PATCH] add client based testing --- tests/client_test.py | 10 ++++++++++ tests/conftest.py | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/client_test.py diff --git a/tests/client_test.py b/tests/client_test.py new file mode 100644 index 0000000..49b4d0d --- /dev/null +++ b/tests/client_test.py @@ -0,0 +1,10 @@ +def test_foreman_content_view(client_environment, activation_key, organization, foremanapi, client): + client.run('dnf install -y subscription-manager') + rcmd = foremanapi.create('registration_commands', {'organization_id': organization['id'], 'insecure': True, 'activation_keys': [activation_key['name']]}) + client.run_test(rcmd['registration_command']) + client.run('subscription-manager repos --enable=*') + client.run_test('dnf install -y bear') + assert client.package('bear').is_installed + client.run('dnf remove -y bear') + client.run('subscription-manager unregister') + client.run('subscription-manager clean') diff --git a/tests/conftest.py b/tests/conftest.py index 975a118..0837b13 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,11 @@ def server(): yield testinfra.get_host('paramiko://quadlet', sudo=True, ssh_config='./.vagrant/ssh-config') +@pytest.fixture(scope="module") +def client(): + yield testinfra.get_host('paramiko://client', sudo=True, ssh_config='./.vagrant/ssh-config') + + @pytest.fixture(scope="module") def ssh_config(): config = paramiko.SSHConfig.from_path('./.vagrant/ssh-config') @@ -74,3 +79,23 @@ def activation_key(organization, foremanapi): ak = foremanapi.create('activation_keys', {'name': str(uuid.uuid4()), 'organization_id': organization['id']}) yield ak foremanapi.delete('activation_keys', ak) + +@pytest.fixture +def client_environment(activation_key, content_view, lifecycle_environment, yum_repository, organization, foremanapi): + foremanapi.resource_action('repositories', 'sync', {'id': yum_repository['id']}) + foremanapi.update('content_views', {'id': content_view['id'], 'repository_ids': [yum_repository['id']]}) + foremanapi.resource_action('content_views', 'publish', {'id': content_view['id']}) + + library = foremanapi.list('lifecycle_environments', 'name=Library', {'organization_id': organization['id']})[0] + foremanapi.update('activation_keys', {'id': activation_key['id'], 'organization_id': organization['id'], 'environment_id': library['id'], 'content_view_id': content_view['id']}) + + yield activation_key + + foremanapi.update('activation_keys', {'id': activation_key['id'], 'organization_id': organization['id'], 'environment_id': None, 'content_view_id': None}) + + versions = foremanapi.list('content_view_versions', params={'content_view_id': content_view['id']}) + for version in versions: + current_environment_ids = {environment['id'] for environment in version['environments']} + for environment_id in current_environment_ids: + foremanapi.resource_action('content_views', 'remove_from_environment', params={'id': content_view['id'], 'environment_id': environment_id}) + foremanapi.delete('content_view_versions', version)