Exemple #1
0
def test_list_by_svc_share_uuids():
    tenant_id = "6d1c06e1d9e84d57aeb42ea80d49018a"
    service_id = "560ca84003254737a426d0bd5f513afd"
    service_cname = "WordPress"
    group_id = 20
    service = TenantServiceInfo()
    service.tenant_id = tenant_id
    service.service_id = service_id
    service.service_cname = service_cname
    service.save()

    service_source = ServiceSourceInfo()
    service_source.team_id = tenant_id
    service_source.service_id = service_id
    service_source.service_share_uuid = "2669c2cec6bc7bf5aab29a0ea2703d66"
    service_source.save()

    group_relation = ServiceGroupRelation()
    group_relation.service_id = service_id
    group_relation.group_id = group_id
    group_relation.save()

    from console.repositories.app import service_repo
    result = service_repo.list_by_svc_share_uuids(
        group_id, ["2669c2cec6bc7bf5aab29a0ea2703d66"])
    service = result[0]
    assert service.get("service_id") == service_id
    assert service.get("service_cname") == service_cname
Exemple #2
0
def test_restore_ports():
    from console.services.app_actions.app_restore import AppRestore
    tn = Tenants()
    tn.tenant_id = "c1a29fe4d7b0413993dc859430cf743d"
    svc = TenantServiceInfo()
    svc.service_id = "5a9209f3a3e94695b23fbd8b16a07d2b"
    backup_data = {
        "service_ports": [{
            "lb_mapping_port": 0,
            "protocol": "http",
            "mapping_port": 80,
            "tenant_id": "c1a29fe4d7b0413993dc859430cf743d",
            "port_alias": "GR063B3980",
            "container_port": 80,
            "is_outer_service": False,
            "is_inner_service": False,
            "service_id": "5a9209f3a3e94695b23fbd8b16a07d2b",
            "ID": 513
        }],
    }
    service_ports = backup_data["service_ports"]
    raw_ports = [port["port_alias"] for port in service_ports]
    app_restore = AppRestore(tn, svc)
    app_restore.ports(service_ports)
    ports = port_repo.get_service_ports(tn.tenant_id, svc.service_id)

    for port in ports:
        assert port.port_alias in raw_ports
    def __init_market_app(self, tenant, region, user, app,
                          tenant_service_group_id, service_origin):
        """
        初始化应用市场创建的应用默认数据
        """
        is_slug = bool(app["image"].startswith('goodrain.me/runner')
                       and app["language"] not in ("dockerfile", "docker"))

        tenant_service = TenantServiceInfo()
        tenant_service.tenant_id = tenant.tenant_id
        tenant_service.service_id = make_uuid()
        tenant_service.service_cname = app_service.generate_service_cname(
            tenant, app["service_cname"], region)
        tenant_service.service_alias = "gr" + tenant_service.service_id[-6:]
        tenant_service.creater = user.pk
        if is_slug:
            tenant_service.image = app["image"]
        else:
            tenant_service.image = app.get("share_image", app["image"])
        tenant_service.cmd = app.get("cmd", "")
        tenant_service.service_region = region
        tenant_service.service_key = app["service_key"]
        tenant_service.desc = "market app "
        tenant_service.category = "app_publish"
        tenant_service.setting = ""
        tenant_service.extend_method = app["extend_method"]
        tenant_service.env = ","
        tenant_service.min_node = app["extend_method_map"]["min_node"]
        tenant_service.min_memory = app["extend_method_map"]["min_memory"]
        tenant_service.min_cpu = baseService.calculate_service_cpu(
            region, tenant_service.min_memory)
        tenant_service.inner_port = 0
        tenant_service.version = app["version"]
        if is_slug:
            if app.get("service_slug", None):
                tenant_service.namespace = app["service_slug"]["namespace"]
        else:
            if app.get("service_image", None):
                tenant_service.namespace = app["service_image"]["namespace"]
        tenant_service.update_version = 1
        tenant_service.port_type = "multi_outer"
        tenant_service.create_time = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        tenant_service.deploy_version = ""
        tenant_service.git_project_id = 0
        tenant_service.service_type = "application"
        tenant_service.total_memory = tenant_service.min_node * tenant_service.min_memory
        tenant_service.volume_mount_path = ""
        tenant_service.host_path = ""
        tenant_service.code_from = ""
        tenant_service.language = ""
        tenant_service.service_source = "market"
        tenant_service.create_status = "creating"
        tenant_service.service_origin = service_origin
        tenant_service.tenant_service_group_id = tenant_service_group_id
        self.__init_service_source(tenant_service, app)
        # 存储并返回
        tenant_service.save()
        return tenant_service
