Ejemplo n.º 1
0
def test_update_app_json():
    with _zero_instance_app():
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'update', 'zero-instance-app',
             "env='{\"key\":\"/value\"}'"])

        assert returncode == 0
        assert stdout.decode().startswith('Created deployment ')
        assert stderr == b''
Ejemplo n.º 2
0
def _update_app(app_id, file_path):
    with open(file_path) as fd:
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'update', app_id],
            stdin=fd)

        assert returncode == 0
        assert stdout.decode().startswith('Created deployment ')
        assert stderr == b''
Ejemplo n.º 3
0
def test_node_ssh_master_proxy_no_agent():
    env = os.environ.copy()
    env.pop('SSH_AUTH_SOCK', None)

    returncode, stdout, stderr = exec_command(
        ['dcos', 'node', 'ssh', '--master-proxy', '--leader'], env=env)

    assert returncode == 1
    assert b'Permission denied' in stderr
Ejemplo n.º 4
0
def test_update_app():
    with _zero_instance_app():
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'update', 'zero-instance-app',
             'cpus=1', 'mem=20', "cmd='sleep 100'"])

        assert returncode == 0
        assert stdout.decode().startswith('Created deployment ')
        assert stderr == b''
Ejemplo n.º 5
0
def test_dont_verify_ssl_with_env_var(env):
    env['DCOS_SSL_VERIFY'] = 'false'

    returncode, stdout, stderr = exec_command(
        ['dcos', 'marathon', 'app', 'list'], env)
    assert returncode == 0
    assert stderr == b''

    env.pop('DCOS_SSL_VERIFY')
Ejemplo n.º 6
0
def test_verify_ssl_without_cert_env_var(env):
    env['DCOS_SSL_VERIFY'] = 'true'
    with update_config('core.ssl_verify', None, env):
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'list'], env)
        assert returncode == 1
        assert stderr.decode('utf-8') == _ssl_error_msg()

    env.pop('DCOS_SSL_VERIFY')
Ejemplo n.º 7
0
def test_history_deprecated_show_failures():

    with _no_schedule_instance_job():
        returncode, stdout, stderr = exec_command(
            ['dcos', 'job', 'history', 'pikachu', '--show-failures'])

        assert returncode == 0
        assert stderr.decode('utf-8').startswith(
                "'--show-failures' is deprecated")
Ejemplo n.º 8
0
def test_add_bad_json_app():
    with open('tests/data/marathon/apps/bad.json') as fd:
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'app', 'add'],
            stdin=fd)

        assert returncode == 1
        assert stdout == b''
        assert stderr.decode('utf-8').startswith('Error loading JSON: ')
Ejemplo n.º 9
0
def test_log_marathon_config():
    returncode, stdout, stderr = exec_command([
        'dcos', 'service', 'log', 'marathon',
        '--ssh-config-file=tests/data/node/ssh_config'
    ])

    assert returncode == 0
    assert len(stdout.decode('utf-8').split('\n')) > 1
    assert b'The --ssh-config-file flag is deprecated.' in stderr
Ejemplo n.º 10
0
def _node():
    returncode, stdout, stderr = exec_command(['dcos', 'node', '--json'])

    assert returncode == 0
    assert stderr == b''

    return [
        n for n in json.loads(stdout.decode('utf-8')) if n['type'] == 'agent'
    ]
Ejemplo n.º 11
0
def _get_app_labels(app_id):
    returncode, stdout, stderr = exec_command(
        ['dcos', 'marathon', 'app', 'show', app_id])

    assert returncode == 0
    assert stderr == b''

    app_json = json.loads(stdout.decode('utf-8'))
    return app_json.get('labels')
Ejemplo n.º 12
0
def test_log_task():
    with app(HELLO_STDERR, 'test-hello-stderr'):
        returncode, stdout, stderr = exec_command([
            'dcos', 'task', 'log', 'test-hello-stderr', 'stderr', '--lines=-1'
        ])

        assert returncode == 0
        assert not stderr
        assert stdout == b'hello\n'
Ejemplo n.º 13
0
def test_bad_configuration(env):
    with update_config('marathon.url', 'http://localhost:88888', env):
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'about'], env=env)

        assert returncode == 1
        assert stdout == b''
        assert stderr.startswith(
            b"URL [http://localhost:88888/v2/info] is unreachable")
Ejemplo n.º 14
0
def test_download_sandbox_to_target():
    with tempdir() as tmp:
        targetdir = '--target-dir=' + tmp + '/sandbox'
        task_id = _get_task_id('download-app')
        returncode, stdout, stderr = exec_command(
            ['dcos', 'task', 'download', task_id, targetdir])

        assert stderr == b''
        assert returncode == 0
        assert os.path.exists(tmp + '/sandbox')
Ejemplo n.º 15
0
def test_leader_show():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'marathon', 'leader', 'show', '--json'])

    result = json.loads(stdout.decode('utf-8'))

    assert returncode == 0
    assert stderr == b''
    assert result['host'] == "marathon.mesos."
    assert 'ip' in result
Ejemplo n.º 16
0
def _pod_add_from_stdin(file_path):
    cmd = _POD_ADD_CMD
    with open(file_path) as fd:
        returncode, stdout, stderr = exec_command(cmd, stdin=fd)

    assert returncode == 0
    assert re.fullmatch(r'Created deployment \S+\n', stdout.decode('utf-8'))
    assert stderr == b''

    watch_all_deployments()
Ejemplo n.º 17
0
def test_package_describe():
    stdout = file_json('tests/data/package/json/test_describe_helloworld.json')

    returncode_, stdout_, stderr_ = exec_command(
        ['dcos', 'package', 'describe', 'helloworld'])

    assert returncode_ == 0
    output = json.loads(stdout_.decode('utf-8'))
    assert output == json.loads(stdout.decode('utf-8'))
    assert stderr_ == b''
