aboutsummaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
Diffstat (limited to 'func')
-rw-r--r--func/args_handler.py11
-rw-r--r--func/driver.py26
-rw-r--r--func/fetchimg.py35
-rw-r--r--func/spawn_vm.py32
4 files changed, 25 insertions, 79 deletions
diff --git a/func/args_handler.py b/func/args_handler.py
index 90d902b6..50d803eb 100644
--- a/func/args_handler.py
+++ b/func/args_handler.py
@@ -55,12 +55,13 @@ def prepare_ansible_env(benchmark_test_case):
def run_benchmark(installer_type, pwd, benchmark, benchmark_details,
proxy_info, env_setup, benchmark_test_case):
driver = Driver()
- driver.drive_bench(installer_type, pwd, benchmark,
- env_setup.roles_dict.items(), _get_f_name(benchmark_test_case),
- benchmark_details, env_setup.ip_pw_dict.items(), proxy_info)
+ return driver.drive_bench(installer_type, pwd, benchmark,
+ env_setup.roles_dict.items(),
+ _get_f_name(benchmark_test_case),
+ benchmark_details, env_setup.ip_pw_dict.items(), proxy_info)
def prepare_and_run_benchmark(installer_type, pwd, benchmark_test_case):
benchmark, benchmark_details, proxy_info, env_setup = prepare_ansible_env(benchmark_test_case)
- run_benchmark(installer_type, pwd, benchmark, benchmark_details,
- proxy_info, env_setup, benchmark_test_case)
+ return run_benchmark(installer_type, pwd, benchmark, benchmark_details,
+ proxy_info, env_setup, benchmark_test_case)
diff --git a/func/driver.py b/func/driver.py
index ff40a4cc..bcda0ce1 100644
--- a/func/driver.py
+++ b/func/driver.py
@@ -7,8 +7,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from utils import logger_utils
+from operator import add
from ansible_api import AnsibleApi
+
logger = logger_utils.QtipLogger('driver').get
@@ -47,7 +49,7 @@ class Driver:
def get_special_var_json(self, role, roles, benchmark_detail, pip_dict):
special_json = {}
index = roles.index(role) + 1
- private_ip = pip_dict[0][1][0] if pip_dict[0][1][0] else 'NONE'
+ private_ip = pip_dict[0][1] if pip_dict[0][1][0] else 'NONE'
map(lambda x: special_json.update({'ip' + str(index): x}), role[1])\
if benchmark_detail and (role[0] == '1-server') else None
map(lambda x: special_json.update({'privateip' + str(index): private_ip}), role[1])\
@@ -65,7 +67,7 @@ class Driver:
ansible_api.execute_playbook('./data/hosts',
'./benchmarks/playbooks/{0}.yaml'.format(benchmark),
'./data/QtipKey', extra_vars)
- return ansible_api.get_detail_playbook_stats()
+ return self.get_ansible_result(extra_vars['role'], ansible_api.get_detail_playbook_stats())
def drive_bench(self, installer_type, pwd, benchmark, roles, benchmark_fname,
benchmark_detail=None, pip_dict=None, proxy_info=None):
@@ -73,8 +75,18 @@ class Driver:
pip_dict = sorted(pip_dict)
var_json = self.get_common_var_json(installer_type, pwd, benchmark_fname,
benchmark_detail, pip_dict, proxy_info)
- map(lambda role: self.run_ansible_playbook
- (benchmark, self.merge_two_dicts(var_json,
- self.get_special_var_json(role, roles,
- benchmark_detail,
- pip_dict))), roles)
+ result = map(lambda role: self.run_ansible_playbook
+ (benchmark, self.merge_two_dicts(var_json,
+ self.get_special_var_json(role, roles,
+ benchmark_detail,
+ pip_dict))), roles)
+ return reduce(self._merge_ansible_result, result)
+
+ def get_ansible_result(self, role, stats):
+ result = reduce(add, map(lambda x: x[1]['failures'] + x[1]['unreachable'], stats))
+ return {'result': result,
+ 'detail': {role: stats}}
+
+ def _merge_ansible_result(self, result_1, result_2):
+ return {'result': result_1['result'] + result_2['result'],
+ 'detail': self.merge_two_dicts(result_1['detail'], result_2['detail'])}
diff --git a/func/fetchimg.py b/func/fetchimg.py
deleted file mode 100644
index 1ed3def6..00000000
--- a/func/fetchimg.py
+++ /dev/null
@@ -1,35 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 Dell Inc 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
-##############################################################################
-import os
-import time
-
-IMGSTORE = "/home/opnfv/imgstore"
-
-
-class FetchImg:
-
- def __init__(self):
- print 'Fetching Image!'
-
- @staticmethod
- def download():
- time.sleep(2)
- os.system('mkdir -p Temp_Img')
- filepath = './Temp_Img/QTIP_CentOS.qcow2'
- imgstorepath = IMGSTORE + "/QTIP_CentOS.qcow2"
- if os.path.isfile(imgstorepath):
- os.system("ln -s %s %s" % (imgstorepath, filepath))
- print "QTIP_CentOS.qcow2 exists locally. Skipping the download and using the file from IMG store"
- else:
- print 'Fetching QTIP_CentOS.qcow2'
- os.system('wget http://artifacts.opnfv.org/qtip/QTIP_CentOS.qcow2 -P Temp_Img')
-
- while not os.path.isfile(filepath):
- time.sleep(10)
- print 'Download Completed!'
diff --git a/func/spawn_vm.py b/func/spawn_vm.py
index 5710308b..7ac4340e 100644
--- a/func/spawn_vm.py
+++ b/func/spawn_vm.py
@@ -11,11 +11,9 @@ import os
import sys
from collections import defaultdict
from func.env_setup import Env_setup
-from func.fetchimg import FetchImg
import yaml
import heatclient.client
import keystoneclient
-import glanceclient
from novaclient import client
import time
from func.create_zones import create_zones
@@ -191,41 +189,12 @@ class SpawnVM(Env_setup):
'1', endpoint=heat_endpoint, token=keystone.auth_token)
return self._heat_client
- def _get_glance_client(self):
- if self._glance_client is None:
- keystone = self._get_keystone_client()
- glance_endpoint = keystone.service_catalog.url_for(
- service_type='image')
- self._glance_client = glanceclient.Client(
- '2', glance_endpoint, token=keystone.auth_token)
- return self._glance_client
-
def create_stack(self, vm_role_ip_dict, heat_template):
global sshkey
stackname = 'QTIP'
heat = self._get_heat_client()
- glance = self._get_glance_client()
-
- available_images = []
- for image_list in glance.images.list():
- available_images.append(image_list.name)
-
- if 'QTIP_CentOS' in available_images:
- print 'Image Present'
-
- elif 'QTIP_CentOS' not in available_images:
- fetchImage = FetchImg()
- fetchImage.download()
- print 'Uploading Image to Glance. Please wait'
- qtip_image = glance.images.create(
- name='QTIP_CentOS',
- visibility='public',
- disk_format='qcow2',
- container_format='bare')
- glance.images.upload(
- qtip_image.id, open('./Temp_Img/QTIP_CentOS.qcow2'))
for checks in range(3):
print "Try to delete heats %s" % checks
for prev_stacks in heat.stacks.list():
@@ -233,7 +202,6 @@ class SpawnVM(Env_setup):
print 'QTIP Stacks exists.\nDeleting Existing Stack'
heat.stacks.delete('QTIP')
time.sleep(10)
-
print '\nStack Creating Started\n'
try: