summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-08-17 08:09:07 +0000
committerLinda Wang <wangwulin@huawei.com>2017-08-18 19:55:00 +0000
commite7b96a812bb7b30416b4adb24ef0f22666687c10 (patch)
treeba4449db8df2dd2f832e1070caad258148d4401d
parentacc4428e76422ad5c60f5433f325258214e6bc3b (diff)
Specify segmentation_id when creating network
When the network_type is vlan, it is necessary to specify physical_network and segmentation_id. JIRA: FUNCTEST-863 Change-Id: I44f57cdd825ee3cde7adb946c4f8dc78e3ee5212 Signed-off-by: Linda Wang <wangwulin@huawei.com>
-rw-r--r--snaps/openstack/create_network.py5
-rw-r--r--snaps/openstack/tests/create_network_tests.py43
2 files changed, 44 insertions, 4 deletions
diff --git a/snaps/openstack/create_network.py b/snaps/openstack/create_network.py
index c3fb575..d0b6d20 100644
--- a/snaps/openstack/create_network.py
+++ b/snaps/openstack/create_network.py
@@ -149,6 +149,8 @@ class NetworkSettings:
:param network_type: the type of network (i.e. vlan|flat).
:param physical_network: the name of the physical network
(this is required when network_type is 'flat')
+ :param segmentation_id: the id of the segmentation
+ (this is required when network_type is 'vlan')
:param subnets or subnet_settings: List of SubnetSettings objects.
:return:
"""
@@ -175,6 +177,7 @@ class NetworkSettings:
self.network_type = kwargs.get('network_type')
self.physical_network = kwargs.get('physical_network')
+ self.segmentation_id = kwargs.get('segmentation_id')
self.subnet_settings = list()
subnet_settings = kwargs.get('subnets')
@@ -239,6 +242,8 @@ class NetworkSettings:
out['provider:network_type'] = self.network_type
if self.physical_network:
out['provider:physical_network'] = self.physical_network
+ if self.segmentation_id:
+ out['provider:segmentation_id'] = self.segmentation_id
if self.external:
out['router:external'] = self.external
return {'network': out}
diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py
index 51927dc..9cee130 100644
--- a/snaps/openstack/tests/create_network_tests.py
+++ b/snaps/openstack/tests/create_network_tests.py
@@ -51,6 +51,7 @@ class NetworkSettingsUnitTests(unittest.TestCase):
self.assertIsNone(settings.project_name)
self.assertFalse(settings.external)
self.assertIsNone(settings.network_type)
+ self.assertIsNone(settings.segmentation_id)
self.assertEqual(0, len(settings.subnet_settings))
def test_config_with_name_only(self):
@@ -61,6 +62,7 @@ class NetworkSettingsUnitTests(unittest.TestCase):
self.assertIsNone(settings.project_name)
self.assertFalse(settings.external)
self.assertIsNone(settings.network_type)
+ self.assertIsNone(settings.segmentation_id)
self.assertEqual(0, len(settings.subnet_settings))
def test_all(self):
@@ -68,23 +70,26 @@ class NetworkSettingsUnitTests(unittest.TestCase):
settings = NetworkSettings(name='foo', admin_state_up=False,
shared=True, project_name='bar',
external=True,
- network_type='flat', physical_network='phy',
+ network_type='vlan', physical_network='phy',
+ segmentation_id=2366,
subnet_settings=[sub_settings])
self.assertEqual('foo', settings.name)
self.assertFalse(settings.admin_state_up)
self.assertTrue(settings.shared)
self.assertEqual('bar', settings.project_name)
self.assertTrue(settings.external)
- self.assertEqual('flat', settings.network_type)
+ self.assertEqual('vlan', settings.network_type)
self.assertEqual('phy', settings.physical_network)
+ self.assertEqual(2366, settings.segmentation_id)
self.assertEqual(1, len(settings.subnet_settings))
self.assertEqual('foo-subnet', settings.subnet_settings[0].name)
def test_config_all(self):
settings = NetworkSettings(
**{'name': 'foo', 'admin_state_up': False, 'shared': True,
- 'project_name': 'bar', 'external': True, 'network_type': 'flat',
+ 'project_name': 'bar', 'external': True, 'network_type': 'vlan',
'physical_network': 'phy',
+ 'segmentation_id': 2366,
'subnets':
[{'subnet': {'name': 'foo-subnet',
'cidr': '10.0.0.0/24'}}]})
@@ -93,8 +98,9 @@ class NetworkSettingsUnitTests(unittest.TestCase):
self.assertTrue(settings.shared)
self.assertEqual('bar', settings.project_name)
self.assertTrue(settings.external)
- self.assertEqual('flat', settings.network_type)
+ self.assertEqual('vlan', settings.network_type)
self.assertEqual('phy', settings.physical_network)
+ self.assertEqual(2366, settings.segmentation_id)
self.assertEqual(1, len(settings.subnet_settings))
self.assertEqual('foo-subnet', settings.subnet_settings[0].name)
@@ -560,6 +566,35 @@ class CreateNetworkTypeTests(OSComponentTestCase):
self.assertEquals(network_type, network.type)
+ def test_create_network_type_vlan_with_physical_net_and_seg_id(self):
+ """
+ Tests the creation of an OpenStack network of type vlan with
+ specified physical network and segmentation id.
+ """
+ # Create Network
+ network_type = 'vlan'
+
+ # The two values must be variable to work on all OpenStack pods
+ physical_network = 'datacentre'
+ segmentation_id = 2366
+
+ net_settings = NetworkSettings(
+ name=self.net_config.network_settings.name,
+ subnet_settings=self.net_config.network_settings.subnet_settings,
+ network_type=network_type,
+ physical_network=physical_network,
+ segmentation_id=segmentation_id)
+
+ # When setting the network_type, creds must be admin
+ self.net_creator = OpenStackNetwork(self.os_creds, net_settings)
+ network = self.net_creator.create()
+
+ # Validate network was created
+ self.assertTrue(neutron_utils_tests.validate_network(
+ self.neutron, net_settings.name, True))
+
+ self.assertEquals(network_type, network.type)
+
def test_create_network_type_vxlan(self):
"""
Tests the creation of an OpenStack network of type vxlan.