def build_all_or_selected_groups(config, conn, groups=None): if not groups: groups = [ g for g in groups_from_dict(config["groups"], conn) if g.autostart ] else: groups = [ g for g in groups_from_dict(config["groups"], conn) if g.name in groups ] return groups
def test_groups_from_dict_multiple_groups(build_mock_libvirtconn_filled): """ Test match_domains_from_config with a str pattern """ conn = build_mock_libvirtconn_filled callbacks_registrer = DomExtSnapshotCallbackRegistrer(conn) groups_config = { "test0": { "target": "/mnt/test0", "packager": "tar", "hosts": [ "matching2", ], }, "test1": { "target": "/mnt/test1", "hosts": ["matching", "a"], }, } groups = tuple(groups_from_dict(groups_config, conn, callbacks_registrer)) assert len(groups) == 2 group0, group1 = groups assert sorted((group0.name, group1.name)) == ["test0", "test1"]
def test_groups_from_sanitize_dict_all_config_group_param( build_mock_libvirtconn_filled, ): """ Test with the example config, containing every possible parameter Related to issue #13 """ conn = build_mock_libvirtconn_filled callbacks_registrer = DomExtSnapshotCallbackRegistrer(conn) groups_config = { "test": { "target": "/mnt/test", "packager": "tar", "autostart": True, "hourly": 1, "daily": 3, "weekly": 2, "monthly": 5, "yearly": 1, "hosts": [ {"host": r"r:^matching\d?$", "disks": ["vda", "vdb"]}, "!matching2", "nonexisting", ], }, } group = next(iter(groups_from_dict(groups_config, conn, callbacks_registrer))) for prop in ("hourly", "daily", "weekly", "monthly", "yearly"): assert prop not in group.default_bak_param
def test_groups_from_dict_multiple_filters(build_mock_libvirtconn_filled): """ Test groups_from_dict with only one group, multiple filters Linked to issue #28 """ conn = build_mock_libvirtconn_filled callbacks_registrer = DomExtSnapshotCallbackRegistrer(conn) groups_config = { "test": { "target": "/mnt/test", "packager": "tar", "hosts": [ {"host": "matching", "disks": ["vda", "vdb"]}, {"host": "matching2", "disks": ["vda"]}, ], }, } groups = tuple(groups_from_dict(groups_config, conn, callbacks_registrer)) dombackups = groups[0].backups assert dombackups[0].dom.name() == "matching" assert tuple(sorted(dombackups[0].disks.keys())) == ("vda", "vdb") assert dombackups[1].dom.name() == "matching2" assert tuple(sorted(dombackups[1].disks.keys())) == ("vda",)
def test_groups_from_dict(build_mock_libvirtconn_filled): """ Test groups_from_dict with only one group """ conn = build_mock_libvirtconn_filled callbacks_registrer = DomExtSnapshotCallbackRegistrer(conn) groups_config = { "test": { "target": "/mnt/test", "packager": "tar", "hosts": [ {"host": r"r:^matching\d?$", "disks": ["vda", "vdb"]}, "!matching2", "nonexisting", ], }, } groups = tuple(groups_from_dict(groups_config, conn, callbacks_registrer)) assert len(groups) == 1 test_group = groups[0] assert test_group.default_bak_param["backup_dir"] == "/mnt/test" assert test_group.default_bak_param["packager"] == "tar" dombackups = test_group.backups assert len(dombackups) == 1 matching_backup = dombackups[0] assert matching_backup.dom.name() == "matching" assert tuple(sorted(matching_backup.disks.keys())) == ("vda", "vdb")
def test_groups_from_sanitize_dict_all_config_group_param( build_mock_libvirtconn_filled): """ Test with the example config, containing every possible parameter Related to issue #13 """ conn = build_mock_libvirtconn_filled groups_config = { "test": { "target": "/mnt/test", "compression": "tar", "autostart": True, "hourly": 1, "daily": 3, "weekly": 2, "monthly": 5, "yearly": 1, "hosts": [ {"host": "r:^matching\d?$", "disks": ["vda", "vdb"]}, "!matching2", "nonexisting" ], }, } group = next(iter(groups_from_dict(groups_config, conn))) for prop in ("hourly", "daily", "weekly", "monthly", "yearly"): assert prop not in group.default_bak_param
def test_groups_from_dict(build_mock_libvirtconn_filled): """ Test groups_from_dict with only one group """ conn = build_mock_libvirtconn_filled groups_config = { "test": { "target": "/mnt/test", "compression": "tar", "hosts": [ {"host": "r:^matching\d?$", "disks": ["vda", "vdb"]}, "!matching2", "nonexisting" ], }, } groups = tuple(groups_from_dict(groups_config, conn)) assert len(groups) == 1 test_group = groups[0] target, compression = ( test_group.default_bak_param[k] for k in ("target_dir", "compression") ) assert target == "/mnt/test" assert compression == "tar" dombackups = test_group.backups assert len(dombackups) == 1 matching_backup = dombackups[0] assert matching_backup.dom.name() == "matching" assert tuple(sorted(matching_backup.disks.keys())) == ("vda", "vdb")
def test_groups_from_dict(build_mock_libvirtconn_filled): """ Test groups_from_dict with only one group """ conn = build_mock_libvirtconn_filled groups_config = { "test": { "target": "/mnt/test", "compression": "tar", "hosts": [{ "host": "r:^matching\d?$", "disks": ["vda", "vdb"] }, "!matching2", "nonexisting"], }, } groups = tuple(groups_from_dict(groups_config, conn)) assert len(groups) == 1 test_group = groups[0] target, compression = (test_group.default_bak_param[k] for k in ("target_dir", "compression")) assert target == "/mnt/test" assert compression == "tar" dombackups = test_group.backups assert len(dombackups) == 1 matching_backup = dombackups[0] assert matching_backup.dom.name() == "matching" assert tuple(sorted(matching_backup.disks.keys())) == ("vda", "vdb")
def test_groups_from_dict_multiple_groups( build_mock_libvirtconn_filled): """ Test match_domains_from_config with a str pattern """ conn = build_mock_libvirtconn_filled groups_config = { "test0": { "target": "/mnt/test0", "compression": "tar", "hosts": ["matching2", ], }, "test1": { "target": "/mnt/test1", "hosts": ["matching", "a"], }, } groups = tuple(groups_from_dict(groups_config, conn)) assert len(groups) == 2 group0, group1 = groups assert sorted((group0.name, group1.name)) == ["test0", "test1"]
def test_groups_from_dict_multiple_groups(build_mock_libvirtconn_filled): """ Test match_domains_from_config with a str pattern """ conn = build_mock_libvirtconn_filled groups_config = { "test0": { "target": "/mnt/test0", "compression": "tar", "hosts": [ "matching2", ], }, "test1": { "target": "/mnt/test1", "hosts": ["matching", "a"], }, } groups = tuple(groups_from_dict(groups_config, conn)) assert len(groups) == 2 group0, group1 = groups assert sorted((group0.name, group1.name)) == ["test0", "test1"]