summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-06-28 09:20:13 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-05 08:47:29 -0600
commit139af8603aa484c1ba08997f30204fb7be146606 (patch)
treed15a7b71a1a5780e5b4447071a9fb886d38f5d5e
parent2a4dc5493763a241c9895652bf1c71ac3ef0e5b3 (diff)
Refactor OSCreds to leverage kwargs instead of named parameters.
JIRA: SNAPS-109 Change-Id: I423ede964cce9fc3b4e5b27f1e8f0dd7603d9ff1 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--examples/launch.py14
-rw-r--r--snaps/openstack/os_credentials.py136
-rw-r--r--snaps/openstack/tests/conf/os_credentials_tests.py208
-rw-r--r--snaps/openstack/tests/openstack_tests.py10
-rw-r--r--snaps/openstack/utils/tests/glance_utils_tests.py34
-rw-r--r--snaps/openstack/utils/tests/keystone_utils_tests.py26
-rw-r--r--snaps/test_suite_builder.py50
7 files changed, 365 insertions, 113 deletions
diff --git a/examples/launch.py b/examples/launch.py
index 8f6697a..9067730 100644
--- a/examples/launch.py
+++ b/examples/launch.py
@@ -51,13 +51,12 @@ def __get_os_credentials(os_conn_config):
if http_proxy:
tokens = re.split(':', http_proxy)
ssh_proxy_cmd = os_conn_config.get('ssh_proxy_cmd')
- proxy_settings = ProxySettings(tokens[0], tokens[1], ssh_proxy_cmd)
+ proxy_settings = ProxySettings(host=tokens[0], port=tokens[1],
+ ssh_proxy_cmd=ssh_proxy_cmd)
- return OSCreds(username=os_conn_config.get('username'),
- password=os_conn_config.get('password'),
- auth_url=os_conn_config.get('auth_url'),
- project_name=os_conn_config.get('project_name'),
- proxy_settings=proxy_settings)
+ os_conn_config['proxy_settings'] = proxy_settings
+
+ return OSCreds(**os_conn_config)
def __parse_ports_config(config):
@@ -567,9 +566,6 @@ def __get_flavor_variable_value(var_config_values, flavor_dict):
var_config_values['value'] == 'id':
return flavor_creator.get_flavor().id
- logger.info("Returning none")
- return None
-
def main(arguments):
"""
diff --git a/snaps/openstack/os_credentials.py b/snaps/openstack/os_credentials.py
index 072c00a..caf7682 100644
--- a/snaps/openstack/os_credentials.py
+++ b/snaps/openstack/os_credentials.py
@@ -20,91 +20,115 @@ class OSCreds:
Represents the credentials required to connect with OpenStack servers
"""
- def __init__(self, username, password, auth_url, project_name, identity_api_version=2, image_api_version=2,
- network_api_version=2, compute_api_version=2, user_domain_id='default', project_domain_id='default',
- interface="admin", proxy_settings=None, cacert=True):
+ def __init__(self, **kwargs):
"""
Constructor
:param username: The user (required)
:param password: The user's password (required)
:param auth_url: The OpenStack cloud's authorization URL (required)
:param project_name: The project/tenant name
- :param identity_api_version: The OpenStack's API version to use for Keystone clients
- :param image_api_version: The OpenStack's API version to use for Glance clients
- :param network_api_version: The OpenStack's API version to use for Neutron clients
- :param compute_api_version: The OpenStack's API version to use for Nova clients
+ :param identity_api_version: The OpenStack's API version to use for
+ Keystone clients
+ :param image_api_version: The OpenStack's API version to use for Glance
+ clients
+ :param network_api_version: The OpenStack's API version to use for
+ Neutron clients
+ :param compute_api_version: The OpenStack's API version to use for Nova
+ clients
:param user_domain_id: Used for v3 APIs
:param project_domain_id: Used for v3 APIs
- :param interface: Used to specify the endpoint type for keystone as public, admin, internal
+ :param interface: Used to specify the endpoint type for keystone as
+ public, admin, internal
:param proxy_settings: instance of os_credentials.ProxySettings class
- :param cacert: Default to be True for http, or the certification file is specified for https verification,
- or set to be False to disable server certificate verification without cert file
+ :param cacert: Default to be True for http, or the certification file
+ is specified for https verification, or set to be False
+ to disable server certificate verification without cert
+ file
"""
- self.username = username
- self.password = password
- self.auth_url = auth_url
- self.project_name = project_name
- self.identity_api_version = identity_api_version
- self.image_api_version = image_api_version
- self.network_api_version = network_api_version
- self.compute_api_version = compute_api_version
- self.user_domain_id = user_domain_id
- self.project_domain_id = project_domain_id
- self.interface = interface
- self.proxy_settings = proxy_settings
- self.cacert = cacert
-
- if self.proxy_settings and not isinstance(self.proxy_settings, ProxySettings):
- raise Exception('proxy_settings must be an instance of the class ProxySettings')
-
- if self.auth_url:
- auth_url_tokens = self.auth_url.split('/')
- last_token = auth_url_tokens[len(auth_url_tokens) - 1]
- if len(last_token) == 0:
- last_token = auth_url_tokens[len(auth_url_tokens) - 2]
-
- if not last_token.startswith('v'):
- raise Exception('auth_url last toke must start with \'v\'')
+ self.username = kwargs.get('username')
+ self.password = kwargs.get('password')
+ self.auth_url = kwargs.get('auth_url')
+ self.project_name = kwargs.get('project_name')
+ self.identity_api_version = kwargs.get('identity_api_version', 2)
+ self.image_api_version = kwargs.get('image_api_version', 2)
+ self.network_api_version = kwargs.get('network_api_version', 2)
+ self.compute_api_version = kwargs.get('compute_api_version', 2)
+ self.user_domain_id = kwargs.get('user_domain_id', 'default')
+ self.project_domain_id = kwargs.get('project_domain_id', 'default')
+ self.interface = kwargs.get('interface', 'admin')
+ self.cacert = kwargs.get('cacert', True)
+ if isinstance(kwargs.get('proxy_settings'), ProxySettings):
+ self.proxy_settings = kwargs.get('proxy_settings')
+ elif isinstance(kwargs.get('proxy_settings'), dict):
+ self.proxy_settings = ProxySettings(**kwargs.get('proxy_settings'))
+ else:
+ self.proxy_settings = None
+
+ if (not self.username or not self.password or not self.auth_url
+ or not self.project_name):
+ raise OSCredsError('username, password, auth_url, and project_name'
+ ' are required')
+
+ auth_url_tokens = self.auth_url.split('/')
+ last_token = auth_url_tokens[len(auth_url_tokens) - 1]
+ if len(last_token) == 0:
+ last_token = auth_url_tokens[len(auth_url_tokens) - 2]
+
+ if not last_token.startswith('v'):
+ raise OSCredsError('auth_url last toke must start with \'v\'')
+
+ @property
def __str__(self):
"""Converts object to a string"""
- return 'OSCreds - username=' + str(self.username) + \
- ', password=' + str(self.password) + \
- ', auth_url=' + str(self.auth_url) + \
- ', project_name=' + str(self.project_name) + \
- ', identity_api_version=' + str(self.identity_api_version) + \
- ', image_api_version=' + str(self.image_api_version) + \
- ', network_api_version=' + str(self.network_api_version) + \
- ', compute_api_version=' + str(self.compute_api_version) + \
- ', user_domain_id=' + str(self.user_domain_id) + \
- ', interface=' + str(self.interface) + \
- ', proxy_settings=' + str(self.proxy_settings) + \
- ', cacert=' + str(self.cacert)
+ return ('OSCreds - username=' + str(self.username) +
+ ', password=' + str(self.password) +
+ ', auth_url=' + str(self.auth_url) +
+ ', project_name=' + str(self.project_name) +
+ ', identity_api_version=' + str(self.identity_api_version) +
+ ', image_api_version=' + str(self.image_api_version) +
+ ', network_api_version=' + str(self.network_api_version) +
+ ', compute_api_version=' + str(self.compute_api_version) +
+ ', user_domain_id=' + str(self.user_domain_id) +
+ ', interface=' + str(self.interface) +
+ ', proxy_settings=' + str(self.proxy_settings) +
+ ', cacert=' + str(self.cacert))
class ProxySettings:
"""
- Represents the information required for sending traffic (HTTP & SSH) through a proxy
+ Represents the information required for sending traffic (HTTP & SSH)
+ through a proxy
"""
- def __init__(self, host, port, ssh_proxy_cmd=None):
+ def __init__(self, **kwargs):
"""
Constructor
:param host: the HTTP proxy host
:param port: the HTTP proxy port
:param ssh_proxy_cmd: the SSH proxy command string (optional)
"""
- # TODO - Add necessary fields here when adding support for secure proxies
+ self.host = kwargs.get('host')
+ self.port = kwargs.get('port')
+ self.ssh_proxy_cmd = kwargs.get('ssh_proxy_cmd')
- self.host = host
- self.port = port
- self.ssh_proxy_cmd = ssh_proxy_cmd
-
- if not self.host and not self.port:
- raise Exception('host & port are required')
+ if not self.host or not self.port:
+ raise ProxySettingsError('host & port are required')
def __str__(self):
"""Converts object to a string"""
return 'ProxySettings - host=' + str(self.host) + \
', port=' + str(self.port) + \
', ssh_proxy_cmd=' + str(self.ssh_proxy_cmd)
+
+
+class ProxySettingsError(Exception):
+ """
+ Exception to be thrown when an OSCred are invalid
+ """
+
+
+class OSCredsError(Exception):
+ """
+ Exception to be thrown when an OSCred are invalid
+ """
diff --git a/snaps/openstack/tests/conf/os_credentials_tests.py b/snaps/openstack/tests/conf/os_credentials_tests.py
new file mode 100644
index 0000000..1c61b41
--- /dev/null
+++ b/snaps/openstack/tests/conf/os_credentials_tests.py
@@ -0,0 +1,208 @@
+# 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 logging
+import unittest
+
+from snaps.openstack.os_credentials import OSCredsError, OSCreds, \
+ ProxySettings, ProxySettingsError
+
+__author__ = 'spisarski'
+
+logger = logging.getLogger('os_credentials_test')
+
+
+class ProxySettingsUnitTests(unittest.TestCase):
+ """
+ Tests the construction of the ProxySettings class
+ """
+
+ def test_no_params(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings()
+
+ def test_empty_kwargs(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings(**dict())
+
+ def test_host_only(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings(host='foo')
+
+ def test_host_only_kwargs(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings(**{'host': 'foo'})
+
+ def test_port_only(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings(port=1234)
+
+ def test_port_only_kwargs(self):
+ with self.assertRaises(ProxySettingsError):
+ ProxySettings(**{'port': 1234})
+
+ def test_minimum(self):
+ proxy_settings = ProxySettings(host='foo', port=1234)
+ self.assertEqual('foo', proxy_settings.host)
+ self.assertEqual(1234, proxy_settings.port)
+ self.assertIsNone(proxy_settings.ssh_proxy_cmd)
+
+ def test_minimum_kwargs(self):
+ proxy_settings = ProxySettings(**{'host': 'foo', 'port': 1234})
+ self.assertEqual('foo', proxy_settings.host)
+ self.assertEqual(1234, proxy_settings.port)
+ self.assertIsNone(proxy_settings.ssh_proxy_cmd)
+
+ def test_all(self):
+ proxy_settings = ProxySettings(host='foo', port=1234,
+ ssh_proxy_cmd='proxy command')
+ self.assertEqual('foo', proxy_settings.host)
+ self.assertEqual(1234, proxy_settings.port)
+ self.assertEqual('proxy command', proxy_settings.ssh_proxy_cmd)
+
+ def test_all_kwargs(self):
+ proxy_settings = ProxySettings(
+ **{'host': 'foo', 'port': 1234, 'ssh_proxy_cmd': 'proxy command'})
+ self.assertEqual('foo', proxy_settings.host)
+ self.assertEqual(1234, proxy_settings.port)
+ self.assertEqual('proxy command', proxy_settings.ssh_proxy_cmd)
+
+
+class OSCredsUnitTests(unittest.TestCase):
+ """
+ Tests the construction of the OSCreds class
+ """
+
+ def test_no_params(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds()
+
+ def test_empty_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**dict())
+
+ def test_username_only(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(username='foo')
+
+ def test_username_only_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**{'username': 'foo'})
+
+ def test_password_only(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(password='foo')
+
+ def test_password_only_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**{'password': 'foo'})
+
+ def test_auth_url_only(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(auth_url='foo')
+
+ def test_auth_url_only_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**{'auth_url': 'foo'})
+
+ def test_project_name_only(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(project_name='foo')
+
+ def test_project_name_only_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**{'project_name': 'foo'})
+
+ def test_invalid_auth_url(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(username='foo', password='bar',
+ auth_url='http://foo.bar', project_name='hello')
+
+ def test_invalid_auth_url_kwargs(self):
+ with self.assertRaises(OSCredsError):
+ OSCreds(**{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar', 'project_name': 'hello'})
+
+ def test_minimal(self):
+ os_creds = OSCreds(
+ username='foo', password='bar', auth_url='http://foo.bar:5000/v2',
+ project_name='hello')
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertIsNone(os_creds.proxy_settings)
+
+ def test_minimal_kwargs(self):
+ os_creds = OSCreds(**{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar:5000/v2',
+ 'project_name': 'hello'})
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertIsNone(os_creds.proxy_settings)
+
+ def test_proxy_settings_obj(self):
+ proxy_settings = ProxySettings(host='foo', port=1234)
+ os_creds = OSCreds(
+ username='foo', password='bar', auth_url='http://foo.bar:5000/v2',
+ project_name='hello', proxy_settings=proxy_settings)
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertEqual('foo', os_creds.proxy_settings.host)
+ self.assertEqual(1234, os_creds.proxy_settings.port)
+ self.assertIsNone(os_creds.proxy_settings.ssh_proxy_cmd)
+
+ def test_proxy_settings_obj_kwargs(self):
+ proxy_settings = ProxySettings(host='foo', port=1234)
+ os_creds = OSCreds(**{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar:5000/v2',
+ 'project_name': 'hello',
+ 'proxy_settings': proxy_settings})
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertEqual('foo', os_creds.proxy_settings.host)
+ self.assertEqual(1234, os_creds.proxy_settings.port)
+ self.assertIsNone(os_creds.proxy_settings.ssh_proxy_cmd)
+
+ def test_proxy_settings_dict(self):
+ os_creds = OSCreds(
+ username='foo', password='bar', auth_url='http://foo.bar:5000/v2',
+ project_name='hello', proxy_settings={'host': 'foo', 'port': 1234})
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertEqual('foo', os_creds.proxy_settings.host)
+ self.assertEqual(1234, os_creds.proxy_settings.port)
+ self.assertIsNone(os_creds.proxy_settings.ssh_proxy_cmd)
+
+ def test_proxy_settings_dict_kwargs(self):
+ os_creds = OSCreds(**{'username': 'foo', 'password': 'bar',
+ 'auth_url': 'http://foo.bar:5000/v2',
+ 'project_name': 'hello',
+ 'proxy_settings': {'host': 'foo', 'port': 1234}})
+ self.assertEqual('foo', os_creds.username)
+ self.assertEqual('bar', os_creds.password)
+ self.assertEqual('http://foo.bar:5000/v2', os_creds.auth_url)
+ self.assertEqual('hello', os_creds.project_name)
+ self.assertEqual('foo', os_creds.proxy_settings.host)
+ self.assertEqual(1234, os_creds.proxy_settings.port)
+ self.assertIsNone(os_creds.proxy_settings.ssh_proxy_cmd)
diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py
index d0c250f..59c7395 100644
--- a/snaps/openstack/tests/openstack_tests.py
+++ b/snaps/openstack/tests/openstack_tests.py
@@ -83,7 +83,8 @@ def get_credentials(os_env_file=None, proxy_settings_str=None,
proxy_settings = None
if proxy_settings_str:
tokens = re.split(':', proxy_settings_str)
- proxy_settings = ProxySettings(tokens[0], tokens[1], ssh_proxy_cmd)
+ proxy_settings = ProxySettings(host=tokens[0], port=tokens[1],
+ ssh_proxy_cmd=ssh_proxy_cmd)
if config.get('OS_CACERT'):
https_cacert = config.get('OS_CACERT')
@@ -121,8 +122,9 @@ def get_credentials(os_env_file=None, proxy_settings_str=None,
proxy_str = config.get('http_proxy')
if proxy_str:
tokens = re.split(':', proxy_str)
- proxy_settings = ProxySettings(tokens[0], tokens[1],
- config.get('ssh_proxy_cmd'))
+ proxy_settings = ProxySettings(
+ host=tokens[0], port=tokens[1],
+ ssh_proxy_cmd=config.get('ssh_proxy_cmd'))
os_creds = OSCreds(username=config['username'],
password=config['password'],
@@ -132,7 +134,7 @@ def get_credentials(os_env_file=None, proxy_settings_str=None,
image_api_version=image_api_version,
proxy_settings=proxy_settings)
- logger.info('OS Credentials = ' + str(os_creds))
+ logger.info('OS Credentials = %s', os_creds)
return os_creds
diff --git a/snaps/openstack/utils/tests/glance_utils_tests.py b/snaps/openstack/utils/tests/glance_utils_tests.py
index 5fa585c..85b59ab 100644
--- a/snaps/openstack/utils/tests/glance_utils_tests.py
+++ b/snaps/openstack/utils/tests/glance_utils_tests.py
@@ -50,7 +50,9 @@ class GlanceSmokeTests(OSComponentTestCase):
from snaps.openstack.os_credentials import OSCreds
with self.assertRaises(Exception):
- glance = glance_utils.glance_client(OSCreds('user', 'pass', 'url', 'project'))
+ glance = glance_utils.glance_client(OSCreds(
+ username='user', password='pass', auth_url='url',
+ project_name='project'))
glance_utils.get_image(glance, 'foo')
@@ -61,8 +63,8 @@ class GlanceUtilsTests(OSComponentTestCase):
def setUp(self):
"""
- Instantiates the CreateImage object that is responsible for downloading and creating an OS image file
- within OpenStack
+ Instantiates the CreateImage object that is responsible for downloading
+ and creating an OS image file within OpenStack
"""
guid = uuid.uuid4()
self.image_name = self.__class__.__name__ + '-' + str(guid)
@@ -89,14 +91,15 @@ class GlanceUtilsTests(OSComponentTestCase):
def test_create_image_minimal_url(self):
"""
- Tests the glance_utils.create_image() function with a URL unless the self.glance_test_meta has configured a
- file to be used.
+ Tests the glance_utils.create_image() function with a URL unless the
+ self.glance_test_meta has configured a file to be used.
"""
if 'disk_file' not in self.glance_test_meta:
- os_image_settings = openstack_tests.cirros_image_settings(name=self.image_name,
- image_metadata=self.glance_test_meta)
+ os_image_settings = openstack_tests.cirros_image_settings(
+ name=self.image_name, image_metadata=self.glance_test_meta)
- self.image = glance_utils.create_image(self.glance, os_image_settings)
+ self.image = glance_utils.create_image(self.glance,
+ os_image_settings)
self.assertIsNotNone(self.image)
self.assertEqual(self.image_name, self.image.name)
@@ -106,21 +109,26 @@ class GlanceUtilsTests(OSComponentTestCase):
validation_utils.objects_equivalent(self.image, image)
else:
- logger.warn('Test not executed as the image metadata requires image files')
+ logger.warn('Test not executed as the image metadata requires '
+ 'image files')
def test_create_image_minimal_file(self):
"""
Tests the glance_utils.create_image() function with a file
"""
if 'disk_file' not in self.glance_test_meta:
- url_image_settings = openstack_tests.cirros_image_settings(name='foo', image_metadata=self.glance_test_meta)
- image_file_name = file_utils.download(url_image_settings.url, self.tmp_dir).name
+ url_image_settings = openstack_tests.cirros_image_settings(
+ name='foo', image_metadata=self.glance_test_meta)
+ image_file_name = file_utils.download(
+ url_image_settings.url, self.tmp_dir).name
else:
image_file_name = self.glance_test_meta['disk_file']
- file_image_settings = openstack_tests.file_image_test_settings(name=self.image_name, file_path=image_file_name)
+ file_image_settings = openstack_tests.file_image_test_settings(
+ name=self.image_name, file_path=image_file_name)
- self.image = glance_utils.create_image(self.glance, file_image_settings)
+ self.image = glance_utils.create_image(self.glance,
+ file_image_settings)
self.assertIsNotNone(self.image)
self.assertEqual(self.image_name, self.image.name)
diff --git a/snaps/openstack/utils/tests/keystone_utils_tests.py b/snaps/openstack/utils/tests/keystone_utils_tests.py
index 845b20b..347b8e0 100644
--- a/snaps/openstack/utils/tests/keystone_utils_tests.py
+++ b/snaps/openstack/utils/tests/keystone_utils_tests.py
@@ -43,7 +43,9 @@ class KeystoneSmokeTests(OSComponentTestCase):
from snaps.openstack.os_credentials import OSCreds
with self.assertRaises(Exception):
- keystone = keystone_utils.keystone_client(OSCreds('user', 'pass', 'url', 'project'))
+ keystone = keystone_utils.keystone_client(OSCreds(
+ username='user', password='pass', auth_url='url',
+ project_name='project'))
keystone.users.list()
@@ -54,8 +56,8 @@ class KeystoneUtilsTests(OSComponentTestCase):
def setUp(self):
"""
- Instantiates the CreateImage object that is responsible for downloading and creating an OS image file
- within OpenStack
+ Instantiates the CreateImage object that is responsible for downloading
+ and creating an OS image file within OpenStack
"""
guid = uuid.uuid4()
self.username = self.__class__.__name__ + '-' + str(guid)
@@ -92,16 +94,19 @@ class KeystoneUtilsTests(OSComponentTestCase):
Tests the keyston_utils.create_project() funtion
"""
project_settings = ProjectSettings(name=self.project_name)
- self.project = keystone_utils.create_project(self.keystone, project_settings)
+ self.project = keystone_utils.create_project(self.keystone,
+ project_settings)
self.assertEqual(self.project_name, self.project.name)
- project = keystone_utils.get_project(keystone=self.keystone, project_name=project_settings.name)
+ project = keystone_utils.get_project(
+ keystone=self.keystone, project_name=project_settings.name)
self.assertIsNotNone(project)
self.assertEqual(self.project_name, self.project.name)
def test_get_endpoint_success(self):
"""
- Tests to ensure that proper credentials and proper service type can succeed.
+ Tests to ensure that proper credentials and proper service type can
+ succeed.
"""
endpoint = keystone_utils.get_endpoint(self.os_creds,
service_type="identity")
@@ -109,18 +114,21 @@ class KeystoneUtilsTests(OSComponentTestCase):
def test_get_endpoint_fail_without_proper_service(self):
"""
- Tests to ensure that proper credentials and improper service type cannot succeed.
+ Tests to ensure that proper credentials and improper service type
+ cannot succeed.
"""
with self.assertRaises(Exception):
keystone_utils.get_endpoint(self.os_creds, service_type="glance")
def test_get_endpoint_fail_without_proper_credentials(self):
"""
- Tests to ensure that improper credentials and proper service type cannot succeed.
+ Tests to ensure that improper credentials and proper service type
+ cannot succeed.
"""
from snaps.openstack.os_credentials import OSCreds
with self.assertRaises(Exception):
keystone_utils.get_endpoint(
- OSCreds('user', 'pass', 'url', 'project'),
+ OSCreds(username='user', password='pass', auth_url='url',
+ project_name='project'),
service_type="image")
diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py
index bf9df20..6c28b7e 100644
--- a/snaps/test_suite_builder.py
+++ b/snaps/test_suite_builder.py
@@ -20,6 +20,8 @@ from snaps.domain.test.image_tests import ImageDomainObjectTests
from snaps.domain.test.stack_tests import StackDomainObjectTests
from snaps.domain.test.vm_inst_tests import (VmInstDomainObjectTests,
FloatingIpDomainObjectTests)
+from snaps.openstack.tests.conf.os_credentials_tests import (
+ ProxySettingsUnitTests, OSCredsUnitTests)
from snaps.openstack.tests.create_flavor_tests import CreateFlavorTests
from snaps.openstack.tests.create_image_tests import (
CreateImageSuccessTests, CreateImageNegativeTests, ImageSettingsUnitTests,
@@ -80,33 +82,37 @@ def add_unit_tests(suite):
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
SecurityGroupRuleSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ ProxySettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ OSCredsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
SecurityGroupSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(ImageSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(ImageDomainObjectTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(KeypairSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(UserSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(ProjectSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(NetworkSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(SubnetSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(PortSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ ImageSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ ImageDomainObjectTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ KeypairSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ UserSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ ProjectSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ NetworkSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ SubnetSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ PortSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
FloatingIpSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
VmInstanceSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(StackDomainObjectTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(StackSettingsUnitTests))
- suite.addTest(
- unittest.TestLoader().loadTestsFromTestCase(VmInstDomainObjectTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ StackDomainObjectTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ StackSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ VmInstDomainObjectTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
FloatingIpDomainObjectTests))