Match Standby activity wording and preserve live status shapes in fakes
Recognize the documented to Standby activity description while retaining existing entry and exit wording. Cover it with a raw-response regression. Keep permit request bodies separate from fixture-derived status, and bind the real parser before CLI tests mock the AWS constructor. All 233 roll, probe, fault and document tests pass offline.
2 files changed,
+49
−9
scripts/region-group-roll.py+2 −1scripts/region_group_roll_test.py+47 −8
CI cancelled — superseded by a newer push — run details
diff --git a/scripts/region-group-roll.py b/scripts/region-group-roll.py| index 5340e0503..610fa3dc6 100755 |
| --- a/scripts/region-group-roll.py |
| +++ b/scripts/region-group-roll.py |
| @@ -714,8 +714,9 @@ class AWS: |
| result = [] |
| for row in rows: |
| description = row.get("Description", "") |
| + # AWS documents "to Standby"; keep accepting "into Standby" too. |
| kind = "exit" if "out of Standby" in description else ( |
| - "enter" if "into Standby" in description else None) |
| + "enter" if any(s in description for s in ("to Standby", "into Standby")) else None) |
| if re.search(r"\b" + re.escape(a["iid"]) + r"\b", description) and kind: |
| dt = datetime.fromisoformat(row["StartTime"].replace("Z", "+00:00")) |
| result.append(dict(id=row["ActivityId"], iid=a["iid"], time=dt.timestamp(), kind=kind)) |
diff --git a/scripts/region_group_roll_test.py b/scripts/region_group_roll_test.py| index a3d7b67ea..5a22411d1 100644 |
| --- a/scripts/region_group_roll_test.py |
| +++ b/scripts/region_group_roll_test.py |
| @@ -50,6 +50,8 @@ class ValidationError(Exception): |
| class Fake: |
| + parse_response = roll.AWS.request |
| + |
| def __init__(self, config): |
| self.c = config |
| self.now = 1800000000.0 |
| @@ -72,6 +74,7 @@ class Fake: |
| self.continues = self.exits = self.launches = self.abandons = 0 |
| self.activity = [] |
| self.used = set() |
| + self.permit_bodies = {} |
| self.after = None |
| self.launch_receipt = True |
| self.publication_lag = 2 |
| @@ -132,13 +135,15 @@ class Fake: |
| group = result["AutoScalingGroups"][0] |
| group.update(MinSize=self.minimum, DesiredCapacity=self.desired, MaxSize=self.maximum) |
| member = group["Instances"][0] |
| - group["Instances"] = [dict(copy.deepcopy(member), InstanceId=iid, LifecycleState=state) |
| + members = {row["InstanceId"]: row for row in group["Instances"]} |
| + group["Instances"] = [dict(copy.deepcopy(members.get(iid, member)), InstanceId=iid, LifecycleState=state) |
| for iid, state in self.states.items() if state != "Terminated"] |
| return result |
| if verb == "describe-auto-scaling-instances": |
| iid = args[args.index("--instance-ids") + 1] |
| result = self.fixture(verb + ".json") |
| - member = result["AutoScalingInstances"][0] |
| + member = next((r for r in result["AutoScalingInstances"] if r["InstanceId"] == iid), |
| + result["AutoScalingInstances"][0]) |
| result["AutoScalingInstances"] = ([] if iid not in self.states or self.states[iid] == "Terminated" |
| else [dict(member, InstanceId=iid, LifecycleState=self.states[iid])]) |
| return result |
| @@ -173,7 +178,7 @@ class Fake: |
| activity = result["Activities"][0] |
| # Transition states are synthetic; the captured activities are launches. |
| result["Activities"] = [dict(copy.deepcopy(activity), ActivityId=a["id"], |
| - Description="Moving EC2 instance " + ("out of" if a["kind"] == "exit" else "into") + |
| + Description="Moving EC2 instance " + ("out of" if a["kind"] == "exit" else "to") + |
| " Standby: " + a["iid"], StartTime=roll.stamp(a["time"])) for a in self.activity] |
| return result |
| if verb == "get-object": |
| @@ -193,7 +198,7 @@ class Fake: |
| def perform(self, op, a): |
| if op in {"group", "instance", "targets", "online", "hooks", "activities", "edges"}: |
| - return roll.AWS.request(self, op, a) |
| + return self.parse_response(op, a) |
| if op == "minimum": |
| self.minimum = a["value"] |
| self.desired = max(self.desired, self.minimum) |
| @@ -253,23 +258,28 @@ class Fake: |
| assert self.states[IID] == "Standby" and self.tg[IID] == "unused" |
| assert self.desired == self.minimum == 1 and self.maximum == 2 |
| assert (p["transaction"], p["action"]) not in self.used |
| - s["permit"] = dict(p, state="present", accepted=True, consumed=False) |
| + self.permit_bodies[a["iid"]] = copy.deepcopy(p) |
| + s["permit"] = live.status()["permit"] |
| + s["permit"].update({k: p[k] for k in ("transaction", "action", "expires")}, |
| + state="present", accepted=True, consumed=False, rollback_consumed=False) |
| return s |
| if verb == "revoke": |
| - s["permit"] = {"state": "absent"} |
| + s["permit"] = live.status()["permit"] |
| + self.permit_bodies.pop(a["iid"], None) |
| return {} |
| if verb in ("apply", "rollback"): |
| p = s["permit"] |
| assert p["action"] == verb and p["accepted"] and not p["consumed"] |
| assert self.states[IID] == "Standby" |
| self.used.add((p["transaction"], verb)) |
| - s["binary_sha256"] = p["new_sha256"] if verb == "apply" else p["old_sha256"] |
| + body = self.permit_bodies[a["iid"]] |
| + s["binary_sha256"] = body["new_sha256"] if verb == "apply" else body["old_sha256"] |
| s["edge"].update(pid=101 if verb == "apply" else 102, |
| identity=verb + "-process", started_at=roll.stamp(self.now)) |
| self.now += 1 |
| if self.outage: |
| self.admitted = False |
| - s["health"] = dict(state="unhealthy", code=503) |
| + s["health"].update(state="unhealthy", code=503) |
| return {} |
| raise AssertionError((op, a)) |
| @@ -1420,6 +1430,22 @@ class LiveFixtureTests(unittest.TestCase): |
| self.assertNotIn("ActivityStatusCode", row) |
| self.assertEqual(self.parse("activities", "describe-scaling-activities.json", iid=IID), []) |
| + def test_documented_standby_activity_descriptions(self): |
| + for wording, kind in (("to Standby", "enter"), ("into Standby", "enter"), |
| + ("out of Standby", "exit")): |
| + for status in ("InProgress", "PreInService", "Successful"): |
| + with self.subTest(wording=wording, status=status): |
| + raw = live.load("describe-scaling-activities.json") |
| + row = raw["Activities"][0] |
| + row.update(Description="Moving EC2 instance " + wording + ": " + IID, |
| + StatusCode=status) |
| + other = dict(row, Description="Moving EC2 instance " + wording + ": " + PEER) |
| + raw["Activities"] = [row, other, raw["Activities"][1]] |
| + with patch.object(self.adapter, "invoke", return_value=raw): |
| + result = self.adapter.request("activities", dict(iid=IID)) |
| + self.assertEqual(result, [dict(id=row["ActivityId"], iid=IID, |
| + time=1793891898.824, kind=kind)]) |
| + |
| def test_live_edges_and_root_frame(self): |
| for box in (live.BOX, live.PEER_BOX): |
| name = "edges-" + box + ".json" |
| @@ -1442,6 +1468,19 @@ class LiveFixtureTests(unittest.TestCase): |
| observation = operator.readiness(IID) |
| self.assertEqual(observation["status"], status) |
| + def test_fake_status_preserves_live_permit_shape(self): |
| + fake = Fake(self.config) |
| + fake.states[IID], fake.tg[IID] = "Standby", "unused" |
| + fake.minimum = fake.desired = 1 |
| + permit = dict(v=1, transaction="example", action="apply", expires=int(fake.now) + 3600, |
| + old_sha256=OLD, new_sha256=NEW, phase="mutation", allow_rollback=True) |
| + expected = live.status()["permit"] |
| + for verb, args in (("permit", dict(permit=permit)), ("apply", {}), ("revoke", {})): |
| + with self.subTest(verb=verb): |
| + fake.perform("session", dict(iid=IID, verb=verb, **args)) |
| + status = fake.perform("session", dict(iid=IID, verb="status")) |
| + self.assertEqual(list(status["permit"]), list(expected)) |
| + |
| def test_fixtures_contain_no_live_identifiers(self): |
| forbidden = ("640012953448", "carlos-dev", "i-003449ff2ae5b7352", "i-0dd24d205739a40bd", |
| "i-046c7fe43620944bc", "i-05498eada6f0afd23", "g-24eac3e7f9be8cdabc7d", |