示例#1
0
def test_build_file_nb():
    filepath = '{}/handler.ipynb'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(config={'spec.maxReplicas': 2})
    name, config, code = build_file(filepath, spec=spec)

    assert name == 'handler', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)

    maxRep = get_in(config, 'spec.maxReplicas')
    assert maxRep == 2, 'failed to set replicas, {}'.format(maxRep)
示例#2
0
def test_build_file_zip(project):
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath, name='hw', spec=spec,
                                    archive=True, project=project, tag='v7',
                                    output_dir='.')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
    assert os.path.exists(project), '{} dir was not created'.format(project)
    zip_path = os.path.join(project, 'hw_v7.zip')
    assert os.path.exists(zip_path), '{} dir was not created'.format(zip_path)
示例#3
0
def test_build_file_zip():
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath,
                                    name='hw',
                                    spec=spec,
                                    archive=True,
                                    project='p1',
                                    tag='v7',
                                    output_dir='.')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)
    assert config.get('spec'), 'build failed, config={}'.format(config)
示例#4
0
def test_build_file_py():
    filepath = '{}/handler.py'.format(here)
    filepath = filepath.replace("\\", "/")  # handle windows
    spec = ConfigSpec(env={'MYENV': 'text'})
    name, config, code = build_file(filepath, name='hw', spec=spec, tag='v7')

    assert name == 'hw', 'build failed, name doesnt match={}'.format(name)

    assert config.get('spec'), 'build failed, config={}'.format(config)

    tag = config['metadata']['labels'].get(meta_keys.tag)
    assert tag == 'v7', 'failed, tag not set properly config={}'.format(config)

    envs = config['spec']['env']
    assert envs[0].get('name') == 'MYENV', 'build failed, env err'.format(envs)
示例#5
0
def test_deploy_with_external_source_env(requests):
    # define my function code template
    code = '''
    def handler(context, event):
        context.logger.info('text')
        return 'something'
    '''

    # deploy code with extra configuration (env vars, external_source_env)
    name = 'ENV1'
    external_source_env = {
        name: {
            'secretKeyRef': {
                'name': 'secret1',
                'key': 'secret-key1'
            }
        }
    }
    expected_output_env = {
        'name': name,
        'valueFrom': external_source_env[name]
    }
    env_var = {'MYENV_VAR': 'something'}
    expected_output_env_var = {'name': 'MYENV_VAR', 'value': 'something'}
    spec = ConfigSpec(env=env_var, external_source_env=external_source_env)
    function_names = set(functions)
    deploy.deploy_code(code,
                       name='myfunc2',
                       project='test-project',
                       verbose=True,
                       spec=spec)

    new_function_names = set(functions)
    assert len(new_function_names) == len(function_names) + 1, 'not deployed'
    name = first(new_function_names - function_names)
    func = functions[name]
    assert expected_output_env in func['spec'][
        'env'], 'secret is not in function spec'
    assert expected_output_env_var in func['spec'][
        'env'], 'env var is not in function spec'
示例#6
0
def test_deploy_code(requests):
    # define my function code template
    code = '''
    def handler(context, event):
        context.logger.info('text')
        return 'something'
    '''

    # deploy my code with extra configuration (env vars, mount)
    vol = Volume('data', '~/')
    spec = ConfigSpec(env={'MYENV_VAR': 'something'}, mount=vol)
    names = set(functions)
    deploy.deploy_code(code,
                       name='myfunc',
                       project='test-project',
                       verbose=True,
                       spec=spec)

    new_names = set(functions)
    assert len(new_names) == len(names) + 1, 'not deployed'
    name = first(new_names - names)
    func = functions[name]
    assert func['status']['state'] == 'ready', 'not ready'