Exemple #4
0
def test_envs_changes():
    from console.services.app_actions.properties_changes import PropertiesChanges
    from console.repositories.app_config import env_var_repo

    tenant_id = "c1a29fe4d7b0413993dc859430cf743d"
    service_id = "03289ae373e65e4a1a22046d7f76ca5e"

    tenantServiceEnvVar = {}
    tenantServiceEnvVar["tenant_id"] = tenant_id
    tenantServiceEnvVar["service_id"] = service_id
    tenantServiceEnvVar['container_port'] = 0
    tenantServiceEnvVar["name"] = "NGINX_VERSION"
    tenantServiceEnvVar["attr_name"] = "NGINX_VERSION"
    tenantServiceEnvVar["attr_value"] = "1.15.12-1~stretch"
    tenantServiceEnvVar["is_change"] = False
    tenantServiceEnvVar["scope"] = "inner"
    env_var_repo.add_service_env(**tenantServiceEnvVar)

    envs = [
        {
            "is_change": True,
            "name": "\u65e5\u5fd7\u8f93\u51fa\u65b9\u5f0f",
            "attr_value": "file",
            "attr_name": "DESTINATION"
        },
        {
            "is_change": True,
            "name": "\u8be6\u7ec6\u9519\u8bef\u65e5\u5fd7",
            "attr_value": "true",
            "attr_name": "TRACEALLEXCEPTIONS"
        },
        {
            "is_change": True,
            "name": "NGINX_VERSION",
            "attr_value": "1.15.12-1~stretch",
            "attr_name": "NGINX_VERSION"
        },
    ]
    service = TenantServiceInfo()
    service.tenant_id = tenant_id
    service.service_id = service_id
    properties_changes = PropertiesChanges(service)
    env_changes = properties_changes.env_changes(envs)
    print env_changes
    assert 2 == len(env_changes["add"])
    assert next(
        iter(
            filter(lambda x: x["attr_name"] == "DESTINATION",
                   env_changes["add"])), None)
    assert next(
        iter(
            filter(lambda x: x["attr_name"] == "TRACEALLEXCEPTIONS",
                   env_changes["add"])), None)
Exemple #5
0
 def __init_compose_service(self, tenant, user, service_cname, image,
                            region):
     """
     初始化docker compose创建的应用默认数据
     """
     tenant_service = TenantServiceInfo()
     tenant_service.tenant_id = tenant.tenant_id
     tenant_service.service_id = make_uuid()
     tenant_service.service_cname = app_service.generate_service_cname(
         tenant, service_cname, region)
     tenant_service.service_alias = "gr" + tenant_service.service_id[-6:]
     tenant_service.creater = user.pk
     tenant_service.image = image
     tenant_service.service_region = region
     tenant_service.service_key = "0000"
     tenant_service.desc = "docker compose application"
     tenant_service.category = "app_publish"
     tenant_service.setting = ""
     tenant_service.extend_method = "stateless"
     tenant_service.env = ","
     tenant_service.min_node = 1
     tenant_service.min_memory = 128
     tenant_service.min_cpu = baseService.calculate_service_cpu(region, 128)
     tenant_service.inner_port = 0
     tenant_service.version = "latest"
     tenant_service.namespace = "goodrain"
     tenant_service.update_version = 1
     tenant_service.port_type = "multi_outer"
     tenant_service.create_time = datetime.datetime.now().strftime(
         '%Y-%m-%d %H:%M:%S')
     tenant_service.deploy_version = ""
     tenant_service.git_project_id = 0
     tenant_service.service_type = "application"
     tenant_service.total_memory = 128
     tenant_service.volume_mount_path = ""
     tenant_service.host_path = "/grdata/tenant/" + tenant.tenant_id + "/service/" + tenant_service.service_id
     tenant_service.code_from = "image_manual"
     tenant_service.language = "docker-compose"
     tenant_service.service_source = AppConstants.DOCKER_COMPOSE
     tenant_service.create_status = "creating"
     # 保存并返回
     tenant_service.save()
     return tenant_service
Exemple #6
0
def test_restore_env():
    from console.services.app_actions.app_restore import AppRestore
    tn = Tenants()
    tn.tenant_id = "c1a29fe4d7b0413993dc859430cf743d"
    svc = TenantServiceInfo()
    svc.service_id = "36966cedcad44358a12f1707dece18da"
    backup_data = {
        "service_env_vars": [{
            "name": "PHPIZE_DEPS",
            "tenant_id": "c1a29fe4d7b0413993dc859430cf743d",
            "attr_name": "PHPIZE_DEPS",
            "container_port": 0,
            "create_time": "2019-05-14 18:04:26",
            "attr_value": "autoconf",
            "is_change": True,
            "scope": "inner",
            "service_id": "36966cedcad44358a12f1707dece18da",
            "ID": 1080
        }, {
            "name": "PHP_EXTRA_CONFIGURE_ARGS",
            "tenant_id": "c1a29fe4d7b0413993dc859430cf743d",
            "attr_name": "PHP_EXTRA_CONFIGURE_ARGS",
            "container_port": 0,
            "create_time": "2019-05-14 18:04:26",
            "attr_value": "--with-apxs2 --disable-cgi",
            "is_change": True,
            "scope": "inner",
            "service_id": "36966cedcad44358a12f1707dece18da",
            "ID": 1081
        }]
    }
    service_env_vars = backup_data["service_env_vars"]
    raw_envs = [env["name"] for env in service_env_vars]
    app_restore = AppRestore(tn, svc)
    service_env_vars = service_env_vars
    app_restore.envs(service_env_vars)
    envs = env_var_repo.get_service_env(tn.tenant_id, svc.service_id)

    for env in envs:
        assert env.name in raw_envs