示例#1
0
def test_process(data, region, text='Hello', full_data=False):
    print "======= service data payload is ========"
    print data
    app_name = data['service_name']
    test_flag = True

    ret_create = create_service(app_name,
                                data,
                                service_detail=text,
                                region=region)
    if not ret_create["success"]:
        print "create service failed :{}".format(ret_create)
        delete_app(app_name, region)
        return add_to_total_dict(ret_create, app_name)

    logger.info(region + " Creating a service %fs finished\n\n" %
                (ret_create["total"]))
    sleep(10)

    ret_metrics = get_metrics(app_name)
    if not ret_metrics['success']:
        test_flag = False
    ret_exec = exec_feature(app_name, region, settings.CLAAS_NAMESPACE)
    if not ret_exec['success']:
        test_flag = False

    ret_stop = stop_app(app_name)
    if not ret_stop["success"]:
        delete_app(app_name, region)
        return add_to_total_dict(ret_stop, app_name)

    logger.info(region +
                " Stop the service %s finished\n\n" % ret_stop["total"])
    sleep(10)

    ret_restart = start_app(app_name, num=1)
    if not ret_restart["success"]:
        delete_app(app_name, region)
        return add_to_total_dict(ret_restart, app_name)

    logger.info(region +
                " Start the service %s finished\n\n" % ret_restart["total"])
    sleep(1)

    scale_up = update_service(app_name, num=2, size="XS", service_detail=text)
    if not scale_up["success"]:
        delete_app(app_name, region)
        return add_to_total_dict(scale_up, app_name)

    scale_down = update_service(app_name,
                                num=1,
                                size="XS",
                                service_detail=text)
    if not scale_down["success"]:
        delete_app(app_name, region)
        return add_to_total_dict(scale_down, app_name)

    logger.info(region +
                " Redeploy the service %s finished\n\n" % scale_down["total"])

    ret_logs = get_logs(app_name)
    if not ret_logs['success']:
        test_flag = False

    logger.info(region + " begin to delete service")
    ret7 = delete_app(app_name, region)
    if not ret7["success"]:
        delete_app(app_name, region)
        return add_to_total_dict(ret7, app_name)

    logger.info(region + " Delete the service %s finished\n\n" % ret7["total"])

    if not full_data:
        obj = {
            "success": test_flag,
            "{} create".format(app_name): ret_create["total"],
            "{} get logs".format(app_name): ret_logs["total"],
            "{} get metrics".format(app_name): ret_metrics["total"],
            "{} exec_feature".format(app_name): ret_exec["total"],
            "{} get stop service".format(app_name): ret_stop["total"],
            "{} get restart service".format(app_name): ret_restart["total"],
            "{} scale up service".format(app_name): scale_up["total"],
            "{} scale down service".format(app_name): scale_down["total"],
            "{} delete".format(app_name): ret7["total"],
        }
    else:
        obj = {
            "success": test_flag,
            "{} create".format(app_name): ret_create,
            "{} get logs".format(app_name): ret_logs,
            "{} get metrics".format(app_name): ret_metrics,
            "{} exec_feature".format(app_name): ret_exec,
            "{} get stop service".format(app_name): ret_stop,
            "{} get restart service".format(app_name): ret_restart,
            "{} scale up service".format(app_name): scale_up,
            "{} scale down service".format(app_name): scale_down,
            "{} delete".format(app_name): ret7,
        }

    return obj
