Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AKS] az aks create/az aks nodepool add: Emit error message when using --asg-ids alone without --allowed-host-ports #30768

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,27 @@ def validate_allowed_host_ports(namespace):


def validate_application_security_groups(namespace):
is_nodepool_operation = False
if hasattr((namespace), "nodepool_asg_ids"):
is_nodepool_operation = True
asg_ids = namespace.nodepool_asg_ids
host_ports = namespace.nodepool_allowed_host_ports
else:
asg_ids = namespace.asg_ids
host_ports = namespace.allowed_host_ports

if not asg_ids:
return

if not host_ports:
if is_nodepool_operation:
raise ArgumentUsageError(
'--nodepool-asg-ids must be used with --nodepool-allowed-host-ports'
)
raise ArgumentUsageError(
'--asg-ids must be used with --allowed-host-ports'
)

from azure.mgmt.core.tools import is_valid_resource_id
for asg in asg_ids:
if not is_valid_resource_id(asg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,17 +725,60 @@ def test_invalid_application_security_groups(self):
namespace = SimpleNamespace(
**{
"asg_ids": "invalid",
"allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
}
)
with self.assertRaises(InvalidArgumentValueError):
validators.validate_application_security_groups(
namespace
)

def test_application_security_groups_without_allowed_host_ports(self):
asg_ids = [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
]
namespace = SimpleNamespace(
**{
"asg_ids": asg_ids,
"allowed_host_ports": [],
}
)
with self.assertRaises(ArgumentUsageError):
validators.validate_application_security_groups(
namespace
)

def test_nodepool_application_security_groups_without_allowed_host_ports(self):
asg_ids = [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
]
namespace = SimpleNamespace(
**{
"nodepool_asg_ids": asg_ids,
"nodepool_allowed_host_ports": [],
}
)
with self.assertRaises(ArgumentUsageError):
validators.validate_application_security_groups(
namespace
)

def test_empty_application_security_groups(self):
namespace = SimpleNamespace(
**{
"asg_ids": "",
"allowed_host_ports": [],
}
)
validators.validate_application_security_groups(
namespace
)

def test_empty_nodepool_application_security_groups(self):
namespace = SimpleNamespace(
**{
"nodepool_asg_ids": "",
"nodepool_allowed_host_ports": [],
}
)
validators.validate_application_security_groups(
Expand All @@ -750,6 +793,22 @@ def test_multiple_application_security_groups(self):
namespace = SimpleNamespace(
**{
"asg_ids": asg_ids,
"allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
}
)
validators.validate_application_security_groups(
namespace
)

def test_multiple_nodepool_application_security_groups(self):
asg_ids = [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg2/providers/Microsoft.Network/applicationSecurityGroups/asg2",
]
namespace = SimpleNamespace(
**{
"nodepool_asg_ids": asg_ids,
"nodepool_allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
}
)
validators.validate_application_security_groups(
Expand Down