Example #1
0
class TestSubnetSuite(object):
    def setup_class(self):
        self.subnet = Subnet()
        self.subnet_name = 'alauda-subnet-{}'.format(self.subnet.region_name).replace('_', '-')
        # macvlan cidr需要和主机同网段
        self.masterip = self.subnet.global_info['$MASTERIPS'].split(',')[0]
        gateway = self.masterip.split('.')
        gateway.pop()
        self.macvlan_gateway = '.'.join(gateway)
        self.macvlan_cidr = "{}.0/24".format(self.macvlan_gateway)
        self.cidr_update = "{}.0/20".format(self.macvlan_gateway)
        self.ip1 = "{}.110".format(self.macvlan_gateway)
        self.ip2 = "{}.111".format(self.macvlan_gateway)
        self.ip3 = "{}.112".format(self.macvlan_gateway)

        # calico cidr不能和主机重合
        self.calico_gateway = '19.19.0'
        self.calico_cidr = "{}.0/24".format(self.calico_gateway)
        self.calico_ip1 = "{}.110".format(self.calico_gateway)

        self.newapp = Newapplication()
        self.k8s_namespace = self.newapp.global_info["$K8S_NAMESPACE"]
        self.newapp_name = 'subnet-statefulset'
        self.newapp_name_ip = 'ip-statefulset'
        self.teardown_class(self)

    def teardown_class(self):
        self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name)
        self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name_ip)
        if self.subnet.global_info['$NETWORK_TYPE'] == 'macvlan':
            self.subnet.delete_ips(self.subnet_name, self.ip1)
            self.subnet.delete_ips(self.subnet_name, self.ip2)
            self.subnet.delete_ips(self.subnet_name, self.ip3)
        self.subnet.delete_subnet(self.subnet_name)

    @pytest.mark.BAT
    def test_macvlan_subnet(self):
        '''
        macvlan子网测试:创建子网-更新子网-子网列表-子网详情-导入IP list-删除IP-导入IP range-IP列表-创建应用指定子网/IP-删除IP-删除子网
        :return:
        '''
        if self.subnet.global_info['$NETWORK_TYPE'] != 'macvlan':
            return True, "集群网络模式不是macvlan,不需要测试"
        crd_result = self.subnet.get_subnet_crd()
        assert crd_result.status_code == 200, "获取subnet的crd 失败:{}".format(crd_result.text)
        if len(crd_result.json()) == 0:
            assert False, "集群不支持subnet,请先部署subnet crd"

        result = {"flag": True}
        # create subnet
        createsubnet_result = self.subnet.create_subnet("./test_data/subnet/macvlan-subnet.json",
                                                        {"$subnet_name": self.subnet_name, "$cidr": self.macvlan_cidr,
                                                         '$gateway': self.macvlan_gateway})
        assert createsubnet_result.status_code == 201, "创建子网失败:{}".format(createsubnet_result.text)

        # update subnet
        update_result = self.subnet.update_subnet(self.subnet_name, "./test_data/subnet/macvlan-subnet.json",
                                                  {"$subnet_name": self.subnet_name, "$cidr": self.cidr_update})
        assert update_result.status_code == 204, "更新子网出错:{}".format(update_result.text)

        # list subnet
        list_result = self.subnet.list_subnet()
        result = self.subnet.update_result(result, list_result.status_code == 200, list_result.text)
        result = self.subnet.update_result(result, self.subnet_name in list_result.text, "子网列表:新建子网不在列表中")

        # detail subnet
        detail_result = self.subnet.get_subnet_detail(self.subnet_name)
        result = self.subnet.update_result(result, detail_result.status_code == 200, detail_result.text)
        result = self.subnet.update_result(result, self.subnet.get_value(detail_result.json(),
                                                                         'kubernetes.spec.cidr_block') == self.cidr_update,
                                           detail_result.text)

        # import list ip
        import_ip_list_result = self.subnet.create_ips(self.subnet_name, "./test_data/subnet/ip-list.json",
                                                       {'$ip3': self.ip3})
        assert import_ip_list_result.status_code == 201, "导入IP list失败:{}".format(import_ip_list_result.text)

        delete_result = self.subnet.delete_subnet(self.subnet_name)
        assert delete_result.status_code == 400, "子网非空 不能删除:{}".format(delete_result.text)

        # delete ip
        delete_ip_result = self.subnet.delete_ips(self.subnet_name, self.ip3)
        assert delete_ip_result.status_code == 204, "删除IP失败:{}".format(delete_ip_result.text)

        # wait for subnet empty
        self.subnet.check_value_in_response(self.subnet.get_private_ip_url(self.subnet_name), '[]')
        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, self.ip3 not in list_ip_result.text,
                                           "删除IP后:IP还在列表中")

        # import range ip
        range_ip_result = self.subnet.create_ips(self.subnet_name, "./test_data/subnet/ip-range.json",
                                                 {'$ip1': self.ip1, '$ip2': self.ip2})
        assert range_ip_result.status_code == 201, "导入IP range失败:{}".format(range_ip_result.text)

        # list ip
        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, list_ip_result.status_code == 200, list_ip_result.text)
        result = self.subnet.update_result(result, len(list_ip_result.json()) == 2, "IP列表:新建IP不在列表中")

        # create app with ip
        create_result = self.newapp.create_newapp('./test_data/newapp/macvlan-ip-statefulset.json',
                                                  {'$newapp_name': self.newapp_name_ip,
                                                   '$subnet_ip': self.ip2})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name_ip, 'Running')
        assert app_status, "创建应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        # create app with subnet
        create_result = self.newapp.create_newapp('./test_data/newapp/macvlan-subnet-statefulset.json',
                                                  {'$newapp_name': self.newapp_name, '$subnet_name': self.subnet_name})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "创建应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, list_ip_result.status_code == 200, list_ip_result.text)
        result = self.subnet.update_result(result, self.subnet.get_value(list_ip_result.json(),
                                                                         '0.kubernetes.spec.used') is True,
                                           "ip状态不是使用中")
        result = self.subnet.update_result(result, self.subnet.get_value(list_ip_result.json(),
                                                                         '1.kubernetes.spec.used') is True,
                                           "ip状态不是使用中")

        delete_result = self.subnet.delete_ips(self.subnet_name, self.ip1)
        assert delete_result.status_code == 400, "IP使用中 不能删除:{}".format(delete_result.text)

        # delete app
        delete_result = self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name_ip)
        assert delete_result.status_code == 204, "删除应用失败 {}".format(delete_result.text)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.newapp_name_ip), 404)

        # delete app
        delete_result = self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name)
        assert delete_result.status_code == 204, "删除应用失败 {}".format(delete_result.text)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.newapp_name), 404)

        # wait for ip not used
        self.subnet.get_status(self.subnet.get_private_ip_url(self.subnet_name), '0.kubernetes.spec.used', False)
        self.subnet.get_status(self.subnet.get_private_ip_url(self.subnet_name), '1.kubernetes.spec.used', False)

        self.subnet.delete_ips(self.subnet_name, self.ip1)
        self.subnet.delete_ips(self.subnet_name, self.ip2)

        # wait for subnet empty
        self.subnet.check_value_in_response(self.subnet.get_private_ip_url(self.subnet_name), '[]')

        # delete subnet
        delete_result = self.subnet.delete_subnet(self.subnet_name)
        assert delete_result.status_code == 204, "删除子网失败:{}".format(delete_result.text)
        assert self.subnet.check_exists(self.subnet.get_common_subnet_url(self.subnet_name), 404)
        assert result['flag'], result

    @pytest.mark.BAT
    def test_calico_subnet(self):
        '''
        calico子网测试:创建子网-子网列表-更新子网-子网详情-IP列表为空-创建应用指定子网-验证IP状态-创建应用指定IP-验证应用容器IP-IP列表-删除非空子网-更新非空子网-删除子网
        :return:
        '''

        if self.subnet.global_info['$NETWORK_TYPE'] != 'calico':
            return True, "集群网络模式不是calico,不需要测试"
        crd_result = self.subnet.get_subnet_crd()
        assert crd_result.status_code == 200, "获取subnet的crd 失败:{}".format(crd_result.text)
        if len(crd_result.json()) == 0:
            assert False, "集群不支持subnet,请先部署subnet crd"

        result = {"flag": True}
        # create subnet
        createsubnet_result = self.subnet.create_subnet_calico("./test_data/subnet/calico-subnet.json",
                                                               {"$subnet_name": self.subnet_name,
                                                                "$cidr": self.calico_cidr})
        assert createsubnet_result.status_code == 201, "创建子网失败:{}".format(createsubnet_result.text)

        # list subnet
        list_result = self.subnet.list_subnet()
        result = self.subnet.update_result(result, list_result.status_code == 200, list_result.text)
        result = self.subnet.update_result(result, self.subnet_name in list_result.text, "子网列表:新建子网不在列表中")

        # update subnet
        update_result = self.subnet.update_subnet(self.subnet_name, './test_data/subnet/update-calico-subnet.json',
                                                  {'$mode': 'Always', '"$nat"': 'false'})
        assert update_result.status_code == 204, "更新子网出错:{}".format(update_result.text)

        # detail subnet
        detail_result = self.subnet.get_subnet_detail(self.subnet_name)
        result = self.subnet.update_result(result, detail_result.status_code == 200, detail_result.text)
        result = self.subnet.update_result(result,
                                           self.subnet.get_status(self.subnet.get_common_subnet_url(self.subnet_name),
                                                                  'kubernetes.spec.ipip_mode', 'Always'),
                                           '更新子网后ipip_mode不是Always')

        # list IP
        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, len(list_ip_result.json()) == 0, "IP列表不为空")

        # create app with subnet
        create_result = self.newapp.create_newapp_by_yaml(self.k8s_namespace, self.newapp_name,
                                                          './test_data/newapp/calico-subnet-statefulset.yml',
                                                          {'$newapp_name': self.newapp_name,
                                                           '$subnet_cidr': self.calico_cidr})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "创建应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, list_ip_result.status_code == 200, list_ip_result.text)
        result = self.subnet.update_result(result, len(list_ip_result.json()) == 1, "IP列表:不是1个")
        result = self.subnet.update_result(result, self.subnet.get_value(list_ip_result.json(),
                                                                         '0.kubernetes.spec.used') is True,
                                           "ip状态不是使用中")

        # delete app
        delete_result = self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name)
        assert delete_result.status_code == 204, "删除应用失败 {}".format(delete_result.text)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.newapp_name), 404)

        # create app with IP
        create_result = self.newapp.create_newapp_by_yaml(self.k8s_namespace, self.newapp_name_ip,
                                                          './test_data/newapp/calico-ip-statefulset.yml',
                                                          {'$newapp_name': self.newapp_name_ip,
                                                           '$subnet_ip': self.calico_ip1})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name_ip, 'Running')
        assert app_status, "创建应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name_ip)
        podip = self.newapp.get_status(self.newapp.get_newapp_pod_url(self.k8s_namespace, self.newapp_name_ip),
                                       '0.kubernetes.status.podIP', self.calico_ip1)
        assert podip, "应用运行后,容器IP不是{}".format(self.calico_ip1)

        # list ip
        list_ip_result = self.subnet.list_ips(self.subnet_name)
        result = self.subnet.update_result(result, list_ip_result.status_code == 200, list_ip_result.text)
        result = self.subnet.update_result(result, self.calico_ip1 in list_ip_result.text,
                                           "{}不在列表中".format(self.calico_ip1))

        delete_result = self.subnet.delete_subnet(self.subnet_name)
        assert delete_result.status_code == 400, "子网非空 不能删除:{}".format(delete_result.text)

        # update subnet not empty
        update_result = self.subnet.update_subnet(self.subnet_name, './test_data/subnet/update-calico-subnet.json',
                                                  {'$mode': 'Never', '"$nat"': 'true'})
        assert update_result.status_code == 204, "子网非空时,更新子网出错:{}".format(update_result.text)
        result = self.subnet.update_result(result,
                                           self.subnet.get_status(self.subnet.get_common_subnet_url(self.subnet_name),
                                                                  'kubernetes.spec.ipip_mode', 'Never'),
                                           '子网非空时,更新子网后ipip_mode不是never')
        result = self.subnet.update_result(result,
                                           self.subnet.get_status(self.subnet.get_common_subnet_url(self.subnet_name),
                                                                  'kubernetes.spec.nat_outgoing', True),
                                           '子网非空时,更新子网后nat_outgoing不是True')

        # delete app
        delete_result = self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name_ip)
        assert delete_result.status_code == 204, "删除应用失败 {}".format(delete_result.text)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.newapp_name_ip), 404)

        # wait for subnet empty
        self.subnet.check_value_in_response(self.subnet.get_private_ip_url(self.subnet_name), '[]')

        # delete subnet
        delete_result = self.subnet.delete_subnet(self.subnet_name)
        assert delete_result.status_code == 204, "删除子网失败:{}".format(delete_result.text)
        assert self.subnet.check_exists(self.subnet.get_common_subnet_url(self.subnet_name), 404)
        assert result['flag'], result
