Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def get_auth_management_client(cli_ctx, scope=None, **_):
matched = re.match('/subscriptions/(?P<subscription>[^/]*)/', scope)
if matched:
subscription_id = matched.groupdict()['subscription']
else:
raise CLIError("{} does not contain subscription Id.".format(scope))
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_AUTHORIZATION, subscription_id=subscription_id)


Expand Down
4 changes: 2 additions & 2 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
validate_nodepool_name, validate_vm_set_type, validate_load_balancer_sku,
validate_load_balancer_outbound_ips, validate_load_balancer_outbound_ip_prefixes,
validate_taints, validate_priority, validate_eviction_policy, validate_acr, validate_user,
validate_load_balancer_outbound_ports, validate_load_balancer_idle_timeout)
validate_load_balancer_outbound_ports, validate_load_balancer_idle_timeout, validate_vnet_subnet_id)
from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING


Expand Down Expand Up @@ -76,7 +76,7 @@ def load_arguments(self, _):
c.argument('no_ssh_key', options_list=['--no-ssh-key', '-x'])
c.argument('pod_cidr')
c.argument('service_cidr')
c.argument('vnet_subnet_id')
c.argument('vnet_subnet_id', type=str, validator=validate_vnet_subnet_id)

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.

Does it has a help message?

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.

yes it does, it keeps same as it was to be in _help.py

        - name: --vnet-subnet-id
          type: string
          short-summary: The ID of a subnet in an existing VNet into which to deploy the cluster.

c.argument('workspace_resource_id')
c.argument('skip_subnet_role_assignment', action='store_true')
c.argument('enable_cluster_autoscaler', action='store_true')
Expand Down
9 changes: 9 additions & 0 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ def validate_user(namespace):
raise CLIError("--user can only be clusterUser or clusterMonitoringUser")


def validate_vnet_subnet_id(namespace):
if namespace.vnet_subnet_id is not None:
if namespace.vnet_subnet_id == '':
return
from msrestazure.tools import is_valid_resource_id
if not is_valid_resource_id(namespace.vnet_subnet_id):
raise CLIError("--vnet-subnet-id is not a valid Azure resource ID.")


def validate_load_balancer_outbound_ports(namespace):
"""validate load balancer profile outbound allocated ports"""
if namespace.load_balancer_outbound_ports is not None:
Expand Down
1 change: 0 additions & 1 deletion src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,6 @@ def aks_kollect(cmd, # pylint: disable=too-many-statements,too-many-locals
if not prompt_y_n('Do you want to see analysis results now?', default="n"):
print(f"You can run 'az aks kanalyze -g {resource_group_name} -n {name}' "
f"anytime to check the analysis results.")
return
else:
display_diagnostics_report(temp_kubeconfig_path)

Expand Down
31 changes: 31 additions & 0 deletions src/aks-preview/azext_aks_preview/tests/latest/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,34 @@ def test_IPv6(self):
class Namespace:
def __init__(self, api_server_authorized_ip_ranges):
self.api_server_authorized_ip_ranges = api_server_authorized_ip_ranges


class TestVNetSubnetId(unittest.TestCase):
def test_invalid_vnet_subnet_id(self):
invalid_vnet_subnet_id = "dummy subnet id"
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
err = ("--vnet-subnet-id is not a valid Azure resource ID.")

with self.assertRaises(CLIError) as cm:
validators.validate_vnet_subnet_id(namespace)
self.assertEqual(str(cm.exception), err)

def test_valid_vnet_subnet_id(self):
invalid_vnet_subnet_id = "/subscriptions/testid/resourceGroups/MockedResourceGroup/providers/Microsoft.Network/virtualNetworks/MockedNetworkId/subnets/MockedSubNetId"
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
validators.validate_vnet_subnet_id(namespace)

def test_none_vnet_subnet_id(self):
invalid_vnet_subnet_id = None
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
validators.validate_vnet_subnet_id(namespace)

def test_empty_vnet_subnet_id(self):
invalid_vnet_subnet_id = ""
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
validators.validate_vnet_subnet_id(namespace)


class VnetSubnetIdNamespace:
def __init__(self, vnet_subnet_id):
self.vnet_subnet_id = vnet_subnet_id