summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorJun Li <matthew.lijun@huawei.com>2016-04-20 01:38:46 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-04-20 01:38:46 +0000
commit80b9e74060078b1323a8394ab797b6022fa48344 (patch)
tree0fd759a7021d4b706c84cf8b21b6d41c8f2f06a3 /testsuites
parent62066c695d3e27bc2a8d76d59b98d4104fd0c5da (diff)
parent0cbac9410d28625da7b71034e9fa7c612c7c428a (diff)
Merge "Using nova and heat client to create a stack for rubbos test suite"
Diffstat (limited to 'testsuites')
-rwxr-xr-xtestsuites/rubbos/run_rubbos.py217
-rwxr-xr-xtestsuites/rubbos/run_rubbos.sh70
2 files changed, 147 insertions, 140 deletions
diff --git a/testsuites/rubbos/run_rubbos.py b/testsuites/rubbos/run_rubbos.py
index 9122fe54..c17f0d3f 100755
--- a/testsuites/rubbos/run_rubbos.py
+++ b/testsuites/rubbos/run_rubbos.py
@@ -7,14 +7,18 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+
import os
import argparse
import time
import logging
-import heatclient
-import keystoneclient
-import glanceclient
-import novaclient
+import urllib2
+import shutil
+from heatclient.client import Client as HeatClient
+from keystoneclient.v2_0.client import Client as KeystoneClient
+from glanceclient.v2.client import Client as GlanceClient
+from novaclient.client import Client as NovaClient
#------------------------------------------------------
# parser for configuration files in each test case
@@ -22,17 +26,17 @@ import novaclient
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--conf",
help="configuration files for the testcase, in yaml format",
- default="rubbos_1-1-1.yaml")
+ default="/tmp/rubbos_1-1-1.yaml")
args = parser.parse_args()
#--------------------------------------------------
# logging configuration
#--------------------------------------------------
-logger = logging.getLogger('run_rubbos')
-logger.setLevel(logging.DEBUG)
+logger = logging.getLogger(__name__)
+
def _get_keystone_client():
- keystone_client = keystoneclient.v2_0.client.Client(
+ keystone_client = KeystoneClient(
auth_url=os.environ.get('OS_AUTH_URL'),
username=os.environ.get('OS_USERNAME'),
password=os.environ.get('OS_PASSWORD'),
@@ -43,116 +47,189 @@ def _get_keystone_client():
def _get_heat_client():
keystone = _get_keystone_client()
heat_endpoint = keystone.service_catalog.url_for(service_type='orchestration')
- heat_client = heatclient.client.Client('1', endpoint=heat_endpoint, token=keystone.auth_token)
-
+ heat_client = HeatClient('1', endpoint=heat_endpoint, token=keystone.auth_token)
return heat_client
def _get_glance_client():
keystone = _get_keystone_client()
- glance_endpoint = keystone.service_catalog.url_for(service_type='image',
- endpoint_type='publicURL')
- return glanceclient.v2.client.Client(glance_endpoint, token=keystone.auth_token)
+ glance_endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
+ return GlanceClient(glance_endpoint, token=keystone.auth_token)
def _get_nova_client():
- nova_client = novaclient.client.Client("2", auth_url=os.environ.get('OS_AUTH_URL'),
- username=os.environ.get('OS_USERNAME'),
- password=os.environ.get('OS_PASSWORD'),
- tenant_name=os.environ.get('OS_TENANT_NAME'),
- region_name=os.environ.get('OS_REGION_NAME'),
- cacert=os.environ.get('OS_CACERT'))
+ nova_client = NovaClient("2", os.environ.get('OS_USERNAME'),
+ os.environ.get('OS_PASSWORD'),
+ os.environ.get('OS_TENANT_NAME'),
+ os.environ.get('OS_AUTH_URL'))
return nova_client
-def download_url(url, dest_path):
- """
- Download a file to a destination path given a URL
- """
- name = url.rsplit('/')[-1]
- dest = dest_path + "/" + name
+def _download_url(src_url, dest_dir):
+ ''' Download a file to a destination path given a URL'''
+ file_name = src_url.rsplit('/')[-1]
+ dest = dest_dir + "/" + file_name
try:
- response = urllib2.urlopen(url)
+ response = urllib2.urlopen(src_url)
except (urllib2.HTTPError, urllib2.URLError):
- return False
+ return None
with open(dest, 'wb') as f:
shutil.copyfileobj(response, f)
- return True
+ return file_name
+
+
+def rubbos_stack_satisfy(name="bottlenecks_rubbos_stack", status="CREATE_COMPLETE"):
+ heat = _get_heat_client()
+ for stack in heat.stacks.list():
+ if status == None and stack.stack_name == name:
+ # Found target stack
+ print "Found stack, name=" + stack.stack_name
+ return True
+ elif stack.stack_name == name and stack.stack_status==status:
+ print "Found stack, name=" + stack.stack_name + ", status=" + stack.stack_status
+ return True
+ return False
def rubbos_env_prepare(template=None):
- """ Prepare for rubbos running env
- """
- #logger.info("generate heat template for the testcase based on template '%s'." % template)
- pass
+ print "========== Prepare rubbos environment =========="
+ logger.info("Generate heat template for the testcase based on template '%s'." % template)
def rubbos_env_cleanup():
+ print "========== Cleanup rubbos environment =========="
glance = _get_glance_client()
heat = _get_heat_client()
nova = _get_nova_client()
- for stack in self.heat.stacks.list():
- heat.stacks.delete(stack.id)
+ for image in glance.images.list():
+ if image.name.find("bottlenecks_rubbos") >= 0:
+ print "Delete image, id:" + str(image.id) + ", name:" + str(image.name)
+ glance.images.delete(image.id)
+
+ for keypair in nova.keypairs.list():
+ if keypair.name.find("bottlenecks_rubbos") >= 0:
+ print "Delete keypair, id:" + keypair.id + ", name:" + keypair.name
+ nova.keypairs.delete(keypair.id)
- for image in self.glance.images.list():
- glance.images.delete(image.id)
+ for flavor in nova.flavors.list():
+ if flavor.name.find("bottlenecks_rubbos") >= 0:
+ print "Delete flavor, id:" + str(flavor.id) + ", name:" + flavor.name
+ nova.flavors.delete(flavor.id)
- for keypair in self.nova.keypairs.list():
- nova.keypairs.delete(keypair.id)
+ for stack in heat.stacks.list():
+ if stack.stack_name.find("bottlenecks_rubbos") >= 0:
+ print "Delete stack, id: " + str(stack.id) + ", name:" + str(stack.stack_name
+ heat.stacks.delete(stack.id)
- for flavor in self.nova.flavors.list():
- nova.flavors.delete(flavor.id)
+ timeInProgress = 0
+ while rubbos_stack_satisfy(name="bottlenecks_rubbos_stack", status=None) and timeInProgress < 60:
+ time.sleep(5)
+ timeInProgress = timeInProgress + 5
- logger.info("openstack env cleanup")
+ if rubbos_stack_satisfy(name="bottlenecks_rubbos_stack", status=None) == True:
+ print "Failed to clean the stack"
+ return False
+ else:
+ return True
-def rubbos_load_image(name=None):
- file_url = '/tmp'
- download_url(image_url,file_url)
+def rubbos_create_images(src_url=None, image_name="bottlenecks_rubbos_image"):
+ print "========== Create rubbos image in OS =========="
+ dest_dir = '/tmp'
+ file_name = _download_url(src_url, dest_dir)
+ #file_name = "bottlenecks-trusty-server.img"
+ if file_name == None:
+ return False
glance = _get_glance_client()
- image_args = {'name': name,
- 'disk-format': 'qcow2',
- 'container_format': 'bare',
- 'file': '/tmp/bottlenecks-trusty-server.img'}
- image = glance.images.create(**image_args)
- if not (image.id):
- logger.error("failed to upload rubbos image to openstack")
- exit(-1)
+ imagefile = dest_dir + "/" + file_name
+ image = glance.images.create(name=image_name, disk_format="qcow2", container_format="bare")
+ with open(imagefile) as fimage:
+ glance.images.upload(image.id, fimage)
+
+ timeInQueue = 0
+ img_status = image.status
+ while img_status == "queued" and timeInQueue < 30:
+ print " image's status: " + img_status
+ time.sleep(1)
+ timeInQueue = timeInQueue + 1
+ img_status = glance.images.get(image.id).status
+
+ print "After %d seconds, the image's status is [%s]" %(timeInQueue, img_status)
+ return True if img_status == "active" else False
+
+def rubbos_create_keypairs(key_path, name="bottlenecks_rubbos_keypair"):
+ print "========== Add rubbos keypairs in OS =========="
+ nova = _get_nova_client()
+ with open(key_path) as pkey:
+ nova.keypairs.create(name=name, public_key=pkey.read())
+
+def rubbos_create_flavors(name="bottlenecks_rubbos_flavor", ram=4096, vcpus=2, disk=10):
+ print "========== Create rubbos flavors in OS =========="
+ nova = _get_nova_client()
+ nova.flavors.create(name=name, ram=ram, vcpus=vcpus, disk=disk)
-def rubbos_create_instance(template_file=None, rubbos_parameters=None):
+def rubbos_create_instance(template_file, rubbos_parameters=None, stack_name="bottlenecks_rubbos_stack"):
+ print "========== Create rubbos instances =========="
heat = _get_heat_client()
- template = open(template_file, 'r')
- rubbos_stack = heat.stacks.create(stack_name='rubbos', template=template.read(), parameters=rubbos_parameters)
- uid = rubbos_stack['stack']['id']
-def rubbos_stack_check(stack_name=None):
- for stack in heat.stacks.list():
- if stack.stack_name == stack_name:
- return stack.stack_status
- return 'NOT_FOUND'
+ with open(template_file) as template:
+ stack = heat.stacks.create(stack_name=stack_name, template=template.read(), parameters=rubbos_parameters)
+
+ stack_id = stack['stack']['id']
+ stack_status = heat.stacks.get(stack_id).stack_status
+
+ print "Created stack, id=" + stack_id + ", status=" + stack_status
+
+ timeInProgress= 0
+ while stack_status == "CREATE_IN_PROGRESS" and timeInProgress < 150:
+ print " stack's status: %s, after %d seconds" %(stack_status, timeInProgress)
+ time.sleep(5)
+ timeInProgress = timeInProgress + 5
+ stack_status = heat.stacks.get(stack_id).stack_status
+
+ print "After %d seconds, the stack's status is [%s]" %(timeInProgress, stack_status)
+ return True if stack_status == "CREATE_COMPLETE" else False
def rubbos_run():
pass
def main():
global Heat_template
+ global Bottlenecks_repo_dir
global image_url
-
+ Bottlenecks_repo_dir = "/tmp/opnfvrepo/bottlenecks"
+ #Bottlenecks_repo_dir = "/root/wyg/bottlenecks" # Test dir in local env
+
image_url = 'http://artifacts.opnfv.org/bottlenecks/rubbos/bottlenecks-trusty-server.img'
if not (args.conf):
- logger.error("configuration files are not set for testcase")
+ logger.error("Configuration files are not set for testcase")
exit(-1)
else:
Heat_template = args.conf
- parameters={'image': 'rubbos',
- 'key_name': 'rubbos-key',
- 'public_net': 'net04_ext'}
+ parameters={'image': 'bottlenecks_rubbos_image',
+ 'key_name': 'bottlenecks_rubbos_keypair',
+ 'flavor': 'm1.small',
+ 'public_net': 'ext-net'}
+
+ print "Heat_template_file: " + Heat_template
+ print "parameters:\n" + str(parameters)
+
+ image_created = False
+ stack_created = False
rubbos_env_prepare(Heat_template)
rubbos_env_cleanup()
- rubbos_load_image(name='rubbos')
- rubbos_create_instance(template_file=Heat_template, rubbos_paramters=parameters)
- time.sleep(400)
- rubbos_stack_check(stack_name='rubbos')
+
+ image_created = rubbos_create_images(image_url)
+ keyPath = Bottlenecks_repo_dir + "/utils/infra_setup/bottlenecks_key/bottlenecks_key.pub"
+ rubbos_create_keypairs(key_path=keyPath)
+ rubbos_create_flavors()
+
+ if image_created == True:
+ stack_created = rubbos_create_instances(template_file=Heat_template, rubbos_parameters=parameters, stack_name="bottlenecks_rubbos_stack")
+ else:
+ print "Cannot create instances, as Failed to create image(s)."
+ exit (-1)
+
rubbos_run()
rubbos_env_cleanup()
diff --git a/testsuites/rubbos/run_rubbos.sh b/testsuites/rubbos/run_rubbos.sh
deleted file mode 100755
index b7492adc..00000000
--- a/testsuites/rubbos/run_rubbos.sh
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/bash
-###############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# 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
-##############################################################################
-
-usage="Script to run the tests in rubbos.
-
-usage:
- bash $(basename "$0") [-h|--help] [-s <test suite>]
-
-where:
- -h|--help show the help text
- -t|--test run specifif test case scenario
- <test case> examples:
- rubbos_1-1-1, rubbos_1-2-1
-
-examples:
- $(basename "$0")
- $(basename "$0") -t rubbos_1-1-1"
-
-while [[ $# > 0 ]]
- do
- key="$1"
- case $key in
- -h|--help)
- echo "$usage"
- exit 0
- shift
- ;;
- -t|--test)
- CASE="$2"
- shift
- ;;
- *)
- echo "unkown option $1 $2"
- exit 1
- ;;
- esac
- shift
-done
-
-BASEDIR=`dirname $0`
-
-#has been checked in upper layer run_tests.sh
-#run tests
-if [ "${CASE}" != "" ]; then
- case_exec=(${CASE//,/})
- for case_exe in "${case_exec[@]}"; do
- client_num=4
- tomcat_num=$(echo "$case_exe"| awk -F '-' '{print $2}')
- mysql_num=$(echo "$case_exe"| awk -F '-' '{print $3')
-
- hosts=(rubbos_control rubbos_benchmark rubbos_httpd)
- for((i=1; i <= client_num; i++)); do
- hosts=(${hosts[*]} client$i)
- done
- for((i=1; i <= tomcat_num; i++)); do
- hosts=(${hosts[*]} tomcat$i)
- done
- for((i=1; i <= mysql_num; i++)); do
- hosts=(${hosts[*]} mysql$i)
- done
- bash $BOTTLENECKS_TOP_DIR/utils/infra_setup/heat_template/rubbos_heat_template/HOT_create_instance.sh
- done
-fi