Skip to content

Commit 8ee2e7c

Browse files
committed
Added kata tests.
1 parent 91a22a9 commit 8ee2e7c

File tree

7 files changed

+99
-88
lines changed

7 files changed

+99
-88
lines changed

src/azure-cli/azure/cli/command_modules/acs/_consts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@
250250
# node provisioning default pools
251251
CONST_NODE_PROVISIONING_DEFAULT_POOLS_NONE = "None"
252252
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO = "Auto"
253+
253254
# consts for workloadruntime
254-
CONST_KATA_VM_ISOLATION = "KataVmIsolation"
255+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION = "KataVmIsolation"
255256

256257

257258
# consts for decorator pattern

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,6 @@
709709
text: az aks create -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto
710710
- name: Create a kubernetes cluster with auto node provisioning and no default pools.
711711
text: az aks create -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto --node-provisioning-default-pools None
712-
- name: Create a kubernetes cluster with KataMshvVmIsolation enabled.
713-
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataMshvVmIsolation --node-count 1
714712
- name: Create a kubernetes cluster with KataVmIsolation enabled.
715713
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataVmIsolation --node-count 1
716714
"""
@@ -1845,8 +1843,6 @@
18451843
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku Ubuntu --pod-subnet-id /subscriptions/SubID/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet --pod-ip-allocation-mode StaticBlock
18461844
- name: create a nodepool of type VirtualMachines
18471845
text: az aks nodepool add -g MyResourceGroup -n MyNodePool --cluster-name MyMC --vm-set-type VirtualMachines --vm-sizes "VMSize1,VMSize2" --node-count 3
1848-
- name: Create a kubernetes cluster with KataMshvVmIsolation enabled.
1849-
text: az aks nodepool add -g MyResourceGroup -n MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataMshvVmIsolation --node-count 1
18501846
- name: Create a kubernetes cluster with KataVmIsolation enabled.
18511847
text: az aks nodepool add -g MyResourceGroup -n MyManagedCluster --os-sku AzureLinux --vm-size Standard_D4s_v3 --workload-runtime KataVmIsolation --node-count 1
18521848
"""

src/azure-cli/azure/cli/command_modules/acs/_params.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
CONST_NODE_PROVISIONING_MODE_MANUAL,
6666
CONST_NODE_PROVISIONING_MODE_AUTO,
6767
CONST_NODE_PROVISIONING_DEFAULT_POOLS_NONE,
68-
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO)
68+
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO,
69+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION)
6970
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
7071
CONST_ACSTOR_ALL,
7172
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
@@ -329,7 +330,7 @@
329330
]
330331

331332
workload_runtime_types = [
332-
CONST_KATA_VM_ISOLATION,
333+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
333334
]
334335

335336

