Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pheonix Subs] Fix AK creation in ui/test_activationkey.py #17290

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
68 changes: 52 additions & 16 deletions tests/foreman/ui/test_activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import random
from time import sleep

from broker import Broker
from fauxfactory import gen_string
Expand Down Expand Up @@ -171,7 +172,9 @@ def test_positive_search_scoped(session, module_org, target_sat):

@pytest.mark.tier2
@pytest.mark.upgrade
def test_positive_create_with_host_collection(session, module_org, module_target_sat):
def test_positive_create_with_host_collection(
session, module_org, module_target_sat, module_lce, module_promoted_cv
):
"""Create Activation key with Host Collection

:id: 0e4ad2b4-47a7-4087-828f-2b0535a97b69
Expand All @@ -181,7 +184,9 @@ def test_positive_create_with_host_collection(session, module_org, module_target
name = gen_string('alpha')
hc = module_target_sat.api.HostCollection(organization=module_org).create()
with session:
session.activationkey.create({'name': name, 'lce': {constants.ENVIRONMENT: True}})
session.activationkey.create(
{'name': name, 'lce': {module_lce.name: True}, 'content_view': module_promoted_cv.name}
)
assert session.activationkey.search(name)[0]['Name'] == name
session.activationkey.add_host_collection(name, hc.name)
ak = session.activationkey.read(name, widget_names='host_collections')
Expand Down Expand Up @@ -214,7 +219,9 @@ def test_positive_create_with_envs(session, module_org, target_sat):


@pytest.mark.tier2
def test_positive_add_host_collection_non_admin(module_org, test_name, target_sat):
def test_positive_add_host_collection_non_admin(
module_org, test_name, target_sat, module_lce, module_promoted_cv
):
"""Test that host collection can be associated to Activation Keys by
non-admin user.

