def test_complete_groups_from_dict(build_mock_libvirtconn_filled):
    """
    Test groups_from_dict with only one group
    """
    groups_config = {
        "test": {
            "target":
            "/mnt/test",
            "compression":
            "tar",
            "hosts": [{
                "host": r"r:^matching\d?$",
                "disks": ["vda", "vdb"]
            }, "!matching2", "nonexisting"],
        },
    }

    groups = tuple(complete_groups_from_dict(groups_config))
    assert len(groups) == 1
    test_group = groups[0]

    assert test_group.name == "test"
    assert test_group.backup_dir == "/mnt/test"
    assert test_group.hosts == [
        r"r:^matching\d?$", r"!matching2", r"nonexisting"
    ]
Example #2
0
def get_usable_complete_groups(config, only_groups_in=None, conn=None):
    groups = complete_groups_from_dict(config.get_groups(), conn=conn)
    for g in groups:
        if not g.backup_dir:
            continue
        elif only_groups_in and g.name not in only_groups_in:
            continue
        yield g
def test_complete_groups_from_dict_multiple_groups(
        build_mock_libvirtconn_filled):
    """
    Test match_domains_from_config with a str pattern
    """
    groups_config = {
        "test0": {
            "target": "/mnt/test0",
            "compression": "tar",
            "hosts": ["matching2", ],
        },
        "test1": {
            "target": "/mnt/test1",
            "hosts": ["matching", "a"],
        },
    }

    groups = tuple(complete_groups_from_dict(groups_config))
    assert len(groups) == 2
    group0, group1 = groups

    assert sorted((group0.name, group1.name)) == ["test0", "test1"]