canonical-ubuntu-qa team mailing list archive
-
canonical-ubuntu-qa team
-
Mailing list archive
-
Message #03988
[Merge] ~hyask/autopkgtest-cloud:skia/fix_cache_amqp into autopkgtest-cloud:master
Skia has proposed merging ~hyask/autopkgtest-cloud:skia/fix_cache_amqp 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/465573
Make `cache-amqp` run no matter which unit is the leader.
--
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/fix_cache_amqp into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/cache-amqp b/charms/focal/autopkgtest-web/webcontrol/cache-amqp
index 9461ea2..da1f109 100755
--- a/charms/focal/autopkgtest-web/webcontrol/cache-amqp
+++ b/charms/focal/autopkgtest-web/webcontrol/cache-amqp
@@ -9,7 +9,6 @@ import sys
import tempfile
import time
import urllib.parse
-import urllib.request
import amqplib.client_0_8 as amqp
from amqplib.client_0_8.exceptions import AMQPChannelException
@@ -17,6 +16,8 @@ from helpers.utils import get_autopkgtest_cloud_conf
AMQP_CONTEXTS = ["ubuntu", "huge", "ppa", "upstream"]
+logger = logging.getLogger()
+
class AutopkgtestQueueContents:
def __init__(self, amqp_uri, database, refresh_semaphores=False):
@@ -248,7 +249,6 @@ if __name__ == "__main__":
cp = get_autopkgtest_cloud_conf()
- logger = logging.getLogger()
formatter = logging.Formatter(
"%(asctime)s: %(message)s", "%Y-%m-%d %H:%M:%S"
)
@@ -272,51 +272,10 @@ if __name__ == "__main__":
except KeyError:
print("No database found", file=sys.stderr)
sys.exit(1)
- try:
- webpage = cp["web"]["ExternalURL"].replace("/results", "")
- except KeyError:
- print("No external url found!")
- sys.exit(1)
- try:
- cookies = cp["web"]["cookies"]
- except KeyError:
- print("No cookies in config!")
- sys.exit(1)
- queue_contents = {}
- # We only actually want to interact with the rabbitmq queue if
- # we're the leader - otherwise these two cache-amqp processes
- # make the queue size go crazy in the KPI
- if os.path.isfile("/run/autopkgtest-web-is-leader"):
- # Get queue details from rabbitmq directly
- aq = AutopkgtestQueueContents(
- amqp_uri, database, args.refresh_semaphores
- )
- queue_contents = aq.get_queue_contents()
- else:
- # We get queues.json from autopkgtest.ubuntu.com, see if it's
- # the same as the version on disk. If it's not, then this webworker
- # (the non leader one) has acquired queues.json from the leader.
- # If they're the same we've queried ourselves for queues.json
- # and we increment the SRVNAME cookie to query the other
- # webworker (the leader)
- queued_local = {}
- if os.path.isfile(args.output):
- with open(args.output, "r") as f:
- queued_local = json.load(f)
- for srvname_cookie in cookies.split(" "):
- try:
- req = urllib.request.Request(webpage + "/queued.json")
- req.add_header("Cookie", "SRVNAME=" + srvname_cookie)
- queue_contents = json.loads(urllib.request.urlopen(req).read())
- if queue_contents != queued_local:
- # we break the loop as we need to write queues.json
- break
- except urllib.error.HTTPError as _:
- # Internal server error means we're requesting queues.json
- # from the web worker this is currently being run on, so
- # we go to next loop iteration to try other cookie
- continue
+ # Get queue details from rabbitmq directly
+ aq = AutopkgtestQueueContents(amqp_uri, database, args.refresh_semaphores)
+ queue_contents = aq.get_queue_contents()
with tempfile.NamedTemporaryFile(
mode="w", dir=os.path.dirname(args.output), delete=False