summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-18 09:37:07 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-20 11:27:52 -0600
commitdc7c6640c95a40623603964df6fde4adcca41e5c (patch)
tree39f7441e2ccf3345add2888dc49b3ed739d2533e /snaps/openstack/utils
parentacda399def76b37345f298c7df14ae2594cdc147 (diff)
Changes required for running CI tests (Pike pod).
Added support for HTTPS proxies HTTPS OSCreds settings for both RC file and os_env.yaml OSCreds 'cacert' T/F and cert file path support OSCreds API version support cleanup including the addition of heat Added more OSCreds test validations Disabling of InsecureRequestWarning PEP8 line width refactoring heat_utils_test.py fix when stack status is error test suite for CI removed default flavor metadata of mem_page_size: Any to None JIRA: SNAPS-80 Change-Id: I333e83ca79d7403bf43a9b74da4c072b4da976ba Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils')
-rw-r--r--snaps/openstack/utils/heat_utils.py12
-rw-r--r--snaps/openstack/utils/keystone_utils.py21
-rw-r--r--snaps/openstack/utils/nova_utils.py13
-rw-r--r--snaps/openstack/utils/tests/heat_utils_tests.py3
4 files changed, 32 insertions, 17 deletions
diff --git a/snaps/openstack/utils/heat_utils.py b/snaps/openstack/utils/heat_utils.py
index d40e3b9..a631b35 100644
--- a/snaps/openstack/utils/heat_utils.py
+++ b/snaps/openstack/utils/heat_utils.py
@@ -36,7 +36,8 @@ def heat_client(os_creds):
:return: the client
"""
logger.debug('Retrieving Nova Client')
- return Client(1, session=keystone_utils.keystone_session(os_creds))
+ return Client(os_creds.heat_api_version,
+ session=keystone_utils.keystone_session(os_creds))
def get_stack_by_name(heat_cli, stack_name):
@@ -97,7 +98,8 @@ def create_stack(heat_cli, stack_settings):
if stack_settings.template:
args['template'] = stack_settings.template
else:
- args['template'] = parse_heat_template_str(file_utils.read_file(stack_settings.template_path))
+ args['template'] = parse_heat_template_str(
+ file_utils.read_file(stack_settings.template_path))
args['stack_name'] = stack_settings.name
if stack_settings.env_values:
@@ -118,8 +120,10 @@ def delete_stack(heat_cli, stack):
def parse_heat_template_str(tmpl_str):
- """Takes a heat template string, performs some simple validation and returns a dict containing the parsed structure.
- This function supports both JSON and YAML Heat template formats.
+ """
+ Takes a heat template string, performs some simple validation and returns a
+ dict containing the parsed structure. This function supports both JSON and
+ YAML Heat template formats.
"""
if tmpl_str.startswith('{'):
tpl = jsonutils.loads(tmpl_str)
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index 9bfc647..4eda4e4 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -25,7 +25,8 @@ from snaps.domain.user import User
logger = logging.getLogger('keystone_utils')
-V2_VERSION = 'v2.0'
+V2_VERSION_NUM = 2.0
+V2_VERSION_STR = 'v' + str(V2_VERSION_NUM)
def get_session_auth(os_creds):
@@ -65,7 +66,11 @@ def keystone_session(os_creds):
req_session.proxies = {
'http':
os_creds.proxy_settings.host + ':' +
- os_creds.proxy_settings.port}
+ os_creds.proxy_settings.port,
+ 'https':
+ os_creds.proxy_settings.https_host + ':' +
+ os_creds.proxy_settings.https_port
+ }
return session.Session(auth=auth, session=req_session,
verify=os_creds.cacert)
@@ -114,7 +119,7 @@ def get_project(keystone=None, os_creds=None, project_name=None):
raise KeystoneException(
'Cannot lookup project without the proper credentials')
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
projects = keystone.tenants.list()
else:
projects = keystone.projects.list(**{'name': project_name})
@@ -133,7 +138,7 @@ def create_project(keystone, project_settings):
:param project_settings: the project configuration
:return: SNAPS-OO Project domain object
"""
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
os_project = keystone.tenants.create(
project_settings.name, project_settings.description,
project_settings.enabled)
@@ -152,7 +157,7 @@ def delete_project(keystone, project):
:param keystone: the Keystone clien
:param project: the SNAPS-OO Project domain object
"""
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
keystone.tenants.delete(project.id)
else:
keystone.projects.delete(project.id)
@@ -202,7 +207,7 @@ def create_user(keystone, user_settings):
project = get_project(keystone=keystone,
project_name=user_settings.project_name)
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
project_id = None
if project:
project_id = project.id
@@ -267,7 +272,7 @@ def get_roles_by_user(keystone, user, project):
:param project: the OpenStack project object (only required for v2)
:return: a list of SNAPS-OO Role domain objects
"""
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
os_user = __get_os_user(keystone, user)
roles = keystone.roles.roles_for_user(os_user, project)
else:
@@ -322,7 +327,7 @@ def grant_user_role_to_project(keystone, role, user, project):
"""
os_role = get_role_by_id(keystone, role.id)
- if keystone.version == V2_VERSION:
+ if keystone.version == V2_VERSION_STR:
keystone.roles.add_user_role(user, os_role, tenant=project)
else:
keystone.roles.grant(os_role, user=user, project=project)
diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py
index fd42c5d..16b3984 100644
--- a/snaps/openstack/utils/nova_utils.py
+++ b/snaps/openstack/utils/nova_utils.py
@@ -91,9 +91,11 @@ def create_server(nova, neutron, glance, instance_settings, image_settings,
'key_name': keypair_name,
'security_groups':
instance_settings.security_group_names,
- 'userdata': instance_settings.userdata,
- 'availability_zone':
- instance_settings.availability_zone}
+ 'userdata': instance_settings.userdata}
+
+ if instance_settings.availability_zone:
+ args['availability_zone'] = instance_settings.availability_zone
+
server = nova.servers.create(**args)
return VmInst(name=server.name, inst_id=server.id,
networks=server.networks)
@@ -322,16 +324,17 @@ def delete_keypair(nova, key):
nova.keypairs.delete(key.id)
-def get_nova_availability_zones(nova):
+def get_availability_zone_hosts(nova, zone_name='nova'):
"""
Returns the names of all nova active compute servers
:param nova: the Nova client
+ :param zone_name: the Nova client
:return: a list of compute server names
"""
out = list()
zones = nova.availability_zones.list()
for zone in zones:
- if zone.zoneName == 'nova':
+ if zone.zoneName == zone_name and zone.hosts:
for key, host in zone.hosts.items():
if host['nova-compute']['available']:
out.append(zone.zoneName + ':' + key)
diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py
index eefc1bf..2ef0c68 100644
--- a/snaps/openstack/utils/tests/heat_utils_tests.py
+++ b/snaps/openstack/utils/tests/heat_utils_tests.py
@@ -139,6 +139,9 @@ class HeatUtilsCreateStackTests(OSComponentTestCase):
if status == create_stack.STATUS_CREATE_COMPLETE:
is_active = True
break
+ elif status == create_stack.STATUS_CREATE_FAILED:
+ is_active = False
+ break
time.sleep(3)