Add API tests for L2Gateway extension

This patch adds a number of positive and negative tests for
the L2Gateway functionality implemented by networking stackforge

Change-Id: I0b5e76da2c66cc2caf3d041ccde974a184f4c4e3
stable/ocata
Ashish Gupta 8 years ago
parent 05a572ca00
commit 8431a51f9e

@ -2,6 +2,7 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./networking_l2gw/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

@ -0,0 +1,92 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
# Copyright 2015 OpenStack Foundation
#
# 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 networking_l2gw.tests.tempest import config
CONF = config.CONF
SEGMENTATION_ID_DELIMITER = "#"
INTERFACE_SEG_ID_DELIMITER = "|"
DEVICE_INTERFACE_DELIMITER = "::"
DEVICE_DELIMITER = ","
INTERFACE_DELIMITER = ";"
"""
Sample for providing input for gateway creation in config is noted below
Options provide flexibility to user to create l2gateway
For single device ,single interface with single vlan
l2gw_switch = device_name1::int_name1|vlan1
For single device multiple interfaces with single or multiple vlans
l2gw_switch = device_name1::int_name1|vlan1#vlan2;int_name2|vlan3
For multiple devices with mutiple interfaces having single or mutiple vlan
l2gw_switch = device_name1::int_name1|vlan1,device_name2::int_name2|vlan2
"""
def get_interface(interfaces):
interface_dict = []
for interface in interfaces:
if INTERFACE_SEG_ID_DELIMITER in interface:
int_name = interface.split(INTERFACE_SEG_ID_DELIMITER)[0]
segid = interface.split(INTERFACE_SEG_ID_DELIMITER)[1]
if SEGMENTATION_ID_DELIMITER in segid:
segid = segid.split(SEGMENTATION_ID_DELIMITER)
else:
segid = [segid]
interface_detail = {'name': int_name, 'segmentation_id': segid}
else:
interface_detail = {'name': interface}
interface_dict.append(interface_detail)
return interface_dict
def get_l2gw_body(l2gw_conf):
device_dict = []
devices = l2gw_conf.split(DEVICE_DELIMITER)
for device in devices:
if DEVICE_INTERFACE_DELIMITER in device:
device_name = device.split(DEVICE_INTERFACE_DELIMITER)[0]
interface = device.split(DEVICE_INTERFACE_DELIMITER)[1]
if INTERFACE_DELIMITER in interface:
interface_dict = interface.split(INTERFACE_DELIMITER)
interfaces = get_interface(interface_dict)
else:
interfaces = get_interface([interface])
device = {'device_name': device_name,
'interfaces': interfaces}
device_dict.append(device)
body = {'devices': device_dict}
return body
def form_dict_devices(devices):
seg_ids = []
devices1 = dict()
int_seg = []
for device in devices:
device_name = device['device_name']
interfaces = device['interfaces']
for interface in interfaces:
interface_name = interface['name']
int_seg.append(interface_name)
seg_id = interface['segmentation_id']
if type(seg_id) is list:
for segid in seg_id:
seg_ids.append(segid)
else:
seg_ids.append(seg_id)
int_seg.append(seg_id)
devices1.setdefault(device_name, []).append(int_seg)
int_seg = []
return devices1