示例#2
0
    def create_k8s_host_app__k8s_applications(self):
        if self.app_region is not None and 'glusterfs' in (
            (self.region_data)['data']['features']['volume']['features']):
            test_flag = True
            ret_env = create_envs(self.app_k8s_env_file)
            self.assert_successful(ret_env)

            ret_volume = create_volume(self.app_k8s_gfs_volume, 'glusterfs',
                                       None)
            self.assert_successful(ret_volume)
            volume_id = ret_volume['volume_id']

            if settings.ENV == 'private':
                yaml_content = "{}:\n alauda_lb: ALB\n net: host\n image: {}/{}:{}\n" \
                               "size: XXS\n ports:\n - '{}:80:80/http'\n number :1\n"\
                               "env_file: {}\n volumes\n - {}:/var/\n" \
                    .format(self.app_host_service_name, get_registry_info().get('registry_url', None),
                            settings.PRIVATE_REPO, settings.IMAGE_TAG,
                            self.haproxy, self.app_k8s_env_file, self.app_k8s_gfs_volume)
            else:
                # APP yaml支持host模式服务,添加环境变量文件,添加gfs的volume
                yaml_content = "{}:\n alauda_lb: ALB\n ports:\n - '{}:81:81/http'\n" \
                               " image: {}/{}/hello-world:latest\n size: XXS\n net: host\n number: 1\n" \
                               " env_file: {}\n volumes:\n - {}:/var/\n" \
                    .format(self.app_host_service_name, self.haproxy, settings.REGISTRY_URL,
                            settings.CLAAS_NAMESPACE, self.app_k8s_env_file, self.app_k8s_gfs_volume)

            print('yaml_content:{}'.format(yaml_content))
            # self.create_app_action(self.app_k8s_name, yaml_content, self.app_region, 'ALB', self.haproxy, False)
            # 创建应用 会判断应用的最终状态,如果不是Running 直接返回
            ret1 = create_application(self.app_k8s_host_name,
                                      files_data=yaml_content,
                                      region=self.app_region)
            self.assert_successful(ret1)

            # 验证环境变量文件是否添加进去 失败可以继续后面测试
            ret4 = exec_feature(self.app_host_service_name,
                                self.namespace,
                                command="env",
                                commands_string="key=value",
                                app_name=self.app_k8s_host_name)
            if not ret4['success']:
                test_flag = False

            # 判断存储卷类型 不阻塞后面的测试
            ret6 = verify_volumes(self.app_host_service_name, volume_id,
                                  self.app_k8s_host_name)
            if not ret6['success']:
                test_flag = False

            # 判断是否有Metrics 不阻塞后面的测试
            ret7 = get_metrics(self.app_host_service_name,
                               self.app_k8s_host_name)
            if not ret7['success']:
                test_flag = False

            # check 服务的日志
            ret14 = get_logs(self.app_host_service_name,
                             app_name=self.app_k8s_host_name)
            if not ret14['success']:
                test_flag = False
            # 删除应用
            ret_delete = delete_application(self.app_k8s_host_name,
                                            self.app_region)
            self.assert_successful(ret_delete)
            result = {
                'success': test_flag,
                "create envfile": ret_env,
                "create gfs volume": ret_volume,
                "create application": ret1,
                "get service env": ret4,
                "get service volume type": ret6,
                "get service metrics": ret7,
                "get service log": ret14,
                "delete service": ret_delete
            }
            self.assert_successful(result)
            return {"success": True, "total": "All success"}

        else:
            return {
                "success": True,
                "total": "there is no alb region, skip the case"
            }
