示例#1
0
    def test_start_multithread(self, build_mock_libvirtconn, mocker):
        conn = build_mock_libvirtconn
        backup_group = build_backup_group(
            conn, domlst=(MockDomain(_conn=conn), MockDomain(_conn=conn),)
        )
        for b in backup_group.backups:
            b.start = mocker.stub()

        backup_group.start_multithread(2)

        for b in backup_group.backups:
            assert b.start.called
示例#2
0
    def test_propagate_attr_multiple_domains(self, mocker):
        backup_group = BackupGroup(domlst=(MockDomain(_conn=mocker.stub()),
                                           MockDomain(_conn=mocker.stub())),
                                   compression="xz")
        for b in backup_group.backups:
            assert b.compression == "xz"

        backup_group.default_bak_param["target_dir"] = "/test"
        for b in backup_group.backups:
            assert b.target_dir is None

        backup_group.propagate_default_backup_attr()
        for b in backup_group.backups:
            assert b.target_dir is "/test"
示例#3
0
    def test_start_with_err(self, build_mock_domain, mocker):
        backup_group = BackupGroup(
            domlst=(MockDomain(_conn=mocker.stub()),
                    MockDomain(_conn=mocker.stub(), name="test_error")))

        def error_start(*args, **kwargs):
            raise Exception()

        backup_group.backups[0].start = error_start
        backup_group.backups[1].start = mocker.stub()

        with pytest.raises(BackupsFailureInGroupError):
            backup_group.start()

        assert backup_group.backups[1].start.called
示例#4
0
def build_mock_libvirtconn_filled(build_mock_libvirtconn):
    conn = build_mock_libvirtconn
    domain_names = ("a", "b", "vm-10", "matching", "matching2")
    conn._domains = [
        MockDomain(name=dom_name, _conn=conn) for dom_name in domain_names
    ]
    return conn
示例#5
0
    def test_start_multithead_with_err(self, build_mock_libvirtconn, mocker):
        conn = build_mock_libvirtconn
        backup_group = build_backup_group(
            conn,
            domlst=(MockDomain(_conn=conn), MockDomain(_conn=conn, name="test_error")),
        )

        def error_start(*args, **kwargs):
            raise Exception()

        backup_group.backups[0].start = error_start
        backup_group.backups[1].start = mocker.stub()

        with pytest.raises(BackupsFailureInGroupError):
            backup_group.start_multithread(2)

        assert backup_group.backups[1].start.called
示例#6
0
def build_mock_libvirtconn_filled(build_mock_libvirtconn):
    conn = build_mock_libvirtconn
    domain_names = ("a", "b", "vm-10", "matching", "matching2")
    conn._domains = [
        MockDomain(name=dom_name, _conn=conn, id=id)
        for id, dom_name in enumerate(domain_names)
    ]
    return conn
示例#7
0
def test_search_domains_regex(build_mock_libvirtconn):
    conn = build_mock_libvirtconn
    domain_names = ("dom1", "dom2", "dom3", "test")
    conn._domains = [MockDomain(name=dom_name, _conn=conn) for dom_name in domain_names]

    matches = list(sorted(search_domains_regex(r"^dom\d$", conn)))
    expected = list(sorted(domain_names))
    expected.remove("test")

    assert matches == expected
示例#8
0
    def test_propagate_attr_multiple_domains(self, build_mock_libvirtconn, mocker):
        conn = build_mock_libvirtconn
        backup_group = build_backup_group(
            conn,
            domlst=(MockDomain(_conn=conn), MockDomain(_conn=conn),),
            packager="tar",
            packager_opts={"compression": "xz"},
        )

        for b in backup_group.backups:
            assert b.packager_opts["compression"] == "xz"

        backup_group.default_bak_param["backup_dir"] = "/test"
        for b in backup_group.backups:
            assert b.backup_dir is None

        backup_group.propagate_default_backup_attr()
        for b in backup_group.backups:
            assert b.backup_dir == "/test"
示例#9
0
    def test_propagate_attr_multiple_domains(
            self, build_mock_libvirtconn, mocker
    ):
        conn = build_mock_libvirtconn
        backup_group = build_backup_group(
            conn, domlst=(
                MockDomain(_conn=conn),
                MockDomain(_conn=conn),
            ), compression="xz"
        )

        for b in backup_group.backups:
            assert b.compression == "xz"

        backup_group.default_bak_param["target_dir"] = "/test"
        for b in backup_group.backups:
            assert b.target_dir is None

        backup_group.propagate_default_backup_attr()
        for b in backup_group.backups:
            assert b.target_dir == "/test"
示例#10
0
    def test_add_domain_quiesce_multiple_domains(self, build_mock_domain,
                                                 build_mock_libvirtconn):
        dom = build_mock_domain
        backup_group = build_backup_group(build_mock_libvirtconn)
        backup_group.default_bak_param["quiesce"] = True

        backup_group.add_domain(dom, quiesce=False)

        dom2 = MockDomain(dom._conn, "test2", id=2)
        backup_group.add_domain(dom2, quiesce=True)

        assert not backup_group.backups[0].quiesce
        assert backup_group.backups[1].quiesce
示例#11
0
def build_mock_domain(mocker):
    return MockDomain(_conn=mocker.stub())
示例#12
0
 def mocked_conn(self, monkeypatch):
     self.conn = MockConn()
     self.conn._domains.append(MockDomain(self.conn, name="mocked_domain"))
     mock_get_conn(monkeypatch, self.conn)