From 8c9207f71147e9e4b44f813793c5bf04f4eba381 Mon Sep 17 00:00:00 2001 From: Mofassir Arif Date: Wed, 16 Dec 2015 02:25:51 -0800 Subject: Removed Root previlages QTIP now uses a key of its own to ssh into VMs The ssh for the baremetal servers still needs work Change-Id: I1aa37e07c4f9b3f7f4902d16cdbf74f39eb6c698 Signed-off-by: Mofassir Arif Conflicts: .gitignore --- func/cli.py | 2 +- func/create_zones.py | 2 +- func/driver.py | 6 +++--- func/env_setup.py | 32 +++++++++++++++----------------- func/spawn_vm.py | 30 ++++++++++++++---------------- 5 files changed, 34 insertions(+), 38 deletions(-) (limited to 'func') diff --git a/func/cli.py b/func/cli.py index 33aacbcb..83a7c36f 100644 --- a/func/cli.py +++ b/func/cli.py @@ -43,7 +43,7 @@ class cli(): [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() diff --git a/func/create_zones.py b/func/create_zones.py index 86cfc23b..a21fb41f 100644 --- a/func/create_zones.py +++ b/func/create_zones.py @@ -55,7 +55,7 @@ class create_zones: agg_name_exist = False for x in list1: - + if x.name == agg_name: agg_name_exist = True return agg_name_exist diff --git a/func/driver.py b/func/driver.py index 83e64a80..318c67b3 100644 --- a/func/driver.py +++ b/func/driver.py @@ -28,7 +28,7 @@ class Driver: 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: @@ -43,8 +43,8 @@ class Driver: 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 ./benchmarks/playbooks/{0} --private-key=./data/QtipKey -i ./data/hosts --extra-vars \'{1}\' '.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/env_setup.py b/func/env_setup.py index 1db54564..f3c01a7c 100644 --- a/func/env_setup.py +++ b/func/env_setup.py @@ -28,7 +28,7 @@ class Env_setup(): print '\nParsing class initiated\n' def writeTofile(self, role): - fname2 = open('/etc/ansible/hosts', 'w') + fname2 = open('./data/hosts', 'w') print role.items() for k in role: fname2.write('[' + k + ']\n') @@ -44,48 +44,46 @@ class Env_setup(): pwvar = v print '\nBeginning SSH Test!\n' if v != '': - print ('\nSSH->>>>> %s\n' % k) + print ('\nSSH->>>>> {0} {1}\n'.format(k,v)) time.sleep(2) ssh_c = 'ssh-keyscan {0} >> ~/.ssh/known_hosts'.format(k) - os.system(ssh_c) - ssh_cmd = 'expect ./data/ssh_exch.exp {0} {1}'.format( - ipvar, pwvar) - res = os.system(ssh_cmd) - ''' + #os.system(ssh_c) + ssh_cmd = 'expect ./data/ssh_exch.exp {0} {1}'.format(ipvar, pwvar) + print ssh_cmd + res = os.system(ssh_cmd) for infinity in range(10000): try : ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(hostname = k , username = 'root', password = v) + ssh.connect(k , username = 'root', password = v) stdin, stdout, stderr = ssh.exec_command('ls') print('SSH successful') break except: print 'Retrying SSH' - time.sleep(1) - ''' + time.sleep(1) if v == '': print ('SSH->>>>>', k) ssh_c = 'ssh-keyscan {0} >> ~/.ssh/known_hosts'.format(k) time.sleep(3) os.system(ssh_c) - + for infinity in range(10000): try : ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(hostname = k ) + ssh.connect(k, key_filename= './data/QtipKey') stdin, stdout, stderr = ssh.exec_command('ls') break except: print 'Retrying SSH' - + def pingtest(self, lister): + pingFlag = 0 - for k, v in lister.iteritems(): time.sleep(10) for val in v: @@ -98,9 +96,9 @@ class Env_setup(): print ('\n\n %s is UP \n\n ' % ipvar) def GetHostMachineinfo(self, Hosttag): + num = len(Hosttag) offset = len(self.roles_ip_list) - for x in range(num): hostlabel = 'machine_' + str(x + 1) self.roles_ip_list.insert( @@ -109,6 +107,7 @@ class Env_setup(): offset, (Hosttag[hostlabel]['ip'], Hosttag[hostlabel]['pw'])) def GetVirtualMachineinfo(self, Virtualtag): + num = len(Virtualtag) for x in range(num): hostlabel = 'virtualmachine_' + str(x + 1) @@ -116,7 +115,7 @@ class Env_setup(): 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 @@ -135,7 +134,6 @@ class Env_setup(): self.GetHostMachineinfo(doc['Context']['Host_Machines']) 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: diff --git a/func/spawn_vm.py b/func/spawn_vm.py index c1bacedc..e7947008 100644 --- a/func/spawn_vm.py +++ b/func/spawn_vm.py @@ -7,8 +7,6 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## - - import os import sys from collections import defaultdict @@ -23,7 +21,6 @@ import time import json from func.create_zones import create_zones - class SpawnVM(Env_setup): vm_role_ip_dict = defaultdict(list) @@ -54,7 +51,8 @@ class SpawnVM(Env_setup): print 'Error in qtip/heat/SampleHeat.yaml at: (%s,%s)' % (mark.line + 1, mark.column + 1) print 'EXITING PROGRAM. Correct File and restart' sys.exit(0) - fopen = open('/root/.ssh/id_rsa.pub', 'r') + #fopen = open('/root/.ssh/id_rsa.pub', 'r') + fopen = open('./data/QtipKey.pub', 'r') fopenstr = fopen.read() fopenstr = fopenstr.rstrip() scriptcmd = '#!/bin/bash \n echo {0} >> foo.txt \n echo {1} >> /root/.ssh/authorized_keys'.format( @@ -77,9 +75,9 @@ class SpawnVM(Env_setup): 'description': 'Availability Zone of the instance', 'default': avail_zone, 'type': 'string' - + } - + Heat_Dic['resources']['public_port_' +str(x)] = { 'type': 'OS::Neutron::Port', 'properties': { @@ -124,18 +122,18 @@ class SpawnVM(Env_setup): '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']}} - + Heat_Dic['outputs']['availability_instance_' + str(x)] = { 'description': 'Availability Zone of the Instance', 'value': { 'get_param': 'availability_zone_'+str(x)}} - + Heat_Dic['outputs']['KeyPair_PublicKey'] = { 'description': 'Private Key', @@ -206,7 +204,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) - + for checks in range(3): for prev_stacks in heat.stacks.list(): @@ -216,13 +214,13 @@ class SpawnVM(Env_setup): time.sleep(10) print '\nStack Creating Started\n' - + # 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': @@ -237,10 +235,10 @@ class SpawnVM(Env_setup): for I in cluster_detail.outputs: availabilityKey = 'availability_instance_'+str(vm+1) - + 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) @@ -248,13 +246,13 @@ class SpawnVM(Env_setup): 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']) - with open('/root/.ssh/my_key.pem', 'w') as fopen: + with open('./data/my_key.pem', 'w') as fopen: fopen.write(sshkey) fopen.close() print Env_setup.ip_pw_list -- cgit 1.2.3-korg