← Back to team overview

canonical-ubuntu-qa team mailing list archive

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

 

Skia has proposed merging ~hyask/autopkgtest-cloud:skia/default_push-amqp_dry-run into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/464132

Improvements on pull/push-amqp scripts.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/default_push-amqp_dry-run into autopkgtest-cloud:master.
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
 def parse_args():
     # pylint: disable=line-too-long
     parser = argparse.ArgumentParser(
-        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.
-        Moving all tests from one queue to another:
-        ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
-        Moving all tests matching a regex from one queue to another:
-        ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
-        To requeue all items in a queue with all-proposed:
-        ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue
-        You can alter the queue messages however you please, but be careful :)
-        """
+        description="""Pulls all messages from a specified amqp queue.
+
+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.
+
+Here are some common use-cases.
+
+Moving all tests from one queue to another:
+    ./pull-amqp --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
+Moving all tests matching a regex from one queue to another:
+    ./pull-amqp --regex="my-regex" --queue-name $old_queue --remove | ./push-amqp --queue-name $new_queue
+To requeue all items in a queue with all-proposed:
+    ./pull-amqp --queue-name debci-noble-amd64 --remove | sed 's/"triggers":/"all-proposed": "1", "triggers"/' | ./push-amqp --queue-name $new_queue
+You can alter the queue messages however you please, but be careful :)
+""",
+        formatter_class=argparse.RawTextHelpFormatter,
     )
     parser.add_argument(
         "--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
 
 def parse_args():
     parser = argparse.ArgumentParser(
-        description="""Pushes a message to a specified queue. Usage:
-        ./push-amqp --queue-name $queue --message "mymessage\n{"key1": "value1"}"
-        If --message isn't passed, the script reads from stdin, like so:
-        ./script-that-produces-messages | ./push-amqp --queue-name $queue
-        Likely to be used with pull-amqp, in this same directory."""
+        description="""Pushes a message to a specified queue.
+
+This script is in dry-run by default, meaning it will only print the message, unless you pass --no-dry-run.
+
+Here are some common use-cases:
+
+Queue a single message:
+    ./push-amqp --queue-name $queue --message "b'mymessage\\n{\\"key1\\": \\"value1\\"}'"
+If --message isn't passed, the script reads from stdin, like so:
+    ./script-that-produces-messages | ./push-amqp --queue-name $queue
+
+This script is more likely to be used with pull-amqp, in this same directory.
+See `pull-amqp -h` for some example of common pipelines.
+""",
+        formatter_class=argparse.RawTextHelpFormatter,
     )
     parser.add_argument("--queue-name", "-q", required=True, help="Queue name")
     parser.add_argument(
-        "--dry-run",
+        "--no-dry-run",
         action="store_true",
-        help="Don't actually push item to queue, just print what would be pushed.",
+        help="Actually push item to queue, instead of just printing what would be pushed.",
     )
     parser.add_argument(
         "--verbose",
@@ -35,16 +45,7 @@ def parse_args():
 
 def main():
     args = parse_args()
-    if args.dry_run:
-
-        def push(message, queue_name, _):
-            if args.verbose:
-                print(
-                    f"Would submit `{message}` to {queue_name}",
-                    file=sys.stderr,
-                )
-
-    else:
+    if args.no_dry_run:
 
         def push(message, queue_name, ch):
             if args.verbose:
@@ -53,6 +54,20 @@ def main():
                 amqp.Message(message, delivery_mode=2), routing_key=queue_name
             )
 
+    else:
+        print(
+            "Running is dry-run mode. "
+            "Pass --no-dry-run if you really wish to push the messages to the queue.",
+            file=sys.stderr,
+        )
+
+        def push(message, queue_name, _):
+            if args.verbose:
+                print(
+                    f"Would submit `{message}` to {queue_name}",
+                    file=sys.stderr,
+                )
+
     cp = configparser.ConfigParser()
     with open("/home/ubuntu/rabbitmq.cred", "r") as f:
         cp.read_string("[rabbit]\n" + f.read().replace('"', ""))