]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py
e41cbba7262513ea616099c7253394be3215c10a
2 from ceph_volume
.devices
import lvm
3 from ceph_volume
.api
import lvm
as api
5 # TODO: add tests for following commands -
7 # ceph-volume list <path-to-pv>
8 # ceph-volume list <path-to-vg>
9 # ceph-volume list <path-to-lv>
11 class TestReadableTag(object):
13 def test_dots_get_replaced(self
):
14 result
= lvm
.listing
.readable_tag('ceph.foo')
15 assert result
== 'foo'
17 def test_underscores_are_replaced_with_spaces(self
):
18 result
= lvm
.listing
.readable_tag('ceph.long_tag')
19 assert result
== 'long tag'
22 class TestPrettyReport(object):
24 def test_is_empty(self
, capsys
):
25 lvm
.listing
.pretty_report({})
26 stdout
, stderr
= capsys
.readouterr()
29 def test_type_and_path_are_reported(self
, capsys
):
30 lvm
.listing
.pretty_report({0: [
31 {'type': 'data', 'path': '/dev/sda1', 'devices': ['/dev/sda']}
33 stdout
, stderr
= capsys
.readouterr()
34 assert '[data] /dev/sda1' in stdout
36 def test_osd_id_header_is_reported(self
, capsys
):
37 lvm
.listing
.pretty_report({0: [
38 {'type': 'data', 'path': '/dev/sda1', 'devices': ['/dev/sda']}
40 stdout
, stderr
= capsys
.readouterr()
41 assert '====== osd.0 =======' in stdout
43 def test_tags_are_included(self
, capsys
):
44 lvm
.listing
.pretty_report(
48 'tags': {'ceph.osd_id': '0'},
49 'devices': ['/dev/sda'],
52 stdout
, stderr
= capsys
.readouterr()
53 assert 'osd id' in stdout
55 def test_devices_are_comma_separated(self
, capsys
):
56 lvm
.listing
.pretty_report({0: [
57 {'type': 'data', 'path': '/dev/sda1', 'devices': ['/dev/sda', '/dev/sdb1']}
59 stdout
, stderr
= capsys
.readouterr()
60 assert '/dev/sda,/dev/sdb1' in stdout
63 class TestList(object):
65 def test_empty_full_json_zero_exit_status(self
, is_root
, volumes
,
67 args
= factory(format
='json', device
=None)
68 lvm
.listing
.List([]).list(args
)
69 stdout
, stderr
= capsys
.readouterr()
70 assert stdout
== '{}\n'
72 def test_empty_device_json_zero_exit_status(self
, is_root
, volumes
,
74 args
= factory(format
='json', device
='/dev/sda1')
75 lvm
.listing
.List([]).list(args
)
76 stdout
, stderr
= capsys
.readouterr()
77 assert stdout
== '{}\n'
79 def test_empty_full_zero_exit_status(self
, is_root
, volumes
, factory
):
80 args
= factory(format
='pretty', device
=None)
81 with pytest
.raises(SystemExit):
82 lvm
.listing
.List([]).list(args
)
84 def test_empty_device_zero_exit_status(self
, is_root
, volumes
, factory
):
85 args
= factory(format
='pretty', device
='/dev/sda1')
86 with pytest
.raises(SystemExit):
87 lvm
.listing
.List([]).list(args
)
89 class TestFullReport(object):
91 def test_no_ceph_lvs(self
, volumes
, monkeypatch
):
92 # ceph lvs are detected by looking into its tags
93 osd
= api
.Volume(lv_name
='volume1', lv_path
='/dev/VolGroup/lv',
96 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
99 result
= lvm
.listing
.List([]).full_report()
102 def test_ceph_data_lv_reported(self
, pvolumes
, volumes
, monkeypatch
):
103 tags
= 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
104 pv
= api
.PVolume(pv_name
='/dev/sda1', pv_tags
={}, pv_uuid
="0000",
105 vg_name
='VolGroup', lv_uuid
="aaaa")
106 osd
= api
.Volume(lv_name
='volume1', lv_uuid
='y', lv_tags
=tags
,
107 lv_path
='/dev/VolGroup/lv', vg_name
='VolGroup')
110 monkeypatch
.setattr(lvm
.listing
.api
, 'get_pvs', lambda **kwargs
:
112 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
115 result
= lvm
.listing
.List([]).full_report()
116 assert result
['0'][0]['name'] == 'volume1'
118 def test_ceph_journal_lv_reported(self
, pvolumes
, volumes
, monkeypatch
):
119 tags
= 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
120 journal_tags
= 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=journal'
121 pv
= api
.PVolume(pv_name
='/dev/sda1', pv_tags
={}, pv_uuid
="0000",
122 vg_name
="VolGroup", lv_uuid
="aaaa")
123 osd
= api
.Volume(lv_name
='volume1', lv_uuid
='y', lv_tags
=tags
,
124 lv_path
='/dev/VolGroup/lv', vg_name
='VolGroup')
125 journal
= api
.Volume(
126 lv_name
='journal', lv_uuid
='x', lv_tags
=journal_tags
,
127 lv_path
='/dev/VolGroup/journal', vg_name
='VolGroup')
130 volumes
.append(journal
)
131 monkeypatch
.setattr(lvm
.listing
.api
, 'get_pvs', lambda **kwargs
:
133 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
136 result
= lvm
.listing
.List([]).full_report()
137 assert result
['0'][0]['name'] == 'volume1'
138 assert result
['0'][1]['name'] == 'journal'
140 def test_ceph_wal_lv_reported(self
, volumes
, monkeypatch
):
141 tags
= 'ceph.osd_id=0,ceph.wal_uuid=x,ceph.type=data'
142 wal_tags
= 'ceph.osd_id=0,ceph.wal_uuid=x,ceph.type=wal'
143 osd
= api
.Volume(lv_name
='volume1', lv_uuid
='y', lv_tags
=tags
,
144 lv_path
='/dev/VolGroup/lv', vg_name
='VolGroup')
145 wal
= api
.Volume(lv_name
='wal', lv_uuid
='x', lv_tags
=wal_tags
,
146 lv_path
='/dev/VolGroup/wal', vg_name
='VolGroup')
149 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
152 result
= lvm
.listing
.List([]).full_report()
153 assert result
['0'][0]['name'] == 'volume1'
154 assert result
['0'][1]['name'] == 'wal'
156 @pytest.mark
.parametrize('type_', ['journal', 'db', 'wal'])
157 def test_physical_2nd_device_gets_reported(self
, type_
, monkeypatch
):
158 tags
= ('ceph.osd_id=0,ceph.{t}_uuid=x,ceph.type=data,'
159 'ceph.{t}_device=/dev/sda1').format(t
=type_
)
160 osd
= api
.Volume(lv_name
='volume1', lv_uuid
='y', lv_tags
=tags
,
161 vg_name
='VolGroup', lv_path
='/dev/VolGroup/lv')
162 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
165 result
= lvm
.listing
.List([]).full_report()
166 assert result
['0'][1]['path'] == '/dev/sda1'
167 assert result
['0'][1]['tags'] == {'PARTUUID': 'x'}
168 assert result
['0'][1]['type'] == type_
171 class TestSingleReport(object):
173 def test_not_a_ceph_lv(self
, volumes
, monkeypatch
):
174 # ceph lvs are detected by looking into its tags
175 lv
= api
.Volume(lv_name
='lv', lv_tags
={}, lv_path
='/dev/VolGroup/lv',
177 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
180 result
= lvm
.listing
.List([]).single_report('VolGroup/lv')
183 def test_report_a_ceph_lv(self
, pvolumes
, volumes
, monkeypatch
):
184 # ceph lvs are detected by looking into its tags
185 tags
= 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
186 lv
= api
.Volume(lv_name
='lv', vg_name
='VolGroup', lv_uuid
='aaaa',
187 lv_path
='/dev/VolGroup/lv', lv_tags
=tags
)
189 monkeypatch
.setattr(lvm
.listing
.api
, 'get_pvs', lambda **kwargs
:
191 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
194 result
= lvm
.listing
.List([]).single_report('VolGroup/lv')
195 assert result
['0'][0]['name'] == 'lv'
196 assert result
['0'][0]['lv_tags'] == tags
197 assert result
['0'][0]['path'] == '/dev/VolGroup/lv'
198 assert result
['0'][0]['devices'] == []
200 def test_report_a_ceph_journal_device(self
, monkeypatch
):
201 # ceph lvs are detected by looking into its tags
202 tags
= 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data,' + \
203 'ceph.journal_device=/dev/sda1'
204 lv
= api
.Volume(lv_name
='lv', lv_uuid
='aaa', lv_tags
=tags
,
205 lv_path
='/dev/VolGroup/lv', vg_name
='VolGroup')
206 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
207 [lv
] if 'tags' in kwargs
else [])
209 result
= lvm
.listing
.List([]).single_report('/dev/sda1')
210 assert result
['0'][0]['tags'] == {'PARTUUID': 'x'}
211 assert result
['0'][0]['type'] == 'journal'
212 assert result
['0'][0]['path'] == '/dev/sda1'
214 def test_report_a_ceph_lv_with_devices(self
, volumes
, pvolumes
, monkeypatch
):
215 tags
= 'ceph.osd_id=0,ceph.type=data'
216 pv1
= api
.PVolume(vg_name
="VolGroup", pv_name
='/dev/sda1',
217 pv_uuid
='', pv_tags
={}, lv_uuid
="aaaa")
218 pv2
= api
.PVolume(vg_name
="VolGroup", pv_name
='/dev/sdb1',
219 pv_uuid
='', pv_tags
={}, lv_uuid
="aaaa")
220 lv
= api
.Volume(lv_name
='lv', vg_name
='VolGroup',lv_uuid
='aaaa',
221 lv_path
='/dev/VolGroup/lv', lv_tags
=tags
)
225 monkeypatch
.setattr(lvm
.listing
.api
, 'get_pvs', lambda **kwargs
:
227 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
230 listing
= lvm
.listing
.List([])
232 {'lv_uuid': 'aaaa', 'pv_name': '/dev/sda1', 'pv_tags': '', 'pv_uuid': ''},
233 {'lv_uuid': 'aaaa', 'pv_name': '/dev/sdb1', 'pv_tags': '', 'pv_uuid': ''},
236 result
= listing
.single_report('VolGroup/lv')
237 assert result
['0'][0]['name'] == 'lv'
238 assert result
['0'][0]['lv_tags'] == tags
239 assert result
['0'][0]['path'] == '/dev/VolGroup/lv'
240 assert result
['0'][0]['devices'] == ['/dev/sda1', '/dev/sdb1']
242 def test_report_a_ceph_lv_with_no_matching_devices(self
, volumes
,
244 tags
= 'ceph.osd_id=0,ceph.type=data'
245 lv
= api
.Volume(lv_name
='lv', vg_name
='VolGroup', lv_uuid
='aaaa',
246 lv_path
='/dev/VolGroup/lv', lv_tags
=tags
)
248 monkeypatch
.setattr(lvm
.listing
.api
, 'get_lvs', lambda **kwargs
:
251 listing
= lvm
.listing
.List([])
253 {'lv_uuid': 'ffff', 'pv_name': '/dev/sda1', 'pv_tags': '',
255 {'lv_uuid': 'ffff', 'pv_name': '/dev/sdb1', 'pv_tags': '',
258 result
= listing
.single_report('VolGroup/lv')
259 assert result
['0'][0]['name'] == 'lv'
260 assert result
['0'][0]['lv_tags'] == tags
261 assert result
['0'][0]['path'] == '/dev/VolGroup/lv'
262 assert result
['0'][0]['devices'] == []