예제 #1
0
    def test_forceDeletePackages(self):
        #import pdb;pdb.set_trace();
        from agent.tests.unit.test_util import createManifest
        if os.name == 'posix':
            serviceName = 'service4'
            manifestName = 'manifestb'
            try:
                createManifest(
                    self,
                    packages=[
                        "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                        "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"
                    ],
                    service=serviceName,
                    manifest=manifestName)
            except Exception as ex:
                print 'exception thrown during mf %s' % str(ex)

            self.app.delete(url(controller='manifest',
                                action='delete',
                                service=serviceName,
                                manifest=manifestName),
                            expect_errors=True)
            age = pylons.config['packageMgr_package_age']
            pylons.config['packageMgr_package_age'] = 86400
            minage = pylons.config['packageMgr_package_min_age']
            pylons.config['packageMgr_package_min_age'] = 0.0
            #appGlobal = pylons.config['pylons.app_globals']
            #appGlobal.packageMgr.start()
            disk_threshold = pylons.config[
                'health_disk_usage_percent_threshold']
            pylons.config['health_disk_usage_percent_threshold'] = 1
            pylons.config['health_disk_usage_gc_threshold'] = 1

            pkgs = PackageMgr.packagePath()
            self.assertEquals(len(os.listdir(pkgs)), 4)
            PackageUtil.forceCleanUpDownloadedPkgs()
            self.assertEquals(len(os.listdir(pkgs)), 0)
            pylons.config['packageMgr_package_age'] = age
            pylons.config['packageMgr_package_min_age'] = minage
            pylons.config[
                'health_disk_usage_percent_threshold'] = disk_threshold
예제 #2
0
    def run(self):
        """
        the garbage collection thread body
        go through the list of packages and delete packages over a certain threshold
        two variables affect operation
        packageMgr_gc_freq = how log GC sleeps for between checks
        pacageMgr_package_age = how old a package can get to before it's deleted

        go through the list of inprogress threads and remove all threads that are done
        """
        #pylint:disable=R0914, R0912, R0915
        while (self.__stop == False):
            time.sleep(self.__garbageFreq)

            try:
                # GC in progress hash
                self.__inProgressLock.acquire()
                try:
                    for key in self.__inProgressPackages.keys():
                        if (not self.__inProgressPackages[key].isAlive()):
                            del self.__inProgressPackages[key]

                finally:
                    self.__inProgressLock.release()

                if not self.__stop:
                    # go through all the packages and see if they are older than the threshold
                    for filename in glob.glob(
                            os.path.join(PackageMgr.packagePath(),
                                         '*.cronus.inprogress')):
                        if (time.time() > os.path.getatime(filename) + float(
                                pylons.config['packageMgr_package_age'])):
                            try:
                                GCLOG.info('Garbage collecting package(%s)' %
                                           filename)
                                LOG.info('Garbage collecting package(%s)' %
                                         filename)
                                os.remove(filename)
                            except OSError, osErr:
                                GCLOG.error(
                                    'Unable to garbage collect %s - %s' %
                                    (filename, osErr))
                                LOG.error('Unable to garbage collect %s - %s' %
                                          (filename, osErr))

                    for filename in glob.glob(
                            os.path.join(PackageMgr.packagePath(),
                                         '*.cronus')):
                        LOG.debug(
                            'garbage collection check in progress for filename %s'
                            % filename)
                        try:
                            if (time.time(
                            ) > os.path.getatime(filename) + float(
                                    pylons.config['packageMgr_package_age'])):
                                LOG.info('Garbage collecting package(%s)' %
                                         filename)
                                os.remove(filename)
                                if os.path.exists(filename + '.prop'):
                                    os.remove(filename + '.prop')
                                if os.path.exists(filename + '.torrent'):
                                    os.remove(filename + '.torrent')
                                if os.path.exists(filename + '.inprogress'):
                                    os.remove(filename + '.inprogress')
                        except OSError, osErr:
                            GCLOG.error('Unable to garbage collect %s - %s' %
                                        (filename, osErr))
                            LOG.error('Unable to garbage collect %s - %s' %
                                      (filename, osErr))
                    #appGlobal = pylons.config['pylons.app_globals']
                #import pdb;pdb.set_trace();
                if not self.__stop:
                    PackageUtil.cleanupOrphanedPackages(False)

                packageMount = pylons.config['agent_root']

                if (not self.__stop
                        and agenthealth.needAggressiveGC(packageMount)):
                    PackageUtil.forceCleanUpDownloadedPkgs()

                # validate all services and remove rogue services
                PackageMgr.cleanRogueService()
예제 #3
0
    def run(self):
        """
        the garbage collection thread body
        go through the list of packages and delete packages over a certain threshold
        two variables affect operation
        packageMgr_gc_freq = how log GC sleeps for between checks
        pacageMgr_package_age = how old a package can get to before it's deleted

        go through the list of inprogress threads and remove all threads that are done
        """
        #pylint:disable=R0914, R0912, R0915
        while (self.__stop == False):
            time.sleep(self.__garbageFreq)

            try: 
                # GC in progress hash
                self.__inProgressLock.acquire()
                try:
                    for key in self.__inProgressPackages.keys():
                        if (not self.__inProgressPackages[key].isAlive()):
                            del self.__inProgressPackages[key]
    
                finally:
                    self.__inProgressLock.release()
    
    
                if not self.__stop:
                    # go through all the packages and see if they are older than the threshold
                    for filename in glob.glob(os.path.join(PackageMgr.packagePath(), '*.cronus.inprogress')):
                        if (time.time() > os.path.getatime(filename) + float(pylons.config['packageMgr_package_age'])):
                            try:
                                GCLOG.info('Garbage collecting package(%s)' % filename)
                                LOG.info('Garbage collecting package(%s)' % filename)
                                os.remove(filename)
                            except OSError, osErr:
                                GCLOG.error('Unable to garbage collect %s - %s' % (filename, osErr))
                                LOG.error('Unable to garbage collect %s - %s' % (filename, osErr))
                        
                    for filename in glob.glob(os.path.join(PackageMgr.packagePath(), '*.cronus')):
                        LOG.debug('garbage collection check in progress for filename %s' % filename)
                        try:
                            if (time.time() > os.path.getatime(filename) + float(pylons.config['packageMgr_package_age'])):
                                LOG.info('Garbage collecting package(%s)' % filename)
                                os.remove(filename)
                                if os.path.exists(filename + '.prop'):
                                    os.remove(filename + '.prop')
                                if os.path.exists(filename + '.torrent'):
                                    os.remove(filename + '.torrent')
                                if os.path.exists(filename + '.inprogress'):
                                    os.remove(filename + '.inprogress')
                        except OSError, osErr:
                            GCLOG.error('Unable to garbage collect %s - %s' % (filename, osErr))
                            LOG.error('Unable to garbage collect %s - %s' % (filename, osErr))
                    #appGlobal = pylons.config['pylons.app_globals']
                #import pdb;pdb.set_trace();
                if not self.__stop:
                    PackageUtil.cleanupOrphanedPackages(False)
    
                packageMount = pylons.config['agent_root']
    
                if(not self.__stop and agenthealth.needAggressiveGC(packageMount)):
                    PackageUtil.forceCleanUpDownloadedPkgs()
                    
                # validate all services and remove rogue services
                PackageMgr.cleanRogueService()