Skip to content

Commit 8dc6fcd

Browse files
committed
Add subcommand to dump task profile urls
fixes #1172
1 parent 4ae3ae0 commit 8dc6fcd

6 files changed

Lines changed: 49 additions & 4 deletions

File tree

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
jobs:
77
test:
88
if: "endsWith(github.base_ref, 'main')"
9-
runs-on: "ubuntu-20.04"
9+
runs-on: "ubuntu-24.04"
1010
steps:
1111
- uses: "actions/checkout@v4"
1212
- uses: "actions/cache@v4"
@@ -28,7 +28,7 @@ jobs:
2828
make docs
2929
no-test:
3030
if: "!endsWith(github.base_ref, 'main')"
31-
runs-on: "ubuntu-20.04"
31+
runs-on: "ubuntu-24.04"
3232
steps:
3333
- run: |
3434
echo "Skip docs testing on non-main branches."

CHANGES/1172.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `profile-artifact-urls` subcommand to `task` command.

CHANGES/pulp-glue/1172.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `profile_artifact_urls` to `PulpTaskContext`.

cookiecutter/docs/{{ cookiecutter.__project_name }}/.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
jobs:
77
test:
88
if: "endsWith(github.base_ref, 'main')"
9-
runs-on: "ubuntu-20.04"
9+
runs-on: "ubuntu-24.04"
1010
steps:
1111
- uses: "actions/checkout@v4"
1212
- uses: "actions/cache@v4"
@@ -28,7 +28,7 @@ jobs:
2828
make docs
2929
no-test:
3030
if: "!endsWith(github.base_ref, 'main')"
31-
runs-on: "ubuntu-20.04"
31+
runs-on: "ubuntu-24.04"
3232
steps:
3333
- run: |
3434
echo "Skip docs testing on non-main branches."

pulp-glue/pulp_glue/core/context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,15 @@ def cancel(self, task_href: t.Optional[str] = None, background: bool = False) ->
447447
self.pulp_ctx.echo(_("Done."), err=True)
448448
return task
449449

450+
def profile_artifact_urls(self) -> t.Dict[str, str]:
451+
self.pulp_ctx.needs_plugin(PluginRequirement("core", specifier=">=3.57.0"))
452+
result = self.call(
453+
"profile_artifacts",
454+
parameters={self.HREF: self.pulp_href},
455+
)["urls"]
456+
assert isinstance(result, dict)
457+
return result
458+
450459
@property
451460
def scope(self) -> t.Dict[str, t.Any]:
452461
if self.resource_context:

pulpcore/cli/core/task.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import re
12
import typing as t
23
from contextlib import suppress
34
from datetime import datetime
5+
from pathlib import Path
46

57
import click
8+
import requests
69
from pulp_glue.common.context import DATETIME_FORMATS, PluginRequirement, PulpEntityContext
710
from pulp_glue.common.exceptions import PulpException
811
from pulp_glue.common.i18n import get_translation
@@ -167,6 +170,37 @@ def cancel(
167170
task_ctx.cancel(task_ctx.pulp_href)
168171

169172

173+
@task.command()
174+
@href_option
175+
@uuid_option
176+
@click.option("--download/--no-download")
177+
@pass_task_context
178+
@pass_pulp_context
179+
def profile_artifact_urls(
180+
pulp_ctx: PulpCLIContext,
181+
task_ctx: PulpTaskContext,
182+
/,
183+
download: bool,
184+
) -> None:
185+
"""Prints download links for profile urls of the task."""
186+
urls = task_ctx.profile_artifact_urls()
187+
pulp_ctx.output_result(urls)
188+
if download:
189+
task_name: str = task_ctx.entity["name"]
190+
uuid_match = re.match(r".*/api/v3/tasks/(?P<uuid>.*)/", task_ctx.entity["pulp_href"])
191+
assert uuid_match is not None
192+
uuid = uuid_match.group("uuid")
193+
profile_artifact_dir = Path(".") / f"task_profile-{task_name}-{uuid}"
194+
profile_artifact_dir.mkdir(exist_ok=True)
195+
with requests.session() as session:
196+
for name, url in urls.items():
197+
profile_artifact_path = profile_artifact_dir / name
198+
click.echo(_("Downloading {path}").format(path=profile_artifact_path))
199+
response = session.get(url)
200+
response.raise_for_status()
201+
profile_artifact_path.write_bytes(response.content)
202+
203+
170204
@task.command()
171205
@click.option(
172206
"--finished-before",

0 commit comments

Comments
 (0)