diff --git a/pytest_fixtures/component/activationkey.py b/pytest_fixtures/component/activationkey.py index 7ec8420861b..b710158984b 100644 --- a/pytest_fixtures/component/activationkey.py +++ b/pytest_fixtures/component/activationkey.py @@ -7,9 +7,12 @@ @pytest.fixture(scope='module') def module_activation_key(module_sca_manifest_org, module_target_sat): """Create activation key using default CV and library environment.""" + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_sca_manifest_org.default_content_view, + module_sca_manifest_org.library, + ) return module_target_sat.api.ActivationKey( - content_view=module_sca_manifest_org.default_content_view.id, - environment=module_sca_manifest_org.library.id, + content_view_environment_ids=[cvenv_id], organization=module_sca_manifest_org, ).create() @@ -17,9 +20,12 @@ def module_activation_key(module_sca_manifest_org, module_target_sat): @pytest.fixture def function_activation_key(function_sca_manifest_org, target_sat): """Create activation key using default CV and library environment.""" + cvenv_id = target_sat.api_factory.get_cvenv_id( + function_sca_manifest_org.default_content_view, + function_sca_manifest_org.library, + ) return target_sat.api.ActivationKey( - content_view=function_sca_manifest_org.default_content_view.id, - environment=function_sca_manifest_org.library.id, + content_view_environment_ids=[cvenv_id], organization=function_sca_manifest_org, ).create() @@ -33,27 +39,27 @@ def module_ak(module_org, module_target_sat): @pytest.fixture(scope='module') def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_sat): + cvenv_id = module_target_sat.api_factory.get_cvenv_id(module_promoted_cv, module_lce) return module_target_sat.api.ActivationKey( - content_view=module_promoted_cv, - environment=module_lce, + content_view_environment_ids=[cvenv_id], organization=module_org, ).create() @pytest.fixture def function_ak_with_cv(function_lce, function_org, function_promoted_cv, target_sat): + cvenv_id = target_sat.api_factory.get_cvenv_id(function_promoted_cv, function_lce) return target_sat.api.ActivationKey( - content_view=function_promoted_cv, - environment=function_lce, + content_view_environment_ids=[cvenv_id], organization=function_org, ).create() @pytest.fixture(scope='module') def module_ak_with_cv_repo(module_lce, module_org, module_cv_repo, module_target_sat): + cvenv_id = module_target_sat.api_factory.get_cvenv_id(module_cv_repo, module_lce) return module_target_sat.api.ActivationKey( - content_view=module_cv_repo, - environment=module_lce, + content_view_environment_ids=[cvenv_id], organization=module_org, ).create() @@ -79,8 +85,11 @@ def module_ak_with_synced_repo(module_sca_manifest_org, module_target_sat): @pytest.fixture(scope='module') def module_default_ak(module_target_sat, module_org): + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_org.default_content_view, + module_org.library, + ) return module_target_sat.api.ActivationKey( organization=module_org, - content_view=module_org.default_content_view.id, - environment=module_org.library.id, + content_view_environment_ids=[cvenv_id], ).create() diff --git a/pytest_fixtures/component/contentview.py b/pytest_fixtures/component/contentview.py index 2387c453af0..d04fba7e622 100644 --- a/pytest_fixtures/component/contentview.py +++ b/pytest_fixtures/component/contentview.py @@ -61,9 +61,9 @@ def module_ak_cv_lce(module_org, module_lce, module_published_cv, module_target_ content_view_version = module_published_cv.version[0] content_view_version.promote(data={'environment_ids': module_lce.id}) module_published_cv = module_published_cv.read() + cvenv_id = module_target_sat.api_factory.get_cvenv_id(module_published_cv, module_lce) return module_target_sat.api.ActivationKey( - content_view=module_published_cv, - environment=module_lce, + content_view_environment_ids=[cvenv_id], organization=module_org, ).create() diff --git a/pytest_fixtures/component/leapp_client.py b/pytest_fixtures/component/leapp_client.py index 2d5f2dc29d6..cb2d3d89452 100644 --- a/pytest_fixtures/component/leapp_client.py +++ b/pytest_fixtures/component/leapp_client.py @@ -102,9 +102,9 @@ def function_leapp_ak( module_leapp_lce, module_sca_manifest_org, ): + cvenv_id = module_target_sat.api_factory.get_cvenv_id(function_leapp_cv, module_leapp_lce) return module_target_sat.api.ActivationKey( - content_view=function_leapp_cv, - environment=module_leapp_lce, + content_view_environment_ids=[cvenv_id], organization=module_sca_manifest_org, ).create() diff --git a/pytest_fixtures/component/provision_capsule_pxe.py b/pytest_fixtures/component/provision_capsule_pxe.py index b18bc1fce3f..d83b223d15a 100644 --- a/pytest_fixtures/component/provision_capsule_pxe.py +++ b/pytest_fixtures/component/provision_capsule_pxe.py @@ -127,9 +127,10 @@ def capsule_provisioning_hostgroup( architecture=default_architecture, domain=capsule_provisioning_sat.domain, content_source=capsule.id, - content_view=capsule_provisioning_rhel_content.cv, + content_view_environment_id=capsule_provisioning_sat.sat.api_factory.get_cvenv_id( + capsule_provisioning_rhel_content.cv, module_lce_library + ), kickstart_repository=capsule_provisioning_rhel_content.ksrepo, - lifecycle_environment=module_lce_library, root_pass=settings.provisioning.host_root_password, operatingsystem=capsule_provisioning_rhel_content.os, ptable=default_partitiontable, @@ -257,10 +258,10 @@ def capsule_provisioning_rhel_content( content_view = sat.api.ContentView( organization=module_sca_manifest_org, name=content_view.name ).search()[0] + cvenv_id = sat.api_factory.get_cvenv_id(content_view, module_lce_library) ak = sat.api.ActivationKey( organization=module_sca_manifest_org, - content_view=content_view, - environment=module_lce_library, + content_view_environment_ids=[cvenv_id], ).create() # Ensure client repo is enabled in the activation key diff --git a/pytest_fixtures/component/provision_ocpv.py b/pytest_fixtures/component/provision_ocpv.py index bcf7f982bb6..ab20363fb56 100644 --- a/pytest_fixtures/component/provision_ocpv.py +++ b/pytest_fixtures/component/provision_ocpv.py @@ -100,10 +100,11 @@ def module_ocpv_hostgroup( location=[module_location], architecture=default_architecture, content_source=module_provisioning_capsule.id, - content_view=module_org.default_content_view, + content_view_environment_id=module_ocpv_sat.api_factory.get_cvenv_id( + module_org.default_content_view, module_lce_library + ), compute_resource=module_ocpv_cr, domain=domain, - lifecycle_environment=module_lce_library, root_pass=settings.provisioning.host_root_password, operatingsystem=module_ocpv_image.os, ).create() diff --git a/pytest_fixtures/component/provision_pxe.py b/pytest_fixtures/component/provision_pxe.py index b8fcdfdd55c..16acdc72f50 100644 --- a/pytest_fixtures/component/provision_pxe.py +++ b/pytest_fixtures/component/provision_pxe.py @@ -137,10 +137,10 @@ def module_provisioning_rhel_content( ) assert task_status[0].result == 'success' # create new activation key for provisioning + cvenv_id = sat.api_factory.get_cvenv_id(content_view, module_lce_library) ak = sat.api.ActivationKey( organization=module_sca_manifest_org, - content_view=content_view, - environment=module_lce_library, + content_view_environment_ids=[cvenv_id], ).create() # enable all custom repos in the activation key product_content = ak.product_content(data={'content_access_mode_all': '1'})['results'] @@ -312,9 +312,10 @@ def provisioning_hostgroup( architecture=default_architecture, domain=module_provisioning_sat.domain, content_source=module_provisioning_capsule.id, - content_view=module_provisioning_rhel_content.cv, + content_view_environment_id=module_provisioning_sat.sat.api_factory.get_cvenv_id( + module_provisioning_rhel_content.cv, module_lce_library + ), kickstart_repository=module_provisioning_rhel_content.ksrepo, - lifecycle_environment=module_lce_library, root_pass=settings.provisioning.host_root_password, operatingsystem=module_provisioning_rhel_content.os, ptable=default_partitiontable, diff --git a/pytest_fixtures/component/provision_vmware.py b/pytest_fixtures/component/provision_vmware.py index e8c4439f6f6..d906de0724e 100644 --- a/pytest_fixtures/component/provision_vmware.py +++ b/pytest_fixtures/component/provision_vmware.py @@ -62,10 +62,11 @@ def module_vmware_hostgroup( architecture=default_architecture, domain=module_provisioning_sat.domain, content_source=module_provisioning_capsule.id, - content_view=module_provisioning_rhel_content.cv, + content_view_environment_id=module_provisioning_sat.sat.api_factory.get_cvenv_id( + module_provisioning_rhel_content.cv, module_lce_library + ), compute_resource=module_vmware_cr, kickstart_repository=module_provisioning_rhel_content.ksrepo, - lifecycle_environment=module_lce_library, root_pass=settings.provisioning.host_root_password, operatingsystem=module_provisioning_rhel_content.os, ptable=default_partitiontable, diff --git a/pytest_fixtures/component/repository.py b/pytest_fixtures/component/repository.py index 02ee130c236..9a367b74ccd 100644 --- a/pytest_fixtures/component/repository.py +++ b/pytest_fixtures/component/repository.py @@ -88,8 +88,9 @@ def setup_content(module_target_sat, module_org): cv.publish() cvv = cv.read().version[0].read() cvv.promote(data={'environment_ids': lce.id, 'force': False}) + cvenv_id = module_target_sat.api_factory.get_cvenv_id(cv, lce) ak = module_target_sat.api.ActivationKey( - content_view=cv, max_hosts=100, organization=org, environment=lce + content_view_environment_ids=[cvenv_id], max_hosts=100, organization=org ).create() return ak, org, custom_repo diff --git a/pytest_fixtures/component/rh_cloud.py b/pytest_fixtures/component/rh_cloud.py index 03bf80ccdc0..82019d52931 100644 --- a/pytest_fixtures/component/rh_cloud.py +++ b/pytest_fixtures/component/rh_cloud.py @@ -67,12 +67,13 @@ def rhcloud_manifest_org(module_target_sat_insights, module_sca_manifest): @pytest.fixture(scope='module') def rhcloud_activation_key(module_target_sat_insights, rhcloud_manifest_org): """A module-level fixture to create an Activation key in rhcloud_manifest_org""" + cvenv_id = module_target_sat_insights.api_factory.get_cvenv_id( + rhcloud_manifest_org.default_content_view, + module_target_sat_insights.api.LifecycleEnvironment(id=rhcloud_manifest_org.library.id), + ) return module_target_sat_insights.api.ActivationKey( - content_view=rhcloud_manifest_org.default_content_view, + content_view_environment_ids=[cvenv_id], organization=rhcloud_manifest_org, - environment=module_target_sat_insights.api.LifecycleEnvironment( - id=rhcloud_manifest_org.library.id - ), service_level='Self-Support', purpose_usage='test-usage', purpose_role='test-role', @@ -82,12 +83,13 @@ def rhcloud_activation_key(module_target_sat_insights, rhcloud_manifest_org): @pytest.fixture(scope='module') def activation_key_with_els_manifest_org(module_target_sat_insights, module_els_manifest_org): """A module-level fixture to create an Activation key in module_els_manifest_org""" + cvenv_id = module_target_sat_insights.api_factory.get_cvenv_id( + module_els_manifest_org.default_content_view, + module_target_sat_insights.api.LifecycleEnvironment(id=module_els_manifest_org.library.id), + ) return module_target_sat_insights.api.ActivationKey( - content_view=module_els_manifest_org.default_content_view, + content_view_environment_ids=[cvenv_id], organization=module_els_manifest_org, - environment=module_target_sat_insights.api.LifecycleEnvironment( - id=module_els_manifest_org.library.id - ), ).create() diff --git a/pytest_fixtures/core/contenthosts.py b/pytest_fixtures/core/contenthosts.py index f8096f2132c..26f4fbcdc0b 100644 --- a/pytest_fixtures/core/contenthosts.py +++ b/pytest_fixtures/core/contenthosts.py @@ -212,11 +212,14 @@ def registered_hosts(request, target_sat, module_org, module_ak_with_cv): def katello_host_tools_host(target_sat, module_org, rhel_contenthost): """Register content host to Satellite and install katello-host-tools on the host.""" repo = settings.repos['SATCLIENT_REPO'][f'RHEL{rhel_contenthost.os_version.major}'] + cvenv_id = target_sat.api_factory.get_cvenv_id( + module_org.default_content_view, + target_sat.api.LifecycleEnvironment(id=module_org.library.id), + ) ak = target_sat.api.ActivationKey( - content_view=module_org.default_content_view, + content_view_environment_ids=[cvenv_id], max_hosts=100, organization=module_org, - environment=target_sat.api.LifecycleEnvironment(id=module_org.library.id), ).create() rhel_contenthost.register(module_org, None, ak.name, target_sat, repo_data=f'repo={repo}') rhel_contenthost.install_katello_host_tools() diff --git a/robottelo/host_helpers/api_factory.py b/robottelo/host_helpers/api_factory.py index f1a382b7e03..af32e8d8713 100644 --- a/robottelo/host_helpers/api_factory.py +++ b/robottelo/host_helpers/api_factory.py @@ -30,6 +30,19 @@ def __init__(self, satellite): self._satellite = satellite self.__dict__.update(initiate_repo_helpers(self._satellite)) + def get_cvenv_id(self, content_view, lifecycle_environment): + """Look up a ContentViewEnvironment ID from a CV + LCE pair.""" + cv_id = content_view.id if hasattr(content_view, 'id') else content_view + lce_id = ( + lifecycle_environment.id + if hasattr(lifecycle_environment, 'id') + else lifecycle_environment + ) + result = self._satellite.api.ContentViewEnvironment().list_content_view_environments( + params={'content_view_id': cv_id, 'lifecycle_environment_id': lce_id} + ) + return result['results'][0]['id'] + def make_http_proxy(self, org, http_proxy_type, use_ip=False): """ Creates HTTP proxy. @@ -649,21 +662,20 @@ def register_host_and_needed_setup( # updated entities after promoting entities = {k: v.read() for k, v in entities.items()} - updates = [] - if ( # assign env to ak if not present - entities['ActivationKey'].environment is None - or entities['ActivationKey'].environment.id != entities['LifecycleEnvironment'].id - ): - entities['ActivationKey'].environment = entities['LifecycleEnvironment'] - updates.append('environment') - if ( # assign cv to ak if not present - entities['ActivationKey'].content_view is None - or entities['ActivationKey'].content_view.id != entities['ContentView'].id + ak = entities['ActivationKey'] + ak_cv = ak.content_view + ak_lce = ak.environment + desired_cv = entities['ContentView'] + desired_lce = entities['LifecycleEnvironment'] + if ( + ak_cv is None + or ak_lce is None + or ak_cv.id != desired_cv.id + or ak_lce.id != desired_lce.id ): - entities['ActivationKey'].content_view = entities['ContentView'] - updates.append('content_view') - if updates: - entities['ActivationKey'].update(['content_view', 'environment']) # both needed anyway + cvenv_id = self.get_cvenv_id(desired_cv, desired_lce) + ak.content_view_environment_ids = [cvenv_id] + ak.update(['content_view_environment_ids']) entities = {k: v.read() for k, v in entities.items()} if enable_repos: diff --git a/tests/foreman/api/test_activationkey.py b/tests/foreman/api/test_activationkey.py index cbe087e4296..1d6785f0aad 100644 --- a/tests/foreman/api/test_activationkey.py +++ b/tests/foreman/api/test_activationkey.py @@ -427,8 +427,9 @@ def test_positive_fetch_product_content( cvv = cv.version[0] cvv.promote(data={'environment_ids': module_lce.id}) + cvenv_id = module_target_sat.api_factory.get_cvenv_id(cv, module_lce) ak = module_target_sat.api.ActivationKey( - content_view=cv.id, organization=module_org.id, environment=module_lce.id + content_view_environment_ids=[cvenv_id], organization=module_org.id ).create() ak_content = ak.product_content()['results'] assert {custom_repo.product.id, rh_repo.product.id} == { @@ -484,11 +485,13 @@ def test_positive_search_by_environment(target_sat): cv.version[0].promote(data={'environment_ids': lce_dev.id}) cv.version[0].promote(data={'environment_ids': lce_qa.id}) + cvenv_dev_id = target_sat.api_factory.get_cvenv_id(cv, lce_dev) + cvenv_qa_id = target_sat.api_factory.get_cvenv_id(cv, lce_qa) ak_dev = target_sat.api.ActivationKey( - organization=org, environment=lce_dev, content_view=cv + organization=org, content_view_environment_ids=[cvenv_dev_id] ).create() ak_qa = target_sat.api.ActivationKey( - organization=org, environment=lce_qa, content_view=cv + organization=org, content_view_environment_ids=[cvenv_qa_id] ).create() for lce, expected_ak in [(lce_dev, ak_dev), (lce_qa, ak_qa)]: diff --git a/tests/foreman/api/test_contentview.py b/tests/foreman/api/test_contentview.py index 17f7b249ca4..32f40f2b53e 100644 --- a/tests/foreman/api/test_contentview.py +++ b/tests/foreman/api/test_contentview.py @@ -130,10 +130,10 @@ def test_positive_subscribe_host( # Check that no host associated to just created content view assert class_cv.content_host_count == 0 assert len(class_promoted_cv.version) == 1 + cvenv_id = module_target_sat.api_factory.get_cvenv_id(class_cv, module_lce) host = module_target_sat.api.Host( content_facet_attributes={ - 'content_view_id': class_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [cvenv_id], }, organization=module_org.id, ).create() @@ -688,17 +688,16 @@ def test_positive_rolling_with_activation_keys(self, module_org, module_ak, targ rolling_cv.update(['environment']) library = module_org.library.read() # Create new activation key providing rolling CV + cvenv_id = target_sat.api_factory.get_cvenv_id(rolling_cv, library) ak = target_sat.api.ActivationKey( organization=module_org, - content_view=rolling_cv, - environment=library, + content_view_environment_ids=[cvenv_id], ).create() assert ak.content_view.read() == rolling_cv assert ak.environment.read() == library # Update an existing activation key with CVE - module_ak.content_view = rolling_cv - module_ak.environment = library - module_ak.update(['content_view', 'environment']) + module_ak.content_view_environment_ids = [cvenv_id] + module_ak.update(['content_view_environment_ids']) module_ak = module_ak.read() assert module_ak.content_view.read() == rolling_cv assert module_ak.environment.read() == library @@ -708,8 +707,8 @@ def test_positive_rolling_with_activation_keys(self, module_org, module_ak, targ with pytest.raises(HTTPError): rolling_cv.delete() ak.delete() - module_ak.content_view = module_ak.environment = None - module_ak.update(['content_view', 'environment']) + module_ak.content_view_environment_ids = [] + module_ak.update(['content_view_environment_ids']) rolling_cv.delete_from_environment(library.id) rolling_cv.delete() with pytest.raises(HTTPError): @@ -1171,10 +1170,11 @@ def test_positive_host_with_rolling_content_source( rolling_cv.update(['repository']) rolling_cv = rolling_cv.read() # create the AK with the rolling cv + lce_library = rolling_cv.environment[0].read() # Library + cvenv_id = target_sat.api_factory.get_cvenv_id(rolling_cv, lce_library) ak = target_sat.api.ActivationKey( organization=org, - content_view=rolling_cv, - environment=rolling_cv.environment[0].read(), # Library + content_view_environment_ids=[cvenv_id], ).create() # Hammer CLI: override the repos to enabled for AK override = target_sat.cli_factory.override_repos_for_activation_key( diff --git a/tests/foreman/api/test_docker.py b/tests/foreman/api/test_docker.py index f7c22f39ebe..07c9d16ba56 100644 --- a/tests/foreman/api/test_docker.py +++ b/tests/foreman/api/test_docker.py @@ -512,8 +512,9 @@ def test_positive_add_docker_repo_cv( key """ content_view = content_view_publish_promote + cvenv_id = module_target_sat.api_factory.get_cvenv_id(content_view, module_lce) ak = module_target_sat.api.ActivationKey( - content_view=content_view, environment=module_lce, organization=module_org + content_view_environment_ids=[cvenv_id], organization=module_org ).create() assert ak.content_view.id == content_view.id assert ak.content_view.read().repository[0].id == repo.id @@ -531,12 +532,13 @@ def test_positive_remove_docker_repo_cv( """ content_view = content_view_publish_promote + cvenv_id = module_target_sat.api_factory.get_cvenv_id(content_view, module_lce) ak = module_target_sat.api.ActivationKey( - content_view=content_view, environment=module_lce, organization=module_org + content_view_environment_ids=[cvenv_id], organization=module_org ).create() assert ak.content_view.id == content_view.id - ak.content_view_environments = None - assert ak.update(['content_view_environments']).content_view is None + ak.content_view_environment_ids = [] + assert ak.update(['content_view_environment_ids']).content_view is None def test_positive_add_docker_repo_ccv( self, content_view_version, module_lce, module_org, module_target_sat @@ -563,8 +565,9 @@ def test_positive_add_docker_repo_ccv( comp_cvv = comp_content_view.read().version[0].read() comp_cvv.promote(data={'environment_ids': module_lce.id, 'force': False}) + cvenv_id = module_target_sat.api_factory.get_cvenv_id(comp_content_view, module_lce) ak = module_target_sat.api.ActivationKey( - content_view=comp_content_view, environment=module_lce, organization=module_org + content_view_environment_ids=[cvenv_id], organization=module_org ).create() assert ak.content_view.id == comp_content_view.id @@ -594,12 +597,13 @@ def test_positive_remove_docker_repo_ccv( comp_cvv = comp_content_view.read().version[0].read() comp_cvv.promote(data={'environment_ids': module_lce.id, 'force': False}) + cvenv_id = module_target_sat.api_factory.get_cvenv_id(comp_content_view, module_lce) ak = module_target_sat.api.ActivationKey( - content_view=comp_content_view, environment=module_lce, organization=module_org + content_view_environment_ids=[cvenv_id], organization=module_org ).create() assert ak.content_view.id == comp_content_view.id - ak.content_view_environments = None - assert ak.update(['content_view_environments']).content_view is None + ak.content_view_environment_ids = [] + assert ak.update(['content_view_environment_ids']).content_view is None class TestPodman: diff --git a/tests/foreman/api/test_host.py b/tests/foreman/api/test_host.py index 3eb9e8f7757..7ea61c474a2 100644 --- a/tests/foreman/api/test_host.py +++ b/tests/foreman/api/test_host.py @@ -220,8 +220,9 @@ def test_positive_create_and_update_with_hostgroup( location=module_location, organization=module_org, content_facet_attributes={ - 'content_view_id': module_published_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id(module_published_cv, module_lce) + ], }, ).create() assert host.hostgroup.read().name == hostgroup.name @@ -230,8 +231,9 @@ def test_positive_create_and_update_with_hostgroup( ).create() host.hostgroup = new_hostgroup host.content_facet_attributes = { - 'content_view_id': module_published_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id(module_published_cv, module_lce) + ], } host = host.update(['hostgroup', 'content_facet_attributes']) assert host.hostgroup.read().name == new_hostgroup.name @@ -250,9 +252,11 @@ def test_positive_create_inherit_lce_cv( :BZ: 1391656 """ + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) hostgroup = module_target_sat.api.HostGroup( - content_view=module_default_org_view, - lifecycle_environment=module_lce_library, + content_view_environment_id=cvenv_id, organization=[module_org], ).create() host = module_target_sat.api.Host(hostgroup=hostgroup, organization=module_org).create() @@ -728,16 +732,20 @@ def test_positive_create_and_update_with_content_view( organization=module_org, location=module_location, content_facet_attributes={ - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) + ], }, ).create() assert host.content_facet_attributes['content_view']['id'] == module_default_org_view.id assert host.content_facet_attributes['lifecycle_environment']['id'] == module_lce_library.id host.content_facet_attributes = { - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id(module_default_org_view, module_lce_library) + ], } host = host.update(['content_facet_attributes']) assert host.content_facet_attributes['content_view']['id'] == module_default_org_view.id @@ -1063,8 +1071,9 @@ def test_positive_read_content_source_id( location=module_location, content_facet_attributes={ 'content_source_id': proxy.id, - 'content_view_id': module_published_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [ + target_sat.api_factory.get_cvenv_id(module_published_cv, module_lce) + ], }, ).create() content_facet_attributes = host.content_facet_attributes @@ -1095,8 +1104,9 @@ def test_positive_update_content_source_id( organization=module_org, location=module_location, content_facet_attributes={ - 'content_view_id': module_published_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [ + target_sat.api_factory.get_cvenv_id(module_published_cv, module_lce) + ], }, ).create() host.content_facet_attributes['content_source_id'] = proxy.id @@ -1154,8 +1164,9 @@ def test_positive_read_enc_information( environment=module_env_search, puppetclass=module_puppet_classes, content_facet_attributes={ - 'content_view_id': cv.id, - 'lifecycle_environment_id': lce.id, + 'content_view_environment_ids': [ + session_puppet_enabled_sat.api_factory.get_cvenv_id(cv, lce) + ], }, host_parameters_attributes=host_parameters_attributes, puppet_proxy=session_puppet_enabled_proxy, diff --git a/tests/foreman/api/test_hostgroup.py b/tests/foreman/api/test_hostgroup.py index 70017b5fb77..d64cf7d3cd3 100644 --- a/tests/foreman/api/test_hostgroup.py +++ b/tests/foreman/api/test_hostgroup.py @@ -143,8 +143,9 @@ def test_inherit_puppetclass(self, session_puppet_enabled_sat): location=location, organization=org, content_facet_attributes={ - 'content_view_id': content_view.id, - 'lifecycle_environment_id': lc_env.id, + 'content_view_environment_ids': [ + session_puppet_enabled_sat.api_factory.get_cvenv_id(content_view, lc_env) + ], }, name=gen_string('alpha'), ).create(False) @@ -174,8 +175,9 @@ def test_rebuild_config(self, module_org, module_location, hostgroup, module_tar organization=module_org, managed=True, content_facet_attributes={ - 'content_view_id': content_view.id, - 'lifecycle_environment_id': lce.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id(content_view, lce) + ], }, ).create() # TODO: use host that can also rebuild the SSH_Nic, SSH_Host, and Content_Host_Status @@ -271,13 +273,13 @@ def test_positive_create_with_properties( organization=module_puppet_org ).create() content_view.version[0].promote(data={'environment_ids': lce.id, 'force': False}) + cvenv_id = session_puppet_enabled_sat.api_factory.get_cvenv_id(content_view, lce) hostgroup = session_puppet_enabled_sat.api.HostGroup( architecture=arch, content_source=proxy, - content_view=content_view, + content_view_environment_id=cvenv_id, domain=domain, environment=env, - lifecycle_environment=lce, location=[module_puppet_loc], medium=media, operatingsystem=os, @@ -330,12 +332,12 @@ def test_positive_create_with_properties( operatingsystem=[os], location=[new_loc], organization=[new_org] ).create() new_cv.version[0].promote(data={'environment_ids': new_lce.id, 'force': False}) + new_cvenv_id = session_puppet_enabled_sat.api_factory.get_cvenv_id(new_cv, new_lce) # update itself hostgroup.organization = [new_org] hostgroup.location = [new_loc] - hostgroup.lifecycle_environment = new_lce - hostgroup.content_view = new_cv + hostgroup.content_view_environment_id = new_cvenv_id hostgroup.domain = new_domain hostgroup.architecture = new_arch hostgroup.operatingsystem = new_os @@ -353,8 +355,7 @@ def test_positive_create_with_properties( 'ptable', 'subnet', 'domain', - 'content_view', - 'lifecycle_environment', + 'content_view_environment_id', 'location', 'organization', 'medium', diff --git a/tests/foreman/api/test_provisioning.py b/tests/foreman/api/test_provisioning.py index 9f375f2006d..b877fd1d12a 100644 --- a/tests/foreman/api/test_provisioning.py +++ b/tests/foreman/api/test_provisioning.py @@ -766,13 +766,15 @@ def test_capsule_pxe_provisioning( host_mac_addr = provisioning_host.provisioning_nic_mac_addr sat = capsule_provisioning_sat.sat cap = module_capsule_configured + cvenv_id = sat.api_factory.get_cvenv_id( + capsule_provisioning_rhel_content.cv, module_lce_library + ) host = sat.api.Host( hostgroup=capsule_provisioning_hostgroup, organization=module_sca_manifest_org, location=module_location, content_facet_attributes={ - 'content_view_id': capsule_provisioning_rhel_content.cv.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, name=gen_string('alpha').lower(), mac=host_mac_addr, diff --git a/tests/foreman/api/test_provisioning_puppet.py b/tests/foreman/api/test_provisioning_puppet.py index 0a396b978a6..4846d244aed 100644 --- a/tests/foreman/api/test_provisioning_puppet.py +++ b/tests/foreman/api/test_provisioning_puppet.py @@ -138,13 +138,13 @@ def test_host_provisioning_with_external_puppetserver( puppet_env = 'production' host_mac_addr = provisioning_host.provisioning_nic_mac_addr sat = module_provisioning_sat.sat + cvenv_id = sat.api_factory.get_cvenv_id(module_provisioning_rhel_content.cv, module_lce_library) host = sat.api.Host( hostgroup=provisioning_hostgroup, organization=module_sca_manifest_org, location=module_location, content_facet_attributes={ - 'content_view_id': module_provisioning_rhel_content.cv.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, name=gen_string('alpha').lower(), mac=host_mac_addr, diff --git a/tests/foreman/api/test_provisioningtemplate.py b/tests/foreman/api/test_provisioningtemplate.py index c8a49969ca8..5689c353311 100644 --- a/tests/foreman/api/test_provisioningtemplate.py +++ b/tests/foreman/api/test_provisioningtemplate.py @@ -264,6 +264,9 @@ def test_positive_template_check_ipxe( """ macaddress = gen_mac(multicast=False) capsule = module_target_sat.nailgun_smart_proxy + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) host = module_target_sat.api.Host( organization=module_sca_manifest_org, location=module_location, @@ -276,8 +279,7 @@ def test_positive_template_check_ipxe( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': capsule.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, ).create() request.addfinalizer(lambda: host.delete()) @@ -320,6 +322,9 @@ def test_positive_template_check_vlan_parameter( identifier = gen_string('alphanumeric') tag = gen_string('numeric', length=4) # create a host with vlan enabled interface + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) host = module_target_sat.api.Host( organization=module_sca_manifest_org, location=module_location, @@ -329,8 +334,7 @@ def test_positive_template_check_vlan_parameter( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': capsule.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, interfaces_attributes=[ { @@ -509,6 +513,9 @@ def test_positive_template_check_aap_snippet( {'name': 'ansible_job_template_id', 'value': template_id, 'parameter_type': 'integer'}, {'name': 'ansible_extra_vars', 'value': extra_vars_dict, 'parameter_type': 'string'}, ] + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) host = module_target_sat.api.Host( organization=module_sca_manifest_org, location=module_location, @@ -520,8 +527,7 @@ def test_positive_template_check_aap_snippet( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': module_target_sat.nailgun_smart_proxy.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, host_parameters_attributes=host_params, ).create() @@ -567,6 +573,9 @@ def test_positive_template_check_rex_snippet( macaddress = gen_mac(multicast=False) rex_user = gen_string('alpha') ssh_key = gen_string('alphanumeric') + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) host = module_target_sat.api.Host( organization=module_sca_manifest_org, location=module_location, @@ -579,8 +588,7 @@ def test_positive_template_check_rex_snippet( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': module_provisioning_capsule.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, host_parameters_attributes=[ { @@ -707,6 +715,9 @@ def test_positive_template_check_fips_enabled( :parametrized: yes """ host_params = [{'name': 'fips_enabled', 'value': 'true', 'parameter_type': 'boolean'}] + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) host = module_target_sat.api.Host( organization=module_sca_manifest_org, location=module_location, @@ -718,8 +729,7 @@ def test_positive_template_check_fips_enabled( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': module_target_sat.nailgun_smart_proxy.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, host_parameters_attributes=host_params, ).create() diff --git a/tests/foreman/api/test_subscription.py b/tests/foreman/api/test_subscription.py index bb19b0bc85c..1f512ca1e0f 100644 --- a/tests/foreman/api/test_subscription.py +++ b/tests/foreman/api/test_subscription.py @@ -59,13 +59,14 @@ def custom_repo(rh_repo, module_sca_manifest_org, module_target_sat): @pytest.fixture(scope='module') def module_ak(module_sca_manifest_org, rh_repo, custom_repo, module_target_sat): """rh_repo and custom_repo are included here to ensure their execution before the AK""" + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_sca_manifest_org.default_content_view, + module_sca_manifest_org.library, + ) return module_target_sat.api.ActivationKey( - content_view=module_sca_manifest_org.default_content_view, + content_view_environment_ids=[cvenv_id], max_hosts=100, organization=module_sca_manifest_org, - environment=module_target_sat.api.LifecycleEnvironment( - id=module_sca_manifest_org.library.id - ), ).create() @@ -228,9 +229,9 @@ def test_sca_end_to_end( content_view.publish() assert len(content_view.repository) == 2 host = rhel_contenthost.nailgun_host + cvenv_id = target_sat.api_factory.get_cvenv_id(content_view, module_ak.environment) host.content_facet_attributes = { - 'content_view_id': content_view.id, - 'lifecycle_environment_id': module_ak.environment.id, + 'content_view_environment_ids': [cvenv_id], } host.update(['content_facet_attributes']) rhel_contenthost.run(r'subscription-manager repos --enable \*') @@ -270,11 +271,14 @@ def test_positive_expired_SCA_cert_handling(module_sca_manifest_org, rhel_conten :CaseImportance: High """ + cvenv_id = target_sat.api_factory.get_cvenv_id( + module_sca_manifest_org.default_content_view, + module_sca_manifest_org.library, + ) ak = target_sat.api.ActivationKey( - content_view=module_sca_manifest_org.default_content_view, + content_view_environment_ids=[cvenv_id], max_hosts=100, organization=module_sca_manifest_org, - environment=target_sat.api.LifecycleEnvironment(id=module_sca_manifest_org.library.id), ).create() # registering the content host with no content enabled/synced in the org # should create a client SCA cert with no content diff --git a/tests/foreman/destructive/test_infoblox.py b/tests/foreman/destructive/test_infoblox.py index e9f583cec79..0ed265e776a 100644 --- a/tests/foreman/destructive/test_infoblox.py +++ b/tests/foreman/destructive/test_infoblox.py @@ -215,8 +215,11 @@ def test_infoblox_end_to_end( ptable=default_partitiontable, content_facet_attributes={ 'content_source_id': module_provisioning_capsule.id, - 'content_view_id': module_default_org_view.id, - 'lifecycle_environment_id': module_lce_library.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id( + module_default_org_view, module_lce_library + ) + ], }, ).create() # check if A Record is created for the host IP on Infoblox diff --git a/tests/foreman/endtoend/test_api_endtoend.py b/tests/foreman/endtoend/test_api_endtoend.py index 0799bf92fe4..8e6d4484e31 100644 --- a/tests/foreman/endtoend/test_api_endtoend.py +++ b/tests/foreman/endtoend/test_api_endtoend.py @@ -1178,8 +1178,9 @@ def test_positive_end_to_end( # content view and last lifecycle where it exists content_host = target_sat.api.Host( content_facet_attributes={ - 'content_view_id': content_view.id, - 'lifecycle_environment_id': le1.id, + 'content_view_environment_ids': [ + target_sat.api_factory.get_cvenv_id(content_view, le1) + ], }, organization=org, ).create() diff --git a/tests/foreman/ui/test_activationkey.py b/tests/foreman/ui/test_activationkey.py index 92703c563cc..3415d2f9b24 100644 --- a/tests/foreman/ui/test_activationkey.py +++ b/tests/foreman/ui/test_activationkey.py @@ -631,7 +631,10 @@ def test_positive_fetch_product_content(target_sat, function_sca_manifest_org, s cv.publish() cvv = cv.read().version[0].read() cvv.promote(data={'environment_ids': lce.id, 'force': True}) - ak = target_sat.api.ActivationKey(content_view=cv, organization=org, environment=lce).create() + cvenv_id = target_sat.api_factory.get_cvenv_id(cv, lce) + ak = target_sat.api.ActivationKey( + content_view_environment_ids=[cvenv_id], organization=org + ).create() with session: session.organization.select(org.name) ak = session.activationkey.read(ak.name, widget_names='repository_sets') diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index ea306148d95..87446b11dbb 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -1084,9 +1084,9 @@ def test_positive_filter_by_environment( host = ( target_sat.api.Host().search(query={'search': f'name={clients[0].hostname}'})[0].read() ) + cvenv_id = target_sat.api_factory.get_cvenv_id(content_view, new_lce) host.content_facet_attributes = { - 'content_view_id': content_view.id, - 'lifecycle_environment_id': new_lce.id, + 'content_view_environment_ids': [cvenv_id], } host.update(['content_facet_attributes']) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index c857f9b2344..26a9e00c24b 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -890,10 +890,12 @@ def test_negative_remove_parameter_non_admin_user( default_organization=module_org, default_location=smart_proxy_location, ).create() + cvenv_id = module_target_sat.api_factory.get_cvenv_id( + module_org.default_content_view, module_org.library + ) host = module_target_sat.api.Host( content_facet_attributes={ - 'content_view_id': module_org.default_content_view.id, - 'lifecycle_environment_id': module_org.library.id, + 'content_view_environment_ids': [cvenv_id], }, location=smart_proxy_location, organization=module_org, @@ -1961,6 +1963,9 @@ def test_positive_set_multi_line_and_with_spaces_parameter_value( 'password-auth\r\n' 'account include password-auth' ) + cvenv_id = session_puppet_enabled_sat.api_factory.get_cvenv_id( + module_puppet_published_cv, module_puppet_lce_library + ) host = session_puppet_enabled_sat.api.Host( organization=host_template.organization, architecture=host_template.architecture, @@ -1972,8 +1977,7 @@ def test_positive_set_multi_line_and_with_spaces_parameter_value( ptable=host_template.ptable, root_pass=host_template.root_pass, content_facet_attributes={ - 'content_view_id': module_puppet_published_cv.id, - 'lifecycle_environment_id': module_puppet_lce_library.id, + 'content_view_environment_ids': [cvenv_id], }, ).create() with session_puppet_enabled_sat.ui_session() as session: @@ -2103,13 +2107,13 @@ def test_all_hosts_bulk_cve_reassign( module_cv = target_sat.api.ContentView(id=module_cv.id).read() module_cv = cv_publish_promote(target_sat, module_org, module_cv, module_lce)['content-view'] module_cv = cv_publish_promote(target_sat, module_org, module_cv, lce2)['content-view'] + cvenv_id = target_sat.api_factory.get_cvenv_id(module_cv, module_lce) for _ in range(3): target_sat.api.Host( organization=module_org, location=module_location, content_facet_attributes={ - 'content_view_id': module_cv.id, - 'lifecycle_environment_id': module_lce.id, + 'content_view_environment_ids': [cvenv_id], }, ).create() with target_sat.ui_session() as session: diff --git a/tests/foreman/ui/test_hostcollection.py b/tests/foreman/ui/test_hostcollection.py index 83e6b6bb87a..713e5011306 100644 --- a/tests/foreman/ui/test_hostcollection.py +++ b/tests/foreman/ui/test_hostcollection.py @@ -358,7 +358,9 @@ def test_positive_add_host(session, module_target_sat): host = module_target_sat.api.Host( organization=org, location=loc, - content_facet_attributes={'content_view_id': cv.id, 'lifecycle_environment_id': lce.id}, + content_facet_attributes={ + 'content_view_environment_ids': [module_target_sat.api_factory.get_cvenv_id(cv, lce)], + }, ).create() with session: session.organization.select(org_name=org.name) @@ -665,8 +667,9 @@ def test_negative_hosts_limit(module_target_sat, module_org_with_parameter, smar organization=module_org_with_parameter, location=smart_proxy_location, content_facet_attributes={ - 'content_view_id': cv.id, - 'lifecycle_environment_id': lce.id, + 'content_view_environment_ids': [ + module_target_sat.api_factory.get_cvenv_id(cv, lce) + ], }, ).create() ) diff --git a/tests/foreman/ui/test_oscappolicy.py b/tests/foreman/ui/test_oscappolicy.py index 21c76cb1176..fda44e4edef 100644 --- a/tests/foreman/ui/test_oscappolicy.py +++ b/tests/foreman/ui/test_oscappolicy.py @@ -61,13 +61,13 @@ def test_positive_check_dashboard( content_view.publish() content_view = content_view.read() content_view.version[0].promote(data={'environment_ids': lce.id}) + cvenv_id = module_target_sat.api_factory.get_cvenv_id(content_view, lce) module_target_sat.api.Host( hostgroup=module_host_group, location=default_location, organization=default_org, content_facet_attributes={ - 'content_view_id': content_view.id, - 'lifecycle_environment_id': lce.id, + 'content_view_environment_ids': [cvenv_id], }, ).create() module_target_sat.api.ScapContents( diff --git a/tests/new_upgrades/test_capsulecontent.py b/tests/new_upgrades/test_capsulecontent.py index 7f68db20699..b9021b7dc08 100755 --- a/tests/new_upgrades/test_capsulecontent.py +++ b/tests/new_upgrades/test_capsulecontent.py @@ -218,11 +218,11 @@ def test_post_user_scenario_capsule_sync_yum_repo(capsule_sync_setup): content_view = target_sat.publish_content_view(org.id, repo, 'post_upgrade_sync_content_view') content_view.version[0].promote(data={'environment_ids': lce.id}) content_view_env_id = [env.id for env in content_view.read().environment] + cvenv_id = target_sat.api_factory.get_cvenv_id(content_view, lce) ak = target_sat.api.ActivationKey( name='post_upgrade_sync_ak', organization=org.id, - environment=lce.id, - content_view=content_view, + content_view_environment_ids=[cvenv_id], ).create() ak_env = ak.environment.read() assert ak_env.id in content_view_env_id