← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] ~andersson123/autopkgtest-cloud:filter-amqp-read-creds-from-rabbitmq-cred into autopkgtest-cloud:master

 

Tim Andersson has proposed merging ~andersson123/autopkgtest-cloud:filter-amqp-read-creds-from-rabbitmq-cred into autopkgtest-cloud:master.

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

For more details, see:
https://code.launchpad.net/~andersson123/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/462698
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~andersson123/autopkgtest-cloud:filter-amqp-read-creds-from-rabbitmq-cred into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/filter-amqp b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/filter-amqp
index 5cd3b0d..cd825c8 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/filter-amqp
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/filter-amqp
@@ -5,6 +5,7 @@ import logging
 import optparse  # pylint: disable=deprecated-module
 import re
 import time
+import configparser
 import urllib.parse
 
 import amqplib.client_0_8 as amqp
@@ -49,7 +50,7 @@ def filter_amqp(options, host, queue_name, regex):
 
 def main():
     parser = optparse.OptionParser(
-        usage="usage: %prog [options] amqp://user:pass@host queue_name regex"
+        usage="usage: %prog [options] queue_name regex"
     )
     parser.add_option(
         "-n",
@@ -75,6 +76,11 @@ def main():
             "When using this option, the provided regex will be ignored."
         ),
     )
+    cp = configparser.ConfigParser()
+    with open("/home/ubuntu/rabbitmq.cred", "r") as f:
+        cp.read_string("[rabbit]\n" + f.read())
+    creds = f"amqp://{cp['rabbit']['RABBIT_USER']}:{cp['rabbit']['RABBIT_PASSWORD']}@{cp['rabbit']['RABBIT_HOST']}"
+
 
     opts, args = parser.parse_args()
 
@@ -83,12 +89,12 @@ def main():
         format="%(asctime)s - %(message)s",
     )
 
-    if len(args) != 3:
-        parser.error("Need to specify host, queue and regex")
+    if len(args) != 2:
+        parser.error("Need to specify queue name and regex")
 
     deletion_count_history = []
     while True:
-        num_deleted = filter_amqp(opts, args[0], args[1], args[2])
+        num_deleted = filter_amqp(opts, creds, args[0], args[1])
         deletion_count_history.append(num_deleted)
         if opts.dry_run:
             break

References