src/azure-cli/azure/cli/command_modules/acs/agentpool_decorator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,22 @@ def get_gateway_prefix_size(self) -> Union[int, None]:
16851685
"""
16861686
return self.raw_param.get('gateway_prefix_size')
16871687

1688+
def get_workload_runtime(self) -> Union[str, None]:
1689+
"""Obtain the value of workload_runtime, default value is None.
1690+
1691+
:return: string or None
1692+
"""
1693+
# read the original value passed by the command
1694+
workload_runtime = self.raw_param.get("workload_runtime", None)
1695+
# try to read the property value corresponding to the parameter from the `mc` object
1696+
if self.agentpool and self.agentpool.workload_runtime is not None:
1697+
workload_runtime = self.agentpool.workload_runtime
1698+
1699+
# this parameter does not need dynamic completion
1700+
# this parameter does not need validation
1701+
return workload_runtime
1702+
1703+
16881704

16891705
class AKSAgentPoolAddDecorator:
16901706
def __init__(

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_agentpool_decorator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
CONST_VIRTUAL_MACHINES,
2727
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
2828
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
29+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
2930
AgentPoolDecoratorMode,
3031
DecoratorEarlyExitException,
3132
DecoratorMode,
@@ -1749,6 +1750,21 @@ def get_if_none_match(self):
17491750
)
17501751
self.assertEqual(ctx_3.get_if_none_match(), "")
17511752

1753+
def common_get_enable_kata_image(self):
1754+
# testing new kata naming convention
1755+
ctx_1 = AKSAgentPoolContext(
1756+
self.cmd,
1757+
AKSAgentPoolParamDict({
1758+
"workload_runtime": CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
1759+
}),
1760+
self.models,
1761+
DecoratorMode.CREATE,
1762+
self.agentpool_decorator_mode,
1763+
)
1764+
agentpool_1 = self.create_initialized_agentpool_instance(workload_runtime=CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION)
1765+
ctx_1.attach_agentpool(agentpool_1)
1766+
self.assertEqual(ctx_1.get_workload_runtime(), CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION)
1767+
17521768
class AKSAgentPoolContextStandaloneModeTestCase(AKSAgentPoolContextCommonTestCase):
17531769
def setUp(self):
17541770
self.cli_ctx = MockCLI()
@@ -1968,6 +1984,9 @@ def test_get_gpu_driver(self):
19681984
def test_get_gateway_prefix_size(self):
19691985
self.common_get_gateway_prefix_size()
19701986

1987+
def test_common_get_enable_kata_image(self):
1988+
self.common_get_enable_kata_image()
1989+
19711990
class AKSAgentPoolContextManagedClusterModeTestCase(AKSAgentPoolContextCommonTestCase):
19721991
def setUp(self):
19731992
self.cli_ctx = MockCLI()
@@ -2154,6 +2173,9 @@ def test_get_if_match(self):
21542173

21552174
def test_get_if_none_match(self):
21562175
self.get_if_none_match()
2176+
2177+
def test_common_get_enable_kata_image(self):
2178+
self.common_get_enable_kata_image()
21572179

21582180
class AKSAgentPoolAddDecoratorCommonTestCase(unittest.TestCase):
21592181
def _remove_defaults_in_agentpool(self, agentpool):

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py

Lines changed: 56 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from azure.cli.command_modules.acs.tests.latest.data.certs import CUSTOM_CA_TEST_CERT_STR
2929
from azure.cli.command_modules.acs.tests.latest.recording_processors import \
3030
KeyReplacer
31+
32+
from azure.cli.command_modules.acs._consts import CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION
3133
from azure.cli.command_modules.acs.tests.latest.utils import get_test_data_file_path
3234
from azure.cli.core.azclierror import ClientRequestError, CLIInternalError
3335
from azure.cli.testsdk import ScenarioTest, live_only
@@ -2729,124 +2731,98 @@ def test_aks_create_update_fips_flow(self, resource_group, resource_group_locati
27292731
checks=[self.is_empty()],
27302732
)
27312733

2732-
# TODO(mheberling): Add kata tests
27332734
@AllowLargeResponse()
27342735
@AKSCustomResourceGroupPreparer(
2735-
random_name_length=17, name_prefix="clitest", location="westcentralus"
2736+
random_name_length=17, name_prefix="clitest", location="westus2"
27362737
)
2737-
def test_aks_create_kata_flow(self, resource_group, resource_group_location):
2738+
def test_aks_cluster_kata(
2739+
self, resource_group, resource_group_location
2740+
):
27382741
# reset the count so in replay mode the random names will start with 0
27392742
self.test_resources_count = 0
2743+
# kwargs for string formatting
27402744
aks_name = self.create_random_name("cliakstest", 16)
2741-
node_pool_name = self.create_random_name("c", 6)
2742-
# node_pool_name_second = self.create_random_name("c", 6)
27432745
self.kwargs.update(
27442746
{
27452747
"resource_group": resource_group,
27462748
"name": aks_name,
27472749
"dns_name_prefix": self.create_random_name("cliaksdns", 16),
27482750
"location": resource_group_location,
27492751
"resource_type": "Microsoft.ContainerService/ManagedClusters",
2750-
"node_pool_name": node_pool_name,
2751-
# "node_pool_name_second": node_pool_name_second,
2752-
# "ssh_key_value": self.generate_ssh_keys(),
2752+
"workload_runtime": CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
2753+
"ssh_key_value": self.generate_ssh_keys(),
27532754
}
27542755
)
27552756

2756-
# 1. create
2757+
# create
27572758
create_cmd = (
27582759
"aks create --resource-group={resource_group} --name={name} --location={location} "
2759-
"--nodepool-name {node_pool_name} --os-sku AzureLinux --node-count 1 --workload-runtime KataVmIsolation "
2760-
"--vm-size Standard_D4s_v3"
2761-
# "--ssh-key-value={ssh_key_value} "
2762-
# '--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview '
2763-
# "--enable-fips-image"
2760+
"--os-sku AzureLinux --workload-runtime {workload_runtime} --node-count 1 "
2761+
"--ssh-key-value={ssh_key_value} --node-vm-size Standard_D4s_v3"
27642762
)
27652763
self.cmd(
27662764
create_cmd,
27672765
checks=[
2766+
self.exists("fqdn"),
2767+
self.exists("nodeResourceGroup"),
27682768
self.check("provisioningState", "Succeeded"),
2769-
self.check("agentPoolProfiles[0].enableFips", True),
2770-
],
2771-
)
2772-
2773-
# verify no flag no change
2774-
self.cmd(
2775-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name} "
2776-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview',
2777-
checks=[
2778-
self.check("provisioningState", "Succeeded"),
2779-
self.check("enableFips", True),
2780-
],
2781-
)
2782-
2783-
# verify same update no change
2784-
self.cmd(
2785-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name} "
2786-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview '
2787-
"--enable-fips-image",
2788-
checks=[
2789-
self.check("provisioningState", "Succeeded"),
2790-
self.check("enableFips", True),
2769+
self.check("agentPoolProfiles[0].workloadRuntime", CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION),
27912770
],
27922771
)
27932772

2794-
# update nodepool1 to disable
2773+
# delete
27952774
self.cmd(
2796-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name} "
2797-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview '
2798-
"--disable-fips-image",
2799-
checks=[
2800-
self.check("provisioningState", "Succeeded"),
2801-
self.check("enableFips", False),
2802-
],
2775+
"aks delete -g {resource_group} -n {name} --yes --no-wait",
2776+
checks=[self.is_empty()],
28032777
)
28042778

2805-
# 2. add nodepool2
2806-
self.cmd(
2807-
"aks nodepool add "
2808-
"--resource-group={resource_group} "
2809-
"--cluster-name={name} "
2810-
"--name={node_pool_name_second} "
2811-
"--os-type Linux "
2812-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview ',
2813-
checks=[
2814-
self.check("provisioningState", "Succeeded"),
2815-
self.check("enableFips", False),
2816-
],
2779+
@AllowLargeResponse()
2780+
@AKSCustomResourceGroupPreparer(
2781+
random_name_length=17, name_prefix="clitest", location="westus2"
2782+
)
2783+
def test_aks_nodepool_add_with_kata(
2784+
self, resource_group, resource_group_location
2785+
):
2786+
# reset the count so in replay mode the random names will start with 0
2787+
self.test_resources_count = 0
2788+
# kwargs for string formatting
2789+
aks_name = self.create_random_name("cliakstest", 16)
2790+
node_pool_name = self.create_random_name('c', 6)
2791+
node_pool_name_second = self.create_random_name('c', 6)
2792+
self.kwargs.update(
2793+
{
2794+
"resource_group": resource_group,
2795+
"name": aks_name,
2796+
"node_pool_name": node_pool_name,
2797+
"node_pool_name_second": node_pool_name_second,
2798+
"location": resource_group_location,
2799+
"resource_type": "Microsoft.ContainerService/ManagedClusters",
2800+
"workload_runtime": CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
2801+
"ssh_key_value": self.generate_ssh_keys(),
2802+
}
28172803
)
28182804

2819-
# verify no flag no change
2820-
self.cmd(
2821-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name_second} "
2822-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview',
2823-
checks=[
2824-
self.check("provisioningState", "Succeeded"),
2825-
self.check("enableFips", False),
2826-
],
2805+
# create
2806+
create_cmd = (
2807+
"aks create --resource-group={resource_group} --name={name} "
2808+
"--nodepool-name {node_pool_name} -c 1 --ssh-key-value={ssh_key_value}"
28272809
)
2810+
self.cmd(create_cmd, checks=[
2811+
self.check('provisioningState', 'Succeeded'),
2812+
])
28282813

2829-
# verify same update no change
2830-
self.cmd(
2831-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name_second} "
2832-
'--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview '
2833-
"--disable-fips-image",
2834-
checks=[
2835-
self.check("provisioningState", "Succeeded"),
2836-
self.check("enableFips", False),
2837-
],
2814+
# nodepool update with kata
2815+
update_cmd = (
2816+
"aks nodepool add --cluster-name={name} --resource-group={resource_group} "
2817+
"--name={node_pool_name_second} --os-sku AzureLinux "
2818+
"--workload-runtime KataVmIsolation --node-vm-size Standard_D4s_v3"
28382819
)
28392820

2840-
# update nodepool2 to enable
28412821
self.cmd(
2842-
"aks nodepool update --resource-group={resource_group} --cluster-name={name} --name={node_pool_name_second} "
2843-
"--nodepool-name {node_pool_name} --os-sku AzureLinux --node-count 1 --workload-runtime KataVmIsolation "
2844-
"--vm-size Standard_D4s_v3"
2845-
# '--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/MutableFipsPreview '
2846-
# "--enable-fips-image",
2822+
update_cmd,
28472823
checks=[
28482824
self.check("provisioningState", "Succeeded"),
2849-
self.check("enableFips", True),
2825+
self.check("workloadRuntime", "KataVmIsolation"),
28502826
],
28512827
)
28522828

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6291,7 +6291,6 @@ def test_set_up_agentpool_profile(self):
62916291
"enable_encryption_at_host": True,
62926292
"enable_ultra_ssd": True,
62936293
"enable_fips_image": True,
6294-
# TODO(mheberling): Add kata?
62956294
"message_of_the_day": get_test_data_file_path("invalidconfig.json"),
62966295
"kubelet_config": None,
62976296
"linux_os_config": None,

0 commit comments

Comments
 (0)