Ejemplo n.º 1
0
def test_auto_mount(
    basic_dog_config,
    call_main,
    tmp_path,
    mock_execvp,
    home_temp_dir,
    extra_dog_conf: str,
    default_mount_point: bool,
):
    append_to_dog_config(tmp_path, ['image=my_image', extra_dog_conf])
    call_main('my_inside_cmd')
    args_left = assert_docker_std_cmdline(mock_execvp)
    args_left = assert_docker_image_and_cmd_inside_docker(
        args_left, 'my_image', ['my_inside_cmd']
    )
    args_left = assert_workdir_param(args_left, get_workdir(tmp_path))
    args_left = std_assert_hostname_param(args_left)
    if default_mount_point:
        if is_windows():
            args_left = assert_volume_params(args_left, [('/C', 'C:\\')])
        else:
            mount_point = str(find_mount_point(tmp_path))
            args_left = assert_volume_params(args_left, [(mount_point, mount_point)])
    else:
        args_left = assert_volume_params(args_left, [])
    args_left = std_assert_interactive(args_left)
    args_left = std_assert_env_params(home_temp_dir, args_left)
    assert args_left == []
Ejemplo n.º 2
0
def test_user_env_vars(call_centos7, tmp_path, capfd, monkeypatch):
    """Test user-env-vars config param."""

    # First call without the local variable
    monkeypatch.delenv('MY_ENV_VAR', raising=False)
    call_centos7('echo', 'MY_ENV_VAR is $MY_ENV_VAR')
    captured = capfd.readouterr()
    assert 'MY_ENV_VAR is' in captured.out

    # Then set the local variable - but still do not preserve it
    monkeypatch.setenv('MY_ENV_VAR', 'this is preserved')
    call_centos7('echo', 'MY_ENV_VAR is $MY_ENV_VAR')
    captured = capfd.readouterr()
    assert 'MY_ENV_VAR is' in captured.out

    # Then preserve the local variable - expect it to be preserved now
    append_to_dog_config(
        tmp_path,
        [
            'exposed-dog-variables=gid,uid,user,group,home,as-root,preserve-env',
            'user-env-vars=MY_ENV_VAR',
            'preserve-env=MY_ENV_VAR',
        ],
    )
    call_centos7('echo', 'MY_ENV_VAR is $MY_ENV_VAR')
    captured = capfd.readouterr()
    assert 'MY_ENV_VAR is this is preserved' in captured.out
Ejemplo n.º 3
0
def test_volumes(call_centos7, capstrip, tmp_path, system_temp_dir):
    """Test of adding the the 'system temp dir' as a volume in the dog.config."""
    append_to_dog_config(
        tmp_path, ['[volumes]', f'/dog_test_of_system_temp={system_temp_dir}'])
    call_centos7('mountpoint', '/dog_test_of_system_temp')
    captured = capstrip.get()
    assert captured == ('/dog_test_of_system_temp is a mountpoint', '')
Ejemplo n.º 4
0
def test_perforce_enabled(basic_dog_config, call_centos7, capstrip, tmp_path,
                          home_dir_with_perforce_file):
    append_to_dog_config(tmp_path,
                         ['[volumes]', '$home/.p4tickets:ro = ~/.p4tickets'])
    call_centos7('cat', '~/.p4tickets')
    stdout, stderr = capstrip.get()
    assert ('This is a mock p4 tickets file'
            in stdout), f'stdout:\n{stdout}\n\nstderr:\n{stderr}'
Ejemplo n.º 5
0
def test_disabled_auto_mount(call_centos7, capstrip, tmp_path):
    """Test disabling auto-mount

    Disable auto-mount and make sure that we do not see the files in the current
    directory (ls should not show any files).
    """
    append_to_dog_config(tmp_path, ['auto-mount=False'])
    call_centos7('ls')
    captured = capstrip.get()
    assert captured == ('', '')
Ejemplo n.º 6
0
def mock_win32(monkeypatch, tmp_path, win_path, dog_config_contents: List[str]):
    monkeypatch.setattr(sys, 'platform', 'win32')
    monkeypatch.setenv('USERNAME', 'dog_test_user')
    monkeypatch.setattr(Path, 'cwd', lambda: win_path)
    monkeypatch.setattr(os.path, 'isfile', lambda x: True)
    append_to_dog_config(tmp_path, dog_config_contents)
    mrdc = MockReadDogConfig(
        dog.read_dog_config, win_path / 'dog.config', tmp_path / 'dog.config'
    )
    monkeypatch.setattr(dog, 'read_dog_config', mrdc.mocked_read_dog_config)
Ejemplo n.º 7
0
def test_registry(basic_dog_config, call_dog, tmp_path, capstrip):
    append_to_dog_config(
        tmp_path,
        [
            'registry=artifactory.oticon.com/demant-docker-local',
            'image=demant-debian:buster-20211011-slim',
        ],
    )
    call_dog('echo', 'ok')
    assert capstrip.get() == ('ok', '')
Ejemplo n.º 8
0
def call_shell(my_dog, basic_dog_config, monkeypatch, tmp_path):
    if 'win32' in sys.platform:
        monkeypatch.setenv('DOG', f'"{DOG_PYTHON_UNDER_TEST}" "{my_dog}"')
    else:
        monkeypatch.setenv('DOG', f'{DOG_PYTHON_UNDER_TEST} {my_dog}')

    append_to_dog_config(tmp_path, ['image=rtol/git-for-dog'])

    def call(shell_string: str):
        return subprocess.run(shell_string, shell=True, cwd=tmp_path)

    return call
