Skip to content

Commit 9b95f43

Browse files
Support middle wildcards in fault injection patterns
1 parent 6baf038 commit 9b95f43

2 files changed

Lines changed: 15 additions & 39 deletions

File tree

‎acceptance/bundle/dms_fault/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Steps 4–6 run first for the job, then for the pipeline. The fault stays enable
1717
through step 8 and is cleared in `finally`. For `CreateDeployment`, skip the healthy
1818
setup deployment so the fault applies to the first deployment.
1919

20+
Each case registers one fault rule. A version wildcard such as
21+
`POST .../versions/*/complete` covers every version the workflow accesses or creates.
22+
Each `*` stays within one path segment, so a version read fault cannot also match
23+
nested operation endpoints.
24+
2025
Each snapshot records the command invocations and output, including warnings and
2126
deployment-version links, then reports whether the injected endpoint was called.
2227
An unused endpoint records `DMS API called: no`.

‎acceptance/bundle/dms_fault/run.py‎

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,27 @@
2121
REQUESTS = Path(os.environ["OUT_REQUESTS"])
2222
LOG = Path("LOG.commands").resolve()
2323
PATTERNS = {
24-
"complete_version": "POST /api/2.0/bundle/deployments/{id}/versions/{version}/complete",
24+
"complete_version": "POST /api/2.0/bundle/deployments/{id}/versions/*/complete",
2525
"create_deployment": "POST /api/2.0/bundle/deployments",
2626
"create_version": "POST /api/2.0/bundle/deployments/{id}/versions",
2727
"delete_deployment": "DELETE /api/2.0/bundle/deployments/{id}",
2828
"get_deployment": "GET /api/2.0/bundle/deployments/{id}",
29-
"get_operation": "GET /api/2.0/bundle/deployments/{id}/versions/{version}/operations/*",
29+
"get_operation": "GET /api/2.0/bundle/deployments/{id}/versions/*/operations/*",
3030
"get_resource": "GET /api/2.0/bundle/deployments/{id}/resources/*",
31-
"get_version": "GET /api/2.0/bundle/deployments/{id}/versions/{version}",
32-
"heartbeat": "POST /api/2.0/bundle/deployments/{id}/versions/{version}/heartbeat",
31+
"get_version": "GET /api/2.0/bundle/deployments/{id}/versions/*",
32+
"heartbeat": "POST /api/2.0/bundle/deployments/{id}/versions/*/heartbeat",
3333
"list_deployments": "GET /api/2.0/bundle/deployments",
34-
"list_operations": "GET /api/2.0/bundle/deployments/{id}/versions/{version}/operations",
34+
"list_operations": "GET /api/2.0/bundle/deployments/{id}/versions/*/operations",
3535
"list_resources": "GET /api/2.0/bundle/deployments/{id}/resources",
3636
"list_versions": "GET /api/2.0/bundle/deployments/{id}/versions",
3737
"update_deployment": "PATCH /api/2.0/bundle/deployments/{id}",
38-
"update_operation": "PATCH /api/2.0/bundle/deployments/{id}/versions/*",
38+
"update_operation": "PATCH /api/2.0/bundle/deployments/{id}/versions/*/operations/*",
3939
}
40-
ACTIVE = None
41-
REGISTERED = set()
4240
KNOWN_IDS = set()
4341

4442

4543
def run(cwd, *args, expected=0):
4644
visible = args[0] == "bundle"
47-
if visible:
48-
refresh_faults(cwd)
4945
result = subprocess.run(
5046
[CLI, *args],
5147
cwd=cwd,
@@ -70,33 +66,10 @@ def fault(pattern, enabled):
7066
)
7167

7268

73-
def refresh_faults(cwd):
74-
if ACTIVE is None:
75-
return
76-
if "{version}" in ACTIVE:
77-
# Cover existing versions and the next version a command can create.
78-
serial = state(cwd).get("serial", 0)
79-
patterns = [ACTIVE.format(version=version) for version in range(1, serial + 2)]
80-
else:
81-
patterns = [ACTIVE]
82-
for pattern in patterns:
83-
if pattern not in REGISTERED:
84-
fault(pattern, True)
85-
REGISTERED.add(pattern)
86-
87-
88-
def clear_faults():
89-
global ACTIVE
90-
ACTIVE = None
91-
for pattern in REGISTERED:
92-
fault(pattern, False)
93-
REGISTERED.clear()
94-
95-
9669
def hits(pattern):
9770
if not REQUESTS.exists():
9871
return 0
99-
regex = re.escape(pattern).replace(r"\{version\}", r"[^/]+").replace(r"\*", ".*") + "$"
72+
regex = re.escape(pattern).replace(r"\*\*", ".*").replace(r"\*", "[^/]*")
10073
return sum(bool(re.fullmatch(regex, f"{r['method']} {r['path']}")) for r in read_json_many(REQUESTS.read_text()))
10174

10275

@@ -133,7 +106,6 @@ def setup(phase):
133106

134107

135108
def activate(cwd, root):
136-
global ACTIVE
137109
print(f"\n=== {cwd.name}: setup", flush=True)
138110
deployment = None
139111
if API != "create_deployment":
@@ -142,9 +114,8 @@ def activate(cwd, root):
142114
run(cwd, "workspace", "get-status", root + "/state/resources.deployment.json", "-o", "json").stdout
143115
)
144116
deployment = str(node["object_id"])
145-
pattern = PATTERNS[API].format(id=deployment, version="{version}")
146-
ACTIVE = pattern
147-
refresh_faults(cwd)
117+
pattern = PATTERNS[API].format(id=deployment)
118+
fault(pattern, True)
148119
print(f"\n=== {cwd.name}: {API} fault enabled", flush=True)
149120
return pattern
150121

@@ -218,4 +189,4 @@ def assert_destroyed(cwd, root, current):
218189
assert_destroyed(cwd, root, current)
219190
print("\nDMS API called: " + ("yes" if hits(pattern) > previous else "no"), flush=True)
220191
finally:
221-
clear_faults()
192+
fault(pattern, False)

0 commit comments

Comments
 (0)