From e51df601fe4a1bd22274e3da62659b1ed7b2c49b Mon Sep 17 00:00:00 2001 From: Mofassir Arif Date: Wed, 9 Dec 2015 04:50:55 -0800 Subject: Networking Testcase: Iperf Implemented The ansible playbooks as well as the config files for the iperf throughput testing have been implemented. Some changes have been made to the driver function for the benchmarks. ansible now gets passed a json file. Change-Id: Ibf4c0210ab9f6cbf9896ca69bf2fb6bda8a9925d Signed-off-by: Mofassir Arif --- func/__init__.pyc | Bin 145 -> 0 bytes func/cli.py | 16 +++++------- func/cli.pyc | Bin 2097 -> 0 bytes func/create_zones.py | 25 +++++++++++------- func/create_zones.pyc | Bin 3912 -> 0 bytes func/driver.py | 37 ++++++++++++++++++++------ func/driver.pyc | Bin 1068 -> 0 bytes func/env_setup.py | 27 +++++++++---------- func/env_setup.pyc | Bin 5113 -> 0 bytes func/fetchimg.pyc | Bin 1073 -> 0 bytes func/spawn_vm.py | 69 +++++++++++++++++++++++-------------------------- func/spawn_vm.pyc | Bin 8366 -> 0 bytes func/validate_yaml.pyc | Bin 777 -> 0 bytes 13 files changed, 98 insertions(+), 76 deletions(-) delete mode 100644 func/__init__.pyc delete mode 100644 func/cli.pyc delete mode 100644 func/create_zones.pyc delete mode 100644 func/driver.pyc delete mode 100644 func/env_setup.pyc delete mode 100644 func/fetchimg.pyc delete mode 100644 func/spawn_vm.pyc delete mode 100644 func/validate_yaml.pyc (limited to 'func') diff --git a/func/__init__.pyc b/func/__init__.pyc deleted file mode 100644 index d217b489..00000000 Binary files a/func/__init__.pyc and /dev/null differ diff --git a/func/cli.py b/func/cli.py index 235040b5..33aacbcb 100644 --- a/func/cli.py +++ b/func/cli.py @@ -38,23 +38,19 @@ class cli(): sys.exit(0) if (args.suite and args.benchmark): obj = Env_setup() - if os.path.isfile( - './test_cases/' + - args.suite + - '/' + - args.benchmark): - - [benchmark, roles, vm_info] = obj.parse( - './test_cases/' + args.suite + '/' + args.benchmark) + if os.path.isfile('./test_cases/' + args.suite + + '/' + args.benchmark): + [benchmark, roles, vm_info, benchmark_details, pip] = obj.parse('./test_cases/' + args.suite + + '/' + args.benchmark) + if len(vm_info) != 0: vmObj = SpawnVM(vm_info) - obj.callpingtest() obj.callsshtest() obj.updateAnsible() dvr = Driver() - dvr.drive_bench(benchmark, obj.roles_dict.items()) + dvr.drive_bench(benchmark, obj.roles_dict.items(), benchmark_details, obj.ip_pw_dict.items()) else: print (args.benchmark, ' is not a Template in the Directory - \ Enter a Valid file name. or use qtip.py -h for list') diff --git a/func/cli.pyc b/func/cli.pyc deleted file mode 100644 index 3a09e907..00000000 Binary files a/func/cli.pyc and /dev/null differ diff --git a/func/create_zones.py b/func/create_zones.py index 92ce43fe..86cfc23b 100644 --- a/func/create_zones.py +++ b/func/create_zones.py @@ -13,6 +13,7 @@ from keystoneclient.auth.identity import v2 from keystoneclient import session from novaclient import client import os +import re from collections import defaultdict @@ -82,6 +83,11 @@ class create_zones: nova.aggregates.remove_host(id, host) nova.aggregates.delete(id) + def get_compute_num(self, computeName): + + num = re.findall(r'\d+',computeName) + return (int(num[0])-1) + def create_agg(self, D): nova = self._get_nova_client() hyper_list = nova.hypervisors.list() @@ -100,18 +106,19 @@ class create_zones: zone_machine[k].append(' ') for x in range(len(zone_machine)): - if not self.check_aggregate(nova, hostnA[x]): - agg_idA = nova.aggregates.create(hostnA[x], D[x]) - nova.aggregates.add_host(aggregate=agg_idA, host=hostnA[x]) + compute_index = self.get_compute_num(D[x]) + if not self.check_aggregate(nova, hostnA[compute_index]): + agg_idA = nova.aggregates.create(hostnA[compute_index], D[x]) + nova.aggregates.add_host(aggregate=agg_idA, host=hostnA[compute_index]) else: - id1 = self.get_aggregate_id(nova, hostnA[x]) - self.del_agg(nova, id1, hostnA[x]) - agg_idA = nova.aggregates.create(hostnA[x], D[x]) - id1 = self.get_aggregate_id(nova, hostnA[x]) + id1 = self.get_aggregate_id(nova, hostnA[compute_index]) + self.del_agg(nova, id1, hostnA[compute_index]) + agg_idA = nova.aggregates.create(hostnA[compute_index], D[x]) + id1 = self.get_aggregate_id(nova, hostnA[compute_index]) if not self.check_host_added_to_aggregate( - nova, id1, hostnA[x]): + nova, id1, hostnA[compute_index]): - nova.aggregates.add_host(aggregate=id1, host=hostnA[x]) + nova.aggregates.add_host(aggregate=id1, host=hostnA[compute_index]) diff --git a/func/create_zones.pyc b/func/create_zones.pyc deleted file mode 100644 index 4faf6abd..00000000 Binary files a/func/create_zones.pyc and /dev/null differ diff --git a/func/driver.py b/func/driver.py index 45ec3fa2..83e64a80 100644 --- a/func/driver.py +++ b/func/driver.py @@ -10,20 +10,41 @@ import os - +import json +from collections import defaultdict class Driver: def __init__(self): + print "Class driver initialized\n" + self.dic_json = defaultdict() - def drive_bench(self, benchmark, roles): - result_dir = '$PWD/results' + def drive_bench(self, benchmark, roles, benchmark_detail= None, pip_dict = None): + roles= sorted(roles) + pip_dict = sorted(pip_dict) + result_dir = 'results' benchmark_name = benchmark + '.yaml' - print roles + self.dic_json['Dest_dir'] = str(result_dir) + self.dic_json['ip1']='' + self.dic_json['ip2']='' + + for k,v in benchmark_detail: + self.dic_json[k]=v for k, v in roles: - print k - run_play = 'ansible-playbook -s $PWD/benchmarks/playbooks/{0} --extra-vars "Dest_dir={1} role={2}" -vvv'.format( - benchmark_name, result_dir, k) - + self.dic_json['role']=k + index=1 + if benchmark_detail != None: + for values in v: + if k == '1-server': + print values, 'saving IP' + self.dic_json['ip'+str(index)]= str(values) + self.dic_json['privateip'+str(index)] = pip_dict[0][1] + index= index+1 + dic_json = json.dumps(dict(self.dic_json.items())) + print dic_json + run_play = 'ansible-playbook -s ./benchmarks/playbooks/{0} --extra-vars \'{1}\' -vvv'.format(benchmark_name, dic_json) +# run_play = 'ansible-playbook -s $PWD/benchmarks/playbooks/{0} --extra-vars "Dest_dir={1} role={2}" -vvv'.format( +# benchmark_name, result_dir, k) status = os.system(run_play) + diff --git a/func/driver.pyc b/func/driver.pyc deleted file mode 100644 index 0ad3c584..00000000 Binary files a/func/driver.pyc and /dev/null differ diff --git a/func/env_setup.py b/func/env_setup.py index 919df176..1db54564 100644 --- a/func/env_setup.py +++ b/func/env_setup.py @@ -7,10 +7,6 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## - - - - import os import sys from collections import defaultdict @@ -23,12 +19,13 @@ class Env_setup(): ip_pw_list = [] # IP and password, this will be used to ssh roles_dict = defaultdict(list) ip_pw_dict = defaultdict(list) + ip_pip_list = [] vm_parameters = defaultdict(list) + benchmark_details= defaultdict() benchmark = '' def __init__(self): print '\nParsing class initiated\n' -# obj1 = SpawnVM() def writeTofile(self, role): fname2 = open('/etc/ansible/hosts', 'w') @@ -113,12 +110,17 @@ class Env_setup(): def GetVirtualMachineinfo(self, Virtualtag): num = len(Virtualtag) - for x in range(num): hostlabel = 'virtualmachine_' + str(x + 1) for k, v in Virtualtag[hostlabel].iteritems(): self.vm_parameters[k].append(v) + def GetBenchmarkDetails(self, detail_dic): + + print detail_dic + for k,v in detail_dic.items(): + self.benchmark_details[k]= v + def parse(self, configfilepath): try: fname = open(configfilepath, 'r+') @@ -131,12 +133,9 @@ class Env_setup(): self.GetVirtualMachineinfo(doc['Context']['Virtual_Machines']) if doc['Context']['Host_Machines']: self.GetHostMachineinfo(doc['Context']['Host_Machines']) - - # num = len(doc['Context']['Vir_Machines']) - # for x in range(num): - # lab = 'host_machine'+ str(x+1) - # self.roles_ip_list.insert(x,(doc[lab]['role'],doc[lab]['ip'])) - # self.ip_pw_list.insert(x,(doc[lab]['ip'],doc[lab]['pw'])) + if doc.get('Scenario',{}).get('benchmark_details',{}): + self.GetBenchmarkDetails(doc.get('Scenario',{}).get('benchmark_details',{})) + for k, v in self.roles_ip_list: self.roles_dict[k].append(v) for k, v in self.ip_pw_list: @@ -144,7 +143,9 @@ class Env_setup(): return ( self.benchmark, self.roles_dict.items(), - self.vm_parameters) + self.vm_parameters, + self.benchmark_details.items(), + self.ip_pw_dict.items()) except KeyboardInterrupt: fname.close() print 'ConfigFile Closed: exiting!' diff --git a/func/env_setup.pyc b/func/env_setup.pyc deleted file mode 100644 index 0f9c1433..00000000 Binary files a/func/env_setup.pyc and /dev/null differ diff --git a/func/fetchimg.pyc b/func/fetchimg.pyc deleted file mode 100644 index 0c0b228d..00000000 Binary files a/func/fetchimg.pyc and /dev/null differ diff --git a/func/spawn_vm.py b/func/spawn_vm.py index a9dada2e..c1bacedc 100644 --- a/func/spawn_vm.py +++ b/func/spawn_vm.py @@ -21,8 +21,6 @@ import glanceclient from novaclient import client import time import json - - from func.create_zones import create_zones @@ -81,17 +79,14 @@ class SpawnVM(Env_setup): 'type': 'string' } - - Heat_Dic['resources'][ - 'public_port_' + - str(x)] = { - 'type': 'OS::Neutron::Port', - 'properties': { - 'network': {'get_resource': 'private_network'}, - 'security_groups': [{ 'get_resource': 'demo1_security_Group'}], - 'fixed_ips': [ - { - 'subnet_id': {'get_resource': 'private_subnet'}}]}} + + Heat_Dic['resources']['public_port_' +str(x)] = { + 'type': 'OS::Neutron::Port', + 'properties': { + 'network': {'get_resource': 'private_network'}, + 'security_groups': [{ 'get_resource': 'demo1_security_Group'}], + 'fixed_ips': [ + {'subnet_id': {'get_resource': 'private_subnet'}}]}} Heat_Dic['resources']['floating_ip_' + str(x)] = { 'type': 'OS::Neutron::FloatingIP', @@ -108,11 +103,11 @@ class SpawnVM(Env_setup): 'type': 'OS::Nova::Server', 'properties': { 'image': img, - 'networks': - [{'port': {'get_resource': 'public_port_' + str(x)}}], + 'networks':[ + {'port': {'get_resource': 'public_port_' + str(x)}}], 'flavor': flavor, 'availability_zone': avail_zone, - 'name': 'QTIP_Instance_' + str(x), + 'name': 'instance' + str(x), 'key_name': {'get_resource': 'KeyPairSavePrivate'}, 'user_data_format': 'RAW', 'user_data': scriptcmd}} @@ -124,9 +119,15 @@ class SpawnVM(Env_setup): 'rules': [{ 'protocol': 'tcp', 'port_range_min': 22, - 'port_range_max': 22}, + 'port_range_max': 5201}, + {'protocol': 'udp', + 'port_range_min': 22, + 'port_range_max': 5201}, {'protocol': 'icmp'}]}} - + + Heat_Dic['outputs']['instance_PIP_' +str(x)] = { + 'description': 'IP address of the instance', + 'value': {'get_attr': ['my_instance_' + str(x), 'first_address']}} Heat_Dic['outputs']['instance_ip_' +str(x)] = { 'description': 'IP address of the instance', 'value': {'get_attr': ['floating_ip_' + str(x), 'floating_ip_address']}} @@ -205,10 +206,7 @@ class SpawnVM(Env_setup): qtip_image = glance.images.upload( qtip_image.id, open('./Temp_Img/QTIP_CentOS.qcow2')) json_temp = json.dumps(Heat_template) -# cluster_body = { -# "stack_name": stackname, -# "template": Heat_template -# } + for checks in range(3): for prev_stacks in heat.stacks.list(): @@ -219,12 +217,12 @@ class SpawnVM(Env_setup): print '\nStack Creating Started\n' - try: - heat.stacks.create(stack_name=stackname, template=Heat_template) - - except: - print 'Create Failed :( ' + # try: + heat.stacks.create(stack_name=stackname, template=Heat_template) + #except: + #print 'Create Failed :( ' + cluster_detail = heat.stacks.get(stackname) while(cluster_detail.status != 'COMPLETE'): if cluster_detail.status == 'IN_PROGRESS': @@ -242,18 +240,17 @@ class SpawnVM(Env_setup): if I['output_key'] == availabilityKey: zone.insert(s,str(I['output_value'])) - s=s+1 - + s=s+1 for i in cluster_detail.outputs: instanceKey = "instance_ip_" + str(vm + 1) - + privateIPkey = 'instance_PIP_' + str(vm +1) if i['output_key'] == instanceKey: - - Env_setup.roles_dict[vm_role_ip_dict['role'][ - vm]].append(str(i['output_value'])) - - Env_setup.ip_pw_list.append( - (str(i['output_value']),'')) + Env_setup.roles_dict[vm_role_ip_dict['role'][vm]].append( + str(i['output_value'])) + Env_setup.ip_pw_list.append((str(i['output_value']),'')) + + if i['output_key'] == privateIPkey: + Env_setup.ip_pw_dict[vm_role_ip_dict['role'][vm]]=str(i['output_value']) if i['output_key'] == 'KeyPair_PublicKey': sshkey = str(i['output_value']) diff --git a/func/spawn_vm.pyc b/func/spawn_vm.pyc deleted file mode 100644 index 8e6ce8f1..00000000 Binary files a/func/spawn_vm.pyc and /dev/null differ diff --git a/func/validate_yaml.pyc b/func/validate_yaml.pyc deleted file mode 100644 index 9a560316..00000000 Binary files a/func/validate_yaml.pyc and /dev/null differ -- cgit 1.2.3-korg