Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
0
 def __init__(self, os_tenant_name, os_project_name, os_username,
              os_password):
     self._readConfig = ReadConfig()
     self._os_tenant_name = os_tenant_name
     self._os_project_name = os_project_name
     self._os_username = os_username
     self._os_password = os_password
     self._novaClient = NovaClient(self._os_project_name, self._os_username,
                                   self._os_password)
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    def __init__(self,account_dict):
        self._os_tenant_name=account_dict['os_tenant_name']
        self._os_project_name=account_dict['os_project_name']
        self._os_project_id = account_dict['os_project_id']
        self._os_username=account_dict['os_username']
        self._os_userid=account_dict['os_userid']
        self._os_password=account_dict['os_password']

        self._novaClient=NovaClient(self._os_project_name,self._os_username,self._os_password)
        self._openstackClient=OpenstackClient(self._os_tenant_name,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._keystoneClient=KeystoneClient()
        self._troveClient=TroveClient(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._objectstoreClient = ObjectStoreClient()
Ejemplo n.º 6
0
class DeleteAllComputes:
    def __init__(self, os_tenant_name, os_project_name, os_username,
                 os_password):
        self._readConfig = ReadConfig()
        self._os_tenant_name = os_tenant_name
        self._os_project_name = os_project_name
        self._os_username = os_username
        self._os_password = os_password
        self._novaClient = NovaClient(self._os_project_name, self._os_username,
                                      self._os_password)

    def deleteComputes(self):
        """
        删除所有的云主机
        :return:
        """
        tmp_compute_ids = self._novaClient.getTenantsComputeId(
            self._readConfig.tools.cleanup_keyword)
        if tmp_compute_ids:
            compute_ids = tmp_compute_ids.split()
            self._novaClient.deleteAllCompute(compute_ids)
        return True
Ejemplo n.º 7
0
    def __init__(self, os_tenant_name, os_project_name, os_username,
                 os_password, logger):
        self._readConfig = ReadConfig()
        self._logger = logger
        self._logger.info('===开始初始化账号' + os_username + '公共资源===')
        self._os_tenant_name = os_tenant_name
        self._os_project_name = os_project_name
        self._os_username = os_username
        self._os_password = os_password

        self._accountResource = AccountResource()

        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._keystoneClient = KeystoneClient()
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
class Init:
    def __init__(self, os_tenant_name, os_project_name, os_username,
                 os_password, logger):
        self._readConfig = ReadConfig()
        self._logger = logger
        self._logger.info('===开始初始化账号' + os_username + '公共资源===')
        self._os_tenant_name = os_tenant_name
        self._os_project_name = os_project_name
        self._os_username = os_username
        self._os_password = os_password

        self._accountResource = AccountResource()

        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._keystoneClient = KeystoneClient()

    def initAccountResource(self):
        """
        初始化一个账号,并设置必要的公共资源
        :return:
        """
        self._logger.info('创建账号' + self._os_username)
        test_account = Account()
        test_account.os_tenant_name = self._os_tenant_name
        test_account.os_project_name = self._os_project_name
        test_account.os_username = self._os_username
        test_account.os_password = self._os_password
        try:
            project_id, user_id = self._keystoneClient.createAccount(
                self._os_project_name, self._os_username, self._os_password)
            test_account.os_project_id = project_id
            test_account.os_userid = user_id
            self._keystoneClient.setAccountBucketsQuota(500, project_id)
            #openstack O版本无需配置
            #self._keystoneClient.setAccountImageQuota(500,100,project_id)
            self._keystoneClient.setAccountNetworkQuota(
                project_id, 100, 100, 100, 100, 100)
            self._keystoneClient.setInstanceStorageQuota(
                project_id, 65535, 100, 1024000, 100, 100, 327675)
            self._keystoneClient.setObjectStoreQuota(5497558138880, project_id)
        except Exception as e:
            self._logger.error('创建账号' + self._os_username + '失败!' + '\r\n' +
                               e.args.__str__())
        self._accountResource.add_account(test_account)

        self._logger.info('初始化默认安全组资源' +
                          self._readConfig.base.default_secgroup_name)
        default_secgroup = SecGroup()
        default_secgroup.name = self._readConfig.base.default_secgroup_name
        try:
            default_secgroup.id = self._openstackClient.getSecGroupId(
                self._readConfig.base.default_secgroup_name)
            # 将安全组tcp规则放开
            self._logger.info('开放安全组' + default_secgroup.name + '的tcp规则')
            self._openstackClient.addAllowTcpRule(default_secgroup.id)
            # 将安全组icmp规则放开
            self._logger.info('开放安全组' + default_secgroup.name + '的icmp规则')
            self._openstackClient.addAllowIcmpRule(default_secgroup.id)
        except Exception as e:
            self._logger.error('初始化安全组资源' +
                               self._readConfig.base.default_secgroup_name +
                               '失败!' + '\r\n' + e.args.__str__())
        self._accountResource.add_secgroup(default_secgroup)

        #账户加入外部网络
        self._logger.info('初始化外部网络资源' +
                          self._readConfig.base.admin_float_net_name)
        admin_float_net = AdminNet()
        admin_float_net.name = self._readConfig.base.admin_float_net_name
        try:
            admin_float_net.id = self._openstackClient.getNetId(
                self._readConfig.base.admin_float_net_name)
        except Exception as e:
            self._logger.error('初始化外部网络' +
                               self._readConfig.base.admin_float_net_name +
                               '资源失败!' + '\r\n' + e.args.__str__())
        self._accountResource.add_adminNet(admin_float_net)

        #账户里加入云主机类型
        self._logger.info('初始化云主机规格资源' +
                          self._readConfig.base.flavor_type_names)
        flavor_types = self._readConfig.base.flavor_type_names.split('||')
        for flavor_type_str in flavor_types:
            tmp_flavor_type = flavor_type_str.split('&')
            flavor_type = Flavor()
            flavor_type.type = tmp_flavor_type[0]
            flavor_type.name = tmp_flavor_type[1]
            try:
                flavor_type.id = self._novaClient.getFlavorId(flavor_type.name)
            except Exception as e:
                self._logger.error('初始化云主机规格资源' + flavor_type_str + '失败!' +
                                   '\r\n' + e.args.__str__())
            self._accountResource.add_flavor(flavor_type)

        #账户里加入镜像
        self._logger.info('初始化测试镜像资源' + self._readConfig.base.test_image_name)
        test_image = Image()
        test_image.name = self._readConfig.base.test_image_name
        try:
            test_image.id = self._novaClient.getImageId(
                self._readConfig.base.test_image_name)
        except Exception as e:
            self._logger.error('初始化测试镜像资源' +
                               self._readConfig.base.test_image_name + '失败!' +
                               '\r\n' + e.args.__str__())
        self._accountResource.add_image(test_image)

        #账户里加入磁盘类型
        self._logger.info('初始化磁盘类型资源' +
                          self._readConfig.base.volume_type_names)
        volume_types = self._readConfig.base.volume_type_names.split('||')
        for volume_type_str in volume_types:
            volume_type = VolumeType()
            tmp_volume_type = volume_type_str.split('&')
            volume_type.type = tmp_volume_type[0]
            volume_type.name = tmp_volume_type[1]
            try:
                volume_type.id = self._cinderClient.getVolumeTypeId(
                    volume_type.name)
            except Exception as e:
                self._logger.error('初始化磁盘类型资源' + volume_type_str + '失败!' +
                                   '\r\n' + e.args.__str__())
            self._accountResource.add_volumeType(volume_type)

        #账户里加入可用域
        self._logger.info('初始化可用域资源')
        self._accountResource.add_zone(
            self._readConfig.base.zone_names.split('||'))

        return self._accountResource
Ejemplo n.º 15
0
class Free:
    def __init__(self,account_dict):
        self._os_tenant_name=account_dict['os_tenant_name']
        self._os_project_name=account_dict['os_project_name']
        self._os_project_id = account_dict['os_project_id']
        self._os_username=account_dict['os_username']
        self._os_userid=account_dict['os_userid']
        self._os_password=account_dict['os_password']

        self._novaClient=NovaClient(self._os_project_name,self._os_username,self._os_password)
        self._openstackClient=OpenstackClient(self._os_tenant_name,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._keystoneClient=KeystoneClient()
        self._troveClient=TroveClient(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._objectstoreClient = ObjectStoreClient()

    def freeCompute(self,computes_array):
        compute_ids=[]
        for compute in computes_array:
            if compute['id']:
                compute_ids.append(compute['id'])
        self._novaClient.deleteAllCompute(compute_ids)

    def freeVolume(self,volumes_array):
        volume_ids=[]
        for volume in volumes_array:
            if volume['id']:
                volume_ids.append(volume['id'])
        self._cinderClient.deleteAllVolume(volume_ids)

    def freeLoadbalancer(self,loadbalancers_array):
        loadbalancer_ids=[]
        for loadbalancer in loadbalancers_array:
            if loadbalancer['id']:
                loadbalancer_ids.append(loadbalancer['id'])
        self._loadbalancerClient.deleteLoadbalancer(loadbalancer_ids)

    def freeRouter(self,routers_array):
        router_ids=[]
        for router in routers_array:
            router_id=router['id']
            if router_id:
                router_ids.append(router_id)
            router_subnet_ids=router['subnet_ids']
            for router_subnet_id in router_subnet_ids:
                if router_subnet_id:
                    self._openstackClient.removeRouterInterface(router_id,router_subnet_id)
        self._openstackClient.deleteAllRouter(router_ids)

    def freeNet(self,nets_array):
        net_ids=[]
        subnetPort_ids=[]
        for net in nets_array:
            if net['id']:
                subnet_id=self._openstackClient.getSubNetId(net['id'])
                subnetPort_ids=subnetPort_ids+self._openstackClient.getSubnetPortIds(subnet_id)
                net_ids.append(net['id'])
        self._openstackClient.deleteSubnetPorts(subnetPort_ids)
        self._openstackClient.deleteAllNet(net_ids)

    def freeFloatIp(self,floatIps_array):
        floatIp_ids=[]
        for floatIp in floatIps_array:
            if floatIp['id']:
                floatIp_ids.append(floatIp['id'])
        self._openstackClient.deleteAllFloatIp(floatIp_ids)

    def freeSecgroup(self,secgruop_array):
        pass

    def freeSysbench(self,sysbench_array):
        sysbench1_ids=[]
        sysbench_ids = []
        for sysbench1 in sysbench_array:
            if sysbench1[1]:
                sysbench1_ids.append(sysbench1[1])
        for sysbench in sysbench1_ids:
            if sysbench['id']:
                sysbench_ids.append(sysbench['id'])
        self._troveClient.deleteAllTrove(sysbench_ids)

    def freeHeat(self,heat_array):
        heat_ids=[]
        for floatIp in heat_array:
            if floatIp['id']:
                heat_ids.append(floatIp['id'])
        self._heatClient.deleteAllHeat(heat_ids)

    def freeObejectstore(self):
        if not self._os_project_id:
            return False
        self._objectstoreClient.deleteAllBuckets(self._os_project_id)

    def freeAccount(self):
        if not self._os_userid or not self._os_project_id:
            return False
        self._keystoneClient.deleteAccount(self._os_userid.encode('utf-8'),self._os_project_id.encode('utf-8'))
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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