]> git.proxmox.com Git - ceph.git/blame - ceph/src/ceph-volume/ceph_volume/tests/conftest.py
update sources to 12.2.2
[ceph.git] / ceph / src / ceph-volume / ceph_volume / tests / conftest.py
CommitLineData
3efd9988 1import os
d2e6a577 2import pytest
3efd9988
FG
3from ceph_volume.api import lvm as lvm_api
4
d2e6a577
FG
5
6class Capture(object):
7
8 def __init__(self, *a, **kw):
9 self.a = a
10 self.kw = kw
11 self.calls = []
12
13 def __call__(self, *a, **kw):
14 self.calls.append({'args': a, 'kwargs': kw})
15
16
3efd9988
FG
17class Factory(object):
18
19 def __init__(self, **kw):
20 for k, v in kw.items():
21 setattr(self, k, v)
22
23
24@pytest.fixture
25def factory():
26 return Factory
27
28
d2e6a577
FG
29@pytest.fixture
30def capture():
31 return Capture()
181888fb
FG
32
33
34@pytest.fixture
35def volumes(monkeypatch):
36 monkeypatch.setattr('ceph_volume.process.call', lambda x: ('', '', 0))
3efd9988 37 volumes = lvm_api.Volumes()
181888fb
FG
38 volumes._purge()
39 return volumes
40
41
42@pytest.fixture
43def volume_groups(monkeypatch):
44 monkeypatch.setattr('ceph_volume.process.call', lambda x: ('', '', 0))
3efd9988 45 vgs = lvm_api.VolumeGroups()
181888fb
FG
46 vgs._purge()
47 return vgs
48
49
50@pytest.fixture
51def is_root(monkeypatch):
52 """
53 Patch ``os.getuid()`` so that ceph-volume's decorators that ensure a user
54 is root (or is sudoing to superuser) can continue as-is
55 """
56 monkeypatch.setattr('os.getuid', lambda: 0)
3efd9988
FG
57
58
59@pytest.fixture
60def tmpfile(tmpdir):
61 """
62 Create a temporary file, optionally filling it with contents, returns an
63 absolute path to the file when called
64 """
65 def generate_file(name='file', contents=''):
66 path = os.path.join(str(tmpdir), name)
67 with open(path, 'w') as fp:
68 fp.write(contents)
69 return path
70 return generate_file