]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/tests/conftest.py
3 from ceph_volume
.api
import lvm
as lvm_api
4 from ceph_volume
import conf
, configuration
9 def __init__(self
, *a
, **kw
):
14 def __call__(self
, *a
, **kw
):
15 self
.calls
.append({'args': a
, 'kwargs': kw
})
18 class Factory(object):
20 def __init__(self
, **kw
):
21 for k
, v
in kw
.items():
36 def fake_run(monkeypatch
):
38 monkeypatch
.setattr('ceph_volume.process.run', fake_run
)
43 def fake_call(monkeypatch
):
45 monkeypatch
.setattr('ceph_volume.process.call', fake_call
)
50 def stub_call(monkeypatch
):
52 Monkeypatches process.call, so that a caller can add behavior to the response
54 def apply(return_value
):
56 'ceph_volume.process.call',
57 lambda *a
, **kw
: return_value
)
63 def conf_ceph(monkeypatch
):
65 Monkeypatches ceph_volume.conf.ceph, which is meant to parse/read
66 a ceph.conf. The patching is naive, it allows one to set return values for
67 specific method calls.
71 monkeypatch
.setattr(conf
, 'ceph', stub
)
77 def conf_ceph_stub(monkeypatch
, tmpfile
):
79 Monkeypatches ceph_volume.conf.ceph with contents from a string that are
80 written to a temporary file and then is fed through the same ceph.conf
81 loading mechanisms for testing. Unlike ``conf_ceph`` which is just a fake,
82 we are actually loading values as seen on a ceph.conf file
84 This is useful when more complex ceph.conf's are needed. In the case of
85 just trying to validate a key/value behavior ``conf_ceph`` is better
89 conf_path
= tmpfile(contents
=contents
)
90 parser
= configuration
.load(conf_path
)
91 monkeypatch
.setattr(conf
, 'ceph', parser
)
97 def volumes(monkeypatch
):
98 monkeypatch
.setattr('ceph_volume.process.call', lambda x
: ('', '', 0))
99 volumes
= lvm_api
.Volumes()
105 def volume_groups(monkeypatch
):
106 monkeypatch
.setattr('ceph_volume.process.call', lambda x
: ('', '', 0))
107 vgs
= lvm_api
.VolumeGroups()
113 def is_root(monkeypatch
):
115 Patch ``os.getuid()`` so that ceph-volume's decorators that ensure a user
116 is root (or is sudoing to superuser) can continue as-is
118 monkeypatch
.setattr('os.getuid', lambda: 0)
124 Create a temporary file, optionally filling it with contents, returns an
125 absolute path to the file when called
127 def generate_file(name
='file', contents
=''):
128 path
= os
.path
.join(str(tmpdir
), name
)
129 with
open(path
, 'w') as fp
: