Skip to content

Commit

Permalink
Added worker command.
Browse files Browse the repository at this point in the history
fixes pulp#144
  • Loading branch information
David Davis committed Feb 13, 2021
1 parent c1f1774 commit 383f5ef
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/144.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added worker command.
Empty file added log.err
Empty file.
1 change: 1 addition & 0 deletions log.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"pulp_created": "2021-02-13T14:04:00.194456Z", "pulp_href": "/pulp/api/v3/workers/f56f4707-af91-4ec5-8932-412d8cfe15ee/", "name": "[email protected]", "last_heartbeat": "2021-02-13T14:05:27.522615Z"}, {"pulp_created": "2021-02-13T14:04:00.007652Z", "pulp_href": "/pulp/api/v3/workers/9e984483-7a84-4f3e-8dee-09bdcc2a5c8e/", "name": "[email protected]", "last_heartbeat": "2021-02-13T14:05:27.525000Z"}, {"pulp_created": "2021-02-13T13:33:04.712612Z", "pulp_href": "/pulp/api/v3/workers/16671754-3562-4bcf-a49b-f76149a91bef/", "name": "[email protected]", "last_heartbeat": "2021-02-13T14:03:44.042739Z"}, {"pulp_created": "2021-02-13T13:33:04.384746Z", "pulp_href": "/pulp/api/v3/workers/4d994177-8ab1-4956-96a9-03a390a6751e/", "name": "[email protected]", "last_heartbeat": "2021-02-13T14:03:44.041780Z"}]
2 changes: 2 additions & 0 deletions pulpcore/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pulpcore.cli.core.status import status
from pulpcore.cli.core.task import task
from pulpcore.cli.core.user import user
from pulpcore.cli.core.worker import worker

# Register commands with cli
main.add_command(status)
Expand All @@ -25,3 +26,4 @@
main.add_command(export)
main.add_command(importer)
main.add_command(config)
main.add_command(worker)
7 changes: 7 additions & 0 deletions pulpcore/cli/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,10 @@ def find(self, **kwargs: Any) -> Any:
if len(search_result) != 1:
raise click.ClickException(f"Could not find {self.ENTITY} with {kwargs}.")
return search_result[0]


class PulpWorkerContext(PulpEntityContext):
ENTITY = "worker"
HREF = "worker_href"
LIST_ID = "workers_list"
READ_ID = "workers_read"
25 changes: 25 additions & 0 deletions pulpcore/cli/core/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import click

from pulpcore.cli.common.context import (
PulpContext,
pass_pulp_context,
)
from pulpcore.cli.common.generic import list_command, show_command, href_option, name_option
from pulpcore.cli.core.context import PulpWorkerContext


@click.group()
@pass_pulp_context
@click.pass_context
def worker(ctx: click.Context, pulp_ctx: PulpContext) -> None:
ctx.obj = PulpWorkerContext(pulp_ctx)


filter_options = [
click.option("--name"),
click.option("--missing/--not-missing", default=None),
click.option("--online/--not-online", default=None),
]

worker.add_command(list_command(decorators=filter_options))
worker.add_command(show_command(decorators=[href_option, name_option]))
15 changes: 15 additions & 0 deletions tests/scripts/pulpcore/test_worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

expect_succ pulp worker list
href=$(echo $OUTPUT | jq -r ".[0].pulp_href")
name=$(echo $OUTPUT | jq -r ".[0].name")
expect_succ pulp worker show --href "$href"
expect_succ pulp worker list --name "$name"

expect_succ pulp worker list --missing
expect_succ pulp worker list --not-missing
expect_succ pulp worker list --online
expect_succ pulp worker list --not-online

0 comments on commit 383f5ef

Please sign in to comment.