Skip to content

Commit d602c8d

Browse files
committed
ceph-volume: update unit tests
This commit consolidates all necessary changes to address unit tests related to the introduction of Python type annotations. Signed-off-by: Guillaume Abrioux <[email protected]>
1 parent 8d47795 commit d602c8d

File tree

7 files changed

+33
-57
lines changed

7 files changed

+33
-57
lines changed

src/ceph-volume/ceph_volume/tests/api/test_lvm.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class TestVolumeGroupSizing(object):
109109

110110
def setup_method(self):
111111
self.vg = api.VolumeGroup(vg_name='ceph',
112-
vg_extent_size=1073741824,
113-
vg_free_count=1024)
112+
vg_extent_size=1073741824,
113+
vg_free_count=1024)
114114

115115
def test_parts_and_size_errors(self):
116116
with pytest.raises(ValueError) as error:
@@ -194,8 +194,8 @@ def setup_method(self):
194194
@patch('ceph_volume.api.lvm.get_single_lv')
195195
def test_uses_size(self, m_get_single_lv, m_call, m_run, monkeypatch):
196196
m_get_single_lv.return_value = self.foo_volume
197-
api.create_lv('foo', 0, vg=self.foo_group, size=419430400, tags={'ceph.type': 'data'})
198-
expected = (['lvcreate', '--yes', '-l', '100', '-n', 'foo-0', 'foo_group'])
197+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, size=419430400, tags={'ceph.type': 'data'})
198+
expected = (['lvcreate', '--yes', '-l', '100', '-n', 'foo-1234-abcd', 'foo_group'])
199199
m_run.assert_called_with(expected, run_on_host=True)
200200

201201
@patch('ceph_volume.api.lvm.process.run')
@@ -209,8 +209,8 @@ def test_uses_size_adjust_if_1percent_over(self, m_get_single_lv, m_call, m_run,
209209
vg_free_count="1000")
210210
m_get_single_lv.return_value = foo_volume
211211
# 423624704 should be just under 1% off of the available size 419430400
212-
api.create_lv('foo', 0, vg=foo_group, size=4232052736, tags={'ceph.type': 'data'})
213-
expected = ['lvcreate', '--yes', '-l', '1000', '-n', 'foo-0', 'foo_group']
212+
api.create_lv('foo', '1234-abcd', vg=foo_group, size=4232052736, tags={'ceph.type': 'data'})
213+
expected = ['lvcreate', '--yes', '-l', '1000', '-n', 'foo-1234-abcd', 'foo_group']
214214
m_run.assert_called_with(expected, run_on_host=True)
215215

216216
@patch('ceph_volume.api.lvm.process.run')
@@ -219,15 +219,15 @@ def test_uses_size_adjust_if_1percent_over(self, m_get_single_lv, m_call, m_run,
219219
def test_uses_size_too_large(self, m_get_single_lv, m_call, m_run, monkeypatch):
220220
m_get_single_lv.return_value = self.foo_volume
221221
with pytest.raises(RuntimeError):
222-
api.create_lv('foo', 0, vg=self.foo_group, size=5368709120, tags={'ceph.type': 'data'})
222+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, size=5368709120, tags={'ceph.type': 'data'})
223223

224224
@patch('ceph_volume.api.lvm.process.run')
225225
@patch('ceph_volume.api.lvm.process.call')
226226
@patch('ceph_volume.api.lvm.get_single_lv')
227227
def test_uses_extents(self, m_get_single_lv, m_call, m_run, monkeypatch):
228228
m_get_single_lv.return_value = self.foo_volume
229-
api.create_lv('foo', 0, vg=self.foo_group, extents='50', tags={'ceph.type': 'data'})
230-
expected = ['lvcreate', '--yes', '-l', '50', '-n', 'foo-0', 'foo_group']
229+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, extents='50', tags={'ceph.type': 'data'})
230+
expected = ['lvcreate', '--yes', '-l', '50', '-n', 'foo-1234-abcd', 'foo_group']
231231
m_run.assert_called_with(expected, run_on_host=True)
232232

233233
@pytest.mark.parametrize("test_input,expected",
@@ -238,17 +238,17 @@ def test_uses_extents(self, m_get_single_lv, m_call, m_run, monkeypatch):
238238
@patch('ceph_volume.api.lvm.get_single_lv')
239239
def test_uses_slots(self, m_get_single_lv, m_call, m_run, monkeypatch, test_input, expected):
240240
m_get_single_lv.return_value = self.foo_volume
241-
api.create_lv('foo', 0, vg=self.foo_group, slots=test_input, tags={'ceph.type': 'data'})
242-
expected = ['lvcreate', '--yes', '-l', str(expected), '-n', 'foo-0', 'foo_group']
241+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, slots=test_input, tags={'ceph.type': 'data'})
242+
expected = ['lvcreate', '--yes', '-l', str(expected), '-n', 'foo-1234-abcd', 'foo_group']
243243
m_run.assert_called_with(expected, run_on_host=True)
244244