Example #2
0
class TestNewApplicationSuite(object):
    def setup_class(self):
        self.newapp = Newapplication()
        self.k8s_namespace = self.newapp.global_info["$K8S_NAMESPACE"]
        self.newapp_name = 'alauda-newapp'

        self.configmap = Configmap()
        self.configmap_name = 'alauda-cmforapp-{}'.format(self.newapp.region_name).replace('_', '-')
        self.appwithcm_name = 'alauda-appwithcm-{}'.format(self.newapp.region_name).replace('_', '-')

        self.scs = Scs()
        self.scs_name = 'alauda-scsforapp-{}'.format(self.newapp.region_name).replace('_', '-')
        self.pvc = Pvc()
        self.pvc_name = 'alauda-pvcforapp-{}'.format(self.newapp.region_name).replace('_', '-')
        self.appwithpvc_name = 'alauda-appwithpvc-{}'.format(self.newapp.region_name).replace('_', '-')

        self.teardown_class(self)

    def teardown_class(self):
        self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name)
        self.newapp.delete_newapp(self.k8s_namespace, self.appwithcm_name)
        self.newapp.delete_newapp(self.k8s_namespace, self.appwithpvc_name)
        self.configmap.delete_configmap(self.k8s_namespace, self.configmap_name)
        self.pvc.delete_pvc(self.k8s_namespace, self.pvc_name)
        self.scs.delete_scs(self.scs_name)

    @pytest.mark.BAT
    @pytest.mark.ace
    def test_newapp(self):
        # if not self.newapp.is_weblab_open("USER_VIEW_ENABLED"):
        #     return True, "用户视角未打开,不需要测试"
        """
        创建应用-获取拓扑图-获取容器组-获取yaml-获取日志-获取事件-获取k8s事件-exec-获取全部应用-获取命名空间下的应用-搜索应用-
        更新应用-获取应用yaml-缩容-扩容-删除应用下的资源-获取应用详情-添加资源到应用-停止应用-启动应用-删除组件-删除应用
        """
        # 创建应用
        result = {"flag": True}
        create_result = self.newapp.create_newapp('./test_data/newapp/appcore.json', {'$newapp_name': self.newapp_name})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_uuid = self.newapp.get_value(create_result.json(), '0.kubernetes.metadata.uid')

        # 获取应用状态
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "创建应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        # 获取拓扑图
        topology_result = self.newapp.get_topology_in_namespace(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, topology_result.status_code == 200, "获取拓扑图失败")
        result = self.newapp.update_result(result, len(topology_result.json().get('referenced_by')) == 2, "拓扑图关联错误")

        # 获取容器组
        pod_result = self.newapp.get_newapp_pods(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, pod_result.status_code == 200, "获取容器组失败")
        result = self.newapp.update_result(result, len(pod_result.json()) == 1,
                                           "容器组不是1 {}".format(len(pod_result.json())))
        container_name = self.newapp.get_value(pod_result.json(), '0.kubernetes.metadata.name')

        # 获取yaml
        yaml_result = self.newapp.get_newapp_yaml(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, yaml_result.status_code == 200, "创建应用后,yaml失败")
        result = self.newapp.update_result(result, 'Application' in yaml_result.text, "创建应用后,yaml失败:不存在Application")
        result = self.newapp.update_result(result, 'Deployment' in yaml_result.text, "创建应用后,yaml失败:不存在Deployment")
        result = self.newapp.update_result(result, 'HorizontalPodAutoscaler' in yaml_result.text,
                                           "创建应用后,yaml失败:HorizontalPodAutoscaler")
        result = self.newapp.update_result(result, 'Service' in yaml_result.text, "创建应用后,yaml失败:不存在Service")

        # 获取日志
        log_result = self.newapp.get_newapp_log(self.k8s_namespace, self.newapp_name, container_name)
        result = self.newapp.update_result(result, log_result.status_code == 200, "获取日志失败")
        result = self.newapp.update_result(result, len(log_result.json()['logs']) > 0, "获取日志为空")

        # 获取事件
        event_result = self.newapp.get_newapp_event(app_uuid)
        result = self.newapp.update_result(result, event_result.status_code == 200, "获取事件失败")
        result = self.newapp.update_result(result, event_result.json().get('total_items') != 0, "获取事件为空")

        # 获取k8s事件
        kevent_result = self.newapp.get_newapp_kevent(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, kevent_result.status_code == 200, "获取k8s事件失败")
        result = self.newapp.update_result(result, kevent_result.json().get('count') != 0, "获取k8s事件为空")

        # exec
        exec_result = self.newapp.exec_newapp(self.k8s_namespace, self.newapp_name, container_name)
        result = self.newapp.update_result(result, exec_result.status_code == 200, "exec失败")

        # 获取全部应用
        list_result = self.newapp.get_all_newapp()
        result = self.newapp.update_result(result, list_result.status_code == 200, "获取应用列表失败")
        result = self.newapp.update_result(result, self.newapp_name in list_result.text, "获取应用列表失败:新建应用不在列表中")

        # 获取命名空间下的应用
        namespace_result = self.newapp.get_newapp_in_namespace(self.k8s_namespace)
        result = self.newapp.update_result(result, namespace_result.status_code == 200, "获取命名空间下的应用列表失败")
        result = self.newapp.update_result(result, self.newapp_name in namespace_result.text,
                                           "获取命名空间下的应用列表失败:新建应用不在列表中")

        # 按名称搜索应用
        search_result = self.newapp.search_newapp(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, search_result.status_code == 200, "按名称搜索应用失败")
        result = self.newapp.update_result(result, self.newapp_name in search_result.text,
                                           "按名称搜索应用失败:新建应用不在列表中")

        # 更新应用,个数为2,添加ClusterRole
        update_result = self.newapp.update_newapp(self.k8s_namespace, self.newapp_name,
                                                  './test_data/newapp/update_appcore.json',
                                                  {'$newapp_name': self.newapp_name})
        assert update_result.status_code == 200, "更新应用失败 {}".format(update_result.text)
        self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Pending')
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "更新应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        # 获取应用yaml
        yaml_result = self.newapp.get_newapp_yaml(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, yaml_result.status_code == 200, "更新应用后,yaml失败")
        result = self.newapp.update_result(result, 'Application' in yaml_result.text, "更新应用后,yaml失败:不存在Application")
        result = self.newapp.update_result(result, 'Deployment' in yaml_result.text, "更新应用后,yaml失败:不存在Deployment")
        result = self.newapp.update_result(result, 'HorizontalPodAutoscaler' in yaml_result.text,
                                           "更新应用后,yaml失败:HorizontalPodAutoscaler")
        result = self.newapp.update_result(result, 'Service' in yaml_result.text, "更新应用后,yaml失败:不存在Service")
        result = self.newapp.update_result(result, 'ClusterRole' in yaml_result.text, "更新应用后,yaml失败:不存在ClusterRole")
        result = self.newapp.update_result(result, '15222222222' in yaml_result.text, "更新应用后,owners未更新")

        # 缩容
        scale_down_result = self.newapp.scale_down_newapp(self.k8s_namespace, self.newapp_name)
        assert scale_down_result.status_code == 204, "缩容失败 {}".format(scale_down_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "缩容后,验证应用状态出错:app: {} is not running".format(self.newapp_name)
        flag = self.newapp.get_status(self.newapp.get_newapp_status_url(self.k8s_namespace, self.newapp_name),
                                      'workloads.deployment-{}.desired'.format(self.newapp_name), 1)
        assert flag, "缩容后,预期个数不是1"

        # 扩容
        scale_up_result = self.newapp.scale_up_newapp(self.k8s_namespace, self.newapp_name)
        assert scale_up_result.status_code == 204, "扩容失败 {}".format(scale_up_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "扩容后,验证应用状态出错:app: {} is not running".format(self.newapp_name)
        flag = self.newapp.get_status(self.newapp.get_newapp_status_url(self.k8s_namespace, self.newapp_name),
                                      'workloads.deployment-{}.desired'.format(self.newapp_name), 2)
        assert flag, "扩容后,预期个数不是2"

        # 删除应用下的资源ClusterRole
        remove_result = self.newapp.remove_resource_newapp(self.k8s_namespace, self.newapp_name,
                                                           './test_data/newapp/resource.json',
                                                           {'$newapp_name': self.newapp_name})
        assert remove_result.status_code == 204, "删除应用下的资源失败 {}".format(remove_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "删除应用下的资源后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        # 获取应用详情
        detail_result = self.newapp.get_newapp_detail(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, detail_result.status_code == 200, "获取应用详情失败")
        result = self.newapp.update_result(result, 'Application' in detail_result.text, "删除应用下的资源详情失败:不存在Application")
        result = self.newapp.update_result(result, 'Deployment' in detail_result.text, "删除应用下的资源详情失败:不存在Deployment")
        result = self.newapp.update_result(result, 'HorizontalPodAutoscaler' in detail_result.text,
                                           "删除应用下的资源详情失败:不存在HorizontalPodAutoscaler")
        result = self.newapp.update_result(result, 'Service' in detail_result.text, "删除应用下的资源详情失败:存在Service")
        result = self.newapp.update_result(result, 'ClusterRole' not in detail_result.text,
                                           "删除应用下的资源详情失败:存在ClusterRole")

        # 添加资源ClusterRole到应用
        add_result = self.newapp.add_resource_newapp(self.k8s_namespace, self.newapp_name,
                                                     './test_data/newapp/resource.json',
                                                     {'$newapp_name': self.newapp_name})
        assert add_result.status_code == 204, "添加资源到应用失败 {}".format(remove_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "添加资源到应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)
        detail_result = self.newapp.get_newapp_detail(self.k8s_namespace, self.newapp_name)
        result = self.newapp.update_result(result, detail_result.status_code == 200, "获取应用详情失败")
        result = self.newapp.update_result(result, 'Application' in detail_result.text, "添加资源到应用详情失败:不存在Application")
        result = self.newapp.update_result(result, 'Deployment' in detail_result.text, "添加资源到应用详情失败:不存在Deployment")
        result = self.newapp.update_result(result, 'HorizontalPodAutoscaler' in detail_result.text,
                                           "删除应用下的资源详情失败:不存在HorizontalPodAutoscaler")
        result = self.newapp.update_result(result, 'Service' in detail_result.text, "添加资源到应用详情失败:不存在Service")
        result = self.newapp.update_result(result, 'ClusterRole' in detail_result.text,
                                           "添加资源到应用详情失败:不存在ClusterRole")

        # 停止应用
        stop_result = self.newapp.stop_newapp(self.k8s_namespace, self.newapp_name)
        assert stop_result.status_code == 204, "停止应用失败 {}".format(stop_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Stopped')
        assert app_status, "停止应用后,验证应用状态出错:app: {} is running".format(self.newapp_name)

        # 开始应用
        start_result = self.newapp.start_newapp(self.k8s_namespace, self.newapp_name)
        assert start_result.status_code == 204, "启动应用失败 {}".format(start_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Running')
        assert app_status, "启动应用后,验证应用状态出错:app: {} is not running".format(self.newapp_name)

        # 删除组件
        deploy_result = self.newapp.delete_deployment(self.k8s_namespace, self.newapp_name)
        assert deploy_result.status_code == 204, "删除组件失败 {}".format(deploy_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.newapp_name, 'Empty')
        assert app_status, "删除组件后,验证应用状态出错:app: {} is not Empty".format(self.newapp_name)

        # 删除应用
        delete_result = self.newapp.delete_newapp(self.k8s_namespace, self.newapp_name)
        assert delete_result.status_code == 204, "删除应用失败 {}".format(delete_result.text)
        delete_flag = self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.newapp_name),
                                               404)
        assert delete_flag, "删除应用失败"
        assert result['flag'], result

    @pytest.mark.cm
    @pytest.mark.BAT
    def test_app_with_cm(self):
        """
        应用使用configmap测试:创建configmap-创建应用-删除应用-删除configmap
        :return:
        """
        result = {"flag": True}
        # create configmap
        createconfigmap_result = self.configmap.create_configmap("./test_data/configmap/configmap.json",
                                                                 {"$cm_name": self.configmap_name,
                                                                  "$cm_key": self.configmap_name})
        assert createconfigmap_result.status_code == 201, "创建cm出错:{}".format(createconfigmap_result.text)

        # create app with cm
        create_result = self.newapp.create_newapp_by_yaml(self.k8s_namespace,
                                                          self.appwithcm_name, './test_data/newapp/daemonset_cm.yml',
                                                          {'$newapp_name': self.appwithcm_name,
                                                           "$cm_name": self.configmap_name,
                                                           "$cm_key": self.configmap_name})
        assert create_result.status_code == 201, "新版应用创建失败 {}".format(create_result.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.appwithcm_name, 'Running')
        assert app_status, "创建使用configmap的应用后,验证应用状态出错:app: {} is not running".format(self.appwithcm_name)
        daemonset_result = self.newapp.get_component(self.k8s_namespace, self.appwithcm_name, 'daemonsets')
        result = self.newapp.update_result(result, daemonset_result.status_code == 200, '获取daemonset详情失败')
        content = daemonset_result.json()
        v1 = self.newapp.get_value(content, 'kubernetes.spec.template.spec.volumes.0.configMap.name')
        result = self.newapp.update_result(result, v1 == self.configmap_name, '存储卷挂载configmap失败')
        v2 = self.newapp.get_value(content, 'kubernetes.spec.template.spec.volumes.1.configMap.name')
        result = self.newapp.update_result(result, v2 == self.configmap_name, '存储卷挂载configmap失败')
        e1 = self.newapp.get_value(content,
                                   'kubernetes.spec.template.spec.containers.0.envFrom.0.configMapRef.name')
        result = self.newapp.update_result(result, e1 == self.configmap_name, '环境变量完整引用configmap失败')
        e2 = ''
        env = self.newapp.get_value(content, 'kubernetes.spec.template.spec.containers.0.env')
        for e in env:
            if e.get('name') == 'cm':
                e2 = self.newapp.get_value(e, 'valueFrom.configMapKeyRef.name')
        result = self.newapp.update_result(result, e2 == self.configmap_name, '环境变量引用configmap的key失败')
        self.newapp.delete_newapp(self.k8s_namespace, self.appwithcm_name)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.appwithcm_name), 404)
        self.configmap.delete_configmap(self.k8s_namespace, self.configmap_name)
        assert result['flag'], result

    @pytest.mark.pvc
    def test_app_with_pvc(self):
        """
        应用使用pvc测试:创建sc-创建pvc-创建应用-获取pvc拓扑图-删除应用-删除pvc-删除sc
        :return:
        """
        result = {"flag": True}
        create_result = self.scs.create_scs("./test_data/scs/scs.yml",
                                            {"$scs_name": self.scs_name, "$is_default": "false",
                                             })
        assert create_result.status_code == 201, "创建sc失败{}".format(create_result.text)

        # create pvc
        createpvc_result = self.pvc.create_pvc("./test_data/pvc/pvc.json",
                                               {"$pvc_name": self.pvc_name, "$pvc_mode": "ReadWriteOnce",
                                                "$scs_name": self.scs_name, "$size": "1"})
        assert createpvc_result.status_code == 201, "创建pvc失败{}".format(createpvc_result.text)
        self.pvc.get_status(self.pvc.get_common_pvc_url(self.pvc.global_info["$K8S_NAMESPACE"], self.pvc_name),
                            "status.phase", "Bound")
        # create app
        create_app = self.newapp.create_newapp_by_yaml(self.k8s_namespace,
                                                       self.appwithpvc_name,
                                                       './test_data/newapp/statefulset_pvc.yml',
                                                       {"$newapp_name": self.appwithpvc_name,
                                                        "$pvc_name": self.pvc_name})
        assert create_app.status_code == 201, "创建app出错:{}".format(create_app.text)
        app_status = self.newapp.get_newapp_status(self.k8s_namespace, self.appwithpvc_name, 'Running')
        assert app_status, "创建使用pvc的应用后,验证应用状态出错:app: {} is not running".format(self.appwithpvc_name)

        # get statefulset detail
        statefulset_result = self.newapp.get_component(self.k8s_namespace, self.appwithpvc_name, 'statefulsets')
        result = self.newapp.update_result(result, statefulset_result.status_code == 200, '获取statefulset详情失败')
        claimName = self.newapp.get_value(statefulset_result.json(),
                                          "kubernetes.spec.template.spec.volumes.0.persistentVolumeClaim.claimName")
        result = self.newapp.update_result(result, claimName == self.pvc_name, "详情中挂载pvc失败")

        # get pvc topology
        pvc_topology = self.newapp.get_topology_in_namespace(self.k8s_namespace, self.pvc_name, 'PersistentVolumeClaim')
        result = self.newapp.update_result(result, pvc_topology.status_code == 200,
                                           "获取pvc拓扑图失败 {}".format(pvc_topology.status_code))
        result = self.newapp.update_result(result, len(pvc_topology.json()['referenced_by']) == 1,
                                           "获取pvc拓扑图错误 {}".format(pvc_topology.text))
        # delete
        self.newapp.delete_newapp(self.k8s_namespace, self.appwithpvc_name)
        self.newapp.check_exists(self.newapp.get_newapp_common_url(self.k8s_namespace, self.appwithpvc_name), 404)
        self.pvc.get_status(
            self.newapp.get_topology_in_namespace_url(self.k8s_namespace, self.pvc_name, 'PersistentVolumeClaim'),
            "referenced_by", [])
        time.sleep(60)
        self.pvc.delete_pvc(self.k8s_namespace, self.pvc_name)
        self.scs.delete_scs(self.scs_name)

        assert result['flag'], result