Beispiel #1
0
def test_repo_tgz_with_invalid_path(mocker, tmpdir_function):
    project_path = ""
    dest_dir = tmpdir_function / 'some_path'

    mocker.patch.object(utils, 'run_subprocess_cmd', autospec=True)

    with pytest.raises(ValueError) as exec:
        utils.repo_tgz(dest_dir, project_path)

    assert "project path is not specified" in str(exec.value)
    def _prepare_repo(self):
        if self.state.repo_tgz:
            logger.info(
                f"Using '{self.state.repo_tgz}' as a repo source archive")
            self.fileroot_copy(self.state.repo_tgz, 'repo.tgz')
        elif self.state.repo_path:
            logger.info(f"Preparing local repo '{self.state.repo_path}'"
                        f" of version '{self.state.repo_version}' for a setup")

            # ensure parent dirs exists in profile file root
            self.repo_tgz_root_path.parent.mkdir(parents=True, exist_ok=True)

            utils.repo_tgz(
                self.repo_tgz_root_path,
                project_path=self.state.repo_path,
                version=self.state.repo_version,
                # TODO FIXME hard-coded
                include_dirs=['pillar', 'srv', 'files', 'api', 'cli'])
Beispiel #3
0
def test_repo_tgz_happy_path_with_ver(mocker, tmpdir_function):
    dest_dir = tmpdir_function / 'repo_tgz_path'
    project_path = 'some-project-path'
    version = '1.0'
    include_dirs = ['dir1', 'dir2']

    run_m = mocker.patch.object(utils, 'run_subprocess_cmd', autospec=True)

    assert utils.repo_tgz(dest_dir,
                          project_path=project_path,
                          version=version,
                          include_dirs=include_dirs) == dest_dir
    run_m.assert_called_once_with(
        ['git', 'archive', '--format=tar.gz', version, '-o',
         str(dest_dir)] + include_dirs)
Beispiel #4
0
def test_repo_tgz_happy_path_no_ver(mocker, tmpdir_function):
    dest_dir = tmpdir_function / 'repo_tgz_path'
    exclude = "excluded"
    project_path = 'some-path'
    include_dirs = ['dir1', 'dir2']

    mocker.patch.object(utils,
                        'get_repo_archive_exclusions',
                        autospec=True,
                        return_value=[exclude])
    run_m = mocker.patch.object(utils, 'run_subprocess_cmd', autospec=True)

    assert utils.repo_tgz(dest_dir,
                          project_path=project_path,
                          include_dirs=include_dirs) == dest_dir
    run_m.assert_called_once_with(
        ['tar', '-czf',
         str(dest_dir), exclude, '-C', project_path] + include_dirs)
def test_repo_tgz_happy_path_no_ver(mocker, tmpdir_function):
    dest_dir = tmpdir_function / 'repo_tgz_path'
    project_path = 'some-path'
    include_dirs = ['dir1', 'dir2']

    class somecls:
        pass

    mock_ret = somecls()
    mock_ret.stdout = 'tar (GNU tar) 1.30'

    run_m = mocker.patch.object(utils,
                                'run_subprocess_cmd',
                                autospec=True,
                                return_value=mock_ret)

    assert utils.repo_tgz(dest_dir,
                          project_path=project_path,
                          include_dirs=include_dirs) == dest_dir

    run_m.assert_called_with(['tar', '-czf', str(dest_dir)] + [
        '--exclude-vcs', '--exclude-from',
        str(config.PROJECT_PATH / '.gitignore'), '--sort', 'name'
    ] + ['-C', project_path] + include_dirs)
Beispiel #6
0
def repo_tgz(project_path, localhost, tmpdir_session):
    res = tmpdir_session / 'repo.tgz'
    return utils.repo_tgz(res, project_path=project_path)