示例#3
0
    def create_k8s_flannel_app__k8s_applications(self):
        ''' create app with most alauda yaml features: environment|links|net|number|size|
        volumes|alauda_lb|amount_points|labels'''
        if self.app_region is not None:
            test_flag = True
            ret1 = create_configuration(self.k8s_app_config, "value",
                                        self.k8s_app_config_key)
            self.assert_successful(ret1)

            if settings.ENV == 'private':
                yaml_content = "{}:\n alauda_lb: ALB\n net: flannel\n image: {}/{}:{}\n number: 1\n" \
                               "size: XXS\n ports:\n - '{}:80:80/http'\n" \
                               " environment:\n - k8s_key=k8s-value\n - __ALAUDA_FILE_LOG_PATH__=/home/*.txt\n" \
                               " volumes:\n - /home/:/var/\n mount_points:\n - path: /home/abc\n   config: {}/{}\n" \
                               " labels:\n - 'constraint:node==ip:{}'" \
                    .format(self.app_flannel_service_name, get_registry_info().get('registry_url', None),
                            settings.PRIVATE_REPO, settings.IMAGE_TAG, self.haproxy,
                            self.k8s_app_config, self.k8s_app_config_key, self.k8s_ip_tag
                            )
            else:
                # APP yaml支持flannel模式服务,添加环境变量,添加配置文件,添加local的volume,指定日志文件,部署在指定的机器上
                yaml_content = "{}:\n alauda_lb: ALB\n ports:\n - '{}:80:80/http'\n" \
                               " image: {}/{}/hello-world:latest\n size: XXS\n net: flannel\n number: 1\n" \
                               " environment:\n - k8s_key=k8s-value\n - __ALAUDA_FILE_LOG_PATH__=/home/*.txt\n"\
                               " volumes:\n - /home/:/var/\n mount_points:\n - path: /home/abc\n   config: {}/{}\n"\
                               " labels:\n - 'constraint:node==ip:{}'"\
                    .format(self.app_flannel_service_name, self.haproxy, settings.REGISTRY_URL,
                            settings.CLAAS_NAMESPACE, self.k8s_app_config, self.k8s_app_config_key, self.k8s_ip_tag)

            print('yaml_content:{}'.format(yaml_content))
            # self.create_app_action(self.app_k8s_name, yaml_content, self.app_region, 'ALB', self.haproxy, False)
            #创建应用 会判断应用的最终状态,如果不是Running 直接返回
            ret1 = create_application(self.app_k8s_name,
                                      files_data=yaml_content,
                                      region=self.app_region)
            self.assert_successful(ret1)

            # 验证应用内的服务是否可以访问,失败不影响后续操作
            ret_access_service = access_service(self.app_flannel_service_name,
                                                self.haproxy,
                                                self.app_k8s_name)
            if not ret_access_service['success']:
                test_flag = False

            # 检查应用创建成功后yaml,失败后返回,因为会影响更新
            ret2 = get_yaml(self.app_k8s_name)
            if ret2['status'] != 200:
                test_flag = False
                ret2 = {
                    "success":
                    False,
                    "message":
                    "get application yaml failed, jakiro api error code {}, error:{}"
                    .format(ret2["status"], ret2["text"])
                }
            elif self.app_flannel_service_name not in ret2['text']:
                test_flag = False
                ret2 = {
                    "success":
                    False,
                    "message":
                    "service_name is {},not in yaml:{}".format(
                        self.app_flannel_service_name, ret2['text'])
                }
            else:
                update_yaml = ret2['text'].replace("XXS", "XS")
                ret2 = {"success": True, "total": ret2["total"]}
            self.assert_successful(ret2)
            # 检查应用的compose-yaml 失败后不影响后续操作
            ret3 = get_compose_yaml(self.app_k8s_name)
            if ret3['status'] != 200:
                test_flag = False
                ret3 = {
                    "success":
                    False,
                    "message":
                    "get application compose yaml failed, jakiro api error code {},error:{}"
                    .format(ret3['status'], ret3['text'])
                }
            elif self.app_flannel_service_name not in ret3['text']:
                test_flag = False
                ret3 = {
                    "success":
                    False,
                    "message":
                    "service_name is {},not in yaml:{}".format(
                        self.app_flannel_service_name, ret3['text'])
                }
            else:
                ret3 = {"success": True, "total": ret3["total"]}

            # 验证环境变量是否添加进去 失败可以继续后面测试
            ret4 = exec_feature(self.app_flannel_service_name,
                                self.namespace,
                                command="env",
                                commands_string="k8s_key=k8s-value",
                                app_name=self.app_k8s_name)
            if not ret4['success']:
                test_flag = False
            # 验证配置文件是否添加进去 失败可以继续后面测试
            ret5 = exec_feature(self.app_flannel_service_name,
                                self.namespace,
                                command="'cat /home/abc'",
                                commands_string="value",
                                app_name=self.app_k8s_name)
            if not ret5['success']:
                test_flag = False

            # 判断存储卷类型 不阻塞后面的测试
            ret6 = verify_volumes(self.app_flannel_service_name, "host_path",
                                  self.app_k8s_name)
            if not ret6['success']:
                test_flag = False

            # 判断是否有Metrics 不阻塞后面的测试
            ret7 = get_metrics(self.app_flannel_service_name,
                               self.app_k8s_name)
            if not ret7['success']:
                test_flag = False

            ret_stop = stop_application(self.app_k8s_name, self.app_region)
            self.assert_successful(ret_stop)

            ret_start = start_application(self.app_k8s_name, self.app_region)
            self.assert_successful(ret_start)
            #验证更新操作,失败直接返回
            ret_update = update_application(self.app_k8s_name,
                                            files_data=update_yaml,
                                            region=self.app_region)
            self.assert_successful(ret_update)

            # check 服务的日志
            ret14 = get_logs(self.app_flannel_service_name,
                             app_name=self.app_k8s_name)
            if not ret14['success']:
                test_flag = False
            # check 日志文件
            ret15 = get_logfile(self.app_flannel_service_name,
                                self.app_k8s_name)
            if not ret15['success']:
                test_flag = False
            #删除应用
            ret_delete = delete_application(self.app_k8s_name, self.app_region)
            self.assert_successful(ret_delete)
            result = {
                'success': test_flag,
                "create application": ret1,
                "access sercie ": ret_access_service,
                "get yaml": ret2,
                "get compose yaml": ret3,
                "get service env": ret4,
                "get service config": ret5,
                "get service volume type": ret6,
                "get service metrics": ret7,
                "stop application": ret_stop,
                "start application": ret_start,
                "update application": ret_update,
                "get service log": ret14,
                "get service logfile": ret15,
                "delete service": ret_delete
            }
            self.assert_successful(result)
            return {"success": True, "total": "All success"}

        else:
            return {
                "success": True,
                "total": "there is no alb region, skip the case"
            }
