示例#1
0
文件: command.py 项目: cathong/dcos
    def _handle_pkg_dir_setup(self, package: Package):
        """Transfer files from special directories into location.

        :param package: Package, DC/OS package manager object
        """
        # TODO: Move this functionality to a method of the Package class and
        #       reuse it in CmdSetup and CmdUpgrade classes to avoid code
        #       duplication.
        pkg_path = getattr(
            package.manifest.istor_nodes, ISTOR_NODE.PKGREPO
        ).joinpath(package.manifest.pkg_id.pkg_id)
        root = getattr(
            package.manifest.istor_nodes, ISTOR_NODE.ROOT
        )

        for name in ('bin', 'etc', 'include', 'lib'):
            srcdir = pkg_path / name
            if srcdir.exists():
                LOG.info(
                    'Install directory %s for package %s',
                    name, package.id.pkg_name
                )
                dstdir = root / name
                dstdir.mkdir(exist_ok=True)
                cm_utl.transfer_files(str(srcdir), str(dstdir))
示例#2
0
def test_transfer_files_should_call_mkdir_and_link(mock_mkdir, mock_link,
                                                   *args):
    """Check transfer files in to new directory mkdir and link invocation."""
    utils.transfer_files('/tmp/.000', '/tmp/.001')
    # Mocked file names not specified because of OS different directory separators
    assert mock_mkdir.called
    assert mock_link.called
示例#3
0
    def setup_conf(self):
        """Setup configuration objects for a DC/OS package."""
        pkg_id = self._pkg_manifest.pkg_id
        pkg_cfg_dpath = getattr(self._pkg_manifest.istor_nodes,
                                ISTOR_NODE.PKGREPO).joinpath(
                                    pkg_id.pkg_id, cr_const.PKG_CFG_DNAME)
        LOG.debug(f'{self.msg_src}: Setup configuration: {pkg_id.pkg_name}:'
                  f' Source directory path: {pkg_cfg_dpath}')

        config_dir = getattr(self._pkg_manifest.istor_nodes, ISTOR_NODE.CFG)
        pkg_shrcfg_dpath = config_dir.joinpath(pkg_id.pkg_name)
        LOG.debug(f'{self.msg_src}: Setup configuration: {pkg_id.pkg_name}:'
                  f' Destination directory path: {pkg_shrcfg_dpath}')

        pkg_context = self._pkg_manifest.context

        if pkg_cfg_dpath.exists():
            # Check source is a directory
            if pkg_cfg_dpath.is_symlink():
                err_msg = (f'Source directory: Symlink conflict:'
                           f' {pkg_cfg_dpath}')
                raise cfgm_exc.PkgConfInvalidError(err_msg)
            elif pkg_cfg_dpath.is_reserved():
                err_msg = (f'Source directory: Reserved name conflict:'
                           f' {pkg_cfg_dpath}')
                raise cfgm_exc.PkgConfInvalidError(err_msg)
            elif not pkg_cfg_dpath.is_dir():
                err_msg = (f'Source directory: Not a directory:'
                           f' {pkg_cfg_dpath}')
                raise cfgm_exc.PkgConfInvalidError(err_msg)

            # Ensure destination exists and is a directory
            try:
                pkg_shrcfg_dpath.mkdir(parents=True, exist_ok=True)
            except FileExistsError:
                raise cr_exc.InstallationStorageError(
                    f'Setup configuration: {pkg_id.pkg_name}:'
                    f' {pkg_shrcfg_dpath} exists but is not a directory')

            try:
                with tf.TemporaryDirectory(dir=str(config_dir)) as tdp:

                    self._process_pkgconf_srcdir(src_dpath=pkg_cfg_dpath,
                                                 tmp_dpath=Path(tdp),
                                                 context=pkg_context)
                    transfer_files(tdp, str(pkg_shrcfg_dpath))
                    LOG.debug(
                        f'{self.msg_src}: Setup configuration:'
                        f' {pkg_id.pkg_name}: Save: {pkg_shrcfg_dpath}: OK')
            except (OSError, RuntimeError) as e:
                err_msg = (f'Setup configuration: {pkg_id.pkg_name}:'
                           f' Process configuration sources:'
                           f' {pkg_cfg_dpath}: {type(e).__name__}: {e}')
                raise cfgm_exc.PkgConfManagerError(err_msg)
        else:
            err_msg = f'Source directory: Not found: {pkg_cfg_dpath}'
            raise cfgm_exc.PkgConfNotFoundError(err_msg)
示例#4
0
def test_transfer_files(tmp_path):
    src = tmp_path / 'src'
    dst = tmp_path / 'dst'
    src.mkdir()
    dst.mkdir()
    (src / 'sub').mkdir()
    with (src / 'file1').open('w') as f:
        f.write(EXPECTED_FILE_CONTENT)
    with (src / 'sub' / 'file2').open('w') as f:
        f.write(EXPECTED_FILE_CONTENT)
    transfer_files(str(src), str(dst))
    check_file(dst / 'file1')
    check_file(dst / 'sub' / 'file2')
示例#5
0
文件: command.py 项目: tokyodevs/dcos
    def _handle_pkg_dir_setup(self, package):
        """Transfer files from special directories into location.

        :param package: Package, DC/OS package manager object
        """
        pkg_path = getattr(package.manifest.istor_nodes,
                           ISTOR_NODE.PKGREPO).joinpath(
                               package.manifest.pkg_id.pkg_id)
        root = getattr(package.manifest.istor_nodes, ISTOR_NODE.ROOT)

        for name in ('bin', 'etc', 'include', 'lib'):
            srcdir = pkg_path / name
            if srcdir.exists():
                dstdir = root / name
                dstdir.mkdir(exist_ok=True)
                cm_utl.transfer_files(str(srcdir), str(dstdir))