Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@
@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()


@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()

Expand All @@ -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()

Expand All @@ -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()
4 changes: 2 additions & 2 deletions pytest_fixtures/component/contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/leapp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
9 changes: 5 additions & 4 deletions pytest_fixtures/component/provision_capsule_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pytest_fixtures/component/provision_ocpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions pytest_fixtures/component/provision_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions pytest_fixtures/component/provision_vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pytest_fixtures/component/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions pytest_fixtures/component/rh_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()


Expand Down
7 changes: 5 additions & 2 deletions pytest_fixtures/core/contenthosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
40 changes: 26 additions & 14 deletions robottelo/host_helpers/api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremylenz This might be worth considering, but not blocking from my side.


def make_http_proxy(self, org, http_proxy_type, use_ip=False):
"""
Creates HTTP proxy.
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tests/foreman/api/test_activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} == {
Expand Down Expand Up @@ -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)]:
Expand Down
22 changes: 11 additions & 11 deletions tests/foreman/api/test_contentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
Loading