Example #1
0
    def cleanupPackages(orphanpkgs):
        '''removes folders under installed-packages which does not have
           any manifest reference. Age is not a factor for cleanup. All orphans are cleaned-up


           Need to check for packages of interest(packages for which create is going on etc.
           '''
        from agent.lib.agent_thread.service_delete import ServiceDelete
        import time
        for pkg in orphanpkgs:
            LOG.debug('attempting to cleanup Installed pkg %s' % pkg)
            if (os.path.exists(pkg) and
                (time.time() > (os.path.getctime(pkg) + float(
                    pylons.config['packageMgr_install_package_min_age'])))):
                parentPkg = os.path.dirname(pkg)
                try:
                    LOG.debug(
                        'attempting to delete folder contents of package %s' %
                        pkg)
                    ServiceDelete.deleteFolderContents(pkg)
                    if os.listdir(parentPkg).__len__() <= 0:
                        ServiceDelete.deleteFolderContents(parentPkg)
                        LOG.debug(
                            'attempting to delete folder contents of package %s'
                            % parentPkg)
                except Exception as ex:
                    LOG.error('Unable to garbage collect %s - %s' % (pkg, ex))
    def __deleteServices(self):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress = 60)
        services = ServiceController.getServices()

        #kill all service threads
        self._threadMgr.stopServiceThread()

        #remove folder
        for service in services:
            if 'agent' == service:
                self.__delAllExceptActiveManifests(service)
                continue

            path = ServiceController.servicePath(service)
            # retry service cleanup
            for _ in range(3):
                if not os.path.exists(path):
                    break
                ServiceDelete.deleteFolderContents(path)
                # sleep here a bit to ensure delete is complete
                time.sleep(1)

            if os.path.exists(path):
                msg = 'Could not delete service %s completely even after 3 retries.' % service
                LOG.error(msg)
                raise Exception(msg)

        self._updateStatus(progress = 90)
Example #3
0
    def __deleteServices(self):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress=60)
        services = ServiceController.getServices()

        #kill all service threads
        self._threadMgr.stopServiceThread()

        #remove folder
        for service in services:
            if 'agent' == service:
                self.__delAllExceptActiveManifests(service)
                continue

            path = ServiceController.servicePath(service)
            # retry service cleanup
            for _ in range(3):
                if not os.path.exists(path):
                    break
                ServiceDelete.deleteFolderContents(path)
                # sleep here a bit to ensure delete is complete
                time.sleep(1)

            if os.path.exists(path):
                msg = 'Could not delete service %s completely even after 3 retries.' % service
                LOG.error(msg)
                raise Exception(msg)

        self._updateStatus(progress=90)
Example #4
0
 def __delAllExceptActiveManifests(self, service):
     '''
     Delete all manifests in the given service except active link and corresponding manifest (if one exists).
     Doesn't delete the corresponding dir in installed-packages (similar to 'delete manifest')
     '''
     manifests = ManifestController.getManifests(service)
     active = ManifestController.getActiveManifest(service)
     if active and len(active) != 0:  # 'active' can be none
         manifests.remove(active)
     for mft in manifests:
         mf_path = ManifestController.manifestPath(service, mft)
         ServiceDelete.deleteFolderContents(mf_path)
 def __delAllExceptActiveManifests(self, service):
     '''
     Delete all manifests in the given service except active link and corresponding manifest (if one exists).
     Doesn't delete the corresponding dir in installed-packages (similar to 'delete manifest')
     '''
     manifests = manifestutil.getManifests(service)
     active = manifestutil.getActiveManifest(service)
     if active and len(active) != 0: # 'active' can be none
         manifests.remove(active)
     for mft in manifests:
         mf_path = manifestutil.manifestPath(service, mft)
         ServiceDelete.deleteFolderContents(mf_path)
