summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2018-07-24 09:19:24 -0600
committerspisarski <s.pisarski@cablelabs.com>2018-07-24 09:19:24 -0600
commite3fd866cceaa621617f5b9efc8dd23c19d56ab11 (patch)
treeefec7a87e8eb24935baa12fe9f8cfd7e4ce61e49
parent821d86248054017ea8ac40b99759df71fa639e3b (diff)
Small fix to network/project when creating ports and
added new tests for routers that create ports to external and shared networks created by the 'admin' user. Change-Id: I0365e9843e0837d720ca8dd907c45afa2c512047 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--docs/how-to-use/IntegrationTests.rst16
-rw-r--r--snaps/openstack/tests/create_router_tests.py113
-rw-r--r--snaps/openstack/utils/neutron_utils.py7
-rw-r--r--snaps/test_suite_builder.py7
4 files changed, 137 insertions, 6 deletions
diff --git a/docs/how-to-use/IntegrationTests.rst b/docs/how-to-use/IntegrationTests.rst
index bc4b706..79ef8ef 100644
--- a/docs/how-to-use/IntegrationTests.rst
+++ b/docs/how-to-use/IntegrationTests.rst
@@ -324,6 +324,22 @@ create_router_tests.py - CreateRouterSecurityGroupTests
| | | applied to it |
+---------------------------------------+---------------+-----------------------------------------------------------+
+create_router_tests.py - CreateRouterSharedNetworksTests
+--------------------------------------------------------
+
++---------------------------------------+---------------+-----------------------------------------------------------+
+| Test Name | Neutron API | Description |
++=======================================+===============+===========================================================+
+| test_create_router_external | 2 | Ensures that a router can be joined to an external network|
+| | | that was created by an admin user |
++---------------------------------------+---------------+-----------------------------------------------------------+
+| test_create_router_port_external | 2 | Ensures that a router can have a port created to an |
+| | | external network that was created by an admin user |
++---------------------------------------+---------------+-----------------------------------------------------------+
+| test_create_router_port_shared | 2 | Ensures that a router can have a port created to an |
+| | | shared network that was created by an admin user |
++---------------------------------------+---------------+-----------------------------------------------------------+
+
create_qos_tests.py - CreateQoSTests
------------------------------------
diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py
index 80e9078..a305cf8 100644
--- a/snaps/openstack/tests/create_router_tests.py
+++ b/snaps/openstack/tests/create_router_tests.py
@@ -21,8 +21,8 @@ from snaps.config.security_group import SecurityGroupConfig
from snaps.openstack import create_network
from snaps.openstack import create_router
from snaps.openstack.create_network import OpenStackNetwork
-from snaps.openstack.create_router import (RouterSettings, OpenStackRouter,
- RouterCreationError)
+from snaps.openstack.create_router import (
+ RouterSettings, OpenStackRouter, RouterCreationError)
from snaps.openstack.create_security_group import OpenStackSecurityGroup
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import neutron_utils, settings_utils, keystone_utils
@@ -31,6 +31,7 @@ __author__ = 'mmakati'
cidr1 = '10.200.201.0/24'
cidr2 = '10.200.202.0/24'
+cidr3 = '10.200.203.0/24'
static_gateway_ip1 = '10.200.201.1'
static_gateway_ip2 = '10.200.202.1'
@@ -285,7 +286,7 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.os_creds, self.router_settings)
with self.assertRaises(RouterCreationError):
- created_router = self.router_creator.create()
+ self.router_creator.create()
def test_create_router_admin_state_false(self):
"""
@@ -764,3 +765,109 @@ class CreateRouterSecurityGroupTests(OSIntegrationTestCase):
self.router_creator = create_router.OpenStackRouter(
self.os_creds, router_settings)
self.router_creator.create()
+
+
+class CreateRouterSharedNetworksTests(OSIntegrationTestCase):
+ """
+ Class for testing routers external and/or shared networks
+ """
+
+ def setUp(self):
+ """
+ Initializes objects used for router testing
+ """
+ super(self.__class__, self).__start__()
+
+ self.guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
+ self.router_creator = None
+
+ ext_network_settings = NetworkConfig(
+ name=self.guid + '-ext-net',
+ external=True,
+ subnet_settings=[
+ create_network.SubnetConfig(
+ cidr=cidr1, name=self.guid + '-ext-subnet1')])
+ self.ext_network_creator = OpenStackNetwork(
+ self.admin_os_creds, ext_network_settings)
+ self.ext_network_creator.create()
+
+ shared_network_settings = NetworkConfig(
+ name=self.guid + '-shared-net',
+ shared=True,
+ subnet_settings=[
+ create_network.SubnetConfig(
+ cidr=cidr2, name=self.guid + '-shared-subnet1')])
+ self.shared_network_creator = OpenStackNetwork(
+ self.admin_os_creds, shared_network_settings)
+ self.shared_network_creator.create()
+
+ overlay_network_settings = NetworkConfig(
+ name=self.guid + '-overlay-net',
+ subnet_settings=[
+ create_network.SubnetConfig(
+ cidr=cidr3, name=self.guid + '-overlay-subnet1')])
+ self.overlay_network_creator = OpenStackNetwork(
+ self.os_creds, overlay_network_settings)
+ self.overlay_network_creator.create()
+
+ self.neutron = neutron_utils.neutron_client(
+ self.os_creds, self.os_session)
+
+ def tearDown(self):
+ """
+ Cleans the remote OpenStack objects used for router testing
+ """
+ if self.router_creator:
+ self.router_creator.clean()
+
+ if self.overlay_network_creator:
+ self.overlay_network_creator.clean()
+
+ if self.shared_network_creator:
+ self.shared_network_creator.clean()
+
+ if self.ext_network_creator:
+ self.ext_network_creator.clean()
+
+ super(self.__class__, self).__clean__()
+
+ def test_create_router_external(self):
+ """
+ Test creation of a router with a custom external network created by
+ admin.
+ """
+ router_settings = RouterConfig(
+ name=self.guid + '-pub-router',
+ external_gateway=self.ext_network_creator.get_network().name)
+ self.router_creator = create_router.OpenStackRouter(
+ self.os_creds, router_settings)
+ self.router_creator.create()
+
+ def test_create_router_port_external(self):
+ """
+ Test creation of a router with a port to an custom external network
+ created by admin.
+ """
+ router_settings = RouterConfig(
+ name=self.guid + '-pub-router',
+ network_name=self.ext_network_creator.get_network().name)
+ self.router_creator = create_router.OpenStackRouter(
+ self.os_creds, router_settings)
+ self.router_creator.create()
+
+ def test_create_router_port_shared(self):
+ """
+ Test creation of a router with a port to an custom shared network
+ created by admin.
+ """
+ port_settings = [
+ create_network.PortConfig(
+ name=self.guid + '-port1',
+ network_name=self.shared_network_creator.get_network().name)]
+
+ router_settings = RouterConfig(
+ name=self.guid + '-pub-router',
+ port_settings=port_settings)
+ self.router_creator = create_router.OpenStackRouter(
+ self.os_creds, router_settings)
+ self.router_creator.create()
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index d82bbf6..c199b99 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -544,8 +544,11 @@ def get_port(neutron, keystone, port_settings=None, port_name=None,
project_name = port_settings.project_name
if port_settings.network_name:
network = get_network(
- neutron, keystone, network_name=port_settings.network_name,
- project_name=project_name)
+ neutron, keystone, network_name=port_settings.network_name)
+ if network and not (network.shared or network.external):
+ network = get_network(
+ neutron, keystone, network_name=port_settings.network_name,
+ project_name=project_name)
if network:
port_filter['network_id'] = network.id
elif port_name:
diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py
index 1fe1f8a..52008a6 100644
--- a/snaps/test_suite_builder.py
+++ b/snaps/test_suite_builder.py
@@ -86,7 +86,7 @@ from snaps.openstack.tests.create_qos_tests import (
from snaps.openstack.tests.create_router_tests import (
CreateRouterSuccessTests, CreateRouterNegativeTests,
RouterSettingsUnitTests, CreateMultipleRouterTests,
- CreateRouterSecurityGroupTests)
+ CreateRouterSecurityGroupTests, CreateRouterSharedNetworksTests)
from snaps.openstack.tests.create_security_group_tests import (
CreateSecurityGroupTests, SecurityGroupRuleSettingsUnitTests,
SecurityGroupSettingsUnitTests, CreateMultipleSecurityGroupTests)
@@ -546,6 +546,11 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name,
flavor_metadata=flavor_metadata, image_metadata=image_metadata,
log_level=log_level))
suite.addTest(OSIntegrationTestCase.parameterize(
+ CreateRouterSharedNetworksTests, os_creds=os_creds,
+ ext_net_name=ext_net_name, use_keystone=use_keystone,
+ flavor_metadata=flavor_metadata, image_metadata=image_metadata,
+ log_level=log_level))
+ suite.addTest(OSIntegrationTestCase.parameterize(
CreateQoSTests, os_creds=os_creds,
ext_net_name=ext_net_name, use_keystone=use_keystone,
flavor_metadata=flavor_metadata, image_metadata=image_metadata,