Esempio n. 1
0
    def create_alb_application__alb_applications(self):
        ''' create app with most alauda yaml features: command|entrypoint|environment|domain|links|net|number|size|
        volumes|ports|expose|alauda_lb|internal_ports'''
        if self.app_region is not None:
            yaml_content = None
            if settings.ENV == 'private':
                yaml_content = "helloworld:\n alauda_lb: ALB\n net: flannel\n image: {}/{}:{}\n size: XXS\n ports:\n - '{}:80:80/http'\n" \
                    .format(get_registry_info().get('registry_url', None), settings.PRIVATE_REPO, settings.IMAGE_TAG, self.haproxy)
            else:
                yaml_content = "redis:\n alauda_lb: ALB\n ports:\n - '{}:6379:6379'\n" \
                                     " image: {}/library/redis:latest\n size: XXS\n net: bridge\n number: 1\n" \
                                     "web:\n alauda_lb: ALB\n command: python app.py\n image: {}/alauda/flask-redis:latest" \
                                     "\n size: XS\n links:\n - redis:redis\n ports:\n - '{}:18080:80/http'" \
                                     "\ntest-volume:\n entrypoint: /start.sh\n image: index.alauda.cn/alauda/volume-test:latest\n " \
                                     "environment:\n - env1=env-value1\n volumes:\n - /home/ubuntu:/var/lib/mysql" \
                                     "\n env_file:\n - {}\n size: CUSTOMIZED\n cpu_quota: 0.125\n mem_limit: 100" \
                    .format(self.haproxy, settings.REGISTRY_URL, settings.REGISTRY_URL, self.haproxy, self.envfile_name)

            print('yaml_content:{}'.format(yaml_content))
            self.create_app_action(self.app_alb_name, yaml_content,
                                   self.app_region, 'ALB', self.haproxy, True)
        else:
            return {
                "success": True,
                "total": "there is no alb region, skip the case"
            }
Esempio n. 2
0
    def create_application__applications(self):
        ''' create app with most alauda yaml features: command|entrypoint|environment|domain|links|net|number|size|
        volumes|ports|expose|alauda_lb|internal_ports'''

        print('self.internal_data:{}'.format(self.internal_data))
        self.create_app_action(self.app_ha_name, self.internal_data,
                               self.app_region, 'HA', None, False)

        yaml_content = None
        if settings.ENV == 'private':
            yaml_content = "helloworld:\n image: {}/{}:{}\n size: XXS\n ports:\n - '80/http'\n" \
                .format(get_registry_info().get('registry_url', None), settings.PRIVATE_REPO, settings.IMAGE_TAG)
        else:
            yaml_content = "redis:\n alauda_lb:\n  internal_ports:\n  - '6379'\n  lb_type: HA\n" \
                                 " image: {}/library/redis:latest\n size: XXS\n net: bridge\n number: 1\n" \
                                 "web:\n alauda_lb: HA\n command: python app.py\n image: {}/alauda/flask-redis:latest" \
                                 "\n size: XS\n links:\n - redis:redis\n ports:\n - '80/http'" \
                                 "\ntest-volume:\n entrypoint: /start.sh\n image: index.alauda.cn/alauda/volume-test:latest\n " \
                                 "environment:\n - env1=env-value1\n volumes:\n - /home/ubuntu:/var/lib/mysql" \
                                 "\n env_file:\n - {}\n size: CUSTOMIZED\n cpu_quota: 0.125\n mem_limit: 100" \
                .format(settings.REGISTRY_URL, settings.REGISTRY_URL, self.envfile_name)

        print('yaml_content:{}'.format(yaml_content))
        self.create_app_action(self.app_ha_name, yaml_content, self.app_region,
                               'HA', None, True)
Esempio n. 3
0
 def get_image_registry(self):
     if settings.ENV == 'private':
         return get_registry_info().get("registry_url", settings.REGISTRY_URL)
     else:
         return settings.REGISTRY_URL
Esempio n. 4
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"
            }
Esempio n. 5
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"
            }
Esempio n. 6
0
import requests
from brewmaster.run import case
import build_data
import pipeline_data
import settings
from CLaaS.sync_image import create_sync_config, delete_sync_config
from utils import get_registry_info, retry, get_events, get_repo, create_private_build, delete_private_build, get_region_data

logger = logging.getLogger()
REGIONS = settings.SERVICE_CLAAS_REGION
headers = {
    "Authorization": "Token " + settings.API_TOKEN,
    'User-Agent': 'rubick/v1.0',
    'Content-Type': "application/json"
}
registry_uuid = get_registry_info().get("registry_uuid", None)
registry_url = get_registry_info().get("registry_url", None)


@retry(times=settings.RETRY_TIMES)
def create_pipeline(pipeline_name, data):
    delete_pipeline(pipeline_name)
    time1 = time()
    url = "{}pipelines/{}/config".format(settings.API_URL, settings.CLAAS_NAMESPACE)
    print data, type(data)
    r = requests.post(url, data=json.dumps(data), headers=headers)
    print r.text
    if r.status_code != 201:
        return {"success":False, "total": "create pipeline return code error: {}, error text:{}".format(r.status_code,r.text)}
    if not get_events(pipeline_name, "create"):
        return {"success": False, "total": "this action do not have events"}