From b7f1d3dcdbe8278be4455bd315bd5f3c759c7484 Mon Sep 17 00:00:00 2001 From: Griffin Sullivan Date: Fri, 9 Feb 2024 14:45:58 -0500 Subject: [PATCH] Integrate FAM pipeline into robottelo --- robottelo/constants/__init__.py | 6 +-- tests/foreman/sys/test_fam.py | 69 ++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index cdd352f85f4..f035390ffa7 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -1885,9 +1885,9 @@ class Colored(Box): "user", ] -FAM_MODULE_PATH = ( - '/usr/share/ansible/collections/ansible_collections/redhat/satellite/plugins/modules' -) +FAM_ROOT_DIR = '/usr/share/ansible/collections/ansible_collections/redhat/satellite' + +FAM_MODULE_PATH = f'{FAM_ROOT_DIR}/plugins/modules' RH_SAT_ROLES = [ 'activation_keys', diff --git a/tests/foreman/sys/test_fam.py b/tests/foreman/sys/test_fam.py index ebc9d155769..00ecb45d74f 100644 --- a/tests/foreman/sys/test_fam.py +++ b/tests/foreman/sys/test_fam.py @@ -11,9 +11,18 @@ :Team: Platform """ +from broker import Broker import pytest -from robottelo.constants import FAM_MODULE_PATH, FOREMAN_ANSIBLE_MODULES, RH_SAT_ROLES +from robottelo.config import settings +from robottelo.constants import ( + FAM_MODULE_PATH, + FAM_ROOT_DIR, + FOREMAN_ANSIBLE_MODULES, + RH_SAT_ROLES, +) + +TEST_ROLES_LIST = [f'{role}_role' for role in RH_SAT_ROLES] @pytest.fixture @@ -32,6 +41,48 @@ def sync_roles(target_sat): target_sat.cli.Ansible.roles_delete({'id': role_id}) +@pytest.fixture(scope='module') +def setup_fam(module_target_sat, module_sca_manifest): + # Execute AAP WF for FAM setup + Broker().execute(workflow='fam-test-setup', source_vm=module_target_sat.name) + + # Edit Makefile to not try to rebuild the collection when tests run + module_target_sat.execute(f"sed -i '/^live/ s/$(MANIFEST)//' {FAM_ROOT_DIR}/Makefile") + + # Upload manifest to test playbooks directory + module_target_sat.put(f'{module_sca_manifest.path}', f'{module_sca_manifest.name}') + module_target_sat.execute( + f'mv {module_sca_manifest.name} {FAM_ROOT_DIR}/tests/test_playbooks/data' + ) + + # Edit config file + config_file = f'{FAM_ROOT_DIR}/tests/test_playbooks/vars/server.yml' + module_target_sat.execute( + f'cp {FAM_ROOT_DIR}/tests/test_playbooks/vars/server.yml.example {config_file}' + ) + module_target_sat.execute( + f'sed -i "s/foreman.example.com/{module_target_sat.hostname}/g" {config_file}' + ) + module_target_sat.execute( + f'sed -i "s/rhsm_pool_id:.*/rhsm_pool_id: {settings.subscription.rhn_poolid}/g" {config_file}' + ) + module_target_sat.execute( + f'''sed -i 's/rhsm_username:.*/rhsm_username: "{settings.subscription.rhn_username}"/g' {config_file}''' + ) + module_target_sat.execute( + f'''sed -i 's|subscription_manifest_path:.*|subscription_manifest_path: "data/{module_sca_manifest.name}.zip"|g' {config_file}''' + ) + module_target_sat.execute( + f'''sed -i 's/rhsm_password:.*/rhsm_password: "{settings.subscription.rhn_password}"/g' {config_file}''' + ) + + # Handle color output formatting + module_target_sat.execute('export ANSIBLE_NOCOLOR=True && export PY_COLORS=0') + module_target_sat.execute( + f"sed -i 's/pytest -vv/pytest -v --color=no /g' {FAM_ROOT_DIR}/Makefile" + ) + + @pytest.mark.pit_server @pytest.mark.run_in_one_thread def test_positive_ansible_modules_installation(target_sat): @@ -71,3 +122,19 @@ def test_positive_import_run_roles(sync_roles, target_sat): target_sat.cli.Host.ansible_roles_assign({'ansible-roles': roles, 'name': target_sat.hostname}) play = target_sat.cli.Host.ansible_roles_play({'name': target_sat.hostname}) assert 'Ansible roles are being played' in play[0]['message'] + + +@pytest.mark.e2e +@pytest.mark.parametrize('ansible_module', FOREMAN_ANSIBLE_MODULES + TEST_ROLES_LIST) +def test_positive_run_modules_and_roles(module_target_sat, setup_fam, ansible_module): + """Run all FAM modules and roles on the Satellite + + :id: b595756f-627c-44ea-b738-aa17ff5b1d39 + + :expectedresults: All modules and roles run successfully + """ + # Execute test_playbook + result = module_target_sat.execute( + f'. ~/localenv/bin/activate && cd {FAM_ROOT_DIR} && make livetest_{ansible_module}' + ) + assert 'PASSED' in result.stdout