@ -0,0 +1,110 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
# Copyright 2015 OpenStack Foundation
#
# 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.tests.api import base
from neutron.tests.tempest import test
from tempest_lib.common.utils import data_utils
from networking_l2gw.tests.api import base_l2gw
from networking_l2gw.tests.tempest import config
CONF = config.CONF
class L2GatewayExtensionTestJSON(base.BaseAdminNetworkTest):
_interface = 'json'
"""
Tests the following operations in the Neutron API using the REST client for
Neutron:
Create l2gateway
List l2gateways
Show l2gateway
Update l2gateway
Delete l2gateway
Create l2gatewayconnection
List l2gatewayconnections
Show l2gatewayconnection
Delete l2gatewayconnection
"""
@classmethod
def resource_setup(cls):
super(L2GatewayExtensionTestJSON, cls).resource_setup()
# Atleast one switch detail should be provided to run the tests
if (len(CONF.network.l2gw_switch) < 0):
msg = ('Atleast one switch detail must be defined.')
raise cls.skipException(msg)
if not test.is_extension_enabled('l2gateway', 'network'):
msg = "L2Gateway Extension not enabled."
raise cls.skipException(msg)
@test.idempotent_id('3ca07946-a3c9-49ac-b058-8be54abecf1f')
def test_create_show_list_update_delete_l2gateway(self):
# Create an L2Gateway
gw_name = data_utils.rand_name('l2gw')
devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
body = self.admin_client.create_l2_gateway(
name=gw_name, devices=devices)
l2_gateway = body['l2_gateway']
self.addCleanup(self.admin_client.delete_l2_gateway, l2_gateway['id'])
# Show details of L2Gateway
show_body = self.admin_client.show_l2_gateway(l2_gateway['id'])
self.assertEqual(gw_name, show_body['l2_gateway']['name'])
conf_devices = base_l2gw.form_dict_devices(devices)
create_devices = base_l2gw.form_dict_devices(show_body['l2_gateway']
['devices'])
# Validate the resource provided in the conf and created
for k, v in zip(conf_devices.items(), create_devices.items()):
self.assertEqual(k, v)
# List L2Gateways
self.admin_client.list_l2_gateways()
# Update the name of an L2Gateway and verify the same
updated_name = 'updated ' + gw_name
update_body = self.admin_client.update_l2_gateway(l2_gateway['id'],
name=updated_name)
self.assertEqual(update_body['l2_gateway']['name'], updated_name)
show_body = self.admin_client.show_l2_gateway(l2_gateway['id'])
self.assertEqual(show_body['l2_gateway']['name'], updated_name)
@test.idempotent_id('3ad5e945-2b42-4ea8-9c03-0bf41d4167f2')
def test_create_show_list_delete_l2gateway_connection(self):
# Create a network
name = data_utils.rand_name('network')
net_body = self.admin_client.create_network(name=name)
net_id = net_body['network']['id']
self.addCleanup(self.admin_client.delete_network, net_id)
# Create an L2Gateway
gw_name = data_utils.rand_name('l2gw')
devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
l2_gw_body = self.admin_client.create_l2_gateway(
name=gw_name, devices=devices)
l2_gw_id = l2_gw_body['l2_gateway']['id']
self.addCleanup(self.admin_client.delete_l2_gateway, l2_gw_id)
# Create an L2Gateway Connection
l2_gw_conn_body = self.admin_client.create_l2_gateway_connection(
l2_gateway_id=l2_gw_id, network_id=net_id)
l2_gw_conn_id = l2_gw_conn_body['l2_gateway_connection']['id']
self.addCleanup(self.admin_client.delete_l2_gateway_connection,
l2_gw_conn_id)
# Show details of created L2 Gateway connection
show_body = self.admin_client.show_l2_gateway_connection(l2_gw_conn_id)
l2_gw_conn = show_body['l2_gateway_connection']
self.assertEqual(net_id, l2_gw_conn['network_id'])
self.assertEqual(l2_gw_id, l2_gw_conn['l2_gateway_id'])
# List L2Gateway Connections
self.admin_client.list_l2_gateway_connections()

