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 15, 2021
1 parent c1f1774 commit 2ae5461
Show file tree
Hide file tree
Showing 5 changed files with 56 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"
27 changes: 27 additions & 0 deletions pulpcore/cli/core/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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("--name-contains", "name__contains"),
click.option("--name-icontains", "name__icontains"),
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]))
19 changes: 19 additions & 0 deletions tests/scripts/pulpcore/test_worker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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")
expect_succ pulp worker show --href "$href"

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
expect_succ pulp worker list --name "resource-manager"

if pulp debug has-plugin --name "pulpcore" --min-version "3.10.0"
then
expect_succ pulp worker list --name-contains "resource"
fi

0 comments on commit 2ae5461

Please sign in to comment.