Ejemplo n.º 9
0
def test_commands_in_docker(
    basic_dog_config, call_main, tmp_path, home_temp_dir, mock_execvp, cmds: List[str],
):
    append_to_dog_config(tmp_path, ['image=my_image'])
    call_main(*cmds)
    args_left = assert_docker_std_cmdline(mock_execvp)
    args_left = assert_docker_image_and_cmd_inside_docker(args_left, 'my_image', cmds)
    args_left = assert_workdir_param(args_left, get_workdir(tmp_path))
    args_left = std_assert_hostname_param(args_left)
    args_left = std_assert_volume_params(tmp_path, args_left)
    args_left = std_assert_interactive(args_left)
    args_left = std_assert_env_params(home_temp_dir, args_left)
    assert args_left == []
Ejemplo n.º 10
0
def test_preserve_non_existing_env(call_centos7, tmp_path, capfd, monkeypatch):
    monkeypatch.delenv('NON_EXISTING_VAR', raising=False)
    append_to_dog_config(
        tmp_path,
        [
            'exposed-dog-variables=gid,uid,user,group,home,as-root,preserve-env',
            'user-env-vars-if-set=MY_ENV_VAR',
            'preserve-env=NON_EXISTING_VAR',
        ],
    )
    assert call_centos7('echo', 'NON_EXISTING_VAR is $NON_EXISTING_VAR') == 0
    captured = capfd.readouterr()
    assert 'NON_EXISTING_VAR is' in captured.out
Ejemplo n.º 11
0
def test_pull_latest_demant_debian(basic_dog_config, call_dog, tmp_path,
                                   capstrip):
    """Dummy test used to pull the latest image before the next test

    - this is to make sure that the test does not fail due to lots of
    pullling layer ....blah.balh... output.
    """
    append_to_dog_config(
        tmp_path,
        [
            'registry=artifactory.oticon.com/demant-docker-local',
            'image=demant-debian:buster-20211011-slim',
        ],
    )
    call_dog('echo', 'ok')
Ejemplo n.º 12
0
def test_images(
    basic_dog_config, call_main, tmp_path, mock_execvp, home_temp_dir, image_name: str,
):
    append_to_dog_config(tmp_path, ['image={}'.format(image_name)])
    call_main('echo', 'foo')
    args_left = assert_docker_std_cmdline(mock_execvp)
    args_left = assert_docker_image_and_cmd_inside_docker(
        args_left, image_name, ['echo', 'foo']
    )
    args_left = assert_workdir_param(args_left, get_workdir(tmp_path))
    args_left = std_assert_hostname_param(args_left)
    args_left = std_assert_volume_params(tmp_path, args_left)
    args_left = std_assert_interactive(args_left)
    args_left = std_assert_env_params(home_temp_dir, args_left)
    assert args_left == []
Ejemplo n.º 13
0
def test_sudo_outside(
    basic_dog_config,
    call_main,
    tmp_path,
    mock_execvp,
    home_temp_dir,
    test_sudo: Tuple[str, bool],
):
    append_to_dog_config(tmp_path, ['image=my_image', test_sudo[0]])
    call_main('my_inside_cmd')
    args_left = assert_docker_std_cmdline(mock_execvp, test_sudo[1])
    args_left = assert_docker_image_and_cmd_inside_docker(
        args_left, 'my_image', ['my_inside_cmd']
    )
    args_left = assert_workdir_param(args_left, get_workdir(tmp_path))
    args_left = std_assert_hostname_param(args_left)
    args_left = std_assert_volume_params(tmp_path, args_left)
    args_left = std_assert_interactive(args_left)
    args_left = std_assert_env_params(home_temp_dir, args_left)
    assert args_left == []
Ejemplo n.º 14
0
def test_perforce_enabled_but_no_file(basic_dog_config, call_centos7, tmp_path,
                                      home_temp_dir):
    append_to_dog_config(tmp_path,
                         ['[volumes]', '$home/.p4tickets:ro = ~/.p4tickets'])
    assert call_centos7('env') == 0
Ejemplo n.º 15
0
def test_ssh_enabled(call_shell, capstrip, dog_env, tmp_path):
    append_to_dog_config(tmp_path, ['[volumes]', '$home/.ssh:ro = ~/.ssh'])
    call_shell(
        f'{dog_env} git clone [email protected]:rasmus-toftdahl-olesen/dog.git')
    stdout, stderr = capstrip.get()
    assert 'Could not read from remote repository' not in stderr
Ejemplo n.º 16
0
def test_ssh_enabled_demant(call_shell, capstrip, dog_env, tmp_path):
    append_to_dog_config(tmp_path, ['[volumes]', '$home/.ssh:ro = ~/.ssh'])
    call_shell(f'{dog_env} git clone [email protected]/teamtc/builders')
    stdout, stderr = capstrip.get()
    assert 'Could not read from remote repository' not in stderr
Ejemplo n.º 17
0
def test_bad_registry(call_centos7, tmp_path, capfd):
    append_to_dog_config(tmp_path, ['registry=this-is-a-bad-registry'])
    call_centos7('echo', 'ok')
    assert 'Unable to find image' in capfd.readouterr().err