Ejemplo n.º 18
0
def test_add_bad_complicated_group():
    with open('tests/data/marathon/groups/complicated_bad.json') as fd:
        returncode, stdout, stderr = exec_command(
            ['dcos', 'marathon', 'group', 'add'], stdin=fd)

        stderr_end = b"""{"message":"Invalid JSON","details":[{"path":"/groups(0)/apps(0)/id","errors":["\'id\' is undefined on object: {}"]}]}"""  # noqa: E501

        assert returncode == 1
        assert stderr_end in stderr
        assert stdout == b''
Ejemplo n.º 19
0
def test_node_table_field_option():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'node', '--field=disk_used:used_resources.disk'])

    assert returncode == 0
    assert stderr == b''
    lines = stdout.decode('utf-8').splitlines()
    assert len(lines) > 2
    assert lines[0].split() == ['HOSTNAME', 'IP', 'ID', 'TYPE', 'REGION',
                                'ZONE', 'DISK_USED']
Ejemplo n.º 20
0
def test_update_invalid_request():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'marathon', 'app', 'update', '{', 'instances'])
    assert returncode == 1
    assert stdout == b''
    stderr = stderr.decode()
    # TODO (tamar): this becomes 'Error: App '/{' does not exist\n"'
    # in Marathon 0.11.0
    assert stderr.startswith('Error on request')
    assert stderr.endswith('HTTP 400: Bad Request\n')
Ejemplo n.º 21
0
def test_node_table_uppercase_field_option():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'node', '--field=TASK_RUNNING'])

    assert returncode == 0
    assert stderr == b''
    lines = stdout.decode('utf-8').splitlines()
    assert len(lines) > 2
    assert lines[0].split() == ['HOSTNAME', 'IP', 'ID', 'TYPE', 'REGION',
                                'ZONE', 'TASK_RUNNING']
Ejemplo n.º 22
0
def test_show_queue():
    with _no_schedule_instance_large_job():
        _run_job('gyarados')

        returncode, stdout, stderr = exec_command(
            ['dcos', 'job', 'queue'])

        assert returncode == 0
        assert 'JOB RUN ID' in stdout.decode('utf-8')
        assert 'gyarados' in stdout.decode('utf-8')
Ejemplo n.º 23
0
def test_search_middle_with_wildcard():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'package', 'search', 'c*s', '--json'])

    assert returncode == 0
    assert b'chronos' in stdout
    assert stderr == b''

    registries = json.loads(stdout.decode('utf-8'))
    assert len(registries['packages']) == 5
Ejemplo n.º 24
0
def test_dcos_dcos_url_env_var(env):
    env['DCOS_DCOS_URL'] = 'http://foobar'

    returncode, stdout, stderr = exec_command(
        ['dcos', 'config', 'show', 'core.dcos_url'], env=env)
    assert returncode == 0
    assert stdout == b"http://foobar\n"
    assert stderr == b''

    env.pop('DCOS_DCOS_URL')
Ejemplo n.º 25
0
def test_show_missing_task():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'marathon', 'task', 'show', 'missing-id'])

    stderr = stderr.decode('utf-8')

    assert returncode == 1
    assert stdout == b''
    assert stderr.startswith("Task '")
    assert stderr.endswith("' does not exist\n")
Ejemplo n.º 26
0
def test_install_certified_packages_cli():
    pkgs = [
        'cassandra',
        'kubernetes',
    ]

    for pkg in pkgs:
        code, _, _ = exec_command(['dcos', 'package', 'install',
                                   '--cli', '--yes', pkg])
        assert code == 0
Ejemplo n.º 27
0
def test_version():
    returncode, stdout, stderr = exec_command(['dcos', '--version'])

    assert returncode == 0
    assert stderr == b''
    versions = stdout.decode('utf-8').split("\n")
    assert versions[0] == "dcoscli.version=SNAPSHOT"
    assert versions[1].startswith("dcos.version")
    assert versions[2].startswith("dcos.commit")
    assert versions[3].startswith("dcos.bootstrap-id")
Ejemplo n.º 28
0
def _add_group_by_stdin(file_path):
    with open(file_path) as fd:
        cmd = ['dcos', 'marathon', 'group', 'add']
        returncode, stdout, stderr = exec_command(cmd, stdin=fd)
        assert returncode == 0
        assert re.fullmatch('Created deployment \S+\n', stdout.decode('utf-8'))
        assert stderr == b''

    # Let's make sure that we don't return until the deployment has finished
    watch_all_deployments()
Ejemplo n.º 29
0
def test_node_dns():
    returncode, stdout, stderr = exec_command(
        ['dcos', 'node', 'dns', 'marathon.mesos', '--json'])

    result = json.loads(stdout.decode('utf-8'))

    assert returncode == 0
    assert stderr == b''
    assert result[0]['host'] == "marathon.mesos."
    assert 'ip' in result[0]
Ejemplo n.º 30
0
def test_uninstall_multiple_frameworknames(zk_znode):
    retcode, _, _ = exec_command([
        'dcos', 'package', 'install',
        'chronos', '--yes', '--options=tests/data/package/chronos-1.json'])
    assert retcode == 0

    retcode, _, _ = exec_command([
        'dcos', 'package', 'install',
        'chronos', '--yes', '--options=tests/data/package/chronos-2.json'])
    assert retcode == 0

    watch_all_deployments()

    _uninstall_chronos(args=['--app-id=chronos-user-1'], returncode=1)
    _uninstall_chronos(args=['--app-id=chronos-user-2'], returncode=1)

    for framework in get_services(args=['--inactive']):
        if framework['name'] == 'chronos-user':
            service_shutdown(framework['id'])