Merge ~hyask/autopkgtest-cloud:skia/default_push-amqp_dry-run into autopkgtest-cloud:master

Proposed by Skia
Status: Merged
Merged at revision: b34ab8837141407cd2d3c4a518ac3232e7c076a4
Proposed branch: ~hyask/autopkgtest-cloud:skia/default_push-amqp_dry-run
Merge into: autopkgtest-cloud:master
Diff against target: 113 lines (+47/-26)
2 files modified
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp (+15/-9)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp (+32/-17)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+464132@code.launchpad.net

Description of the change

Improvements on pull/push-amqp scripts.

To post a comment you must log in.
Revision history for this message
Tim Andersson (andersson123) wrote :

LGTM! Sorry I started this work but then laterally got sidetracked with a couple meetings. Thanks for doing it.

review: Approve
Revision history for this message
Skia (hyask) wrote :

No problem, thanks :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
2index e3a57d6..cdda67a 100755
3--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
4+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
5@@ -11,15 +11,21 @@ import amqplib.client_0_8 as amqp
6 def parse_args():
7 # pylint: disable=line-too-long
8 parser = argparse.ArgumentParser(
9- description="""Pulls all messages from specified amqp queue. If the --remove arg is passed, it will also remove messages from the queue. You can specify to filter with a regex, also.
10- Moving all tests from one queue to another:
11- ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
12- Moving all tests matching a regex from one queue to another:
13- ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
14- To requeue all items in a queue with all-proposed:
15- ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue
16- You can alter the queue messages however you please, but be careful :)
17- """
18+ description="""Pulls all messages from a specified amqp queue.
19+
20+If the --remove arg is passed, it will also remove messages from the queue, otherwise, it will just print them. You can also specify to filter with a regex.
21+
22+Here are some common use-cases.
23+
24+Moving all tests from one queue to another:
25+ ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
26+Moving all tests matching a regex from one queue to another:
27+ ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
28+To requeue all items in a queue with all-proposed:
29+ ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue
30+You can alter the queue messages however you please, but be careful :)
31+""",
32+ formatter_class=argparse.RawTextHelpFormatter,
33 )
34 parser.add_argument(
35 "--regex",
36diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
37index dff98a7..5e5ae94 100755
38--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
39+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
40@@ -10,17 +10,27 @@ import amqplib.client_0_8 as amqp
41
42 def parse_args():
43 parser = argparse.ArgumentParser(
44- description="""Pushes a message to a specified queue. Usage:
45- ./push-amqp --queue-name $queue --message "mymessage\n{"key1": "value1"}"
46- If --message isn't passed, the script reads from stdin, like so:
47- ./script-that-produces-messages | ./push-amqp --queue-name $queue
48- Likely to be used with pull-amqp, in this same directory."""
49+ description="""Pushes a message to a specified queue.
50+
51+This script is in dry-run by default, meaning it will only print the message, unless you pass --no-dry-run.
52+
53+Here are some common use-cases:
54+
55+Queue a single message:
56+ ./push-amqp --queue-name $queue --message "b'mymessage\\n{\\"key1\\": \\"value1\\"}'"
57+If --message isn't passed, the script reads from stdin, like so:
58+ ./script-that-produces-messages | ./push-amqp --queue-name $queue
59+
60+This script is more likely to be used with pull-amqp, in this same directory.
61+See `pull-amqp -h` for some example of common pipelines.
62+""",
63+ formatter_class=argparse.RawTextHelpFormatter,
64 )
65 parser.add_argument("--queue-name", "-q", required=True, help="Queue name")
66 parser.add_argument(
67- "--dry-run",
68+ "--no-dry-run",
69 action="store_true",
70- help="Don't actually push item to queue, just print what would be pushed.",
71+ help="Actually push item to queue, instead of just printing what would be pushed.",
72 )
73 parser.add_argument(
74 "--verbose",
75@@ -35,16 +45,7 @@ def parse_args():
76
77 def main():
78 args = parse_args()
79- if args.dry_run:
80-
81- def push(message, queue_name, _):
82- if args.verbose:
83- print(
84- f"Would submit `{message}` to {queue_name}",
85- file=sys.stderr,
86- )
87-
88- else:
89+ if args.no_dry_run:
90
91 def push(message, queue_name, ch):
92 if args.verbose:
93@@ -53,6 +54,20 @@ def main():
94 amqp.Message(message, delivery_mode=2), routing_key=queue_name
95 )
96
97+ else:
98+ print(
99+ "Running is dry-run mode. "
100+ "Pass --no-dry-run if you really wish to push the messages to the queue.",
101+ file=sys.stderr,
102+ )
103+
104+ def push(message, queue_name, _):
105+ if args.verbose:
106+ print(
107+ f"Would submit `{message}` to {queue_name}",
108+ file=sys.stderr,
109+ )
110+
111 cp = configparser.ConfigParser()
112 with open("/home/ubuntu/rabbitmq.cred", "r") as f:
113 cp.read_string("[rabbit]\n" + f.read().replace('"', ""))

Subscribers

People subscribed via source and target branches