Merge ~r00ta/maas:lp-2058273-sync-bootresources-deterministic-3.5 into maas:3.5

Proposed by Jacopo Rota
Status: Merged
Approved by: Jacopo Rota
Approved revision: 6c002aa673f81a8d3e479eaeae23617bbb6107f1
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~r00ta/maas:lp-2058273-sync-bootresources-deterministic-3.5
Merge into: maas:3.5
Diff against target: 44 lines (+8/-3)
1 file modified
src/maasserver/workflow/bootresource.py (+8/-3)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Jacopo Rota Approve
Review via email: mp+462671@code.launchpad.net

Commit message

fix: lp-2058273. Make the sync-bootresources workflow deterministic

(cherry-picked from 37bb6c453c7f0971f551affb939ee6368996c10d)

To post a comment you must log in.
Revision history for this message
Jacopo Rota (r00ta) wrote :

self approving backport

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp-2058273-sync-bootresources-deterministic-3.5 lp:~r00ta/maas/+git/maas into -b 3.5 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 6c002aa673f81a8d3e479eaeae23617bbb6107f1

review: Approve

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/workflow/bootresource.py b/src/maasserver/workflow/bootresource.py
index 4097f7e..513908d 100644
--- a/src/maasserver/workflow/bootresource.py
+++ b/src/maasserver/workflow/bootresource.py
@@ -2,14 +2,13 @@ import asyncio
2from asyncio import gather2from asyncio import gather
3from dataclasses import dataclass, field, replace3from dataclasses import dataclass, field, replace
4from datetime import datetime, timedelta4from datetime import datetime, timedelta
5import random
6from typing import Coroutine, Sequence5from typing import Coroutine, Sequence
76
8from aiohttp.client_exceptions import ClientError7from aiohttp.client_exceptions import ClientError
9from temporalio import activity, workflow8from temporalio import activity, workflow
10from temporalio.common import RetryPolicy, WorkflowIDReusePolicy9from temporalio.common import RetryPolicy, WorkflowIDReusePolicy
11from temporalio.exceptions import ApplicationError10from temporalio.exceptions import ApplicationError
12from temporalio.workflow import ActivityCancellationType11from temporalio.workflow import ActivityCancellationType, random
1312
14from maasserver.utils.bootresource import (13from maasserver.utils.bootresource import (
15 get_bootresource_store_path,14 get_bootresource_store_path,
@@ -282,6 +281,9 @@ class SyncBootResourcesWorkflow:
282 workflow.logger.info("Sync complete")281 workflow.logger.info("Sync complete")
283 return282 return
284283
284 # Use a random generator from the temporal sdk in order to keep the workflow deterministic.
285 random_generator = random()
286
285 sync_jobs: list[Coroutine] = []287 sync_jobs: list[Coroutine] = []
286 for res in input.resources:288 for res in input.resources:
287 missing: set[str] = set()289 missing: set[str] = set()
@@ -298,9 +300,12 @@ class SyncBootResourcesWorkflow:
298 for reg in sources300 for reg in sources
299 for ep in endpoints[reg]301 for ep in endpoints[reg]
300 ]302 ]
303 # In order to balance the workload on the regions we randomize the order of the source_list.
301 new_res = replace(304 new_res = replace(
302 res,305 res,
303 source_list=random.sample(eps, min(len(eps), MAX_SOURCES)),306 source_list=random_generator.sample(
307 eps, min(len(eps), MAX_SOURCES)
308 ),
304 )309 )
305 for region in missing:310 for region in missing:
306 sync_jobs.append(_schedule(new_res, region))311 sync_jobs.append(_schedule(new_res, region))

Subscribers

People subscribed via source and target branches