Skip to content

Commit

Permalink
Added worker command.
Browse files Browse the repository at this point in the history
fixes #144
  • Loading branch information
David Davis committed Feb 13, 2021
1 parent c1f1774 commit 4e1f800
Show file tree
Hide file tree
Showing 5 changed files with 50 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.
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 4e1f800

Please sign in to comment.