Example #1
0
def render_dependency(service_app, service):
    from apis.models import App
    d = Dependency()
    d.PodName = "%s.portal.%s" % (service_app,
                                  App.get_portal_name_from_service_name(
                                      App.get_or_none(service_app), service))
    d.Policy = DependencyPolicy.NamespaceLevel  # TODO allow user definiton
    return d
Example #2
0
def test_Render_system_volumes():
    hello = App()
    hello.appname = 'hello'
    hello.meta_version = HELLO_META_VERSION
    hello.meta = HELLO_META
    conf = hello.app_spec
    for podg in conf.PodGroups:
        for container in podg.Pod.Containers:
            assert container.SystemVolumes == DEFAULT_SYSTEM_VOLUMES
Example #3
0
def render_dependency(service_app, service):
    from apis.models import App
    d = Dependency()
    d.PodName = "%s.portal.%s" % (
         service_app,
         App.get_portal_name_from_service_name(
            App.get_or_none(service_app), service)
    )
    d.Policy = DependencyPolicy.NamespaceLevel # TODO allow user definiton
    return d
def test_Render_system_volumes_registry(system_volumes):
    system_volumes.return_value = [REGISTRY_SYSTEM_VOLUME]
    registry = App()
    registry.appname = 'registry'
    registry.meta_version = REGISTRY_META_VERSION
    registry.meta = REGISTRY_META
    conf = registry.app_spec
    for podg in conf.PodGroups:
        for container in podg.Pod.Containers:
            assert container.SystemVolumes == DEFAULT_SYSTEM_VOLUMES + [REGISTRY_SYSTEM_VOLUME]
Example #5
0
def test_Render_system_volumes_registry(system_volumes):
    system_volumes.return_value = [REGISTRY_SYSTEM_VOLUME]
    registry = App()
    registry.appname = 'registry'
    registry.meta_version = REGISTRY_META_VERSION
    registry.meta = REGISTRY_META
    conf = registry.app_spec
    for podg in conf.PodGroups:
        for container in podg.Pod.Containers:
            assert container.SystemVolumes == DEFAULT_SYSTEM_VOLUMES + \
                [REGISTRY_SYSTEM_VOLUME]
Example #6
0
def test_Render_system_volumes_registry(etcd_operations):
    etcd_operations[
        'utils_read_from_etcd'].return_value = generate_etcd_app_key_result(
            REGISTRY_SYSTEM_VOLUME)
    registry = App()
    registry.appname = 'registry'
    registry.meta_version = REGISTRY_META_VERSION
    registry.meta = REGISTRY_META
    conf = registry.app_spec
    for podg in conf.PodGroups:
        for container in podg.Pod.Containers:
            assert container.SystemVolumes == DEFAULT_SYSTEM_VOLUMES + [
                REGISTRY_SYSTEM_VOLUME
            ]
Example #7
0
def init_app_data():
    old_apps = App.objects.all()
    path = os.path.join(settings.BASE_DIR, 'utils', 'app.yaml')
    with open(path, 'r', encoding='utf-8') as f:
        apps = json.load(f)
        published = apps['published']
        for item in published:
            item = item['app']
            #生成唯一id
            src = item['category'] + item['application']
            appid = hashlib.md5(src.encoding('utf8')).hexdigest()

            if len(old_apps.filter(appid=appid)) == 1:
                print('already exist,appid:', appid)
                app = old_apps.get(appid=appid)
            else:
                print('not exist,creare appid:', appid)
                app = App()
            app.appid = appid
            app.category = item['category']
            app.application = item['application']
            app.name = item['name']
            app.publish_date = item['publish_date']
            app.url = item['url']
            app.desc = item['desc']
            app.save()
Example #8
0
def init_app_data():
    old_apps = App.objects.all()
    path = os.path.join(settings.BASE_DIR, 'app.yaml')
    with open(path, 'r', encoding='utf-8') as f:
        apps = yaml.load(f)
        published = apps.get('published')
        for item in published:
            item = item.get('app')
            # 生成唯一id
            src = item.get('category') + item.get('application')
            appid = hashlib.md5(src.encode('utf8')).hexdigest()
            # 存在更新 不存在新建
            if len(old_apps.filter(appid=appid)) == 1:
                print('already exist, appid:', appid)
                app = old_apps.filter(appid=appid)[0]
            else:
                app = App()
                print('not exist, appid:', appid)
            app.appid = appid
            app.name = item.get('name')
            app.application = item.get('application')
            app.url = item.get('url')
            app.publish_date = item.get('publish_date')
            app.category = item.get('category')
            app.desc = item.get('desc')
            app.save()
Example #9
0
def test_Resource_instance_meta_render():
    hello = App()
    hello.appname = 'hello'
    hello.meta_version = REDIS_CLIENT_META_VERSION
    hello.meta = REDIS_CLIENT_META
    hello_config = hello.lain_config

    redis_resource = App()
    redis_resource.appname = 'redis'
    redis_resource.meta_version = REDIS_RESOURCE_META_VERSION

    meta_from_file = yaml.safe_load(REDIS_RESOURCE_META)
    meta_yaml = yaml.safe_dump(meta_from_file, default_style='"')
    redis_resource.meta = meta_yaml
    redis_instance = App()
    redis_instance.meta_version = REDIS_RESOURCE_META_VERSION
    redis_instance.meta = redis_resource.get_resource_instance_meta(
        'hello', hello_config.use_resources['redis']['context'])
    redis_instance.default_image = \
        "{}/redis:release-{}".format(PRIVATE_REGISTRY,
                                     REDIS_RESOURCE_META_VERSION)
    redis_instance_config = redis_instance.lain_config
    assert redis_instance_config.appname == 'resource.redis.hello'
    assert redis_instance_config.procs[
        'redis'].image == redis_instance.default_image
    assert redis_instance_config.procs['redis'].memory == '128M'
    assert redis_instance_config.procs['redis'].num_instances == 1
    assert redis_instance_config.procs[
        'portal-redis'].image == redis_instance.default_image