#!/usr/bin/python # # Copyright (c) 2015 All rights reserved # This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 # which accompanies this distribution, and is available at # # http://www.apache.org/licenses/LICENSE-2.0 # # Maintainer : jose.lausuch@ericsson.com # import argparse import json import os import subprocess import time import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils import functest.utils.openstack_utils as openstack_utils import keystoneclient.v2_0.client as ksclient from neutronclient.v2_0 import client as ntclient import novaclient.client as nvclient import yaml parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", help="Debug mode", action="store_true") parser.add_argument("-r", "--report", help="Create json result file", action="store_true") args = parser.parse_args() with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f: functest_yaml = yaml.safe_load(f) dirs = functest_yaml.get('general').get('directories') FUNCTEST_REPO = dirs.get('dir_repo_functest') PROMISE_REPO = dirs.get('dir_repo_promise') TEST_DB = functest_yaml.get('results').get('test_db_url') TENANT_NAME = functest_yaml.get('promise').get('general').get('tenant_name') TENANT_DESCRIPTION = functest_yaml.get('promise').get( 'general').get('tenant_description') USER_NAME = functest_yaml.get('promise').get('general').get('user_name') USER_PWD = functest_yaml.get('promise').get('general').get('user_pwd') IMAGE_NAME = functest_yaml.get('promise').get('general').get('image_name') FLAVOR_NAME = functest_yaml.get('promise').get('general').get('flavor_name') FLAVOR_VCPUS = functest_yaml.get('promise').get('general').get('flavor_vcpus') FLAVOR_RAM = functest_yaml.get('promise').get('general').get('flavor_ram') FLAVOR_DISK = functest_yaml.get('promise').get('general').get('flavor_disk') GLANCE_IMAGE_FILENAME = functest_yaml.get('general').get('openstack').get( 'image_file_name') GLANCE_IMAGE_FORMAT = functest_yaml.get('general').get('openstack').get( 'image_disk_format') GLANCE_IMAGE_PATH = functest_yaml.get('general').get('directories').get( 'dir_functest_data') + "/" + GLANCE_IMAGE_FILENAME NET_NAME = functest_yaml.get('promise').get('general').get('network_name') SUBNET_NAME = functest_yaml.get('promise').get('general').get('subnet_name') SUBNET_CIDR = functest_yaml.get('promise').get('general').get('subnet_cidr') ROUTER_NAME = functest_yaml.get('promise').get('general').get('router_name') """ logging configuration """ logger = ft_logger.Logger("promise").getLogger() def main(): exit_code = -1 start_time = time.time() ks_creds = openstack_utils.get_credentials("keystone") nv_creds = openstack_utils.get_credentials("nova") nt_creds = openstack_utils.get_credentials("neutron") keystone = ksclient.Client(**ks_creds) user_id = openstack_utils.get_user_id(keystone, ks_creds['username']) if user_id == '': logger.error("Error : Failed to get id of %s user" % ks_creds['username']) exit(-1) logger.info("Creating tenant '%s'..." % TENANT_NAME) tenant_id = openstack_utils.create_tenant( keystone, TENANT_NAME, TENANT_DESCRIPTION) if tenant_id == '': logger.error("Error : Failed to create %s tenant" % TENANT_NAME) exit(-1) logger.debug("Tenant '%s' created successfully." % TENANT_NAME) roles_name = ["admin", "Admin"] role_id = '' for role_name in roles_name: if role_id == '': role_id = openstack_utils.get_role_id(keystone, role_name) if role_id == '': logger.error("Error : Failed to get id for %s role" % role_name) exit(-1) logger.info("Adding role '%s' to tenant '%s'..." % (role_id, TENANT_NAME)) if not openstack_utils.add_role_user(keystone, user_id, role_id, tenant_id): logger.error("Error : Failed to add %s on tenant %s" % (ks_creds['username'], TENANT_NAME)) exit(-1) logger.debug("Role added successfully.") logger.info("Creating user '%s'..." % USER_NAME) user_id = openstack_utils.create_user( keystone, USER_NAME, USER_PWD, None, tenant_id) if user_id == '': logger.error("Error : Failed to create %s user" % USER_NAME)