def test_print_report(): assert Printer.print_report({}) is None with open("tests/mocks/ami.json") as mock_file: json_to_parse = json.load(mock_file) ami = AMI.object_with_json(json_to_parse) candidates = [ami] assert Printer.print_report(candidates) is None
def test_print_report(): assert Printer.print_report({}) is None with open("tests/mocks/ami.json") as mock_file: json_to_parse = json.load(mock_file) ami = AMI.object_with_json(json_to_parse) candidates = {'test': [ami]} assert Printer.print_report(candidates) is None assert Printer.print_report(candidates, full_report=True) is None
def prepare_delete_amis(self, candidates, from_ids=False): """ Prepare deletion of candidates AMIs""" failed = [] if from_ids: print(TERM.bold("\nCleaning from {} AMI id(s) ...".format( len(candidates)) )) failed = AMICleaner().remove_amis_from_ids(candidates) else: print(TERM.bold("\nCleaning {} AMIs ...".format(len(candidates)))) failed = AMICleaner().remove_amis(candidates) if failed: print(TERM.red("\n{0} failed snapshots".format(len(failed)))) Printer.print_failed_snapshots(failed)
def clean_orphans(self): """ Find and removes orphan snapshots """ cleaner = OrphanSnapshotCleaner() snaps = cleaner.fetch() if not snaps: return Printer.print_orphan_snapshots(snaps) answer = input( "Do you want to continue and remove {} orphan snapshots " "[y/N] ? : ".format(len(snaps))) confirm = (answer.lower() == "y") if confirm: print("Removing orphan snapshots... ") count = cleaner.clean(snaps) print("\n{0} orphan snapshots successfully removed !".format(count))
def prepare_candidates(self, candidates_amis=None): """ From an AMI list apply mapping strategy and filters """ candidates_amis = candidates_amis or self.fetch_candidates() if not candidates_amis: return None c = AMICleaner() mapped_amis = c.map_candidates( candidates_amis=candidates_amis, mapping_strategy=self.mapping_strategy, ) if not mapped_amis: return None candidates = [] report = dict() for group_name, amis in mapped_amis.items(): group_name = group_name or "" if not group_name: report["no-tags (excluded)"] = amis else: reduced = c.reduce_candidates(amis, self.keep_previous, self.ami_min_days) if reduced: report[group_name] = reduced candidates.extend(reduced) Printer.print_report(report, self.full_report) return candidates
def test_print_orphan_snapshots(): assert Printer.print_orphan_snapshots({}) is None assert Printer.print_orphan_snapshots(["ami-one", "ami-two"]) is None