Commit d80fbcc6 authored by Jayesh Kishor's avatar Jayesh Kishor

Initial commit

parents
{
"Server Configuration":
[
{
"IP address":"10.96.23.32",
"Username":"helen",
"Password":"helen@12",
"Location":"/home/helen/Desktop/thesis/Project/test.py",
"Name":"CPU-cores",
"Regexp":"(workers\",\\s\")[0-9]+(.*)",
"Range":["1"]
}
],
"Server Profiling":
[
{
"IP address":"10.96.23.32",
"Username":"helen",
"Password":"helen@12",
"Name":["apache2"],
"Path":"/home/helen/Desktop/thesis/Project/profile.py"
}
],
"Command":
[
],
"BaseURL":"http://10.96.23.32/",
"AutomaticLoadLevelSelection":"True",
"LoadLevels":[1,20,40,44,60,80],
"OTSLG":"jmeter",
"SessionDescriptionFile":"sample.jmx",
"ThinkTime":2,
"NumberOfCores":20,
"MasterConfiguration":
{
"IP address":"10.129.29.155",
"Username":"helen",
"Password":"helen@12"
}
}
import paramiko
import re
import json
import multiprocessing
from multiprocessing import Process, Manager
import ast
class ServerSystem:
def SetServerConfiguration(self,nextServerConfiguration,ServerConfigurationInfo,serverConfigurationFilePath):
ioError="00"
for i in range(0,len(nextServerConfiguration)):
try:
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ServerConfigurationInfo[i]["IP address"],username=ServerConfigurationInfo[i]["Username"],password=ServerConfigurationInfo[i]["Password"])
try:
ssh.open_sftp().file(ServerConfigurationInfo[i]["Location"],"r+")
except IOError:
ioError="12"
if ioError=="12":
fileLocation=ServerConfigurationInfo[i]["Location"]
password=ServerConfigurationInfo[i]["Password"]
stdin, stdout, stderr =ssh.exec_command(f'cat {fileLocation}')
fileContent=stdout.read()
fileContent = fileContent.decode('utf-8')
fileContent=re.sub(ServerConfigurationInfo[i]["Regexp"],rf'\g<1>{nextServerConfiguration[i]}\g<2>',fileContent)
tempFilePath=serverConfigurationFilePath+"/temp.txt"
with ssh.open_sftp().file(tempFilePath,"w") as tempFile:
tempFile.write(fileContent)
stdin, stdout, stderr =ssh.exec_command(f'echo {password} | sudo -S cp {tempFilePath} {fileLocation}')
else:
with ssh.open_sftp().file(ServerConfigurationInfo[i]["Location"],"r+") as remoteFile:
fileContent=remoteFile.read()
fileContent=fileContent.decode("utf-8")
fileContent=re.sub(ServerConfigurationInfo[i]["Regexp"],rf'\g<1>{nextServerConfiguration[i]}\g<2>',fileContent)
with ssh.open_sftp().file(ServerConfigurationInfo[i]["Location"],"w") as remoteFile:
remoteFile.write(fileContent)
except paramiko.AuthenticationException:
return "08"
except paramiko.SSHException as e:
return "09"
except Exception as e:
return "10"
finally:
ssh.close()
return "00"
def executeCommands(self,ServerCommands,serverConfigurationFilePath):
for i in range(0,len(ServerCommands)):
try:
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ServerCommands[i]["IP address"],username=ServerCommands[i]["Username"],password=ServerCommands[i]["Password"])
if ServerCommands[i]["Inputs"]==[]:
command=ServerCommands[i]["Command"]
stdin, stdout, stderr =ssh.exec_command(f'{command}')
channel=stdout.channel
while not channel.exit_status_ready():
pass
else:
inputs=""
for j in ServerCommands[i]["Inputs"]:
inputs=inputs+j+" "
command=ServerCommands[i]["Command"]
stdin, stdout, stderr =ssh.exec_command(f'echo {inputs}| {command}')
channel=stdout.channel
while not channel.exit_status_ready():
pass
except paramiko.AuthenticationException:
return "08"
except paramiko.SSHException as e:
return "09"
except Exception as e:
return "10"
finally:
ssh.close()
return "00"
def IntializeProfilers(self,ServerProfilingInfo,MasterConfiguration):
ssh=[]
stdin=[]
stdout=[]
stderr=[]
channel=[]
count=0
self.backgroundProcessExecTime=[]
for i in range(0,len(ServerProfilingInfo)):
try:
ssh.append(paramiko.SSHClient())
ssh[i].set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh[i].connect(ServerProfilingInfo[i]["IP address"],username=ServerProfilingInfo[i]["Username"],password=ServerProfilingInfo[i]["Password"]) #Connect to the server
ServerProcessName=ServerProfilingInfo[i]["Name"] # Server process names
ServerProcessPath=ServerProfilingInfo[i]["Path"] # Server profiling agent execute file path
ServerProcessName=json.dumps(ServerProcessName)
masterConfiguration=json.dumps(MasterConfiguration) # Client Configuration
command=f"python3 {ServerProcessPath} '{ServerProcessName}' '{masterConfiguration}'" # Command to run profiling agent
stdinTemp, stdoutTemp, stderrTemp =ssh[i].exec_command(command) # exectue the command at server shell
channel=stdoutTemp.channel
while not channel.exit_status_ready():
pass
exit_status = channel.recv_exit_status()
output = channel.recv(1024).decode().strip() # capture the output(resource usage data)
output = ast.literal_eval(output)
for j in output:
self.backgroundProcessExecTime.append(j)
except paramiko.AuthenticationException:
return "08"
except paramiko.SSHException as e:
return "09"
except Exception as e:
return "10"
for i in range(0,len(ServerProfilingInfo)): # close the connection
ssh[i].close()
return self.backgroundProcessExecTime # return the resource usage data
def startAPAgent(self,ServerProfilingInfo):
self.ssh=[]
self.stdin=[]
self.stdout=[]
self.stderr=[]
for i in range(0,len(ServerProfilingInfo)):
try:
ssh.append(paramiko.SSHClient())
ssh[i].set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh[i].connect(ServerProfilingInfo[i]["IP address"],username=ServerProfilingInfo[i]["Username"],password=ServerProfilingInfo[i]["Password"])
except paramiko.AuthenticationException:
return "08"
except paramiko.SSHException as e:
return "09"
except Exception as e:
return "10"
def GetProfilingData(self,ServerProfilingInfo,MasterConfiguration):
profileDataUNF=[]
ssh=[]
stdin=[]
stdout=[]
stderr=[]
channel=[]
count=0
for i in range(0,len(ServerProfilingInfo)):
try:
ssh.append(paramiko.SSHClient())
ssh[i].set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh[i].connect(ServerProfilingInfo[i]["IP address"],username=ServerProfilingInfo[i]["Username"],password=ServerProfilingInfo[i]["Password"]) #Connect to the server
ServerProcessName=ServerProfilingInfo[i]["Name"] # Server process names
ServerProcessPath=ServerProfilingInfo[i]["Path"] # Server profiling agent execute file path
ServerProcessName=json.dumps(ServerProcessName)
masterConfiguration=json.dumps(MasterConfiguration) # Client Configuration
command=f"python3 {ServerProcessPath} '{ServerProcessName}' '{masterConfiguration}'" # Command to run profiling agent
stdinTemp, stdoutTemp, stderrTemp =ssh[i].exec_command(command) # exectue the command at server shell
channel=stdoutTemp.channel
while not channel.exit_status_ready():
pass
exit_status = channel.recv_exit_status()
output = channel.recv(1024).decode().strip() # capture the output(resource usage data)
output = ast.literal_eval(output)
for j in output:
profileDataUNF.append(j)
except paramiko.AuthenticationException:
return "08"
except paramiko.SSHException as e:
return "09"
except Exception as e:
return "10"
for i in range(0,len(ServerProfilingInfo)):
ssh[i].close()
return profileDataUNF # return the resource usage data
This diff is collapsed.
execution:
- executor: jmeter
scenario: example
concurrency: 49
hold-for: 120m
scenarios:
example:
default-address: http://blazedemo.com
script: sample.jmx
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment