From 3a8ab0146cca1fcb17c3ac2351faa2c0bbce0a65 Mon Sep 17 00:00:00 2001 From: Omkar Khatavkar Date: Thu, 9 Mar 2023 17:54:18 +0530 Subject: [PATCH] [class_parameter, bookmark, satellite_sync] - Upgrade scenario refactor (#10638) * added the support for class parameter upgrade * refactored and tested upgrade scenarios for bookmark --- pytest_fixtures/component/contentview.py | 26 ---- pytest_fixtures/component/puppet.py | 24 +-- pytest_fixtures/core/upgrade.py | 2 +- robottelo/constants/__init__.py | 15 ++ robottelo/host_helpers/__init__.py | 3 +- robottelo/host_helpers/satellite_mixins.py | 53 +++++++ tests/foreman/cli/test_satellitesync.py | 142 +++++++++--------- .../foreman/destructive/test_puppetplugin.py | 5 +- tests/upgrades/conftest.py | 45 +++++- tests/upgrades/test_bookmarks.py | 17 +-- tests/upgrades/test_classparameter.py | 35 +++-- tests/upgrades/test_satellitesync.py | 96 ++++++------ 12 files changed, 262 insertions(+), 201 deletions(-) diff --git a/pytest_fixtures/component/contentview.py b/pytest_fixtures/component/contentview.py index 8b7bfbea1b9..e82f69d04b5 100644 --- a/pytest_fixtures/component/contentview.py +++ b/pytest_fixtures/component/contentview.py @@ -54,29 +54,3 @@ def module_cv_repo(module_org, module_repository, module_lce, module_target_sat) content_view = content_view.read() content_view.version[0].promote(data={'environment_ids': module_lce.id, 'force': False}) return content_view - - -@pytest.fixture -def set_importing_org(request, module_target_sat): - """ - Sets same CV, product and repository in importing organization as exporting organization - """ - product_name, repo_name, cv_name, mos = request.param - importing_org = module_target_sat.api.Organization().create() - importing_prod = module_target_sat.api.Product( - organization=importing_org, name=product_name - ).create() - - importing_repo = module_target_sat.api.Repository( - name=repo_name, - mirror_on_sync=mos, - download_policy='immediate', - product=importing_prod, - ).create() - - importing_cv = module_target_sat.api.ContentView( - name=cv_name, organization=importing_org - ).create() - importing_cv.repository = [importing_repo] - importing_cv.update(['repository']) - yield [importing_cv, importing_org] diff --git a/pytest_fixtures/component/puppet.py b/pytest_fixtures/component/puppet.py index 3b731f2f0da..857e499956b 100644 --- a/pytest_fixtures/component/puppet.py +++ b/pytest_fixtures/component/puppet.py @@ -2,28 +2,11 @@ import pytest from robottelo.config import settings +from robottelo.constants import COMMON_INSTALLER_OPTS as common_opts from robottelo.constants import ENVIRONMENT from robottelo.utils.installer import InstallerCommand -common_opts = { - 'foreman-proxy-puppetca': 'true', - 'foreman-proxy-puppet': 'true', - 'puppet-server': 'true', - # Options for puppetbootstrap test - 'foreman-proxy-templates': 'true', - 'foreman-proxy-http': 'true', -} - -enable_satellite_cmd = InstallerCommand( - installer_args=[ - 'enable-foreman-plugin-puppet', - 'enable-foreman-cli-puppet', - 'enable-puppet', - ], - installer_opts=common_opts, -) - enable_capsule_cmd = InstallerCommand( installer_args=[ 'enable-puppet', @@ -35,10 +18,7 @@ @pytest.fixture(scope='session') def session_puppet_enabled_sat(session_satellite_host): """Satellite with enabled puppet plugin""" - result = session_satellite_host.execute(enable_satellite_cmd.get_command(), timeout='20m') - assert result.status == 0 - session_satellite_host.execute('hammer -r') # workaround for BZ#2039696 - yield session_satellite_host + yield session_satellite_host.enable_puppet() @pytest.fixture(scope='module') diff --git a/pytest_fixtures/core/upgrade.py b/pytest_fixtures/core/upgrade.py index be3b318834c..b38536b61f7 100644 --- a/pytest_fixtures/core/upgrade.py +++ b/pytest_fixtures/core/upgrade.py @@ -4,7 +4,7 @@ @pytest.fixture(scope="function") def dependent_scenario_name(request): """ - This fixture is used to collect the depend test case name. + This fixture is used to collect the dependent test case name. """ depend_test_name = [ mark.kwargs['depend_on'].__name__ diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index 17189303840..3f2b16855ea 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -812,6 +812,21 @@ class Colored(Box): } CUSTOM_PUPPET_MODULE_REPOS_VERSION = '-0.2.0.tar.gz' +PULP_EXPORT_DIR = '/var/lib/pulp/exports/' +PULP_IMPORT_DIR = '/var/lib/pulp/imports/' +COMMON_INSTALLER_OPTS = { + 'foreman-proxy-puppetca': 'true', + 'foreman-proxy-content-puppet': 'true', + 'foreman-proxy-puppet': 'true', + 'puppet-server': 'true', + 'puppet-server-foreman-ssl-ca': '/etc/pki/katello/puppet/puppet_client_ca.crt', + 'puppet-server-foreman-ssl-cert': '/etc/pki/katello/puppet/puppet_client.crt', + 'puppet-server-foreman-ssl-key': '/etc/pki/katello/puppet/puppet_client.key', + # Options for puppetbootstrap test + 'foreman-proxy-templates': 'true', + 'foreman-proxy-http': 'true', +} + KICKSTART_CONTENT = [ 'treeinfo', 'images/pxeboot/initrd.img', diff --git a/robottelo/host_helpers/__init__.py b/robottelo/host_helpers/__init__.py index b513ded5246..7e54915bd59 100644 --- a/robottelo/host_helpers/__init__.py +++ b/robottelo/host_helpers/__init__.py @@ -2,6 +2,7 @@ from robottelo.host_helpers.contenthost_mixins import SystemFacts from robottelo.host_helpers.contenthost_mixins import VersionedContent from robottelo.host_helpers.satellite_mixins import ContentInfo +from robottelo.host_helpers.satellite_mixins import EnablePlugins from robottelo.host_helpers.satellite_mixins import Factories from robottelo.host_helpers.satellite_mixins import SystemInfo @@ -14,5 +15,5 @@ class CapsuleMixins(CapsuleInfo): pass -class SatelliteMixins(ContentInfo, Factories, SystemInfo): +class SatelliteMixins(ContentInfo, Factories, SystemInfo, EnablePlugins): pass diff --git a/robottelo/host_helpers/satellite_mixins.py b/robottelo/host_helpers/satellite_mixins.py index 7d8134978b9..548ff03ac98 100644 --- a/robottelo/host_helpers/satellite_mixins.py +++ b/robottelo/host_helpers/satellite_mixins.py @@ -1,5 +1,6 @@ import contextlib import io +import os import random import re @@ -8,12 +9,34 @@ from robottelo.cli.base import CLIReturnCodeError from robottelo.cli.proxy import CapsuleTunnelError from robottelo.config import settings +from robottelo.constants import COMMON_INSTALLER_OPTS as common_opts +from robottelo.constants import PULP_EXPORT_DIR +from robottelo.constants import PULP_IMPORT_DIR from robottelo.host_helpers.api_factory import APIFactory from robottelo.host_helpers.cli_factory import CLIFactory from robottelo.logging import logger +from robottelo.utils.installer import InstallerCommand from robottelo.utils.manifest import clone +class EnablePlugins: + """Miscellaneous settings helper methods""" + + def enable_puppet(self): + enable_satellite_cmd = InstallerCommand( + installer_args=[ + 'enable-foreman-plugin-puppet', + 'enable-foreman-cli-puppet', + 'enable-puppet', + ], + installer_opts=common_opts, + ) + result = self.execute(enable_satellite_cmd.get_command(), timeout='20m') + assert result.status == 0 + self.execute('hammer -r') # workaround for BZ#2039696 + return self + + class ContentInfo: """Miscellaneous content helper methods""" @@ -168,6 +191,25 @@ def publish_content_view(self, org, repo_list): content_view = content_view.read() return content_view + def move_pulp_archive(self, org, export_message): + """ + Moves exported archive(s) and its metadata into import directory, + sets ownership, returns import path + """ + self.execute( + f'mv {PULP_EXPORT_DIR}/{org.name} {PULP_IMPORT_DIR} && ' + f'chown -R pulp:pulp {PULP_IMPORT_DIR}' + ) + + # removes everything before export path, + # replaces EXPORT_PATH by IMPORT_PATH, + # removes metadata filename + import_path = os.path.dirname( + re.sub(rf'.*{PULP_EXPORT_DIR}', PULP_IMPORT_DIR, export_message) + ) + + return import_path + class SystemInfo: """Things that needs access to satellite shell for gaining satellite system configuration""" @@ -258,6 +300,17 @@ def default_url_on_new_port(self, oldport, newport): logger.debug(f'Killing ncat pid: {ncat_pid}') self.execute(f'kill {ncat_pid.pop()}') + def validate_pulp_filepath( + self, + org, + dir_path, + file_names=['*.json', '*.tar.gz'], + ): + """Checks the existence of certain files in a pulp dir""" + extension_query = ' -o '.join([f'-name "{file}"' for file in file_names]) + result = self.execute(fr'find {dir_path}{org.name} -type f \( {extension_query} \)') + return result.stdout + class Factories: """Mixin that provides attributes for each factory type""" diff --git a/tests/foreman/cli/test_satellitesync.py b/tests/foreman/cli/test_satellitesync.py index 985ff4c7cdb..52a20eca3a0 100644 --- a/tests/foreman/cli/test_satellitesync.py +++ b/tests/foreman/cli/test_satellitesync.py @@ -16,8 +16,6 @@ :Upstream: No """ -import os.path -import re from random import randint import pytest @@ -42,13 +40,12 @@ from robottelo.constants import CONTAINER_REGISTRY_HUB from robottelo.constants import DEFAULT_CV from robottelo.constants import PRDS +from robottelo.constants import PULP_EXPORT_DIR +from robottelo.constants import PULP_IMPORT_DIR from robottelo.constants import REPOS from robottelo.constants import REPOSET from robottelo.constants.repos import ANSIBLE_GALAXY -EXPORT_DIR = '/var/lib/pulp/exports/' -IMPORT_DIR = '/var/lib/pulp/imports/' - @pytest.fixture(scope='class') def config_export_import_settings(): @@ -68,8 +65,10 @@ def export_import_cleanup_function(target_sat, function_org): """Deletes export/import dirs of function org""" yield # Deletes directories created for export/import test - target_sat.execute(f'rm -rf {EXPORT_DIR}/{function_org.name}') - target_sat.execute(f'rm -rf {IMPORT_DIR}/{function_org.name}') + target_sat.execute( + f'rm -rf {PULP_EXPORT_DIR}/{function_org.name} {PULP_IMPORT_DIR}/{function_org.name}', + status=0, + ) @pytest.fixture(scope='function') # perform the cleanup after each testcase of a module @@ -77,32 +76,9 @@ def export_import_cleanup_module(target_sat, module_org): """Deletes export/import dirs of module_org""" yield # Deletes directories created for export/import test - target_sat.execute(f'rm -rf {EXPORT_DIR}/{module_org.name}') - target_sat.execute(f'rm -rf {IMPORT_DIR}/{module_org.name}') - - -def validate_filepath(sat_obj, org): - """Checks the existence of certain files in a dir""" - result = sat_obj.execute( - fr'find {EXPORT_DIR}{org.name} -type f \( -name "*.json" -o -name "*.tar.gz" \)' + target_sat.execute( + f'rm -rf {PULP_EXPORT_DIR}/{module_org.name} {PULP_IMPORT_DIR}/{module_org.name}' ) - return result.stdout - - -def move_pulp_archive(sat_obj, org, export_message): - """ - Moves exported archive(s) and its metadata into import directory, - sets ownership, returns import path - """ - sat_obj.execute(f'mv {EXPORT_DIR}/{org.name} {IMPORT_DIR}') - sat_obj.execute(f'chown -R pulp:pulp {IMPORT_DIR}') - - # removes everything before export path, - # replaces EXPORT_PATH by IMPORT_PATH, - # removes metadata filename - import_path = os.path.dirname(re.sub(rf'.*{EXPORT_DIR}', IMPORT_DIR, export_message)) - - return import_path @pytest.mark.run_in_one_thread @@ -147,11 +123,11 @@ def test_positive_export_complete_version_custom_repo( assert len(cv['versions']) == 1 cvv = cv['versions'][0] # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export content view ContentExport.completeVersion({'id': cvv['id'], 'organization-id': module_org.id}) # Verify export directory is not empty - assert validate_filepath(target_sat, module_org) != '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier3 def test_positive_export_incremental_version_custom_repo( @@ -195,12 +171,12 @@ def test_positive_export_incremental_version_custom_repo( assert len(cv['versions']) == 1 cvv = cv['versions'][0] # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export complete first, then incremental ContentExport.completeVersion({'id': cvv['id'], 'organization-id': module_org.id}) ContentExport.incrementalVersion({'id': cvv['id'], 'organization-id': module_org.id}) # Verify export directory is not empty - assert validate_filepath(target_sat, module_org) != '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier3 def test_positive_export_complete_library_custom_repo( @@ -235,11 +211,11 @@ def test_positive_export_complete_library_custom_repo( ) ContentView.publish({'id': cv['id']}) # Verify export directory is empty - assert validate_filepath(target_sat, function_org) == '' + assert target_sat.validate_pulp_filepath(function_org, PULP_EXPORT_DIR) == '' # Export content view ContentExport.completeLibrary({'organization-id': function_org.id}) # Verify export directory is not empty - assert validate_filepath(target_sat, function_org) != '' + assert target_sat.validate_pulp_filepath(function_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier3 def test_positive_export_incremental_library_custom_repo( @@ -275,12 +251,12 @@ def test_positive_export_incremental_library_custom_repo( ) ContentView.publish({'id': cv['id']}) # Verify export directory is empty - assert validate_filepath(target_sat, function_org) == '' + assert target_sat.validate_pulp_filepath(function_org, PULP_EXPORT_DIR) == '' # Export complete library, then export incremental ContentExport.completeLibrary({'organization-id': function_org.id}) ContentExport.incrementalLibrary({'organization-id': function_org.id}) # Verify export directory is not empty - assert validate_filepath(target_sat, function_org) != '' + assert target_sat.validate_pulp_filepath(function_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier3 @pytest.mark.upgrade @@ -333,13 +309,19 @@ def test_positive_export_complete_version_rh_repo( assert len(cv['versions']) == 1 cvv = cv['versions'][0] # Verify export directory is empty - assert validate_filepath(target_sat, module_entitlement_manifest_org) == '' + assert ( + target_sat.validate_pulp_filepath(module_entitlement_manifest_org, PULP_EXPORT_DIR) + == '' + ) # Export content view ContentExport.completeVersion( {'id': cvv['id'], 'organization-id': module_entitlement_manifest_org.id} ) # Verify export directory is not empty - assert validate_filepath(target_sat, module_entitlement_manifest_org) != '' + assert ( + target_sat.validate_pulp_filepath(module_entitlement_manifest_org, PULP_EXPORT_DIR) + != '' + ) @pytest.mark.tier3 @pytest.mark.upgrade @@ -389,11 +371,17 @@ def test_positive_complete_library_rh_repo( ) ContentView.publish({'id': cv['id']}) # Verify export directory is empty - assert validate_filepath(target_sat, function_entitlement_manifest_org) == '' + assert ( + target_sat.validate_pulp_filepath(function_entitlement_manifest_org, PULP_EXPORT_DIR) + == '' + ) # Export content view ContentExport.completeLibrary({'organization-id': function_entitlement_manifest_org.id}) # Verify export directory is not empty - assert validate_filepath(target_sat, function_entitlement_manifest_org) != '' + assert ( + target_sat.validate_pulp_filepath(function_entitlement_manifest_org, PULP_EXPORT_DIR) + != '' + ) @pytest.fixture(scope='class') @@ -586,12 +574,12 @@ def test_positive_export_import_cv_end_to_end( exported_packages = Package.list({'content-view-version-id': export_cvv_id}) assert len(exported_packages) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': export_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # importing portion importing_org = make_org() @@ -701,11 +689,11 @@ def test_positive_export_import_default_org_view( cv_packages = Package.list({'content-view-version-id': default_cvv_id}) assert len(cv_packages) # Verify export directory is empty - assert validate_filepath(target_sat, function_org) == '' + assert target_sat.validate_pulp_filepath(function_org, PULP_EXPORT_DIR) == '' # Export complete library export = ContentExport.completeLibrary({'organization-id': function_org.id}) # Verify 'export-library' is created and packages are there - import_path = move_pulp_archive(target_sat, function_org, export['message']) + import_path = target_sat.move_pulp_archive(function_org, export['message']) export_lib_cv = ContentView.info( { 'name': export_library, @@ -802,12 +790,12 @@ def test_positive_export_import_filtered_cvv( export_packages = Package.list({'content-view-version-id': exporting_cvv_id}) assert len(export_packages) == 1 # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': exporting_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # Import section importing_org = make_org() @@ -872,12 +860,12 @@ def test_positive_export_import_promoted_cv( exported_packages = Package.list({'content-view-version-id': promoted_cvv_id}) assert len(exported_packages) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': export_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # importing portion importing_org = make_org() @@ -977,14 +965,17 @@ def test_positive_export_import_redhat_cv( assert len(cv['versions']) == 1 cvv = cv['versions'][0] # Verify export directory is empty - assert validate_filepath(target_sat, function_entitlement_manifest_org) == '' + assert ( + target_sat.validate_pulp_filepath(function_entitlement_manifest_org, PULP_EXPORT_DIR) + == '' + ) # Export cv export = ContentExport.completeVersion( {'id': cvv['id'], 'organization-id': function_entitlement_manifest_org.id}, timeout=7200000, ) - import_path = move_pulp_archive( - target_sat, function_entitlement_manifest_org, export['message'] + import_path = target_sat.move_pulp_archive( + function_entitlement_manifest_org, export['message'] ) exported_packages = Package.list({'content-view-version-id': cvv['id']}) assert len(exported_packages) @@ -1108,8 +1099,8 @@ def test_positive_export_import_redhat_cv_with_huge_contents( {'id': cvv['id'], 'organization-id': function_entitlement_manifest_org.id}, timeout=7200000, ) - import_path = move_pulp_archive( - target_sat, function_entitlement_manifest_org, export['message'] + import_path = target_sat.move_pulp_archive( + function_entitlement_manifest_org, export['message'] ) exported_packages = Package.list({'content-view-version-id': cvv['id']}) assert len(exported_packages) @@ -1219,7 +1210,7 @@ def test_positive_export_cv_with_on_demand_repo( ContentView.publish({'id': cv['id']}) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export Content View version result = ContentExport.completeVersion( @@ -1239,7 +1230,7 @@ def test_positive_export_cv_with_on_demand_repo( # Export is generated assert "Generated" in result - assert validate_filepath(target_sat, module_org) != '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier2 def test_negative_import_same_cv_twice( @@ -1271,12 +1262,12 @@ def test_negative_import_same_cv_twice( export_cvv_id = class_export_entities['exporting_cvv_id'] export_cv_name = class_export_entities['exporting_cv_name'] # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': export_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # importing portion importing_org = make_org() @@ -1311,7 +1302,7 @@ def test_negative_import_invalid_path(self, module_org): displayed """ export_folder = gen_string('alpha') - import_path = f'{IMPORT_DIR}{export_folder}' + import_path = f'{PULP_IMPORT_DIR}{export_folder}' # Import section with pytest.raises(CLIReturnCodeError) as error: ContentImport.version({'organization-id': module_org.id, 'path': import_path}) @@ -1387,7 +1378,7 @@ def test_negative_export_cv_with_on_demand_repo( ContentView.publish({'id': cv['id']}) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export Content View version with pytest.raises(CLIReturnCodeError) as error: @@ -1399,7 +1390,7 @@ def test_negative_export_cv_with_on_demand_repo( assert error.status != 0 # Export is not generated - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' @pytest.mark.tier2 def test_positive_create_custom_major_minor_cv_version(self): @@ -1505,13 +1496,13 @@ def test_postive_export_cv_with_mixed_content_repos( exported_packages = Package.list({'content-view-version-id': exporting_cvv_id['id']}) assert len(exported_packages) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv ContentExport.completeVersion( {'id': exporting_cvv_id['id'], 'organization-id': module_org.id} ) # Verify export directory is not empty - assert validate_filepath(target_sat, module_org) != '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) != '' @pytest.mark.tier3 def test_postive_import_export_cv_with_file_content( @@ -1565,12 +1556,12 @@ def test_postive_import_export_cv_with_file_content( exported_files = File.list({'content-view-version-id': exporting_cvv_id}) assert len(exported_files) # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': exporting_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # importing portion importing_org = make_org() @@ -1627,7 +1618,7 @@ def test_postive_import_export_ansible_collection_repo( Repository.synchronize({'id': ansible_repo['id']}) # Export library export = ContentExport.completeLibrary({'organization-id': function_org.id}) - import_path = move_pulp_archive(target_sat, function_org, export['message']) + import_path = target_sat.move_pulp_archive(function_org, export['message']) # importing portion importing_org = make_org() @@ -1714,13 +1705,16 @@ def test_negative_import_redhat_cv_without_manifest( assert len(cv['versions']) == 1 cvv = cv['versions'][0] # Verify export directory is empty - assert validate_filepath(target_sat, function_entitlement_manifest_org) == '' + assert ( + target_sat.validate_pulp_filepath(function_entitlement_manifest_org, PULP_EXPORT_DIR) + == '' + ) # Export cv export = ContentExport.completeVersion( {'id': cvv['id'], 'organization-id': function_entitlement_manifest_org.id} ) - import_path = move_pulp_archive( - target_sat, function_entitlement_manifest_org, export['message'] + import_path = target_sat.move_pulp_archive( + function_entitlement_manifest_org, export['message'] ) # check that files are present in import_path result = target_sat.execute(f'ls {import_path}') @@ -1767,12 +1761,12 @@ def test_positive_import_content_for_disconnected_sat_with_existing_content( export_cvv_id = class_export_entities['exporting_cvv_id'] export_cv_name = class_export_entities['exporting_cv_name'] # Verify export directory is empty - assert validate_filepath(target_sat, module_org) == '' + assert target_sat.validate_pulp_filepath(module_org, PULP_EXPORT_DIR) == '' # Export cv export = ContentExport.completeVersion( {'id': export_cvv_id, 'organization-id': module_org.id} ) - import_path = move_pulp_archive(target_sat, module_org, export['message']) + import_path = target_sat.move_pulp_archive(module_org, export['message']) # importing portion importing_org = make_org() # set disconnected mode diff --git a/tests/foreman/destructive/test_puppetplugin.py b/tests/foreman/destructive/test_puppetplugin.py index 846ee509e69..13cd084fc3f 100644 --- a/tests/foreman/destructive/test_puppetplugin.py +++ b/tests/foreman/destructive/test_puppetplugin.py @@ -19,7 +19,6 @@ import pytest from pytest_fixtures.component.puppet import enable_capsule_cmd -from pytest_fixtures.component.puppet import enable_satellite_cmd from robottelo.hosts import Satellite puppet_cli_commands = [ @@ -95,9 +94,7 @@ def test_positive_enable_disable_logic(target_sat, capsule_configured): # Enable puppet on Satellite and check it succeeded. target_sat.register_to_cdn() - result = target_sat.execute(enable_satellite_cmd.get_command(), timeout='20m') - assert result.status == 0 - assert 'Success!' in result.stdout + target_sat.enable_puppet() assert_puppet_status(target_sat, expected=True) diff --git a/tests/upgrades/conftest.py b/tests/upgrades/conftest.py index 1bd9208f0bd..1ff24104a17 100644 --- a/tests/upgrades/conftest.py +++ b/tests/upgrades/conftest.py @@ -88,6 +88,7 @@ def test_capsule_post_upgrade_skipped(pre_upgrade_data): import pytest from automation_tools.satellite6.hammer import set_hammer_config +from box import Box from fabric.api import env from robottelo.config import settings @@ -160,6 +161,23 @@ def get_entity_data(scenario_name): return entity_data +def get_all_entity_data(): + """Retrieves a dictionary containing data for entities in all scenarios. + + Reads the contents of the 'scenario_entities' file using the JSON format, + and returns the resulting dictionary of entity data. + + Returns: + ------- + dict: + A dictionary containing information on entities in all scenarios, + with scenario_name as keys and corresponding attribute data as values. + """ + with open('scenario_entities') as pref: + entity_data = json.load(pref) + return entity_data + + def _read_test_data(test_node_id): """Read the saved data of test at node id""" try: @@ -223,7 +241,32 @@ def test_something_post_upgrade(pre_upgrade_data): data = [_read_test_data(test_node_id) for test_node_id in depend_on_node_ids] if len(data) == 1: data = data[0] - return data + return Box(data) + + +@pytest.fixture(scope='class') +def class_pre_upgrade_data(request): + """Returns a dictionary of entity data for a specific upgrade test classes. + + Filters the output of get_all_entity_data() to include only entities that + match the test class name and the name of the test function currently being run. + + Args: + ----- + request (pytest.FixtureRequest): A pytest FixtureRequest object containing + information about the current test. + + Returns: + ------- + Box: A Box object containing information on entities in the upgrade test class, + with entity IDs as keys and corresponding attribute data as values. + """ + data = { + key: value + for key, value in get_all_entity_data().items() + if f"{request.node.parent.name}::{request.node.name}" in key + } + return Box(data) def pytest_configure(config): diff --git a/tests/upgrades/test_bookmarks.py b/tests/upgrades/test_bookmarks.py index f1b0d37b426..dde6b112a3b 100644 --- a/tests/upgrades/test_bookmarks.py +++ b/tests/upgrades/test_bookmarks.py @@ -17,7 +17,6 @@ :Upstream: No """ import pytest -from nailgun import entities from robottelo.constants import BOOKMARK_ENTITIES @@ -29,7 +28,7 @@ class TestPublicDisableBookmark: """ @pytest.mark.pre_upgrade - def test_pre_create_public_disable_bookmark(self, request): + def test_pre_create_public_disable_bookmark(self, request, target_sat): """Create public disabled bookmarks for system entities using available bookmark data. @@ -53,7 +52,7 @@ def test_pre_create_public_disable_bookmark(self, request): for entity in BOOKMARK_ENTITIES: book_mark_name = entity["name"] + request.node.name - bm = entities.Bookmark( + bm = target_sat.api.Bookmark( controller=entity['controller'], name=book_mark_name, public=False, @@ -66,7 +65,7 @@ def test_pre_create_public_disable_bookmark(self, request): assert not bm.public @pytest.mark.post_upgrade(depend_on=test_pre_create_public_disable_bookmark) - def test_post_create_public_disable_bookmark(self, dependent_scenario_name): + def test_post_create_public_disable_bookmark(self, dependent_scenario_name, target_sat): """Check the status of public disabled bookmark for all the system entities(activation keys, tasks, compute profile, content hosts etc) after upgrade. @@ -85,7 +84,7 @@ def test_post_create_public_disable_bookmark(self, dependent_scenario_name): pre_test_name = dependent_scenario_name for entity in BOOKMARK_ENTITIES: book_mark_name = entity["name"] + pre_test_name - bm = entities.Bookmark().search(query={'search': f'name="{book_mark_name}"'})[0] + bm = target_sat.api.Bookmark().search(query={'search': f'name="{book_mark_name}"'})[0] assert bm.controller == entity['controller'] assert bm.name == book_mark_name assert bm.query == f"name={book_mark_name}" @@ -100,7 +99,7 @@ class TestPublicEnableBookmark: """ @pytest.mark.pre_upgrade - def test_pre_create_public_enable_bookmark(self, request): + def test_pre_create_public_enable_bookmark(self, request, target_sat): """Create public enable bookmark for system entities using available bookmark data. @@ -124,7 +123,7 @@ def test_pre_create_public_enable_bookmark(self, request): for entity in BOOKMARK_ENTITIES: book_mark_name = entity["name"] + request.node.name - bm = entities.Bookmark( + bm = target_sat.api.Bookmark( controller=entity['controller'], name=book_mark_name, public=True, @@ -136,7 +135,7 @@ def test_pre_create_public_enable_bookmark(self, request): assert bm.public @pytest.mark.post_upgrade(depend_on=test_pre_create_public_enable_bookmark) - def test_post_create_public_enable_bookmark(self, dependent_scenario_name): + def test_post_create_public_enable_bookmark(self, dependent_scenario_name, target_sat): """Check the status of public enabled bookmark for all the system entities(activation keys, tasks, compute profile, content hosts etc) after upgrade. @@ -155,7 +154,7 @@ def test_post_create_public_enable_bookmark(self, dependent_scenario_name): pre_test_name = dependent_scenario_name for entity in BOOKMARK_ENTITIES: book_mark_name = entity["name"] + pre_test_name - bm = entities.Bookmark().search(query={'search': f'name="{book_mark_name}"'})[0] + bm = target_sat.api.Bookmark().search(query={'search': f'name="{book_mark_name}"'})[0] assert bm.controller == entity['controller'] assert bm.name == book_mark_name assert bm.query == f"name={book_mark_name}" diff --git a/tests/upgrades/test_classparameter.py b/tests/upgrades/test_classparameter.py index c08a0215856..c22d39c48b1 100644 --- a/tests/upgrades/test_classparameter.py +++ b/tests/upgrades/test_classparameter.py @@ -19,7 +19,6 @@ import json import pytest -from nailgun import entities def _valid_sc_parameters_data(): @@ -52,28 +51,32 @@ class TestScenarioPositivePuppetParameterAndDatatypeIntact: """ @pytest.fixture(scope="class") - def _setup_scenario(self, target_sat, save_test_data): + def _setup_scenario(self, class_target_sat): """Import some parametrized puppet classes. This is required to make sure that we have smart class variable available. Read all available smart class parameters for imported puppet class to be able to work with unique entity for each specific test. """ - self.org = entities.Organization().create() + self.org = class_target_sat.api.Organization().create() repo = 'api_test_classparameters' - env_name = target_sat.create_custom_environment(repo=repo) - self.puppet_class = entities.PuppetClass().search( + env_name = class_target_sat.create_custom_environment(repo=repo) + self.puppet_class = class_target_sat.api.PuppetClass().search( query={'search': f'name = "{repo}" and environment = "{env_name}"'} )[0] - self.sc_params_list = entities.SmartClassParameters().search( + self.sc_params_list = class_target_sat.api.SmartClassParameters().search( query={'search': f'puppetclass="{self.puppet_class.name}"', 'per_page': 1000} ) - save_test_data({'puppet_class': self.puppet_class.name}) + return { + 'puppet_class': self.puppet_class.name, + } @pytest.fixture(scope="class") - def _clean_scenario(self, request, class_target_sat, pre_upgrade_data): + def _clean_scenario(self, request, class_pre_upgrade_data, class_target_sat): @request.addfinalizer def _cleanup(): - puppet_class = pre_upgrade_data.get('puppet_class') + puppet_class = getattr( + class_pre_upgrade_data, next(iter(class_pre_upgrade_data)) + ).puppet_class class_target_sat.delete_puppet_class(puppet_class) def _validate_value(self, data, sc_param): @@ -96,7 +99,9 @@ def _validate_value(self, data, sc_param): @pytest.mark.pre_upgrade @pytest.mark.parametrize('count', list(range(1, 10))) - def test_pre_puppet_class_parameter_data_and_type(self, count, _setup_scenario): + def test_pre_puppet_class_parameter_data_and_type( + self, class_target_sat, count, _setup_scenario, save_test_data + ): """Puppet Class parameters with different data type are created :id: preupgrade-08012f39-240b-40df-b893-2ee767129737 @@ -111,8 +116,9 @@ def test_pre_puppet_class_parameter_data_and_type(self, count, _setup_scenario): :expectedresults: The parameters are updated with different data types """ + save_test_data(_setup_scenario) data = _valid_sc_parameters_data()[count - 1] - sc_param = entities.SmartClassParameters().search( + sc_param = class_target_sat.api.SmartClassParameters().search( query={'search': f'parameter="api_classparameters_scp_00{count}"'} )[0] sc_param.override = True @@ -125,7 +131,9 @@ def test_pre_puppet_class_parameter_data_and_type(self, count, _setup_scenario): @pytest.mark.post_upgrade(depend_on=test_pre_puppet_class_parameter_data_and_type) @pytest.mark.parametrize('count', list(range(1, 10))) - def test_post_puppet_class_parameter_data_and_type(self, count, _clean_scenario): + def test_post_puppet_class_parameter_data_and_type( + self, count, _clean_scenario, class_pre_upgrade_data, class_target_sat + ): """Puppet Class Parameters value and type is intact post upgrade :id: postupgrade-08012f39-240b-40df-b893-2ee767129737 @@ -137,9 +145,8 @@ def test_post_puppet_class_parameter_data_and_type(self, count, _clean_scenario) :expectedresults: The puppet class parameters data and type should be intact post upgrade """ - data = _valid_sc_parameters_data()[count - 1] - sc_param = entities.SmartClassParameters().search( + sc_param = class_target_sat.api.SmartClassParameters().search( query={'search': f'parameter="api_classparameters_scp_00{count}"'} )[0] assert sc_param.parameter_type == data['sc_type'] diff --git a/tests/upgrades/test_satellitesync.py b/tests/upgrades/test_satellitesync.py index 1d067d967ef..5421ec00129 100644 --- a/tests/upgrades/test_satellitesync.py +++ b/tests/upgrades/test_satellitesync.py @@ -17,10 +17,8 @@ :Upstream: No """ import pytest -from nailgun import entities -from robottelo.cli.contentview import ContentView -from robottelo.cli.package import Package +from robottelo.constants import PULP_EXPORT_DIR class TestSatelliteSync: @@ -29,7 +27,7 @@ class TestSatelliteSync: """ @pytest.mark.pre_upgrade - def test_pre_version_cv_export_import(self, request): + def test_pre_version_cv_export_import(self, module_org, target_sat, save_test_data): """Before Upgrade, Create the content view and publish, and promote it. :id: preupgrade-f19e4928-94db-4df6-8ce8-b5e4afe34258 @@ -43,39 +41,28 @@ def test_pre_version_cv_export_import(self, request): :expectedresults: Before the upgrade, Content view published and promoted, and package count should be greater than 0. """ - test_name = request.node.name - org = entities.Organization(name=f"{test_name}_org").create() - product = entities.Product(organization=org, name=f"{test_name}_prod").create() - repo = entities.Repository( + product = target_sat.api.Product(organization=module_org).create() + repo = target_sat.api.Repository( product=product, - name=f"{test_name}_repo", - mirror_on_sync=False, download_policy='immediate', ).create() repo.sync() - cv = entities.ContentView(name=f"{test_name}_cv", organization=org).create() + cv = target_sat.api.ContentView(organization=module_org).create() cv.repository = [repo] cv.update(['repository']) cv.publish() cv = cv.read() assert cv.version[0].read().package_count > 0 + save_test_data( + { + "product": product.name, + "org": module_org.name, + "content_view": cv.name, + } + ) @pytest.mark.post_upgrade(depend_on=test_pre_version_cv_export_import) - @pytest.mark.parametrize( - 'set_importing_org', - [ - ( - "test_pre_version_cv_export_import_prod", - "test_pre_version_cv_export_import_repo", - "test_pre_version_cv_export_import_cv", - "no", - ) - ], - indirect=True, - ) - def test_post_version_cv_export_import( - self, request, set_importing_org, dependent_scenario_name, target_sat - ): + def test_post_version_cv_export_import(self, request, target_sat, pre_upgrade_data): """After upgrade, content view version import and export works on the existing content view(that we created before the upgrade). @@ -92,40 +79,51 @@ def test_post_version_cv_export_import( 1: Content view created before upgrade should be imported and exported successfully. 2: Imported and Exported content view should be deleted successfully """ - pre_test_name = dependent_scenario_name - export_base = '/var/lib/pulp/katello-export/' - org = entities.Organization().search(query={'search': f'name="{pre_test_name}_org"'})[0] + org = target_sat.api.Organization().search( + query={'search': f'name="{pre_upgrade_data.org}"'} + )[0] request.addfinalizer(org.delete) - product = entities.Product(organization=org).search( - query={'search': f'name="{pre_test_name}_prod"'} + product = target_sat.api.Product(organization=org).search( + query={'search': f'name="{pre_upgrade_data.product}"'} )[0] request.addfinalizer(product.delete) - exporting_cv = entities.ContentView(organization=org).search( - query={'search': f'name="{pre_test_name}_cv"'} + exporting_cv = target_sat.api.ContentView(organization=org).search( + query={'search': f'name="{pre_upgrade_data.content_view}"'} )[0] request.addfinalizer(exporting_cv.delete) exporting_cvv_id = max(cvv.id for cvv in exporting_cv.version) - exporting_cvv_version = entities.ContentViewVersion(id=exporting_cvv_id).read().version - - ContentView.version_export({'export-dir': f'{export_base}', 'id': exporting_cvv_id}) - exported_tar = f'{export_base}/export-{exporting_cv.name}-{exporting_cvv_version}.tar' - result = target_sat.execute(f'[ -f {exported_tar} ]') - assert result.status == 0 - - exported_packages = Package.list({'content-view-version-id': exporting_cvv_id}) + # Export content view + export = target_sat.cli.ContentExport.completeVersion( + {'id': exporting_cvv_id, 'organization-id': org.id} + ) + # Verify export directory is not empty + assert target_sat.validate_pulp_filepath(org, PULP_EXPORT_DIR) != '' + exported_packages = target_sat.cli.Package.list( + {'content-view-version-id': exporting_cvv_id} + ) assert len(exported_packages) > 0 - importing_cv, importing_org = set_importing_org - ContentView.version_import( - {'export-tar': f'{exported_tar}', 'organization-id': importing_org.id} + importing_org = target_sat.api.Organization().create() + + # Import files and verify content + import_path = target_sat.move_pulp_archive(org, export['message']) + target_sat.cli.ContentImport.version( + {'organization-id': importing_org.id, 'path': import_path} + ) + importing_cv = target_sat.cli.ContentView.info( + {'name': exporting_cv.name, 'organization-id': importing_org.id} ) - importing_cvv = importing_cv.read().version - assert len(importing_cvv) == 1 - imported_packages = Package.list({'content-view-version-id': importing_cvv[0].id}) - assert len(imported_packages) > 0 + importing_cvv = importing_cv['versions'] + assert len(importing_cvv) >= 1 + imported_packages = target_sat.cli.Package.list( + {'content-view-version-id': importing_cvv[0]['id']} + ) + assert len(imported_packages) assert len(exported_packages) == len(imported_packages) - target_sat.execute(f'rm -rf {export_base}/*') + importing_cv = target_sat.api.ContentView(organization=importing_org).search( + query={'search': f'name="{exporting_cv.name}"'} + )[0] exporting_cv_json = exporting_cv.read_json() importing_cv_json = importing_cv.read_json() exporting_cv_env_id = exporting_cv_json['environments'][0]['id']