Example #1
0
 def __init__(self, mountPoint):
     objectStorePath = os.path.join(mountPoint, "var", "lib", "osmosis",
                                    "objectstore")
     self._objectStore = objectstore.ObjectStore(objectStorePath)
     before = disk.dfPercent(mountPoint)
     if self._objectStoreExists():
         self._attemptObjectStoreCleanup()
     logging.info(
         "Disk usage: before cleanup: %(before)s%%, after: %(after)s%%",
         dict(before=before, after=disk.dfPercent(mountPoint)))
     if disk.dfPercent(mountPoint) > self.ALLOWED_DISK_USAGE_PERCENT:
         logging.info("Erasing disk - osmosis cleanup did not help")
         self._eraseEverything(mountPoint)
Example #2
0
 def test_Policy_CleanupRemoveLabelsUntilDiskUsage(self):
     self.client.writeFile("aFile", "123456")
     self.client.checkin("yuvu1")
     self.client.checkin("yuvu2")
     self.client.checkin("yuvu3")
     self.client.checkin("yuvu4")
     self.client.checkin("yuvu5")
     fakeshell.makeDfSensitiveToLabels(
         100 / 5, self.server.path, os.path.join(self.server.path, 'labels'))
     objectStore = objectstore.ObjectStore(self.server.path)
     self.assertEquals(len(objectStore.labels()), 5)
     tested = cleanupremovelabelsuntildiskusage.CleanupRemoveLabelsUntilDiskUsage(objectStore, 50)
     tested.go()
     self.assertEquals(len(objectStore.labels()), 2)
Example #3
0
 def __init__(self,
              mountPoint,
              usageUpperThreshold=ALLOWED_DISK_USAGE_PERCENT,
              isErase=False):
     self._usageUpperThreshold = usageUpperThreshold
     objectStorePath = os.path.join(mountPoint, "var", "lib", "osmosis",
                                    "objectstore")
     self._objectStore = objectstore.ObjectStore(objectStorePath)
     before = disk.dfPercent(mountPoint)
     if self._objectStoreExists() and isErase:
         self._attemptObjectStoreCleanup()
     logging.info(
         "Disk usage: before cleanup: %(before)s%%, after: %(after)s%%",
         dict(before=before, after=disk.dfPercent(mountPoint)))
     diskUsage = disk.dfPercent(mountPoint)
     if diskUsage > self._usageUpperThreshold:
         if isErase:
             logging.info("Erasing disk - osmosis cleanup did not help")
             self._eraseEverything(mountPoint)
         else:
             msg = "Disk usage is - %s bigger than the upper threshold - %s" \
                   "and inaugurator was configured not to wipe objectstore" % \
                   (diskUsage, self._usageUpperThreshold)
             raise Exception(msg)
Example #4
0
logging.basicConfig(level=logging.INFO)

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="cmd")
labelsOlder = subparsers.add_parser("labelsOlder")
labelsOlder.add_argument("--hours", type=int, required=True)
labelsOlder.add_argument("--regex", required=True)
eraseLabelsOlder = subparsers.add_parser("eraseLabelsOlder")
eraseLabelsOlder.add_argument("--hours", type=int, required=True)
eraseLabelsOlder.add_argument("--regex", required=True)
eraseLabelsOlder.add_argument("--iamsure", action="store_true")
parser.add_argument("--objectStore", default="/var/lib/osmosis/objectstore")
args = parser.parse_args()

if args.cmd == "labelsOlder":
    objectStore = objectstore.ObjectStore(args.objectStore)
    regex = re.compile(args.regex)
    for label, ageHours in objectStore.labelsOlder(args.hours).iteritems():
        if regex.search(label) is None:
            continue
        print "%s: %d hours old" % (label, ageHours)
elif args.cmd == "eraseLabelsOlder":
    objectStore = objectstore.ObjectStore(args.objectStore)
    regex = re.compile(args.regex)
    for label, ageHours in objectStore.labelsOlder(args.hours).iteritems():
        if regex.search(label) is None:
            continue
        if args.iamsure:
            objectStore.eraseLabel(label)
        else:
            print "would have erased %s, which is %d hours old, but you must specify --iamsure" % (
Example #5
0
        withoutHash = {}
        for label, age in labels.iteritems():
            if not label.startswith("solvent__"):
                continue
            without = label.split("__")
            without[3:4] = []
            without = "__".join(without)
            withoutHash.setdefault(without, []).append((age, label))
            withoutHash[without].sort()
        removed = False
        for without, labels in withoutHash.iteritems():
            if len(labels) <= self._last:
                continue
            logging.info(
                "'%(without)s' has %(labelsCount)d entries, removing %(removeCount)d",
                dict(without=without,
                     labelsCount=len(labels),
                     removeCount=len(labels) - self._last))
            for age, label in labels[self._last:]:
                objectStore.eraseLabel(label)
                removed = True
        if removed:
            objectStore.purge()


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    from osmosis import objectstore
    objectStore = objectstore.ObjectStore("/var/lib/osmosis/objectstore")
    CleanupLeaveLast(objectStore).go()