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

Fix publishing collection to specified repository when content approval is set to false #1717

Merged
merged 6 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGES/2328.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix publishing collection with ansible-galaxy when content approval si set to false.
34 changes: 20 additions & 14 deletions galaxy_ng/app/tasks/promotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
def auto_approve(src_repo_pk, cv_pk, ns_pk=None):
published_repos = AnsibleRepository.objects.filter(pulp_labels__pipeline="approved")
published_pks = list(published_repos.values_list("pk", flat=True))
staging_repo = AnsibleRepository.objects.get(pk=src_repo_pk)

staging_repos = AnsibleRepository.objects.filter(pulp_labels__pipeline="staging")
staging_pks = list(staging_repos.values_list("pk", flat=True))

source_repo = AnsibleRepository.objects.get(pk=src_repo_pk)

add = [cv_pk]
if ns_pk:
Expand All @@ -35,23 +39,25 @@ def auto_approve(src_repo_pk, cv_pk, ns_pk=None):
# Sign the collection if auto sign is enabled
if AUTO_SIGN:
sign(
repository_href=staging_repo,
repository_href=source_repo,
content_hrefs=[cv_pk],
signing_service_href=signing_service.pk
)

# move the new collection (along with all it's associated objects) into
# all of the approved repos.
dispatch(
move_collection,
exclusive_resources=published_repos,
shared_resources=[staging_repo],
kwargs={
"cv_pk_list": [cv_pk],
"src_repo_pk": staging_repo.pk,
"dest_repo_list": published_pks,
}
)
# if source repo isn't staging, don't move it to published repos
if source_repo.pk in staging_pks:
# move the new collection (along with all it's associated objects) into
# all of the approved repos.
dispatch(
move_collection,
exclusive_resources=published_repos,
shared_resources=[source_repo],
kwargs={
"cv_pk_list": [cv_pk],
"src_repo_pk": source_repo.pk,
"dest_repo_list": published_pks,
}
)


def call_auto_approve_task(collection_version, repo, ns_pk):
Expand Down
32 changes: 16 additions & 16 deletions galaxy_ng/tests/integration/api/test_upload_to_custom_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@


def _upload_test_common(config, client, artifact, base_path, dest_base_path=None):
api_prefix = config.get("api_prefix")
url = config["url"]

if dest_base_path is None:
url = f"{config['url']}content/{base_path}/"
dest_base_path = base_path

cmd = [
Expand All @@ -22,7 +26,7 @@ def _upload_test_common(config, client, artifact, base_path, dest_base_path=None
"--api-key",
config["token"],
"--server",
config["url"] + f"content/{base_path}/",
url,
artifact.filename,
"--ignore-certs"
]
Expand All @@ -33,7 +37,7 @@ def _upload_test_common(config, client, artifact, base_path, dest_base_path=None
wait_for_all_tasks(client)

collection_url = (
f"/content/{dest_base_path}/v3/collections/"
f"{api_prefix}content/{dest_base_path}/v3/collections/"
f"{artifact.namespace}/{artifact.name}/versions/1.0.0/"
)

Expand Down Expand Up @@ -94,11 +98,9 @@ def test_publish_to_custom_staging_repo(ansible_config, artifact, settings):
_upload_test_common(config, client, artifact, repo.get_distro()["base_path"])


@pytest.mark.standalone_only
@pytest.mark.community_only
@pytest.mark.min_hub_version("4.7dev")
def test_publish_to_custom_repo(ansible_config, artifact, settings):
if settings.get("GALAXY_REQUIRE_CONTENT_APPROVAL") is not True:
pytest.skip("GALAXY_REQUIRE_CONTENT_APPROVAL must be true")
config = ansible_config(profile="admin")
client = get_client(
config=config
Expand All @@ -112,13 +114,14 @@ def test_publish_to_custom_repo(ansible_config, artifact, settings):
_upload_test_common(config, client, artifact, repo.get_distro()["base_path"])


@pytest.mark.standalone_only
@pytest.mark.community_only
@pytest.mark.auto_approve
@pytest.mark.min_hub_version("4.7dev")
def test_publish_and_auto_approve(ansible_config, artifact, settings):
if settings.get("GALAXY_REQUIRE_CONTENT_APPROVAL"):
pytest.skip("GALAXY_REQUIRE_CONTENT_APPROVAL must be false")
config = ansible_config(profile="admin")
api_prefix = config.get("api_prefix")
client = get_client(
config=config
)
Expand All @@ -131,21 +134,21 @@ def test_publish_and_auto_approve(ansible_config, artifact, settings):
_upload_test_common(config, client, artifact, repo.get_distro()["base_path"], "published")

cv = client(
"/content/published/v3/collections/"
f"{api_prefix}content/published/v3/collections/"
f"{artifact.namespace}/{artifact.name}/versions/1.0.0/"

)

assert len(cv["signatures"]) >= 1
assert cv["version"] == "1.0.0"


@pytest.mark.standalone_only
@pytest.mark.community_only
@pytest.mark.auto_approve
@pytest.mark.min_hub_version("4.7dev")
def test_auto_approve_muliple(ansible_config, artifact, settings):
if settings.get("GALAXY_REQUIRE_CONTENT_APPROVAL"):
pytest.skip("GALAXY_REQUIRE_CONTENT_APPROVAL must be false")
config = ansible_config(profile="admin")
api_prefix = config.get("api_prefix")
client = get_client(
config=config
)
Expand All @@ -160,18 +163,15 @@ def test_auto_approve_muliple(ansible_config, artifact, settings):
_upload_test_common(config, client, artifact, "staging", published)

cv = client(
f"/content/{published}/v3/collections/"
f"{api_prefix}content/{published}/v3/collections/"
f"{artifact.namespace}/{artifact.name}/versions/1.0.0/"

)

assert len(cv["signatures"]) >= 1
assert cv["version"] == "1.0.0"

cv = client(
f"/content/published/v3/collections/"
f"{api_prefix}content/published/v3/collections/"
f"{artifact.namespace}/{artifact.name}/versions/1.0.0/"

)

assert len(cv["signatures"]) >= 1
assert cv["name"] == artifact.name
7 changes: 4 additions & 3 deletions galaxy_ng/tests/integration/utils/pulp_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def __init__(self, client, name, repo_body=None, distro_body=None):

def create(self):
self._repo = self.client(
"pulp/api/v3/repositories/ansible/ansible/",
f"{self.api_prefix}pulp/api/v3/repositories/ansible/ansible/",
args=self._repo_body,
method="POST"
)

resp = self.client(
"pulp/api/v3/distributions/ansible/ansible/",
f"{self.api_prefix}pulp/api/v3/distributions/ansible/ansible/",
args={
"repository": self._repo["pulp_href"],
**self._distro_body
Expand All @@ -67,7 +67,8 @@ def create(self):
wait_for_task(self.client, resp)

self._distro = self.client(
f"pulp/api/v3/distributions/ansible/ansible/?name={self._repo_body['name']}",
f"{self.api_prefix}pulp/api/v3/distributions/ansible/ansible/"
f"?name={self._repo_body['name']}",
)["results"][0]

self.cleanup_hrefs = [self._distro["pulp_href"], self._repo["pulp_href"]]
Expand Down
5 changes: 1 addition & 4 deletions galaxy_ng/tests/integration/utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ def url_safe_join(server, url):
# url contains the base url
if url.startswith(new_url) and server_path in url_path:
return (
new_url
+ server_path.rstrip('/')
+ '/'
+ url_path.replace(server_path, '').lstrip('/')
new_url + url_path
)

# url path is a pulp root
Expand Down