Merge "Nuage core plugin decomposition"
This commit is contained in:
commit
71917da5d1
|
@ -21,9 +21,9 @@ from neutron.i18n import _LE
|
|||
from neutron.openstack.common import log
|
||||
from neutron.plugins.common import constants
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.nuage.common import config
|
||||
from neutron.plugins.nuage.common import constants as nuage_const
|
||||
from neutron.plugins.nuage import plugin
|
||||
from nuage_neutron.plugins.nuage.common import config
|
||||
from nuage_neutron.plugins.nuage.common import constants as nuage_const
|
||||
from nuage_neutron.plugins.nuage import plugin
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
restproxy_opts = [
|
||||
cfg.StrOpt('server', default='localhost:8800',
|
||||
help=_("IP Address and Port of Nuage's VSD server")),
|
||||
cfg.StrOpt('serverauth', default='username:password',
|
||||
secret=True,
|
||||
help=_("Username and password for authentication")),
|
||||
cfg.BoolOpt('serverssl', default=False,
|
||||
help=_("Boolean for SSL connection with VSD server")),
|
||||
cfg.StrOpt('base_uri', default='/',
|
||||
help=_("Nuage provided base uri to reach out to VSD")),
|
||||
cfg.StrOpt('organization', default='system',
|
||||
help=_("Organization name in which VSD will orchestrate "
|
||||
"network resources using openstack")),
|
||||
cfg.StrOpt('auth_resource', default='',
|
||||
help=_("Nuage provided uri for initial authorization to "
|
||||
"access VSD")),
|
||||
cfg.StrOpt('default_net_partition_name',
|
||||
default='OpenStackDefaultNetPartition',
|
||||
help=_("Default Network partition in which VSD will "
|
||||
"orchestrate network resources using openstack")),
|
||||
cfg.IntOpt('default_floatingip_quota',
|
||||
default=254,
|
||||
help=_("Per Net Partition quota of floating ips")),
|
||||
]
|
||||
|
||||
syncmanager_opts = [
|
||||
cfg.BoolOpt('enable_sync', default=False,
|
||||
help=_("Nuage plugin will sync resources between openstack "
|
||||
"and VSD")),
|
||||
cfg.IntOpt('sync_interval', default=0,
|
||||
help=_("Sync interval in seconds between openstack and VSD. "
|
||||
"It defines how often the synchronization is done. "
|
||||
"If not set, value of 0 is assumed and sync will be "
|
||||
"performed only once, at the Neutron startup time.")),
|
||||
]
|
||||
|
||||
|
||||
def nuage_register_cfg_opts():
|
||||
cfg.CONF.register_opts(restproxy_opts, "RESTPROXY")
|
||||
cfg.CONF.register_opts(syncmanager_opts, "SYNCMANAGER")
|
|
@ -1,26 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.common import constants
|
||||
|
||||
AUTO_CREATE_PORT_OWNERS = [
|
||||
constants.DEVICE_OWNER_DHCP,
|
||||
constants.DEVICE_OWNER_ROUTER_INTF,
|
||||
constants.DEVICE_OWNER_ROUTER_GW,
|
||||
constants.DEVICE_OWNER_FLOATINGIP
|
||||
]
|
||||
|
||||
NOVA_PORT_OWNER_PREF = 'compute:'
|
||||
|
||||
SR_TYPE_FLOATING = "FLOATING"
|
|
@ -1,25 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
''' Nuage specific exceptions '''
|
||||
|
||||
from neutron.common import exceptions as n_exc
|
||||
|
||||
|
||||
class OperationNotSupported(n_exc.InvalidConfigurationOption):
|
||||
message = _("Nuage Plugin does not support this operation: %(msg)s")
|
||||
|
||||
|
||||
class NuageBadRequest(n_exc.BadRequest):
|
||||
message = _("Bad request: %(msg)s")
|
|
@ -1,105 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import base
|
||||
from neutron import manager
|
||||
from neutron import quota
|
||||
|
||||
|
||||
# Attribute Map
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
'net_partitions': {
|
||||
'id': {'allow_post': False, 'allow_put': False,
|
||||
'validate': {'type:uuid': None},
|
||||
'is_visible': True},
|
||||
'name': {'allow_post': True, 'allow_put': False,
|
||||
'is_visible': True, 'default': '',
|
||||
'validate': {'type:name_not_default': None}},
|
||||
'description': {'allow_post': True, 'allow_put': False,
|
||||
'is_visible': True, 'default': '',
|
||||
'validate': {'type:string_or_none': None}},
|
||||
'tenant_id': {'allow_post': True, 'allow_put': False,
|
||||
'required_by_policy': True,
|
||||
'is_visible': True},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Netpartition(object):
|
||||
"""Extension class supporting net_partition.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "NetPartition"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "net-partition"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "NetPartition"
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return "http://nuagenetworks.net/ext/net_partition/api/v1.0"
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2014-01-01T10:00:00-00:00"
|
||||
|
||||
@classmethod
|
||||
def get_resources(cls):
|
||||
"""Returns Ext Resources."""
|
||||
exts = []
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
resource_name = 'net_partition'
|
||||
collection_name = resource_name.replace('_', '-') + "s"
|
||||
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
|
||||
quota.QUOTAS.register_resource_by_name(resource_name)
|
||||
controller = base.create_resource(collection_name,
|
||||
resource_name,
|
||||
plugin, params, allow_bulk=True)
|
||||
ex = extensions.ResourceExtension(collection_name,
|
||||
controller)
|
||||
exts.append(ex)
|
||||
|
||||
return exts
|
||||
|
||||
|
||||
class NetPartitionPluginBase(object):
|
||||
|
||||
@abc.abstractmethod
|
||||
def create_net_partition(self, context, router):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def update_net_partition(self, context, id, router):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_net_partition(self, context, id, fields=None):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete_net_partition(self, context, id):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_net_partitions(self, context, filters=None, fields=None):
|
||||
pass
|
|
@ -1,78 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'routers': {
|
||||
'net_partition': {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:string_or_none': None}
|
||||
},
|
||||
'rd': {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:string_or_none': None}
|
||||
},
|
||||
'rt': {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:string_or_none': None}
|
||||
},
|
||||
'nuage_router_template': {
|
||||
'allow_post': True,
|
||||
'allow_put': False,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Nuage_router(object):
|
||||
"""Extension class supporting nuage router.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Nuage router"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "nuage-router"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Nuage Router"
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return "http://nuagenetworks.net/ext/routers/api/v1.0"
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2014-01-01T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
|
@ -1,64 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
'subnets': {
|
||||
'net_partition': {
|
||||
'allow_post': True,
|
||||
'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:string_or_none': None}
|
||||
},
|
||||
'nuage_subnet_template': {
|
||||
'allow_post': True,
|
||||
'allow_put': False,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:uuid_or_none': None}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Nuage_subnet(object):
|
||||
"""Extension class supporting Nuage subnet.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Nuage subnet"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "nuage-subnet"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Nuage subnet"
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return "http://nuagenetworks.net/ext/subnets/api/v1.0"
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2014-01-01T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
|
@ -1,291 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.db import common_db_mixin
|
||||
from neutron.db import extraroute_db
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.plugins.nuage import nuage_models
|
||||
|
||||
|
||||
def add_net_partition(session, netpart_id,
|
||||
l3dom_id, l2dom_id,
|
||||
ent_name):
|
||||
net_partitioninst = nuage_models.NetPartition(id=netpart_id,
|
||||
name=ent_name,
|
||||
l3dom_tmplt_id=l3dom_id,
|
||||
l2dom_tmplt_id=l2dom_id)
|
||||
session.add(net_partitioninst)
|
||||
return net_partitioninst
|
||||
|
||||
|
||||
def delete_net_partition(session, net_partition):
|
||||
session.delete(net_partition)
|
||||
|
||||
|
||||
def delete_net_partition_by_id(session, netpart_id):
|
||||
query = session.query(nuage_models.NetPartition)
|
||||
query.filter_by(id=netpart_id).delete()
|
||||
|
||||
|
||||
def get_net_partition_by_name(session, name):
|
||||
query = session.query(nuage_models.NetPartition)
|
||||
return query.filter_by(name=name).first()
|
||||
|
||||
|
||||
def get_net_partition_by_id(session, id):
|
||||
query = session.query(nuage_models.NetPartition)
|
||||
return query.filter_by(id=id).first()
|
||||
|
||||
|
||||
def get_net_partitions(session, filters=None, fields=None):
|
||||
query = session.query(nuage_models.NetPartition)
|
||||
common_db = common_db_mixin.CommonDbMixin()
|
||||
query = common_db._apply_filters_to_query(query,
|
||||
nuage_models.NetPartition,
|
||||
filters)
|
||||
return query
|
||||
|
||||
|
||||
def get_net_partition_ids(session):
|
||||
query = session.query(nuage_models.NetPartition.id)
|
||||
return [netpart[0] for netpart in query]
|
||||
|
||||
|
||||
def get_net_partition_with_lock(session, netpart_id):
|
||||
query = session.query(nuage_models.NetPartition)
|
||||
netpart_db = query.filter_by(id=netpart_id).with_lockmode('update').one()
|
||||
return make_net_partition_dict(netpart_db)
|
||||
|
||||
|
||||
def get_subnet_ids(session):
|
||||
query = session.query(models_v2.Subnet.id)
|
||||
return [subn[0] for subn in query]
|
||||
|
||||
|
||||
def get_subnet_with_lock(session, sub_id):
|
||||
query = session.query(models_v2.Subnet)
|
||||
subnet_db = query.filter_by(id=sub_id).with_lockmode('update').one()
|
||||
return subnet_db
|
||||
|
||||
|
||||
def get_router_ids(session):
|
||||
query = session.query(l3_db.Router.id)
|
||||
return [router[0] for router in query]
|
||||
|
||||
|
||||
def get_router_with_lock(session, router_id):
|
||||
query = session.query(l3_db.Router)
|
||||
router_db = query.filter_by(id=router_id).with_lockmode('update').one()
|
||||
return router_db
|
||||
|
||||
|
||||
def get_secgrp_ids(session):
|
||||
query = session.query(securitygroups_db.SecurityGroup.id)
|
||||
return [secgrp[0] for secgrp in query]
|
||||
|
||||
|
||||
def get_secgrp_with_lock(session, secgrp_id):
|
||||
query = session.query(securitygroups_db.SecurityGroup)
|
||||
secgrp_db = query.filter_by(id=secgrp_id).with_lockmode('update').one()
|
||||
return secgrp_db
|
||||
|
||||
|
||||
def get_secgrprule_ids(session):
|
||||
query = session.query(securitygroups_db.SecurityGroupRule.id)
|
||||
return [secgrprule[0] for secgrprule in query]
|
||||
|
||||
|
||||
def get_secgrprule_with_lock(session, secgrprule_id):
|
||||
query = session.query(securitygroups_db.SecurityGroupRule)
|
||||
secgrprule_db = (query.filter_by(id=secgrprule_id).with_lockmode(
|
||||
'update').one())
|
||||
return secgrprule_db
|
||||
|
||||
|
||||
def get_port_with_lock(session, port_id):
|
||||
query = session.query(models_v2.Port)
|
||||
port_db = query.filter_by(id=port_id).with_lockmode('update').one()
|
||||
return port_db
|
||||
|
||||
|
||||
def get_fip_with_lock(session, fip_id):
|
||||
query = session.query(l3_db.FloatingIP)
|
||||
fip_db = query.filter_by(id=fip_id).with_lockmode('update').one()
|
||||
return fip_db
|
||||
|
||||
|
||||
def add_entrouter_mapping(session, np_id,
|
||||
router_id,
|
||||
n_l3id):
|
||||
ent_rtr_mapping = nuage_models.NetPartitionRouter(net_partition_id=np_id,
|
||||
router_id=router_id,
|
||||
nuage_router_id=n_l3id)
|
||||
session.add(ent_rtr_mapping)
|
||||
|
||||
|
||||
def add_subnetl2dom_mapping(session, neutron_subnet_id,
|
||||
nuage_sub_id,
|
||||
np_id,
|
||||
l2dom_id=None,
|
||||
nuage_user_id=None,
|
||||
nuage_group_id=None):
|
||||
subnet_l2dom = nuage_models.SubnetL2Domain(subnet_id=neutron_subnet_id,
|
||||
nuage_subnet_id=nuage_sub_id,
|
||||
net_partition_id=np_id,
|
||||
nuage_l2dom_tmplt_id=l2dom_id,
|
||||
nuage_user_id=nuage_user_id,
|
||||
nuage_group_id=nuage_group_id)
|
||||
session.add(subnet_l2dom)
|
||||
|
||||
|
||||
def update_subnetl2dom_mapping(subnet_l2dom,
|
||||
new_dict):
|
||||
subnet_l2dom.update(new_dict)
|
||||
|
||||
|
||||
def get_update_subnetl2dom_mapping(session, new_dict):
|
||||
subnet_l2dom = get_subnet_l2dom_with_lock(session, new_dict['subnet_id'])
|
||||
subnet_l2dom.update(new_dict)
|
||||
|
||||
|
||||
def update_entrtr_mapping(ent_rtr, new_dict):
|
||||
ent_rtr.update(new_dict)
|
||||
|
||||
|
||||
def get_update_entrtr_mapping(session, new_dict):
|
||||
ent_rtr = get_ent_rtr_mapping_with_lock(session, new_dict['router_id'])
|
||||
ent_rtr.update(new_dict)
|
||||
|
||||
|
||||
def delete_subnetl2dom_mapping(session, subnet_l2dom):
|
||||
session.delete(subnet_l2dom)
|
||||
|
||||
|
||||
def get_subnet_l2dom_by_id(session, id):
|
||||
query = session.query(nuage_models.SubnetL2Domain)
|
||||
return query.filter_by(subnet_id=id).first()
|
||||
|
||||
|
||||
def get_subnet_l2dom_with_lock(session, id):
|
||||
query = session.query(nuage_models.SubnetL2Domain)
|
||||
subl2dom = query.filter_by(subnet_id=id).with_lockmode('update').one()
|
||||
return subl2dom
|
||||
|
||||
|
||||
def get_ent_rtr_mapping_by_entid(session, entid):
|
||||
query = session.query(nuage_models.NetPartitionRouter)
|
||||
return query.filter_by(net_partition_id=entid).all()
|
||||
|
||||
|
||||
def get_ent_rtr_mapping_by_rtrid(session, rtrid):
|
||||
query = session.query(nuage_models.NetPartitionRouter)
|
||||
return query.filter_by(router_id=rtrid).first()
|
||||
|
||||
|
||||
def add_network_binding(session, network_id, network_type, physical_network,
|
||||
vlan_id):
|
||||
binding = nuage_models.ProviderNetBinding(
|
||||
network_id=network_id,
|
||||
network_type=network_type,
|
||||
physical_network=physical_network,
|
||||
vlan_id=vlan_id)
|
||||
session.add(binding)
|
||||
return binding
|
||||
|
||||
|
||||
def get_network_binding(session, network_id):
|
||||
return (session.query(nuage_models.ProviderNetBinding).
|
||||
filter_by(network_id=network_id).
|
||||
first())
|
||||
|
||||
|
||||
def get_ent_rtr_mapping_with_lock(session, rtrid):
|
||||
query = session.query(nuage_models.NetPartitionRouter)
|
||||
entrtr = query.filter_by(router_id=rtrid).with_lockmode('update').one()
|
||||
return entrtr
|
||||
|
||||
|
||||
def get_ipalloc_for_fip(session, network_id, ip, lock=False):
|
||||
query = session.query(models_v2.IPAllocation)
|
||||
if lock:
|
||||
# Lock is required when the resource is synced
|
||||
ipalloc_db = (query.filter_by(network_id=network_id).filter_by(
|
||||
ip_address=ip).with_lockmode('update').one())
|
||||
else:
|
||||
ipalloc_db = (query.filter_by(network_id=network_id).filter_by(
|
||||
ip_address=ip).one())
|
||||
return make_ipalloc_dict(ipalloc_db)
|
||||
|
||||
|
||||
def get_all_net_partitions(session):
|
||||
net_partitions = get_net_partitions(session)
|
||||
return make_net_partition_list(net_partitions)
|
||||
|
||||
|
||||
def get_all_routes(session):
|
||||
routes = session.query(extraroute_db.RouterRoute)
|
||||
return make_route_list(routes)
|
||||
|
||||
|
||||
def get_route_with_lock(session, dest, nhop):
|
||||
query = session.query(extraroute_db.RouterRoute)
|
||||
route_db = (query.filter_by(destination=dest).filter_by(nexthop=nhop)
|
||||
.with_lockmode('update').one())
|
||||
return make_route_dict(route_db)
|
||||
|
||||
|
||||
def make_ipalloc_dict(subnet_db):
|
||||
return {'port_id': subnet_db['port_id'],
|
||||
'subnet_id': subnet_db['subnet_id'],
|
||||
'network_id': subnet_db['network_id'],
|
||||
'ip_address': subnet_db['ip_address']}
|
||||
|
||||
|
||||
def make_net_partition_dict(net_partition):
|
||||
return {'id': net_partition['id'],
|
||||
'name': net_partition['name'],
|
||||
'l3dom_tmplt_id': net_partition['l3dom_tmplt_id'],
|
||||
'l2dom_tmplt_id': net_partition['l2dom_tmplt_id']}
|
||||
|
||||
|
||||
def make_net_partition_list(net_partitions):
|
||||
return [make_net_partition_dict(net_partition) for net_partition in
|
||||
net_partitions]
|
||||
|
||||
|
||||
def make_route_dict(route):
|
||||
return {'destination': route['destination'],
|
||||
'nexthop': route['nexthop'],
|
||||
'router_id': route['router_id']}
|
||||
|
||||
|
||||
def make_route_list(routes):
|
||||
return [make_route_dict(route) for route in routes]
|
||||
|
||||
|
||||
def make_subnl2dom_dict(subl2dom):
|
||||
return {'subnet_id': subl2dom['subnet_id'],
|
||||
'net_partition_id': subl2dom['net_partition_id'],
|
||||
'nuage_subnet_id': subl2dom['nuage_subnet_id'],
|
||||
'nuage_l2dom_tmplt_id': subl2dom['nuage_l2dom_tmplt_id'],
|
||||
'nuage_user_id': subl2dom['nuage_user_id'],
|
||||
'nuage_group_id': subl2dom['nuage_group_id']}
|
||||
|
||||
|
||||
def make_entrtr_dict(entrtr):
|
||||
return {'net_partition_id': entrtr['net_partition_id'],
|
||||
'router_id': entrtr['router_id'],
|
||||
'nuage_router_id': entrtr['nuage_router_id']}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,424 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import importutils
|
||||
import sqlalchemy.orm.exc as db_exc
|
||||
|
||||
from neutron import context as ncontext
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import extraroute_db
|
||||
from neutron.db import securitygroups_db
|
||||
from neutron.i18n import _LE, _LI, _LW
|
||||
from neutron.openstack.common import log
|
||||
from neutron.plugins.nuage.common import config
|
||||
from neutron.plugins.nuage import nuagedb
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
NUAGE_CONFIG_FILE = '/etc/neutron/plugins/nuage/nuage_plugin.ini'
|
||||
|
||||
|
||||
class SyncManager(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
extraroute_db.ExtraRoute_db_mixin,
|
||||
securitygroups_db.SecurityGroupDbMixin):
|
||||
"""
|
||||
This class provides functionality to sync data between OpenStack and VSD.
|
||||
"""
|
||||
|
||||
def __init__(self, nuageclient):
|
||||
self.context = ncontext.get_admin_context()
|
||||
self.nuageclient = nuageclient
|
||||
|
||||
@lockutils.synchronized('synchronize', 'nuage-sync', external=True)
|
||||
def synchronize(self, fipquota):
|
||||
LOG.info(_LI("Starting the sync between Neutron and VSD"))
|
||||
try:
|
||||
# Get all data to determine the resources to sync
|
||||
data = self._get_all_data()
|
||||
resources = self.nuageclient.get_resources_to_sync(data)
|
||||
|
||||
# Sync all resources
|
||||
self._sync(resources, fipquota)
|
||||
except Exception:
|
||||
LOG.exception(_LE("Cannot complete the sync between Neutron and "
|
||||
"VSD because of error."))
|
||||
return
|
||||
|
||||
LOG.info(_LI("Sync between Neutron and VSD completed successfully"))
|
||||
|
||||
def _get_all_data(self):
|
||||
# Get all net-partitions
|
||||
net_partition_list = nuagedb.get_all_net_partitions(
|
||||
self.context.session)
|
||||
|
||||
# Get all subnet ids
|
||||
subnet_id_list = nuagedb.get_subnet_ids(self.context.session)
|
||||
|
||||
# Get all router ids
|
||||
router_id_list = nuagedb.get_router_ids(self.context.session)
|
||||
|
||||
# Get all ports
|
||||
port_list = self.get_ports(self.context)
|
||||
|
||||
# Get all routes
|
||||
route_list = nuagedb.get_all_routes(self.context.session)
|
||||
|
||||
# Get all floatingips
|
||||
fip_list = self.get_floatingips(self.context)
|
||||
|
||||
# Get all securitygrp ids
|
||||
secgrp_id_list = nuagedb.get_secgrp_ids(self.context.session)
|
||||
|
||||
# Get all securitygrprules
|
||||
secgrprule_id_list = self.get_security_group_rules(self.context)
|
||||
|
||||
# Get all portbindings
|
||||
portbinding_list = self._get_port_security_group_bindings(self.context)
|
||||
|
||||
data = {
|
||||
'netpartition': net_partition_list,
|
||||
'subnet': subnet_id_list,
|
||||
'router': router_id_list,
|
||||
'port': port_list,
|
||||
'route': route_list,
|
||||
'fip': fip_list,
|
||||
'secgroup': secgrp_id_list,
|
||||
'secgrouprule': secgrprule_id_list,
|
||||
'portbinding': portbinding_list,
|
||||
}
|
||||
return data
|
||||
|
||||
def _sync(self, resources, fip_quota):
|
||||
# Sync net-partitions
|
||||
net_partition_id_dict = self.sync_net_partitions(fip_quota, resources)
|
||||
|
||||
# Sync sharednetworks
|
||||
self.sync_sharednetworks(resources)
|
||||
|
||||
# Sync l2domains
|
||||
self.sync_l2domains(net_partition_id_dict, resources)
|
||||
|
||||
# Sync domains
|
||||
self.sync_domains(net_partition_id_dict, resources)
|
||||
|
||||
# Sync domainsubnets
|
||||
self.sync_domainsubnets(resources)
|
||||
|
||||
# Sync routes
|
||||
self.sync_routes(resources)
|
||||
|
||||
# Sync vms
|
||||
self.sync_vms(resources)
|
||||
|
||||
# Sync secgrps
|
||||
self.sync_secgrps(resources)
|
||||
|
||||
# Sync secgrprules
|
||||
self.sync_secgrp_rules(resources)
|
||||
|
||||
# Sync fips
|
||||
self._sync_fips(resources)
|
||||
|
||||
# Delete the old net-partitions
|
||||
for net_id in net_partition_id_dict:
|
||||
nuagedb.delete_net_partition_by_id(self.context.session,
|
||||
net_id)
|
||||
|
||||
def sync_net_partitions(self, fip_quota, resources):
|
||||
net_partition_id_dict = {}
|
||||
for netpart_id in resources['netpartition']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
netpart = self._get_netpart_data(netpart_id)
|
||||
if netpart:
|
||||
result = self.nuageclient.create_netpart(netpart,
|
||||
fip_quota)
|
||||
netpart = result.get(netpart_id)
|
||||
if netpart:
|
||||
net_partition_id_dict[netpart_id] = netpart['id']
|
||||
nuagedb.add_net_partition(
|
||||
self.context.session,
|
||||
netpart['id'],
|
||||
netpart['l3dom_tmplt_id'],
|
||||
netpart['l2dom_tmplt_id'],
|
||||
netpart['name'])
|
||||
|
||||
return net_partition_id_dict
|
||||
|
||||
def sync_sharednetworks(self, resources):
|
||||
for sharednet_id in resources['sharednetwork']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
subnet, subl2dom = self._get_subnet_data(
|
||||
sharednet_id,
|
||||
get_mapping=False)
|
||||
if subnet:
|
||||
self.nuageclient.create_sharednetwork(subnet)
|
||||
|
||||
def sync_l2domains(self, net_partition_id_dict, resources):
|
||||
for l2dom_id in resources['l2domain']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
subnet, subl2dom = self._get_subnet_data(l2dom_id)
|
||||
if subnet:
|
||||
# if subnet exists, subl2dom will exist
|
||||
netpart_id = subl2dom['net_partition_id']
|
||||
if netpart_id in net_partition_id_dict.keys():
|
||||
# Use the id of the newly created net_partition
|
||||
netpart_id = net_partition_id_dict[netpart_id]
|
||||
|
||||
result = self.nuageclient.create_l2domain(netpart_id,
|
||||
subnet)
|
||||
if result:
|
||||
nuagedb.get_update_subnetl2dom_mapping(
|
||||
self.context.session,
|
||||
result)
|
||||
|
||||
def sync_domains(self, net_partition_id_dict, resources):
|
||||
for domain_id in resources['domain']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
router, entrtr = self._get_router_data(domain_id)
|
||||
if router:
|
||||
# if router exists, entrtr will exist
|
||||
netpart_id = entrtr['net_partition_id']
|
||||
if netpart_id in net_partition_id_dict.keys():
|
||||
# Use the id of the newly created net_partition
|
||||
netpart_id = net_partition_id_dict[netpart_id]
|
||||
|
||||
netpart = nuagedb.get_net_partition_by_id(
|
||||
self.context.session,
|
||||
netpart_id)
|
||||
result = self.nuageclient.create_domain(netpart, router)
|
||||
if result:
|
||||
nuagedb.get_update_entrtr_mapping(self.context.session,
|
||||
result)
|
||||
|
||||
def sync_domainsubnets(self, resources):
|
||||
for domsubn_id in resources['domainsubnet']['add']:
|
||||
# This is a dict of subn_id and the router interface port
|
||||
subn_rtr_intf_port_dict = (
|
||||
resources['port']['sub_rtr_intf_port_dict'])
|
||||
port_id = subn_rtr_intf_port_dict[domsubn_id]
|
||||
port = self._get_port_data(port_id)
|
||||
if port:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
subnet, subl2dom = self._get_subnet_data(domsubn_id)
|
||||
if subnet:
|
||||
result = self.nuageclient.create_domainsubnet(subnet,
|
||||
port)
|
||||
if result:
|
||||
nuagedb.get_update_subnetl2dom_mapping(
|
||||
self.context.session,
|
||||
result)
|
||||
|
||||
def sync_routes(self, resources):
|
||||
for rt in resources['route']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
route = self._get_route_data(rt)
|
||||
if route:
|
||||
self.nuageclient.create_route(route)
|
||||
|
||||
def sync_vms(self, resources):
|
||||
for port_id in resources['port']['vm']:
|
||||
port = self._get_port_data(port_id)
|
||||
if port:
|
||||
self.nuageclient.create_vm(port)
|
||||
|
||||
def sync_secgrps(self, resources):
|
||||
secgrp_dict = resources['security']['secgroup']
|
||||
for secgrp_id, ports in secgrp_dict['l2domain']['add'].iteritems():
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
secgrp = self._get_sec_grp_data(secgrp_id)
|
||||
if secgrp:
|
||||
self.nuageclient.create_security_group(secgrp, ports)
|
||||
|
||||
for secgrp_id, ports in secgrp_dict['domain']['add'].iteritems():
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
secgrp = self._get_sec_grp_data(secgrp_id)
|
||||
if secgrp:
|
||||
self.nuageclient.create_security_group(secgrp, ports)
|
||||
|
||||
def sync_secgrp_rules(self, resources):
|
||||
secrule_list = resources['security']['secgrouprule']
|
||||
for secrule_id in secrule_list['l2domain']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
secgrprule = self._get_sec_grp_rule_data(secrule_id)
|
||||
if secgrprule:
|
||||
self.nuageclient.create_security_group_rule(secgrprule)
|
||||
|
||||
for secrule_id in secrule_list['domain']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
secgrprule = self._get_sec_grp_rule_data(secrule_id)
|
||||
if secgrprule:
|
||||
self.nuageclient.create_security_group_rule(secgrprule)
|
||||
|
||||
def _sync_fips(self, resources):
|
||||
for fip_id in resources['fip']['add']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
fip = self._get_fip_data(fip_id)
|
||||
if fip:
|
||||
ipalloc = self._get_ipalloc_for_fip(fip)
|
||||
self.nuageclient.create_fip(fip, ipalloc)
|
||||
|
||||
for fip_id in resources['fip']['disassociate']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
fip = self._get_fip_data(fip_id)
|
||||
if fip:
|
||||
self.nuageclient.disassociate_fip(fip)
|
||||
|
||||
for fip_id in resources['fip']['associate']:
|
||||
with self.context.session.begin(subtransactions=True):
|
||||
fip = self._get_fip_data(fip_id)
|
||||
if fip:
|
||||
self.nuageclient.associate_fip(fip)
|
||||
|
||||
def _get_subnet_data(self, subnet_id, get_mapping=True):
|
||||
subnet = None
|
||||
subl2dom = None
|
||||
try:
|
||||
if get_mapping:
|
||||
subl2dom_db = nuagedb.get_subnet_l2dom_with_lock(
|
||||
self.context.session,
|
||||
subnet_id)
|
||||
subl2dom = nuagedb.make_subnl2dom_dict(subl2dom_db)
|
||||
|
||||
subnet_db = nuagedb.get_subnet_with_lock(self.context.session,
|
||||
subnet_id)
|
||||
subnet = self._make_subnet_dict(subnet_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Subnet %s not found in neutron for sync"),
|
||||
subnet_id)
|
||||
|
||||
return subnet, subl2dom
|
||||
|
||||
def _get_router_data(self, router_id):
|
||||
router = None
|
||||
entrtr = None
|
||||
try:
|
||||
entrtr_db = nuagedb.get_ent_rtr_mapping_with_lock(
|
||||
self.context.session,
|
||||
router_id)
|
||||
entrtr = nuagedb.make_entrtr_dict(entrtr_db)
|
||||
|
||||
router_db = nuagedb.get_router_with_lock(self.context.session,
|
||||
router_id)
|
||||
router = self._make_router_dict(router_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Router %s not found in neutron for sync"),
|
||||
router_id)
|
||||
|
||||
return router, entrtr
|
||||
|
||||
def _get_route_data(self, rt):
|
||||
route = None
|
||||
try:
|
||||
route = nuagedb.get_route_with_lock(self.context.session,
|
||||
rt['destination'],
|
||||
rt['nexthop'])
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Route with destination %(dest)s and nexthop "
|
||||
"%(hop)s not found in neutron for sync"),
|
||||
{'dest': rt['destination'],
|
||||
'hop': rt['nexthop']})
|
||||
|
||||
return route
|
||||
|
||||
def _get_sec_grp_data(self, secgrp_id):
|
||||
secgrp = None
|
||||
try:
|
||||
secgrp_db = nuagedb.get_secgrp_with_lock(self.context.session,
|
||||
secgrp_id)
|
||||
secgrp = self._make_security_group_dict(secgrp_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Security group %s not found in neutron for sync"),
|
||||
secgrp_id)
|
||||
return secgrp
|
||||
|
||||
def _get_sec_grp_rule_data(self, secgrprule_id):
|
||||
secgrprule = None
|
||||
try:
|
||||
secrule_db = nuagedb.get_secgrprule_with_lock(self.context.session,
|
||||
secgrprule_id)
|
||||
secgrprule = self._make_security_group_rule_dict(secrule_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Security group rule %s not found in neutron for "
|
||||
"sync"), secgrprule_id)
|
||||
return secgrprule
|
||||
|
||||
def _get_fip_data(self, fip_id):
|
||||
fip = None
|
||||
try:
|
||||
fip_db = nuagedb.get_fip_with_lock(self.context.session, fip_id)
|
||||
fip = self._make_floatingip_dict(fip_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Floating ip %s not found in neutron for sync"),
|
||||
fip_id)
|
||||
return fip
|
||||
|
||||
def _get_ipalloc_for_fip(self, fip):
|
||||
ipalloc = None
|
||||
try:
|
||||
ipalloc = nuagedb.get_ipalloc_for_fip(self.context.session,
|
||||
fip['floating_network_id'],
|
||||
fip['floating_ip_address'],
|
||||
lock=True)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("IP allocation for floating ip %s not found in "
|
||||
"neutron for sync"), fip['id'])
|
||||
return ipalloc
|
||||
|
||||
def _get_netpart_data(self, netpart_id):
|
||||
netpart = None
|
||||
try:
|
||||
netpart = nuagedb.get_net_partition_with_lock(
|
||||
self.context.session,
|
||||
netpart_id)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("Net-partition %s not found in neutron for sync"),
|
||||
netpart_id)
|
||||
return netpart
|
||||
|
||||
def _get_port_data(self, port_id):
|
||||
port = None
|
||||
try:
|
||||
port_db = nuagedb.get_port_with_lock(self.context.session, port_id)
|
||||
port = self._make_port_dict(port_db)
|
||||
except db_exc.NoResultFound:
|
||||
LOG.warning(_LW("VM port %s not found in neutron for sync"),
|
||||
port_id)
|
||||
return port
|
||||
|
||||
|
||||
def main():
|
||||
cfg.CONF(default_config_files=(
|
||||
[NUAGE_CONFIG_FILE]))
|
||||
config.nuage_register_cfg_opts()
|
||||
server = cfg.CONF.RESTPROXY.server
|
||||
serverauth = cfg.CONF.RESTPROXY.serverauth
|
||||
serverssl = cfg.CONF.RESTPROXY.serverssl
|
||||
base_uri = cfg.CONF.RESTPROXY.base_uri
|
||||
auth_resource = cfg.CONF.RESTPROXY.auth_resource
|
||||
organization = cfg.CONF.RESTPROXY.organization
|
||||
fipquota = str(cfg.CONF.RESTPROXY.default_floatingip_quota)
|
||||
logging = importutils.import_module('logging')
|
||||
nuageclientinst = importutils.import_module('nuagenetlib.nuageclient')
|
||||
nuageclient = nuageclientinst.NuageClient(server, base_uri,
|
||||
serverssl, serverauth,
|
||||
auth_resource,
|
||||
organization)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
SyncManager(nuageclient).synchronize(fipquota)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,46 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.plugins.ml2 import config as ml2_config
|
||||
from neutron.tests.unit.ml2 import test_ml2_plugin
|
||||
import neutron.tests.unit.nuage.test_nuage_plugin as tnp
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
|
||||
|
||||
class TestNuageMechDriverBase(tnp.NuagePluginV2TestCase):
|
||||
def setUp(self):
|
||||
ml2_config.cfg.CONF.set_override('mechanism_drivers',
|
||||
['nuage'],
|
||||
'ml2')
|
||||
|
||||
super(TestNuageMechDriverBase,
|
||||
self).setUp(plugin=test_ml2_plugin.PLUGIN_NAME)
|
||||
|
||||
|
||||
class TestNuageMechDriverNetworksV2(test_db_plugin.TestNetworksV2,
|
||||
TestNuageMechDriverBase):
|
||||
pass
|
||||
|
||||
|
||||
class TestNuageMechDriverSubnetsV2(test_db_plugin.TestSubnetsV2,
|
||||
TestNuageMechDriverBase):
|
||||
pass
|
||||
|
||||
|
||||
class TestNuageMechDriverPortsV2(test_db_plugin.TestPortsV2,
|
||||
TestNuageMechDriverBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNuageMechDriverPortsV2, self).setUp()
|
||||
self.port_create_status = 'DOWN'
|
|
@ -1,320 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.openstack.common import uuidutils
|
||||
|
||||
|
||||
class FakeNuageClient(object):
|
||||
def __init__(self, server, base_uri, serverssl,
|
||||
serverauth, auth_resource, organization):
|
||||
pass
|
||||
|
||||
def rest_call(self, action, resource, data, extra_headers=None):
|
||||
pass
|
||||
|
||||
def vms_on_l2domain(self, l2dom_id):
|
||||
pass
|
||||
|
||||
def vms_on_subnet(self, subnet_id):
|
||||
pass
|
||||
|
||||
def create_subnet(self, neutron_subnet, params):
|
||||
nuage_subnet = {
|
||||
'nuage_l2template_id': uuidutils.generate_uuid(),
|
||||
'nuage_userid': uuidutils.generate_uuid(),
|
||||
'nuage_groupid': uuidutils.generate_uuid(),
|
||||
'nuage_l2domain_id': uuidutils.generate_uuid()
|
||||
}
|
||||
return nuage_subnet
|
||||
|
||||
def update_subnet(self, neutron_subnet, params):
|
||||
pass
|
||||
|
||||
def delete_subnet(self, id):
|
||||
pass
|
||||
|
||||
def create_router(self, neutron_router, router, params):
|
||||
nuage_router = {
|
||||
'nuage_userid': uuidutils.generate_uuid(),
|
||||
'nuage_groupid': uuidutils.generate_uuid(),
|
||||
'nuage_domain_id': uuidutils.generate_uuid(),
|
||||
'nuage_def_zone_id': uuidutils.generate_uuid(),
|
||||
}
|
||||
return nuage_router
|
||||
|
||||
def delete_router(self, id):
|
||||
pass
|
||||
|
||||
def delete_user(self, id):
|
||||
pass
|
||||
|
||||
def delete_group(self, id):
|
||||
pass
|
||||
|
||||
def create_domain_subnet(self, neutron_subnet, params):
|
||||
pass
|
||||
|
||||
def delete_domain_subnet(self, id):
|
||||
pass
|
||||
|
||||
def create_net_partition(self, params):
|
||||
fake_net_partition = {
|
||||
'nuage_entid': uuidutils.generate_uuid(),
|
||||
'l3dom_id': uuidutils.generate_uuid(),
|
||||
'l2dom_id': uuidutils.generate_uuid(),
|
||||
}
|
||||
return fake_net_partition
|
||||
|
||||
def get_def_netpartition_data(self, default_net_part):
|
||||
if default_net_part == 'default_test_np':
|
||||
fake_defnetpart_data = {
|
||||
'np_id': uuidutils.generate_uuid(),
|
||||
'l3dom_tid': uuidutils.generate_uuid(),
|
||||
'l2dom_tid': uuidutils.generate_uuid(),
|
||||
}
|
||||
return fake_defnetpart_data
|
||||
|
||||
def get_net_partition_id_by_name(self, name):
|
||||
return uuidutils.generate_uuid()
|
||||
|
||||
def delete_net_partition(self, id, l3dom_id=None, l2dom_id=None):
|
||||
pass
|
||||
|
||||
def check_del_def_net_partition(self, ent_name):
|
||||
pass
|
||||
|
||||
def create_vms(self, params):
|
||||
pass
|
||||
|
||||
def delete_vms(self, params):
|
||||
pass
|
||||
|
||||
def create_nuage_staticroute(self, params):
|
||||
return uuidutils.generate_uuid()
|
||||
|
||||
def delete_nuage_staticroute(self, id):
|
||||
pass
|
||||
|
||||
def create_nuage_sharedresource(self, params):
|
||||
return uuidutils.generate_uuid()
|
||||
|
||||
def delete_nuage_sharedresource(self, id):
|
||||
pass
|
||||
|
||||
def create_nuage_floatingip(self, params):
|
||||
return uuidutils.generate_uuid()
|
||||
|
||||
def delete_nuage_floatingip(self, id):
|
||||
pass
|
||||
|
||||
def update_nuage_vm_vport(self, params):
|
||||
pass
|
||||
|
||||
def get_nuage_fip_pool_by_id(self, net_id):
|
||||
result = {
|
||||
'nuage_fip_pool_id': uuidutils.generate_uuid()
|
||||
}
|
||||
return result
|
||||
|
||||
def get_nuage_fip_by_id(self, params):
|
||||
if 'neutron_fip' in params:
|
||||
neutron_fip = params['neutron_fip']
|
||||
if (neutron_fip['floating_ip_address'] == '12.0.0.3' and
|
||||
neutron_fip['fixed_ip_address'] == '10.0.1.2') or (
|
||||
neutron_fip['floating_ip_address'] == '12.0.0.5' and
|
||||
neutron_fip['fixed_ip_address'] == '10.0.1.3'):
|
||||
result = {
|
||||
'nuage_fip_id': '1',
|
||||
'nuage_parent_id': '1'
|
||||
}
|
||||
return result
|
||||
|
||||
def get_nuage_port_by_id(self, params):
|
||||
if params.get('nuage_fip_id') == '1':
|
||||
domain_id = uuidutils.generate_uuid()
|
||||
else:
|
||||
if 'nuage_router_id' in params:
|
||||
domain_id = params['nuage_router_id']
|
||||
else:
|
||||
return
|
||||
|
||||
result = {
|
||||
'nuage_vif_id': uuidutils.generate_uuid(),
|
||||
'nuage_vport_id': uuidutils.generate_uuid(),
|
||||
'nuage_domain_id': domain_id
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
def get_zone_by_routerid(self, neutron_router_id):
|
||||
result = {
|
||||
'nuage_zone_id': uuidutils.generate_uuid()
|
||||
}
|
||||
return result
|
||||
|
||||
def get_usergroup(self, tenant, net_partition_id):
|
||||
return uuidutils.generate_uuid(), uuidutils.generate_uuid()
|
||||
|
||||
def get_sg_vptag_mapping(self, id):
|
||||
pass
|
||||
|
||||
def validate_nuage_sg_rule_definition(self, params):
|
||||
pass
|
||||
|
||||
def create_nuage_sgrule(self, params):
|
||||
pass
|
||||
|
||||
def update_nuage_vport(self, params):
|
||||
pass
|
||||
|
||||
def delete_nuage_sgrule(self, params):
|
||||
pass
|
||||
|
||||
def delete_nuage_secgroup(self, params):
|
||||
pass
|
||||
|
||||
def process_port_create_security_group(self, params):
|
||||
pass
|
||||
|
||||
def delete_port_security_group_bindings(self, params):
|
||||
pass
|
||||
|
||||
def validate_provider_network(self, net_type, phy_net, vlan_id):
|
||||
pass
|
||||
|
||||
def remove_router_interface(self, params):
|
||||
pass
|
||||
|
||||
def get_resources_to_sync(self, data):
|
||||
netpart_id_list = []
|
||||
for netpart in data['netpartition']:
|
||||
netpart_id_list.append(netpart['id'])
|
||||
|
||||
netpart_dict = {
|
||||
'add': netpart_id_list,
|
||||
'sync': []
|
||||
}
|
||||
|
||||
subn_id_list = []
|
||||
if data['subnet']:
|
||||
subn_id_list.append(data['subnet'][0])
|
||||
|
||||
l2domain_dict = {
|
||||
'add': subn_id_list
|
||||
}
|
||||
|
||||
rtr_id_list = []
|
||||
if data['router']:
|
||||
rtr_id_list.append(data['router'][0])
|
||||
|
||||
domain_dict = {
|
||||
'add': rtr_id_list
|
||||
}
|
||||
|
||||
domain_subn_id = uuidutils.generate_uuid()
|
||||
|
||||
result = {
|
||||
'netpartition': netpart_dict,
|
||||
'l2domain': l2domain_dict,
|
||||
'domain': domain_dict,
|
||||
'domainsubnet': {'add': [domain_subn_id]},
|
||||
'sharednetwork': {'add': [uuidutils.generate_uuid()]},
|
||||
'route': {'add': []},
|
||||
'security': {
|
||||
'secgroup': {
|
||||
'l2domain': {'add': {
|
||||
uuidutils.generate_uuid(): [uuidutils.generate_uuid()]
|
||||
}},
|
||||
'domain': {'add': {
|
||||
uuidutils.generate_uuid(): [uuidutils.generate_uuid()]
|
||||
}}
|
||||
},
|
||||
'secgrouprule': {
|
||||
'l2domain': {'add': [uuidutils.generate_uuid()]},
|
||||
'domain': {'add': [uuidutils.generate_uuid()]}
|
||||
},
|
||||
},
|
||||
'port': {
|
||||
'vm': [uuidutils.generate_uuid()],
|
||||
'sub_rtr_intf_port_dict': {
|
||||
domain_subn_id: uuidutils.generate_uuid()
|
||||
},
|
||||
'secgroup': [uuidutils.generate_uuid()]
|
||||
},
|
||||
'subl2dommapping': [uuidutils.generate_uuid()],
|
||||
'fip': {
|
||||
'add': [uuidutils.generate_uuid()],
|
||||
'associate': [uuidutils.generate_uuid()],
|
||||
'disassociate': [uuidutils.generate_uuid()]
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
||||
def create_netpart(self, netpart, fip_quota):
|
||||
if netpart['name'] == 'sync-new-netpartition':
|
||||
oldid = netpart['id']
|
||||
netpart['id'] = 'a917924f-3139-4bdb-a4c3-ea7c8011582f'
|
||||
netpart = {
|
||||
oldid: netpart
|
||||
}
|
||||
return netpart
|
||||
return {}
|
||||
|
||||
def create_sharednetwork(self, subnet):
|
||||
pass
|
||||
|
||||
def create_l2domain(self, netpart_id, subnet):
|
||||
subl2dom = {
|
||||
'subnet_id': subnet['id'],
|
||||
'nuage_subnet_id': '52daa465-cf33-4efd-91d3-f5bc2aebd',
|
||||
'net_partition_id': netpart_id,
|
||||
'nuage_l2dom_tmplt_id': uuidutils.generate_uuid(),
|
||||
'nuage_user_id': uuidutils.generate_uuid(),
|
||||
'nuage_group_id': uuidutils.generate_uuid(),
|
||||
}
|
||||
|
||||
return subl2dom
|
||||
|
||||
def create_domain(self, netpart, router):
|
||||
entrtr = {
|
||||
'router_id': router['id'],
|
||||
'nuage_router_id': '2d782c02-b88e-44ad-a79b-4bdf11f7df3d',
|
||||
'net_partition_id': netpart['id']
|
||||
}
|
||||
|
||||
return entrtr
|
||||
|
||||
def create_domainsubnet(self, subnet, ports):
|
||||
pass
|
||||
|
||||
def create_route(self, route):
|
||||
pass
|
||||
|
||||
def create_vm(self, port):
|
||||
pass
|
||||
|
||||
def create_security_group(self, secgrp, ports):
|
||||
pass
|
||||
|
||||
def create_security_group_rule(self, secgrprule):
|
||||
pass
|
||||
|
||||
def create_fip(self, fip, ipalloc):
|
||||
pass
|
||||
|
||||
def associate_fip(self, fip):
|
||||
pass
|
||||
|
||||
def disassociate_fip(self, fip):
|
||||
pass
|
|
@ -1,628 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import os
|
||||
|
||||
import mock
|
||||
import netaddr
|
||||
from oslo_config import cfg
|
||||
from webob import exc
|
||||
|
||||
from neutron.common import constants
|
||||
from neutron import context
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.extensions import providernet as pnet
|
||||
from neutron.extensions import securitygroup as ext_sg
|
||||
from neutron import manager
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.nuage import extensions
|
||||
from neutron.plugins.nuage.extensions import nuage_router
|
||||
from neutron.plugins.nuage import plugin as nuage_plugin
|
||||
from neutron.tests.unit import _test_extension_portbindings as test_bindings
|
||||
from neutron.tests.unit.nuage import fake_nuageclient
|
||||
from neutron.tests.unit import test_db_plugin
|
||||
from neutron.tests.unit import test_extension_extraroute as extraroute_test
|
||||
from neutron.tests.unit import test_extension_security_group as test_sg
|
||||
from neutron.tests.unit import test_extensions
|
||||
|
||||
|
||||
API_EXT_PATH = os.path.dirname(extensions.__file__)
|
||||
FAKE_DEFAULT_ENT = 'default'
|
||||
NUAGE_PLUGIN_PATH = 'neutron.plugins.nuage.plugin'
|
||||
FAKE_SERVER = '1.1.1.1'
|
||||
FAKE_SERVER_AUTH = 'user:pass'
|
||||
FAKE_SERVER_SSL = False
|
||||
FAKE_BASE_URI = '/base/'
|
||||
FAKE_AUTH_RESOURCE = '/auth'
|
||||
FAKE_ORGANIZATION = 'fake_org'
|
||||
|
||||
_plugin_name = ('%s.NuagePlugin' % NUAGE_PLUGIN_PATH)
|
||||
|
||||
|
||||
def getNuageClient():
|
||||
server = FAKE_SERVER
|
||||
serverauth = FAKE_SERVER_AUTH
|
||||
serverssl = FAKE_SERVER_SSL
|
||||
base_uri = FAKE_BASE_URI
|
||||
auth_resource = FAKE_AUTH_RESOURCE
|
||||
organization = FAKE_ORGANIZATION
|
||||
nuageclient = fake_nuageclient.FakeNuageClient(server,
|
||||
base_uri,
|
||||
serverssl,
|
||||
serverauth,
|
||||
auth_resource,
|
||||
organization)
|
||||
return nuageclient
|
||||
|
||||
|
||||
class NuagePluginV2TestCase(test_db_plugin.NeutronDbPluginV2TestCase):
|
||||
def setUp(self, plugin=_plugin_name,
|
||||
ext_mgr=None, service_plugins=None):
|
||||
|
||||
if 'v6' in self._testMethodName:
|
||||
self.skipTest("Nuage Plugin does not support IPV6.")
|
||||
|
||||
def mock_nuageClient_init(self):
|
||||
self.nuageclient = getNuageClient()
|
||||
|
||||
with mock.patch.object(nuage_plugin.NuagePlugin,
|
||||
'nuageclient_init', new=mock_nuageClient_init):
|
||||
cfg.CONF.set_override('api_extensions_path',
|
||||
API_EXT_PATH)
|
||||
super(NuagePluginV2TestCase, self).setUp(plugin=plugin,
|
||||
ext_mgr=ext_mgr)
|
||||
|
||||
def _assert_no_assoc_fip(self, fip):
|
||||
body = self._show('floatingips',
|
||||
fip['floatingip']['id'])
|
||||
self.assertIsNone(body['floatingip']['port_id'])
|
||||
self.assertIsNone(
|
||||
body['floatingip']['fixed_ip_address'])
|
||||
|
||||
def _associate_and_assert_fip(self, fip, port, allow=True):
|
||||
port_id = port['port']['id']
|
||||
ip_address = (port['port']['fixed_ips']
|
||||
[0]['ip_address'])
|
||||
if allow:
|
||||
body = self._update(
|
||||
'floatingips', fip['floatingip']['id'],
|
||||
{'floatingip': {'port_id': port_id}})
|
||||
self.assertEqual(
|
||||
body['floatingip']['port_id'], port_id)
|
||||
self.assertEqual(
|
||||
body['floatingip']['fixed_ip_address'],
|
||||
ip_address)
|
||||
return body['floatingip']['router_id']
|
||||
else:
|
||||
code = exc.HTTPInternalServerError.code
|
||||
self._update(
|
||||
'floatingips', fip['floatingip']['id'],
|
||||
{'floatingip': {'port_id': port_id}},
|
||||
expected_code=code)
|
||||
|
||||
def _test_floatingip_update_different_router(self):
|
||||
with contextlib.nested(self.subnet(cidr='10.0.0.0/24'),
|
||||
self.subnet(cidr='10.0.1.0/24')) as (
|
||||
s1, s2):
|
||||
with contextlib.nested(self.port(subnet=s1),
|
||||
self.port(subnet=s2)) as (p1, p2):
|
||||
private_sub1 = {'subnet':
|
||||
{'id':
|
||||
p1['port']['fixed_ips'][0]['subnet_id']}}
|
||||
private_sub2 = {'subnet':
|
||||
{'id':
|
||||
p2['port']['fixed_ips'][0]['subnet_id']}}
|
||||
with self.subnet(cidr='12.0.0.0/24') as public_sub:
|
||||
with contextlib.nested(
|
||||
self.floatingip_no_assoc_with_public_sub(
|
||||
private_sub1, public_sub=public_sub),
|
||||
self.floatingip_no_assoc_with_public_sub(
|
||||
private_sub2, public_sub=public_sub)) as (
|
||||
(fip1, r1), (fip2, r2)):
|
||||
|
||||
self._assert_no_assoc_fip(fip1)
|
||||
self._assert_no_assoc_fip(fip2)
|
||||
|
||||
fip1_r1_res = self._associate_and_assert_fip(fip1, p1)
|
||||
self.assertEqual(fip1_r1_res, r1['router']['id'])
|
||||
# The following operation will associate the floating
|
||||
# ip to a different router and should fail
|
||||
self._associate_and_assert_fip(fip1, p2, allow=False)
|
||||
# disassociate fip1
|
||||
self._update(
|
||||
'floatingips', fip1['floatingip']['id'],
|
||||
{'floatingip': {'port_id': None}})
|
||||
fip2_r2_res = self._associate_and_assert_fip(fip2, p2)
|
||||
self.assertEqual(fip2_r2_res, r2['router']['id'])
|
||||
|
||||
def _test_network_update_external_failure(self):
|
||||
with self.router() as r:
|
||||
with self.subnet() as s1:
|
||||
self._set_net_external(s1['subnet']['network_id'])
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'],
|
||||
s1['subnet']['network_id'])
|
||||
self._update('networks', s1['subnet']['network_id'],
|
||||
{'network': {external_net.EXTERNAL: False}},
|
||||
expected_code=exc.HTTPInternalServerError.code)
|
||||
self._remove_external_gateway_from_router(
|
||||
r['router']['id'],
|
||||
s1['subnet']['network_id'])
|
||||
|
||||
def _test_floatingip_update_different_fixed_ip_same_port(self):
|
||||
with self.subnet() as s:
|
||||
# The plugin use the last IP as a gateway
|
||||
ip_range = list(netaddr.IPNetwork(s['subnet']['cidr']))[:-1]
|
||||
fixed_ips = [{'ip_address': str(ip_range[-3])},
|
||||
{'ip_address': str(ip_range[-2])}]
|
||||
with self.port(subnet=s, fixed_ips=fixed_ips) as p:
|
||||
with self.floatingip_with_assoc(
|
||||
port_id=p['port']['id'],
|
||||
fixed_ip=str(ip_range[-3])) as fip:
|
||||
body = self._show('floatingips', fip['floatingip']['id'])
|
||||
self.assertEqual(fip['floatingip']['id'],
|
||||
body['floatingip']['id'])
|
||||
self.assertEqual(fip['floatingip']['port_id'],
|
||||
body['floatingip']['port_id'])
|
||||
self.assertEqual(str(ip_range[-3]),
|
||||
body['floatingip']['fixed_ip_address'])
|
||||
self.assertIsNotNone(body['floatingip']['router_id'])
|
||||
body_2 = self._update(
|
||||
'floatingips', fip['floatingip']['id'],
|
||||
{'floatingip': {'port_id': p['port']['id'],
|
||||
'fixed_ip_address': str(ip_range[-2])}
|
||||
})
|
||||
self.assertEqual(fip['floatingip']['port_id'],
|
||||
body_2['floatingip']['port_id'])
|
||||
self.assertEqual(str(ip_range[-2]),
|
||||
body_2['floatingip']['fixed_ip_address'])
|
||||
|
||||
def _test_floatingip_create_different_fixed_ip_same_port(self):
|
||||
"""Test to create fixed IPs using the same port.
|
||||
|
||||
This tests that it is possible to delete a port that has
|
||||
multiple floating ip addresses associated with it (each floating
|
||||
address associated with a unique fixed address).
|
||||
"""
|
||||
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='11.0.0.0/24') as public_sub:
|
||||
self._set_net_external(public_sub['subnet']['network_id'])
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'],
|
||||
public_sub['subnet']['network_id'])
|
||||
|
||||
with self.subnet() as private_sub:
|
||||
ip_range = list(netaddr.IPNetwork(
|
||||
private_sub['subnet']['cidr']))[:-1]
|
||||
fixed_ips = [{'ip_address': str(ip_range[-3])},
|
||||
{'ip_address': str(ip_range[-2])}]
|
||||
|
||||
self._router_interface_action(
|
||||
'add', r['router']['id'],
|
||||
private_sub['subnet']['id'], None)
|
||||
|
||||
with self.port(subnet=private_sub,
|
||||
fixed_ips=fixed_ips) as p:
|
||||
|
||||
fip1 = self._make_floatingip(
|
||||
self.fmt,
|
||||
public_sub['subnet']['network_id'],
|
||||
p['port']['id'],
|
||||
fixed_ip=str(ip_range[-2]))
|
||||
fip2 = self._make_floatingip(
|
||||
self.fmt,
|
||||
public_sub['subnet']['network_id'],
|
||||
p['port']['id'],
|
||||
fixed_ip=str(ip_range[-3]))
|
||||
|
||||
# Test that floating ips are assigned successfully.
|
||||
body = self._show('floatingips',
|
||||
fip1['floatingip']['id'])
|
||||
self.assertEqual(
|
||||
fip1['floatingip']['port_id'],
|
||||
body['floatingip']['port_id'])
|
||||
|
||||
body = self._show('floatingips',
|
||||
fip2['floatingip']['id'])
|
||||
self.assertEqual(
|
||||
fip2['floatingip']['port_id'],
|
||||
body['floatingip']['port_id'])
|
||||
self._delete('ports', p['port']['id'])
|
||||
|
||||
# Test that port has been successfully deleted.
|
||||
body = self._show('ports', p['port']['id'],
|
||||
expected_code=exc.HTTPNotFound.code)
|
||||
|
||||
for fip in [fip1, fip2]:
|
||||
self._delete('floatingips',
|
||||
fip['floatingip']['id'])
|
||||
|
||||
self._router_interface_action(
|
||||
'remove', r['router']['id'],
|
||||
private_sub['subnet']['id'], None)
|
||||
|
||||
self._remove_external_gateway_from_router(
|
||||
r['router']['id'],
|
||||
public_sub['subnet']['network_id'])
|
||||
|
||||
def test_router_update_gateway_with_different_external_subnet(self):
|
||||
self.skipTest("Plugin doesn't support multiple external networks")
|
||||
|
||||
def test_router_create_with_gwinfo_ext_ip_subnet(self):
|
||||
self.skipTest("Plugin doesn't support multiple external networks")
|
||||
|
||||
|
||||
class TestNuageBasicGet(NuagePluginV2TestCase,
|
||||
test_db_plugin.TestBasicGet):
|
||||
pass
|
||||
|
||||
|
||||
class TestNuageV2HTTPResponse(NuagePluginV2TestCase,
|
||||
test_db_plugin.TestV2HTTPResponse):
|
||||
pass
|
||||
|
||||
|
||||
class TestNuageNetworksV2(NuagePluginV2TestCase,
|
||||
test_db_plugin.TestNetworksV2):
|
||||
pass
|
||||
|
||||
|
||||
class TestNuageSubnetsV2(NuagePluginV2TestCase,
|
||||
test_db_plugin.TestSubnetsV2):
|
||||
|
||||
def test_create_subnet_nonzero_cidr(self):
|
||||
# The plugin requires 2 IP addresses available if gateway is set
|
||||
with contextlib.nested(
|
||||
self.subnet(cidr='10.129.122.5/8'),
|
||||
self.subnet(cidr='11.129.122.5/15'),
|
||||
self.subnet(cidr='12.129.122.5/16'),
|
||||
self.subnet(cidr='13.129.122.5/18'),
|
||||
self.subnet(cidr='14.129.122.5/22'),
|
||||
self.subnet(cidr='15.129.122.5/24'),
|
||||
self.subnet(cidr='16.129.122.5/28'),
|
||||
) as subs:
|
||||
# the API should accept and correct these for users
|
||||
self.assertEqual('10.0.0.0/8', subs[0]['subnet']['cidr'])
|
||||
self.assertEqual('11.128.0.0/15', subs[1]['subnet']['cidr'])
|
||||
self.assertEqual('12.129.0.0/16', subs[2]['subnet']['cidr'])
|
||||
self.assertEqual('13.129.64.0/18', subs[3]['subnet']['cidr'])
|
||||
self.assertEqual('14.129.120.0/22', subs[4]['subnet']['cidr'])
|
||||
self.assertEqual('15.129.122.0/24', subs[5]['subnet']['cidr'])
|
||||
self.assertEqual('16.129.122.0/28', subs[6]['subnet']['cidr'])
|
||||
|
||||
def test_create_subnet_gateway_outside_cidr(self):
|
||||
with self.network() as network:
|
||||
data = {'subnet': {'network_id': network['network']['id'],
|
||||
'cidr': '10.0.2.0/24',
|
||||
'ip_version': '4',
|
||||
'tenant_id': network['network']['tenant_id'],
|
||||
'gateway_ip': '10.0.3.1'}}
|
||||
subnet_req = self.new_create_request('subnets', data)
|
||||
res = subnet_req.get_response(self.api)
|
||||
self.assertEqual(exc.HTTPClientError.code, res.status_int)
|
||||
|
||||
def test_create_subnet_with_dhcp_port(self):
|
||||
nuage_dhcp_port = '10.0.0.254'
|
||||
with self.network() as network:
|
||||
keys = {
|
||||
'cidr': '10.0.0.0/24',
|
||||
'gateway_ip': '10.0.0.1'
|
||||
}
|
||||
with self.subnet(network=network, **keys) as subnet:
|
||||
query_params = "fixed_ips=ip_address%%3D%s" % nuage_dhcp_port
|
||||
ports = self._list('ports', query_params=query_params)
|
||||
self.assertEqual(4, subnet['subnet']['ip_version'])
|
||||
self.assertIn('name', subnet['subnet'])
|
||||
self.assertEqual(1, len(ports['ports']))
|
||||
self.assertEqual(nuage_dhcp_port,
|
||||
ports['ports'][0]['fixed_ips']
|
||||
[0]['ip_address'])
|
||||
|
||||
def test_create_subnet_with_nuage_subnet_template(self):
|
||||
with self.network() as network:
|
||||
nuage_subn_template = uuidutils.generate_uuid()
|
||||
data = {'subnet': {'tenant_id': network['network']['tenant_id']}}
|
||||
data['subnet']['cidr'] = '10.0.0.0/24'
|
||||
data['subnet']['ip_version'] = 4
|
||||
data['subnet']['network_id'] = network['network']['id']
|
||||
data['subnet']['nuage_subnet_template'] = nuage_subn_template
|
||||
subnet_req = self.new_create_request('subnets', data, 'json')
|
||||
subnet_res = subnet_req.get_response(self.api)
|
||||
self.assertEqual(exc.HTTPCreated.code, subnet_res.status_int)
|
||||
|
||||
def test_delete_subnet_port_exists_returns_409(self):
|
||||
gateway_ip = '10.0.0.1'
|
||||
cidr = '10.0.0.0/24'
|
||||
res = self._create_network(fmt=self.fmt, name='net',
|
||||
admin_state_up=True)
|
||||
network = self.deserialize(self.fmt, res)
|
||||
subnet = self._make_subnet(self.fmt, network, gateway_ip,
|
||||
cidr, ip_version=4)
|
||||
self._create_port(self.fmt,
|
||||
network['network']['id'])
|
||||
req = self.new_delete_request('subnets', subnet['subnet']['id'])
|
||||
res = req.get_response(self.api)
|
||||
self.assertEqual(409, res.status_int)
|
||||
|
||||
|
||||
class TestNuagePluginPortBinding(NuagePluginV2TestCase,
|
||||
test_bindings.PortBindingsTestCase):
|
||||
VIF_TYPE = portbindings.VIF_TYPE_OVS
|
||||
|
||||
def setUp(self):
|
||||
super(TestNuagePluginPortBinding, self).setUp()
|
||||
|
||||
def test_ports_vif_details(self):
|
||||
# The Plugin will create 2 extra ports
|
||||
plugin = manager.NeutronManager.get_plugin()
|
||||
cfg.CONF.set_default('allow_overlapping_ips', True)
|
||||
with contextlib.nested(self.port(), self.port()):
|
||||
ctx = context.get_admin_context()
|
||||
ports = plugin.get_ports(ctx)
|
||||
self.assertEqual(4, len(ports))
|
||||
for port in ports:
|
||||
self._check_response_portbindings(port)
|
||||
# By default user is admin - now test non admin user
|
||||
ctx = self._get_non_admin_context()
|
||||
ports = self._list('ports', neutron_context=ctx)['ports']
|
||||
self.assertEqual(4, len(ports))
|
||||
for non_admin_port in ports:
|
||||
self._check_response_no_portbindings(non_admin_port)
|
||||
|
||||
|
||||
class TestNuageExtrarouteTestCase(NuagePluginV2TestCase,
|
||||
extraroute_test.ExtraRouteDBIntTestCase):
|
||||
|
||||
def test_router_create_with_gwinfo_ext_ip_subnet(self):
|
||||
self.skipTest("Nuage plugin does not support multiple subnets per "
|
||||
"external network.")
|
||||
|
||||
def test_router_update_gateway_with_different_external_subnet(self):
|
||||
self.skipTest("Nuage plugin does not support multiple subnets per "
|
||||
"external networks.")
|
||||
|
||||
def test_router_update_with_dup_destination_address(self):
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s:
|
||||
with self.port(subnet=s) as p:
|
||||
self._router_interface_action('add',
|
||||
r['router']['id'],
|
||||
None,
|
||||
p['port']['id'])
|
||||
|
||||
routes = [{'destination': '135.207.0.0/16',
|
||||
'nexthop': '10.0.1.3'},
|
||||
{'destination': '135.207.0.0/16',
|
||||
'nexthop': '10.0.1.5'}]
|
||||
|
||||
self._update('routers', r['router']['id'],
|
||||
{'router': {'routes':
|
||||
routes}},
|
||||
expected_code=exc.HTTPBadRequest.code)
|
||||
|
||||
# clean-up
|
||||
self._router_interface_action('remove',
|
||||
r['router']['id'],
|
||||
None,
|
||||
p['port']['id'])
|
||||
|
||||
def test_router_update_on_external_port(self):
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s:
|
||||
self._set_net_external(s['subnet']['network_id'])
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'],
|
||||
s['subnet']['network_id'])
|
||||
body = self._show('routers', r['router']['id'])
|
||||
net_id = body['router']['external_gateway_info']['network_id']
|
||||
self.assertEqual(net_id, s['subnet']['network_id'])
|
||||
port_res = self._list_ports(
|
||||
'json',
|
||||
200,
|
||||
s['subnet']['network_id'],
|
||||
tenant_id=r['router']['tenant_id'],
|
||||
device_own=constants.DEVICE_OWNER_ROUTER_GW)
|
||||
port_list = self.deserialize('json', port_res)
|
||||
# The plugin will create 1 port
|
||||
self.assertEqual(2, len(port_list['ports']))
|
||||
|
||||
routes = [{'destination': '135.207.0.0/16',
|
||||
'nexthop': '10.0.1.3'}]
|
||||
|
||||
body = self._update('routers', r['router']['id'],
|
||||
{'router': {'routes':
|
||||
routes}})
|
||||
|
||||
body = self._show('routers', r['router']['id'])
|
||||
self.assertEqual(routes,
|
||||
body['router']['routes'])
|
||||
|
||||
self._remove_external_gateway_from_router(
|
||||
r['router']['id'],
|
||||
s['subnet']['network_id'])
|
||||
body = self._show('routers', r['router']['id'])
|
||||
gw_info = body['router']['external_gateway_info']
|
||||
self.assertIsNone(gw_info)
|
||||
|
||||
def test_floatingip_create_different_fixed_ip_same_port(self):
|
||||
self._test_floatingip_create_different_fixed_ip_same_port()
|
||||
|
||||
def test_floatingip_update_different_router(self):
|
||||
self._test_floatingip_update_different_router()
|
||||
|
||||
def test_floatingip_update_different_fixed_ip_same_port(self):
|
||||
self._test_floatingip_update_different_fixed_ip_same_port()
|
||||
|
||||
def test_network_update_external_failure(self):
|
||||
self._test_network_update_external_failure()
|
||||
|
||||
def test_update_port_with_assoc_floatingip(self):
|
||||
with self.subnet(cidr='200.0.0.0/24') as public_sub:
|
||||
self._set_net_external(public_sub['subnet']['network_id'])
|
||||
with self.port() as port:
|
||||
p_id = port['port']['id']
|
||||
with self.floatingip_with_assoc(port_id=p_id):
|
||||
# Update the port with dummy vm info
|
||||
port_dict = {
|
||||
'device_id': uuidutils.generate_uuid(),
|
||||
'device_owner': 'compute:Nova'
|
||||
}
|
||||
port = self._update('ports', port['port']['id'],
|
||||
{'port': port_dict})
|
||||
self.assertEqual(port_dict['device_id'],
|
||||
port['port']['device_id'])
|
||||
|
||||
def test_disassociated_floatingip_delete(self):
|
||||
with self.subnet(cidr='200.0.0.0/24') as public_sub:
|
||||
self._set_net_external(public_sub['subnet']['network_id'])
|
||||
with self.port() as port:
|
||||
p_id = port['port']['id']
|
||||
with self.floatingip_with_assoc(port_id=p_id) as fip:
|
||||
|
||||
# Disassociate fip from the port
|
||||
fip = self._update('floatingips', fip['floatingip']['id'],
|
||||
{'floatingip': {'port_id': None}})
|
||||
self.assertIsNone(fip['floatingip']['router_id'])
|
||||
|
||||
|
||||
class NuageRouterTestExtensionManager(object):
|
||||
|
||||
def get_resources(self):
|
||||
l3.RESOURCE_ATTRIBUTE_MAP['routers'].update(
|
||||
nuage_router.EXTENDED_ATTRIBUTES_2_0['routers'])
|
||||
return l3.L3.get_resources()
|
||||
|
||||
def get_actions(self):
|
||||
return []
|
||||
|
||||
def get_request_extensions(self):
|
||||
return []
|
||||
|
||||
|
||||
class TestNuageRouterExtTestCase(NuagePluginV2TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._l3_attribute_map_bk = copy.deepcopy(l3.RESOURCE_ATTRIBUTE_MAP)
|
||||
ext_mgr = NuageRouterTestExtensionManager()
|
||||
super(TestNuageRouterExtTestCase, self).setUp(plugin=_plugin_name,
|
||||
ext_mgr=ext_mgr)
|
||||
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
|
||||
self.addCleanup(self.restore_l3_attribute_map)
|
||||
|
||||
def restore_l3_attribute_map(self):
|
||||
l3.RESOURCE_ATTRIBUTE_MAP = self._l3_attribute_map_bk
|
||||
|
||||
def test_router_create_with_nuage_rtr_template(self):
|
||||
nuage_rtr_template = uuidutils.generate_uuid()
|
||||
data = {'router': {'tenant_id': uuidutils.generate_uuid()}}
|
||||
data['router']['name'] = 'router1'
|
||||
data['router']['admin_state_up'] = True
|
||||
data['router']['nuage_router_template'] = nuage_rtr_template
|
||||
router_req = self.new_create_request('routers', data, 'json')
|
||||
router_res = router_req.get_response(self.ext_api)
|
||||
self.assertEqual(exc.HTTPCreated.code, router_res.status_int)
|
||||
|
||||
|
||||
class TestNuageProviderNetTestCase(NuagePluginV2TestCase):
|
||||
|
||||
def test_create_provider_network(self):
|
||||
phys_net = uuidutils.generate_uuid()
|
||||
data = {'network': {'name': 'pnet1',
|
||||
'tenant_id': 'admin',
|
||||
pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: phys_net,
|
||||
pnet.SEGMENTATION_ID: 123}}
|
||||
network_req = self.new_create_request('networks', data, self.fmt)
|
||||
net = self.deserialize(self.fmt, network_req.get_response(self.api))
|
||||
self.assertEqual('vlan', net['network'][pnet.NETWORK_TYPE])
|
||||
self.assertEqual(phys_net, net['network'][pnet.PHYSICAL_NETWORK])
|
||||
self.assertEqual(123, net['network'][pnet.SEGMENTATION_ID])
|
||||
|
||||
def test_create_provider_network_no_admin(self):
|
||||
phys_net = uuidutils.generate_uuid()
|
||||
data = {'network': {'name': 'pnet1',
|
||||
'tenant_id': 'no_admin',
|
||||
pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: phys_net,
|
||||
pnet.SEGMENTATION_ID: 123}}
|
||||
network_req = self.new_create_request('networks', data, self.fmt)
|
||||
network_req.environ['neutron.context'] = context.Context(
|
||||
'', 'no_admin', is_admin=False)
|
||||
res = network_req.get_response(self.api)
|
||||
self.assertEqual(exc.HTTPForbidden.code, res.status_int)
|
||||
|
||||
def test_get_network_for_provider_network(self):
|
||||
phys_net = uuidutils.generate_uuid()
|
||||
data = {'network': {'name': 'pnet1',
|
||||
'tenant_id': 'admin',
|
||||
pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: phys_net,
|
||||
pnet.SEGMENTATION_ID: 123}}
|
||||
network_req = self.new_create_request('networks', data, self.fmt)
|
||||
res = self.deserialize(self.fmt, network_req.get_response(self.api))
|
||||
|
||||
get_req = self.new_show_request('networks', res['network']['id'])
|
||||
net = self.deserialize(self.fmt, get_req.get_response(self.api))
|
||||
self.assertEqual('vlan', net['network'][pnet.NETWORK_TYPE])
|
||||
self.assertEqual(phys_net, net['network'][pnet.PHYSICAL_NETWORK])
|
||||
self.assertEqual(123, net['network'][pnet.SEGMENTATION_ID])
|
||||
|
||||
def test_list_networks_for_provider_network(self):
|
||||
phys_net = uuidutils.generate_uuid()
|
||||
data1 = {'network': {'name': 'pnet1',
|
||||
'tenant_id': 'admin',
|
||||
pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: phys_net,
|
||||
pnet.SEGMENTATION_ID: 123}}
|
||||
network_req_1 = self.new_create_request('networks', data1, self.fmt)
|
||||
network_req_1.get_response(self.api)
|
||||
data2 = {'network': {'name': 'pnet2',
|
||||
'tenant_id': 'admin',
|
||||
pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: phys_net,
|
||||
pnet.SEGMENTATION_ID: 234}}
|
||||
network_req_2 = self.new_create_request('networks', data2, self.fmt)
|
||||
network_req_2.get_response(self.api)
|
||||
|
||||
list_req = self.new_list_request('networks')
|
||||
pnets = self.deserialize(self.fmt, list_req.get_response(self.api))
|
||||
self.assertEqual(2, len(pnets['networks']))
|
||||
self.assertEqual('vlan', pnets['networks'][0][pnet.NETWORK_TYPE])
|
||||
self.assertEqual(phys_net, pnets['networks'][0][pnet.PHYSICAL_NETWORK])
|
||||
self.assertEqual(123, pnets['networks'][0][pnet.SEGMENTATION_ID])
|
||||
self.assertEqual('vlan', pnets['networks'][1][pnet.NETWORK_TYPE])
|
||||
self.assertEqual(phys_net, pnets['networks'][1][pnet.PHYSICAL_NETWORK])
|
||||
self.assertEqual(234, pnets['networks'][1][pnet.SEGMENTATION_ID])
|
||||
|
||||
|
||||
class TestNuageSecurityGroupTestCase(NuagePluginV2TestCase,
|
||||
test_sg.TestSecurityGroups):
|
||||
|
||||
def test_list_ports_security_group(self):
|
||||
with self.network() as n:
|
||||
with self.subnet(n):
|
||||
self._create_port(self.fmt, n['network']['id'])
|
||||
req = self.new_list_request('ports')
|
||||
res = req.get_response(self.api)
|
||||
ports = self.deserialize(self.fmt, res)
|
||||
# The Nuage plugin reserve the first port
|
||||
port = ports['ports'][1]
|
||||
self.assertEqual(1, len(port[ext_sg.SECURITYGROUPS]))
|
||||
self._delete('ports', port['id'])
|
|
@ -1,332 +0,0 @@
|
|||
# Copyright 2014 Alcatel-Lucent USA Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import contextlib
|
||||
|
||||
from neutron import context
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.nuage import nuage_models
|
||||
from neutron.plugins.nuage import syncmanager as sync
|
||||
from neutron.tests.unit.nuage import test_netpartition
|
||||
from neutron.tests.unit.nuage import test_nuage_plugin
|
||||
from neutron.tests.unit import test_extension_extraroute as extraroute_test
|
||||
from neutron.tests.unit import test_extension_security_group as test_sg
|
||||
|
||||
_uuid = uuidutils.generate_uuid
|
||||
|
||||
|
||||
class TestL3Sync(test_nuage_plugin.NuagePluginV2TestCase,
|
||||
extraroute_test.ExtraRouteDBIntTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL3Sync, self).setUp()
|
||||
self.syncmanager = sync.SyncManager(
|
||||
test_nuage_plugin.getNuageClient())
|
||||
self.session = context.get_admin_context().session
|
||||
|
||||
def _make_floatingip_for_tenant_port(self, net_id, port_id, tenant_id):
|
||||
data = {'floatingip': {'floating_network_id': net_id,
|
||||
'tenant_id': tenant_id,
|
||||
'port_id': port_id}}
|
||||
floatingip_req = self.new_create_request('floatingips', data, self.fmt)
|
||||
res = floatingip_req.get_response(self.ext_api)
|
||||
return self.deserialize(self.fmt, res)
|
||||
|
||||
def test_router_sync(self):
|
||||
# If the router exists in neutron and not in VSD,
|
||||
# sync will create it in VSD. But the nuage_router_id
|
||||
# will now change and will be updated in neutron
|
||||
# accordingly
|
||||
rtr_res = self._create_router('json', 'foo', 'test-router', True)
|
||||
router = self.deserialize('json', rtr_res)
|
||||
|
||||
self.syncmanager.synchronize('250')
|
||||
|
||||
# Check that the nuage_router_id is updated in entrtrmapping table
|
||||
router_db = self.session.query(
|
||||
nuage_models.NetPartitionRouter).filter_by(
|
||||
router_id=router['router']['id']).first()
|
||||
|
||||
self.assertEqual('2d782c02-b88e-44ad-a79b-4bdf11f7df3d',
|
||||
router_db['nuage_router_id'])
|
||||
|
||||
self._delete('routers', router['router']['id'])
|
||||
|
||||
def test_router_deleted_get(self):
|
||||
data = self.syncmanager._get_router_data(_uuid())
|
||||
self.assertIsNone(data[0])
|
||||
self.assertIsNone(data[1])
|
||||
|
||||
def test_fip_sync(self):
|
||||
with self.subnet(cidr='200.0.0.0/24') as public_sub:
|
||||
self._set_net_external(public_sub['subnet']['network_id'])
|
||||
with contextlib.nested(self.port(), self.port(), self.port()) as (
|
||||
p1, p2, p3):
|
||||
p1_id = p1['port']['id']
|
||||
p2_id = p2['port']['id']
|
||||
p3_id = p3['port']['id']
|
||||
with contextlib.nested(self.floatingip_with_assoc(
|
||||
port_id=p1_id), self.floatingip_with_assoc(
|
||||
port_id=p2_id), self.floatingip_with_assoc(
|
||||
port_id=p3_id)) as (fip1, fip2, fip3):
|
||||
fip_dict = {'fip': {
|
||||
'add': [fip1['floatingip']['id']],
|
||||
'associate': [fip2['floatingip']['id']],
|
||||
'disassociate': [fip3['floatingip']['id']]
|
||||
}}
|
||||
self.syncmanager._sync_fips(fip_dict)
|
||||
|
||||
def test_deleted_fip_sync(self):
|
||||
fip_dict = {'fip': {
|
||||
'add': [_uuid()],
|
||||
'associate': [_uuid()],
|
||||
'disassociate': [_uuid()]
|
||||
}}
|
||||
self.syncmanager._sync_fips(fip_dict)
|
||||
|
||||
def test_fip_and_ipalloc_get(self):
|
||||
with self.subnet(cidr='200.0.0.0/24') as public_sub:
|
||||
self._set_net_external(public_sub['subnet']['network_id'])
|
||||
with self.port() as port:
|
||||
p_id = port['port']['id']
|
||||
with self.floatingip_with_assoc(port_id=p_id) as fip:
|
||||
|
||||
data = self.syncmanager._get_fip_data(
|
||||
fip['floatingip']['id'])
|
||||
|
||||
self.assertEqual(fip['floatingip']['id'], data['id'])
|
||||
|
||||
data = self.syncmanager._get_ipalloc_for_fip(
|
||||
fip['floatingip'])
|
||||
self.assertEqual(fip['floatingip']['floating_ip_address'],
|
||||
data['ip_address'])
|
||||
|
||||
def test_fip_and_ipalloc_deleted_get(self):
|
||||
data = self.syncmanager._get_fip_data(_uuid())
|
||||
self.assertIsNone(data)
|
||||
|
||||
fip = {
|
||||
'id': _uuid(),
|
||||
'floating_network_id': _uuid(),
|
||||
'floating_ip_address': '176.176.10.10'
|
||||
}
|
||||
data = self.syncmanager._get_ipalloc_for_fip(fip)
|
||||
self.assertIsNone(data)
|
||||
|
||||
def test_domainsubnet_sync(self):
|
||||
with self.subnet() as s1:
|
||||
with contextlib.nested(
|
||||
self.router(),
|
||||
self.port()) as (r1, p1):
|
||||
self._router_interface_action(
|
||||
'add', r1['router']['id'],
|
||||
s1['subnet']['id'], p1['port']['id'])
|
||||
domainsubn_dict = {
|
||||
'domainsubnet': {'add': [s1['subnet']['id']]},
|
||||
'port': {'sub_rtr_intf_port_dict': {s1['subnet']['id']:
|
||||
p1['port']['id']}}}
|
||||
self.syncmanager.sync_domainsubnets(domainsubn_dict)
|
||||
self._router_interface_action('remove', r1['router']['id'],
|
||||
s1['subnet']['id'], None)
|
||||
|
||||
def test_floatingip_update_different_router(self):
|
||||
self._test_floatingip_update_different_router()
|
||||
|
||||
def test_floatingip_update_different_fixed_ip_same_port(self):
|
||||
self._test_floatingip_update_different_fixed_ip_same_port()
|
||||
|
||||
def test_floatingip_create_different_fixed_ip_same_port(self):
|
||||
self._test_floatingip_create_different_fixed_ip_same_port()
|
||||
|
||||
def test_network_update_external_failure(self):
|
||||
self._test_network_update_external_failure()
|
||||
|
||||
def test_route_sync(self):
|
||||
route = {'destination': '135.207.0.0/16', 'nexthop': '10.0.1.3'}
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s:
|
||||
net_id = s['subnet']['network_id']
|
||||
res = self._create_port('json', net_id)
|
||||
p = self.deserialize(self.fmt, res)
|
||||
self._routes_update_prepare(r['router']['id'],
|
||||
None, p['port']['id'], [route])
|
||||
|
||||
route_dict = {'route': {'add': [route]}}
|
||||
self.syncmanager.sync_routes(route_dict)
|
||||
|
||||
self._routes_update_cleanup(p['port']['id'],
|
||||
None, r['router']['id'], [])
|
||||
|
||||
def test_route_get(self):
|
||||
routes = [{'destination': '135.207.0.0/16', 'nexthop': '10.0.1.3'}]
|
||||
with self.router() as r:
|
||||
with self.subnet(cidr='10.0.1.0/24') as s:
|
||||
net_id = s['subnet']['network_id']
|
||||
res = self._create_port('json', net_id)
|
||||
p = self.deserialize(self.fmt, res)
|
||||
self._routes_update_prepare(r['router']['id'],
|
||||
None, p['port']['id'], routes)
|
||||
|
||||
data = self.syncmanager._get_route_data(routes[0])
|
||||
self.assertEqual(routes[0]['destination'], data['destination'])
|
||||
self.assertEqual(routes[0]['nexthop'], data['nexthop'])
|
||||
self._routes_update_cleanup(p['port']['id'],
|
||||
None, r['router']['id'], [])
|
||||
|
||||
def test_route_deleted_get(self):
|
||||
route = {'destination': '135.207.0.0/16', 'nexthop': '10.0.1.3'}
|
||||
data = self.syncmanager._get_route_data(route)
|
||||
self.assertIsNone(data)
|
||||
|
||||
|
||||
class TestNetPartSync(test_netpartition.NetPartitionTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.syncmanager = sync.SyncManager(
|
||||
test_nuage_plugin.getNuageClient())
|
||||
super(TestNetPartSync, self).setUp()
|
||||
self.session = context.get_admin_context().session
|
||||
|
||||
def test_net_partition_sync(self):
|
||||
# If the net-partition exists in neutron and not in VSD,
|
||||
# sync will create it in VSD. But the net-partition
|
||||
# id will now change and has to be updated in neutron
|
||||
# accordingly
|
||||
netpart = self._make_netpartition('json', 'sync-new-netpartition')
|
||||
|
||||
self.syncmanager.synchronize('250')
|
||||
|
||||
# Check that the net-partition id is updated in db
|
||||
netpart_db = self.session.query(
|
||||
nuage_models.NetPartition).filter_by(name=netpart['net_partition'][
|
||||
'name']).first()
|
||||
|
||||
self.assertEqual('a917924f-3139-4bdb-a4c3-ea7c8011582f',
|
||||
netpart_db['id'])
|
||||
self._del_netpartition(netpart_db['id'])
|
||||
|
||||
def test_net_partition_deleted_get(self):
|
||||
data = self.syncmanager._get_netpart_data(_uuid())
|
||||
self.assertIsNone(data)
|
||||
|
||||
|
||||
class TestL2Sync(test_nuage_plugin.NuagePluginV2TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL2Sync, self).setUp()
|
||||
self.syncmanager = sync.SyncManager(
|
||||
test_nuage_plugin.getNuageClient())
|
||||
self.session = context.get_admin_context().session
|
||||
|
||||
def test_subnet_sync(self):
|
||||
# If the subnet exists in neutron and not in VSD,
|
||||
# sync will create it in VSD. But the nuage_subnet_id
|
||||
# will now change and will be updated in neutron
|
||||
# accordingly
|
||||
net_res = self._create_network("json", "pub", True)
|
||||
network = self.deserialize('json', net_res)
|
||||
|
||||
sub_res = self._create_subnet("json", network['network']['id'],
|
||||
'10.0.0.0/24')
|
||||
subnet = self.deserialize('json', sub_res)
|
||||
|
||||
self.syncmanager.synchronize('250')
|
||||
|
||||
# Check that the nuage_subnet_id is updated in db
|
||||
subl2dom_db = self.session.query(
|
||||
nuage_models.SubnetL2Domain).filter_by(subnet_id=subnet[
|
||||
'subnet']['id']).first()
|
||||
self.assertEqual('52daa465-cf33-4efd-91d3-f5bc2aebd',
|
||||
subl2dom_db['nuage_subnet_id'])
|
||||
|
||||
self._delete('subnets', subnet['subnet']['id'])
|
||||
self._delete('networks', network['network']['id'])
|
||||
|
||||
def test_subnet_deleted_get(self):
|
||||
data = self.syncmanager._get_subnet_data(_uuid())
|
||||
self.assertIsNone(data[0])
|
||||
self.assertIsNone(data[1])
|
||||
|
||||
def test_sharednetwork_sync(self):
|
||||
with self.subnet(cidr='200.0.0.0/24') as public_sub:
|
||||
sharednet_dict = {'sharednetwork': {'add': [public_sub['subnet'][
|
||||
'id']]}}
|
||||
self.syncmanager.sync_sharednetworks(sharednet_dict)
|
||||
|
||||
def test_vm_sync(self):
|
||||
with self.port() as p:
|
||||
port_dict = {'port': {'vm': [p['port']['id']]}}
|
||||
self.syncmanager.sync_vms(port_dict)
|
||||
|
||||
|
||||
class TestSecurityGroupSync(test_sg.TestSecurityGroups):
|
||||
|
||||
def setUp(self):
|
||||
self.syncmanager = sync.SyncManager(
|
||||
test_nuage_plugin.getNuageClient())
|
||||
super(TestSecurityGroupSync, self).setUp()
|
||||
self.session = context.get_admin_context().session
|
||||
|
||||
def test_sg_get(self):
|
||||
with self.security_group() as sg:
|
||||
data = self.syncmanager._get_sec_grp_data(
|
||||
sg['security_group']['id'])
|
||||
self.assertEqual(sg['security_group']['id'], data['id'])
|
||||
|
||||
def test_sg_deleted_get(self):
|
||||
data = self.syncmanager._get_sec_grp_data(_uuid())
|
||||
self.assertIsNone(data)
|
||||
|
||||
def test_sg_rule_get(self):
|
||||
with self.security_group() as sg:
|
||||
sg_rule_id = sg['security_group']['security_group_rules'][0]['id']
|
||||
data = self.syncmanager._get_sec_grp_rule_data(sg_rule_id)
|
||||
self.assertEqual(sg_rule_id, data['id'])
|
||||
|
||||
def test_sg_rule_deleted_get(self):
|
||||
data = self.syncmanager._get_sec_grp_rule_data(_uuid())
|
||||
self.assertIsNone(data)
|
||||
|
||||
def test_sg_grp_sync(self):
|
||||
with contextlib.nested(self.security_group(),
|
||||
self.security_group()) as (sg1, sg2):
|
||||
sg1_id = sg1['security_group']['id']
|
||||
sg2_id = sg2['security_group']['id']
|
||||
sg_dict = {'security': {'secgroup': {'l2domain': {'add': {sg1_id: [
|
||||
_uuid()]}}, 'domain': {'add': {sg2_id: [_uuid()]}}}}}
|
||||
self.syncmanager.sync_secgrps(sg_dict)
|
||||
|
||||
def test_deleted_sg_grp_sync(self):
|
||||
sg_dict = {'security': {'secgroup': {'l2domain': {'add': {_uuid(): [
|
||||
_uuid()]}}, 'domain': {'add': {_uuid(): [_uuid()]}}}}}
|
||||
self.syncmanager.sync_secgrps(sg_dict)
|
||||
|
||||
def test_sg_rule_sync(self):
|
||||
with contextlib.nested(self.security_group(),
|
||||
self.security_group()) as (sg1, sg2):
|
||||
sg1_rule_id = (
|
||||
sg1['security_group']['security_group_rules'][0]['id'])
|
||||
sg2_rule_id = (
|
||||
sg2['security_group']['security_group_rules'][0]['id'])
|
||||
|
||||
sg_dict = {'security': {'secgrouprule': {'l2domain': {
|
||||
'add': [sg1_rule_id]}, 'domain': {'add': [sg2_rule_id]}}}}
|
||||
self.syncmanager.sync_secgrp_rules(sg_dict)
|
||||
|
||||
def test_deleted_sg_grp_rule_sync(self):
|
||||
sg_dict = {'security': {'secgrouprule':
|
||||
{'l2domain': {'add': [_uuid()]},
|
||||
'domain': {'add': [_uuid()]}}}}
|
||||
self.syncmanager.sync_secgrp_rules(sg_dict)
|
Loading…
Reference in New Issue