Skip to content

Commit

Permalink
[6.15.z] Use RHEL8 for container contenthost (#15202)
Browse files Browse the repository at this point in the history
Use RHEL8 for container contenthost (#15179)

(cherry picked from commit 765e030)

Co-authored-by: vsedmik <[email protected]>
  • Loading branch information
Satellite-QE and vsedmik authored Jun 3, 2024
1 parent 352f92d commit e7de38d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 52 deletions.
26 changes: 13 additions & 13 deletions pytest_fixtures/core/contenthosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,25 @@ def katello_host_tools_tracer_host(rex_contenthost, target_sat):
return rex_contenthost


@pytest.fixture
def container_contenthost(request, target_sat):
@pytest.fixture(scope='module')
def module_container_contenthost(request, module_target_sat):
"""Fixture that installs docker on the content host"""
request.param = {
"rhel_version": "7",
"rhel_version": "8",
"distro": "rhel",
"no_containers": True,
}
with Broker(**host_conf(request), host_class=ContentHost) as host:
host.install_katello_ca(target_sat)
repos = {
'server': settings.repos.rhel7_os,
'optional': settings.repos.rhel7_optional,
'extras': settings.repos.rhel7_extras,
}
host.create_custom_repos(**repos)
for service in constants.CONTAINER_CLIENTS:
host.execute(f'yum -y install {service}')
host.execute(f'systemctl start {service}')
host.register_to_cdn()
# needed for docker commands to accept Satellite's cert
host.install_katello_ca(module_target_sat)
for client in constants.CONTAINER_CLIENTS:
assert (
host.execute(f'yum -y install {client}').status == 0
), f'{client} installation failed'
assert (
host.execute('systemctl enable --now podman').status == 0
), 'Start of podman service failed'
yield host


Expand Down
12 changes: 6 additions & 6 deletions tests/foreman/api/test_capsulecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def test_positive_sync_container_repo_end_to_end(
self,
target_sat,
module_capsule_configured,
container_contenthost,
module_container_contenthost,
function_org,
function_product,
function_lce,
Expand Down Expand Up @@ -943,29 +943,29 @@ def test_positive_sync_container_repo_end_to_end(
]

for con_client in CONTAINER_CLIENTS:
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'{con_client} login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {module_capsule_configured.hostname}'
)
assert result.status == 0

for path in repo_paths:
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'{con_client} search {module_capsule_configured.hostname}/{path}'
)
assert result.status == 0

result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'{con_client} pull {module_capsule_configured.hostname}/{path}'
)
assert result.status == 0

result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'{con_client} rmi {module_capsule_configured.hostname}/{path}'
)
assert result.status == 0

result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'{con_client} logout {module_capsule_configured.hostname}'
)
assert result.status == 0
Expand Down
78 changes: 45 additions & 33 deletions tests/foreman/cli/test_container_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class TestDockerClient:
"""

@pytest.mark.tier3
def test_positive_pull_image(self, module_org, container_contenthost, target_sat):
def test_positive_pull_image(
self, request, module_org, module_container_contenthost, target_sat
):
"""A Docker-enabled client can use ``docker pull`` to pull a
Docker image off a Satellite 6 instance.
Expand All @@ -74,41 +76,44 @@ def test_positive_pull_image(self, module_org, container_contenthost, target_sat
target_sat.cli.Repository.synchronize({'id': repo['id']})
repo = target_sat.cli.Repository.info({'id': repo['id']})
try:
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)

# publishing takes few seconds sometimes
result, _ = wait_for(
lambda: container_contenthost.execute(f'docker pull {repo["published-at"]}'),
lambda: module_container_contenthost.execute(f'docker pull {repo["published-at"]}'),
num_sec=60,
delay=2,
fail_condition=lambda out: out.status != 0,
logger=logger,
)
assert result.status == 0
try:
result = container_contenthost.execute(f'docker run {repo["published-at"]}')
result = module_container_contenthost.execute(f'docker run {repo["published-at"]}')
assert result.status == 0
finally:
# Stop and remove the container
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'docker ps -a | grep {repo["published-at"]}'
)
container_id = result.stdout[0].split()[0]
container_contenthost.execute(f'docker stop {container_id}')
container_contenthost.execute(f'docker rm {container_id}')
module_container_contenthost.execute(f'docker stop {container_id}')
module_container_contenthost.execute(f'docker rm {container_id}')
finally:
# Remove docker image
container_contenthost.execute(f'docker rmi {repo["published-at"]}')
module_container_contenthost.execute(f'docker rmi {repo["published-at"]}')

