class InitUnixbenchResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_unixbench_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_unixbench_os_project_name self._os_username = self._readConfig.accounts.stability_unixbench_os_username self._os_password = self._readConfig.accounts.stability_unixbench_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityUnixbenchLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_unixbench_router' self._user_data_path = 'userdata/user_data' self._test_unixbench_net_name = 'basebench_unixbench_net' self._test_unixbench_subnet_cidr = '192.168.30.0/24' self._loggers.stabilityUnixbenchLogger.info( '===初始化稳定性测试基础资源[unixbench账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilityUnixbenchLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityUnixbenchLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') #判断是否进行unixbench测试 if self._readConfig.executeTest.is_stability_test_unixbench.lower( ) == 'true': self._loggers.stabilityUnixbenchLogger.info( '===开始初始化稳定性测试unixbench资源===') self._initUnixbench() self._loggers.stabilityUnixbenchLogger.info( '将测试初始化资源写入到文件dbs/stabilityUnixbenchTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityUnixbenchTestAccountResource.dbs') 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 getStabilityUnixbenchAccountResource(self): return self._accountResource
class InitHeatResource: def __init__(self): self._readConfig=ReadConfig() self._loggers=Loggers() self._os_tenant_name=self._readConfig.accounts.stability_heat_os_tenant_name self._os_project_name=self._readConfig.accounts.stability_heat_os_project_name self._os_username =self._readConfig.accounts.stability_heat_os_username self._os_password=self._readConfig.accounts.stability_heat_os_password self._init=Init(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password,self._loggers.stabilityHeatLogger) self._accountResource = self._init.initAccountResource() self._router_name='basebench_heat_router' self._user_data_path='userdata/user_data' self._test_heat_net_name='basebench_heat_net' self._test_heat_subnet_cidr='192.168.50.0/24' self._loggers.stabilityHeatLogger.info('===初始化稳定性测试基础资源[heat账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilityHeatLogger.info('初始化命令行客户端') self._openstackClient=OpenstackClient(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password) self._novaClient=NovaClient(self._os_project_name,self._os_username,self._os_password) self._cinderClient=CinderClient(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password) self._heatClient = HeatClient(self._os_tenant_name, self._os_project_name, self._os_username,self._os_password) self._loggers.stabilityHeatLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id=getDefaultSecGroupId(self._accountResource.get_secgroups(),self._readConfig.base.default_secgroup_name) self._admin_float_net_id=getAdminFloatNetId(self._accountResource.get_adminNets(),self._readConfig.base.admin_float_net_name) self._test_image_id=getTestImageId(self._accountResource.get_images(),self._readConfig.base.test_image_name) #判断是否进行memtester测试 if self._readConfig.executeTest.is_stability_test_heat.lower()=='true': self._loggers.stabilityHeatLogger.info('===开始初始化稳定性测试heat资源===') self._initHeat() self._loggers.stabilityHeatLogger.info('将测试初始化资源写入到文件dbs/stabilityHeatTestAccountResource.dbs') FileTool.writeObjectIntoFile(self._accountResource,'dbs/stabilityHeatTestAccountResource.dbs') def _initHeat(self): """ 根据heat所需要测试,创建云主机 :return: """ self._loggers.stabilityHeatLogger.info('初始化heat测试的云主机规格') self._test_heat_flavor_id = getFlavorId(self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_heat_flavor) self._test_heat_flavor_name = getFlavorId(self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_heat_flavor) self._loggers.stabilityHeatLogger.info('初始化heat网络资源,创建名为' + self._test_heat_net_name + '的网络') test_heat_net = Net() test_heat_net.name = StrTool.addUUID(self._test_heat_net_name) test_heat_net.cidr = self._test_heat_subnet_cidr try: test_heat_net.id = self._openstackClient.createNetwork(test_heat_net.name, test_heat_net.cidr) except Exception as e: self._loggers.stabilityHeatLogger.error('初始化网络'+self._router_name+'失败!'+'\r\n'+e.args.__str__()) self._test_heat_net_id = test_heat_net.id self._loggers.stabilityHeatLogger.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.stabilityHeatLogger.error('创建路由器'+self._router_name+'失败!'+'\r\n'+e.args.__str__()) self._router_id=test_router.id self._loggers.stabilityHeatLogger.info('将heat网络' + self._test_heat_net_name + '绑定到路由器' + self._router_name) try: test_heat_net_subnet_id = self._openstackClient.getSubNetId(self._test_heat_net_id) self._openstackClient.addRouterInterface(self._router_id, test_heat_net_subnet_id) test_router.add_subnet_id(test_heat_net_subnet_id) test_heat_net.add_subnet_id(test_heat_net_subnet_id) except Exception as e: self._loggers.stabilityHeatLogger.error('将heat网络' + self._test_heat_net_name + '绑定到路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_heat_net) self._accountResource.add_router(test_router) # 初始化heat必须有的资源 self._password = '******' self._max_computes = '5' self._min_computes = '3' self._alarm_type = 'cpu_util' self._max_alarmvalue = '90' self._min_alarmvalue = '45' self._heat_templatepath = 'heat_template/heat_new.yaml' for i in range(int(self._readConfig.executeTest.stability_test_heat_group_num)): heatName = StrTool.addUUID('basebench_heat'+str(i)) testType = 'heat' #启动heat test_heat = Heat() test_heat.name = heatName test_heat.testType=testType self._loggers.stabilityHeatLogger.info('创建一个伸缩组名为'+ test_heat.name) try: test_heat.id=self._heatClient.creatHeat(self._test_heat_net_id, self._test_heat_subnet_cidr, self._test_image_id, self._readConfig.base.test_image_name, self._test_heat_flavor_id, self._test_heat_flavor_name, self._password, self._default_secgroup_id, self._max_computes, self._min_computes, self._alarm_type, self._max_alarmvalue, self._min_alarmvalue, self._heat_templatepath, heatName) except Exception as e: self._loggers.stabilityHeatLogger.info('创建一个伸缩组名为' + test_heat.name + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_heatCompute(test_heat) def getStabilityheatAccountResource(self): return self._accountResource
class InitResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.basebench_os_tenant_name self._os_project_name = self._readConfig.accounts.basebench_os_project_name self._os_username = self._readConfig.accounts.basebench_os_username self._os_password = self._readConfig.accounts.basebench_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.basebenchLogger) self._accountResource = self._init.initAccountResource() self._test_fio_router_name = 'basebench_fio_router' self._test_iperf_router_name = 'basebench_iperf_router' self._test_unixbench_router_name = 'basebench_unixbench_router' self._user_data_path = 'userdata/user_data' self._test_fio_net_name = 'basebench_fio_net' self._test_fio_subnet_cidr = '192.168.50.0/24' self._test_iperf_net1_name = 'basebench_iperf_net1' self._test_iperf_subnet1_cidr = '192.168.70.0/24' self._test_iperf_net2_name = 'basebench_iperf_net2' self._test_iperf_subnet2_cidr = '192.168.80.0/24' self._test_unixbench_net_name = 'basebench_unixbench_net' self._test_unixbench_subnet_cidr = '192.168.60.0/24' self._loggers.basebenchLogger.info('===初始化基准测试基础资源===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.basebenchLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.basebenchLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._loggers.basebenchLogger.info('初始化可用域' + self._readConfig.base.zone_names) self._zone_names = self._readConfig.base.zone_names.split('||') #判断需要测试的类型 if self._readConfig.executeTest.is_basebench_test_fio.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化fio资源===') self._initFio() if self._readConfig.executeTest.is_basebench_test_unixbench.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化unixbench资源===') self._initUnixbench() if self._readConfig.executeTest.is_basebench_test_iperf.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化iperf资源===') self._initIperf() self._loggers.basebenchLogger.info( '将测试初始化资源写入到文件dbs/basebenchTestAccountResource.dbs') FileTool.writeObjectIntoFile(self._accountResource, 'dbs/basebenchTestAccountResource.dbs') 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, e: self._loggers.basebenchLogger.error('创建网络' + test_fio_net.name + '失败!' + '\r\n' + e.message) 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, e: self._loggers.basebenchLogger.error('初始化fio路由器' + test_fio_router.name + '失败!' + '\r\n' + e.message)
class InitMemtesterResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_memtester_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_memtester_os_project_name self._os_username = self._readConfig.accounts.stability_memtester_os_username self._os_password = self._readConfig.accounts.stability_memtester_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityMemtesterLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_memtester_router' self._user_data_path = 'userdata/user_data' self._test_memtester_net_name = 'basebench_memtester_net' self._test_memtester_subnet_cidr = '192.168.50.0/24' self._loggers.stabilityMemtesterLogger.info( '===初始化稳定性测试基础资源[memtester账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilityMemtesterLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityMemtesterLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') #判断是否进行memtester测试 if self._readConfig.executeTest.is_stability_test_memtester.lower( ) == 'true': self._loggers.stabilityMemtesterLogger.info( '===开始初始化稳定性测试memtester资源===') self._initMemtester() self._loggers.stabilityMemtesterLogger.info( '将测试初始化资源写入到文件dbs/stabilityMemtesterTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityMemtesterTestAccountResource.dbs') def _initMemtester(self): """ 根据memtester所需要测试,创建云主机 :return: """ self._loggers.stabilityMemtesterLogger.info('初始化memtester测试的云主机规格') self._test_memtester_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_memtester_flavor) self._loggers.stabilityMemtesterLogger.info( '初始化memtester网络资源,创建名为' + self._test_memtester_net_name + '的网络') test_memtester_net = Net() test_memtester_net.name = StrTool.addUUID( self._test_memtester_net_name) test_memtester_net.cidr = self._test_memtester_subnet_cidr try: test_memtester_net.id = self._openstackClient.createNetwork( test_memtester_net.name, test_memtester_net.cidr) except Exception, e: self._loggers.stabilityMemtesterLogger.error( '创建网络' + test_memtester_net.name + '失败!' + '\r\n' + e.message) self._test_memtester_net_id = test_memtester_net.id self._loggers.stabilityMemtesterLogger.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, e: self._loggers.stabilityMemtesterLogger.error('创建路由器' + test_router.name + '失败!' + '\r\n' + e.message)
class InitResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.basebench_os_tenant_name self._os_project_name = self._readConfig.accounts.basebench_os_project_name self._os_username = self._readConfig.accounts.basebench_os_username self._os_password = self._readConfig.accounts.basebench_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.basebenchLogger) self._accountResource = self._init.initAccountResource() self._test_fio_router_name = 'basebench_fio_router' self._test_iperf_router_name = 'basebench_iperf_router' self._test_unixbench_router_name = 'basebench_unixbench_router' self._user_data_path = 'userdata/user_data' self._test_fio_net_name = 'basebench_fio_net' self._test_fio_subnet_cidr = '192.168.50.0/24' self._test_iperf_net1_name = 'basebench_iperf_net1' self._test_iperf_subnet1_cidr = '192.168.70.0/24' self._test_iperf_net2_name = 'basebench_iperf_net2' self._test_iperf_subnet2_cidr = '192.168.80.0/24' self._test_unixbench_net_name = 'basebench_unixbench_net' self._test_unixbench_subnet_cidr = '192.168.60.0/24' self._loggers.basebenchLogger.info('===初始化基准测试基础资源===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.basebenchLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.basebenchLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._loggers.basebenchLogger.info('初始化可用域' + self._readConfig.base.zone_names) self._zone_names = self._readConfig.base.zone_names.split('||') #判断需要测试的类型 if self._readConfig.executeTest.is_basebench_test_fio.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化fio资源===') self._initFio() if self._readConfig.executeTest.is_basebench_test_unixbench.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化unixbench资源===') self._initUnixbench() if self._readConfig.executeTest.is_basebench_test_iperf.lower( ) == 'true': self._loggers.basebenchLogger.info('===开始初始化iperf资源===') self._initIperf() self._loggers.basebenchLogger.info( '将测试初始化资源写入到文件dbs/basebenchTestAccountResource.dbs') FileTool.writeObjectIntoFile(self._accountResource, 'dbs/basebenchTestAccountResource.dbs') 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 _initUnixbench(self): """ 根据unixbench所需要测试,设置要测试的网络/云主机名 :return: """ self._loggers.basebenchLogger.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) except Exception as e: self._loggers.basebenchLogger.error('创网络' + self._test_unixbench_net_name + '失败!' + '\r\n' + e.args.__str__()) self._unixbench_net_id = test_unixbench_net.id self._loggers.basebenchLogger.info('初始化unixbench路由器资源,创建名为' + self._test_unixbench_router_name + '的路由器') test_unixbench_router = Router() test_unixbench_router.name = StrTool.addUUID( self._test_unixbench_router_name) try: test_unixbench_router.id = self._openstackClient.createRouter( test_unixbench_router.name, self._admin_float_net_id) except Exception as e: self._loggers.basebenchLogger.error('初始化unixbench路由器' + test_unixbench_router.name + '失败!' + '\r\n' + e.args.__str__()) self._loggers.basebenchLogger.info('将unixbench网络' + test_unixbench_net.name + '绑定到路由器' + test_unixbench_router.name) try: test_unixbench_net_subnet_id = self._openstackClient.getSubNetId( self._unixbench_net_id) self._openstackClient.addRouterInterface( test_unixbench_router.id, test_unixbench_net_subnet_id) test_unixbench_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.basebenchLogger.error('将unixbench网络' + test_unixbench_net.name + '绑定到路由器' + test_unixbench_router.name + '失败' + '\r\n' + e.args.__str__()) self._accountResource.add_net(test_unixbench_net) self._accountResource.add_router(test_unixbench_router) self._loggers.basebenchLogger.info('初始化unixbench测试的云主机') test_unixbench_flavor_types = self._readConfig.executeTest.basebench_test_unixbench_flavors.split( '||') for test_unixbench_flavor_type in test_unixbench_flavor_types: self._loggers.basebenchLogger.info('初始化unixbench测试的云主机规格') self._test_unixbench_flavor_id = getFlavorId( self._accountResource.get_flavors(), test_unixbench_flavor_type) computeName = StrTool.addUUID('basebench_unixbench_' + test_unixbench_flavor_type) testType = 'basebench_unixbench_' + test_unixbench_flavor_type # 申请一个浮动ip test_unixbench_floatIp = FloatIp() self._loggers.basebenchLogger.info('申请一个浮动ip') try: test_unixbench_floatIp.ip = self._openstackClient.getFloatIp( self._admin_float_net_id) test_unixbench_floatIp.id = self._openstackClient.getFloatId( test_unixbench_floatIp.ip) self._loggers.basebenchLogger.info('申请到一个浮动ip:' + test_unixbench_floatIp.ip) except Exception as e: self._loggers.basebenchLogger.error('申请浮动ip失败' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_unixbench_floatIp) # 启动云主机 test_unixbench_compute = Compute() test_unixbench_compute.name = computeName test_unixbench_compute.testType = testType self._loggers.basebenchLogger.info('启动云主机' + test_unixbench_compute.name) try: test_unixbench_compute.id = self._novaClient.bootCompute( computeName, self._test_unixbench_flavor_id, self._test_image_id, self._unixbench_net_id, self._default_secgroup_id, random.choice(self._zone_names), self._user_data_path) except Exception as e: self._loggers.basebenchLogger.error( '启动云主机' + test_unixbench_compute.name + '失败!' + '\r\n' + e.args.__str__()) # 绑定浮动ip self._loggers.basebenchLogger.info('为云主机' + test_unixbench_compute.name + '绑定浮动ip:' + test_unixbench_floatIp.ip) try: is_add_succ = self._novaClient.addFloatForCompute( test_unixbench_compute.id, test_unixbench_floatIp.ip) if is_add_succ: test_unixbench_compute.float_ip = test_unixbench_floatIp.ip except Exception as e: self._loggers.basebenchLogger.error( '为云主机' + test_unixbench_compute.name + '绑定浮动ip:' + test_unixbench_floatIp.ip + '失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_unixbenchCompute(test_unixbench_compute) self._accountResource.add_compute(test_unixbench_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 getBasebenchTestAccountResource(self): return self._accountResource
class InitSysbenchResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name=self._readConfig.accounts.stability_sysbench_os_tenant_name self._os_project_name=self._readConfig.accounts.stability_sysbench_os_project_name self._os_username =self._readConfig.accounts.stability_sysbench_os_username self._os_password = self._readConfig.accounts.stability_sysbench_os_password self._init=Init(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password,self._loggers.stabilitySysbenchLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_sysbench_router' self._user_data_path='userdata/user_data' self._test_sysbench_net_name = 'basebench_sysbench' self._test_sysbench_subnet_cidr = '192.168.70.0/24' self._loggers.stabilitySysbenchLogger.info('===初始化稳定性测试基础资源[sysbench账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilitySysbenchLogger.info('初始化命令行客户端') self._openstackClient=OpenstackClient(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password) self._novaClient=NovaClient(self._os_project_name,self._os_username,self._os_password) self._cinderClient=CinderClient(self._os_tenant_name,self._os_project_name,self._os_username,self._os_password) self._troveClient = TroveClient(self._os_tenant_name, self._os_project_name, self._os_username,self._os_password) self._loggers.stabilitySysbenchLogger.info('初始化默认安全组、测试浮动ip、测试云主机镜像') self._default_secgroup_id=getDefaultSecGroupId(self._accountResource.get_secgroups(),self._readConfig.base.default_secgroup_name) self._admin_float_net_id=getAdminFloatNetId(self._accountResource.get_adminNets(),self._readConfig.base.admin_float_net_name) self._test_image_id=getTestImageId(self._accountResource.get_images(),self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') #判断需要测试的类型 if self._readConfig.executeTest.is_stability_test_memtester.lower()=='true': self._loggers.stabilitySysbenchLogger.info('===开始初始化稳定性测试sysbench资源===') self._initSysbench() self._loggers.stabilitySysbenchLogger.info('将测试初始化资源写入到文件dbs/stabilitySysbenchTestAccountResource.dbs') FileTool.writeObjectIntoFile(self._accountResource,'dbs/stabilitySysbenchTestAccountResource.dbs') 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) def getStabilitySysbenchAccountResource(self): return self._accountResource
class InitIperfResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_iperf_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_iperf_os_project_name self._os_username = self._readConfig.accounts.stability_iperf_os_username self._os_password = self._readConfig.accounts.stability_iperf_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityIperfLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_iperf_router' self._user_data_path = 'userdata/user_data' self._test_iperf_net1_name = 'basebench_iperf_net1' self._test_iperf_subnet1_cidr = '192.168.70.0/24' self._test_iperf_net2_name = 'basebench_iperf_net2' self._test_iperf_subnet2_cidr = '192.168.80.0/24' self._loggers.stabilityIperfLogger.info('===初始化稳定性测试基础资源[iperf账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilityIperfLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityIperfLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') #判断需要测试的类型 if self._readConfig.executeTest.is_stability_test_iperf.lower( ) == 'true': self._loggers.stabilityIperfLogger.info('===开始初始化稳定性测试iperf资源===') self._initIperf() self._loggers.stabilityIperfLogger.info( '将测试初始化资源写入到文件dbs/stabilityIperfTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityIperfTestAccountResource.dbs') def _initIperf(self): """ 初始化iperf测试必须有的资源 :return: """ self._loggers.stabilityIperfLogger.info('初始化iperf测试的云主机规格') self._test_iperf_flavor_id = getFlavorId( self._accountResource.get_flavors(), self._readConfig.executeTest.stability_test_iperf_flavor) self._loggers.stabilityIperfLogger.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.stabilityIperfLogger.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.stabilityIperfLogger.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.stabilityIperfLogger.error('创建路由器' + self._router_name + '失败!' + '\r\n' + e.args.__str__()) self._router_id = test_router.id self._loggers.stabilityIperfLogger.info('将iperf网络' + self._test_iperf_net1_name + '绑定到路由器' + self._router_name) try: test_iperf_net1_subnet_id = self._openstackClient.getSubNetId( self._test_iperf_net1_id) self._openstackClient.addRouterInterface( self._router_id, test_iperf_net1_subnet_id) test_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.stabilityIperfLogger.error( '将iperf网络' + self._test_iperf_net1_name + '绑定到路由器' + self._router_name + '失败!' + e.args.__str__()) self._loggers.stabilityIperfLogger.info('将iperf网络' + self._test_iperf_net2_name + '绑定到路由器' + self._router_name) try: test_iperf_net2_subnet_id = self._openstackClient.getSubNetId( self._test_iperf_net2_id) self._openstackClient.addRouterInterface( self._router_id, test_iperf_net2_subnet_id) test_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.stabilityIperfLogger.error( '将iperf网络' + self._test_iperf_net2_name + '绑定到路由器' + self._router_name + '失败!' + e.args.__str__()) self._accountResource.add_net(test_iperf_net1) self._accountResource.add_net(test_iperf_net2) self._accountResource.add_router(test_router) # 获取可用域 if len(self._zone_names) < 2: self._loggers.stabilityIperfLogger.error('可用域' + self._zone_names + '少于两个无法进行iperf测试') return for i in range( int(self._readConfig.executeTest.stability_test_iperf_group_num )): self._loggers.stabilityIperfLogger.info('初始化iperf测试的云主机') # 启动一组iperf测试云主机,不同网段 self._loggers.stabilityIperfLogger.info('启动一组iperf测试的云主机,在不同网段') iperf_computePair = [] for j in range(2): #申请一个浮动ip self._loggers.stabilityIperfLogger.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.stabilityIperfLogger.info('申请到一个浮动ip:' + test_floatIp.ip) except Exception as e: self._loggers.stabilityIperfLogger.error('申请浮动ip失败!' + '\r\n' + e.args.__str__()) self._accountResource.add_floatIp(test_floatIp) zone = None net_id = None tmp_testType = 'iperf_two_net' name = None #第一台 if j == 0: 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 as e: self._loggers.stabilityIperfLogger.error( '启动云主机' + test_compute.name + '失败!' + '\r\n' + e.args.__str__()) #绑定浮动ip self._loggers.stabilityIperfLogger.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.stabilityIperfLogger.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 getStabilityIperfAccountResource(self): return self._accountResource
class InitObjectStoreResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_objstore_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_objstore_os_project_name self._os_username = self._readConfig.accounts.stability_objstore_os_username self._os_password = self._readConfig.accounts.stability_objstore_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityObjstoreLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_stablity_oss_router' self._user_data_path = 'userdata/user_data' self._oss_net_name = 'basebench_oss_stable_net' self._oss_subnet_cidr = '192.168.50.0/24' self._loggers.stabilityObjstoreLogger.info('===初始化对象存储稳定性测试资源===') self._initResource() def _initResource(self): """ """ self._loggers.stabilityObjstoreLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityObjstoreLogger.info('初始化默认安全组、外部网络、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') if self._readConfig.executeTest.is_stability_test_objstore.lower( ) == 'true': self._loggers.stabilityObjstoreLogger.info( '===开始初始化对象存储稳定性测试资源===') self._initObjectstore() self._loggers.stabilityObjstoreLogger.info( '将测试初始化资源写入到文件dbs/stabilityObjectStorageTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityObjectStorageTestAccountResource.dbs') 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 getStableObjectstoreResource(self): return self._accountResource
class InitFioResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_fio_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_fio_os_project_name self._os_username = self._readConfig.accounts.stability_fio_os_username self._os_password = self._readConfig.accounts.stability_fio_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityFioLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_stablity_fio_router' self._user_data_path = 'userdata/user_data' self._fio_net_name = 'basebench_fio_stable_net' self._fio_subnet_cidr = '192.168.50.0/24' self._loggers.stabilityFioLogger.info('===初始化fio稳定性测试资源===') self._initResource() def _initResource(self): """ 初始化fio资源 公共资源初始化 :return: """ self._loggers.stabilityFioLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityFioLogger.info('初始化默认安全组、外部网络、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') if self._readConfig.executeTest.is_stability_test_fio.lower( ) == 'true': self._loggers.stabilityFioLogger.info('===开始初始化fio稳定性测试资源===') self._initFio() self._loggers.stabilityFioLogger.info( '将测试初始化资源写入到文件dbs/stabilityFioTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityFioTestAccountResource.dbs') 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 getStabilityFioAccountResource(self): return self._accountResource
class InitLoadbalancerResource: def __init__(self): self._readConfig = ReadConfig() self._loggers = Loggers() self._os_tenant_name = self._readConfig.accounts.stability_loadbalancer_os_tenant_name self._os_project_name = self._readConfig.accounts.stability_loadbalancer_os_project_name self._os_username = self._readConfig.accounts.stability_loadbalancer_os_username self._os_password = self._readConfig.accounts.stability_loadbalancer_os_password self._init = Init(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password, self._loggers.stabilityLoadbalancerLogger) self._accountResource = self._init.initAccountResource() self._router_name = 'basebench_loadbalancer_router' self._user_data_path = 'userdata/user_data' self._test_loadbalancer_net_name = 'basebench_loadbalancer_net' self._test_loadbalancer_subnet_cidr = '192.168.80.0/24' self._test_loadbalancer_subnet_cidr = '192.168.80.0/24' self._loggers.stabilityLoadbalancerLogger.info( '===初始化稳定性测试基础资源[loadbalancer账号]===') self._initResource() def _initResource(self): """ 公共资源初始化 :return: """ self._loggers.stabilityLoadbalancerLogger.info('初始化命令行客户端') self._openstackClient = OpenstackClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._novaClient = NovaClient(self._os_project_name, self._os_username, self._os_password) self._cinderClient = CinderClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loadbalancerClient = LoadbalancerClient(self._os_tenant_name, self._os_project_name, self._os_username, self._os_password) self._loggers.stabilityLoadbalancerLogger.info('初始化默认安全组、测试镜像、测试镜像') self._default_secgroup_id = getDefaultSecGroupId( self._accountResource.get_secgroups(), self._readConfig.base.default_secgroup_name) self._admin_float_net_id = getAdminFloatNetId( self._accountResource.get_adminNets(), self._readConfig.base.admin_float_net_name) self._test_image_id = getTestImageId( self._accountResource.get_images(), self._readConfig.base.test_image_name) self._zone_names = self._readConfig.base.zone_names.split('||') #判断需要测试的类型 if self._readConfig.executeTest.is_stability_test_loadbalancer.lower( ) == 'true': self._loggers.stabilityLoadbalancerLogger.info( '===开始初始化稳定性测试loadbalancer资源===') self._initLoadbalancer() self._loggers.stabilityLoadbalancerLogger.info( '将测试初始化资源写入到文件dbs/stabilityLoadbalancerTestAccountResource.dbs') FileTool.writeObjectIntoFile( self._accountResource, 'dbs/stabilityLoadbalancerTestAccountResource.dbs') 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) def getStabilityLoadbalancerAccountResource(self): return self._accountResource