Ejemplo n.º 1
0
    def _cleanup_kit(self, session: Session, kit: Kit, force: bool,
                     skip_db: bool = False):
        """
        Uninstalls the kit and it's file repos.

        :param session: a database session
        :param kit:     the Kit instance
        :param force:   whether or not to force the deletion

        """
        repo_dir = kit.getKitRepoDir()

        #
        # Remove the kit from the DB
        #
        if not skip_db:
            self._kit_db_api.deleteKit(session, kit.getName(),
                                       kit.getVersion(), kit.getIteration(),
                                       force=force)

        #
        # Remove the files and repo
        #
        for repo in repoManager.getRepoList():
            #
            # Delete the repo
            #
            repo.delete(repo_dir)

            #
            # Remove repo files
            #
            full_repo_dir = os.path.join(repo.getLocalPath(), repo_dir)
            self._logger.debug(
                'Removing repo dir: {}'.format(full_repo_dir))
            #
            # When LINKOSKITMEDIA is used, the kit directory is a symlink
            # to the real media, delete the link instead of attempting
            # to delete the directory.
            #
            if os.path.islink(full_repo_dir):
                os.unlink(full_repo_dir)
            else:
                osUtility.removeDir(full_repo_dir)

        #
        # Check and clean up proxy
        #
        self.remove_proxy(repo_dir)

        #
        # Remove the kit installation dir
        #
        kit_dir = os.path.join(self._kits_root, kit.getDirName())
        if os.path.exists(kit_dir):
            self._logger.debug(
                'Removing kit installation directory: {}'.format(kit_dir))
            osUtility.removeDir(kit_dir)
Ejemplo n.º 2
0
    def _delete_kit(self, session: Session, kit: Kit, force: bool):
        """
        Deletes a regular kit.

        :param session: a database instance
        :param kit:     the Kit instance
        :param force:   whether or not to force the deletion

        """
        kit_spec = (kit.getName(), kit.getVersion(), kit.getIteration())

        #
        # If the kit does not exist in the DB, then we want to skip
        # the step of removing it from the DB
        #
        skip_db = False
        try:
            self.getKit(session, *kit_spec)
        except KitNotFound:
            skip_db = True

        kit_install_path = os.path.join(self._kits_root, kit.getDirName())
        if os.path.exists(kit_install_path):

            #
            # Attempt to get the kit installer
            #
            installer = None
            try:
                installer = get_kit_installer(kit_spec)()
                installer.session = session

            except KitNotFound:
                pass

            #
            # Attempt to run pre-uninstall action
            #
            if installer:
                try:
                    installer.run_action('pre_uninstall')
                except Exception as ex:
                    self._logger.warning(
                        'Error running pre_uninstall: {}'.format(
                            str(ex)
                        )
                    )

            #
            # Remove db record and files
            #
            self._cleanup_kit(session, kit, force, skip_db)

            #
            # Attempt to uninstall puppet modules, and perform post-install
            #
            if installer:
                try:
                    installer.run_action('uninstall_puppet_modules')
                except Exception as ex:
                    self._logger.warning(
                        'Error uninstalling puppet modules: {}'.format(
                            str(ex)
                        )
                    )
                try:
                    installer.run_action('post_uninstall')
                except Exception as ex:
                    self._logger.warning(
                        'Error running post-install: {}'.format(
                            str(ex)
                        )
                    )