From 000050b151fa661f0a73e1b86c5c058c3041834f Mon Sep 17 00:00:00 2001 From: Lindley Vieira Date: Tue, 24 Sep 2024 10:13:26 -0300 Subject: [PATCH] Check before deleting old deployments When the Software Agent starts, it lists all ostree deployments, and deletes all with an index greater than 2 in the list. But it does not check the list size before trying to delete, leading in some cases to an out-of-range exception. This commit adds a check before iterating through the list to delete. Test-Plan: PASS: Deploy an ISO and check no out-of-range error after unlock PASS: Deploy an RR patch and see only two deployments after unlock Story: 2010676 Task: 51069 Change-Id: I2555597fac30677bcb36629a2ea66feb52a40de1 Signed-off-by: Lindley Vieira --- software/software/ostree_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/software/software/ostree_utils.py b/software/software/ostree_utils.py index dca40849..26b88897 100644 --- a/software/software/ostree_utils.py +++ b/software/software/ostree_utils.py @@ -445,8 +445,12 @@ def delete_older_deployments(): # We want to delete all deployments except the two mentioned above. # This means we will undeploy all deployments starting from the # 2nd index of deployment_id_list + deploys_amount = len(deployment_id_list) + if deploys_amount <= 2: + LOG.info("No older deployments to delete") + return - for index in reversed(range(2, len(deployment_id_list))): + for index in reversed(range(2, deploys_amount)): try: cmd = "ostree admin undeploy %s" % index output = subprocess.run(cmd, shell=True, check=True, capture_output=True)