NSX|V3 rename the default availability zone

The default AZ was called default, like the one of NSX-V
For creating a common plugin, we need a different name for it.

Change-Id: I7d978614b7521a72a4d7a7763e748dcb7b8d084c
This commit is contained in:
Adit Sarfaty 2017-11-20 14:18:06 +02:00
parent 32199faa02
commit 10722f96b8
3 changed files with 14 additions and 7 deletions

View File

@ -29,8 +29,9 @@ DEFAULT_NAME = 'default'
class ConfiguredAvailabilityZone(object): class ConfiguredAvailabilityZone(object):
def __init__(self, config_line): def __init__(self, config_line, default_name=DEFAULT_NAME):
self.name = "" self.name = ""
self._is_default = False
if config_line and ':' in config_line: if config_line and ':' in config_line:
# Older configuration - each line contains all the relevant # Older configuration - each line contains all the relevant
# values for one availability zones, separated by ':' # values for one availability zones, separated by ':'
@ -46,11 +47,12 @@ class ConfiguredAvailabilityZone(object):
self.init_from_config_section(self.name) self.init_from_config_section(self.name)
else: else:
# Default zone configuration # Default zone configuration
self.name = DEFAULT_NAME self.name = default_name
self._is_default = True
self.init_default_az() self.init_default_az()
def is_default(self): def is_default(self):
return self.name == DEFAULT_NAME return self._is_default
def _validate_zone_name(self, config_line): def _validate_zone_name(self, config_line):
if len(self.name) > 36: if len(self.name) > 36:
@ -74,6 +76,8 @@ class ConfiguredAvailabilityZone(object):
class ConfiguredAvailabilityZones(object): class ConfiguredAvailabilityZones(object):
default_name = DEFAULT_NAME
def __init__(self, az_conf, az_class): def __init__(self, az_conf, az_class):
self.availability_zones = {} self.availability_zones = {}
@ -83,7 +87,7 @@ class ConfiguredAvailabilityZones(object):
self.availability_zones[obj.name] = obj self.availability_zones[obj.name] = obj
# add a default entry # add a default entry
obj = az_class(None) obj = az_class(None, default_name=self.default_name)
self.availability_zones[obj.name] = obj self.availability_zones[obj.name] = obj
# validate the default az: # validate the default az:
@ -103,7 +107,7 @@ class ConfiguredAvailabilityZones(object):
"plugin")) "plugin"))
self._default_az = self.availability_zones[default_az_name] self._default_az = self.availability_zones[default_az_name]
else: else:
self._default_az = self.availability_zones[DEFAULT_NAME] self._default_az = self.availability_zones[self.default_name]
def get_availability_zone(self, name): def get_availability_zone(self, name):
"""Return an availability zone object by its name """Return an availability zone object by its name

View File

@ -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 core_resources
from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts 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): class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
@ -202,6 +202,8 @@ class NsxV3AvailabilityZone(common_az.ConfiguredAvailabilityZone):
class NsxV3AvailabilityZones(common_az.ConfiguredAvailabilityZones): class NsxV3AvailabilityZones(common_az.ConfiguredAvailabilityZones):
default_name = DEFAULT_NAME
def __init__(self): def __init__(self):
super(NsxV3AvailabilityZones, self).__init__( super(NsxV3AvailabilityZones, self).__init__(
cfg.CONF.nsx_v3.availability_zones, cfg.CONF.nsx_v3.availability_zones,

View File

@ -31,6 +31,7 @@ from vmware_nsx.common import exceptions as nsx_exc
from vmware_nsx.common import utils from vmware_nsx.common import utils
from vmware_nsx.db import db as nsx_db from vmware_nsx.db import db as nsx_db
from vmware_nsx.extensions import advancedserviceproviders as as_providers 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_nsx.tests.unit.nsx_v3 import test_plugin
from vmware_nsxlib.v3 import nsx_constants from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import resources as nsx_resources from vmware_nsxlib.v3 import resources as nsx_resources
@ -819,7 +820,7 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin):
net = p.create_network(ctx, data) net = p.create_network(ctx, data)
self.assertEqual([], self.assertEqual([],
net['availability_zone_hints']) net['availability_zone_hints'])
self.assertEqual(['default'], self.assertEqual([nsx_az.DEFAULT_NAME],
net['availability_zones']) net['availability_zones'])
def test_dhcp_service_with_create_az_network(self): def test_dhcp_service_with_create_az_network(self):