Пример #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)
Пример #2
0
    def _prepare_installer(self, kit_pkg_url):
        """
        Extracts a kit archive and prepares the kit installer for the
        installation process.

        :param kit_pkg_url: the URL to the kit package archive

        :return: the KitInstaller instance

        """
        #
        # Download/copy kit archive.
        #
        kit_src_path = os.path.basename(kit_pkg_url)
        kit_pkg_path = utils.retrieve(
            kit_src_path, kit_pkg_url, self._kits_root)

        #
        # Make sure the kit version is compatible
        #
        kit_meta = utils.get_metadata_from_archive(kit_pkg_path)
        kit_spec = (kit_meta['name'], kit_meta['version'],
                    kit_meta['iteration'])
        requires_core = kit_meta.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            errmsg = 'The {} kit requires tortuga core >= {}'.format(
                kit_meta['name'], requires_core)

            raise OperationFailed(errmsg)

        #
        # Unpack the archive
        #
        kit_dir = utils.unpack_kit_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        try:
            installer = get_kit_installer(kit_spec)()
            assert installer.is_installable()

        except Exception as ex:
            if os.path.exists(kit_dir):
                self._logger.debug(
                    'Removing kit installation directory: {}'.format(kit_dir))
                osUtility.removeDir(kit_dir)
            self._logger.warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        return installer
Пример #3
0
    def cleanup(self):
        # If possible, remove any package sources we added
        self._removePackageSources()

        osUtility.removeFile(self._lockFilePath)

        osUtility.removeFile(self._cm.getProfileNiiFile())

        # Turn off the webservice daemon
        self._disableTortugaws()

        # Restore resolv.conf
        if osUtility.haveBackupFile('/etc/resolv.conf'):
            osUtility.restoreFile('/etc/resolv.conf')

        # Drop database
        dbManager = self._osObjectFactory.getOsApplicationManager(
            self._settings['database']['engine'])

        try:
            dbSchema = self._cm.getDbSchema()

            self.out('  * Removing database [%s]\n' % (dbSchema))

            dbManager.destroyDb(dbSchema)
        except Exception as ex:   # pylint: disable=broad-except
            self._logger.exception(
                'Could not destroy existing db: {}'.format(ex))

        # Remove DB password file
        osUtility.removeFile(self._cm.getDbPasswordFile())

        # Remove CFM secret
        cfmSecretFile = self._cm.getCfmSecretFile()
        if os.path.exists(cfmSecretFile):
            osUtility.removeFile(self._cm.getCfmSecretFile())

        # Generic cleanup
        osUtility.removeLink('/etc/tortuga-release')

        # Cleanup or remove depot directory
        errmsg = 'Removing contents of [%s]' % (self._settings['depotpath'])

        self._logger.debug(errmsg)

        if self._depotCreated:
            self.out('  * %s\n' % (errmsg))

            osUtility.removeDir(self._settings['depotpath'])
        else:
            if self._settings['depotpath']:
                self.out('  * %s\n' % (errmsg))

                tortugaSubprocess.executeCommand(
                    'rm -rf %s/*' % (self._settings['depotpath']))

                self.out('\n')

        if not self._forceCleaning:
            self.out('Consult log(s) for further details.\n')

            self._logger.error('Installation failed')