Skip to content

Commit

Permalink
Rebased.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Feb 15, 2024
1 parent ab3e99e commit 1043b63
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 54 deletions.
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/api/test_aiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..utils import (
UIClient,
SocialGithubClient,
generate_unused_namespace,
generate_unused_namespace_name,
get_client
)

Expand Down Expand Up @@ -31,7 +31,7 @@ def pe_namespace(ansible_config) -> str:
"""create a new namespace owned by PE user."""
config = ansible_config("partner_engineer")
api_client = get_client(config, request_token=True, require_auth=True)
new_namespace = generate_unused_namespace(api_client=api_client, api_version="_ui/v1")
new_namespace = generate_unused_namespace_name(api_client=api_client, api_version="_ui/v1")
with UIClient(config=config) as uclient:
# get user
resp = uclient.get("_ui/v1/me/")
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_auth_admin(ansible_config):

@pytest.mark.deployment_standalone
@pytest.mark.galaxyapi_smoke
def test_auth_exception(ansible_config, published):
def test_auth_exception(ansible_config):
"""Test whether an HTTP exception when using an invalid token."""

config = ansible_config("basic_user")
Expand Down
12 changes: 6 additions & 6 deletions galaxy_ng/tests/integration/api/test_ui_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from ..utils import (
UIClient,
generate_unused_namespace,
generate_unused_namespace_name,
get_client,
wait_for_task_ui_client,
wait_for_task,
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_api_ui_v1_me(ansible_config, settings):
def test_api_ui_v1_my_namespaces(ansible_config):
config = ansible_config("partner_engineer")
api_client = get_client(config, request_token=True, require_auth=True)
new_namespace = generate_unused_namespace(api_client=api_client, api_version='_ui/v1')
new_namespace = generate_unused_namespace_name(api_client=api_client, api_version='_ui/v1')

cfg = ansible_config('partner_engineer')
with UIClient(config=cfg) as uclient:
Expand Down Expand Up @@ -718,11 +718,11 @@ def test_api_ui_v1_repo_distro_by_basepath(ansible_config):
# /api/automation-hub/_ui/v1/repo/{distro_base_path}/{namespace}/{name}/
@pytest.mark.deployment_standalone
@pytest.mark.api_ui
def test_api_ui_v1_collection_detail_view(ansible_config, published):
def test_api_ui_v1_collection_detail_view(ansible_config, published_artifact):

namespace = published.namespace
name = published.name
version = published.version
namespace = published_artifact.namespace
name = published_artifact.name
version = published_artifact.version

cfg = ansible_config('basic_user')
with UIClient(config=cfg) as uclient:
Expand Down
13 changes: 6 additions & 7 deletions galaxy_ng/tests/integration/cli/test_cli_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ def test_publish_newer_certified_collection_version(
@pytest.mark.all
@pytest.mark.cli
@pytest.mark.skip(reason="pulp is changing how this works")
def test_publish_same_collection_version(ansible_config, galaxy_client):
def test_publish_same_collection_version(ansible_config, galaxy_client, new_v3_namespace):
"""Test you cannot publish same collection version already published."""

gc = galaxy_client("partner_engineer")
cnamespace = create_test_namespace(gc)
collection = build_collection(namespace=cnamespace)
collection = build_collection(namespace=new_v3_namespace)
ansible_galaxy(
f"collection publish {collection.filename}",
ansible_config=ansible_config("admin")
Expand All @@ -94,13 +93,13 @@ def test_publish_same_collection_version(ansible_config, galaxy_client):

@pytest.mark.all
@pytest.mark.cli
def test_publish_and_install_by_self(ansible_config, published, cleanup_collections):
def test_publish_and_install_by_self(ansible_config, published_artifact, cleanup_collections):
"""A publishing user has the permission to install an uncertified version of their
own collection.
"""

ansible_galaxy(
f"collection install {published.namespace}.{published.name}:{published.version}",
f"collection install {published_artifact.namespace}.{published_artifact.name}:{published_artifact.version}",
ansible_config=ansible_config("basic_user"),
)

Expand All @@ -121,11 +120,11 @@ def test_publish_and_expect_uncertified_hidden(
uncertified collection, but not an unspecified version range.
"""
ansible_galaxy(
f"collection install {published.namespace}.{published.name}",
f"collection install {published_artifact.namespace}.{published_artifact.name}",
check_retcode=0,
ansible_config=ansible_config("basic_user"),
)
ansible_galaxy(
f"collection install {published.namespace}.{published.name}:1.0.0",
f"collection install {published_artifact.namespace}.{published_artifact.name}:1.0.0",
ansible_config=ansible_config("basic_user"),
)
6 changes: 3 additions & 3 deletions galaxy_ng/tests/integration/cli/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DependencySpec:
),
ids=lambda s: s.name,
)
def test_collection_dependency_install(ansible_config, published, cleanup_collections,
def test_collection_dependency_install(ansible_config, published_artifact, cleanup_collections,
params, galaxy_client):
"""Collections defining dependencies can be installed and their dependencies are installed
as well.
Expand All @@ -54,7 +54,7 @@ def test_collection_dependency_install(ansible_config, published, cleanup_collec

spec = params.spec
retcode = params.retcode
artifact2 = build_collection(dependencies={f"{published.namespace}.{published.name}": spec})
artifact2 = build_collection(dependencies={f"{published_artifact.namespace}.{published_artifact.name}": spec})

try:
ansible_galaxy(
Expand Down Expand Up @@ -89,6 +89,6 @@ def test_collection_dependency_install(ansible_config, published, cleanup_collec
pid.returncode == retcode
), f"Unexpected {'failure' if pid.returncode else 'success'} during installing \
{artifact2.namespace}.{artifact2.name}:{artifact2.version} \
with dependency {published.namespace}.{published.name}{spec}"
with dependency {published_artifact.namespace}.{published_artifact.name}{spec}"
except AssertionError:
raise
6 changes: 3 additions & 3 deletions galaxy_ng/tests/integration/community/test_v1_namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ansible_galaxy,
SocialGithubClient,
get_client,
generate_unused_namespace,
generate_unused_namespace_name,
)

from ..utils.legacy import cleanup_social_user
Expand Down Expand Up @@ -96,12 +96,12 @@ def test_v1_namespace_provider_filter(ansible_config):
v1_b_id = v1_b['id']

# make 1 v3 namespace
v3_a_name = generate_unused_namespace(admin_client)
v3_a_name = generate_unused_namespace_name(admin_client)
v3_a = admin_client(
'/api/v3/namespaces/', method='POST', args={'name': v3_a_name, 'groups': []}
)
v3_a_id = v3_a['id']
v3_b_name = generate_unused_namespace(admin_client)
v3_b_name = generate_unused_namespace_name(admin_client)
v3_b = admin_client(
'/api/v3/namespaces/', method='POST', args={'name': v3_b_name, 'groups': []}
)
Expand Down
40 changes: 29 additions & 11 deletions galaxy_ng/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from .utils import (
ansible_galaxy,
build_collection,
cleanup_namespace,
create_unused_namespace,
get_client,
set_certification,
set_synclist,
Expand Down Expand Up @@ -104,7 +106,8 @@ def ansible_config():


@pytest.fixture(scope="function")
def published(ansible_config, artifact, galaxy_client):
def published_artifact(ansible_config, artifact, galaxy_client):
"""Make and return a published collection."""
# make sure the expected namespace exists ...
config = ansible_config("partner_engineer")
api_client = get_client(config)
Expand All @@ -122,7 +125,8 @@ def published(ansible_config, artifact, galaxy_client):
hub_4_5 = is_hub_4_5(ansible_config)
set_certification(api_client, gc, artifact, hub_4_5=hub_4_5)

return artifact
yield artifact
cleanup_namespace(artifact.namespace, api_client=api_client)


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -165,24 +169,24 @@ def certifiedv2(ansible_config, artifact, galaxy_client):
# certify newer version
set_certification(api_client, gc, artifact2, hub_4_5=hub_4_5)

return (artifact, artifact2)
yield (artifact, artifact2)
cleanup_namespace(artifact.namespace, api_client=api_client)


@pytest.fixture(scope="function")
def uncertifiedv2(ansible_config, artifact, settings, galaxy_client):
""" Create and publish collection version N and N+1 but only certify N"""

# make sure the expected namespace exists ...
config = ansible_config("partner_engineer")
api_client = get_client(config)
pe_config = ansible_config("partner_engineer")
api_client = get_client(pe_config)
gc = galaxy_client("partner_engineer")
create_namespace(gc, artifact.namespace, "")

# publish
config = ansible_config("basic_user")
ansible_galaxy(
f"collection publish {artifact.filename}",
ansible_config=config
ansible_config=pe_config
)

# certify v1
Expand All @@ -199,17 +203,17 @@ def uncertifiedv2(ansible_config, artifact, settings, galaxy_client):
)

# Publish but do -NOT- certify newer version ...
config = ansible_config("basic_user")
ansible_galaxy(
f"collection publish {artifact2.filename}",
ansible_config=config
ansible_config=pe_config
)
dest_url = (
f"v3/plugin/ansible/content/staging/collections/index/"
f"{artifact2.namespace}/{artifact2.name}/versions/{artifact2.version}/"
)
wait_for_url(api_client, dest_url)
return artifact, artifact2
yield artifact, artifact2
cleanup_namespace(artifact.namespace, api_client=api_client)


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -255,7 +259,8 @@ def auto_approved_artifacts(ansible_config, artifact, galaxy_client):
f"{artifact2.namespace}/{artifact2.name}/versions/{artifact2.version}/"
)
wait_for_url(api_client, dest_url)
return artifact, artifact2
yield artifact, artifact2
cleanup_namespace(artifact.namespace, api_client=api_client)


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -622,3 +627,16 @@ def clean_test_user_and_groups():
return user

return _


###############################################
# auto-clean fixtures
###############################################

@pytest.fixture
def new_v3_namespace(ansible_config):
config = ansible_config("admin")
client = get_client(config)
ns = create_unused_namespace(api_client=client)
yield ns
cleanup_namespace(ns, api_client=client)
8 changes: 4 additions & 4 deletions galaxy_ng/tests/integration/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
CapturingGalaxyError,
)
from .namespaces import (
generate_namespace,
generate_namespace_name,
get_all_namespaces,
generate_unused_namespace,
generate_unused_namespace_name,
create_unused_namespace,
cleanup_namespace
)
Expand Down Expand Up @@ -68,9 +68,9 @@
get_all_repository_collection_versions,
TaskWaitingTimeout,
CapturingGalaxyError,
generate_namespace,
generate_namespace_name,
get_all_namespaces,
generate_unused_namespace,
generate_unused_namespace_name,
create_unused_namespace,
cleanup_namespace,
wait_for_task,
Expand Down
44 changes: 34 additions & 10 deletions galaxy_ng/tests/integration/utils/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,18 @@ def get_all_collections_by_repo(api_client=None):
""" Return a dict of each repo and their collections """
assert api_client is not None, "api_client is a required param"
api_prefix = api_client.config.get("api_prefix").rstrip("/")
collections = {
'staging': {},
'published': {},
'community': {},
'rh-certified': {},
}

# get all distributions ...
# /api/galaxy/pulp/api/v3/distributions/
distro_names = []
next_page = f'{api_prefix}/pulp/api/v3/distributions/'
while next_page:
resp = api_client(next_page)
next_page = resp.get('links', {}).get('next')
for distro in resp['results']:
distro_names.append(distro['name'])

collections = dict((x, {}) for x in distro_names)
for repo in collections.keys():
next_page = f'{api_prefix}/_ui/v1/collection-versions/?repository={repo}'
while next_page:
Expand Down Expand Up @@ -638,25 +644,43 @@ def delete_all_collections(api_client):
def delete_all_collections_in_namespace(api_client, namespace_name):

assert api_client is not None, "api_client is a required param"
api_prefix = api_client.config.get("api_prefix").rstrip("/")

# accumlate a list of matching collections in each repo
ctuples = set()

'''
cmap = get_all_collections_by_repo(api_client)
for repo, cvs in cmap.items():
for cv_spec in cvs.keys():
if cv_spec[0] == namespace_name:
ctuples.add((repo, cv_spec[0], cv_spec[1]))
'''

#import epdb; epdb.st()
next_page = f'{api_prefix}/_ui/v1/collection-versions/?namespace={namespace_name}'
while next_page:
resp = api_client(next_page)
next_page = resp.get('links', {}).get('next')

for collection in resp['data']:
for repository_name in collection['repository_list']:
ctuples.add((repository_name, collection['namespace'], collection['name']))

# delete each collection ...
results = []
for ctuple in ctuples:
crepo = ctuple[0]
cname = ctuple[2]

recursive_delete(api_client, namespace_name, cname, crepo)
res = recursive_delete(api_client, namespace_name, cname, crepo)
results.append(res)

return results


def recursvive_delete(api_client, namespace_name, cname, crepo):
return recursive_delete(api_client, namespace_name, cname, crepo)
#def recursvive_delete(api_client, namespace_name, cname, crepo):
# return recursive_delete(api_client, namespace_name, cname, crepo)


def recursive_delete(api_client, namespace_name, cname, crepo):
Expand All @@ -672,7 +696,7 @@ def recursive_delete(api_client, namespace_name, cname, crepo):

if dependants:
for ns, name in dependants:
recursvive_delete(api_client, ns, name, crepo)
recursive_delete(api_client, ns, name, crepo)

# Try deleting the whole collection ...
try:
Expand Down
Loading

0 comments on commit 1043b63

Please sign in to comment.