コード例 #1
0
                    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, e:
                    self._loggers.basebenchLogger.error('启动云主机' +
                                                        test_compute.name +
                                                        '失败!' + '\r\n' +
                                                        e.message)

                #绑定浮动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, e:
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
                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, e:
                    self._loggers.stabilityLoadbalancerLogger.error(
                        '为后端服务器' + member_compute.name + '绑定浮动ip:' +
                        member_floatIp.ip + '失败!' + '\r\n' + e.message)
                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)