@pytest.mark.skip_if_not_set('docker')
@pytest.mark.tier3
@pytest.mark.e2e
def test_positive_container_admin_end_to_end_search(
self, module_org, container_contenthost, target_sat
self, request, module_org, module_container_contenthost, target_sat
):
"""Verify that docker command line can be used against
Satellite server to search for container images stored
Expand Down Expand Up @@ -166,34 +171,37 @@ def test_positive_container_admin_end_to_end_search(
}
)
docker_repo_uri = (
f' {target_sat.hostname}/{pattern_prefix}-{content_view["label"]}/'
f'{CONTAINER_UPSTREAM_NAME} '
f'{target_sat.hostname}/{pattern_prefix}-{content_view["label"]}/'
f'{CONTAINER_UPSTREAM_NAME}'
).lower()

# 3. Try to search for docker images on Satellite
remote_search_command = f'docker search {target_sat.hostname}/{CONTAINER_UPSTREAM_NAME}'
result = container_contenthost.execute(remote_search_command)
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri not in result.stdout

# 4. Use Docker client to login to Satellite docker hub
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)

# 5. Search for docker images
result = container_contenthost.execute(remote_search_command)
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri in result.stdout

# 6. Use Docker client to log out of Satellite docker hub
result = container_contenthost.execute(f'docker logout {target_sat.hostname}')
result = module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
assert result.status == 0

# 7. Try to search for docker images
result = container_contenthost.execute(remote_search_command)
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri not in result.stdout

Expand All @@ -207,15 +215,15 @@ def test_positive_container_admin_end_to_end_search(
)

# 9. Search for docker images
result = container_contenthost.execute(remote_search_command)
result = module_container_contenthost.execute(remote_search_command)
assert result.status == 0
assert docker_repo_uri in result.stdout

@pytest.mark.skip_if_not_set('docker')
@pytest.mark.tier3
@pytest.mark.e2e
def test_positive_container_admin_end_to_end_pull(
self, module_org, container_contenthost, target_sat
self, request, module_org, module_container_contenthost, target_sat
):
"""Verify that docker command line can be used against
Satellite server to pull in container images stored
Expand Down Expand Up @@ -280,20 +288,23 @@ def test_positive_container_admin_end_to_end_pull(

# 3. Try to pull in docker image from Satellite
docker_pull_command = f'docker pull {docker_repo_uri}'
result = container_contenthost.execute(docker_pull_command)
assert result.status == 1
result = module_container_contenthost.execute(docker_pull_command)
assert result.status != 0

# 4. Use Docker client to login to Satellite docker hub
result = container_contenthost.execute(
result = module_container_contenthost.execute(
f'docker login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
)
assert result.status == 0
request.addfinalizer(
lambda: module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
)

# 5. Pull in docker image
# publishing takes few seconds sometimes
result, _ = wait_for(
lambda: container_contenthost.execute(docker_pull_command),
lambda: module_container_contenthost.execute(docker_pull_command),
num_sec=60,
delay=2,
fail_condition=lambda out: out.status != 0,
Expand All @@ -302,12 +313,12 @@ def test_positive_container_admin_end_to_end_pull(
assert result.status == 0

# 6. Use Docker client to log out of Satellite docker hub
result = container_contenthost.execute(f'docker logout {target_sat.hostname}')
result = module_container_contenthost.execute(f'docker logout {target_sat.hostname}')
assert result.status == 0

# 7. Try to pull in docker image
result = container_contenthost.execute(docker_pull_command)
assert result.status == 1
result = module_container_contenthost.execute(docker_pull_command)
assert result.status != 0

# 8. Set 'Unauthenticated Pull' option to true
target_sat.cli.LifecycleEnvironment.update(
Expand All @@ -319,11 +330,11 @@ def test_positive_container_admin_end_to_end_pull(
)

# 9. Pull in docker image
result = container_contenthost.execute(docker_pull_command)
result = module_container_contenthost.execute(docker_pull_command)
assert result.status == 0

def test_negative_pull_content_with_longer_name(
self, target_sat, container_contenthost, module_org
self, request, target_sat, module_container_contenthost, module_org
):
"""Verify that long name CV publishes when CV & docker repo both have a larger name.
Expand Down Expand Up @@ -383,19 +394,20 @@ def test_negative_pull_content_with_longer_name(
)

podman_pull_command = (
f"podman pull --tls-verify=false {target_sat.hostname}/{module_org.label.lower()}"
f"-{lce['label'].lower()}-{cv['label'].lower()}-{product['label'].lower()}-{repo_name}"
f"podman pull --tls-verify=false {target_sat.hostname}/{module_org.label}"
f"-{lce['label']}-{cv['label']}-{product['label']}-{repo_name}".lower()
)

# 4. Pull in docker image
assert (
container_contenthost.execute(
module_container_contenthost.execute(
f'podman login -u {settings.server.admin_username}'
f' -p {settings.server.admin_password} {target_sat.hostname}'
).status
== 0
)
request.addfinalizer(
lambda: module_container_contenthost.execute(f'podman logout {target_sat.hostname}')
)

assert container_contenthost.execute(podman_pull_command).status == 0

assert container_contenthost.execute(f'podman logout {target_sat.hostname}').status == 0
assert module_container_contenthost.execute(podman_pull_command).status == 0

0 comments on commit e7de38d

Please sign in to comment.