Skip to content

Commit

Permalink
CE-SAT-21617
Browse files Browse the repository at this point in the history
  • Loading branch information
lhellebr committed Jan 31, 2024
1 parent e10e536 commit 68fb262
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 33 deletions.
10 changes: 10 additions & 0 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_
return ak


@pytest.fixture(scope='module')
def module_ak_with_cv_repo(module_lce, module_org, module_cv_repo, module_target_sat):
ak = module_target_sat.api.ActivationKey(
content_view=module_cv_repo,
environment=module_lce,
organization=module_org,
).create()
return ak


@pytest.fixture(scope='module')
def module_ak_with_synced_repo(module_org, module_target_sat):
"""Prepare an activation key with synced repository for host registration"""
Expand Down
6 changes: 5 additions & 1 deletion robottelo/cli/hammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def get_line_indentation_level(line, tab_spaces=4, indentation_spaces=4):
assert get_line_indentation_level(' level 2') == 2
"""
return get_line_indentation_spaces(line, tab_spaces=tab_spaces) // indentation_spaces
spaces = get_line_indentation_spaces(line, tab_spaces=tab_spaces)
return spaces // indentation_spaces + (1 if spaces % indentation_spaces > 0 else 0)


def parse_info(output):
Expand Down Expand Up @@ -249,6 +250,9 @@ def parse_info(output):
# URL: /custom/4f84fc90-9ffa-...
starts_with_number = re.match(r'(\d+)\)', key)
if starts_with_number:
# if this is a numbered list on level 2, do nothing - this script doesn't support it
if current_indent_level >= 2:
continue
sub_num = int(starts_with_number.group(1))
# no. 1) we need to change dict() to list()
if sub_num == 1:
Expand Down
106 changes: 74 additions & 32 deletions tests/foreman/cli/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,31 +2467,38 @@ def test_positive_host_with_puppet(
session_puppet_enabled_sat.cli.target_sat.cli.Host.delete({'id': host['id']})


@pytest.fixture
def function_proxy(session_puppet_enabled_sat, puppet_proxy_port_range):
proxy = session_puppet_enabled_sat.cli_factory.make_proxy()
yield proxy
session_puppet_enabled_sat.cli.Proxy.delete({'id': proxy['id']})


@pytest.fixture
def function_host_content_source(
session_puppet_enabled_sat,
session_puppet_enabled_proxy,
module_puppet_lce_library,
module_puppet_org,
module_puppet_published_cv,
target_sat,
module_capsule_configured,
module_lce_library,
module_org,
module_ak_with_cv_repo,
module_product,
module_repository,
module_cv_repo,
rhel_contenthost,
):
host = session_puppet_enabled_sat.cli_factory.make_fake_host(
{
'content-source-id': session_puppet_enabled_proxy.id,
'content-view-id': module_puppet_published_cv.id,
'lifecycle-environment-id': module_puppet_lce_library.id,
'organization': module_puppet_org.name,
target_sat.cli.Product.info({'id': module_product.id, 'organization-id': module_org.id})
module_ak_with_cv_repo.content_override(
data={
'content_overrides': [
{
'content_label': '_'.join(
[module_org.name, module_product.name, module_repository.name]
),
'value': '1',
}
]
}
)
yield host
session_puppet_enabled_sat.cli.target_sat.cli.Host.delete({'id': host['id']})
target_sat.cli.Capsule.update(
{'name': module_capsule_configured.hostname, 'organization-ids': [module_org.id]}
)
# target_sat.cli.Capsule.info({'name': module_capsule_configured.hostname})
res = rhel_contenthost.register(module_org, None, module_ak_with_cv_repo.name, target_sat)
assert res.status == 0, f'Failed to register host: {res.stderr}'
return res


@pytest.mark.tier2
Expand Down Expand Up @@ -2637,33 +2644,68 @@ def test_positive_update_host_owner_and_verify_puppet_class_name(
@pytest.mark.cli_puppet_enabled
@pytest.mark.run_in_one_thread
@pytest.mark.tier2
@pytest.mark.rhel_ver_match('[8]')
@pytest.mark.no_containers
def test_positive_create_and_update_with_content_source(
session_puppet_enabled_sat,
session_puppet_enabled_proxy,
target_sat,
module_capsule_configured,
module_org,
module_lce,
module_repository,
rhel_contenthost,
function_host_content_source,
function_proxy,
):
"""Create a host with content source specified and update content
source
:id: 5712f4db-3610-447d-b1da-0fe461577d59
:customerscenario: true
:BZ: 1260697, 1483252, 1313056, 1488465
:expectedresults: A host is created with expected content source
assigned and then content source is successfully updated
:CaseImportance: High
"""
host = function_host_content_source
target_sat.cli.Repository.synchronize({'id': module_repository.id})

host = target_sat.cli.Host.info({'name': rhel_contenthost.hostname})
assert (
host['content-information']['content-source']['name'] == session_puppet_enabled_proxy.name
host['content-information']['content-source']['name'] == target_sat.hostname
or host['content-information']['content-source']['name'] == ''
)
new_content_source = function_proxy
session_puppet_enabled_sat.cli.target_sat.cli.Host.update(
{'id': host['id'], 'content-source-id': new_content_source.id}

# set a new proxy
target_sat.cli.Capsule.update(
{'name': module_capsule_configured.hostname, 'organization-id': module_org.id}
)
host = session_puppet_enabled_sat.cli.target_sat.cli.Host.info({'id': host['id']})
assert host['content-information']['content-source']['name'] == new_content_source.name
target_sat.cli.Capsule.content_add_lifecycle_environment(
{
'name': module_capsule_configured.hostname,
'organization-id': module_org.id,
'environment-id': module_lce.id,
}
)
target_sat.cli.Host.update(
{'id': host['id'], 'content-source': module_capsule_configured.hostname}
)
host = target_sat.cli.Host.info({'id': host['id']})
assert (
host['content-information']['content-source']['name'] == module_capsule_configured.hostname
)

# run an ansible job that makes a host aware that it should use a different content source
target_sat.cli_factory.job_invocation(
{
'job-template': 'Configure host for new content source',
'search-query': f"name ~ {rhel_contenthost.hostname}",
}
)

# test that the new content source is really used to get content
package = 'at'
assert rhel_contenthost.execute(f'rpm -q {package}').status != 0
assert rhel_contenthost.execute(f'dnf -y install {package}').status != 0
target_sat.cli.Capsule.content_synchronize({'name': module_capsule_configured.hostname})
assert rhel_contenthost.execute(f'dnf -y install {package}').status == 0
assert rhel_contenthost.execute(f'rpm -q {package}').status == 0

0 comments on commit 68fb262

Please sign in to comment.