示例#4
0
    def k8s_flannel__k8s_service(self):
        # 创建flannel服务支持:环境变量,配置文件,local volume,日志文件,部署到指定机器
        if self.haproxy:
            test_flag = True
            ret1 = get_haproxy(self.haproxy)

            self.assert_successful(ret1)

            k8sFlannelData = data.ServiceData(
                self.k8s_flannel_service,
                self.namespace,
                settings.SERVICE_CLAAS_REGION[0],
                lb_type='haproxy',
                alb_name=self.haproxy,
                lb_id=ret1['haproxy_id'],
                node_tag=self.node_tag.split(":")[1],
                mipn_enabled=True)

            #创建服务支持 环境变量 local volume,配置文件,指定日志文件,部署在指定的机器上  block后面操作
            ret2 = create_service(self.k8s_flannel_service,
                                  k8sFlannelData.k8s_flannel_service(),
                                  settings.SERVICE_CLAAS_REGION[0])
            self.assert_successful(ret2)
            #验证服务是否可以访问 失败可以继续后面测试
            ret3 = access_service(self.k8s_flannel_service, self.haproxy)
            if not ret3['success']:
                test_flag = False
            #验证环境变量是否添加进去 失败可以继续后面测试
            ret4 = exec_feature(self.k8s_flannel_service,
                                self.namespace,
                                command="env",
                                commands_string="k8s_key=k8s_value")
            if not ret4['success']:
                test_flag = False
            #验证配置文件是否添加进去 失败可以继续后面测试
            ret5 = exec_feature(self.k8s_flannel_service,
                                self.namespace,
                                command="'cat /home/abc'",
                                commands_string="config")
            if not ret5['success']:
                test_flag = False
            #判断存储卷类型 不阻塞后面的测试
            ret6 = verify_volumes(self.k8s_flannel_service, "host_path")
            if not ret6['success']:
                test_flag = False
            #判断是否有Metrics 不阻塞后面的测试
            ret7 = get_metrics(self.k8s_flannel_service)
            if not ret7['success']:
                test_flag = False
            # 停止服务 如果失败block后面操作
            ret8 = stop_app(self.k8s_flannel_service)
            self.assert_successful(ret8)
            #启动服务 如果失败block 后面操作
            ret9 = start_app(self.k8s_flannel_service, num=1)
            self.assert_successful(ret9)
            #scale up 服务,更新服务的数量和size,失败block后面操作
            ret10 = update_service(self.k8s_flannel_service, num=2, size="XS")
            self.assert_successful(ret10)
            #check 所有的容器都部署在指定的机器上 不阻塞后面的测试
            ret11 = check_node(self.k8s_flannel_service, self.node_tag)
            if not ret11['success']:
                test_flag = False
            # scale down 服务更新服务的数量和size  失败block后面操作
            ret12 = update_service(self.k8s_flannel_service, num=1, size="XXS")
            self.assert_successful(ret12)
            # check 所有的容器都部署在指定的机器上 不阻塞后面的测试
            ret13 = check_node(self.k8s_flannel_service, self.node_tag)
            if not ret13['success']:
                test_flag = False
            # check 服务的日志
            ret14 = get_logs(self.k8s_flannel_service)
            if not ret14['success']:
                test_flag = False
            #check 日志文件
            ret15 = get_logfile(self.k8s_flannel_service)
            if not ret15['success']:
                test_flag = False
            #删除服务
            ret16 = delete_app(self.k8s_flannel_service,
                               settings.SERVICE_CLAAS_REGION[0])
            if not ret16['success']:
                test_flag = False

            result = {
                'success': test_flag,
                "get haproxy id ": ret1,
                "create k8s haproxy service": ret2,
                "access sercie ": ret3,
                "get service env": ret4,
                "get servie config": ret5,
                "get service volume type": ret6,
                "get service metrics": ret7,
                "stop service": ret8,
                "start service": ret9,
                "scale up service": ret10,
                "check instance in node": ret11,
                "scale down service": ret12,
                "check instance in node": ret13,
                "get service log": ret14,
                "get service logfile": ret15,
                "delete service": ret16
            }
            self.assert_successful(result)
            return result