245245
@patch('ceph_volume.api.lvm.process.run')
246246
@patch('ceph_volume.api.lvm.process.call')
247247
@patch('ceph_volume.api.lvm.get_single_lv')
248248
def test_uses_all(self, m_get_single_lv, m_call, m_run, monkeypatch):
249249
m_get_single_lv.return_value = self.foo_volume
250-
api.create_lv('foo', 0, vg=self.foo_group, tags={'ceph.type': 'data'})
251-
expected = ['lvcreate', '--yes', '-l', '100%FREE', '-n', 'foo-0', 'foo_group']
250+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, tags={'ceph.type': 'data'})
251+
expected = ['lvcreate', '--yes', '-l', '100%FREE', '-n', 'foo-1234-abcd', 'foo_group']
252252
m_run.assert_called_with(expected, run_on_host=True)
253253

254254
@patch('ceph_volume.api.lvm.process.run')
@@ -257,7 +257,7 @@ def test_uses_all(self, m_get_single_lv, m_call, m_run, monkeypatch):
257257
@patch('ceph_volume.api.lvm.get_single_lv')
258258
def test_calls_to_set_tags_default(self, m_get_single_lv, m_set_tags, m_call, m_run, monkeypatch):
259259
m_get_single_lv.return_value = self.foo_volume
260-
api.create_lv('foo', 0, vg=self.foo_group)
260+
api.create_lv('foo', '1234-abcd', vg=self.foo_group)
261261
tags = {
262262
"ceph.osd_id": "null",
263263
"ceph.type": "null",
@@ -272,7 +272,7 @@ def test_calls_to_set_tags_default(self, m_get_single_lv, m_set_tags, m_call, m_
272272
@patch('ceph_volume.api.lvm.get_single_lv')
273273
def test_calls_to_set_tags_arg(self, m_get_single_lv, m_set_tags, m_call, m_run, monkeypatch):
274274
m_get_single_lv.return_value = self.foo_volume
275-
api.create_lv('foo', 0, vg=self.foo_group, tags={'ceph.type': 'data'})
275+
api.create_lv('foo', '1234-abcd', vg=self.foo_group, tags={'ceph.type': 'data'})
276276
tags = {
277277
"ceph.type": "data",
278278
"ceph.data_device": "/path"
@@ -288,7 +288,7 @@ def test_create_vg(self, m_get_single_lv, m_create_vg, m_get_device_vgs, m_call,
288288
m_run, monkeypatch):
289289
m_get_single_lv.return_value = self.foo_volume
290290
m_get_device_vgs.return_value = []
291-
api.create_lv('foo', 0, device='dev/foo', size='5G', tags={'ceph.type': 'data'})
291+
api.create_lv('foo', '1234-abcd', device='dev/foo', size='5G', tags={'ceph.type': 'data'})
292292
m_create_vg.assert_called_with('dev/foo', name_prefix='ceph')
293293

294294

src/ceph-volume/ceph_volume/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def disable_kernel_queries(monkeypatch):
291291

292292

293293
@pytest.fixture(params=[
294-
'', 'ceph data', 'ceph journal', 'ceph block',
294+
'ceph data', 'ceph journal', 'ceph block',
295295
'ceph block.wal', 'ceph block.db', 'ceph lockbox'])
296296
def ceph_partlabel(request):
297297
return request.param

src/ceph-volume/ceph_volume/tests/devices/lvm/test_batch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class TestBatch(object):
1313

1414
def test_batch_instance(self, is_root):
1515
b = batch.Batch([])
16-
b.main()
16+
with pytest.raises(SystemExit):
17+
b.main()
1718

1819
def test_invalid_osd_ids_passed(self):
1920
with pytest.raises(SystemExit):

src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_report_by_osd_id_for_just_block_dev(self, monkeypatch):
262262
monkeypatch.setattr(lvm.listing.api, 'get_lvs', lambda **kwargs: lvs)
263263

264264
listing = lvm.listing.List([])
265-
result = listing.single_report(0)
265+
result = listing.single_report('0')
266266
assert result['0'][0]['name'] == 'lv1'
267267
assert result['0'][0]['lv_tags'] == tags
268268
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'
@@ -277,7 +277,7 @@ def test_report_by_osd_id_for_just_data_dev(self, monkeypatch):
277277
monkeypatch.setattr(lvm.listing.api, 'get_lvs', lambda **kwargs: lvs)
278278

279279
listing = lvm.listing.List([])
280-
result = listing.single_report(0)
280+
result = listing.single_report('0')
281281
assert result['0'][0]['name'] == 'lv1'
282282
assert result['0'][0]['lv_tags'] == tags
283283
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'
@@ -298,7 +298,7 @@ def test_report_by_osd_id_for_just_block_wal_and_db_dev(self, monkeypatch):
298298
monkeypatch.setattr(lvm.listing.api, 'get_lvs', lambda **kwargs: lvs)
299299

300300
listing = lvm.listing.List([])
301-
result = listing.single_report(0)
301+
result = listing.single_report('0')
302302
assert result['0'][0]['name'] == 'lv1'
303303
assert result['0'][0]['lv_tags'] == tags1
304304
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'
@@ -324,7 +324,7 @@ def test_report_by_osd_id_for_data_and_journal_dev(self, monkeypatch):
324324
monkeypatch.setattr(lvm.listing.api, 'get_lvs', lambda **kwargs: lvs)
325325

326326
listing = lvm.listing.List([])
327-
result = listing.single_report(0)
327+
result = listing.single_report('0')
328328
assert result['0'][0]['name'] == 'lv1'
329329
assert result['0'][0]['lv_tags'] == tags1
330330
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'

src/ceph-volume/ceph_volume/tests/devices/lvm/test_prepare.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from ceph_volume.devices import lvm
33
from ceph_volume.api import lvm as api
4-
from mock.mock import patch, Mock
4+
from mock.mock import patch
55
from ceph_volume import objectstore
66

77

@@ -72,19 +72,6 @@ def test_main_shows_full_help(self, m_create_key, capsys):
7272
assert 'Use the bluestore objectstore' in stdout
7373
assert 'A physical device or logical' in stdout
7474

75-
@patch('ceph_volume.api.lvm.is_ceph_device')
76-
def test_safe_prepare_osd_already_created(self, m_create_key, m_is_ceph_device):
77-
m_is_ceph_device.return_value = True
78-
with pytest.raises(RuntimeError) as error:
79-
self.p.args = Mock()
80-
self.p.args.data = '/dev/sdfoo'
81-
self.p.args.with_tpm = '0'
82-
self.p.get_lv = Mock()
83-
self.p.objectstore = objectstore.lvmbluestore.LvmBlueStore(args=self.p.args)
84-
self.p.objectstore.safe_prepare()
85-
expected = 'skipping {}, it is already prepared'.format('/dev/sdfoo')
86-
assert expected in str(error.value)
87-
8875
def test_setup_device_device_name_is_none(self, m_create_key):
8976
self.p.objectstore = objectstore.lvmbluestore.LvmBlueStore(args=[])
9077
result = self.p.objectstore.setup_device(device_type='data',

src/ceph-volume/ceph_volume/tests/objectstore/test_lvmbluestore.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,6 @@ def test_prepare_data_device_fails(self, factory):
142142
assert ('Cannot use device (/dev/foo). '
143143
'A vg/lv path or an existing device is needed') == str(error.value)
144144

145-
@patch('ceph_volume.api.lvm.is_ceph_device', Mock(return_value=True))
146-
@patch('ceph_volume.api.lvm.get_single_lv')
147-
def test_safe_prepare_is_ceph_device(self, m_get_single_lv, factory):
148-
args = factory(data='/dev/foo')
149-
self.lvm_bs.args = args
150-
m_get_single_lv.return_value = Volume(lv_name='lv_foo',
151-
lv_path='/fake-path',
152-
vg_name='vg_foo',
153-
lv_tags='',
154-
lv_uuid='fake-uuid')
155-
self.lvm_bs.prepare = MagicMock()
156-
with pytest.raises(RuntimeError) as error:
157-
self.lvm_bs.safe_prepare(args)
158-
assert str(error.value) == 'skipping /dev/foo, it is already prepared'
159-
160145
@patch('ceph_volume.api.lvm.is_ceph_device', Mock(return_value=False))
161146
@patch('ceph_volume.api.lvm.get_single_lv')
162147
def test_safe_prepare(self, m_get_single_lv, factory):
@@ -287,15 +272,17 @@ def test_setup_device_is_device(self, m_create_lv, m_set_tags):
287272
{},
288273
1,
289274
1)
290-
assert m_create_lv.mock_calls == [call('osd-block',
291-
'd83fa1ca-bd68-4c75-bdc2-464da58e8abd',
275+
assert m_create_lv.mock_calls == [call(name_prefix='osd-block',
276+
uuid='d83fa1ca-bd68-4c75-bdc2-464da58e8abd',
277+
vg=None,
292278
device='/dev/foo',
279+
slots=1,
280+
extents=None,
281+
size=1,
293282
tags={'ceph.type': 'block',
294283
'ceph.vdo': '0',
295284
'ceph.block_device': '/fake-path',
296-
'ceph.block_uuid': 'fake-uuid'},
297-
slots=1,
298-
size=1)]
285+
'ceph.block_uuid': 'fake-uuid'})]
299286
assert result == ('/fake-path',
300287
'fake-uuid',
301288
{'ceph.type': 'block',

src/ceph-volume/ceph_volume/tests/util/test_device.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
import os
23
import pytest
34
from copy import deepcopy
@@ -591,7 +592,7 @@ def test_lv_is_encrypted_lvm_api(self, fake_call, factory, device_info, monkeypa
591592
blkid = {'TYPE': 'mapper'}
592593
device_info(lsblk=lsblk, blkid=blkid)
593594
disk = device.Device("/dev/sda")
594-
disk.lv_api = factory(encrypted=True)
595+
disk.lv_api = api.Volume(**{'lv_name': 'lv1', 'lv_tags': 'ceph.encrypted=1'})
595596
assert disk.is_encrypted is True
596597

597598
@patch("ceph_volume.util.disk.has_bluestore_label", lambda x: False)

0 commit comments

Comments
 (0)