← Back to team overview

canonical-ubuntu-qa team mailing list archive

[Merge] autopkgtest-cloud:put-semaphore-in-queue into autopkgtest-cloud:master

 

Brian Murray has proposed merging autopkgtest-cloud:put-semaphore-in-queue into autopkgtest-cloud:master.

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

For more details, see:
https://code.launchpad.net/~ubuntu-release/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/450071

I'd encountered an issue where the semaphore queues were created but had no messages in them. This prevented cache-amqp from running at all as it could never obtain a lock on the reading the actual queues.

While I used this to resolve the issue I don't think this is the best fix.
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of autopkgtest-cloud:put-semaphore-in-queue into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/cache-amqp b/charms/focal/autopkgtest-web/webcontrol/cache-amqp
index b626171..512b495 100755
--- a/charms/focal/autopkgtest-web/webcontrol/cache-amqp
+++ b/charms/focal/autopkgtest-web/webcontrol/cache-amqp
@@ -57,6 +57,8 @@ class AutopkgtestQueueContents:
                             self.amqp_channel.queue_declare(
                                 queue_name, durable=True
                             )
+                            # add a single message to the queue so only one run
+                            # of cache-amqp can read the actual queue contents
                             self.amqp_channel.basic_publish(
                                 amqp.Message(f"{queue_name}", delivery_mode=2),
                                 routing_key=queue_name,
@@ -67,6 +69,14 @@ class AutopkgtestQueueContents:
                                 "We are not the leader, and there is no semaphore queue yet, we can't do anything - exiting."
                             )
                             sys.exit(0)
+                    # if the queue is empty basic_get will return None
+                    if os.path.exists(
+                        "/run/autopkgtest-web-is-leader"
+                    ) and not self.amqp_channel.basic_get(queue_name):
+                        self.amqp_channel.basic_publish(
+                            amqp.Message(f"{queue_name}", delivery_mode=2),
+                            routing_key=queue_name,
+                        )
 
     @property
     def release_arches(self):

References