示例#5
0
    def inner_elb_service_test__k8s_service(self):
        test_flag = True
        # 创建一个内网的ELB 失败返回
        ret1 = create_alb(self.k8s_internal_elb,
                          create_type='manual',
                          type='elb',
                          alb_region=settings.SERVICE_CLAAS_REGION[0],
                          address_type="internal")
        self.assert_successful(ret1)

        elb_data = data.ServiceData(self.k8s_innerelb_service,
                                    settings.CLAAS_NAMESPACE,
                                    settings.SERVICE_CLAAS_REGION[0],
                                    lb_type='elb',
                                    alb_name=self.k8s_internal_elb,
                                    lb_id=ret1['id'])
        # 创建一个使用ELB网络模式的服务 失败返回
        ret2 = create_service(self.k8s_innerelb_service,
                              elb_data.k8s_innerelb_service(),
                              settings.SERVICE_CLAAS_REGION[0])
        self.assert_successful(ret2)
        # 验证服务是否可以访问 失败继续测试
        ret3 = access_service(self.k8s_innerelb_service, self.k8s_internal_elb)
        if not ret3['success']:
            test_flag = False

        # 验证环境变量是否添加进去 失败可以继续后面测试
        ret4 = exec_feature(self.k8s_innerelb_service,
                            self.namespace,
                            command="'/bin/ls /'")
        if not ret4['success']:
            test_flag = False
        # 判断是否有Metrics 不阻塞后面的测试
        ret5 = get_metrics(self.k8s_innerelb_service)
        if not ret5['success']:
            test_flag = False
        # 停止服务 如果失败block后面操作
        ret6 = stop_app(self.k8s_innerelb_service)
        self.assert_successful(ret6)
        # 启动服务 如果失败block 后面操作
        ret7 = start_app(self.k8s_innerelb_service, num=1)
        self.assert_successful(ret7)
        # scale up 服务,更新服务的数量和size,失败block后面操作
        ret8 = update_service(self.k8s_innerelb_service, num=2, size="XS")
        self.assert_successful(ret8)
        # scale down 服务更新服务的数量和size  失败block后面操作
        ret9 = update_service(self.k8s_innerelb_service, num=1, size="XXS")
        self.assert_successful(ret9)

        # check 服务的日志
        # ret10 = get_logs(self.k8s_innerelb_service)
        # if not ret10['success']:
        #     test_flag = False

        ret11 = delete_alb(self.k8s_innerelb_service)
        self.assert_successful(ret11)

        ret12 = delete_app(self.k8s_innerelb_service)
        self.assert_successful(ret12)
        result = {
            'success': test_flag,
            "create elb": ret1,
            "create elb service": ret2,
            "access service": ret3,
            "service exec ": ret4,
            "get metrics": ret5,
            "stop service": ret6,
            "start service": ret7,
            "scale up service": ret8,
            "scale down service": ret9,
            # "get logs": ret10,
            "delete elb": ret11,
            "delete service": ret12
        }
        self.assert_successful(result)
        return result
