Skip to content

Commit 8340039

Browse files
committed
Emit error message when using --asg-ids alone without --allowed-host-ports
1 parent cf83ff0 commit 8340039

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,26 @@ def validate_allowed_host_ports(namespace):
783783

784784

785785
def validate_application_security_groups(namespace):
786+
is_nodepool_operation = False
786787
if hasattr((namespace), "nodepool_asg_ids"):
788+
is_nodepool_operation = True
787789
asg_ids = namespace.nodepool_asg_ids
790+
host_ports = namespace.nodepool_allowed_host_ports
788791
else:
789792
asg_ids = namespace.asg_ids
793+
host_ports = namespace.allowed_host_ports
790794
if not asg_ids:
791795
return
792796

797+
if not host_ports:
798+
if is_nodepool_operation:
799+
raise ArgumentUsageError(
800+
'--nodepool-asg-ids must be used with --nodepool-allowed-host-ports'
801+
)
802+
raise ArgumentUsageError(
803+
'--asg-ids must be used with --allowed-host-ports'
804+
)
805+
793806
from azure.mgmt.core.tools import is_valid_resource_id
794807
for asg in asg_ids:
795808
if not is_valid_resource_id(asg):

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

+59
Original file line numberDiff line numberDiff line change
@@ -725,17 +725,60 @@ def test_invalid_application_security_groups(self):
725725
namespace = SimpleNamespace(
726726
**{
727727
"asg_ids": "invalid",
728+
"allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
728729
}
729730
)
730731
with self.assertRaises(InvalidArgumentValueError):
731732
validators.validate_application_security_groups(
732733
namespace
733734
)
734735

736+
def test_application_security_groups_without_allowed_host_ports(self):
737+
asg_ids = [
738+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
739+
]
740+
namespace = SimpleNamespace(
741+
**{
742+
"asg_ids": asg_ids,
743+
"allowed_host_ports": [],
744+
}
745+
)
746+
with self.assertRaises(ArgumentUsageError):
747+
validators.validate_application_security_groups(
748+
namespace
749+
)
750+
751+
def test_nodepool_application_security_groups_without_allowed_host_ports(self):
752+
asg_ids = [
753+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
754+
]
755+
namespace = SimpleNamespace(
756+
**{
757+
"nodepool_asg_ids": asg_ids,
758+
"nodepool_allowed_host_ports": [],
759+
}
760+
)
761+
with self.assertRaises(ArgumentUsageError):
762+
validators.validate_application_security_groups(
763+
namespace
764+
)
765+
735766
def test_empty_application_security_groups(self):
736767
namespace = SimpleNamespace(
737768
**{
738769
"asg_ids": "",
770+
"allowed_host_ports": [],
771+
}
772+
)
773+
validators.validate_application_security_groups(
774+
namespace
775+
)
776+
777+
def test_empty_nodepool_application_security_groups(self):
778+
namespace = SimpleNamespace(
779+
**{
780+
"nodepool_asg_ids": "",
781+
"nodepool_allowed_host_ports": [],
739782
}
740783
)
741784
validators.validate_application_security_groups(
@@ -750,6 +793,22 @@ def test_multiple_application_security_groups(self):
750793
namespace = SimpleNamespace(
751794
**{
752795
"asg_ids": asg_ids,
796+
"allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
797+
}
798+
)
799+
validators.validate_application_security_groups(
800+
namespace
801+
)
802+
803+
def test_multiple_nodepool_application_security_groups(self):
804+
asg_ids = [
805+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Network/applicationSecurityGroups/asg1",
806+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg2/providers/Microsoft.Network/applicationSecurityGroups/asg2",
807+
]
808+
namespace = SimpleNamespace(
809+
**{
810+
"nodepool_asg_ids": asg_ids,
811+
"nodepool_allowed_host_ports": ["80/tcp", "443/tcp", "8080-8090/tcp", "53/udp"],
753812
}
754813
)
755814
validators.validate_application_security_groups(

0 commit comments

Comments
 (0)