test_floatIp = FloatIp() try: test_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId( test_floatIp.ip) self._loggers.basebenchLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception, e: self._loggers.basebenchLogger.error('申请浮动ip失败!' + '\r\n' + e.message) self._accountResource.add_floatIp(test_floatIp) # 启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType = testType self._loggers.basebenchLogger.info('启动云主机' + test_compute.name) try: test_compute.id = self._novaClient.bootCompute( computeName, self._test_fio_flavor_id, self._test_image_id, self._test_fio_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception, e: self._loggers.basebenchLogger.error('启动云主机' + test_compute.name + '失败!' + '\r\n' + e.message) # 绑定浮动ip
def _initUnixbench(self): """ 根据unixbench所需要测试,创建云主机 :return: """ self._loggers.stabilityUnixbenchLogger.info('初始化unixbench测试的云主机规格') self._test_unixbench_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_unixbench_flavor) self._loggers.stabilityUnixbenchLogger.info( '初始化unixbench网络资源,创建名为' + self._test_unixbench_net_name + '的网络') test_unixbench_net = Net() test_unixbench_net.name = StrTool.addUUID( self._test_unixbench_net_name) test_unixbench_net.cidr = self._test_unixbench_subnet_cidr try: test_unixbench_net.id = self._openstackClient.createNetwork( test_unixbench_net.name, test_unixbench_net.cidr) self._test_unixbench_net_id = test_unixbench_net.id except Exception as e: self._loggers.stabilityUnixbenchLogger.error( '创建unixbench所需网络' + self._test_unixbench_net_name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.stabilityUnixbenchLogger.info('初始化一个路由器资源,创建名为' + self._router_name + '的路由') test_router = Router() test_router.name = StrTool.addUUID(self._router_name) try: test_router.id = self._openstackClient.createRouter( test_router.name, self._admin_float_net_id) self._router_id = test_router.id except Exception as e: self._loggers.stabilityUnixbenchLogger.error('创建路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.stabilityUnixbenchLogger.info( '将unixbench网络' + self._test_unixbench_net_name + '绑定到路由器' + self._router_name) try: test_unixbench_net_subnet_id = self._openstackClient.getSubNetId( self._test_unixbench_net_id) self._openstackClient.addRouterInterface( self._router_id, test_unixbench_net_subnet_id) test_router.add_subnet_id(test_unixbench_net_subnet_id) test_unixbench_net.add_subnet_id(test_unixbench_net_subnet_id) except Exception as e: self._loggers.stabilityUnixbenchLogger.error( '将unixbench网络' + self._test_unixbench_net_name + '绑定到路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_unixbench_net) self._accountResource.add_router(test_router) self._loggers.stabilityUnixbenchLogger.info('初始化unixbench测试的云主机') for i in range( int(self._readConfig.executeTest.stability_test_unixbench_num) ): computeName = StrTool.addUUID('basebench_unixbench' + str(i)) testType = 'unixbench' #申请一个浮动ip self._loggers.stabilityUnixbenchLogger.info('申请一个浮动ip') test_floatIp = FloatIp() try: test_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId( test_floatIp.ip) except Exception as e: self._loggers.stabilityUnixbenchLogger.error('申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_floatIp) #启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType = testType try: test_compute.id = self._novaClient.bootCompute( test_compute.name, self._test_unixbench_flavor_id, self._test_image_id, self._test_unixbench_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilityUnixbenchLogger.error( '启动云主机' + test_compute.name + '失败!' + '\r\n' + e.args.__str__()) #绑定浮动ip self._loggers.stabilityUnixbenchLogger.info('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( test_compute.id, test_floatIp.ip) if is_add_succ: test_compute.float_ip = test_floatIp.ip except Exception as e: self._loggers.stabilityUnixbenchLogger.error( '为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_unixbenchCompute(test_compute) self._accountResource.add_compute(test_compute)
def _initFio(self): """ 根据fio所需要测试,设置要测试的网络/云主机名/云硬盘名 :return: """ self._loggers.basebenchLogger.info('初始化fio测试的云主机规格') self._test_fio_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.basebench_test_fio_flavor) self._loggers.basebenchLogger.info('初始化fio网络资源,创建名为' + self._test_fio_net_name + '的网络') test_fio_net = Net() test_fio_net.name = StrTool.addUUID(self._test_fio_net_name) test_fio_net.cidr = self._test_fio_subnet_cidr try: test_fio_net.id = self._openstackClient.createNetwork( test_fio_net.name, test_fio_net.cidr) except Exception as e: self._loggers.basebenchLogger.error('创建网络' + test_fio_net.name + '失败!' + '\r\n' + e.args.__str__()) self._test_fio_net_id = test_fio_net.id self._loggers.basebenchLogger.info('初始化fio路由器资源,创建名为' + self._test_fio_router_name + '的路由器') test_fio_router = Router() test_fio_router.name = StrTool.addUUID(self._test_fio_router_name) try: test_fio_router.id = self._openstackClient.createRouter( test_fio_router.name, self._admin_float_net_id) except Exception as e: self._loggers.basebenchLogger.error('初始化fio路由器' + test_fio_router.name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.basebenchLogger.info('将fio网络' + test_fio_net.name + '绑定到路由器' + test_fio_router.name) try: test_fio_net_subnet_id = self._openstackClient.getSubNetId( self._test_fio_net_id) self._openstackClient.addRouterInterface(test_fio_router.id, test_fio_net_subnet_id) test_fio_net.add_subnet_id(test_fio_net_subnet_id) test_fio_router.add_subnet_id(test_fio_net_subnet_id) except Exception as e: self._loggers.basebenchLogger.error('将fio网络' + test_fio_net.name + '绑定到路由器' + test_fio_router.name + '失败' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_fio_net) self._accountResource.add_router(test_fio_router) self._loggers.basebenchLogger.info('初始化fio测试的云主机') test_fio_volume_types = self._readConfig.executeTest.basebench_test_fio_volume_types.split( '||') test_fio_types = self._readConfig.executeTest.basebench_test_fio_types.split( '||') for test_fio_volume_type in test_fio_volume_types: volumeType_id = getVolumeTypeId( self._accountResource.get_volumeTypes(), test_fio_volume_type) for test_fio_type in test_fio_types: volumeName = StrTool.addUUID('basebench_fio_' + test_fio_type + test_fio_volume_type) computeName = StrTool.addUUID('basebench_fio_' + test_fio_type + test_fio_volume_type) testType = test_fio_type + test_fio_volume_type # 创建云硬盘 test_volume = Volume() test_volume.name = volumeName test_volume.size = self._readConfig.executeTest.basebench_test_fio_volume_size test_volume.type = test_fio_volume_type self._loggers.basebenchLogger.info('创建云硬盘' + test_volume.name) try: test_volume.id = self._cinderClient.createVolume( volumeName, volumeType_id, test_volume.size) except Exception as e: self._loggers.basebenchLogger.error('创建云硬盘' + test_volume.name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_volume(test_volume) # 申请一个浮动ip self._loggers.basebenchLogger.info('申请一个浮动ip') test_floatIp = FloatIp() try: test_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId( test_floatIp.ip) self._loggers.basebenchLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception as e: self._loggers.basebenchLogger.error('申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_floatIp) # 启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType = testType self._loggers.basebenchLogger.info('启动云主机' + test_compute.name) try: test_compute.id = self._novaClient.bootCompute( computeName, self._test_fio_flavor_id, self._test_image_id, self._test_fio_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.basebenchLogger.error('启动云主机' + test_compute.name + '失败!' + '\r\n' + e.args.__str__()) # 绑定浮动ip self._loggers.basebenchLogger.info('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( test_compute.id, test_floatIp.ip) if is_add_succ: test_compute.float_ip = test_floatIp.ip except Exception as e: self._loggers.basebenchLogger.error('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) # 挂载云硬盘 self._loggers.basebenchLogger.info('为云主机' + test_compute.name + '挂载云硬盘' + test_volume.name) try: is_add_succ = self._novaClient.attachVolume( test_compute.id, test_volume.id, '/dev/vdc') if is_add_succ: test_compute.volumeName = test_volume.name test_compute.volumeId = test_volume.id except Exception as e: self._loggers.basebenchLogger.error('为云主机' + test_compute.name + '挂载云硬盘' + test_volume.name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_fioCompute(test_compute) self._accountResource.add_compute(test_compute)
def _initIperf(self): """ 初始化iperf测试必须有的资源 :return: """ self._loggers.basebenchLogger.info('初始化iperf测试的云主机规格') self._test_iperf_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.basebench_test_iperf_flavor) self._loggers.basebenchLogger.info('初始化iperf测试的网络' + self._test_iperf_net1_name + '和' + self._test_iperf_net2_name) test_iperf_net1 = Net() test_iperf_net2 = Net() test_iperf_net1.name = self._test_iperf_net1_name test_iperf_net1.cidr = self._test_iperf_subnet1_cidr test_iperf_net2.name = self._test_iperf_net2_name test_iperf_net2.cidr = self._test_iperf_subnet2_cidr try: test_iperf_net1.id = self._openstackClient.createNetwork( self._test_iperf_net1_name, self._test_iperf_subnet1_cidr) test_iperf_net2.id = self._openstackClient.createNetwork( self._test_iperf_net2_name, self._test_iperf_subnet2_cidr) except Exception as e: self._loggers.basebenchLogger.error('初始化iperf测试的网络' + self._test_iperf_net1_name + '和' + self._test_iperf_net2_name + '失败!' + '\r\n' + e.args.__str__()) self._test_iperf_net1_id = test_iperf_net1.id self._test_iperf_net2_id = test_iperf_net2.id self._loggers.basebenchLogger.info('初始化iperf路由器资源,创建名为' + self._test_iperf_router_name + '的路由器') test_iperf_router = Router() test_iperf_router.name = StrTool.addUUID(self._test_iperf_router_name) try: test_iperf_router.id = self._openstackClient.createRouter( test_iperf_router.name, self._admin_float_net_id) except Exception as e: self._loggers.basebenchLogger.error('初始化iperf路由器' + test_iperf_router.name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.basebenchLogger.info('将iperf网络' + self._test_iperf_net1_name + '绑定到路由器' + test_iperf_router.name) try: test_iperf_net1_subnet_id = self._openstackClient.getSubNetId( self._test_iperf_net1_id) self._openstackClient.addRouterInterface( test_iperf_router.id, test_iperf_net1_subnet_id) test_iperf_router.add_subnet_id(test_iperf_net1_subnet_id) test_iperf_net1.add_subnet_id(test_iperf_net1_subnet_id) except Exception as e: self._loggers.basebenchLogger.error('将iperf网络' + self._test_iperf_net1_name + '绑定到路由器' + test_iperf_router.name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.basebenchLogger.info('将iperf网络' + self._test_iperf_net2_name + '绑定到路由器' + test_iperf_router.name) try: test_iperf_net2_subnet_id = self._openstackClient.getSubNetId( self._test_iperf_net2_id) self._openstackClient.addRouterInterface( test_iperf_router.id, test_iperf_net2_subnet_id) test_iperf_router.add_subnet_id(test_iperf_net2_subnet_id) test_iperf_net2.add_subnet_id(test_iperf_net2_subnet_id) except Exception as e: self._loggers.basebenchLogger.error('将iperf网络' + self._test_iperf_net2_name + '绑定到路由器' + test_iperf_router.name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_iperf_net1) self._accountResource.add_net(test_iperf_net2) self._accountResource.add_router(test_iperf_router) self._loggers.basebenchLogger.info('初始化iperf测试的云主机') self._loggers.basebenchLogger.info('启动两组iperf测试云主机,同网段和不同网段') for i in range(2): #获取可用域 if len(self._zone_names) < 2: self._loggers.basebenchLogger.error( '可用域' + self._zone_names.__str__() + '少于两个无法进行iperf测试') return # 启动2组iperf测试云主机,同网段和不同网段 iperf_computePair = [] for j in range(2): #申请一个浮动ip test_floatIp = FloatIp() self._loggers.basebenchLogger.info('申请一个浮动ip') try: test_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId( test_floatIp.ip) self._loggers.basebenchLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception as e: self._loggers.basebenchLogger.error('申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_floatIp) # tmp_zone=None # tmp_net=None # tmp_testType=None # tmp_name=None #同网段 if i == 0 and j == 0: self._loggers.basebenchLogger.info('启动同网段的第一台云主机') tmp_zone = self._zone_names[0] tmp_net = self._test_iperf_net1_id tmp_testType = 'basebench_iperf_one_net' tmp_name = StrTool.addUUID('basebench_iperf_one_' + str(j)) #同网段 elif i == 0 and j == 1: self._loggers.basebenchLogger.info('启动同网段的第二台云主机') tmp_zone = self._zone_names[1] tmp_net = self._test_iperf_net1_id tmp_testType = 'basebench_iperf_one_net' tmp_name = StrTool.addUUID('basebench_iperf_one_' + str(j)) #不同网段 elif i == 1 and j == 0: self._loggers.basebenchLogger.info('启动不同网段的第一台云主机') tmp_zone = self._zone_names[0] tmp_net = self._test_iperf_net1_id tmp_testType = 'basebench_iperf_two_net' tmp_name = StrTool.addUUID('basebench_iperf_two_' + str(j)) #不同网段 else: self._loggers.basebenchLogger.info('启动不同网段的第二台云主机') tmp_zone = self._zone_names[1] tmp_net = self._test_iperf_net2_id tmp_testType = 'basebench_iperf_two_net' tmp_name = StrTool.addUUID('basebench_iperf_two_' + str(j)) #创建云主机 test_compute = Compute() test_compute.name = tmp_name test_compute.testType = tmp_testType self._loggers.basebenchLogger.info('启动云主机' + test_compute.name) try: test_compute.id = self._novaClient.bootCompute( test_compute.name, self._test_iperf_flavor_id, self._test_image_id, tmp_net, self._default_secgroup_id, tmp_zone, self._user_data_path) test_compute.ip = self._novaClient.getComputeIp( test_compute.name) except Exception as e: self._loggers.basebenchLogger.error('启动云主机' + test_compute.name + '失败!' + '\r\n' + e.args.__str__()) #绑定浮动ip self._loggers.basebenchLogger.info('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( test_compute.id, test_floatIp.ip) if is_add_succ: test_compute.float_ip = test_floatIp.ip except Exception as e: self._loggers.basebenchLogger.error('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) iperf_computePair.append(test_compute) self._accountResource.add_compute(test_compute) #设置一组iperf云主机 self._accountResource.add_iperfComputePair(iperf_computePair)
def _initSysbench(self): """ 初始化Sysbench测试必须有的资源 :return: """ self._loggers.stabilitySysbenchLogger.info('初始化Sysbench测试的云主机规格') self._test_sysbench_flavor_id=getFlavorId(self._accountResource.get_flavors(),self._readConfig.executeTest.stability_test_sysbench_flavor) self._loggers.stabilitySysbenchLogger.info('初始化Sysbench测试的网络'+self._test_sysbench_net_name) test_sysbench_net=Net() test_sysbench_net.name=self._test_sysbench_net_name test_sysbench_net.cidr = self._test_sysbench_subnet_cidr try: test_sysbench_net.id=self._openstackClient.createNetwork(self._test_sysbench_net_name,self._test_sysbench_subnet_cidr) except Exception as e: self._loggers.stabilitySysbenchLogger.info('创建网络' + self._test_sysbench_net_name + '失败'+'\r\n'+e.args.__str__()) self._test_sysbench_net_id=test_sysbench_net.id self._loggers.stabilitySysbenchLogger.info('初始化一个路由器资源,创建名为' + self._router_name + '的路由') test_router = Router() test_router.name = StrTool.addUUID(self._router_name) try: test_router.id = self._openstackClient.createRouter(test_router.name, self._admin_float_net_id) except Exception as e: self._loggers.stabilitySysbenchLogger.info('创建路由器' + self._router_name + '失败' + '\r\n' + e.args.__str__()) self._router_id = test_router.id self._loggers.stabilitySysbenchLogger.info('将Sysbench网络' + self._test_sysbench_net_name + '绑定到路由器' + self._router_name) try: test_sysbench_net_subnet_id=self._openstackClient.getSubNetId(self._test_sysbench_net_id) self._openstackClient.addRouterInterface(self._router_id, test_sysbench_net_subnet_id) test_router.add_subnet_id(test_sysbench_net_subnet_id) test_sysbench_net.add_subnet_id(test_sysbench_net_subnet_id) except Exception as e: self._loggers.stabilitySysbenchLogger.info('将Sysbench网络' + self._test_sysbench_net_name + '绑定到路由器' + self._router_name+ '失败'+'\r\n'+e.args.__str__()) self._accountResource.add_net(test_sysbench_net) self._accountResource.add_router(test_router) #初始化trove必须有的资源 self._trove_volume_size = '100' self._database_name = 'sbtest' self._user_name = 'test' self._user_password = '******' self._datastore_name = 'mysql' self._datastore_version_name = '5.6' for i in range(int(self._readConfig.executeTest.stability_test_sysbench_group_num)): self._loggers.stabilitySysbenchLogger.info('初始化Sysbench测试的云主机') # 启动一组Sysbench测试,同网段 sysbench_computePair=[] computeName = StrTool.addUUID('basebench_sysbench' + str(i)) testType = 'sysbench' #申请一个浮动ip test_floatIp = FloatIp() try: test_floatIp.ip = self._openstackClient.getFloatIp(self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId(test_floatIp.ip) self._loggers.stabilitySysbenchLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception as e: self._loggers.stabilitySysbenchLogger.info('申请浮动ip失败:'+'\r\n'+e.args.__str__()) self._accountResource.add_floatIp(test_floatIp) #启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType=testType self._loggers.stabilitySysbenchLogger.info('启动云主机'+test_compute.name) try: test_compute.id=self._novaClient.bootCompute(computeName, self._test_sysbench_flavor_id, self._test_image_id, self._test_sysbench_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilitySysbenchLogger.info('启动云主机' + test_compute.name + '失败'+'\r\n'+e.args.__str__()) #绑定浮动ip self._loggers.stabilitySysbenchLogger.info('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip) try: is_add_succ=self._novaClient.addFloatForCompute(test_compute.id,test_floatIp.ip) if is_add_succ: test_compute.float_ip = test_floatIp.ip except Exception as e: self._loggers.stabilitySysbenchLogger.info('为云主机' + test_compute.name + '绑定浮动ip:' + test_floatIp.ip + '失败'+'\r\n'+e.args.__str__()) #创建数据库实例 troveName = StrTool.addUUID('trove' + str(i)) test_trove = Trove() test_trove.name = troveName self._loggers.stabilitySysbenchLogger.info('创建一台数据库实例' + test_trove.name) try: test_trove.id = self._troveClient.createtrove(test_trove.name, self._test_sysbench_flavor_id, self._trove_volume_size, self._database_name, self._user_name, self._user_password, self._test_sysbench_net_id, random.choice(self._zone_names), self._datastore_name, self._datastore_version_name) except Exception as e: self._loggers.stabilitySysbenchLogger.info('创建一台数据库实例' + test_trove.name + '失败'+'\r\n'+e.args.__str__()) test_trove.ip = self._novaClient.getComputeIp(test_trove.name) sysbench_computePair.append(test_compute) self._accountResource.add_compute(test_compute) sysbench_computePair.append(test_trove) #self._accountResource.add_compute(test_trove) #设置一组iperf云主机 self._accountResource.add_sysbenchComputePair(sysbench_computePair)
try: test_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatIp.id = self._openstackClient.getFloatId( test_floatIp.ip) self._loggers.stabilityMemtesterLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception, e: self._loggers.stabilityMemtesterLogger.error('申请浮动ip失败!' + '\r\n' + e.message) self._accountResource.add_floatIp(test_floatIp) #启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType = testType self._loggers.stabilityMemtesterLogger.info('启动云主机' + test_compute.name) try: test_compute.id = self._novaClient.bootCompute( computeName, self._test_memtester_flavor_id, self._test_image_id, self._test_memtester_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception, e: self._loggers.stabilityMemtesterLogger.error( '启动云主机' + test_compute.name + '失败!' + '\r\n' + e.message) #绑定浮动ip self._loggers.stabilityMemtesterLogger.info('为云主机' +
self._loggers.stabilityIperfLogger.info('启动第一台云主机') zone = self._zone_names[0] net_id = self._test_iperf_net1_id name = StrTool.addUUID('basebench_iperf_' + str(i) + '_' + str(j)) #第二台 elif j == 1: self._loggers.stabilityIperfLogger.info('启动第二台云主机') zone = self._zone_names[1] net_id = self._test_iperf_net2_id name = StrTool.addUUID('basebench_iperf_' + str(i) + '_' + str(j)) #创建云主机 test_compute = Compute() test_compute.name = name test_compute.testType = tmp_testType self._loggers.stabilityIperfLogger.info('启动云主机' + test_compute.name) try: test_compute.id = self._novaClient.bootCompute( test_compute.name, self._test_iperf_flavor_id, self._test_image_id, net_id, self._default_secgroup_id, zone, self._user_data_path) test_compute.ip = self._novaClient.getComputeIp( test_compute.name) except Exception, e: self._loggers.stabilityIperfLogger.error( '启动云主机' + test_compute.name + '失败!' + '\r\n' + e.message) #绑定浮动ip
def _initObjectstore(self): """ 初始化对象存储稳定性测试资源 :return: """ self._loggers.stabilityObjstoreLogger.info('初始化对象存储测试的云主机规格') self._test_oss_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_objstore_load_flavor) self._loggers.stabilityObjstoreLogger.info('初始化对象存储网络资源,创建名为' + self._oss_net_name + '的网络') oss_test_net = Net() oss_test_net.name = StrTool.addUUID(self._oss_net_name) oss_test_net.cidr = self._oss_subnet_cidr try: oss_test_net.id = self._openstackClient.createNetwork( oss_test_net.name, oss_test_net.cidr) except Exception as e: self._loggers.stabilityObjstoreLogger.error('创建网络' + oss_test_net.name + '失败!' + '\r\n' + e.args.__str__()) self._oss_test_net_id = oss_test_net.id self._loggers.stabilityObjstoreLogger.info('初始化一个路由器资源,创建名为' + self._router_name + '的路由') test_router = Router() test_router.name = StrTool.addUUID(self._router_name) try: test_router.id = self._openstackClient.createRouter( test_router.name, self._admin_float_net_id) except Exception as e: self._loggers.stabilityObjstoreLogger.error('创建路由器' + test_router.name + '失败!' + '\r\n' + e.args.__str__()) self._router_id = test_router.id self._loggers.stabilityObjstoreLogger.info('将网络' + self._oss_net_name + '绑定到路由器' + self._router_name) try: oss_subnet_id = self._openstackClient.getSubNetId( self._oss_test_net_id) self._openstackClient.addRouterInterface(self._router_id, oss_subnet_id) test_router.add_subnet_id(oss_subnet_id) oss_test_net.add_subnet_id(oss_subnet_id) except Exception as e: self._loggers.stabilityObjstoreLogger.error('将对象存储网络' + self._oss_net_name + '绑定到路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(oss_test_net) self._accountResource.add_router(test_router) self._loggers.stabilityObjstoreLogger.info('初始化对象存储测试的云主机') computeName = StrTool.addUUID('basebench_OSS') testType = StrTool.addUUID('OSS') #申请浮动IP test_oss_floatIp = FloatIp() try: test_oss_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_oss_floatIp.id = self._openstackClient.getFloatId( test_oss_floatIp.ip) except Exception as e: self._loggers.stabilityObjstoreLogger.error('申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_oss_floatIp) #启动云主机 test_oss_compute = Compute() test_oss_compute.name = computeName test_oss_compute.testType = testType try: test_oss_compute.id = self._novaClient.bootCompute( computeName, self._test_oss_flavor_id, self._test_image_id, self._oss_test_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilityObjstoreLogger.error('启动云主机' + test_oss_compute.name + '失败!' + '\r\n' + e.args.__str__()) # 绑定浮动ip try: is_add_succ = self._novaClient.addFloatForCompute( test_oss_compute.id, test_oss_floatIp.ip) if is_add_succ: test_oss_compute.float_ip = test_oss_floatIp.ip except Exception as e: self._loggers.stabilityObjstoreLogger.error('为云主机' + test_oss_compute.name + '绑定浮动ip:' + test_oss_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_objectstorageCompute(test_oss_compute) self._accountResource.add_compute(test_oss_compute)
def _initFio(self): """ 根据fio测试需要,设置要测试的网络/云主机名/云硬盘名 :return: """ self._loggers.stabilityFioLogger.info('初始化fio测试的云主机规格') self._test_fio_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_fio_flavor) self._loggers.stabilityFioLogger.info('初始化fio网络资源,创建名为' + self._fio_net_name + '的网络') fio_test_net = Net() fio_test_net.name = StrTool.addUUID(self._fio_net_name) fio_test_net.cidr = self._fio_subnet_cidr try: fio_test_net.id = self._openstackClient.createNetwork( fio_test_net.name, fio_test_net.cidr) except Exception as e: self._loggers.stabilityFioLogger.error('创建网络' + fio_test_net.name + '失败!' + '\r\n' + e.args.__str__()) self._fio_net_id = fio_test_net.id self._loggers.stabilityFioLogger.info('初始化一个路由器资源,创建名为' + self._router_name + '的路由') test_router = Router() test_router.name = StrTool.addUUID(self._router_name) try: test_router.id = self._openstackClient.createRouter( test_router.name, self._admin_float_net_id) except Exception as e: self._loggers.stabilityFioLogger.error('创建路由器' + test_router.name + '失败!' + '\r\n' + e.args.__str__()) self._router_id = test_router.id self._loggers.stabilityFioLogger.info('将fio网络' + self._fio_net_name + '绑定到路由器' + self._router_name) try: fio_subnet_id = self._openstackClient.getSubNetId(self._fio_net_id) self._openstackClient.addRouterInterface(self._router_id, fio_subnet_id) test_router.add_subnet_id(fio_subnet_id) fio_test_net.add_subnet_id(fio_subnet_id) except Exception as e: self._loggers.stabilityFioLogger.error('将fio网络' + self._fio_net_name + '绑定到路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(fio_test_net) self._accountResource.add_router(test_router) self._loggers.stabilityFioLogger.info('初始化fio测试的云主机') volume_types_and_num = self._readConfig.executeTest.stability_test_fio_volume_types_and_num.split( '||') test_fio_types = self._readConfig.executeTest.stability_test_fio_types.split( '||') for volume_type_and_num_str in volume_types_and_num: volume_type_and_num = volume_type_and_num_str.split('&') volumeType_id = getVolumeTypeId( self._accountResource.get_volumeTypes(), volume_type_and_num[0]) num = int(volume_type_and_num[1]) while num > 0: num = num - 1 for test_fio_type in test_fio_types: volumeName = StrTool.addUUID('basebench_fio_' + test_fio_type + volume_type_and_num[0]) computeName = StrTool.addUUID('basebench_fio_' + test_fio_type + volume_type_and_num[0] + '_' + str(num)) #创建云硬盘 test_volume = Volume() try: test_volume.name = volumeName test_volume.type = volume_type_and_num[0] test_volume.size = self._readConfig.executeTest.stability_test_fio_volume_size test_volume.id = self._cinderClient.createVolume( test_volume.name, volumeType_id, test_volume.size) except Exception as e: self._loggers.stabilityFioLogger.error( '创建云硬盘' + volumeName + '失败' + '\r\n' + e.args.__str__()) self._accountResource.add_volume(test_volume) #申请浮动IP test_floatip = FloatIp() try: test_floatip.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_floatip.id = self._openstackClient.getFloatId( test_floatip.ip) except Exception as e: self._loggers.stabilityFioLogger.error( '申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_floatip) #启动云主机 test_compute = Compute() test_compute.name = computeName test_compute.testType = test_fio_type try: test_compute.id = self._novaClient.bootCompute( test_compute.name, self._test_fio_flavor_id, self._test_image_id, self._fio_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilityFioLogger.error( '启动云主机' + test_compute.name + '失败!' + '\r\n' + e.args.__str__()) # 绑定浮动IP try: is_add_succ = self._novaClient.addFloatForCompute( test_compute.id, test_floatip.ip) if is_add_succ: test_compute.float_ip = test_floatip.ip except Exception as e: self._loggers.stabilityFioLogger.error( '为云主机' + test_compute.name + '绑定浮动ip:' + test_floatip.ip + '失败!' + '\r\n' + e.args.__str__()) # 挂载云硬盘 try: is_attach_succ = self._novaClient.attachVolume( test_compute.id, test_volume.id, '/dev/vdb') if is_attach_succ: test_compute.volumeId = test_volume.id test_compute.volumeName = test_volume.name except Exception as e: self._loggers.stabilityFioLogger.error( '挂载云硬盘失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_fioCompute(test_compute) self._accountResource.add_compute(test_compute)
def _initLoadbalancer(self): """ 初始化loadbalancer测试必须有的资源 :return: """ self._loggers.stabilityLoadbalancerLogger.info( '初始化loadbalancer测试的云主机规格') self._test_loadbalancer_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_loadbalancer_flavor) self._loggers.stabilityLoadbalancerLogger.info( '初始化loadbalancer测试的网络' + self._test_loadbalancer_net_name) test_loadbalancer_net = Net() test_loadbalancer_net.name = self._test_loadbalancer_net_name test_loadbalancer_net.cidr = self._test_loadbalancer_subnet_cidr try: test_loadbalancer_net.id = self._openstackClient.createNetwork( self._test_loadbalancer_net_name, self._test_loadbalancer_subnet_cidr) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '创建loadbalancer网络' + self._test_loadbalancer_net_name + '失败!' + '\r\n' + e.args.__str__()) self._test_loadbalancer_net_id = test_loadbalancer_net.id self._loggers.stabilityLoadbalancerLogger.info('初始化一个路由器资源,创建名为' + self._router_name + '的路由') test_router = Router() test_router.name = StrTool.addUUID(self._router_name) try: test_router.id = self._openstackClient.createRouter( test_router.name, self._admin_float_net_id) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error('创建路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._router_id = test_router.id self._loggers.stabilityLoadbalancerLogger.info( '将loadbalancer网络' + self._test_loadbalancer_net_name + '绑定到路由器' + self._router_name) try: self._test_loadbalancer_net_subnet_id = self._openstackClient.getSubNetId( self._test_loadbalancer_net_id) self._openstackClient.addRouterInterface( self._router_id, self._test_loadbalancer_net_subnet_id) test_router.add_subnet_id(self._test_loadbalancer_net_subnet_id) test_loadbalancer_net.add_subnet_id( self._test_loadbalancer_net_subnet_id) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '将loadbalancer网络' + self._test_loadbalancer_net_name + '绑定到路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_loadbalancer_net) self._accountResource.add_router(test_router) for i in range( int(self._readConfig.executeTest. stability_test_loadbalancer_group_num)): self._loggers.stabilityLoadbalancerLogger.info( '初始化loadbalancer测试的云主机') loadbalancerName = StrTool.addUUID('basebench_loadbalancer' + str(i)) test_loadbalancer = LoadBalancer() test_loadbalancer.name = loadbalancerName # 启动一组loadbalancer测试云主机,以及一台jmeter云主机 member_ips_weight = [] loadbalancer_member_weight = self._readConfig.executeTest.stability_test_loadbalancer_member_weight.split( '||') for j in range( int(self._readConfig.executeTest. stability_test_loadbalancer_member_num)): member_computeName = StrTool.addUUID( 'basebench_loadbalancer_' + str(i) + '_' + str(j)) tmp_testType = 'loadbalancer' #申请一个浮动ip self._loggers.stabilityLoadbalancerLogger.info( '为后端服务器申请一个浮动ip') member_floatIp = FloatIp() try: member_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) member_floatIp.id = self._openstackClient.getFloatId( member_floatIp.ip) self._loggers.stabilityLoadbalancerLogger.info( '为后端服务器申请到一个浮动ip:' + member_floatIp.ip) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '为后端服务器申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(member_floatIp) #创建云主机 member_compute = Compute() member_compute.name = member_computeName member_compute.testType = tmp_testType try: member_compute.id = self._novaClient.bootCompute( member_compute.name, self._test_loadbalancer_flavor_id, self._test_image_id, self._test_loadbalancer_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '启动一台后端服务器' + member_compute.name + '失败!' + '\r\n' + e.args.__str__()) #绑定浮动ip self._loggers.stabilityLoadbalancerLogger.info( '为后端服务器' + member_compute.name + '绑定浮动ip:' + member_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( member_compute.id, member_floatIp.ip) if is_add_succ: member_compute.float_ip = member_floatIp.ip except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '为后端服务器' + member_compute.name + '绑定浮动ip:' + member_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) test_loadbalancer.add_member(member_compute) self._accountResource.add_compute(member_compute) tmp_member_ip_weight = [] member_compute.ip = self._novaClient.getComputeIp( member_compute.name) member_weight = loadbalancer_member_weight[j] tmp_member_ip_weight.append(member_compute.ip) tmp_member_ip_weight.append(member_weight) member_ips_weight.append(tmp_member_ip_weight) # 申请一个浮动ip self._loggers.stabilityLoadbalancerLogger.info('为负载均衡器申请到一个浮动ip') loadbalancer_floatIp = FloatIp() try: loadbalancer_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) loadbalancer_floatIp.id = self._openstackClient.getFloatId( loadbalancer_floatIp.ip) self._loggers.stabilityLoadbalancerLogger.info( '为负载均衡器申请到一个浮动ip:' + loadbalancer_floatIp.ip) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '为负载均衡器申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(loadbalancer_floatIp) #启动负载均衡器 try: test_loadbalancer.id = self._loadbalancerClient.createLoadbalancer( test_loadbalancer.name, loadbalancer_floatIp.id, self._test_loadbalancer_net_subnet_id, self._readConfig. executeTest.stability_test_loadbalancer_connection_limit, self._readConfig.executeTest. stability_test_loadbalancer_protocol, self._readConfig. executeTest.stability_test_loadbalancer_protocol_port, self._readConfig.executeTest. stability_test_loadbalancer_lb_algorithmt, self._readConfig.executeTest. stability_test_loadbalancer_delay_time, self._readConfig. executeTest.stability_test_loadbalancer_max_retries, self._readConfig.executeTest. stability_test_loadbalancer_timeout, self._readConfig. executeTest.stability_test_loadbalancer_protocol_type, member_ips_weight) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '启动负载均衡器' + test_loadbalancer.name + '失败!' + '\r\n' + e.args.__str__()) if test_loadbalancer.id: test_loadbalancer.virtual_ip = loadbalancer_floatIp.ip test_loadbalancer.port = self._readConfig.executeTest.stability_test_loadbalancer_protocol_port jmeter_computeName = StrTool.addUUID( 'basebench_loadbalancer_jmeter' + str(i)) tmp_testType = 'loadbalancer_jmeter' # 申请一个浮动ip self._loggers.stabilityLoadbalancerLogger.info( '为负载均衡器加压云主机申请到一个浮动ip') jmeter_floatIp = FloatIp() try: jmeter_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) jmeter_floatIp.id = self._openstackClient.getFloatId( jmeter_floatIp.ip) self._loggers.stabilityLoadbalancerLogger.info( '为负载均衡器加压云主机申请到一个浮动ip:' + jmeter_floatIp.ip) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '为负载均衡器加压云主机申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(jmeter_floatIp) # 创建均衡负载器加压的云主机 jmeter_compute = Compute() jmeter_compute.name = jmeter_computeName jmeter_compute.testType = tmp_testType try: jmeter_compute.id = self._novaClient.bootCompute( jmeter_compute.name, self._test_loadbalancer_flavor_id, self._test_image_id, self._test_loadbalancer_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '启动负载均衡器加压云主机' + jmeter_compute.name + '失败!' + '\r\n' + e.args.__str__()) # 绑定浮动ip self._loggers.stabilityLoadbalancerLogger.info( '为负载均衡器加压云主机' + jmeter_compute.name + '绑定浮动ip:' + jmeter_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( jmeter_compute.id, jmeter_floatIp.ip) if is_add_succ: jmeter_compute.float_ip = jmeter_floatIp.ip test_loadbalancer.load_compute = jmeter_compute except Exception as e: self._loggers.stabilityLoadbalancerLogger.error( '为负载均衡器加压云主机' + jmeter_compute.name + '绑定浮动ip:' + jmeter_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_compute(jmeter_compute) test_loadbalancer.load_compute = jmeter_compute #设置一组loadbalancer云主机 self._accountResource.add_loadbalancer(test_loadbalancer)
member_floatIp = FloatIp() try: member_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) member_floatIp.id = self._openstackClient.getFloatId( member_floatIp.ip) self._loggers.stabilityLoadbalancerLogger.info( '为后端服务器申请到一个浮动ip:' + member_floatIp.ip) except Exception, e: self._loggers.stabilityLoadbalancerLogger.error( '为后端服务器申请浮动ip失败!' + '\r\n' + e.message) self._accountResource.add_floatIp(member_floatIp) #创建云主机 member_compute = Compute() member_compute.name = member_computeName member_compute.testType = tmp_testType try: member_compute.id = self._novaClient.bootCompute( member_compute.name, self._test_loadbalancer_flavor_id, self._test_image_id, self._test_loadbalancer_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception, e: self._loggers.stabilityLoadbalancerLogger.error( '启动一台后端服务器' + member_compute.name + '失败!' + '\r\n' + e.message) #绑定浮动ip self._loggers.stabilityLoadbalancerLogger.info( '为后端服务器' + member_compute.name + '绑定浮动ip:' +