Skip to content

Commit e5cc1dd

Browse files
committed
add tests and e2e
1 parent 04fd2dd commit e5cc1dd

File tree

7 files changed

+3016
-10
lines changed

7 files changed

+3016
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def load_arguments(self, _):
893893

894894
with self.argument_context('aks scale', resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters') as c:
895895
c.argument('nodepool_name', validator=validate_nodepool_name, help='Node pool name, up to 12 alphanumeric characters.')
896-
896+
897897
# managed namespace
898898
with self.argument_context("aks namespace") as c:
899899
c.argument("cluster_name", help="The cluster name.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def load_command_table(self, _):
154154
g.custom_command('add', 'aks_maintenanceconfiguration_add')
155155
g.custom_command('update', 'aks_maintenanceconfiguration_update')
156156
g.custom_command('delete', 'aks_maintenanceconfiguration_delete')
157-
157+
158158
# AKS managed namespace commands
159159
with self.command_group(
160160
"aks namespace",

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def aks_namespace_add(
512512
existedNamespace = None
513513
try:
514514
existedNamespace = client.get(resource_group_name, cluster_name, name)
515-
except ResourceNotFoundError:
515+
except ResourceNotFoundErrorAzCore:
516516
pass
517517

518518
if existedNamespace:
@@ -555,7 +555,7 @@ def aks_namespace_update(
555555
):
556556
try:
557557
existedNamespace = client.get(resource_group_name, cluster_name, name)
558-
except ResourceNotFoundError:
558+
except ResourceNotFoundErrorAzCore:
559559
raise ClientRequestError(
560560
f"Namespace '{name}' doesn't exist."
561561
"Please use 'aks namespace list' to get current list of managed namespaces"
@@ -565,12 +565,12 @@ def aks_namespace_update(
565565
# DO NOT MOVE: get all the original parameters and save them as a dictionary
566566
raw_parameters = locals()
567567
headers = extract_comma_separated_string(
568-
aks_custom_headers,
569-
enable_strip=True,
570-
extract_kv=True,
571-
default_value={},
572-
allow_appending_values_to_same_key=True,
573-
)
568+
aks_custom_headers,
569+
enable_strip=True,
570+
extract_kv=True,
571+
default_value={},
572+
allow_appending_values_to_same_key=True,
573+
)
574574
return aks_managed_namespace_update(cmd, client, raw_parameters, headers, existedNamespace, no_wait)
575575

576576

src/azure-cli/azure/cli/command_modules/acs/tests/latest/recordings/test_aks_managed_namespace.yaml

Lines changed: 2564 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,6 +6557,114 @@ def test_aks_nodepool_stop_and_start(self, resource_group, resource_group_locati
65576557
self.cmd(
65586558
'aks delete -g {resource_group} -n {name} --yes --no-wait', checks=[self.is_empty()])
65596559

6560+
@AllowLargeResponse()
6561+
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
6562+
def test_aks_managed_namespace(self, resource_group, resource_group_location):
6563+
# reset the count so that in replay mode the random names will start with 0
6564+
self.test_resources_count = 0
6565+
# kwargs for string formatting
6566+
resource_name = self.create_random_name('cliakstest', 16)
6567+
6568+
self.kwargs.update({
6569+
'resource_group': resource_group,
6570+
'resource_name': resource_name,
6571+
'namespace_name': 'namespace01',
6572+
'location': resource_group_location,
6573+
'resource_type': 'Microsoft.ContainerService/ManagedClusters',
6574+
'ssh_key_value': self.generate_ssh_keys(),
6575+
})
6576+
6577+
create_cmd = (
6578+
"aks create --resource-group={resource_group} --name={resource_name} --location={location} "
6579+
"--enable-aad --aad-admin-group-object-ids 00000000-0000-0000-0000-000000000001 "
6580+
"--ssh-key-value={ssh_key_value}"
6581+
)
6582+
6583+
self.cmd(create_cmd, checks=[
6584+
self.check('provisioningState', 'Succeeded'),
6585+
])
6586+
6587+
create_namespace_cmd = (
6588+
"aks namespace add --resource-group={resource_group} --cluster-name={resource_name} --name={namespace_name} "
6589+
"--cpu-request 500m --cpu-limit 800m --memory-request 1Gi --memory-limit 2Gi"
6590+
)
6591+
6592+
self.cmd(create_namespace_cmd, checks=[
6593+
self.check('properties.provisioningState', 'Succeeded'),
6594+
])
6595+
6596+
show_namespace_cmd = (
6597+
"aks namespace show --resource-group={resource_group} --cluster-name={resource_name} --name={namespace_name}"
6598+
)
6599+
6600+
self.cmd(show_namespace_cmd, checks=[
6601+
self.check('properties.adoptionPolicy', 'Never'),
6602+
self.check('properties.deletePolicy', 'Keep'),
6603+
self.check('properties.defaultNetworkPolicy.ingress', 'AllowSameNamespace'),
6604+
self.check('properties.defaultNetworkPolicy.egress', 'AllowAll'),
6605+
],
6606+
)
6607+
6608+
list_namespace_full_cmd = (
6609+
"aks namespace list --resource-group={resource_group} --cluster-name={resource_name} -o json"
6610+
)
6611+
6612+
namespace_list = self.cmd(list_namespace_full_cmd).get_output_in_json()
6613+
assert len(namespace_list) > 0
6614+
6615+
list_namespace_with_resource_group_cmd = (
6616+
"aks namespace list --resource-group={resource_group} -o json"
6617+
)
6618+
6619+
namespace_list = self.cmd(list_namespace_with_resource_group_cmd).get_output_in_json()
6620+
assert len(namespace_list) > 0
6621+
6622+
list_namespace_subscription_level_cmd = (
6623+
"aks namespace list -o json"
6624+
)
6625+
6626+
namespace_list = self.cmd(list_namespace_subscription_level_cmd).get_output_in_json()
6627+
assert len(namespace_list) > 0
6628+
6629+
fd, temp_path = tempfile.mkstemp()
6630+
self.kwargs.update({"file": temp_path})
6631+
try:
6632+
self.cmd(
6633+
'aks namespace get-credentials --resource-group={resource_group} --cluster-name={resource_name} --name={namespace_name} --file "{file}"'
6634+
)
6635+
self.assertGreater(os.path.getsize(temp_path), 0)
6636+
finally:
6637+
os.close(fd)
6638+
os.remove(temp_path)
6639+
6640+
update_namespace_cmd = (
6641+
"aks namespace update --resource-group={resource_group} --cluster-name={resource_name} --name={namespace_name} "
6642+
"--cpu-request 700m --cpu-limit 800m --memory-request 3Gi --memory-limit 5Gi --labels x=y"
6643+
)
6644+
6645+
self.cmd(update_namespace_cmd, checks=[
6646+
self.check('properties.provisioningState', 'Succeeded'),
6647+
self.check('properties.defaultResourceQuota.cpuRequest', '700m'),
6648+
self.check('properties.defaultResourceQuota.memoryRequest', '3Gi'),
6649+
self.check('properties.defaultResourceQuota.memoryLimit', '5Gi'),
6650+
])
6651+
6652+
delete_namespace_cmd = (
6653+
"aks namespace delete --resource-group={resource_group} --cluster-name={resource_name} --name={namespace_name}"
6654+
)
6655+
6656+
self.cmd(
6657+
delete_namespace_cmd,
6658+
checks=[self.is_empty()],
6659+
)
6660+
6661+
time.sleep(2*60)
6662+
6663+
self.cmd(
6664+
"aks delete -g {resource_group} -n {resource_name} --yes --no-wait",
6665+
checks=[self.is_empty()],
6666+
)
6667+
65606668
@live_only() # live only due to workspace is not mocked correctly and role assignment is not mocked
65616669
@AllowLargeResponse()
65626670
@AKSCustomResourceGroupPreparer(

0 commit comments

Comments
 (0)