Beispiel #1
0
    def audit_snapshots(self, clean):
        """
        Display a list of snapshots that should not exist and
        need to be cleaned up
        """
        helper = self.load_conf(self.config)
        first = audit.snapshots(helper)
        if not len(first):
            return 0

        # Sleep for a second, then check again
        sleep(1)
        second = audit.snapshots(helper)

        # If the lists do not match, something must have
        # changed while we were sleeping
        if not audit.compare_lists(first, second, key='snapshot'):
            return self.audit_snapshots(clean=clean)

        # At this point we know the snapshots in the first list
        # Are verifiably bad, and not apart of a transient backup,
        # or clone operation
        print "\nThe following Snapshots should not exist, " \
            "and need to be cleaned up (Use --clean to remove these snapshots)"
        self.display(first)
        if clean:
            lvs = [lv for lv in helper.volumes._scan_volumes()
                   if lv['origin'] != '']
            for snap in first:
                lv = audit.find(snap['snapshot'], lvs)
                helper.volumes.remove_lvm_snapshot(lv)
        return 1
Beispiel #2
0
    def audit_snapshots(self, clean):
        """
        Display a list of snapshots that should not exist and
        need to be cleaned up
        """
        helper = self.load_conf(self.config)
        first = audit.snapshots(helper)
        if not len(first):
            return 0

        # Sleep for a second, then check again
        sleep(1)
        second = audit.snapshots(helper)

        # If the lists do not match, something must have
        # changed while we were sleeping
        if not audit.compare_lists(first, second, key='snapshot'):
            return self.audit_snapshots(clean=clean)

        # At this point we know the snapshots in the first list
        # Are verifiably bad, and not apart of a transient backup,
        # or clone operation
        print "\nThe following Snapshots should not exist, " \
            "and need to be cleaned up (Use --clean to remove these snapshots)"
        self.display(first)
        if clean:
            lvs = [
                lv for lv in helper.volumes._scan_volumes()
                if lv['origin'] != ''
            ]
            for snap in first:
                lv = audit.find(snap['snapshot'], lvs)
                helper.volumes.remove_lvm_snapshot(lv)
        return 1
Beispiel #3
0
 def test_no_problems(self):
     self.resp = [{
         'id': '33485eb3-5900-4068-93a1-2b72677fd699',
         'status': 'SAVING',
     }, {
         'id': '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b',
         'status': 'CLONING',
     }]
     # Should not report any issue, there are 2 snapshots and API reports
     # they are both CLONING and SAVING
     self.assertEquals(audit.snapshots(self.helper), [])
Beispiel #4
0
 def test_no_problems(self):
     self.resp = [{
         'id': '33485eb3-5900-4068-93a1-2b72677fd699',
         'status': 'SAVING',
         }, {
         'id': '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b',
         'status': 'CLONING',
         }]
     # Should not report any issue, there are 2 snapshots and API reports
     # they are both CLONING and SAVING
     self.assertEquals(audit.snapshots(self.helper), [])
Beispiel #5
0
 def test_bad_clone(self):
     self.resp = [{
         'id': '33485eb3-5900-4068-93a1-2b72677fd699',
         'status': 'SAVING',
     }, {
         'id': '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b',
         'status': 'ACTIVE',
     }]
     # Should report 1 issue, the API reports the backup is AVAILABLE
     result = audit.snapshots(self.helper)
     self.assertEquals(result[0]['snapshot'],
                       '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b')
     self.assertNotEqual(result[0]['msg'], None)
Beispiel #6
0
 def test_bad_clone(self):
     self.resp = [{
         'id': '33485eb3-5900-4068-93a1-2b72677fd699',
         'status': 'SAVING',
         }, {
         'id': '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b',
         'status': 'ACTIVE',
         }]
     # Should report 1 issue, the API reports the backup is AVAILABLE
     result = audit.snapshots(self.helper)
     self.assertEquals(result[0]['snapshot'],
                       '70bde49f-0ca7-4fe1-bce4-b5a73f850b8b')
     self.assertNotEqual(result[0]['msg'], None)