Skip to content

Commit

Permalink
fix the logic on returning events for when none of the targeted minio…
Browse files Browse the repository at this point in the history
…ns exist. so no job can be created
  • Loading branch information
whytewolf committed Nov 15, 2024
1 parent 75a9175 commit 1abd9a4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
Binary file added out.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 5 additions & 14 deletions src/guajillo/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ def build_args(self, args: list["str"]) -> None:
"-o",
"--out",
dest="output",
choices=["json", "yaml", "boolean"],
help="Output method will auto detect if possable, use this to force or set to json for json output",
)
self.parser.add_argument(
"--out-list", help="list known output methods", action="store_true"
)
self.parser.add_argument(
"--output-file", dest="output_file", help="Output File"
)
self.parser.add_argument(
"-L",
"-l",
"--log",
dest="log_level",
choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"],
Expand Down Expand Up @@ -101,17 +99,10 @@ def help(self, doexit: bool = True):
options.add_row(
"-o",
"--out",
"OUTPUT",
"currently not used, but will let uses force output style",
"{json, yaml, boolean}",
"force output style through a known output",
"auto",
)
options.add_row(
"",
"--out-list",
"",
"list known output types, currently not implimented",
"",
)
options.add_row(
"",
"--output-file",
Expand All @@ -127,7 +118,7 @@ def help(self, doexit: bool = True):
"30",
)
options.add_row(
"-L",
"-l",
"--log",
"{[bold red]CRITICAL[/bold red],[red]ERROR[/red],[yellow]WARNING[/yellow],[blue]INFO[/blue],[green]DEBUG[/green]}",
"console log level",
Expand Down
13 changes: 12 additions & 1 deletion src/guajillo/utils/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,20 @@ async def taskMan(self, async_comms: dict["str", Any]) -> None:
if "tag" in output["return"][0]:
job_type = "master"
jid = output["return"][0]["jid"]
else:
elif "jid" in output["return"][0]:
job_type = "minion"
jid = output["return"][0]["jid"]
else:
job_type = "error"
output_event = {
"meta": {
"output": "json",
"step": "final",
},
"output": output,
}
self.async_comms["events"].append(output_event)
self.async_comms["update"].set()
else:
output_event = {
"meta": {
Expand Down
5 changes: 5 additions & 0 deletions src/guajillo/utils/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ async def boolean(self, event: dict[str, Any]) -> None:
for item in nonreturned:
self.console.print(f"[red]✘ {item}[/red]")

async def string(self, output: str) -> None:
self.console.print(output)

async def taskMan(self, async_comms: dict[str, Any]) -> None:
try:
log.info("Starting output Task Manager")
Expand All @@ -72,6 +75,8 @@ async def taskMan(self, async_comms: dict[str, Any]) -> None:
if event["meta"]["step"] == "final":
self.cstatus.stop()
log.debug(f"calling outputer {event["meta"]["output"]}")
if event["output"]["return"][0] == {}:
await self.string("No known minions matched target")
await getattr(self, event["meta"]["output"])(event["output"])
await asyncio.sleep(0.5)
self.async_comms["one"] = True
Expand Down
31 changes: 7 additions & 24 deletions tests/unit/utils/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ def test_cli_out_fail():
assert excinfo.value.code == 2


def test_cli_out_list():
testing = CliParse()
testing.build_args(["--out-list"])
assert testing.parsed_args.out_list


def test_cli_out_list_default():
testing = CliParse()
testing.build_args(["-c", "/fake/file"])
assert not testing.parsed_args.out_list


def test_cli_output_file():
testing = CliParse()
testing.build_args(["--output-file", "/fake/file"])
Expand All @@ -70,14 +58,14 @@ def test_cli_output_file_fail():

def test_cli_log():
testing = CliParse()
testing.build_args(["-L", "DEBUG"])
testing.build_args(["-l", "DEBUG"])
assert testing.parsed_args.log_level == "DEBUG"


def test_cli_log_fail():
testing = CliParse()
with pytest.raises(SystemExit) as excinfo:
testing.build_args(["-L", "ALL"])
testing.build_args(["-l", "ALL"])
assert excinfo.value.code == 2


Expand All @@ -104,28 +92,23 @@ def test_help():
│ │ │ │ config file to │ │
│ │ │ │ use as login │ │
│ │ │ │ info │ │
│ -o │ --out │ OUTPUT │ currently not │ auto │
│ │ │ │ used, but will │ │
│ │ │ │ let uses force │ │
│ │ │ │ output style │ │
│ │ --out-list │ │ list known │ │
│ │ │ │ output types, │ │
│ │ │ │ currently not │ │
│ │ │ │ implimented │ │
│ -o │ --out │ {json, yaml, │ force output │ auto │
│ │ │ boolean} │ style through a │ │
│ │ │ │ known output │ │
│ │ --output-file │ OUTPUT_FILE │ Not implimented, │ │
│ │ │ │ output file to │ │
│ │ │ │ dump output to │ │
│ -t │ --timeout │ TIMEOUT │ timeout for │ 30 │
│ │ │ │ internal │ │
│ │ │ │ operations, │ │
│ │ │ │ loops to fetch │ │
│ -L │ --log │ {CRITICAL,ERRO… │ console log │ WARNING │
│ -l │ --log │ {CRITICAL,ERRO… │ console log │ WARNING │
│ │ │ │ level │ │
└───────┴───────────────┴─────────────────┴──────────────────┴─────────────────┘
Copyright© 2024 Thomas Phipps
"""
assert capture.get() == expected
with pytest.raises(SystemExit) as excinfo:
with pytest.raises(SystemExit):
testing.build_args(["-h"])

0 comments on commit 1abd9a4

Please sign in to comment.