diff --git a/vmware_nsx/common/availability_zones.py b/vmware_nsx/common/availability_zones.py index 9aada724d3..71c138d8a4 100644 --- a/vmware_nsx/common/availability_zones.py +++ b/vmware_nsx/common/availability_zones.py @@ -29,8 +29,9 @@ DEFAULT_NAME = 'default' class ConfiguredAvailabilityZone(object): - def __init__(self, config_line): + def __init__(self, config_line, default_name=DEFAULT_NAME): self.name = "" + self._is_default = False if config_line and ':' in config_line: # Older configuration - each line contains all the relevant # values for one availability zones, separated by ':' @@ -46,11 +47,12 @@ class ConfiguredAvailabilityZone(object): self.init_from_config_section(self.name) else: # Default zone configuration - self.name = DEFAULT_NAME + self.name = default_name + self._is_default = True self.init_default_az() def is_default(self): - return self.name == DEFAULT_NAME + return self._is_default def _validate_zone_name(self, config_line): if len(self.name) > 36: @@ -74,6 +76,8 @@ class ConfiguredAvailabilityZone(object): class ConfiguredAvailabilityZones(object): + default_name = DEFAULT_NAME + def __init__(self, az_conf, az_class): self.availability_zones = {} @@ -83,7 +87,7 @@ class ConfiguredAvailabilityZones(object): self.availability_zones[obj.name] = obj # add a default entry - obj = az_class(None) + obj = az_class(None, default_name=self.default_name) self.availability_zones[obj.name] = obj # validate the default az: @@ -103,7 +107,7 @@ class ConfiguredAvailabilityZones(object): "plugin")) self._default_az = self.availability_zones[default_az_name] else: - self._default_az = self.availability_zones[DEFAULT_NAME] + self._default_az = self.availability_zones[self.default_name] def get_availability_zone(self, name): """Return an availability zone object by its name diff --git a/vmware_nsx/plugins/nsx_v3/availability_zones.py b/vmware_nsx/plugins/nsx_v3/availability_zones.py index de0314c28c..3b11c88b36 100644 --- a/vmware_nsx/plugins/nsx_v3/availability_zones.py +++ b/vmware_nsx/plugins/nsx_v3/availability_zones.py @@ -22,7 +22,7 @@ from vmware_nsx.common import exceptions as nsx_exc from vmware_nsxlib.v3 import core_resources from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts -DEFAULT_NAME = common_az.DEFAULT_NAME +DEFAULT_NAME = common_az.DEFAULT_NAME + 'v3' class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone): @@ -202,6 +202,8 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone): class NsxV3AvailabilityZones(common_az.ConfiguredAvailabilityZones): + default_name = DEFAULT_NAME + def __init__(self): super(NsxV3AvailabilityZones, self).__init__( cfg.CONF.nsx_v3.availability_zones, diff --git a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py index 6fbda53a6b..3f91c8f0ec 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_dhcp_metadata.py @@ -31,6 +31,7 @@ from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.common import utils from vmware_nsx.db import db as nsx_db from vmware_nsx.extensions import advancedserviceproviders as as_providers +from vmware_nsx.plugins.nsx_v3 import availability_zones as nsx_az from vmware_nsx.tests.unit.nsx_v3 import test_plugin from vmware_nsxlib.v3 import nsx_constants from vmware_nsxlib.v3 import resources as nsx_resources @@ -819,7 +820,7 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin): net = p.create_network(ctx, data) self.assertEqual([], net['availability_zone_hints']) - self.assertEqual(['default'], + self.assertEqual([nsx_az.DEFAULT_NAME], net['availability_zones']) def test_dhcp_service_with_create_az_network(self):