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
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"
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
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
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
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
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
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"
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"
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
def build_mock_domain(mocker): return MockDomain(_conn=mocker.stub())
def mocked_conn(self, monkeypatch): self.conn = MockConn() self.conn._domains.append(MockDomain(self.conn, name="mocked_domain")) mock_get_conn(monkeypatch, self.conn)