Skip to content

Commit

Permalink
Add a test case to consume flatpak via CV
Browse files Browse the repository at this point in the history
  • Loading branch information
vsedmik committed Feb 12, 2025
1 parent 2aeb15f commit e0889d1
Showing 1 changed file with 168 additions and 6 deletions.
174 changes: 168 additions & 6 deletions tests/foreman/cli/test_flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from robottelo.config import settings
from robottelo.constants import FLATPAK_ENDPOINTS, FLATPAK_INDEX_SUFFIX, FLATPAK_REMOTES
from robottelo.exceptions import CLIReturnCodeError
from robottelo.exceptions import CLIFactoryError, CLIReturnCodeError
from robottelo.utils.datafactory import gen_string


Expand All @@ -44,6 +44,17 @@ def function_user(target_sat, function_role, function_org):
user.delete()


@pytest.fixture
def function_host_cleanup(target_sat, module_flatpak_contenthost):
"""Cleans up the flatpak contenthost so it can be re-registered with different org"""
module_flatpak_contenthost.unregister()
host = target_sat.api.Host().search(
query={'search': f'name={module_flatpak_contenthost.hostname}'}
)
if len(host) > 0:
target_sat.api.Host(id=host[0].id).delete()


def test_CRUD_and_sync_flatpak_remote_with_permissions(
target_sat, function_user, function_role, function_org
):
Expand Down Expand Up @@ -224,11 +235,12 @@ def test_sync_consume_flatpak_repo_via_library(
request,
module_target_sat,
module_flatpak_contenthost,
function_host_cleanup,
function_org,
function_product,
function_flatpak_remote,
):
"""Verify flatpak repository workflow end to end.
"""Verify flatpak repository workflow end to end via library.
:id: 06043b3e-be9b-4444-96b1-d3d15b7e3d8c
Expand All @@ -241,7 +253,7 @@ def test_sync_consume_flatpak_repo_via_library(
1. Mirror flatpak repositories and sync them.
2. Create an AK assigned to the Library.
3. Register a content host using the AK.
4. Configure the contenthost via REX to use Satellite's flatpak index.
4. Configure the contenthost via REX to use Satellite's pulpcore flatpak index.
5. Install flatpak app from the repo via REX on the contenthost.
6. Ensure the app has been installed successfully.
Expand Down Expand Up @@ -298,7 +310,7 @@ def test_sync_consume_flatpak_repo_via_library(
)
assert host.subscribed

# 4. Configure the contenthost via REX to use Satellite's flatpak index.
# 4. Configure the contenthost via REX to use Satellite's pulpcore flatpak index.
remote_name = f'SAT-remote-{gen_string("alpha")}'
job = module_target_sat.cli_factory.job_invocation(
{
Expand All @@ -316,11 +328,10 @@ def test_sync_consume_flatpak_repo_via_library(
res = module_target_sat.cli.JobInvocation.info({'id': job.id})
assert 'succeeded' in res['status']
request.addfinalizer(lambda: host.execute(f'flatpak remote-delete {remote_name}'))

# 5. Install flatpak app from the repo via REX on the contenthost.
res = host.execute('flatpak remotes')
assert remote_name in res.stdout

# 5. Install flatpak app from the repo via REX on the contenthost.
app_name = 'Firefox' # or 'org.mozilla.Firefox'
res = host.execute('flatpak remote-ls')
assert app_name in res.stdout
Expand All @@ -342,3 +353,154 @@ def test_sync_consume_flatpak_repo_via_library(
# 6. Ensure the app has been installed successfully.
res = host.execute('flatpak list')
assert app_name in res.stdout


@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.parametrize('function_flatpak_remote', ['RedHat'], indirect=True)
def test_sync_consume_flatpak_repo_via_cv(
request,
module_target_sat,
module_flatpak_contenthost,
function_host_cleanup,
function_org,
function_lce,
function_product,
function_flatpak_remote,
):
"""Verify flatpak repository workflow end to end via CV.
:id: 820b59b0-20f0-472a-afab-5c480bedbfd0
:parametrized: yes
:setup:
1. Create a Product and a Lifecycle Environment.
2. Create a flatpak remote and scan it.
:steps:
1. Mirror flatpak repositories and sync them.
2. Create two CVs, put different repos inside, publish and promote them to LCE.
3. Create an AK assigned with one CVE only.
4. Register a content host using the AK.
5. Configure the content host to use Satellite's flatpak index.
6. Ensure only the proper Apps are available.
7. Install flatpak app from the first CV, ensure it succeeded.
8. Try to install flatpak app from the second CV, ensure it failed.
:expectedresults:
1. Flatpak repos published in a CV are installable on a host via the CV.
2. Other flatpak repos published in a different CV are isolated from the first CV.
"""
sat, host = module_target_sat, module_flatpak_contenthost

# 1. Mirror flatpak repositories and sync them.
repo_names = ['rhel9/firefox-flatpak', 'rhel9/inkscape-flatpak', 'rhel9/flatpak-runtime']
remote_repos = [r for r in function_flatpak_remote.repos if r['name'] in repo_names]
for repo in remote_repos:
sat.cli.FlatpakRemote().repository_mirror(
{
'flatpak-remote-id': function_flatpak_remote.remote['id'],
'id': repo['id'],
'product-id': function_product.id,
}
)
local_repo = sat.cli.Repository.list(
{'product-id': function_product.id, 'name': repo['name']}
)[0]
sat.cli.Repository.synchronize({'id': local_repo['id']})

local_repos = sat.cli.Repository.list({'product-id': function_product.id})
assert set([r['name'] for r in local_repos]) == set(repo_names), (
'Required repo(s) were not scanned or mirrored'
)

# 2. Create two CVs, put different repos inside, publish and promote them to LCE.
cv1 = sat.api.ContentView(
organization=function_org,
repository=[
r['id']
for r in local_repos
if r['name'] in ['rhel9/inkscape-flatpak', 'rhel9/flatpak-runtime']
],
).create()
cv2 = sat.api.ContentView(
organization=function_org,
repository=[
r['id']
for r in local_repos
if r['name'] in ['rhel9/firefox-flatpak', 'rhel9/flatpak-runtime']
],
).create()
for cv in [cv1, cv2]:
cv.publish()
cv.read().version[0].promote(data={'environment_ids': function_lce.id})

# 3. Create an AK assigned with one CVE only.
ak = sat.api.ActivationKey(
organization=function_org,
content_view=cv1,
environment=function_lce,
).create()

# 4. Register a content host using the AK.
res = host.register(function_org, None, ak.name, sat, force=True)
assert res.status == 0, (
f'Failed to register host: {host.hostname}\nStdOut: {res.stdout}\nStdErr: {res.stderr}'
)
assert host.subscribed

# 5. Configure the content host to use Satellite's flatpak index.
remote_name = f'SAT-remote-{gen_string("alpha")}'
job = module_target_sat.cli_factory.job_invocation(
{
'organization': function_org.name,
'job-template': 'Flatpak - Set up remote on host',
'inputs': (
f'Remote Name={remote_name}, '
f'Flatpak registry URL=https://{sat.hostname}/, '
f'Username={settings.server.admin_username}, '
f'Password={settings.server.admin_password}'
),
'search-query': f"name ~ {host.hostname}",
}
)
res = module_target_sat.cli.JobInvocation.info({'id': job.id})
assert 'succeeded' in res['status']
request.addfinalizer(lambda: host.execute(f'flatpak remote-delete {remote_name}'))
res = host.execute('flatpak remotes')
assert remote_name in res.stdout

# 6. Ensure only the proper Apps are available.
res = host.execute('flatpak remote-ls')
assert all(app_name in res.stdout for app_name in ['Inkscape', 'Platform'])
assert 'Firefox' not in res.stdout

# 7. Install flatpak app from the first CV, ensure it succeeded.
opts = {
'organization': function_org.name,
'job-template': 'Flatpak - Install application on host',
'search-query': f"name ~ {host.hostname}",
}
cv1_app = 'Inkscape'
job = module_target_sat.cli_factory.job_invocation(
opts | {'inputs': f'Flatpak remote name={remote_name}, Application name={cv1_app}'}
)
res = module_target_sat.cli.JobInvocation.info({'id': job.id})
assert 'succeeded' in res['status']
request.addfinalizer(
lambda: host.execute(f'flatpak uninstall {remote_name} {cv1_app} com.redhat.Platform -y')
)
res = host.execute('flatpak list')
assert cv1_app in res.stdout

# 8. Try to install flatpak app from the second CV, ensure it failed.
cv2_app = 'Firefox'
with pytest.raises(CLIFactoryError) as error:
sat.cli_factory.job_invocation(
opts | {'inputs': f'Flatpak remote name={remote_name}, Application name={cv2_app}'}
)
assert 'A sub task failed' in error.value.args[0]
res = host.execute('flatpak list')
assert cv2_app not in res.stdout

0 comments on commit e0889d1

Please sign in to comment.