use l3 ext ha mode api def from neutron-lib
The l3 ext ha mode extension's API definition was rehomed into neutron-lib with commit Ie407d56cdac6996133fcd855754185c74707e992 This patch consumes the API definition by removing/using the rehomed code and using the APIExtensionDescriptor for the extension class. NeutronLibImpact Change-Id: I8f728c8707172ed7340fb90cce43b885c61938c2
This commit is contained in:
parent
1665395b19
commit
573134e0b9
@ -25,6 +25,7 @@ from neutron_lib.callbacks import registry
|
|||||||
from neutron_lib.callbacks import resources
|
from neutron_lib.callbacks import resources
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
|
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
|
||||||
from neutron_lib.objects import exceptions as obj_base
|
from neutron_lib.objects import exceptions as obj_base
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
@ -47,7 +48,6 @@ from neutron.db import l3_dvr_db
|
|||||||
from neutron.db.l3_dvr_db import is_distributed_router
|
from neutron.db.l3_dvr_db import is_distributed_router
|
||||||
from neutron.db.models import l3ha as l3ha_model
|
from neutron.db.models import l3ha as l3ha_model
|
||||||
from neutron.extensions import l3
|
from neutron.extensions import l3
|
||||||
from neutron.extensions import l3_ext_ha_mode as l3_ha
|
|
||||||
from neutron.objects import base
|
from neutron.objects import base
|
||||||
from neutron.objects import l3_hamode
|
from neutron.objects import l3_hamode
|
||||||
from neutron.objects import router as l3_obj
|
from neutron.objects import router as l3_obj
|
||||||
@ -73,9 +73,9 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
try:
|
try:
|
||||||
net = netaddr.IPNetwork(self.ha_cidr)
|
net = netaddr.IPNetwork(self.ha_cidr)
|
||||||
except netaddr.AddrFormatError:
|
except netaddr.AddrFormatError:
|
||||||
raise l3_ha.HANetworkCIDRNotValid(cidr=self.ha_cidr)
|
raise l3ha_exc.HANetworkCIDRNotValid(cidr=self.ha_cidr)
|
||||||
if ('/' not in self.ha_cidr or net.network != net.ip):
|
if ('/' not in self.ha_cidr or net.network != net.ip):
|
||||||
raise l3_ha.HANetworkCIDRNotValid(cidr=self.ha_cidr)
|
raise l3ha_exc.HANetworkCIDRNotValid(cidr=self.ha_cidr)
|
||||||
|
|
||||||
self._check_num_agents_per_router()
|
self._check_num_agents_per_router()
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
max_agents = cfg.CONF.max_l3_agents_per_router
|
max_agents = cfg.CONF.max_l3_agents_per_router
|
||||||
|
|
||||||
if max_agents != UNLIMITED_AGENTS_PER_ROUTER and max_agents < 1:
|
if max_agents != UNLIMITED_AGENTS_PER_ROUTER and max_agents < 1:
|
||||||
raise l3_ha.HAMaximumAgentsNumberNotValid(max_agents=max_agents)
|
raise l3ha_exc.HAMaximumAgentsNumberNotValid(max_agents=max_agents)
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
inst = super(L3_HA_NAT_db_mixin, cls).__new__(cls, *args, **kwargs)
|
inst = super(L3_HA_NAT_db_mixin, cls).__new__(cls, *args, **kwargs)
|
||||||
@ -128,7 +128,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
available_vr_ids = VR_ID_RANGE - allocated_vr_ids
|
available_vr_ids = VR_ID_RANGE - allocated_vr_ids
|
||||||
|
|
||||||
if not available_vr_ids:
|
if not available_vr_ids:
|
||||||
raise l3_ha.NoVRIDAvailable(router_id=router_id)
|
raise l3ha_exc.NoVRIDAvailable(router_id=router_id)
|
||||||
|
|
||||||
allocation = l3_hamode.L3HARouterVRIdAllocation(
|
allocation = l3_hamode.L3HARouterVRIdAllocation(
|
||||||
context, network_id=network_id,
|
context, network_id=network_id,
|
||||||
@ -149,7 +149,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
{'count': count, 'network': network_id,
|
{'count': count, 'network': network_id,
|
||||||
'router': router_id})
|
'router': router_id})
|
||||||
|
|
||||||
raise l3_ha.MaxVRIDAllocationTriesReached(
|
raise l3ha_exc.MaxVRIDAllocationTriesReached(
|
||||||
network_id=network_id, router_id=router_id,
|
network_id=network_id, router_id=router_id,
|
||||||
max_tries=MAX_ALLOCATION_TRIES)
|
max_tries=MAX_ALLOCATION_TRIES)
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
if not ha_net:
|
if not ha_net:
|
||||||
# net was deleted, throw a retry to start over to create another
|
# net was deleted, throw a retry to start over to create another
|
||||||
raise db_exc.RetryRequest(
|
raise db_exc.RetryRequest(
|
||||||
l3_ha.HANetworkConcurrentDeletion(
|
l3ha_exc.HANetworkConcurrentDeletion(
|
||||||
tenant_id=router['tenant_id']))
|
tenant_id=router['tenant_id']))
|
||||||
|
|
||||||
@registry.receives(resources.ROUTER, [events.AFTER_CREATE])
|
@registry.receives(resources.ROUTER, [events.AFTER_CREATE])
|
||||||
@ -385,7 +385,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
|||||||
self._notify_router_updated(context, router_id)
|
self._notify_router_updated(context, router_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
with excutils.save_and_reraise_exception() as ctx:
|
with excutils.save_and_reraise_exception() as ctx:
|
||||||
if isinstance(e, l3_ha.NoVRIDAvailable):
|
if isinstance(e, l3ha_exc.NoVRIDAvailable):
|
||||||
ctx.reraise = False
|
ctx.reraise = False
|
||||||
LOG.warning("No more VRIDs for router: %s", e)
|
LOG.warning("No more VRIDs for router: %s", e)
|
||||||
else:
|
else:
|
||||||
|
@ -12,71 +12,11 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib.api import converters
|
from neutron_lib.api.definitions import l3_ext_ha_mode as apidef
|
||||||
from neutron_lib.api import extensions
|
from neutron_lib.api import extensions
|
||||||
from neutron_lib import constants
|
|
||||||
from neutron_lib import exceptions
|
|
||||||
|
|
||||||
from neutron._i18n import _
|
|
||||||
|
|
||||||
HA_INFO = 'ha'
|
|
||||||
EXTENDED_ATTRIBUTES_2_0 = {
|
|
||||||
'routers': {
|
|
||||||
HA_INFO: {'allow_post': True, 'allow_put': True,
|
|
||||||
'default': constants.ATTR_NOT_SPECIFIED, 'is_visible': True,
|
|
||||||
'enforce_policy': True,
|
|
||||||
'convert_to': converters.convert_to_boolean_if_not_none}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class MaxVRIDAllocationTriesReached(exceptions.NeutronException):
|
class L3_ext_ha_mode(extensions.APIExtensionDescriptor):
|
||||||
message = _("Failed to allocate a VRID in the network %(network_id)s "
|
|
||||||
"for the router %(router_id)s after %(max_tries)s tries.")
|
|
||||||
|
|
||||||
|
|
||||||
class NoVRIDAvailable(exceptions.Conflict):
|
|
||||||
message = _("No more Virtual Router Identifier (VRID) available when "
|
|
||||||
"creating router %(router_id)s. The limit of number "
|
|
||||||
"of HA Routers per tenant is 254.")
|
|
||||||
|
|
||||||
|
|
||||||
class HANetworkConcurrentDeletion(exceptions.Conflict):
|
|
||||||
message = _("Network for tenant %(tenant_id)s concurrently deleted.")
|
|
||||||
|
|
||||||
|
|
||||||
class HANetworkCIDRNotValid(exceptions.NeutronException):
|
|
||||||
message = _("The HA Network CIDR specified in the configuration file "
|
|
||||||
"isn't valid; %(cidr)s.")
|
|
||||||
|
|
||||||
|
|
||||||
class HAMaximumAgentsNumberNotValid(exceptions.NeutronException):
|
|
||||||
message = _("max_l3_agents_per_router %(max_agents)s config parameter "
|
|
||||||
"is not valid as it cannot be negative. It must be 1 or "
|
|
||||||
"greater. Alternatively, it can be 0 to mean unlimited.")
|
|
||||||
|
|
||||||
|
|
||||||
class L3_ext_ha_mode(extensions.ExtensionDescriptor):
|
|
||||||
"""Extension class supporting virtual router in HA mode."""
|
"""Extension class supporting virtual router in HA mode."""
|
||||||
|
|
||||||
@classmethod
|
api_definition = apidef
|
||||||
def get_name(cls):
|
|
||||||
return "HA Router extension"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_alias(cls):
|
|
||||||
return constants.L3_HA_MODE_EXT_ALIAS
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_description(cls):
|
|
||||||
return "Add HA capability to routers."
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_updated(cls):
|
|
||||||
return "2014-04-26T00:00:00-00:00"
|
|
||||||
|
|
||||||
def get_extended_resources(self, version):
|
|
||||||
if version == "2.0":
|
|
||||||
return EXTENDED_ATTRIBUTES_2_0
|
|
||||||
else:
|
|
||||||
return {}
|
|
||||||
|
@ -24,6 +24,7 @@ from neutron_lib.callbacks import resources
|
|||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib import context
|
from neutron_lib import context
|
||||||
from neutron_lib import exceptions as n_exc
|
from neutron_lib import exceptions as n_exc
|
||||||
|
from neutron_lib.exceptions import l3_ext_ha_mode as l3ha_exc
|
||||||
from neutron_lib.objects import exceptions
|
from neutron_lib.objects import exceptions
|
||||||
from neutron_lib.plugins import constants as plugin_constants
|
from neutron_lib.plugins import constants as plugin_constants
|
||||||
from neutron_lib.plugins import directory
|
from neutron_lib.plugins import directory
|
||||||
@ -43,7 +44,6 @@ from neutron.db import l3_agentschedulers_db
|
|||||||
from neutron.db import l3_hamode_db
|
from neutron.db import l3_hamode_db
|
||||||
from neutron.db.models import l3ha as l3ha_model
|
from neutron.db.models import l3ha as l3ha_model
|
||||||
from neutron.extensions import l3
|
from neutron.extensions import l3
|
||||||
from neutron.extensions import l3_ext_ha_mode
|
|
||||||
from neutron.objects import l3_hamode
|
from neutron.objects import l3_hamode
|
||||||
from neutron.scheduler import l3_agent_scheduler
|
from neutron.scheduler import l3_agent_scheduler
|
||||||
from neutron.services.revisions import revision_plugin
|
from neutron.services.revisions import revision_plugin
|
||||||
@ -126,19 +126,19 @@ class L3HATestCase(L3HATestFramework):
|
|||||||
def test_verify_configuration_l3_ha_net_cidr_is_not_a_cidr(self):
|
def test_verify_configuration_l3_ha_net_cidr_is_not_a_cidr(self):
|
||||||
cfg.CONF.set_override('l3_ha_net_cidr', 'not a cidr')
|
cfg.CONF.set_override('l3_ha_net_cidr', 'not a cidr')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
l3_ext_ha_mode.HANetworkCIDRNotValid,
|
l3ha_exc.HANetworkCIDRNotValid,
|
||||||
self.plugin._verify_configuration)
|
self.plugin._verify_configuration)
|
||||||
|
|
||||||
def test_verify_configuration_l3_ha_net_cidr_is_not_a_subnet(self):
|
def test_verify_configuration_l3_ha_net_cidr_is_not_a_subnet(self):
|
||||||
cfg.CONF.set_override('l3_ha_net_cidr', '10.0.0.1/8')
|
cfg.CONF.set_override('l3_ha_net_cidr', '10.0.0.1/8')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
l3_ext_ha_mode.HANetworkCIDRNotValid,
|
l3ha_exc.HANetworkCIDRNotValid,
|
||||||
self.plugin._verify_configuration)
|
self.plugin._verify_configuration)
|
||||||
|
|
||||||
def test_verify_configuration_max_l3_agents_below_0(self):
|
def test_verify_configuration_max_l3_agents_below_0(self):
|
||||||
cfg.CONF.set_override('max_l3_agents_per_router', -5)
|
cfg.CONF.set_override('max_l3_agents_per_router', -5)
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
l3_ext_ha_mode.HAMaximumAgentsNumberNotValid,
|
l3ha_exc.HAMaximumAgentsNumberNotValid,
|
||||||
self.plugin._check_num_agents_per_router)
|
self.plugin._check_num_agents_per_router)
|
||||||
|
|
||||||
def test_verify_configuration_max_l3_agents_unlimited(self):
|
def test_verify_configuration_max_l3_agents_unlimited(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user