Example #6
0
 def cleanupInstalledPkgs(installedPkgPath, orphanPkgs):
     '''removes folders under installed-packages which does not have
        any manifest reference'''
     from agent.lib.agent_thread.service_delete import ServiceDelete
     import time
     #import pdb; pdb.set_trace()
     for pkg in orphanPkgs:
         if (os.path.exists(pkg) and (time.time() > (os.path.getctime(pkg) + float(pylons.config['packageMgr_install_package_min_age'])))):
             parentPkg = os.path.dirname(pkg)
             try :
                 LOG.info('Garbage collecting folder contents of package %s' % pkg)
                 ServiceDelete.deleteFolderContents(pkg)
                 if os.listdir(parentPkg).__len__() <= 0:
                     ServiceDelete.deleteFolderContents(parentPkg)
                     LOG.info('attempting to delete folder contents of package %s' % parentPkg)
             except Exception as ex:
                 LOG.error('Unable to garbage collect %s - %s' % (pkg, ex))
         LOG.info('Completed cleanup Installed pkg %s' % pkg)
    def __deleteService(self, service):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress = 60)
        #remove folder
        path = manifestutil.servicePath(service)
        # retry service cleanup
        for _ in range(3):
            if not os.path.exists(path):
                break
            ServiceDelete.deleteFolderContents(path)
            # sleep here a bit to ensure delete is complete
            time.sleep(1)

        if os.path.exists(path):
            msg = 'Could not delete service %s completely even after 3 retries.' % service
            LOG.error(msg)
            raise Exception(msg)

        self._updateStatus(progress = 90)
Example #8
0
    def cleanupPackages(orphanpkgs):
        '''removes folders under installed-packages which does not have
           any manifest reference. Age is not a factor for cleanup. All orphans are cleaned-up


           Need to check for packages of interest(packages for which create is going on etc.
           '''
        from agent.lib.agent_thread.service_delete import ServiceDelete
        import time
        for pkg in orphanpkgs:
            LOG.debug('attempting to cleanup Installed pkg %s' % pkg)
            if (os.path.exists(pkg) and (time.time() > (os.path.getctime(pkg) + float(pylons.config['packageMgr_install_package_min_age'])))):
                parentPkg = os.path.dirname(pkg)
                try :
                    LOG.debug('attempting to delete folder contents of package %s' % pkg)
                    ServiceDelete.deleteFolderContents(pkg)
                    if os.listdir(parentPkg).__len__() <= 0:
                        ServiceDelete.deleteFolderContents(parentPkg)
                        LOG.debug('attempting to delete folder contents of package %s' % parentPkg)
                except Exception as ex:
                    LOG.error('Unable to garbage collect %s - %s' % (pkg, ex))
Example #9
0
 def cleanupInstalledPkgs(installedPkgPath, orphanPkgs):
     '''removes folders under installed-packages which does not have
        any manifest reference'''
     from agent.lib.agent_thread.service_delete import ServiceDelete
     import time
     #import pdb; pdb.set_trace()
     for pkg in orphanPkgs:
         if (os.path.exists(pkg) and
             (time.time() > (os.path.getctime(pkg) + float(
                 pylons.config['packageMgr_install_package_min_age'])))):
             parentPkg = os.path.dirname(pkg)
             try:
                 LOG.info(
                     'Garbage collecting folder contents of package %s' %
                     pkg)
                 ServiceDelete.deleteFolderContents(pkg)
                 if os.listdir(parentPkg).__len__() <= 0:
                     ServiceDelete.deleteFolderContents(parentPkg)
                     LOG.info(
                         'attempting to delete folder contents of package %s'
                         % parentPkg)
             except Exception as ex:
                 LOG.error('Unable to garbage collect %s - %s' % (pkg, ex))
         LOG.info('Completed cleanup Installed pkg %s' % pkg)
Example #10
0
 def __cleanupShareFolder(self):
     """ cleanup all files in share folder,
     """
     shareFolder = ServiceController.shareFolderPath()
     ServiceDelete.deleteFolderContents(shareFolder, onlyChildren=True)
Example #11
0
 def __deletePackages(self):
     """ delete all packages from pakcage directory """
     package_path = PackageMgr.packagePath()
     ServiceDelete.deleteFolderContents(package_path, onlyChildren=True)
 def __deletePackages(self):
     """ delete all packages from pakcage directory """
     package_path = PackageMgr.packagePath()
     ServiceDelete.deleteFolderContents(package_path, onlyChildren = True)
Example #13
0
 def __cleanupShareFolder(self):
     """ cleanup all files in share folder,
     """
     shareFolder = ServiceController.shareFolderPath()
     ServiceDelete.deleteFolderContents(shareFolder, onlyChildren = True)