import argparse
import datetime
import json
-import logging
import os
import pprint
import requests
import clearwater
import orchestrator
+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 functest.utils.openstack_utils as os_utils
pp = pprint.PrettyPrinter(indent=4)
args = parser.parse_args()
""" logging configuration """
-logger = logging.getLogger('vIMS')
-logger.setLevel(logging.INFO)
-
-ch = logging.StreamHandler()
-if args.debug:
- ch.setLevel(logging.DEBUG)
-else:
- ch.setLevel(logging.INFO)
-formatter = logging.Formatter(
- '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
-ch.setFormatter(formatter)
-logger.addHandler(ch)
+logger = ft_logger.Logger("vIMS").getLogger()
REPO_PATH = os.environ['repos_dir'] + '/functest/'
if not os.path.exists(REPO_PATH):
logger.error("Failed to download image %s" % file_name)
return False
- image = openstack_utils.create_glance_image(
+ image = os_utils.create_glance_image(
glance, image_name, dest_path + file_name)
if not image:
logger.error("Failed to upload image on glance")
if not os.path.exists(VIMS_DATA_DIR):
os.makedirs(VIMS_DATA_DIR)
- ks_creds = openstack_utils.get_credentials("keystone")
- nv_creds = openstack_utils.get_credentials("nova")
- nt_creds = openstack_utils.get_credentials("neutron")
+ ks_creds = os_utils.get_credentials("keystone")
+ nv_creds = os_utils.get_credentials("nova")
+ nt_creds = os_utils.get_credentials("neutron")
logger.info("Prepare OpenStack plateform (create tenant and user)")
keystone = ksclient.Client(**ks_creds)
- user_id = openstack_utils.get_user_id(keystone, ks_creds['username'])
+ user_id = os_utils.get_user_id(keystone, ks_creds['username'])
if user_id == '':
step_failure("init", "Error : Failed to get id of " +
ks_creds['username'])
- tenant_id = openstack_utils.create_tenant(
+ tenant_id = os_utils.create_tenant(
keystone, TENANT_NAME, TENANT_DESCRIPTION)
if tenant_id == '':
step_failure("init", "Error : Failed to create " +
role_id = ''
for role_name in roles_name:
if role_id == '':
- role_id = openstack_utils.get_role_id(keystone, role_name)
+ role_id = os_utils.get_role_id(keystone, role_name)
if role_id == '':
logger.error("Error : Failed to get id for %s role" % role_name)
- if not openstack_utils.add_role_user(keystone, user_id,
- role_id, tenant_id):
+ if not os_utils.add_role_user(keystone, user_id, role_id, tenant_id):
logger.error("Error : Failed to add %s on tenant" %
ks_creds['username'])
- user_id = openstack_utils.create_user(
+ user_id = os_utils.create_user(
keystone, TENANT_NAME, TENANT_NAME, None, tenant_id)
if user_id == '':
logger.error("Error : Failed to create %s user" % TENANT_NAME)
image_name = IMAGES[img]['image_name']
image_url = IMAGES[img]['image_url']
- image_id = openstack_utils.get_image_id(glance, image_name)
+ image_id = os_utils.get_image_id(glance, image_name)
if image_id == '':
logger.info("""%s image doesn't exist on glance repository. Try
logger.info("Update security group quota for this tenant")
neutron = ntclient.Client(**nt_creds)
- if not openstack_utils.update_sg_quota(neutron, tenant_id, 50, 100):
+ if not os_utils.update_sg_quota(neutron, tenant_id, 50, 100):
step_failure(
"init",
"Failed to update security group quota for tenant " + TENANT_NAME)
logger.info("Update cinder quota for this tenant")
from cinderclient import client as cinderclient
- creds_cinder = openstack_utils.get_credentials("cinder")
+ creds_cinder = os_utils.get_credentials("cinder")
cinder_client = cinderclient.Client('1', creds_cinder['username'],
creds_cinder['api_key'],
creds_cinder['project_id'],
creds_cinder['auth_url'],
service_type="volume")
- if not openstack_utils.update_cinder_quota(cinder_client, tenant_id,
- 20, 10, 150):
+ if not os_utils.update_cinder_quota(cinder_client, tenant_id, 20, 10, 150):
step_failure(
"init", "Failed to update cinder quota for tenant " + TENANT_NAME)
nova = nvclient.Client("2", **nv_creds)
flavor_name = "m1.medium"
- flavor_id = openstack_utils.get_flavor_id(nova, flavor_name)
+ flavor_id = os_utils.get_flavor_id(nova, flavor_name)
for requirement in CFY_MANAGER_REQUIERMENTS:
if requirement == 'ram_min':
- flavor_id = openstack_utils.get_flavor_id_by_ram_range(
+ flavor_id = os_utils.get_flavor_id_by_ram_range(
nova, CFY_MANAGER_REQUIERMENTS['ram_min'], 8196)
if flavor_id == '':
logger.error(
"Failed to find %s flavor. "
"Try with ram range default requirement !" % flavor_name)
- flavor_id = openstack_utils.get_flavor_id_by_ram_range(
- nova, 4000, 8196)
+ flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)
if flavor_id == '':
step_failure("orchestrator",
cfy.set_flavor_id(flavor_id)
image_name = "centos_7"
- image_id = openstack_utils.get_image_id(glance, image_name)
+ image_id = os_utils.get_image_id(glance, image_name)
for requirement in CFY_MANAGER_REQUIERMENTS:
if requirement == 'os_image':
- image_id = openstack_utils.get_image_id(
+ image_id = os_utils.get_image_id(
glance, CFY_MANAGER_REQUIERMENTS['os_image'])
if image_id == '':
cfy.set_image_id(image_id)
- ext_net = openstack_utils.get_external_net(neutron)
+ ext_net = os_utils.get_external_net(neutron)
if not ext_net:
step_failure("orchestrator", "Failed to get external network")
nova = nvclient.Client("2", **nv_creds)
flavor_name = "m1.small"
- flavor_id = openstack_utils.get_flavor_id(nova, flavor_name)
+ flavor_id = os_utils.get_flavor_id(nova, flavor_name)
for requirement in CW_REQUIERMENTS:
if requirement == 'ram_min':
- flavor_id = openstack_utils.get_flavor_id_by_ram_range(
+ flavor_id = os_utils.get_flavor_id_by_ram_range(
nova, CW_REQUIERMENTS['ram_min'], 8196)
if flavor_id == '':
logger.error(
"Failed to find %s flavor. Try with ram range "
"default requirement !" % flavor_name)
- flavor_id = openstack_utils.get_flavor_id_by_ram_range(
- nova, 4000, 8196)
+ flavor_id = os_utils.get_flavor_id_by_ram_range(nova, 4000, 8196)
if flavor_id == '':
step_failure(
cw.set_flavor_id(flavor_id)
image_name = "ubuntu_14.04"
- image_id = openstack_utils.get_image_id(glance, image_name)
+ image_id = os_utils.get_image_id(glance, image_name)
for requirement in CW_REQUIERMENTS:
if requirement == 'os_image':
- image_id = openstack_utils.get_image_id(
+ image_id = os_utils.get_image_id(
glance, CW_REQUIERMENTS['os_image'])
if image_id == '':
cw.set_image_id(image_id)
- ext_net = openstack_utils.get_external_net(neutron)
+ ext_net = os_utils.get_external_net(neutron)
if not ext_net:
step_failure("vIMS", "Failed to get external network")
if args.noclean:
exit(0)
- ks_creds = openstack_utils.get_credentials("keystone")
+ ks_creds = os_utils.get_credentials("keystone")
keystone = ksclient.Client(**ks_creds)
logger.info("Removing %s tenant .." % CFY_INPUTS['keystone_tenant_name'])
- tenant_id = openstack_utils.get_tenant_id(
+ tenant_id = os_utils.get_tenant_id(
keystone, CFY_INPUTS['keystone_tenant_name'])
if tenant_id == '':
logger.error("Error : Failed to get id of %s tenant" %
CFY_INPUTS['keystone_tenant_name'])
else:
- if not openstack_utils.delete_tenant(keystone, tenant_id):
+ if not os_utils.delete_tenant(keystone, tenant_id):
logger.error("Error : Failed to remove %s tenant" %
CFY_INPUTS['keystone_tenant_name'])
logger.info("Removing %s user .." % CFY_INPUTS['keystone_username'])
- user_id = openstack_utils.get_user_id(
+ user_id = os_utils.get_user_id(
keystone, CFY_INPUTS['keystone_username'])
if user_id == '':
logger.error("Error : Failed to get id of %s user" %
CFY_INPUTS['keystone_username'])
else:
- if not openstack_utils.delete_user(keystone, user_id):
+ if not os_utils.delete_user(keystone, user_id):
logger.error("Error : Failed to remove %s user" %
CFY_INPUTS['keystone_username'])