清单 3. 部署制定的虚拟系统模式

import time, threading, Queue, csv
 
# deploy the images for performance throughput
class waitfor(threading.Thread):
    def __init__(self, system, log_q):
        self.system = system
        self.log_q = log_q
        threading.Thread.__init__(self)
          
    def run(self):
        start = time.clock()
        self.system.waitFor()
        finish = time.clock()         
        self.log_q.put_nowait([time.strftime("%m/%d/%Y"), time.strftime("%H:%M:%S"),
                              self.system.name,self.system.currentstatus,(finish-start)])
  
def run_test(instances, fname):
    log_q = Queue.Queue()
    threads = []
    for instance in range (int(instances)):
        virtualsystem = None
        sysName = '%s-%s-%s-%d' % (pfx, time.strftime("%Y%m%d"),time.strftime("%H%M5%S"),
                                   instance+1)
        print 'deploying virtual system: %s' % sysName
      
        createParms['name'] = sysName
        virtualsystem = deployer.virtualsystems << createParms
        sys = waitfor(virtualsystem, log_q)
        sys.start()
        threads.append(sys)
  
    #wait until all are done
    for thd in threads:
        thd.join()
  
    # write out the results
    fname = csv.writer(open(fname, 'w'))
    fname.writerow(['date', 'time', 'system_name','status','duration'])
    for xx in range(log_q.qsize()):
        data = log_q.get()
        fname.writerow(data)

#################################################################
# select pattern to deploy
instances = raw_input('number of instances to create: ')
pfx = raw_input('prefix for created systems: ')
output = raw_input('results file (** will be overwritten **): ')
createParms = {}

# default parameters
createParms['*.script-4.CHEF_NODE'] = 'devops_default'
createParms['*.script-4.DEPS_FILE_URL'] = '/tmp/devops_install/media/Deps-devops_services'
createParms['*.script-4.CHEF_NODE_ATTR'] =
    '"devops_server":
    {"app_source":"file:///tmp/devops_install/media/devops_services_app.zip"},
    "ram":{"server_url":
    "http://devops.rtp.raleigh.ibm.com/downloads/RAM-Server-7.5.1.1-Linux64.zip",
    "persist_url"
    :"http://devops.rtp.raleigh.ibm.com/downloads/RAM-Data-7.5.1.1.tar.gz",
    /"database_url":
    "http://devops.rtp.raleigh.ibm.com/downloads/RAM-Database-7.5.1.1.tar.gz"},
    "db2":{
    "host_server_url":"http://devops.rtp.raleigh.ibm.com/downloads"},
    "jruby":{"download_url":"http://devops.rtp.raleigh.ibm.com/downloads/"}'
createParms['cloud'] = deployer.clouds[0]

# select the performance pattern to deploy
pattern = None
while not pattern:
    i = 1
    for p in deployer.patterns:
        print '%d. %s' % (i, p.name)
        i = i + 1
    x = raw_input('select the test pattern to deploy: ')
    try:
        pattern = deployer.patterns[int(x) - 1]
    except:
        # try again
        pass
createParms['pattern'] = pattern

#start deploying
started = time.strftime("%m/%d/%Y at %H:%M:%S")
run_test(instances, output)  
completed = time.strftime("%m/%d/%Y at %H:%M:%S")

print '#############   test summary  #######################'
print 'Started on: %s Completed on: %s' % (started, completed)
print 'Images deployed: %s' % instances

  实现部分 3:测试执行

  测试执行的时候我们需要调用 RQM 的命令行执行工具 (Command Line Execution Tool),这个工具是跟着 RQM 同时发布在 Jazz.net 上的,具体下载请看参考资源中提供的链接。

  RQM 命令行执行工具是我们可以方便的执行测试,通过 RQM RESTAPI 启动测试执行记录 (Test Execution Record) 的运行。在运行测试执行时需要提供以下信息:

  ● RQM url – https://hostname:9443/qm

  ● 用户名和密码 -- 使用这个用户名允许运行相应的测试执行记录

  ● 项目– 测试用例所在的 RQM 中的测试项目

  ● 测试执行记录的 id

  ● 测试执行记录关联的脚本的 id

  ● 执行适配器 (Adapter) 的 id

    ▲ 执行适配器是 RQM 提供的用以连接并操作具体测试脚本的功能,常用的适配器包括 Rational Functional Tester、Rational Performance Tester、Rational Build Forge 以及其他更多第三方厂商和开源工具的适配器。用户也可以自己编写适配器。

  ● 执行时需要的参数

  通过命令行调用后执行结果是会输出到命令行的,也可以直接输出到文件,用于后续操作。