示例#6
0
    def k8s_host__k8s_service(self):
        if self.haproxy:
            #设置flag
            test_flag = True
            #创建部署服务需要的环境变量文件 创建失败就直接返回
            ret1 = create_envs(self.k8s_envfile)
            self.assert_successful(ret1)
            #创建部署服务需要的glustfs存储卷,创建失败直接返回
            ret2 = create_volume(self.gluster_name, 'glusterfs', None)
            self.assert_successful(ret2)
            #获取当前所在集群的Haproxy信息,获取失败直接返回
            ret3 = get_haproxy(self.haproxy)

            self.assert_successful(ret3)
            #获取创建服务需要的数据
            k8sFlannelData = data.ServiceData(self.k8s_host_service,
                                              self.namespace,
                                              settings.SERVICE_CLAAS_REGION[0],
                                              lb_type='haproxy',
                                              alb_name=self.haproxy,
                                              lb_id=ret3['haproxy_id'],
                                              volume_id=ret2['volume_id'],
                                              volume_name=self.gluster_name,
                                              envfile=self.k8s_envfile)
            #创建Host模式挂载环境变量文件和glustfs存储卷的服务
            ret4 = create_service(self.k8s_host_service,
                                  k8sFlannelData.k8s_host_service(),
                                  settings.SERVICE_CLAAS_REGION[0])
            if not ret4["success"]:
                delete_volume(ret2['volume_id'], self.gluster_name)
            self.assert_successful(ret4)
            #访问服务,及时失败也可以继续执行测试
            ret5 = access_service(self.k8s_host_service, self.haproxy)
            if not ret5['success']:
                test_flag = False
            # 验证环境变量是否添加进去 失败可以继续后面测试
            ret6 = exec_feature(self.k8s_host_service,
                                self.namespace,
                                command="env",
                                commands_string="key=value")
            if not ret6['success']:
                test_flag = False
            # 验证volume id是否一致
            ret7 = verify_volumes(self.k8s_host_service, ret2['volume_id'])
            if not ret7['success']:
                test_flag = False

            # 判断是否有Metrics 不阻塞后面的测试
            ret8 = get_metrics(self.k8s_host_service)
            if not ret8['success']:
                test_flag = False
            # 停止服务 如果失败block后面操作
            ret9 = stop_app(self.k8s_host_service)
            self.assert_successful(ret9)
            # 启动服务 如果失败block 后面操作
            ret10 = start_app(self.k8s_host_service, num=1)
            self.assert_successful(ret10)
            # scale up 服务,更新服务的数量和size,失败block后面操作
            ret11 = update_service(self.k8s_host_service, num=2, size="XS")
            self.assert_successful(ret11)
            # scale down 服务更新服务的数量和size  失败block后面操作
            ret12 = update_service(self.k8s_host_service, num=1, size="XXS")
            self.assert_successful(ret12)

            # check 服务的日志
            ret13 = get_logs(self.k8s_host_service)
            if not ret13['success']:
                test_flag = False

            ret14 = delete_app(self.k8s_host_service,
                               settings.SERVICE_CLAAS_REGION[0])
            if not ret14['success']:
                test_flag = False
            #删除volume
            sleep(30)
            delete_volume(ret2['volume_id'], self.gluster_name)

            result = {
                'success': test_flag,
                "create envfile ": ret1,
                "create glustfs volume": ret2,
                "get haproxy id ": ret3,
                "create service": ret4,
                "access service": ret5,
                "check envfile": ret6,
                "check volume": ret7,
                "check metrics": ret8,
                "stop service": ret9,
                "start service": ret10,
                "scale up": ret11,
                "scale down": ret12,
                "check log": ret13,
                "delete service": ret14
            }
            self.assert_successful(result)
            return result