@ -0,0 +1,140 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
# 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.tests.api import base
from neutron.tests.tempest import test
from networking_l2gw.tests.api import base_l2gw
from networking_l2gw.tests.tempest import config
from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as lib_exc
CONF = config.CONF
class L2GatewaysNegativeTestJSON(base.BaseNetworkTest):
_interface = 'json'
@classmethod
def resource_setup(cls):
super(L2GatewaysNegativeTestJSON, cls).resource_setup()
# Atleast one switch detail should be provided to run the tests
if (len(CONF.network.l2gw_switch) < 0):
msg = ('Atleast one switch detail must be defined.')
raise cls.skipException(msg)
if not test.is_extension_enabled('l2gateway', 'network'):
msg = "L2Gateway Extension not enabled."
raise cls.skipException(msg)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('b301d83d-3af3-4712-86dc-a6824e9b14e5')
def test_create_l2gateway_non_admin_user(self):
gw_name = data_utils.rand_name('l2gw')
devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
self.assertRaises(lib_exc.Forbidden,
self.client.create_l2_gateway,
name=gw_name, devices=devices)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('68451dfe-b3b5-4eb1-b03f-9935d4a2dbe7')
def test_list_l2gateway_non_admin_user(self):
self.assertRaises(lib_exc.Forbidden,
self.client.list_l2_gateways)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('f8589452-7aff-4992-b865-5bb5c41fa755')
def test_update_l2gateway_non_admin_user(self):
non_exist_id = data_utils.rand_name('l2gw')
self.assertRaises(lib_exc.Forbidden,
self.client.update_l2_gateway,
non_exist_id, name="updated_name")
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('d9f57800-6cae-4770-a2d7-ab60cf7417bf')
def test_delete_l2gateway_non_admin_user(self):
non_exist_id = data_utils.rand_name('l2gw')
self.assertRaises(lib_exc.Forbidden,
self.client.delete_l2_gateway,
non_exist_id)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('c6b61a8d-8c82-497d-9fad-9929c9acf035')
def test_create_l2gateway_connection_non_admin_user(self):
non_exist_id = data_utils.rand_name('network')
self.assertRaises(lib_exc.Forbidden,
self.client.create_l2_gateway_connection,
network_id=non_exist_id, l2_gateway_id=non_exist_id)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('a56a0180-7d98-414c-9a44-fe47a30fe436')
def test_list_l2gateway_connection_non_admin_user(self):
self.assertRaises(lib_exc.Forbidden,
self.client.list_l2_gateway_connections)
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('ce42c68d-5c41-4988-8912-233e3fe5c8fd')
def test_delete_l2gateway_connection_non_admin_user(self):
non_exist_id = data_utils.rand_name('l2gwconnection')
self.assertRaises(lib_exc.Forbidden,
self.client.delete_l2_gateway_connection,
non_exist_id)
class L2GatewaysNegativeAdminTestJSON(base.BaseAdminNetworkTest):
_interface = 'json'
@classmethod
def resource_setup(cls):
super(L2GatewaysNegativeAdminTestJSON, cls).resource_setup()
if not test.is_extension_enabled('l2gateway', 'network'):
msg = "L2Gateway Extension not enabled."
raise cls.skipException(msg)
@classmethod
def _initialize_l2gw_attributes(self, vlan_id):
self.interface_name = CONF.network.interface_name
self.device_name = CONF.network.device_name
self.device = [{"device_name": self.device_name, "interfaces":
[{"name": self.interface_name,
"segmentation_id": [vlan_id]}]}]
return self.device
@test.attr(type=['negative', 'smoke'])
@test.idempotent_id('42067b44-3aff-4428-8305-d0496bd38179')
def test_delete_l2gw_associated_l2gw_connection(self):
# Create a network
name = data_utils.rand_name('network')
net_body = self.admin_client.create_network(name=name)
net_id = net_body['network']['id']
self.addCleanup(self.admin_client.delete_network, net_id)
# Create an L2Gateway
gw_name = data_utils.rand_name('l2gw')
devices = base_l2gw.get_l2gw_body(CONF.network.l2gw_switch)["devices"]
body = self.admin_client.create_l2_gateway(
name=gw_name, devices=devices)
l2_gateway = body['l2_gateway']
self.addCleanup(self.admin_client.delete_l2_gateway, l2_gateway['id'])
# Create an L2Gateway Connection
l2_gw_conn_body = self.admin_client.create_l2_gateway_connection(
l2_gateway_id=l2_gateway['id'], network_id=net_id)
l2_gw_conn_id = l2_gw_conn_body['l2_gateway_connection']['id']
self.addCleanup(self.admin_client.delete_l2_gateway_connection,
l2_gw_conn_id)
self.assertRaises(lib_exc.Conflict,
self.admin_client.delete_l2_gateway,
l2_gateway['id'])

File diff suppressed because it is too large Load Diff

@ -0,0 +1,6 @@
[l2_gateway]
#List of switch device,interfaces name and segmentation_ids for l2gateway
l2gw_switch = cell08-5930-01::FortyGigE1/0/1|100
#l2gw_switch = cell08-5930-01::FortyGigE1/0/1|100#200;FortyGigE1/0/2|300
#l2gw_switch = cell08-5930-01::FortyGigE1/0/1|100#200,cell08-5930-02::FortyGigE1/0/2|300

@ -13,3 +13,4 @@ oslotest>=1.1.0.0a1
testrepository>=0.0.18
testscenarios>=0.4
testtools>=0.9.34
tempest-lib>=0.4.0

@ -33,3 +33,8 @@ show-source = True
ignore = E123,H803,H302
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
[testenv:api]
setenv = OS_TEST_PATH=./networking_l2gw/tests/api
TEMPEST_CONFIG_DIR={env:TEMPEST_CONFIG_DIR:/opt/stack/tempest/etc}
OS_TEST_API_WITH_REST=1

Loading…
Cancel
Save