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
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
index e3a57d6..cdda67a 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/pull-amqp
@@ -11,15 +11,21 @@ import amqplib.client_0_8 as amqp
11def parse_args():11def parse_args():
12 # pylint: disable=line-too-long12 # pylint: disable=line-too-long
13 parser = argparse.ArgumentParser(13 parser = argparse.ArgumentParser(
14 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.14 description="""Pulls all messages from a specified amqp queue.
15 Moving all tests from one queue to another:15
16 ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue16If 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.
17 Moving all tests matching a regex from one queue to another:17
18 ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue18Here are some common use-cases.
19 To requeue all items in a queue with all-proposed:19
20 ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue20Moving all tests from one queue to another:
21 You can alter the queue messages however you please, but be careful :)21 ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
22 """22Moving all tests matching a regex from one queue to another:
23 ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
24To requeue all items in a queue with all-proposed:
25 ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue
26You can alter the queue messages however you please, but be careful :)
27""",
28 formatter_class=argparse.RawTextHelpFormatter,
23 )29 )
24 parser.add_argument(30 parser.add_argument(
25 "--regex",31 "--regex",
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
index dff98a7..5e5ae94 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/push-amqp
@@ -10,17 +10,27 @@ import amqplib.client_0_8 as amqp
1010
11def parse_args():11def parse_args():
12 parser = argparse.ArgumentParser(12 parser = argparse.ArgumentParser(
13 description="""Pushes a message to a specified queue. Usage:13 description="""Pushes a message to a specified queue.
14 ./push-amqp --queue-name $queue --message "mymessage\n{"key1": "value1"}"14
15 If --message isn't passed, the script reads from stdin, like so:15This script is in dry-run by default, meaning it will only print the message, unless you pass --no-dry-run.
16 ./script-that-produces-messages | ./push-amqp --queue-name $queue16
17 Likely to be used with pull-amqp, in this same directory."""17Here are some common use-cases:
18
19Queue a single message:
20 ./push-amqp --queue-name $queue --message "b'mymessage\\n{\\"key1\\": \\"value1\\"}'"
21If --message isn't passed, the script reads from stdin, like so:
22 ./script-that-produces-messages | ./push-amqp --queue-name $queue
23
24This script is more likely to be used with pull-amqp, in this same directory.
25See `pull-amqp -h` for some example of common pipelines.
26""",
27 formatter_class=argparse.RawTextHelpFormatter,
18 )28 )
19 parser.add_argument("--queue-name", "-q", required=True, help="Queue name")29 parser.add_argument("--queue-name", "-q", required=True, help="Queue name")
20 parser.add_argument(30 parser.add_argument(
21 "--dry-run",31 "--no-dry-run",
22 action="store_true",32 action="store_true",
23 help="Don't actually push item to queue, just print what would be pushed.",33 help="Actually push item to queue, instead of just printing what would be pushed.",
24 )34 )
25 parser.add_argument(35 parser.add_argument(
26 "--verbose",36 "--verbose",
@@ -35,16 +45,7 @@ def parse_args():
3545
36def main():46def main():
37 args = parse_args()47 args = parse_args()
38 if args.dry_run:48 if args.no_dry_run:
39
40 def push(message, queue_name, _):
41 if args.verbose:
42 print(
43 f"Would submit `{message}` to {queue_name}",
44 file=sys.stderr,
45 )
46
47 else:
4849
49 def push(message, queue_name, ch):50 def push(message, queue_name, ch):
50 if args.verbose:51 if args.verbose:
@@ -53,6 +54,20 @@ def main():
53 amqp.Message(message, delivery_mode=2), routing_key=queue_name54 amqp.Message(message, delivery_mode=2), routing_key=queue_name
54 )55 )
5556
57 else:
58 print(
59 "Running is dry-run mode. "
60 "Pass --no-dry-run if you really wish to push the messages to the queue.",
61 file=sys.stderr,
62 )
63
64 def push(message, queue_name, _):
65 if args.verbose:
66 print(
67 f"Would submit `{message}` to {queue_name}",
68 file=sys.stderr,
69 )
70
56 cp = configparser.ConfigParser()71 cp = configparser.ConfigParser()
57 with open("/home/ubuntu/rabbitmq.cred", "r") as f:72 with open("/home/ubuntu/rabbitmq.cred", "r") as f:
58 cp.read_string("[rabbit]\n" + f.read().replace('"', ""))73 cp.read_string("[rabbit]\n" + f.read().replace('"', ""))

Subscribers

People subscribed via source and target branches