Using vlan id assigned by neutron instead of NWA.
If use_neutron_vlan_id in necnwa.ini is True, the NWA plugin uses a vlan id which was assigned by neutron instead of NWA. Change-Id: I84e58e4c61abbe3fe8932523b807ce0dda7884d2
This commit is contained in:
parent
fff1cea302
commit
d2a15d8eb6
|
@ -104,11 +104,17 @@ It is usually placed at ``/etc/neutron/plugins/nec/necnwa.ini``.
|
|||
|
||||
resource_group_file = resource_group.json
|
||||
|
||||
* **use_necnwa_router**: If you use OpenStack L3 Router insted of NEC NWA Router,
|
||||
* **use_necnwa_router**: If you use OpenStack L3 Router instead of NEC NWA Router,
|
||||
it set to False. The default value is True. ::
|
||||
|
||||
use_necnwa_router = True
|
||||
|
||||
* **use_neutron_vlan_id**: If you want to use a vlan id which is
|
||||
assigned by neutron, it set to True. The default value is False. In
|
||||
case of False, the vlan id will be assigned by NWA. ::
|
||||
|
||||
use_neutron_vlan_id = True
|
||||
|
||||
NWA resource group file
|
||||
=======================
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ server_url = http://192.168.122.166:12081
|
|||
access_key_id = mjivAk6O3G4Ko/0mD8mHUyQwqugEPgTe0FSli8REyN4=
|
||||
secret_access_key = /3iSORtq1E3F+SQtQg6YN00eM3GUda0EKqWDUV/mvqo=
|
||||
use_necnwa_router = True
|
||||
use_neutron_vlan_id = False
|
||||
resource_group_name = OpenStack/DC/APP
|
||||
scenario_polling_timer = 5
|
||||
scenario_polling_count = 300
|
||||
|
|
|
@ -58,7 +58,7 @@ class NECNWANeutronAgent(object):
|
|||
self.conf = cfg.CONF
|
||||
self.host = socket.gethostname()
|
||||
self.agent_id = 'necnwa-q-agent.%s' % self.host
|
||||
|
||||
self.multi_dc = cfg.CONF.NWA.use_neutron_vlan_id
|
||||
self.client = nwa_cli.NwaClient()
|
||||
|
||||
self.agent_state = {
|
||||
|
@ -71,8 +71,8 @@ class NECNWANeutronAgent(object):
|
|||
|
||||
self.server_manager = server_manager.ServerManager(self.topic, self)
|
||||
self.proxy_tenant = proxy_tenant.AgentProxyTenant(self, self.client)
|
||||
self.proxy_l2 = proxy_l2.AgentProxyL2(self, self.client)
|
||||
self.proxy_l3 = proxy_l3.AgentProxyL3(self, self.client)
|
||||
self.proxy_l2 = proxy_l2.AgentProxyL2(self, self.client, self.multi_dc)
|
||||
self.proxy_l3 = proxy_l3.AgentProxyL3(self, self.client, self.multi_dc)
|
||||
self.setup_rpc()
|
||||
|
||||
LOG.debug('NWA Agent state %s', self.agent_state)
|
||||
|
|
|
@ -102,12 +102,13 @@ def get_resource_group_name(nwa_info, nwa_data, dev_type):
|
|||
|
||||
class AgentProxyL2(object):
|
||||
|
||||
def __init__(self, agent_top, client):
|
||||
def __init__(self, agent_top, client, multi_dc=False):
|
||||
self.nwa_tenant_rpc = tenant_binding_api.TenantBindingServerRpcApi(
|
||||
topics.PLUGIN)
|
||||
self.nwa_l2_rpc = nwa_l2_server_api.NwaL2ServerRpcApi(topics.PLUGIN)
|
||||
self.agent_top = agent_top
|
||||
self.client = client
|
||||
self.multi_dc = multi_dc
|
||||
|
||||
@property
|
||||
def proxy_tenant(self):
|
||||
|
@ -296,9 +297,12 @@ class AgentProxyL2(object):
|
|||
|
||||
# create general dev
|
||||
if not check_segment_gd(network_id, resource_group_name, nwa_data):
|
||||
if self.multi_dc:
|
||||
sync_vlan_id = self._create_connect_port
|
||||
else:
|
||||
sync_vlan_id = self._create_general_dev
|
||||
# raise AgentProxyException if fail
|
||||
nwa_data = self._create_general_dev(
|
||||
context, nwa_data=nwa_data, **kwargs)
|
||||
nwa_data = sync_vlan_id(context, nwa_data=nwa_data, **kwargs)
|
||||
else:
|
||||
ret_val = self._create_general_dev_data(
|
||||
nwa_data=nwa_data, **kwargs)
|
||||
|
@ -436,10 +440,12 @@ class AgentProxyL2(object):
|
|||
self._delete_general_dev_segment(context, nwa_data, nwa_info)
|
||||
raise nwa_exc.AgentProxyException(value=nwa_data)
|
||||
|
||||
# delete general dev
|
||||
if self.multi_dc:
|
||||
sync_vlan_id = self._delete_connect_port
|
||||
else:
|
||||
sync_vlan_id = self._delete_general_dev
|
||||
# raise AgentProxyException if fail
|
||||
nwa_data = self._delete_general_dev(context,
|
||||
nwa_data=nwa_data, **kwargs)
|
||||
nwa_data = sync_vlan_id(context, nwa_data=nwa_data, **kwargs)
|
||||
# delete general dev end
|
||||
|
||||
return self._terminate_l2_network(context, nwa_data, **kwargs)
|
||||
|
@ -557,3 +563,78 @@ class AgentProxyL2(object):
|
|||
# delete general dev end
|
||||
|
||||
return nwa_data
|
||||
|
||||
@utils.log_method_return_value
|
||||
@helpers.log_method_call
|
||||
def create_connect_port(self, context, **kwargs):
|
||||
nwa_info = kwargs['nwa_info']
|
||||
nwa_data = kwargs['nwa_data']
|
||||
network_id = nwa_info['network']['id']
|
||||
vlan_id = nwa_info['network']['vlan_id']
|
||||
resource_group_name = nwa_info['resource_group_name']
|
||||
rcode, body = self.client.l2.create_connect_port(
|
||||
kwargs.get('nwa_tenant_id'),
|
||||
resource_group_name,
|
||||
data_utils.get_vlan_logical_name(nwa_data, network_id),
|
||||
nwa_info['network']['vlan_type'],
|
||||
vlan_id
|
||||
)
|
||||
if rcode == 200 and body['status'] == 'SUCCEED':
|
||||
LOG.debug("CreateConnectPort SUCCEED")
|
||||
return body
|
||||
|
||||
@utils.log_method_return_value
|
||||
@helpers.log_method_call
|
||||
def _create_connect_port(self, context, **kwargs):
|
||||
body = self.create_connect_port(context, **kwargs)
|
||||
if body:
|
||||
nwa_data = kwargs['nwa_data']
|
||||
nwa_info = kwargs['nwa_info']
|
||||
network_id = nwa_info['network']['id']
|
||||
vlan_id = nwa_info['network']['vlan_id']
|
||||
resource_group_name = nwa_info['resource_group_name']
|
||||
vlan_key = data_utils.get_vlan_key(network_id)
|
||||
if vlan_key not in nwa_data:
|
||||
LOG.error(_LE("not create vlan."))
|
||||
raise nwa_exc.AgentProxyException(value=nwa_data)
|
||||
data_utils.set_vp_net_data(nwa_data, network_id,
|
||||
resource_group_name,
|
||||
nwa_const.NWA_DEVICE_GDV,
|
||||
vlan_id)
|
||||
self._append_device_for_gdv(nwa_info, nwa_data)
|
||||
else:
|
||||
LOG.debug("CreateConnectPort %s", body['status'])
|
||||
raise nwa_exc.AgentProxyException(value=nwa_data)
|
||||
return nwa_data
|
||||
|
||||
@utils.log_method_return_value
|
||||
@helpers.log_method_call
|
||||
def delete_connect_port(self, context, **kwargs):
|
||||
nwa_info = kwargs['nwa_info']
|
||||
nwa_data = kwargs['nwa_data']
|
||||
network_id = nwa_info['network']['id']
|
||||
vlan_id = nwa_info['network']['vlan_id']
|
||||
resource_group_name = nwa_info['resource_group_name']
|
||||
rcode, body = self.client.l2.delete_connect_port(
|
||||
kwargs['nwa_tenant_id'],
|
||||
resource_group_name,
|
||||
data_utils.get_vlan_logical_name(nwa_data, network_id),
|
||||
nwa_info['network']['vlan_type'],
|
||||
vlan_id
|
||||
)
|
||||
if rcode == 200 and body['status'] == 'SUCCEED':
|
||||
LOG.debug("DeleteConnectPort SUCCEED")
|
||||
return body
|
||||
|
||||
@utils.log_method_return_value
|
||||
@helpers.log_method_call
|
||||
def _delete_connect_port(self, context, **kwargs):
|
||||
body = self.delete_connect_port(context, **kwargs)
|
||||
if body:
|
||||
nwa_data = self._delete_general_dev_data(**kwargs)
|
||||
self._delete_general_dev_segment(context, nwa_data,
|
||||
kwargs['nwa_info'])
|
||||
else:
|
||||
LOG.debug("DeleteConnectPort %s", body['status'])
|
||||
raise nwa_exc.AgentProxyException(value=kwargs['nwa_data'])
|
||||
return nwa_data
|
||||
|
|
|
@ -39,7 +39,7 @@ LOG = logging.getLogger(__name__)
|
|||
# pylint: disable=too-many-instance-attributes
|
||||
class AgentProxyL3(object):
|
||||
|
||||
def __init__(self, agent_top, client,
|
||||
def __init__(self, agent_top, client, multi_dc=False,
|
||||
tenant_fw_create_hook=None,
|
||||
tenant_fw_delete_hook=None,
|
||||
tenant_fw_connect_hook=None,
|
||||
|
@ -50,6 +50,7 @@ class AgentProxyL3(object):
|
|||
self.nwa_l3_rpc = nwa_l3_server_api.NwaL3ServerRpcApi(topics.L3PLUGIN)
|
||||
self.agent_top = agent_top
|
||||
self.client = client
|
||||
self.multi_dc = multi_dc
|
||||
self.tenant_fw_create_hook = tenant_fw_create_hook
|
||||
self.tenant_fw_delete_hook = tenant_fw_delete_hook
|
||||
self.tenant_fw_connect_hook = tenant_fw_connect_hook
|
||||
|
@ -107,6 +108,9 @@ class AgentProxyL3(object):
|
|||
|
||||
@utils.log_method_return_value
|
||||
def _create_tenant_fw(self, nwa_data, context, **kwargs):
|
||||
if self.multi_dc:
|
||||
self.proxy_l2.create_connect_port(context, nwa_data=nwa_data,
|
||||
**kwargs)
|
||||
device_id = kwargs['nwa_info']['device']['id']
|
||||
network_id = kwargs['nwa_info']['network']['id']
|
||||
rcode, body = self.client.l3.create_tenant_fw(
|
||||
|
@ -153,8 +157,9 @@ class AgentProxyL3(object):
|
|||
return kwargs['nwa_data']
|
||||
|
||||
def _update_tenant_fw_connect(self, context, **kwargs):
|
||||
if self.multi_dc:
|
||||
self.proxy_l2.create_connect_port(context, **kwargs)
|
||||
nwa_data = kwargs.get('nwa_data')
|
||||
|
||||
device_id = kwargs['nwa_info']['device']['id']
|
||||
network_id = kwargs['nwa_info']['network']['id']
|
||||
|
||||
|
@ -196,8 +201,9 @@ class AgentProxyL3(object):
|
|||
@return: nwa_data
|
||||
@raise AgentProxyException
|
||||
"""
|
||||
if self.multi_dc:
|
||||
self.proxy_l2.delete_connect_port(context, **kwargs)
|
||||
nwa_data = kwargs.get('nwa_data')
|
||||
|
||||
device_id = kwargs['nwa_info']['device']['id']
|
||||
network_id = kwargs['nwa_info']['network']['id']
|
||||
device_name = data_utils.get_tfw_device_name(nwa_data, device_id)
|
||||
|
@ -242,6 +248,8 @@ class AgentProxyL3(object):
|
|||
@param kwargs: nwa_tenant_id, nwa_tenant_id, nwa_info, nwa_data
|
||||
@return: resutl(succeed = True, other = False), data(nwa_data or None)
|
||||
"""
|
||||
if self.multi_dc:
|
||||
self.proxy_l2.delete_connect_port(context, **kwargs)
|
||||
nwa_data = kwargs.get('nwa_data')
|
||||
nwa_info = kwargs['nwa_info']
|
||||
|
||||
|
|
|
@ -47,8 +47,11 @@ NWA_opts = [
|
|||
cfg.IntOpt('scenario_polling_count', default=6,
|
||||
help=_("Count value for polling scenario status.")),
|
||||
cfg.BoolOpt('use_necnwa_router',
|
||||
help=_("Using necnwa_router insted of the l3-router"),
|
||||
help=_("Using necnwa_router instead of the l3-router"),
|
||||
default=True),
|
||||
cfg.BoolOpt('use_neutron_vlan_id',
|
||||
help=_("Using vlan id of neutron instead of NWA"),
|
||||
default=False),
|
||||
cfg.StrOpt('ironic_az_prefix',
|
||||
help=_("The prefix name of device_owner used in ironic"),
|
||||
default='BM_'),
|
||||
|
|
|
@ -42,6 +42,7 @@ class NECNWAMechanismDriver(ovs.OpenvswitchMechanismDriver):
|
|||
'resource_group', cfg.CONF.NWA.resource_group_file,
|
||||
cfg.CONF.NWA.resource_group, default_value=[])
|
||||
self.necnwa_router = cfg.CONF.NWA.use_necnwa_router
|
||||
self.multi_dc = cfg.CONF.NWA.use_neutron_vlan_id
|
||||
|
||||
def _get_l2api_proxy(self, context, tenant_id):
|
||||
proxy = context._plugin.get_nwa_proxy(tenant_id,
|
||||
|
@ -124,6 +125,8 @@ class NECNWAMechanismDriver(ovs.OpenvswitchMechanismDriver):
|
|||
return res['ResourceGroupName']
|
||||
|
||||
def _bind_segment_to_vif_type(self, context, physical_network):
|
||||
if self.multi_dc:
|
||||
return
|
||||
network_id = context.network.current['id']
|
||||
session = context.network._plugin_context.session
|
||||
dummy_segment = db.get_dynamic_segment(
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# under the License.
|
||||
|
||||
from neutron.db import external_net_db
|
||||
from neutron.plugins.ml2 import db as db_ml2
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron_lib import constants
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -57,6 +59,21 @@ def is_external_network(context, net_id):
|
|||
return False
|
||||
|
||||
|
||||
def get_vlan_id_of_physical_network(context, network_id, physical_network):
|
||||
if hasattr(context, 'session'):
|
||||
session = context.session
|
||||
else:
|
||||
session = context.network._plugin_context.session
|
||||
segments = db_ml2.get_network_segments(session, network_id)
|
||||
if not segments:
|
||||
return ''
|
||||
for segment in segments:
|
||||
if segment[api.PHYSICAL_NETWORK] == physical_network:
|
||||
return str(segment[api.SEGMENTATION_ID])
|
||||
return str(segments[0][api.SEGMENTATION_ID])
|
||||
|
||||
|
||||
# pylint: disable=too-many-locals
|
||||
def portcontext_to_nwa_info(context, resource_groups,
|
||||
use_original_port=False):
|
||||
tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context)
|
||||
|
@ -64,6 +81,12 @@ def portcontext_to_nwa_info(context, resource_groups,
|
|||
|
||||
port = context.original if use_original_port else context.current
|
||||
device_owner = port['device_owner']
|
||||
resource_group_name = _get_resource_group_name(context, resource_groups,
|
||||
use_original_port)
|
||||
physical_network = get_physical_network(device_owner, resource_groups,
|
||||
resource_group_name)
|
||||
vlan_id = get_vlan_id_of_physical_network(context, network_id,
|
||||
physical_network)
|
||||
vlan_type = 'PublicVLAN' if is_external_network(context, network_id) \
|
||||
else 'BusinessVLAN'
|
||||
|
||||
|
@ -74,6 +97,7 @@ def portcontext_to_nwa_info(context, resource_groups,
|
|||
'nwa_tenant_id': nwa_tenant_id,
|
||||
'network': {'id': network_id,
|
||||
'name': network_name,
|
||||
'vlan_id': vlan_id,
|
||||
'vlan_type': vlan_type},
|
||||
'device': {'owner': device_owner,
|
||||
'id': port['device_id']},
|
||||
|
@ -96,14 +120,9 @@ def portcontext_to_nwa_info(context, resource_groups,
|
|||
'ip': '',
|
||||
'mac': port['mac_address']}
|
||||
|
||||
resource_group_name = _get_resource_group_name(context, resource_groups,
|
||||
use_original_port)
|
||||
nwa_info['resource_group_name'] = resource_group_name
|
||||
nwa_info['resource_group_name_nw'] = cfg.CONF.NWA.resource_group_name
|
||||
nwa_info['physical_network'] = get_physical_network(device_owner,
|
||||
resource_groups,
|
||||
resource_group_name)
|
||||
|
||||
nwa_info['physical_network'] = physical_network
|
||||
return nwa_info
|
||||
|
||||
|
||||
|
|
|
@ -114,3 +114,35 @@ class NwaClientL2(object):
|
|||
return self.client.call_workflow(
|
||||
tenant_id, self.client.post, 'DeleteGeneralDev', body
|
||||
)
|
||||
|
||||
# --- Connect Port ---
|
||||
|
||||
def create_connect_port(self, tenant_id, dc_resource_group_name,
|
||||
logical_name, vlan_type, vlan_id):
|
||||
body = {
|
||||
'CreateNW_DCResourceGroupName': dc_resource_group_name,
|
||||
'CreateNW_DeviceType1': 'GeneralDev',
|
||||
'CreateNW_OperationType': 'CreateConnectPort',
|
||||
'CreateNW_VlanID1': vlan_id,
|
||||
'CreateNW_VlanLogicalName1': logical_name,
|
||||
'CreateNW_VlanType1': vlan_type,
|
||||
'TenantID': tenant_id,
|
||||
}
|
||||
return self.client.call_workflow(
|
||||
tenant_id, self.client.post, 'CreateConnectPort', body
|
||||
)
|
||||
|
||||
def delete_connect_port(self, tenant_id, dc_resource_group_name,
|
||||
logical_name, vlan_type, vlan_id):
|
||||
body = {
|
||||
'DeleteNW_DCResourceGroupName': dc_resource_group_name,
|
||||
'DeleteNW_DeviceType1': 'GeneralDev',
|
||||
'DeleteNW_OperationType': 'DeleteConnectPort',
|
||||
'DeleteNW_VlanID1': vlan_id,
|
||||
'DeleteNW_VlanLogicalName1': logical_name,
|
||||
'DeleteNW_VlanType1': vlan_type,
|
||||
'TenantID': tenant_id,
|
||||
}
|
||||
return self.client.call_workflow(
|
||||
tenant_id, self.client.post, 'DeleteConnectPort', body
|
||||
)
|
||||
|
|
|
@ -38,6 +38,8 @@ class NwaWorkflow(object):
|
|||
'CreateTenantLB': '40030092',
|
||||
'UpdateTenantLB': '40030093',
|
||||
'DeleteTenantLB': '40030094',
|
||||
'CreateConnectPort': '50000001',
|
||||
'DeleteConnectPort': '50000002',
|
||||
}
|
||||
_errno = {
|
||||
'1': 'Unknown parent node',
|
||||
|
|
|
@ -35,9 +35,12 @@ def _init_nwa_client_patch(mocked_nwacli):
|
|||
mocked_nwacli.l2.create_general_dev.return_value = succeed
|
||||
mocked_nwacli.l2.create_tenant_nw.return_value = succeed
|
||||
mocked_nwacli.l2.create_vlan.return_value = succeed
|
||||
mocked_nwacli.l2.create_connect_port.return_value = succeed
|
||||
|
||||
mocked_nwacli.l2.delete_general_dev.return_value = succeed
|
||||
mocked_nwacli.l2.delete_tenant_nw.return_value = succeed
|
||||
mocked_nwacli.l2.delete_vlan.return_value = succeed
|
||||
mocked_nwacli.l2.delete_connect_port.return_value = succeed
|
||||
|
||||
|
||||
class TestNWAAgentBase(base.BaseTestCase):
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "546a8551-5c2b-4050-a769-cc3c962fc5cf",
|
||||
"name": "net100",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"physical_network": "OpenStack/DC1/APP",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "b2246c56-d465-49c7-a332-f329aa524277",
|
||||
"name": "net101",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"physical_network": "OpenStack/DC1/APP",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4",
|
||||
"name": "pj1-net100",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4",
|
||||
"name": "pj1-net100",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "a94fd0fc-2282-4092-9485-b0f438b0f6c4",
|
||||
"name": "pj1-net100",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC1_844eb55f21e84a289e9c22098d387e5d",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0ed65870-9acb-48ce-8c0b-e803d527a9d2",
|
||||
"name": "net100",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC02_844eb55f21e84a289e9c22098d387e5d",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "0f17fa8f-40fe-43bd-8573-1a1e1bfb699d",
|
||||
"name": "net01",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "DC_KILO3_5d9c51b1d6a34133bb735d4988b309c2",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"network": {
|
||||
"id": "315414a5-8d06-4d8e-8932-6f73665e5733",
|
||||
"name": "LNetA",
|
||||
"vlan_id": "123",
|
||||
"vlan_type": "BusinessVLAN"
|
||||
},
|
||||
"nwa_tenant_id": "T01DC7483b391c2c647c59097240d59e705d4",
|
||||
|
|
|
@ -241,11 +241,23 @@ class TestAgentProxyL2CreateGeneralDev(testscenarios.WithScenarios,
|
|||
load_data_file(self.retval_create_vlan[1])
|
||||
)
|
||||
|
||||
self.agent.proxy_l2.multi_dc = False
|
||||
if isinstance(self.gtb_data, six.string_types):
|
||||
gtb.return_value = load_data_file(self.gtb_data)
|
||||
else:
|
||||
gtb.return_value = self.gtb_data
|
||||
self.agent.proxy_l2.create_general_dev(
|
||||
context,
|
||||
tenant_id=tenant_id,
|
||||
nwa_tenant_id=nwa_tenant_id,
|
||||
nwa_info=nwa_info
|
||||
)
|
||||
|
||||
self.agent.proxy_l2.multi_dc = True
|
||||
if isinstance(self.gtb_data, six.string_types):
|
||||
gtb.return_value = load_data_file(self.gtb_data)
|
||||
else:
|
||||
gtb.return_value = self.gtb_data
|
||||
self.agent.proxy_l2.create_general_dev(
|
||||
context,
|
||||
tenant_id=tenant_id,
|
||||
|
@ -364,11 +376,23 @@ class TestAgentProxyL2DeleteGeneralDev(testscenarios.WithScenarios,
|
|||
load_data_file(self.retval_delete_vlan[1])
|
||||
)
|
||||
|
||||
self.agent.proxy_l2.multi_dc = False
|
||||
if isinstance(self.gtb_data, six.string_types):
|
||||
gtb.return_value = load_data_file(self.gtb_data)
|
||||
else:
|
||||
gtb.return_value = self.gtb_data
|
||||
self.agent.proxy_l2.delete_general_dev(
|
||||
context,
|
||||
tenant_id=tenant_id,
|
||||
nwa_tenant_id=nwa_tenant_id,
|
||||
nwa_info=nwa_info
|
||||
)
|
||||
|
||||
self.agent.proxy_l2.multi_dc = True
|
||||
if isinstance(self.gtb_data, six.string_types):
|
||||
gtb.return_value = load_data_file(self.gtb_data)
|
||||
else:
|
||||
gtb.return_value = self.gtb_data
|
||||
self.agent.proxy_l2.delete_general_dev(
|
||||
context,
|
||||
tenant_id=tenant_id,
|
||||
|
|
|
@ -46,6 +46,10 @@ class TestNWAConfig(base.BaseTestCase):
|
|||
self.assertIsInstance(cfg.CONF.NWA.use_necnwa_router, bool)
|
||||
self.assertTrue(cfg.CONF.NWA.use_necnwa_router)
|
||||
|
||||
def test_section_default_NWA_use_neutron_vlan_id(self):
|
||||
self.assertIsInstance(cfg.CONF.NWA.use_neutron_vlan_id, bool)
|
||||
self.assertFalse(cfg.CONF.NWA.use_neutron_vlan_id)
|
||||
|
||||
def test_section_default_NWA_ironic_az_prefix(self):
|
||||
self.assertEqual(cfg.CONF.NWA.ironic_az_prefix, 'BM_')
|
||||
|
||||
|
|
|
@ -37,6 +37,20 @@ class TestNwa(base.BaseTestCase):
|
|||
return
|
||||
pass
|
||||
|
||||
class network_segment(object):
|
||||
id = '1'
|
||||
network_id = 0
|
||||
network_type = 'vlan'
|
||||
physical_network = 'Phys1'
|
||||
segmentation_id = '1001'
|
||||
|
||||
def __init__(self, id_, nid, ntype, physnet, vid):
|
||||
self.id = id_
|
||||
self.network_id = nid
|
||||
self.network_type = ntype
|
||||
self.physical_network = physnet
|
||||
self.segmentation_id = vid
|
||||
|
||||
self.context = network_context()
|
||||
self.context.network.current = {}
|
||||
self.context.network.current['tenant_id'] = 'T1'
|
||||
|
@ -84,20 +98,27 @@ class TestNwa(base.BaseTestCase):
|
|||
{
|
||||
"physical_network": "Common/KVM/Pod1-1",
|
||||
"id": "uuid-1-1",
|
||||
"segmentation_id": 100
|
||||
"segmentation_id": '100'
|
||||
},
|
||||
{
|
||||
"physical_network": "Common/KVM/Pod1-2",
|
||||
"id": "uuid-1-2",
|
||||
"segmentation_id": 101
|
||||
"segmentation_id": '101'
|
||||
},
|
||||
{
|
||||
"physical_network": "Common/App/Pod3",
|
||||
"id": "uuid-1-3",
|
||||
"segmentation_id": 102
|
||||
"segmentation_id": '102'
|
||||
}
|
||||
]
|
||||
|
||||
self.segments_db = []
|
||||
for segment in self.network_segments:
|
||||
self.segments_db.append(network_segment(
|
||||
self.context.network.current['id'],
|
||||
segment['id'], 'vlan',
|
||||
segment['physical_network'], segment['segmentation_id']))
|
||||
|
||||
self.resource_group = [
|
||||
{
|
||||
"physical_network": "Common/BM/Pod1-1",
|
||||
|
@ -189,6 +210,38 @@ class TestGetPhysicalNetwork(TestNwa):
|
|||
self.assertIsNone(pnet)
|
||||
|
||||
|
||||
class TestGetVlanIdOfPhysicalNetwork(TestNwa):
|
||||
def test_segment_not_found(self):
|
||||
network_id = 'uuid-1-2'
|
||||
physical_network = 'Common/KVM/Pod1-2'
|
||||
self.context.network.session = MagicMock()
|
||||
self.context.network.session.query().filter().order_by().filter_by().\
|
||||
all.return_value = []
|
||||
vid = nwa_l2_utils.get_vlan_id_of_physical_network(
|
||||
self.context.network, network_id, physical_network)
|
||||
self.assertEqual(vid, '')
|
||||
|
||||
def test_physical_network_not_found(self):
|
||||
network_id = 'uuid-1-2'
|
||||
physical_network = 'Common/KVM/Pod1-X'
|
||||
self.context.network.session = MagicMock()
|
||||
self.context.network.session.query().filter().order_by().filter_by().\
|
||||
all.return_value = [self.segments_db[1]]
|
||||
vid = nwa_l2_utils.get_vlan_id_of_physical_network(
|
||||
self.context.network, network_id, physical_network)
|
||||
self.assertEqual(vid, '101')
|
||||
|
||||
def test_found(self):
|
||||
network_id = 'uuid-1-2'
|
||||
physical_network = 'Common/KVM/Pod1-2'
|
||||
self.context.network.session = MagicMock()
|
||||
self.context.network.session.query().filter().order_by().filter_by().\
|
||||
all.return_value = [self.segments_db[1]]
|
||||
vid = nwa_l2_utils.get_vlan_id_of_physical_network(
|
||||
self.context.network, network_id, physical_network)
|
||||
self.assertEqual(vid, '101')
|
||||
|
||||
|
||||
class TestPortcontextToNwaInfo(TestNwa):
|
||||
def test_portcontext_to_nwa_info(self):
|
||||
self.context.current = self.context._port
|
||||
|
@ -202,6 +255,11 @@ class TestPortcontextToNwaInfo(TestNwa):
|
|||
self.assertEqual(rd['port']['id'], p['id'])
|
||||
self.assertEqual(rd['port']['ip'], p['fixed_ips'][0]['ip_address'])
|
||||
self.assertEqual(rd['port']['mac'], p['mac_address'])
|
||||
c = self.context.network.current
|
||||
self.assertEqual(rd['network']['id'], c['id'])
|
||||
self.assertEqual(rd['network']['name'], c['name'])
|
||||
self.assertEqual(rd['network']['vlan_type'], 'PublicVLAN')
|
||||
self.assertEqual(rd['network']['vlan_id'], '')
|
||||
|
||||
def test_portcontext_to_nwa_info_business_vlan(self):
|
||||
# session in context
|
||||
|
|
|
@ -214,3 +214,45 @@ class TestNwaClientL2(test_client.TestNwaClientBase):
|
|||
self.assertEqual(rd, 200)
|
||||
self.assertEqual(rj['status'], 'SUCCESS')
|
||||
self.assertEqual(self.post.call_count, 1)
|
||||
|
||||
def test_create_connect_port(self):
|
||||
vlan_name = 'LNW_BusinessVLAN_49'
|
||||
vlan_type = 'BusinessVLAN'
|
||||
vlan_id = 1001
|
||||
rd, rj = self.nwa.l2.create_connect_port(
|
||||
TENANT_ID, DC_RESOURCE_GROUP_POD1,
|
||||
vlan_name, vlan_type, vlan_id
|
||||
)
|
||||
self.post.assert_called_once_with(
|
||||
workflow.NwaWorkflow.path('CreateConnectPort'),
|
||||
{'CreateNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1,
|
||||
'CreateNW_DeviceType1': 'GeneralDev',
|
||||
'CreateNW_OperationType': 'CreateConnectPort',
|
||||
'CreateNW_VlanID1': vlan_id,
|
||||
'CreateNW_VlanLogicalName1': vlan_name,
|
||||
'CreateNW_VlanType1': vlan_type,
|
||||
'TenantID': TENANT_ID})
|
||||
self.assertEqual(rd, 200)
|
||||
self.assertEqual(rj['status'], 'SUCCESS')
|
||||
self.assertEqual(self.post.call_count, 1)
|
||||
|
||||
def test_delete_connect_port(self):
|
||||
vlan_name = 'LNW_BusinessVLAN_49'
|
||||
vlan_type = 'BusinessVLAN'
|
||||
vlan_id = 1001
|
||||
rd, rj = self.nwa.l2.delete_connect_port(
|
||||
TENANT_ID, DC_RESOURCE_GROUP_POD1,
|
||||
vlan_name, vlan_type, vlan_id
|
||||
)
|
||||
self.post.assert_called_once_with(
|
||||
workflow.NwaWorkflow.path('DeleteConnectPort'),
|
||||
{'DeleteNW_DCResourceGroupName': DC_RESOURCE_GROUP_POD1,
|
||||
'DeleteNW_DeviceType1': 'GeneralDev',
|
||||
'DeleteNW_OperationType': 'DeleteConnectPort',
|
||||
'DeleteNW_VlanID1': vlan_id,
|
||||
'DeleteNW_VlanLogicalName1': vlan_name,
|
||||
'DeleteNW_VlanType1': vlan_type,
|
||||
'TenantID': TENANT_ID})
|
||||
self.assertEqual(rd, 200)
|
||||
self.assertEqual(rj['status'], 'SUCCESS')
|
||||
self.assertEqual(self.post.call_count, 1)
|
||||
|
|
Loading…
Reference in New Issue