summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
Diffstat (limited to 'func')
-rw-r--r--func/args_handler.py12
-rw-r--r--func/cli.py2
-rw-r--r--func/create_zones.py108
-rw-r--r--func/env_setup.py4
-rwxr-xr-xfunc/fetch_compute_ips.sh117
-rw-r--r--func/spawn_vm.py9
6 files changed, 46 insertions, 206 deletions
diff --git a/func/args_handler.py b/func/args_handler.py
index e27d37e7..59712800 100644
--- a/func/args_handler.py
+++ b/func/args_handler.py
@@ -14,14 +14,14 @@ from func.spawn_vm import SpawnVM
from func.driver import Driver
-def get_files_in_test_list(suit_name, case_type='all'):
- benchmark_list = json.load(file('test_list/{0}'.format(suit_name)))
+def get_files_in_test_list(suite_name, case_type='all'):
+ benchmark_list = json.load(file('test_list/{0}'.format(suite_name)))
return reduce(add, benchmark_list.values()) \
if case_type == 'all' else benchmark_list[case_type]
-def get_files_in_test_case(lab, suit_name, case_type='all'):
- test_case_all = os.listdir('./test_cases/{0}/{1}'.format(lab, suit_name))
+def get_files_in_test_case(lab, suite_name, case_type='all'):
+ test_case_all = os.listdir('./test_cases/{0}/{1}'.format(lab, suite_name))
return test_case_all if case_type == 'all' else \
filter(lambda x: case_type in x, test_case_all)
@@ -30,8 +30,8 @@ def get_benchmark_path(lab, suit, benchmark):
return './test_cases/{0}/{1}/{2}'.format(lab, suit, benchmark)
-def check_suit_in_test_list(suit_name):
- return True if os.path.isfile('test_list/' + suit_name) else False
+def check_suite_in_test_list(suite_name):
+ return True if os.path.isfile('test_list/' + suite_name) else False
def check_lab_name(lab_name):
diff --git a/func/cli.py b/func/cli.py
index 7d526203..d914a2de 100644
--- a/func/cli.py
+++ b/func/cli.py
@@ -40,7 +40,7 @@ class Cli:
def __init__(self, args=sys.argv[1:]):
args = self._parse_args(args)
- if not args_handler.check_suit_in_test_list(args.file):
+ if not args_handler.check_suite_in_test_list(args.file):
print('\n\n ERROR: Test File Does not exist in test_list/ please enter correct file \n\n')
sys.exit(1)
diff --git a/func/create_zones.py b/func/create_zones.py
index e715dfd4..30b6ef57 100644
--- a/func/create_zones.py
+++ b/func/create_zones.py
@@ -1,5 +1,5 @@
##############################################################################
-# Copyright (c) 2015 Dell Inc and others.
+# Copyright (c) 2016 Dell Inc, ZTE and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -10,14 +10,15 @@ from keystoneclient.auth.identity import v2
from keystoneclient import session
from novaclient import client
import os
-import re
-from collections import defaultdict
+import random
+from utils import logger_utils
+logger = logger_utils.QtipLogger('create_zones').get
-class create_zones:
+
+class AvailabilityZone:
def __init__(self):
- print 'Creating Zones'
self._keystone_client = None
self._nova_client = None
@@ -49,82 +50,37 @@ class create_zones:
self._nova_client = client.Client('2', session=keystone)
return self._nova_client
- @staticmethod
- def check_aggregate(nova, agg_name):
- list1 = nova.aggregates.list()
- agg_name_exist = False
- for x in list1:
- if x.name == agg_name:
- agg_name_exist = True
- return agg_name_exist
-
- @staticmethod
- def get_aggregate_id(nova, agg_name):
- list1 = nova.aggregates.list()
- for x in list1:
- if x.name == agg_name:
- agg_id = x.id
- return agg_id
-
- @staticmethod
- def check_host_added_to_aggregate(nova, agg_id, hostname):
- host_added = False
- list1 = nova.aggregates.get_details(agg_id)
-
- nme = str(list1.hosts)
- if hostname in nme:
- host_added = True
- return host_added
-
- @staticmethod
- def del_agg(nova, id, host):
-
- nova.aggregates.remove_host(id, host)
- nova.aggregates.delete(id)
-
- @staticmethod
- def get_compute_num(compute_name):
-
- num = re.findall(r'\d+', compute_name)
- return int(num[0]) - 1
-
- def test(self):
- nova = self._get_nova_client()
- hyper_list = nova.hypervisors.list()
- return hyper_list
-
- def create_agg(self, d):
+ def clean_all_aggregates(self):
+ logger.info("clean all aggregates")
nova = self._get_nova_client()
- hyper_list = nova.hypervisors.list()
- host_a = []
- zone_machine = defaultdict(list)
-
- for x in range(len(hyper_list)):
+ agg_list = nova.aggregates.list()
- host_a.append(hyper_list[x].service['host'])
- host_a[x] = str(host_a[x])
+ for agg in agg_list:
+ agg_info = nova.aggregates.get_details(agg.id)
+ agg_hosts = agg_info.hosts
+ if len(agg_hosts):
+ for host in agg_hosts:
+ nova.aggregates.remove_host(agg.id, host)
+ nova.aggregates.delete(agg.id)
- host_a.sort()
- for k in d:
+ def create_aggs(self, args):
+ azone_list = list(set(args))
+ azone_list.sort()
- zone_machine[k].append(' ')
+ nova = self._get_nova_client()
+ hyper_list = nova.hypervisors.list()
- for x in range(len(zone_machine)):
- compute_index = self.get_compute_num(d[x])
- if compute_index > len(hyper_list):
- print '\n The specified compute node doesnt exist. using compute 1'
- compute_index = 1
- if not self.check_aggregate(nova, host_a[compute_index]):
- agg_id_a = nova.aggregates.create(host_a[compute_index], d[x])
- nova.aggregates.add_host(aggregate=agg_id_a, host=host_a[compute_index])
+ if len(azone_list) > len(hyper_list):
+ logger.error("required available zones > compute nodes")
+ return None
- else:
- id1 = self.get_aggregate_id(nova, host_a[compute_index])
- self.del_agg(nova, id1, host_a[compute_index])
- nova.aggregates.create(host_a[compute_index], d[x])
- id1 = self.get_aggregate_id(nova, host_a[compute_index])
+ compute_nodes = map(lambda x: x.service['host'], hyper_list)
+ sample_nodes = random.sample(compute_nodes, len(azone_list))
+ sample_nodes.sort()
- if not self.check_host_added_to_aggregate(
- nova, id1, host_a[compute_index]):
+ for index, item in enumerate(azone_list):
+ logger.info("create aggregates: %s" % str(item))
+ agg_id = nova.aggregates.create(item, item)
- nova.aggregates.add_host(aggregate=id1, host=host_a[compute_index])
+ logger.info("add host: %s" % sample_nodes[index])
+ nova.aggregates.add_host(aggregate=agg_id, host=sample_nodes[index])
diff --git a/func/env_setup.py b/func/env_setup.py
index f10f8620..ca83f040 100644
--- a/func/env_setup.py
+++ b/func/env_setup.py
@@ -14,10 +14,8 @@ import sys
import time
from collections import defaultdict
from os.path import expanduser
-
import paramiko
import yaml
-
from utils import logger_utils
logger = logger_utils.QtipLogger('env_setup').get
@@ -111,7 +109,7 @@ class Env_setup:
if not installer_ip:
raise RuntimeError("undefine environment variable INSTALLER_IP")
- cmd = "bash ./func/fetch_compute_ips.sh -i %s -a %s" % \
+ cmd = "bash ./data/fetch_compute_ips.sh -i %s -a %s" % \
(installer_type, installer_ip)
logger.info(cmd)
os.system(cmd)
diff --git a/func/fetch_compute_ips.sh b/func/fetch_compute_ips.sh
deleted file mode 100755
index ebe817a6..00000000
--- a/func/fetch_compute_ips.sh
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/bash
-##############################################################################
-#Copyright (c) 2016 Ericsson AB, ZTE and others.
-#jose.lausuch@ericsson.com
-#wu.zhihui1@zte.com.cn
-#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(){
- echo "usage: $0 [-v] -i <installer_type> -a <installer_ip>" >&2
- echo "[-v] Virtualized deployment" >&2
-}
-
-info() {
- logger -s -t "fetch_compute_info.info" "$*"
-}
-
-
-error() {
- logger -s -t "fetch_compute_info.error" "$*"
- exit 1
-}
-
-verify_connectivity(){
- local ip=$1
- info "Verifying connectivity to $ip..."
- for i in $(seq 0 10); do
- if ping -c 1 -W 1 $ip > /dev/null; then
- info "$ip is reachable!"
- return 0
- fi
- sleep 1
- done
- error "Can not talk to $ip."
-}
-
-:${DEPLOY_TYPE:=''}
-
-#Getoptions
-while getopts ":i:a:h:v" optchar; do
- case "${optchar}" in
- i) installer_type=${OPTARG} ;;
- a) installer_ip=${OPTARG} ;;
- v) DEPLOY_TYPE="virt" ;;
- *) echo "Non-option argument: '-${OPTARG}'" >&2
- usage
- exit 2
- ;;
- esac
-done
-
-#set vars from env if not provided by user as options
-installer_type=${installer_type:-$INSTALLER_TYPE}
-installer_ip=${installer_ip:-$INSTALLER_IP}
-
-if [ -z $installer_type ] || [ -z $installer_ip ]; then
- usage
- exit 2
-fi
-
-ssh_options="-oUserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
-
-#Start fetching compute ip
-if [ "$installer_type" == "fuel" ]; then
- verify_connectivity $installer_ip
-
- env=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
- 'fuel env'|grep operational|head -1|awk '{print $1}') &> /dev/null
- if [ -z $env ]; then
- error "No operational environment detected in Fuel"
- fi
- env_id="${FUEL_ENV:-$env}"
-
- # Check if compute is alive (online='True')
- IPS=$(sshpass -p r00tme ssh 2>/dev/null $ssh_options root@${installer_ip} \
- "fuel node --env ${env_id} | grep compute | grep 'True\| 1' | awk -F\| '{print \$5}' " | \
- sed 's/ //g') &> /dev/null
-
-
-elif [ "$installer_type" == "apex" ]; then
- echo "not implement now"
- exit 1
-
-elif [ "$installer_type" == "compass" ]; then
- # need test
- verify_connectivity $installer_ip
- IPS=$(sshpass -p'root' ssh 2>/dev/null $ssh_options root@${installer_ip} \
- 'mysql -ucompass -pcompass -Dcompass -e"select * from cluster;"' \
- | awk -F"," '{for(i=1;i<NF;i++)if($i~/\"host[4-5]\"/) {print $(i+1);}}' \
- | grep -oP "\d+.\d+.\d+.\d+")
-
-elif [ "$installer_type" == "joid" ]; then
- echo "not implement now"
- exit 1
-
-elif [ "$installer_type" == "foreman" ]; then
- echo "not implement now"
- exit 1
-
-else
- error "Installer $installer is not supported by this script"
-fi
-
-if [ -z "$IPS" ]; then
- error "The compute node $IPS are not up. Please check that the POD is correctly deployed."
-else
- echo "-------- all compute node ips: --------"
- touch $HOME/ips.log
- echo "$IPS" > $HOME/ips.log
- echo $IPS
-fi
-
-exit 0
diff --git a/func/spawn_vm.py b/func/spawn_vm.py
index b467ab1f..c45af00e 100644
--- a/func/spawn_vm.py
+++ b/func/spawn_vm.py
@@ -16,7 +16,7 @@ import heatclient.client
import keystoneclient
from novaclient import client
import time
-from func.create_zones import create_zones
+from func.create_zones import AvailabilityZone
class SpawnVM(Env_setup):
@@ -25,6 +25,7 @@ class SpawnVM(Env_setup):
def __init__(self, vm_info):
print 'SpawnVM Class initiated'
+ print 'vm_info: %s' % vm_info
vm_role_ip_dict = vm_info.copy()
print 'Generating Heat Template\n'
self._keystone_client = None
@@ -32,8 +33,10 @@ class SpawnVM(Env_setup):
self._glance_client = None
self._nova_client = None
self. _get_nova_client()
- azoneobj = create_zones()
- azoneobj.create_agg(vm_info['availability_zone'])
+ self.azone = AvailabilityZone()
+ # TODO: it should clean up aggregates and stack after test case finished.
+ self.azone.clean_all_aggregates()
+ self.azone.create_aggs(vm_info['availability_zone'])
installer = self.get_installer_type()
self.Heat_template1 = self.heat_template_vm(vm_info, installer)
self.create_stack(vm_role_ip_dict, self.Heat_template1)