summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--snaps/openstack/create_network.py17
-rw-r--r--snaps/openstack/create_router.py5
-rw-r--r--snaps/openstack/create_security_group.py5
-rw-r--r--snaps/openstack/tests/create_network_tests.py60
-rw-r--r--snaps/openstack/tests/create_router_tests.py86
-rw-r--r--snaps/openstack/tests/create_security_group_tests.py57
-rw-r--r--snaps/openstack/tests/os_source_file_test.py3
7 files changed, 197 insertions, 36 deletions
diff --git a/snaps/openstack/create_network.py b/snaps/openstack/create_network.py
index 4f27eec..2f26c43 100644
--- a/snaps/openstack/create_network.py
+++ b/snaps/openstack/create_network.py
@@ -190,7 +190,6 @@ class NetworkSettings:
if not self.name or len(self.name) < 1:
raise NetworkSettingsError('Name required for networks')
- raise NetworkSettingsError('Name required for networks')
def get_project_id(self, os_creds):
"""
@@ -203,8 +202,8 @@ class NetworkSettings:
else:
if self.project_name:
keystone = keystone_utils.keystone_client(os_creds)
- project = keystone_utils.get_project(keystone,
- self.project_name)
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
if project:
return project.id
@@ -231,7 +230,7 @@ class NetworkSettings:
if self.project_name:
project_id = self.get_project_id(os_creds)
if project_id:
- out['project_id'] = project_id
+ out['tenant_id'] = project_id
else:
raise NetworkSettingsError(
'Could not find project ID for project named - ' +
@@ -345,12 +344,13 @@ class SubnetSettings:
out['name'] = self.name
if self.project_name:
keystone = keystone_utils.keystone_client(os_creds)
- project = keystone_utils.get_project(keystone, self.project_name)
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
project_id = None
if project:
project_id = project.id
if project_id:
- out['project_id'] = project_id
+ out['tenant_id'] = project_id
else:
raise SubnetSettingsError(
'Could not find project ID for project named - ' +
@@ -492,7 +492,8 @@ class PortSettings:
project_id = None
if self.project_name:
keystone = keystone_utils.keystone_client(os_creds)
- project = keystone_utils.get_project(keystone, self.project_name)
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
if project:
project_id = project.id
@@ -512,7 +513,7 @@ class PortSettings:
out['name'] = self.name
if self.project_name:
if project_id:
- out['project_id'] = project_id
+ out['tenant_id'] = project_id
else:
raise PortSettingsError(
'Could not find project ID for project named - ' +
diff --git a/snaps/openstack/create_router.py b/snaps/openstack/create_router.py
index e50009c..acf6602 100644
--- a/snaps/openstack/create_router.py
+++ b/snaps/openstack/create_router.py
@@ -238,12 +238,13 @@ class RouterSettings:
out['name'] = self.name
if self.project_name:
keystone = keystone_utils.keystone_client(os_creds)
- project = keystone_utils.get_project(keystone, self.project_name)
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
project_id = None
if project:
project_id = project.id
if project_id:
- out['project_id'] = project_id
+ out['tenant_id'] = project_id
else:
raise RouterSettingsError(
'Could not find project ID for project named - ' +
diff --git a/snaps/openstack/create_security_group.py b/snaps/openstack/create_security_group.py
index 4291796..bde5d01 100644
--- a/snaps/openstack/create_security_group.py
+++ b/snaps/openstack/create_security_group.py
@@ -265,12 +265,13 @@ class SecurityGroupSettings:
if self.description:
out['description'] = self.description
if self.project_name:
- project = keystone_utils.get_project(keystone, self.project_name)
+ project = keystone_utils.get_project(
+ keystone=keystone, project_name=self.project_name)
project_id = None
if project:
project_id = project.id
if project_id:
- out['project_id'] = project_id
+ out['tenant_id'] = project_id
else:
raise SecurityGroupSettingsError(
'Could not find project ID for project named - ' +
diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py
index 322d383..bd373f1 100644
--- a/snaps/openstack/tests/create_network_tests.py
+++ b/snaps/openstack/tests/create_network_tests.py
@@ -464,6 +464,66 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase):
self.assertEqual(self.net_creator.get_network().id,
self.net_creator2.get_network().id)
+ def test_create_network_router_admin_user_to_new_project(self):
+ """
+ Tests the creation of an OpenStack network and router with the current
+ user to the admin project.
+ """
+ # Create Network/Subnet where the project names have been changed
+ admin_project_name = self.admin_os_creds.project_name
+ self.net_config.network_settings.project_name = admin_project_name
+ self.net_config.network_settings.subnet_settings[0].project_name = \
+ admin_project_name
+ self.net_creator = OpenStackNetwork(self.os_creds,
+ self.net_config.network_settings)
+ self.net_creator.create()
+
+ retrieved_net = neutron_utils.get_network(
+ self.neutron, self.net_config.network_settings.name)
+
+ self.assertEqual(self.net_creator.get_network().id, retrieved_net.id)
+
+ # Create Router
+ self.net_config.router_settings.project_name = admin_project_name
+ self.router_creator = create_router.OpenStackRouter(
+ self.os_creds, self.net_config.router_settings)
+ self.router_creator.create()
+
+ retrieved_router = neutron_utils.get_router_by_name(
+ self.neutron, self.router_creator.get_router().name)
+ self.assertEqual(
+ self.router_creator.get_router().id, retrieved_router.id)
+
+ def test_create_network_router_new_user_to_admin_project(self):
+ """
+ Tests the creation of an OpenStack network and router with the admin
+ user to the new project.
+ """
+ # Create Network/Subnet where the project names have been changed
+ new_project_name = self.os_creds.project_name
+ self.net_config.network_settings.project_name = new_project_name
+ self.net_config.network_settings.subnet_settings[0].project_name = \
+ new_project_name
+ self.net_creator = OpenStackNetwork(self.admin_os_creds,
+ self.net_config.network_settings)
+ self.net_creator.create()
+
+ retrieved_net = neutron_utils.get_network(
+ self.neutron, self.net_config.network_settings.name)
+
+ self.assertEqual(self.net_creator.get_network().id, retrieved_net.id)
+
+ # Create Router
+ self.net_config.router_settings.project_name = new_project_name
+ self.router_creator = create_router.OpenStackRouter(
+ self.admin_os_creds, self.net_config.router_settings)
+ self.router_creator.create()
+
+ retrieved_router = neutron_utils.get_router_by_name(
+ self.neutron, self.router_creator.get_router().name)
+ self.assertEqual(
+ self.router_creator.get_router().id, retrieved_router.id)
+
class CreateNetworkTypeTests(OSComponentTestCase):
"""
diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py
index efa0993..6e10d66 100644
--- a/snaps/openstack/tests/create_router_tests.py
+++ b/snaps/openstack/tests/create_router_tests.py
@@ -21,7 +21,7 @@ from snaps.openstack.create_network import (
NetworkSettings, PortSettings)
from snaps.openstack.create_network import OpenStackNetwork
from snaps.openstack.create_router import (
- RouterSettings, RouterSettingsError, RouterCreationError)
+ RouterSettings, RouterSettingsError)
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import neutron_utils
@@ -169,6 +169,46 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.assertTrue(verify_router_attributes(
router, self.router_creator, ext_gateway=self.ext_net_name))
+ def test_create_router_admin_user_to_new_project(self):
+ """
+ Test creation of a most basic router with the admin user pointing
+ to the new project.
+ """
+ router_settings = RouterSettings(
+ name=self.guid + '-pub-router', external_gateway=self.ext_net_name,
+ project_name=self.os_creds.project_name)
+
+ self.router_creator = create_router.OpenStackRouter(
+ self.admin_os_creds, router_settings)
+ self.router_creator.create()
+
+ router = neutron_utils.get_router_by_name(self.neutron,
+ router_settings.name)
+ self.assertIsNotNone(router)
+
+ self.assertTrue(verify_router_attributes(
+ router, self.router_creator, ext_gateway=self.ext_net_name))
+
+ def test_create_router_new_user_to_admin_project(self):
+ """
+ Test creation of a most basic router with the new user pointing
+ to the admin project.
+ """
+ router_settings = RouterSettings(
+ name=self.guid + '-pub-router', external_gateway=self.ext_net_name,
+ project_name=self.admin_os_creds.project_name)
+
+ self.router_creator = create_router.OpenStackRouter(
+ self.os_creds, router_settings)
+ self.router_creator.create()
+
+ router = neutron_utils.get_router_by_name(self.neutron,
+ router_settings.name)
+ self.assertIsNotNone(router)
+
+ self.assertTrue(verify_router_attributes(
+ router, self.router_creator, ext_gateway=self.ext_net_name))
+
def test_create_delete_router(self):
"""
Test that clean() will not raise an exception if the router is deleted
@@ -257,14 +297,23 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.network_creator2.create()
port_settings = [
- create_network.PortSettings(name=self.guid + '-port1', ip_addrs=[
- {'subnet_name': network_settings1.subnet_settings[0].name,
- 'ip': static_gateway_ip1}],
- network_name=network_settings1.name),
- create_network.PortSettings(name=self.guid + '-port2', ip_addrs=[
- {'subnet_name': network_settings2.subnet_settings[0].name,
- 'ip': static_gateway_ip2}],
- network_name=network_settings2.name)]
+ create_network.PortSettings(
+ name=self.guid + '-port1',
+ ip_addrs=[{
+ 'subnet_name':
+ network_settings1.subnet_settings[0].name,
+ 'ip': static_gateway_ip1
+ }],
+ network_name=network_settings1.name,
+ project_name=self.os_creds.project_name),
+ create_network.PortSettings(
+ name=self.guid + '-port2',
+ ip_addrs=[{
+ 'subnet_name': network_settings2.subnet_settings[0].name,
+ 'ip': static_gateway_ip2
+ }],
+ network_name=network_settings2.name,
+ project_name=self.os_creds.project_name)]
router_settings = RouterSettings(name=self.guid + '-pub-router',
port_settings=port_settings)
@@ -293,14 +342,17 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.network_creator1.create()
port_settings = [
- create_network.PortSettings(name=self.guid + '-port1', ip_addrs=[
- {'subnet_name': network_settings.subnet_settings[0].name,
- 'ip': static_gateway_ip1}],
- network_name=network_settings.name)]
-
- router_settings = RouterSettings(name=self.guid + '-pub-router',
- external_gateway=self.ext_net_name,
- port_settings=port_settings)
+ create_network.PortSettings(
+ name=self.guid + '-port1',
+ ip_addrs=[{
+ 'subnet_name': network_settings.subnet_settings[0].name,
+ 'ip': static_gateway_ip1}],
+ network_name=network_settings.name,
+ project_name=self.os_creds.project_name)]
+
+ router_settings = RouterSettings(
+ name=self.guid + '-pub-router', external_gateway=self.ext_net_name,
+ port_settings=port_settings)
self.router_creator = create_router.OpenStackRouter(self.os_creds,
router_settings)
self.router_creator.create()
diff --git a/snaps/openstack/tests/create_security_group_tests.py b/snaps/openstack/tests/create_security_group_tests.py
index dd28d7d..7cae62b 100644
--- a/snaps/openstack/tests/create_security_group_tests.py
+++ b/snaps/openstack/tests/create_security_group_tests.py
@@ -16,12 +16,9 @@ import unittest
import uuid
from snaps.openstack import create_security_group
-from snaps.openstack.create_security_group import (SecurityGroupSettings,
- SecurityGroupRuleSettings,
- Direction, Ethertype,
- Protocol,
- SecurityGroupRuleSettingsError,
- SecurityGroupSettingsError)
+from snaps.openstack.create_security_group import (
+ SecurityGroupSettings, SecurityGroupRuleSettings, Direction, Ethertype,
+ Protocol, SecurityGroupRuleSettingsError, SecurityGroupSettingsError)
from snaps.openstack.tests import validation_utils
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import neutron_utils
@@ -212,6 +209,54 @@ class CreateSecurityGroupTests(OSIntegrationTestCase):
validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
rules)
+ def test_create_group_admin_user_to_new_project(self):
+ """
+ Tests the creation of an OpenStack Security Group without custom rules.
+ """
+ # Create Image
+ sec_grp_settings = SecurityGroupSettings(
+ name=self.sec_grp_name, description='hello group',
+ project_name=self.admin_os_creds.project_name)
+ self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
+ self.os_creds, sec_grp_settings)
+ self.sec_grp_creator.create()
+
+ sec_grp = neutron_utils.get_security_group(self.neutron,
+ self.sec_grp_name)
+ self.assertIsNotNone(sec_grp)
+
+ validation_utils.objects_equivalent(
+ self.sec_grp_creator.get_security_group(), sec_grp)
+ rules = neutron_utils.get_rules_by_security_group(
+ self.neutron, self.sec_grp_creator.get_security_group())
+ self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
+ validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
+ rules)
+
+ def test_create_group_new_user_to_admin_project(self):
+ """
+ Tests the creation of an OpenStack Security Group without custom rules.
+ """
+ # Create Image
+ sec_grp_settings = SecurityGroupSettings(
+ name=self.sec_grp_name, description='hello group',
+ project_name=self.os_creds.project_name)
+ self.sec_grp_creator = create_security_group.OpenStackSecurityGroup(
+ self.admin_os_creds, sec_grp_settings)
+ self.sec_grp_creator.create()
+
+ sec_grp = neutron_utils.get_security_group(self.neutron,
+ self.sec_grp_name)
+ self.assertIsNotNone(sec_grp)
+
+ validation_utils.objects_equivalent(
+ self.sec_grp_creator.get_security_group(), sec_grp)
+ rules = neutron_utils.get_rules_by_security_group(
+ self.neutron, self.sec_grp_creator.get_security_group())
+ self.assertEqual(len(self.sec_grp_creator.get_rules()), len(rules))
+ validation_utils.objects_equivalent(self.sec_grp_creator.get_rules(),
+ rules)
+
def test_create_delete_group(self):
"""
Tests the creation of an OpenStack Security Group without custom rules.
diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py
index 2ccee3f..da474a2 100644
--- a/snaps/openstack/tests/os_source_file_test.py
+++ b/snaps/openstack/tests/os_source_file_test.py
@@ -31,6 +31,7 @@ dev_os_env_file = pkg_resources.resource_filename(
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
+
class OSComponentTestCase(unittest.TestCase):
def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None,
@@ -82,7 +83,7 @@ class OSComponentTestCase(unittest.TestCase):
class OSIntegrationTestCase(OSComponentTestCase):
def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None,
- use_keystone=False, flavor_metadata=None, image_metadata=None,
+ use_keystone=True, flavor_metadata=None, image_metadata=None,
log_level=logging.DEBUG):
"""
Super for integration tests requiring a connection to OpenStack