Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion scripts/aks-flex-config
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def cluster_metadata(args: argparse.Namespace) -> dict[str, str]:
"resource_id": run(["az", "aks", "show", *aks, "--query", "id", "-o", "tsv"], capture=True),
"location": run(["az", "aks", "show", *aks, "--query", "location", "-o", "tsv"], capture=True),
"kubernetes_version": run(
["az", "aks", "show", *aks, "--query", "currentKubernetesVersion || kubernetesVersion", "-o", "tsv"],
["az", "aks", "show", *aks, "--query", "currentKubernetesVersion", "-o", "tsv"],
capture=True,
),
Comment on lines 138 to 141
"dns_service_ip": run(
Expand Down
51 changes: 51 additions & 0 deletions scripts/aks_flex_config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e283564: removed scripts/aks_flex_config_test.py.

import importlib.machinery
import importlib.util
from pathlib import Path
import unittest
from unittest import mock


SCRIPT_PATH = Path(__file__).with_name("aks-flex-config")


def load_module():
loader = importlib.machinery.SourceFileLoader("aks_flex_config", str(SCRIPT_PATH))
spec = importlib.util.spec_from_loader(loader.name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module


class ClusterMetadataTest(unittest.TestCase):
def test_cluster_metadata_uses_current_kubernetes_version(self):
module = load_module()
args = argparse.Namespace(resource_group="rg", cluster_name="cluster", subscription="sub")
responses = iter(["sub", "tenant", "resource-id", "westus2", "1.34.8", "10.0.0.10"])

with mock.patch.object(module, "run", side_effect=lambda *unused_args, **unused_kwargs: next(responses)) as run:
metadata = module.cluster_metadata(args)

self.assertEqual(metadata["kubernetes_version"], "1.34.8")
run.assert_any_call(
[
"az",
"aks",
"show",
"--resource-group",
"rg",
"--name",
"cluster",
"--subscription",
"sub",
"--query",
"currentKubernetesVersion",
"-o",
"tsv",
],
capture=True,
)


if __name__ == "__main__":
unittest.main()
Loading