diff --git a/src/zones/HISTORY.rst b/src/zones/HISTORY.rst index d8ade94ae25..a14fe2e0890 100644 --- a/src/zones/HISTORY.rst +++ b/src/zones/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +1.0.0b2 +++++++ +* Minor bugfixes to improve command loading + 1.0.0b1 ++++++ * Initial preview release. \ No newline at end of file diff --git a/src/zones/azext_zones/__init__.py b/src/zones/azext_zones/__init__.py index 7fc7b1dbb06..5f759396f4c 100644 --- a/src/zones/azext_zones/__init__.py +++ b/src/zones/azext_zones/__init__.py @@ -4,27 +4,19 @@ # -------------------------------------------------------------------------------------------- -import importlib -from pathlib import Path from azure.cli.core import AzCommandsLoader from azext_zones._help import helps # pylint: disable=unused-import - -# Import all the resource type validator modules dynamically: -validators_dir = Path(__file__).parent / "resource_type_validators" -for file in validators_dir.glob("*.py"): - if file.name != "__init__.py": - module_name = f".resource_type_validators.{file.stem}" - importlib.import_module(module_name, package=__package__) +from ._resourceTypeValidation import load_validators class ZonesCommandsLoader(AzCommandsLoader): - def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType from azext_zones._client_factory import cf_zones zones_custom = CliCommandType( operations_tmpl='azext_zones.custom#{}', client_factory=cf_zones) + load_validators() super(ZonesCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=zones_custom) diff --git a/src/zones/azext_zones/_help.py b/src/zones/azext_zones/_help.py index 82f81a73223..2988d0311dd 100644 --- a/src/zones/azext_zones/_help.py +++ b/src/zones/azext_zones/_help.py @@ -18,7 +18,7 @@ examples: - name: Validate zone redundancy status of all resources in the specified resource group text: |- - az zones validate --resource-groups myProductionRG --omit-dependent + az zones validate --resource-groups myProductionRG - name: Validate zone redundancy status of all resources in the specified resource group, but omit the dependent/child resources text: |- az zones validate --resource-groups myProductionRG --omit-dependent diff --git a/src/zones/azext_zones/_resourceTypeValidation.py b/src/zones/azext_zones/_resourceTypeValidation.py index 1da8408736e..d73bf038eee 100644 --- a/src/zones/azext_zones/_resourceTypeValidation.py +++ b/src/zones/azext_zones/_resourceTypeValidation.py @@ -3,14 +3,20 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +import importlib +from pathlib import Path from abc import ABC, abstractmethod from enum import Enum +from knack.log import get_logger resource_type_validators = {} +__logger = get_logger(__name__) # This is the decorator to register resource type validators: def register_resource_type(resourceType): + __logger.debug("Registering resource type validator for %s", resourceType) + def decorator(cls): resource_type_validators[resourceType] = cls return cls @@ -25,6 +31,32 @@ def getResourceTypeValidator(resourceType): return None +def load_validators(): + # Import all the resource type validator modules dynamically: + validators_dir = Path(__file__).parent / "resource_type_validators" + __logger.debug("Starting resource type validator module import from %s", validators_dir) + + if len(resource_type_validators) > 0: + __logger.debug("Resource type validators already loaded, skipping import.") + return + + try: + if validators_dir.exists(): + for file in validators_dir.glob("*.py"): + if file.name != "__init__.py": + try: + __logger.debug("Importing resource type validator module: %s", file.name) + module_name = f".resource_type_validators.{file.stem}" + importlib.import_module(module_name, package=__package__) + except ImportError as e: + __logger.warning("Failed to import module %s: %s", module_name, str(e)) + else: + __logger.error("Resource type validators directory not found: %s", validators_dir) + + except Exception as e: # pylint: disable=broad-except + __logger.warning("Error scanning for resource type validator modules: %s", str(e)) + + # This is the base class for all resource type validators: class ResourceTypeValidator(ABC): # pylint: disable=too-few-public-methods` @abstractmethod diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_apimanagement.py b/src/zones/azext_zones/tests/latest/test_microsoft_apimanagement.py index 0c74eb7e18e..47b7d0ddea9 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_apimanagement.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_apimanagement.py @@ -6,45 +6,38 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_apimanagement(ScenarioTest): + resource_zr = { + "type": "microsoft.apimanagement/service", + "sku": {"name": "Premium", "capacity": 3}, + "zones": ["1", "2", "3"], + } + + resource_nonzr = { + "type": "microsoft.apimanagement/service", + "sku": {"name": "Premium", "capacity": 1}, + "tags": {}, + "zones": None, + } - resource_zr = \ - { - "type": "microsoft.apimanagement/service", - "sku": { - "name": "Premium", - "capacity": 3 - }, - "zones": [ - "1", - "2", - "3" - ] - } - - resource_nonzr = \ - { - "type": "microsoft.apimanagement/service", - "sku": { - "name": "Premium", - "capacity": 1 - }, - "tags": {}, - "zones": None - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_apimanagement, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -54,4 +47,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_app.py b/src/zones/azext_zones/tests/latest/test_microsoft_app.py index d6353142e6f..bd240b7b0da 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_app.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_app.py @@ -6,38 +6,41 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_app(ScenarioTest): + resource_zr = { + "type": "microsoft.app/managedenvironments", + "resourceGroup": "testResourceGroup", + "properties": { + "zoneRedundant": True, + }, + } + + resource_nonzr = { + "type": "microsoft.app/managedenvironments", + "resourceGroup": "testResourceGroup", + "properties": { + "zoneRedundant": False, + }, + } - resource_zr = \ - { - "type": "microsoft.app/managedenvironments", - "resourceGroup": "testResourceGroup", - "properties": { - "zoneRedundant": True, - }, - } - - resource_nonzr = \ - { - "type": "microsoft.app/managedenvironments", - "resourceGroup": "testResourceGroup", - "properties": { - "zoneRedundant": False, - }, - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_app, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -47,4 +50,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_cache.py b/src/zones/azext_zones/tests/latest/test_microsoft_cache.py index a1fdf170d8a..1460e8fba48 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_cache.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_cache.py @@ -6,36 +6,29 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_cache(ScenarioTest): + resource_zr = {"type": "microsoft.cache/redis", "zones": ["1", "2", "3"]} + + resource_nonzr = {"type": "microsoft.cache/redis", "zones": None} - resource_zr = \ - { - "type": "microsoft.cache/redis", - "zones": [ - "1", - "2", - "3" - ] - } - - resource_nonzr = \ - { - "type": "microsoft.cache/redis", - "zones": None - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_cache, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -45,4 +38,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_compute.py b/src/zones/azext_zones/tests/latest/test_microsoft_compute.py index f472ca720c3..57e7765845f 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_compute.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_compute.py @@ -6,68 +6,46 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_app(ScenarioTest): + resource_disk_zr = {"type": "microsoft.compute/disks", "zones": ["1", "2", "3"]} - resource_disk_zr = \ - { - "type": "microsoft.compute/disks", - "zones": [ - "1", - "2", - "3" - ] - } - - resource_disk_nonzr = \ - { - "type": "microsoft.compute/disks", - "zones": None - } - - resource_vmss_zr = \ - { - "type": "microsoft.compute/virtualmachinescalesets", - "zones": [ - "1", - "2", - "3" - ] - } - - resource_vmss_nonzr = \ - { - "type": "microsoft.compute/virtualmachinescalesets", - "zones": None - } - - resource_vm_zr = \ - { - "type": "microsoft.compute/virtualmachines", - "zones": [ - "1", - "2", - "3" - ] - } - - resource_vm_nonzr = \ - { - "type": "microsoft.compute/virtualmachines", - "zones": None - } + resource_disk_nonzr = {"type": "microsoft.compute/disks", "zones": None} + + resource_vmss_zr = { + "type": "microsoft.compute/virtualmachinescalesets", + "zones": ["1", "2", "3"], + } + + resource_vmss_nonzr = { + "type": "microsoft.compute/virtualmachinescalesets", + "zones": None, + } + + resource_vm_zr = { + "type": "microsoft.compute/virtualmachines", + "zones": ["1", "2", "3"], + } + + resource_vm_nonzr = {"type": "microsoft.compute/virtualmachines", "zones": None} validator = None @classmethod def setUpClass(cls): super(test_microsoft_app, cls).setUpClass() - resourceProvider = cls.resource_disk_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_disk_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_disk_zr(self): # Test for zone redundancy scenario @@ -97,4 +75,4 @@ def test_vm_zr(self): def test_vm_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_vm_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_containerregistry.py b/src/zones/azext_zones/tests/latest/test_microsoft_containerregistry.py index b6f2995777f..96e7289cb62 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_containerregistry.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_containerregistry.py @@ -6,38 +6,36 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_containerregistry(ScenarioTest): + resource_zr = { + "type": "microsoft.containerregistry/registries", + "properties": {"zoneRedundancy": "Enabled"}, + } + + resource_nonzr = { + "type": "microsoft.containerregistry/registries", + "properties": {"zoneRedundancy": "Disabled"}, + } - resource_zr = \ - { - "type": "microsoft.containerregistry/registries", - "properties": { - "zoneRedundancy": "Enabled" - } - } - - - resource_nonzr = \ - { - "type": "microsoft.containerregistry/registries", - "properties": { - "zoneRedundancy": "Disabled" - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_containerregistry, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -46,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_containerservice.py b/src/zones/azext_zones/tests/latest/test_microsoft_containerservice.py index 597a36bcc13..a87c05b2341 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_containerservice.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_containerservice.py @@ -6,47 +6,36 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_containerservice(ScenarioTest): + resource_zr = { + "type": "microsoft.containerservice/managedclusters", + "properties": {"agentPoolProfiles": [{"availabilityZones": ["1", "2", "3"]}]}, + } + + resource_nonzr = { + "type": "microsoft.containerservice/managedclusters", + "properties": {"agentPoolProfiles": [{}]}, + } - resource_zr = \ - { - "type": "microsoft.containerservice/managedclusters", - "properties": { - "agentPoolProfiles": [ - { - "availabilityZones": [ - "1", - "2", - "3" - ] - } - ] - } - } - - resource_nonzr = \ - { - "type": "microsoft.containerservice/managedclusters", - "properties": { - "agentPoolProfiles": [ - {} - ] - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_containerservice, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -55,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_dashboard.py b/src/zones/azext_zones/tests/latest/test_microsoft_dashboard.py index c8f689d6475..fb9464ae902 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_dashboard.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_dashboard.py @@ -6,37 +6,36 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_dashboard(ScenarioTest): + resource_zr = { + "type": "microsoft.dashboard/grafana", + "properties": {"zoneRedundancy": "Enabled"}, + } + + resource_nonzr = { + "type": "microsoft.dashboard/grafana", + "properties": {"zoneRedundancy": "Disabled"}, + } - resource_zr = \ - { - "type": "microsoft.dashboard/grafana", - "properties": { - "zoneRedundancy": 'Enabled' - } - } - - resource_nonzr = \ - { - "type": "microsoft.dashboard/grafana", - "properties": { - "zoneRedundancy": 'Disabled' - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_dashboard, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -45,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_dbformysql.py b/src/zones/azext_zones/tests/latest/test_microsoft_dbformysql.py index 0263c06c822..4d4e30217ca 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_dbformysql.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_dbformysql.py @@ -6,41 +6,36 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_dbformysql(ScenarioTest): + resource_zr = { + "type": "microsoft.dbformysql/flexibleservers", + "properties": {"highAvailability": {"mode": "ZoneRedundant"}}, + } + + resource_nonzr = { + "type": "microsoft.dbformysql/flexibleservers", + "properties": {"highAvailability": {"mode": "Disabled"}}, + } - resource_zr = \ - { - "type": "microsoft.dbformysql/flexibleservers", - "properties": { - "highAvailability": { - "mode": "ZoneRedundant" - } - } - } - - resource_nonzr = \ - { - "type": "microsoft.dbformysql/flexibleservers", - "properties": { - "highAvailability": { - "mode": "Disabled" - } - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_dbformysql, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -49,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_dbforpostgresql.py b/src/zones/azext_zones/tests/latest/test_microsoft_dbforpostgresql.py index ebf0ddfbef0..9a5a6a890a6 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_dbforpostgresql.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_dbforpostgresql.py @@ -6,42 +6,36 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_dbforpostgresql(ScenarioTest): + resource_zr = { + "type": "microsoft.dbforpostgresql/flexibleservers", + "properties": {"highAvailability": {"mode": "ZoneRedundant"}}, + } + + resource_nonzr = { + "type": "microsoft.dbforpostgresql/flexibleservers", + "properties": {"highAvailability": {"state": "NotEnabled", "mode": "Disabled"}}, + } - resource_zr = \ - { - "type": "microsoft.dbforpostgresql/flexibleservers", - "properties": { - "highAvailability": { - "mode": "ZoneRedundant" - } - } - } - - resource_nonzr = \ - { - "type": "microsoft.dbforpostgresql/flexibleservers", - "properties": { - "highAvailability": { - "state": "NotEnabled", - "mode": "Disabled" - } - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_dbforpostgresql, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -50,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_documentdb.py b/src/zones/azext_zones/tests/latest/test_microsoft_documentdb.py index 88521131a55..bce814c7f78 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_documentdb.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_documentdb.py @@ -6,44 +6,35 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_documentdb(ScenarioTest): + resource_zr = { + "type": "microsoft.documentdb/databaseaccounts", + "properties": {"locations": [{"isZoneRedundant": True}]}, + } - resource_zr = \ - { - "type": "microsoft.documentdb/databaseaccounts", - "properties": { - "locations": [ - { - "isZoneRedundant": True - } - ] - } - } - - resource_nonzr = \ - { - "type": "microsoft.documentdb/databaseaccounts", - "properties": { - "locations": [ - { - "isZoneRedundant": False - } - ] - } - } + resource_nonzr = { + "type": "microsoft.documentdb/databaseaccounts", + "properties": {"locations": [{"isZoneRedundant": False}]}, + } validator = None @classmethod def setUpClass(cls): super(test_microsoft_documentdb, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -53,4 +44,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_kusto.py b/src/zones/azext_zones/tests/latest/test_microsoft_kusto.py index 80bd6980e10..3b7cbaa2be0 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_kusto.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_kusto.py @@ -6,37 +6,30 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_kusto(ScenarioTest): + resource_zr = {"type": "microsoft.kusto/clusters", "zones": ["1", "3", "2"]} + + resource_nonzr = {"type": "microsoft.kusto/clusters", "zones": None} - resource_zr = \ - { - "type": "microsoft.kusto/clusters", - "zones": [ - "1", - "3", - "2" - ] - } - - resource_nonzr = \ - { - "type": "microsoft.kusto/clusters", - "zones": None - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_kusto, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -45,4 +38,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_network.py b/src/zones/azext_zones/tests/latest/test_microsoft_network.py index 2d4021ad9cb..a7c582627de 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_network.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_network.py @@ -6,128 +6,87 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_network(ScenarioTest): + resource_applicationgateways_zr = { + "type": "microsoft.network/applicationgateways", + "zones": ["1", "2", "3"], + } - resource_applicationgateways_zr = \ - { - "type": "microsoft.network/applicationgateways", - "zones": [ - "1", - "2", - "3" - ] - } - - resource_applicationgateways_nonzr = \ - { - "type": "microsoft.network/applicationgateways", - "zones": None - } - - resource_azurefirewalls_zr = \ - { - "type": "microsoft.network/azurefirewalls", - "sku": { - "capacity": 3 - }, - "zones": [ - "1", - "2", - "3" - ] - } - - resource_azurefirewalls_nonzr = \ - { - "type": "microsoft.network/azurefirewalls", - "sku": { - "capacity": 1 - }, - "zones": None - } - - resource_loadbalancers_zr = \ - { - "type": "microsoft.network/loadbalancers", - "properties": { - "frontendIPConfigurations": [ - { - "zones": [ - "1", - "2", - "3" - ] - } - ] - } - } - resource_loadbalancers_nonzr = \ - { - "type": "microsoft.network/loadbalancers", - "properties": { - "frontendIPConfigurations": [ - { - "zones": None - } - ] - } - } + resource_applicationgateways_nonzr = { + "type": "microsoft.network/applicationgateways", + "zones": None, + } + + resource_azurefirewalls_zr = { + "type": "microsoft.network/azurefirewalls", + "sku": {"capacity": 3}, + "zones": ["1", "2", "3"], + } + + resource_azurefirewalls_nonzr = { + "type": "microsoft.network/azurefirewalls", + "sku": {"capacity": 1}, + "zones": None, + } + + resource_loadbalancers_zr = { + "type": "microsoft.network/loadbalancers", + "properties": {"frontendIPConfigurations": [{"zones": ["1", "2", "3"]}]}, + } + resource_loadbalancers_nonzr = { + "type": "microsoft.network/loadbalancers", + "properties": {"frontendIPConfigurations": [{"zones": None}]}, + } - resource_publicipaddresses_zr = \ - { + resource_publicipaddresses_zr = { "type": "microsoft.network/publicipaddresses", - "sku": { - "name": "Standard" - }, - "zones": [ - "1", - "2", - "3" - ] + "sku": {"name": "Standard"}, + "zones": ["1", "2", "3"], } - resource_publicipaddresses_nonzr = \ - { + resource_publicipaddresses_nonzr = { "type": "microsoft.network/publicipaddresses", - "sku": { - "name": "Basic" - }, - "zones": None + "sku": {"name": "Basic"}, + "zones": None, } - resource_virtualnetworkgateways_zr = \ - { - "type": "microsoft.network/virtualnetworkgateways", - "properties": { - "sku": { - "name": "VpnGw2AZ", - } + resource_virtualnetworkgateways_zr = { + "type": "microsoft.network/virtualnetworkgateways", + "properties": { + "sku": { + "name": "VpnGw2AZ", } - } - - resource_virtualnetworkgateways_nonzr = \ - { - "type": "microsoft.network/virtualnetworkgateways", - "properties": { - "sku": { - "name": "VpnGw2", - } + }, + } + + resource_virtualnetworkgateways_nonzr = { + "type": "microsoft.network/virtualnetworkgateways", + "properties": { + "sku": { + "name": "VpnGw2", } - } - + }, + } + validator = None @classmethod def setUpClass(cls): super(test_microsoft_network, cls).setUpClass() - resourceProvider = cls.resource_applicationgateways_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_applicationgateways_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_applicationgateways_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_applicationgateways_zr) @@ -176,4 +135,4 @@ def test_virtualnetworkgateways_zr(self): def test_virtualnetworkgateways_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_virtualnetworkgateways_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_recoveryservices.py b/src/zones/azext_zones/tests/latest/test_microsoft_recoveryservices.py index 8d1d2b3741f..10e2b669f10 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_recoveryservices.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_recoveryservices.py @@ -6,41 +6,44 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_recoveryservices(ScenarioTest): - - resource_zr = \ - { - "type": "microsoft.recoveryservices/vaults", - "properties": { - "redundancySettings": { - "standardTierStorageRedundancy": "ZoneRedundant", - } + resource_zr = { + "type": "microsoft.recoveryservices/vaults", + "properties": { + "redundancySettings": { + "standardTierStorageRedundancy": "ZoneRedundant", } - } - - resource_nonzr = \ - { - "type": "microsoft.recoveryservices/vaults", - "properties": { - "redundancySettings": { - "standardTierStorageRedundancy": "LocallyRedundant", - } + }, + } + + resource_nonzr = { + "type": "microsoft.recoveryservices/vaults", + "properties": { + "redundancySettings": { + "standardTierStorageRedundancy": "LocallyRedundant", } - } - + }, + } + validator = None @classmethod def setUpClass(cls): super(test_microsoft_recoveryservices, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] + # Load the resource type validators + load_validators() + + resourceProvider = cls.resource_zr["type"].split("/")[0] cls.validator = getResourceTypeValidator(resourceProvider) - def test_zr(self): # Test for zone redundancy scenario zrResult = self.validator.validate(self.resource_zr) @@ -49,4 +52,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_search.py b/src/zones/azext_zones/tests/latest/test_microsoft_search.py index 0a06600b19f..7c7dc7816fe 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_search.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_search.py @@ -6,42 +6,37 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_search(ScenarioTest): + resource_zr = { + "type": "microsoft.search/searchservices", + "sku": {"name": "standard"}, + "properties": {"replicaCount": 3}, + } + + resource_nonzr = { + "type": "microsoft.search/searchservices", + "sku": {"name": "standard"}, + "properties": {"replicaCount": 1}, + } - resource_zr = \ - { - "type": "microsoft.search/searchservices", - "sku": { - "name": "standard" - }, - "properties": { - "replicaCount": 3 - } - } - - resource_nonzr = \ - { - "type": "microsoft.search/searchservices", - "sku": { - "name": "standard" - }, - "properties": { - "replicaCount": 1 - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_search, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -51,4 +46,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_signalrservice.py b/src/zones/azext_zones/tests/latest/test_microsoft_signalrservice.py index 99a0712d2c6..27b6bb7f9fb 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_signalrservice.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_signalrservice.py @@ -6,38 +6,37 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_signalrservice(ScenarioTest): - - resource_zr = \ - { + resource_zr = { "type": "microsoft.signalrservice/signalr", - "sku": { - "name": "Premium" - }, - "zones": None + "sku": {"name": "Premium"}, + "zones": None, } - resource_nonzr = \ - { + resource_nonzr = { "type": "microsoft.signalrservice/signalr", - "sku": { - "name": "Standard" - }, - "zones": None + "sku": {"name": "Standard"}, + "zones": None, } - + validator = None @classmethod def setUpClass(cls): super(test_microsoft_signalrservice, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -47,4 +46,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_sql.py b/src/zones/azext_zones/tests/latest/test_microsoft_sql.py index f24c1946bf5..20c729b9dc1 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_sql.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_sql.py @@ -6,36 +6,39 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_sql(ScenarioTest): + resource_zr = { + "type": "microsoft.sql/servers/databases", + "properties": { + "zoneRedundant": True, + }, + } + + resource_nonzr = { + "type": "microsoft.sql/servers/databases", + "properties": { + "zoneRedundant": False, + }, + } - resource_zr = \ - { - "type": "microsoft.sql/servers/databases", - "properties": { - "zoneRedundant": True, - }, - } - - resource_nonzr = \ - { - "type": "microsoft.sql/servers/databases", - "properties": { - "zoneRedundant": False, - }, - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_sql, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -45,4 +48,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_storage.py b/src/zones/azext_zones/tests/latest/test_microsoft_storage.py index ae8f1ddb1a3..f3374c08689 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_storage.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_storage.py @@ -6,36 +6,39 @@ import os import unittest -from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from azure.cli.testsdk import ScenarioTest +from ..._resourceTypeValidation import ( + getResourceTypeValidator, + load_validators, + ZoneRedundancyValidationResult, +) class test_microsoft_storage(ScenarioTest): + resource_zr = { + "type": "microsoft.storage/storageaccounts", + "sku": { + "name": "Standard_ZRS", + }, + } + + resource_nonzr = { + "type": "microsoft.storage/storageaccounts", + "sku": { + "name": "Standard_LRS", + }, + } - resource_zr = \ - { - "type": "microsoft.storage/storageaccounts", - "sku": { - "name": "Standard_ZRS", - } - } - - resource_nonzr = \ - { - "type": "microsoft.storage/storageaccounts", - "sku": { - "name": "Standard_LRS", - } - } - validator = None @classmethod def setUpClass(cls): super(test_microsoft_storage, cls).setUpClass() - resourceProvider = cls.resource_zr['type'].split('/')[0] - cls.validator = getResourceTypeValidator(resourceProvider) + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr["type"].split("/")[0] + cls.validator = getResourceTypeValidator(resourceProvider) def test_zr(self): # Test for zone redundancy scenario @@ -45,4 +48,4 @@ def test_zr(self): def test_nonzr(self): # Test for non-zone redundancy scenario zrResult = self.validator.validate(self.resource_nonzr) - self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) \ No newline at end of file + self.assertEqual(zrResult, ZoneRedundancyValidationResult.No) diff --git a/src/zones/azext_zones/tests/latest/test_microsoft_web.py b/src/zones/azext_zones/tests/latest/test_microsoft_web.py index cc59ced625e..8b7f1cfeb7b 100644 --- a/src/zones/azext_zones/tests/latest/test_microsoft_web.py +++ b/src/zones/azext_zones/tests/latest/test_microsoft_web.py @@ -7,7 +7,7 @@ import unittest from azure.cli.testsdk import (ScenarioTest) -from ..._resourceTypeValidation import getResourceTypeValidator, ZoneRedundancyValidationResult +from ..._resourceTypeValidation import getResourceTypeValidator, load_validators, ZoneRedundancyValidationResult class test_microsoft_web(ScenarioTest): @@ -40,6 +40,9 @@ class test_microsoft_web(ScenarioTest): @classmethod def setUpClass(cls): super(test_microsoft_web, cls).setUpClass() + # Load the resource type validators + load_validators() + resourceProvider = cls.resource_zr['type'].split('/')[0] cls.validator = getResourceTypeValidator(resourceProvider) diff --git a/src/zones/setup.py b/src/zones/setup.py index 402e474fd50..55b69e13e8b 100644 --- a/src/zones/setup.py +++ b/src/zones/setup.py @@ -16,7 +16,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '1.0.0b1' +VERSION = '1.0.0b2' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers