Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ac4f829
feat(crud-machine): add scenario terraform inputs
karenychen May 5, 2026
e74cb69
feat(crud-machine): add machine data classes
karenychen May 5, 2026
33226c8
feat(crud-machine): add result handler with nested payload
karenychen May 5, 2026
5ebed58
fix(crud-machine): delegate to save_info_to_file and isolate write er…
karenychen May 5, 2026
2fc85c0
feat(crud-machine): add AKSMachineClient composing AKSClient
karenychen May 6, 2026
f5c83a5
fix(crud-machine): drop AKSMachineClient.cluster_name and load_kubeco…
karenychen May 6, 2026
5cd6956
feat(crud-machine): port create_machine_agentpool
karenychen May 6, 2026
bac2e3b
fix(crud-machine): add docstrings and failure-branch tests to create_…
karenychen May 6, 2026
5f0689c
feat(crud-machine): port machine readiness percentile wait
karenychen May 6, 2026
4fb3bfb
fix(crud-machine): harden machine readiness wait against transient fa…
karenychen May 6, 2026
99df955
feat(crud-machine): port scale_machine non-batch path
karenychen May 6, 2026
da9ff1f
fix(crud-machine): bounded retry on missing provisioningState and bat…
karenychen May 6, 2026
350f74d
feat(crud-machine): port scale_machine batch path
karenychen May 6, 2026
aeef5db
fix(crud-machine): tighten batch path docstring and test assertion
karenychen May 6, 2026
db7a461
feat(crud-machine): add MachineManager orchestrator
karenychen May 6, 2026
0e18207
fix(crud-machine): early-return when create fails and validate cluste…
karenychen May 6, 2026
0af4304
feat(crud-machine): add CLI entrypoint
karenychen May 6, 2026
0743f19
fix(crud-machine): harden CLI input validation and exception handling
karenychen May 6, 2026
5e51d53
feat(crud-machine): aggregator with golden-file parity gate
karenychen May 6, 2026
4d15268
fix(crud-machine): handle malformed payloads and drop unused cloud arg
karenychen May 6, 2026
c116367
chore(crud-machine): satisfy pylint and coverage gates
karenychen May 6, 2026
914370e
fix(crud-machine): use k8s_client attribute name to match AKSClient
karenychen May 6, 2026
436f752
fix(crud-machine): drop dead SystemExit branch and unused arg, streng…
karenychen May 6, 2026
69acbe4
feat(crud-machine): add machine engine step templates
karenychen May 6, 2026
d4dce4a
feat(crud-machine): add topology step templates
karenychen May 6, 2026
cb38e4d
feat(crud-machine): add production pipeline (Autoscale Benchmark)
karenychen May 6, 2026
b39bd35
test(crud-machine): stage in new-pipeline-test for E2E validation [ph…
karenychen May 6, 2026
c1967fb
fix(crud-machine): align topology params with dispatcher contract
karenychen May 6, 2026
23e46cd
fix(crud-machine): type engine numeric params as string for matrix vars
karenychen May 6, 2026
f18b098
fix(crud-machine): set default_node_pool vm_size to allowed SKU
karenychen May 6, 2026
0d82ea0
fix(crud-machine): use 2025-04-02-preview API version for machines su…
karenychen May 6, 2026
398f5b1
fix(crud-machine): drop tags from machine PUT body and bump to 2025-0…
karenychen May 6, 2026
75f14a9
fix(crud-machine): F1 propagate scale_machine_count to create + F2 wa…
karenychen May 6, 2026
ecbf0fb
test(crud-machine): add medium + large staging stages [phase-a]
karenychen May 6, 2026
896a8c1
fix(crud-machine): G1 token cache + G2 BatchPutMachine header pattern
karenychen May 6, 2026
7b198ec
fix(crud-machine): align machine naming with ado + scale large stage …
karenychen May 7, 2026
95b4756
fix(crud-machine): I1 separate readiness-wait-timeout from request.ti…
karenychen May 7, 2026
742c234
fix(crud-machine): J1 use ado verbatim BatchPutMachine envelope shape
karenychen May 7, 2026
8443a1f
test(crud-machine): large stage 4 workers x 50 machines per batch [ph…
karenychen May 7, 2026
5c3cc79
test(crud-machine): parameterize region in staging pipeline [phase-a]
karenychen May 8, 2026
0091857
fix(crud-machine): drop per-machine ARM poll, single agentpool check,…
karenychen May 11, 2026
154a5d3
feat(crud-machine): add ado-parity logging for command_execution_time…
karenychen May 12, 2026
2ff7b24
feat(crud-machine): add P70/P100 percentiles and ado-parity nested re…
karenychen May 12, 2026
2514700
refactor(crud-machine): align with gh-telescope CRUD framework
karenychen May 14, 2026
2eb8f36
chore(crud-machine): self-audit cleanup of redundant pylint disables
karenychen May 14, 2026
ab00a66
chore(crud-machine): drop ENV_* override defense + adopt f-string log…
karenychen May 21, 2026
c0f8216
reconcile(crud-machine): adopt origin/main batch contract from #1185
karenychen May 21, 2026
1fadc90
fix(crud-machine): size Session HTTPAdapter pool for worker fan-out
karenychen May 21, 2026
f8c14c4
fix(crud-machine): gate node readiness on P99 not P100
karenychen May 21, 2026
ebc745e
Merge remote-tracking branch 'origin/main' into feat/k8s-cluster-crud…
karenychen May 27, 2026
4ba684e
feat(crud-machine): use az cli for non-batch machine creates
karenychen May 27, 2026
4affdd3
ci: wire new pipeline test to machine crud scenario
karenychen May 27, 2026
d1af072
ci: add larger machine crud test cases
karenychen May 27, 2026
99523b7
ci: align machine crud stage names
karenychen May 27, 2026
a0642b5
ci: align machine crud scale stages
karenychen May 28, 2026
6213852
ci: expand machine crud overlay pod cidr
karenychen May 28, 2026
9c4d3c8
ci: include node counts in machine crud stage names
karenychen May 28, 2026
a6515f1
fix(machine): cap batch machine request size
karenychen May 28, 2026
f326bf4
ci: include region and count in machine matrix names
karenychen May 28, 2026
4d2cc9f
fix(machine): upload successful machine count
karenychen May 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 115 additions & 64 deletions modules/python/clients/aks_machine_client.py

Large diffs are not rendered by default.

213 changes: 163 additions & 50 deletions modules/python/tests/test_aks_machine_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
the right keys
- failure path raises (so the OperationContext records ``success=False``)

This revision adds tests for both scale paths (non-batch individual PUTs and
the BatchPutMachine-headered chunked path) plus the batch-path helpers
This revision adds tests for both scale paths (non-batch individual CLI calls
and the BatchPutMachine-headered chunked path) plus the batch-path helpers
``_scale_machine_batch``, ``_create_batch_machines``, and
``_make_batch_request``.
"""
Expand Down Expand Up @@ -85,34 +85,34 @@ def tearDown(self):

@mock.patch.object(AKSMachineClient, "_wait_for_agentpool_provisioning",
return_value=True)
@mock.patch.object(AKSMachineClient, "make_request")
def test_create_machine_agentpool_success(self, mock_make_request, _mock_wait):
"""PUT 200 + Succeeded poll -> returns; metadata enriched."""
mock_resp = mock.MagicMock()
mock_resp.status_code = 200
mock_make_request.return_value = mock_resp
@mock.patch.object(AKSMachineClient, "_run_az_cli_command")
def test_create_machine_agentpool_success(self, mock_run_cli, _mock_wait):
"""CLI command accepted + Succeeded poll -> returns; metadata enriched."""

self.client.create_machine_agentpool(
agentpool_name="apool", vm_size="Standard_D2_v3"
)

mock_make_request.assert_called_once()
call_args = mock_make_request.call_args
self.assertEqual(call_args.args[0], "PUT")
self.assertEqual(call_args.kwargs["data"], {"properties": {"mode": "Machines"}})
mock_run_cli.assert_called_once()
command = mock_run_cli.call_args.args[0]
self.assertEqual(command[:4], ["az", "aks", "nodepool", "add"])
self.assertIn("--mode", command)
self.assertIn("Machines", command)
self.assertIn("--node-vm-size", command)
self.assertIn("Standard_D2_v3", command)
self.assertIn("--node-count", command)
self.assertIn("0", command)
self.assertIn("--no-wait", command)
metadata_keys = {
call.args[0] for call in self.mock_operation.add_metadata.call_args_list
}
self.assertIn("agentpool_info", metadata_keys)
self.assertIn("cluster_info", metadata_keys)

@mock.patch.object(AKSMachineClient, "make_request")
def test_create_machine_agentpool_put_failure_raises(self, mock_make_request):
"""PUT non-2xx -> RuntimeError propagates out of with-block."""
mock_resp = mock.MagicMock()
mock_resp.status_code = 500
mock_resp.text = "boom"
mock_make_request.return_value = mock_resp
@mock.patch.object(AKSMachineClient, "_run_az_cli_command",
side_effect=RuntimeError("boom"))
def test_create_machine_agentpool_cli_failure_raises(self, _mock_run_cli):
"""CLI failure -> RuntimeError propagates out of with-block."""

with self.assertRaises(RuntimeError):
self.client.create_machine_agentpool(
Expand All @@ -121,14 +121,11 @@ def test_create_machine_agentpool_put_failure_raises(self, mock_make_request):

@mock.patch.object(AKSMachineClient, "_wait_for_agentpool_provisioning",
return_value=False)
@mock.patch.object(AKSMachineClient, "make_request")
@mock.patch.object(AKSMachineClient, "_run_az_cli_command")
def test_create_machine_agentpool_provisioning_timeout_raises(
self, mock_make_request, _mock_wait
self, _mock_run_cli, _mock_wait
):
"""PUT OK but provisioning never reaches Succeeded -> RuntimeError."""
mock_resp = mock.MagicMock()
mock_resp.status_code = 200
mock_make_request.return_value = mock_resp
"""CLI succeeds but provisioning never reaches Succeeded -> RuntimeError."""

with self.assertRaises(RuntimeError):
self.client.create_machine_agentpool(
Expand Down Expand Up @@ -184,6 +181,7 @@ def test_scale_machine_non_batch_success(
call.args[0] for call in self.mock_operation.add_metadata.call_args_list
}
self.assertIn("successful_machines", metadata_keys)
self.mock_operation.add_metadata.assert_any_call("successful_machines", 2)
self.assertIn("percentile_node_readiness_times", metadata_keys)
self.assertIn("node_readiness_time", metadata_keys)
self.assertIn("cluster_info", metadata_keys)
Expand All @@ -195,12 +193,12 @@ def test_scale_machine_non_batch_success(
def test_scale_machine_partial_landing_raises(
self, mock_create, mock_wait_ap, mock_wait_ready
):
"""Non-batch path: if fewer machines land than requested,
"""Non-batch path: if fewer machine CLI commands succeed than requested,
scale_machine raises RuntimeError BEFORE waiting on agentpool
provisioning or node readiness -- otherwise the recorded percentile
envelope and node_readiness_time describe a smaller target than
requested."""
# Two PUTs requested, first lands, second fails.
# Two machine adds requested, first lands, second fails.
mock_create.side_effect = [True, False]
self.mock_k8s.get_ready_nodes.return_value = []

Expand All @@ -216,12 +214,14 @@ def test_scale_machine_partial_landing_raises(
# have been reached.
mock_wait_ap.assert_not_called()
mock_wait_ready.assert_not_called()
# successful_machines metadata IS recorded so operators can see which
# PUTs landed; downstream readiness/cluster_info metadata is not.
# Machine names are intentionally not uploaded; only the successful count
# is recorded. Downstream readiness/cluster_info metadata is not recorded
# on partial landing.
metadata_keys = {
call.args[0] for call in self.mock_operation.add_metadata.call_args_list
}
self.assertIn("successful_machines", metadata_keys)
self.mock_operation.add_metadata.assert_any_call("successful_machines", 1)
self.assertNotIn("percentile_node_readiness_times", metadata_keys)
self.assertNotIn("node_readiness_time", metadata_keys)
self.assertNotIn("cluster_info", metadata_keys)
Expand Down Expand Up @@ -257,6 +257,47 @@ def test_scale_machine_passes_baseline_count_to_readiness(
self.assertEqual(mock_wait_ready.call_args.kwargs["baseline_count"], 3)
self.assertEqual(mock_wait_ready.call_args.kwargs["expected_count"], 1)

def test_scale_machine_consumes_timeout_budgets(self):
"""scale_machine forwards the caller's timeout budgets to dispatch and waits."""
names = ["scale2-machine-1", "scale2-machine-2"]
readiness_envelope = {
f"P{p}": {
"target_nodes": 2,
"elapsed_time_seconds": 10.0,
"percentage": p,
"success": True,
}
for p in (50, 70, 90, 99, 100)
}
with mock.patch.object(
AKSMachineClient,
"_scale_machine_individually",
return_value=names,
) as mock_individual, mock.patch.object(
AKSMachineClient,
"_wait_for_agentpool_provisioning",
return_value=True,
) as mock_wait_ap, mock.patch.object(
AKSMachineClient,
"_wait_for_machine_node_readiness",
return_value=readiness_envelope,
) as mock_wait_ready:
self.mock_k8s.get_ready_nodes.return_value = []

self.client.scale_machine(
agentpool_name="apool",
vm_size="Standard_D2_v3",
scale_machine_count=2,
timeout=900,
readiness_wait_timeout=900,
)

request = mock_individual.call_args.args[0]
self.assertEqual(request.timeout, 900)
self.assertEqual(request.readiness_wait_timeout, 900)
self.assertEqual(mock_wait_ap.call_args.args[1], 900)
self.assertEqual(mock_wait_ready.call_args.kwargs["timeout"], 900)

def test_scale_machine_batch_path_dispatches_to_batch(self):
"""The use_batch_api=True branch calls _scale_machine_batch (not _individually)
and records command_execution_time in operation metadata."""
Expand Down Expand Up @@ -300,39 +341,37 @@ def test_scale_machine_batch_path_dispatches_to_batch(self):

# ---- _create_single_machine ----

@mock.patch.object(AKSMachineClient, "make_request")
def test_create_single_machine_2xx_returns_true(self, mock_make_request):
"""Any 200/201/202 response counts as a successful PUT."""
@mock.patch.object(AKSMachineClient, "_run_az_cli_command")
def test_create_single_machine_cli_success_returns_true(self, mock_run_cli):
"""A zero-exit Azure CLI command counts as a successful machine add."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
)
for code in (200, 201, 202):
with self.subTest(status=code):
mock_resp = mock.MagicMock()
mock_resp.status_code = code
mock_make_request.return_value = mock_resp
self.assertTrue(
self.client._create_single_machine("m1", request)
)

@mock.patch.object(AKSMachineClient, "make_request")
def test_create_single_machine_non_2xx_returns_false(self, mock_make_request):
"""Non-2xx responses are logged and return False (never raise)."""
self.assertTrue(self.client._create_single_machine("m1", request))
mock_run_cli.assert_called_once()
command = mock_run_cli.call_args.args[0]
self.assertEqual(command[:4], ["az", "aks", "machine", "add"])
self.assertIn("--machine-name", command)
self.assertIn("m1", command)
self.assertIn("--vm-size", command)
self.assertIn("Standard_D2_v3", command)
self.assertIn("--no-wait", command)

@mock.patch.object(AKSMachineClient, "_run_az_cli_command",
side_effect=RuntimeError("boom"))
def test_create_single_machine_cli_failure_returns_false(self, _mock_run_cli):
"""CLI failures are logged and return False (never raise)."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
)
mock_resp = mock.MagicMock()
mock_resp.status_code = 500
mock_resp.text = "boom"
mock_make_request.return_value = mock_resp
self.assertFalse(self.client._create_single_machine("m1", request))

# ---- _wait_for_machine_node_readiness ----
Expand Down Expand Up @@ -512,7 +551,7 @@ def test_wait_readiness_no_k8s_client_short_circuits(self):
# ---- _scale_machine_batch ----

def test_scale_machine_batch_partitions_and_aggregates(self):
"""Names sharded across machine_workers; all successful slices aggregated."""
"""Names sharded across workers; all successful slices aggregated."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
Expand All @@ -529,8 +568,11 @@ def test_scale_machine_batch_partitions_and_aggregates(self):
) as mock_create_batch:
successful = self.client._scale_machine_batch(request, names)
self.assertEqual(set(successful), set(names))
# 2 workers, each handling per_worker = 4 // 2 = 2 names
self.assertEqual(mock_create_batch.call_count, 2)
chunk_lengths = [
len(call.args[1]) for call in mock_create_batch.call_args_list
]
self.assertEqual(sorted(chunk_lengths), [2, 2])

def test_scale_machine_batch_per_worker_failure_isolated(self):
"""One worker raising does not poison the other worker's success list."""
Expand Down Expand Up @@ -571,6 +613,60 @@ def test_scale_machine_batch_rejects_non_exact_multiple(self):
with self.assertRaises(ValueError):
self.client._scale_machine_batch(request, names)

def test_scale_machine_batch_rejects_non_positive_workers(self):
"""machine_workers must be positive."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
machine_workers=0,
)
with self.assertRaises(ValueError):
self.client._scale_machine_batch(request, ["m-1"])

def test_scale_machine_batch_rejects_calculated_batch_over_limit(self):
"""Fail fast before ARM when calculated per-worker batch size exceeds 50."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
machine_workers=10,
)
names = [f"m-{i}" for i in range(1, 1001)]
with mock.patch.object(
AKSMachineClient, "_create_batch_machines"
) as mock_create_batch:
with self.assertRaisesRegex(ValueError, "calculated batch size"):
self.client._scale_machine_batch(request, names)
mock_create_batch.assert_not_called()

def test_scale_machine_batch_allows_calculated_batch_at_limit(self):
"""A calculated per-worker batch size of exactly 50 is allowed."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
machine_workers=20,
)
names = [f"m-{i}" for i in range(1, 1001)]
with mock.patch.object(
AKSMachineClient,
"_create_batch_machines",
side_effect=lambda req, chunk, worker_id: list(chunk),
) as mock_create_batch:
successful = self.client._scale_machine_batch(request, names)
self.assertEqual(set(successful), set(names))
self.assertEqual(mock_create_batch.call_count, 20)
self.assertTrue(
all(len(call.args[1]) == 50 for call in mock_create_batch.call_args_list)
)

# ---- _create_batch_machines ----

def test_create_batch_machines_empty_chunk_returns_empty(self):
Expand Down Expand Up @@ -626,6 +722,23 @@ def test_create_batch_machines_header_shape(self):
[{"machineName": "m-2"}, {"machineName": "m-3"}],
)

def test_create_batch_machines_rejects_oversized_chunk(self):
"""BatchPutMachine rejects more than 50 machines per request client-side."""
request = SimpleNamespace(
agentpool_name="apool",
cluster_name="fake-cluster",
resource_group="fake-rg",
vm_size="Standard_D2_v3",
timeout=60,
)
names = [f"m-{i}" for i in range(1, 52)]
with mock.patch.object(
AKSMachineClient, "_make_batch_request"
) as mock_make_batch:
with self.assertRaises(ValueError):
self.client._create_batch_machines(request, names, chunk_idx=0)
mock_make_batch.assert_not_called()

# ---- _make_batch_request ----

def test_make_batch_request_2xx_returns(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
trigger: none

schedules:
- cron: "0 12 * * *"
displayName: "Daily 12:00 UTC"
branches:
include:
- main
always: true

variables:
SCENARIO_TYPE: perf-eval
SCENARIO_NAME: k8s-cluster-crud-machine # matches ado-telescope: feeds Kusto table k8s_cluster_crud_machine_main
USE_LATEST_GA_K8S_VERSION: true

stages:
- stage: azure_canadacentral_small_machine_pool
dependsOn: []
jobs:
- template: /jobs/competitive-test.yml
parameters:
cloud: azure
regions:
- canadacentral
topology: k8s-cluster-crud-machine
engine: machine
matrix:
small_machine_pool:
vm_size: Standard_D2_v3
pool_name: smallpool1
scale_machine_count: 1
machine_workers: 1
use_batch_api: "false"
step_time_out: 600
max_parallel: 1
timeout_in_minutes: 180
credential_type: service_connection
ssh_key_enabled: false
Loading
Loading