summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/how-to-use/LibraryUsage.rst7
-rw-r--r--docs/how-to-use/UnitTests.rst8
-rw-r--r--examples/launch.py5
-rw-r--r--snaps/config/project.py57
-rw-r--r--snaps/config/tests/project_tests.py69
-rw-r--r--snaps/openstack/create_project.py42
-rw-r--r--snaps/openstack/tests/create_project_tests.py18
-rw-r--r--snaps/openstack/tests/os_source_file_test.py8
-rw-r--r--snaps/openstack/utils/keystone_utils.py2
-rw-r--r--snaps/openstack/utils/tests/keystone_utils_tests.py6
-rw-r--r--snaps/test_suite_builder.py3
11 files changed, 166 insertions, 59 deletions
diff --git a/docs/how-to-use/LibraryUsage.rst b/docs/how-to-use/LibraryUsage.rst
index c45cc83..ae28212 100644
--- a/docs/how-to-use/LibraryUsage.rst
+++ b/docs/how-to-use/LibraryUsage.rst
@@ -112,7 +112,7 @@ Create Project
--------------
- Project - snaps.openstack.create\_project.OpenStackProject
- - snaps.openstack.create\_project.ProjectSettings
+ - snaps.openstack.project.ProjectConfig
- name - the project name (required)
- domain - the project's domain (default='default')
@@ -123,8 +123,9 @@ Create Project
.. code:: python
- from snaps.openstack.create_project import ProjectSettings, OpenStackProject
- project_settings = ProjectSettings(name='username', password='password')
+ from snaps.openstack.project import ProjectConfig
+ from snaps.openstack.create_project import OpenStackProject
+ project_settings = ProjectConfig(name='username', password='password')
project_creator = OpenStackProject(os_creds, project_settings)
project_creator.create()
diff --git a/docs/how-to-use/UnitTests.rst b/docs/how-to-use/UnitTests.rst
index 013b646..214e2b8 100644
--- a/docs/how-to-use/UnitTests.rst
+++ b/docs/how-to-use/UnitTests.rst
@@ -126,11 +126,17 @@ UserDomainObjectTests
Ensures that all required members are included when constructing a
User domain object
+ProjectConfigUnitTests
+----------------------
+
+Ensures that all required members are included when constructing a
+ProjectConfig object
+
ProjectSettingsUnitTests
------------------------
Ensures that all required members are included when constructing a
-ProjectSettings object
+deprecated ProjectSettings object
ProjectDomainObjectTests
------------------------
diff --git a/examples/launch.py b/examples/launch.py
index 4d2a69f..d1129b0 100644
--- a/examples/launch.py
+++ b/examples/launch.py
@@ -29,13 +29,14 @@ from snaps import file_utils
from snaps.config.flavor import FlavorConfig
from snaps.config.image import ImageConfig
from snaps.config.keypair import KeypairConfig
+from snaps.config.project import ProjectConfig
from snaps.openstack.create_flavor import OpenStackFlavor
from snaps.openstack.create_image import OpenStackImage
from snaps.openstack.create_instance import VmInstanceSettings
from snaps.openstack.create_keypairs import OpenStackKeypair
from snaps.openstack.create_network import (
PortSettings, NetworkSettings, OpenStackNetwork)
-from snaps.openstack.create_project import OpenStackProject, ProjectSettings
+from snaps.openstack.create_project import OpenStackProject
from snaps.openstack.create_qos import QoSSettings, OpenStackQoS
from snaps.openstack.create_router import RouterSettings, OpenStackRouter
from snaps.openstack.create_security_group import (
@@ -615,7 +616,7 @@ def main(arguments):
try:
# Create projects
projects_dict = __create_instances(
- os_creds_dict, OpenStackProject, ProjectSettings,
+ os_creds_dict, OpenStackProject, ProjectConfig,
os_config.get('projects'), 'project', clean)
creators.append(projects_dict)
diff --git a/snaps/config/project.py b/snaps/config/project.py
new file mode 100644
index 0000000..6790609
--- /dev/null
+++ b/snaps/config/project.py
@@ -0,0 +1,57 @@
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. 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.
+
+
+class ProjectConfig(object):
+ """
+ Class to hold the configuration settings required for creating OpenStack
+ project objects
+ """
+
+ def __init__(self, **kwargs):
+
+ """
+ Constructor
+ :param name: the project's name (required)
+ :param domain or domain_name: the project's domain name
+ (default = 'Default').
+ Field is used for v3 clients
+ :param description: the description (optional)
+ :param users: list of users to associate project to (optional)
+ :param enabled: denotes whether or not the project is enabled
+ (default True)
+ """
+
+ self.name = kwargs.get('name')
+ self.domain_name = kwargs.get(
+ 'domain', kwargs.get('domain', 'Default'))
+
+ self.description = kwargs.get('description')
+ if kwargs.get('enabled') is not None:
+ self.enabled = kwargs['enabled']
+ else:
+ self.enabled = True
+
+ self.users = kwargs.get('users', list())
+
+ if not self.name:
+ raise ProjectConfigError(
+ "The attribute name is required for ProjectConfig")
+
+
+class ProjectConfigError(Exception):
+ """
+ Exception to be thrown when project settings attributes are incorrect
+ """
diff --git a/snaps/config/tests/project_tests.py b/snaps/config/tests/project_tests.py
new file mode 100644
index 0000000..0470d83
--- /dev/null
+++ b/snaps/config/tests/project_tests.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
+# and others. 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.
+import unittest
+
+from snaps.config.project import ProjectConfig, ProjectConfigError
+
+
+class ProjectConfigUnitTests(unittest.TestCase):
+ """
+ Tests the construction of the ProjectConfig class
+ """
+
+ def test_no_params(self):
+ with self.assertRaises(ProjectConfigError):
+ ProjectConfig()
+
+ def test_empty_config(self):
+ with self.assertRaises(ProjectConfigError):
+ ProjectConfig(**dict())
+
+ def test_name_only(self):
+ settings = ProjectConfig(name='foo')
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('Default', settings.domain_name)
+ self.assertIsNone(settings.description)
+ self.assertTrue(settings.enabled)
+ self.assertEqual(list(), settings.users)
+
+ def test_config_with_name_only(self):
+ settings = ProjectConfig(**{'name': 'foo'})
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('Default', settings.domain_name)
+ self.assertIsNone(settings.description)
+ self.assertTrue(settings.enabled)
+ self.assertEqual(list(), settings.users)
+
+ def test_all(self):
+ users = ['test1', 'test2']
+ settings = ProjectConfig(
+ name='foo', domain='bar', description='foobar', enabled=False,
+ users=users)
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('bar', settings.domain_name)
+ self.assertEqual('foobar', settings.description)
+ self.assertFalse(settings.enabled)
+ self.assertEqual(users, settings.users)
+
+ def test_config_all(self):
+ users = ['test1', 'test2']
+ settings = ProjectConfig(
+ **{'name': 'foo', 'domain': 'bar', 'description': 'foobar',
+ 'enabled': False, 'users': users})
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('bar', settings.domain_name)
+ self.assertEqual('foobar', settings.description)
+ self.assertFalse(settings.enabled)
+ self.assertEqual(users, settings.users)
diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py
index 7d405a8..0349890 100644
--- a/snaps/openstack/create_project.py
+++ b/snaps/openstack/create_project.py
@@ -16,6 +16,7 @@ import logging
from keystoneclient.exceptions import NotFound, Conflict
+from snaps.config.project import ProjectConfig
from snaps.openstack.openstack_creator import OpenStackIdentityObject
from snaps.openstack.utils import keystone_utils, neutron_utils, nova_utils
@@ -169,44 +170,15 @@ class OpenStackProject(OpenStackIdentityObject):
neutron_utils.update_quotas(neutron, self.__project.id, network_quotas)
-class ProjectSettings:
+class ProjectSettings(ProjectConfig):
"""
Class to hold the configuration settings required for creating OpenStack
project objects
+ deprecated
"""
def __init__(self, **kwargs):
-
- """
- Constructor
- :param name: the project's name (required)
- :param domain or domain_name: the project's domain name
- (default = 'Default').
- Field is used for v3 clients
- :param description: the description (optional)
- :param users: list of users to associate project to (optional)
- :param enabled: denotes whether or not the project is enabled
- (default True)
- """
-
- self.name = kwargs.get('name')
- self.domain_name = kwargs.get(
- 'domain', kwargs.get('domain', 'Default'))
-
- self.description = kwargs.get('description')
- if kwargs.get('enabled') is not None:
- self.enabled = kwargs['enabled']
- else:
- self.enabled = True
-
- self.users = kwargs.get('users', list())
-
- if not self.name:
- raise ProjectSettingsError(
- "The attribute name is required for ProjectSettings")
-
-
-class ProjectSettingsError(Exception):
- """
- Exception to be thrown when project settings attributes are incorrect
- """
+ from warnings import warn
+ warn('Use snaps.config.project.ProjectConfig instead',
+ DeprecationWarning)
+ super(self.__class__, self).__init__(**kwargs) \ No newline at end of file
diff --git a/snaps/openstack/tests/create_project_tests.py b/snaps/openstack/tests/create_project_tests.py
index aa9dcfb..178d3fe 100644
--- a/snaps/openstack/tests/create_project_tests.py
+++ b/snaps/openstack/tests/create_project_tests.py
@@ -17,9 +17,10 @@ import uuid
from keystoneclient.exceptions import BadRequest
+from snaps.config.project import ProjectConfigError, ProjectConfig
from snaps.domain.project import ComputeQuotas, NetworkQuotas
from snaps.openstack.create_project import (
- OpenStackProject, ProjectSettings, ProjectSettingsError)
+ OpenStackProject, ProjectSettings)
from snaps.openstack.create_security_group import OpenStackSecurityGroup
from snaps.openstack.create_security_group import SecurityGroupSettings
from snaps.openstack.create_user import OpenStackUser
@@ -36,11 +37,11 @@ class ProjectSettingsUnitTests(unittest.TestCase):
"""
def test_no_params(self):
- with self.assertRaises(ProjectSettingsError):
+ with self.assertRaises(ProjectConfigError):
ProjectSettings()
def test_empty_config(self):
- with self.assertRaises(ProjectSettingsError):
+ with self.assertRaises(ProjectConfigError):
ProjectSettings(**dict())
def test_name_only(self):
@@ -94,7 +95,7 @@ class CreateProjectSuccessTests(OSComponentTestCase):
"""
guid = str(uuid.uuid4())[:-19]
guid = self.__class__.__name__ + '-' + guid
- self.project_settings = ProjectSettings(
+ self.project_settings = ProjectConfig(
name=guid + '-name',
domain=self.os_creds.project_domain_name)
@@ -236,7 +237,7 @@ class CreateProjectUserTests(OSComponentTestCase):
"""
guid = str(uuid.uuid4())[:-19]
self.guid = self.__class__.__name__ + '-' + guid
- self.project_settings = ProjectSettings(
+ self.project_settings = ProjectConfig(
name=self.guid + '-name',
domain=self.os_creds.project_domain_name)
@@ -274,7 +275,8 @@ class CreateProjectUserTests(OSComponentTestCase):
user_creator = OpenStackUser(
self.os_creds, UserSettings(
name=self.guid + '-user',
- password=self.guid, roles={'admin': self.project_settings.name},
+ password=self.guid, roles={
+ 'admin': self.project_settings.name},
domain_name=self.os_creds.user_domain_name))
self.project_creator.assoc_user(user_creator.create())
self.user_creators.append(user_creator)
@@ -282,8 +284,8 @@ class CreateProjectUserTests(OSComponentTestCase):
sec_grp_os_creds = user_creator.get_os_creds(
self.project_creator.get_project().name)
sec_grp_creator = OpenStackSecurityGroup(
- sec_grp_os_creds, SecurityGroupSettings(name=self.guid + '-name',
- description='hello group'))
+ sec_grp_os_creds, SecurityGroupSettings(
+ name=self.guid + '-name', description='hello group'))
sec_grp = sec_grp_creator.create()
self.assertIsNotNone(sec_grp)
self.sec_grp_creators.append(sec_grp_creator)
diff --git a/snaps/openstack/tests/os_source_file_test.py b/snaps/openstack/tests/os_source_file_test.py
index 1617f91..db54f10 100644
--- a/snaps/openstack/tests/os_source_file_test.py
+++ b/snaps/openstack/tests/os_source_file_test.py
@@ -14,13 +14,11 @@
# limitations under the License.
import logging
import pkg_resources
-import requests
-from requests.packages.urllib3.exceptions import InsecureRequestWarning
import uuid
import unittest
from snaps import file_utils
-from snaps.openstack.create_project import ProjectSettings
+from snaps.config.project import ProjectConfig
from snaps.openstack.create_user import UserSettings
from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import deploy_utils, keystone_utils
@@ -29,8 +27,6 @@ from snaps.openstack.utils import deploy_utils, keystone_utils
dev_os_env_file = pkg_resources.resource_filename(
'snaps.openstack.tests.conf', 'os_env.yaml')
-requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
-
class OSComponentTestCase(unittest.TestCase):
@@ -149,7 +145,7 @@ class OSIntegrationTestCase(OSComponentTestCase):
guid = self.__class__.__name__ + '-' + str(uuid.uuid4())[:-19]
project_name = guid + '-proj'
self.project_creator = deploy_utils.create_project(
- self.admin_os_creds, ProjectSettings(
+ self.admin_os_creds, ProjectConfig(
name=project_name,
domain=self.admin_os_creds.project_domain_name))
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index 387f6c7..b8769c0 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -114,7 +114,7 @@ def get_project(keystone=None, os_creds=None, project_settings=None,
:param keystone: the Keystone client
:param os_creds: the OpenStack credentials used to obtain the Keystone
client if the keystone parameter is None
- :param project_settings: a ProjectSettings object
+ :param project_settings: a ProjectConfig object
:param project_name: the name to query
:return: the SNAPS-OO Project domain object or None
"""
diff --git a/snaps/openstack/utils/tests/keystone_utils_tests.py b/snaps/openstack/utils/tests/keystone_utils_tests.py
index bd0086b..ef08acc 100644
--- a/snaps/openstack/utils/tests/keystone_utils_tests.py
+++ b/snaps/openstack/utils/tests/keystone_utils_tests.py
@@ -14,7 +14,7 @@
# limitations under the License.
import uuid
-from snaps.openstack.create_project import ProjectSettings
+from snaps.config.project import ProjectConfig
from snaps.openstack.create_user import UserSettings
from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
from snaps.openstack.utils import keystone_utils, neutron_utils
@@ -111,7 +111,7 @@ class KeystoneUtilsTests(OSComponentTestCase):
"""
Tests the keyston_utils.create_project() funtion
"""
- project_settings = ProjectSettings(
+ project_settings = ProjectConfig(
name=self.project_name, domain=self.os_creds.project_domain_name)
self.project = keystone_utils.create_project(self.keystone,
project_settings)
@@ -186,7 +186,7 @@ class KeystoneUtilsTests(OSComponentTestCase):
self.user = keystone_utils.create_user(self.keystone, user_settings)
self.assertEqual(self.username, self.user.name)
- project_settings = ProjectSettings(
+ project_settings = ProjectConfig(
name=self.project_name, domain=self.os_creds.project_domain_name)
self.project = keystone_utils.create_project(self.keystone,
project_settings)
diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py
index 3f8f5c5..235bb91 100644
--- a/snaps/test_suite_builder.py
+++ b/snaps/test_suite_builder.py
@@ -16,6 +16,7 @@
import logging
import unittest
+from snaps.config.tests.project_tests import ProjectConfigUnitTests
from snaps.config.tests.keypair_tests import KeypairConfigUnitTests
from snaps.config.tests.flavor_tests import FlavorConfigUnitTests
import snaps.config.tests.image_tests as image_tests
@@ -158,6 +159,8 @@ def add_unit_tests(suite):
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
UserDomainObjectTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ ProjectConfigUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
ProjectSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
ProjectDomainObjectTests))