Expand All @@ -241,7 +248,13 @@ def test_positive_add_host_collection_non_admin(module_org, test_name, target_sa
admin=False, role=roles, password=password, organization=[module_org]
).create()
with target_sat.ui_session(test_name, user=user.login, password=password) as session:
session.activationkey.create({'name': ak_name, 'lce': {constants.ENVIRONMENT: True}})
session.activationkey.create(
{
'name': ak_name,
'lce': {module_lce.name: True},
'content_view': module_promoted_cv.name,
}
)
assert session.activationkey.search(ak_name)[0]['Name'] == ak_name
session.activationkey.add_host_collection(ak_name, hc.name)
ak = session.activationkey.read(ak_name, widget_names='host_collections')
Expand All @@ -250,7 +263,9 @@ def test_positive_add_host_collection_non_admin(module_org, test_name, target_sa

@pytest.mark.tier2
@pytest.mark.upgrade
def test_positive_remove_host_collection_non_admin(module_org, test_name, target_sat):
def test_positive_remove_host_collection_non_admin(
module_org, test_name, target_sat, module_lce, module_promoted_cv
):
"""Test that host collection can be removed from Activation Keys by
non-admin user.

Expand All @@ -275,7 +290,13 @@ def test_positive_remove_host_collection_non_admin(module_org, test_name, target
admin=False, role=roles, password=password, organization=[module_org]
).create()
with target_sat.ui_session(test_name, user=user.login, password=password) as session:
session.activationkey.create({'name': ak_name, 'lce': {constants.ENVIRONMENT: True}})
session.activationkey.create(
{
'name': ak_name,
'lce': {module_lce.name: True},
'content_view': module_promoted_cv.name,
}
)
assert session.activationkey.search(ak_name)[0]['Name'] == ak_name
session.activationkey.add_host_collection(ak_name, hc.name)
ak = session.activationkey.read(ak_name, widget_names='host_collections')
Expand All @@ -301,7 +322,9 @@ def test_positive_delete_with_env(session, module_org, target_sat):
repo_id = target_sat.api_factory.create_sync_custom_repo(module_org.id)
target_sat.api_factory.cv_publish_promote(cv_name, env_name, repo_id, module_org.id)
with session:
session.activationkey.create({'name': name, 'lce': {env_name: True}})
session.activationkey.create(
{'name': name, 'lce': {env_name: True}, 'content_view': cv_name}
)
assert session.activationkey.search(name)[0]['Name'] == name
session.activationkey.delete(name)
assert session.activationkey.search(name)[0]['Name'] != name
Expand Down Expand Up @@ -347,7 +370,9 @@ def test_positive_update_env(session, module_org, target_sat):
repo_id = target_sat.api_factory.create_sync_custom_repo(module_org.id)
target_sat.api_factory.cv_publish_promote(cv_name, env_name, repo_id, module_org.id)
with session:
session.activationkey.create({'name': name, 'lce': {constants.ENVIRONMENT: True}})
session.activationkey.create(
{'name': name, 'lce': {constants.ENVIRONMENT: True}, 'content_view': cv_name}
)
assert session.activationkey.search(name)[0]['Name'] == name
ak = session.activationkey.read(name, widget_names='details')
assert ak['details']['lce'][env_name][constants.ENVIRONMENT]
Expand Down Expand Up @@ -712,7 +737,9 @@ def test_positive_access_non_admin_user(session, test_name, target_sat):


@pytest.mark.tier2
def test_positive_remove_user(session, module_org, test_name, module_target_sat):
def test_positive_remove_user(
session, module_org, test_name, module_target_sat, module_lce, module_promoted_cv
):
"""Delete any user who has previously created an activation key
and check that activation key still exists

Expand All @@ -731,7 +758,11 @@ def test_positive_remove_user(session, module_org, test_name, module_target_sat)
# Create Activation Key using new user credentials
with module_target_sat.ui_session(test_name, user.login, password) as non_admin_session:
non_admin_session.activationkey.create(
{'name': ak_name, 'lce': {constants.ENVIRONMENT: True}}
{
'name': ak_name,
'lce': {module_lce.name: True},
'content_view': module_promoted_cv.name,
}
)
assert non_admin_session.activationkey.search(ak_name)[0]['Name'] == ak_name
# Remove user and check that AK still exists
Expand Down Expand Up @@ -760,6 +791,7 @@ def test_positive_add_docker_repo_cv(session, module_org, module_target_sat):
content_view = module_target_sat.api.ContentView(
composite=False, organization=module_org, repository=[repo]
).create()
sleep(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks the test fails with "errors":["Pending tasks detected in repositories of this content view.
because there is the Metadata generate task running in the background after repo creation.

Could you use wait_for_task instead of sleep(5)? Though the sleep works now it may not be enough in future, IMHO we should better wait for the dependant background task before proceeding with publish.

You can do this

Suggested change
sleep(5)
module_target_sat.wait_for_tasks(
search_query='Actions::Katello::Repository::MetadataGenerate'
f' and resource_id = {repo.id}'
' and resource_type = Katello::Repository',
max_tries=6,
search_rate=10,
)

or better, throw it into a fixture together with the repo creation like here, so you don't duplicate code for the other sleep.

content_view.publish()
cvv = content_view.read().version[0].read()
cvv.promote(data={'environment_ids': lce.id, 'force': False})
Expand Down Expand Up @@ -794,6 +826,7 @@ def test_positive_add_docker_repo_ccv(session, module_org, module_target_sat):
content_view = module_target_sat.api.ContentView(
composite=False, organization=module_org, repository=[repo]
).create()
sleep(5)
content_view.publish()
cvv = content_view.read().version[0].read()
cvv.promote(data={'environment_ids': lce.id, 'force': False})
Expand All @@ -814,7 +847,9 @@ def test_positive_add_docker_repo_ccv(session, module_org, module_target_sat):


@pytest.mark.tier3
def test_positive_add_host(session, module_org, rhel_contenthost, target_sat):
def test_positive_add_host(
session, module_org, rhel_contenthost, target_sat, module_promoted_cv, module_lce
):
"""Test that hosts can be associated to Activation Keys

:id: 886e9ea5-d917-40e0-a3b1-41254c4bf5bf
Expand All @@ -829,9 +864,8 @@ def test_positive_add_host(session, module_org, rhel_contenthost, target_sat):
:parametrized: yes
"""
ak = target_sat.api.ActivationKey(
environment=target_sat.api.LifecycleEnvironment(
name=constants.ENVIRONMENT, organization=module_org
).search()[0],
content_view=module_promoted_cv,
environment=module_lce,
organization=module_org,
).create()
result = rhel_contenthost.register(module_org, None, ak.name, target_sat)
Expand Down Expand Up @@ -884,7 +918,7 @@ def test_positive_delete_with_system(session, rhel_contenthost, target_sat):


@pytest.mark.tier3
def test_negative_usage_limit(session, module_org, target_sat):
def test_negative_usage_limit(session, module_org, target_sat, module_promoted_cv, module_lce):
"""Test that Usage limit actually limits usage

:id: 9fe2d661-66f8-46a4-ae3f-0a9329494bdd
Expand All @@ -901,7 +935,9 @@ def test_negative_usage_limit(session, module_org, target_sat):
name = gen_string('alpha')
hosts_limit = '1'
with session:
session.activationkey.create({'name': name, 'lce': {constants.ENVIRONMENT: True}})
session.activationkey.create(
{'name': name, 'lce': {module_lce.name: True}, 'content_view': module_promoted_cv.name}
)
assert session.activationkey.search(name)[0]['Name'] == name
session.activationkey.update(name, {'details.hosts_limit': hosts_limit})
ak = session.activationkey.read(name, widget_names='details')
Expand Down
Loading