一种搭建分布式测试环境和批量性能测试的思路

发表于:2013-1-04 10:14

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:小亮    来源:51Testing软件测试网采编

分享:

  然后比如关于Searcher的配置文件,在上面也是一个模版文件阿,我们可以把这个文件设计成:

  1. se_conf_file=${searchRoot}/scripts/conf/se.conf 
  2. simon_conf_path=${searchRoot}/scripts/conf/simon_searcher.xml 
  3. sort_config=${searchRoot}/scripts/conf/searcher_sort.xml 
  4. cache_size=0 
  5. cache_min_doc=0 
  6. conn_queue_limit=500 
  7. [services] 
  8. tcp ${port} # 主要就是为了替换监听的端口,其实要做得通用一点的话,很多配置都可以搞成变量,但就是可能你自己的配置文件变得很复杂。因此我们能不改的就尽量不改。 
  9.  
  10. [clustermap] 
  11. local_config_path=${searchRoot}/scripts/conf/clustermap.xml

  上述就是关于searcher和merger多行多列的配置,下面我们完善一下我们刚才的Python脚本

  1. # 得的一个ssh登录后的client对象,用于调用远程机器上的命令 
  2. def getClient(host, port, username, password): 
  3.     client = paramiko.SSHClient() 
  4.     client.load_system_host_keys() 
  5.     client.set_missing_host_key_policy(paramiko.WarningPolicy() 
  6.     client.connect(hostname, port, username, password) 
  7.     return client 
  8.  
  9. # 得到一个sftp对象,因为需要scp渲染好的配置文件什么的,因此需要sftp对象,它的put方法其实就类似scp 
  10. def getSftp(host, port, username, password): 
  11.     transport = paramiko.Transport((hostname, port)) 
  12.     transport.connect(username=username, password=password) 
  13.     sftp = paramiko.SFTPClient.from_transport(transport) 
  14.     return sftp 
  15.  
  16. # 更新和部署Searchers 
  17. def cleanSearchers(config, searchers): 
  18.     for searcher in searchers: 
  19.         # 得到渲染好的配置文件的内容 
  20.         templateLine = Template(file(config["searcher"]["templateConfigFile"]).read()).render( 
  21.             port=searcher["port"], 
  22.             searchRoot=config["searchRoot"] 
  23.             ) 
  24.         # 将渲染好的配置文件写入一个临时文件 
  25.         tmpConfigFile = tempfile.NamedTemporaryFile(delete=False) 
  26.         tmpConfigFile.file.write(templateLine) 
  27.         tmpConfigFile.file.close() 
  28.         # 将这个临时文件scp拷远程机器上的哪儿 
  29.         targetConfigFile = Template(searcher["configFile"]).render(searchRoot=config["searchRoot"]) 
  30.         sftp = getSftp(searcher["host"], 22, searcher["username"], searcher["password"]) 
  31.         sftp.put(tmpConfigFile.name, targetConfigFile) 
  32.         sftp.close() 
  33.         # 删除掉之前的临时文件 
  34.         os.remove(tmpConfigFile.name) 
  35.         # 运行启动searcher的命令 
  36.         client = getClient(searcher["host"], 22, searcher["username"], searcher["password"]) 
  37.         for command in config["searcher"]["commands"]: 
  38.             command = Template(command).render( 
  39.                 searchRoot=config["searchRoot"], 
  40.                 configFile=targetConfigFile, 
  41.                 logConfigFile=targetLogConfigFile 
  42.                 ) 
  43.             client.exec_command(cmd) 
  44.         client.close()

53/5<12345>
重磅发布,2022软件测试行业现状调查报告~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号