Skip to content

Commit

Permalink
ceph-volume: tests shouldn't require lvm2 to pass
Browse files Browse the repository at this point in the history
some tests are currently failing when `lvm2` isn't installed:

```
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestList::test_empty_device_json_zero_exit_status - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestList::test_empty_device_zero_exit_status - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_no_ceph_lvs - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_ceph_data_lv_reported - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_ceph_journal_lv_reported - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_ceph_wal_lv_reported - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_physical_2nd_device_gets_reported[journal] - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_physical_2nd_device_gets_reported[db] - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestFullReport::test_physical_2nd_device_gets_reported[wal] - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_not_a_ceph_lv - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_a_ceph_lv - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_a_ceph_journal_device - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_by_osd_id_for_just_block_dev - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_by_osd_id_for_just_data_dev - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_by_osd_id_for_just_block_wal_and_db_dev - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_by_osd_id_for_data_and_journal_dev - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_by_nonexistent_osd_id - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_listing.py::TestSingleReport::test_report_a_ceph_lv_with_no_matching_devices - FileNotFoundError: [Errno 2] No such file or directory: 'pvs'
FAILED ceph_volume/tests/devices/lvm/test_migrate.py::TestNew::test_newdb_not_target_lvm - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/devices/lvm/test_zap.py::TestEnsureAssociatedLVs::test_nothing_is_found - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/devices/lvm/test_zap.py::TestEnsureAssociatedLVs::test_multiple_journals_are_found - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/devices/lvm/test_zap.py::TestEnsureAssociatedLVs::test_multiple_dbs_are_found - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/devices/lvm/test_zap.py::TestEnsureAssociatedLVs::test_multiple_wals_are_found - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/devices/lvm/test_zap.py::TestEnsureAssociatedLVs::test_multiple_backing_devs_are_found - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
FAILED ceph_volume/tests/objectstore/test_lvmbluestore.py::TestLvmBlueStore::test_activate_all_osd_is_active - FileNotFoundError: [Errno 2] No such file or directory: 'lvs'
```

Everything should be actually mocked. This commit addresses that.

Signed-off-by: Guillaume Abrioux <[email protected]>
  • Loading branch information
guits committed Jun 17, 2024
1 parent 9390592 commit c68fbf0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from ceph_volume.devices import lvm
from ceph_volume.api import lvm as api
from mock import patch, Mock

# TODO: add tests for following commands -
# ceph-volume list
Expand Down Expand Up @@ -68,6 +69,7 @@ def test_empty_full_json_zero_exit_status(self, fake_call, is_root, factory, cap
stdout, stderr = capsys.readouterr()
assert stdout == '{}\n'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_empty_device_json_zero_exit_status(self, is_root,factory,capsys):
args = factory(format='json', device='/dev/sda1')
lvm.listing.List([]).list(args)
Expand All @@ -79,13 +81,15 @@ def test_empty_full_zero_exit_status(self, fake_call, is_root, factory):
with pytest.raises(SystemExit):
lvm.listing.List([]).list(args)

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_empty_device_zero_exit_status(self, is_root, factory):
args = factory(format='pretty', device='/dev/sda1')
with pytest.raises(SystemExit):
lvm.listing.List([]).list(args)

class TestFullReport(object):

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_no_ceph_lvs(self, monkeypatch):
# ceph lvs are detected by looking into its tags
osd = api.Volume(lv_name='volume1', lv_path='/dev/VolGroup/lv',
Expand All @@ -98,6 +102,7 @@ def test_no_ceph_lvs(self, monkeypatch):
result = lvm.listing.List([]).full_report()
assert result == {}

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_ceph_data_lv_reported(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
pv = api.PVolume(pv_name='/dev/sda1', pv_tags={}, pv_uuid="0000",
Expand All @@ -113,6 +118,7 @@ def test_ceph_data_lv_reported(self, monkeypatch):
result = lvm.listing.List([]).full_report()
assert result['0'][0]['name'] == 'volume1'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_ceph_journal_lv_reported(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
journal_tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=journal'
Expand All @@ -134,6 +140,7 @@ def test_ceph_journal_lv_reported(self, monkeypatch):
assert result['0'][0]['name'] == 'volume1'
assert result['0'][1]['name'] == 'journal'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_ceph_wal_lv_reported(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.wal_uuid=x,ceph.type=data'
wal_tags = 'ceph.osd_id=0,ceph.wal_uuid=x,ceph.type=wal'
Expand All @@ -151,6 +158,7 @@ def test_ceph_wal_lv_reported(self, monkeypatch):
assert result['0'][0]['name'] == 'volume1'
assert result['0'][1]['name'] == 'wal'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
@pytest.mark.parametrize('type_', ['journal', 'db', 'wal'])
def test_physical_2nd_device_gets_reported(self, type_, monkeypatch):
tags = ('ceph.osd_id=0,ceph.{t}_uuid=x,ceph.type=data,'
Expand All @@ -168,6 +176,7 @@ def test_physical_2nd_device_gets_reported(self, type_, monkeypatch):

class TestSingleReport(object):

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_not_a_ceph_lv(self, monkeypatch):
# ceph lvs are detected by looking into its tags
lv = api.Volume(lv_name='lv', lv_tags={}, lv_path='/dev/VolGroup/lv',
Expand All @@ -178,6 +187,7 @@ def test_not_a_ceph_lv(self, monkeypatch):
result = lvm.listing.List([]).single_report('VolGroup/lv')
assert result == {}

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_a_ceph_lv(self, monkeypatch):
# ceph lvs are detected by looking into its tags
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
Expand All @@ -194,6 +204,7 @@ def test_report_a_ceph_lv(self, monkeypatch):
assert result['0'][0]['path'] == '/dev/VolGroup/lv'
assert result['0'][0]['devices'] == []

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_a_ceph_journal_device(self, monkeypatch):
# ceph lvs are detected by looking into its tags
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data,' + \
Expand Down Expand Up @@ -242,6 +253,7 @@ def test_report_a_ceph_lv_with_devices(self, monkeypatch):
assert result['0'][0]['path'] == '/dev/VolGroup/lv'
assert result['0'][0]['devices'] == ['/dev/sda1', '/dev/sdb1']

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_by_osd_id_for_just_block_dev(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=block'
lvs = [ api.Volume(lv_name='lv1', lv_tags=tags, lv_path='/dev/vg/lv1',
Expand All @@ -256,6 +268,7 @@ def test_report_by_osd_id_for_just_block_dev(self, monkeypatch):
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'
assert result['0'][0]['vg_name'] == 'vg'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_by_osd_id_for_just_data_dev(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
lvs = [ api.Volume(lv_name='lv1', lv_tags=tags, lv_path='/dev/vg/lv1',
Expand All @@ -270,6 +283,7 @@ def test_report_by_osd_id_for_just_data_dev(self, monkeypatch):
assert result['0'][0]['lv_path'] == '/dev/vg/lv1'
assert result['0'][0]['vg_name'] == 'vg'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_by_osd_id_for_just_block_wal_and_db_dev(self, monkeypatch):
tags1 = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=block'
tags2 = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=wal'
Expand Down Expand Up @@ -298,7 +312,7 @@ def test_report_by_osd_id_for_just_block_wal_and_db_dev(self, monkeypatch):
assert result['0'][2]['lv_path'] == '/dev/vg/lv3'
assert result['0'][2]['vg_name'] == 'vg'


@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_by_osd_id_for_data_and_journal_dev(self, monkeypatch):
tags1 = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=data'
tags2 = 'ceph.osd_id=0,ceph.journal_uuid=x,ceph.type=journal'
Expand All @@ -320,6 +334,7 @@ def test_report_by_osd_id_for_data_and_journal_dev(self, monkeypatch):
assert result['0'][1]['lv_path'] == '/dev/vg/lv2'
assert result['0'][1]['vg_name'] == 'vg'

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_by_nonexistent_osd_id(self, monkeypatch):
lv = api.Volume(lv_name='lv', lv_tags={}, lv_path='/dev/VolGroup/lv',
vg_name='VolGroup')
Expand All @@ -329,6 +344,7 @@ def test_report_by_nonexistent_osd_id(self, monkeypatch):
result = lvm.listing.List([]).single_report('1')
assert result == {}

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_report_a_ceph_lv_with_no_matching_devices(self, monkeypatch):
tags = 'ceph.osd_id=0,ceph.type=data'
lv = api.Volume(lv_name='lv', vg_name='VolGroup', lv_uuid='aaaa',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from mock.mock import patch
from mock.mock import patch, Mock
from ceph_volume import process
from ceph_volume.api import lvm as api
from ceph_volume.devices.lvm import migrate
Expand Down Expand Up @@ -535,6 +535,7 @@ def test_newdb_non_root(self, is_non_root):
expected = 'This command needs to be executed with sudo or as root'
assert expected in str(error.value)

@patch('ceph_volume.api.lvm.get_lv_by_fullname', Mock(return_value=None))
def test_newdb_not_target_lvm(self, is_root, capsys):
with pytest.raises(SystemExit) as error:
migrate.NewDB(argv=[
Expand Down
7 changes: 6 additions & 1 deletion src/ceph-volume/ceph_volume/tests/devices/lvm/test_zap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pytest
from copy import deepcopy
from mock.mock import patch, call
from mock.mock import patch, call, Mock
from ceph_volume import process
from ceph_volume.api import lvm as api
from ceph_volume.devices.lvm import zap
Expand Down Expand Up @@ -100,6 +100,7 @@ def test_lv_is_matched_id_fsid(self, monkeypatch):

class TestEnsureAssociatedLVs(object):

@patch('ceph_volume.devices.lvm.zap.api', Mock(return_value=[]))
def test_nothing_is_found(self):
volumes = []
result = zap.ensure_associated_lvs(volumes)
Expand Down Expand Up @@ -148,6 +149,7 @@ def test_journal_is_found(self, fake_call):
result = zap.ensure_associated_lvs(volumes)
assert result == ['/dev/VolGroup/lv']

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_multiple_journals_are_found(self):
tags = 'ceph.osd_id=0,ceph.osd_fsid=asdf-lkjh,ceph.journal_uuid=x,ceph.type=journal'
volumes = []
Expand All @@ -160,6 +162,7 @@ def test_multiple_journals_are_found(self):
assert '/dev/VolGroup/lv1' in result
assert '/dev/VolGroup/lv2' in result

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_multiple_dbs_are_found(self):
tags = 'ceph.osd_id=0,ceph.osd_fsid=asdf-lkjh,ceph.journal_uuid=x,ceph.type=db'
volumes = []
Expand All @@ -172,6 +175,7 @@ def test_multiple_dbs_are_found(self):
assert '/dev/VolGroup/lv1' in result
assert '/dev/VolGroup/lv2' in result

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_multiple_wals_are_found(self):
tags = 'ceph.osd_id=0,ceph.osd_fsid=asdf-lkjh,ceph.wal_uuid=x,ceph.type=wal'
volumes = []
Expand All @@ -184,6 +188,7 @@ def test_multiple_wals_are_found(self):
assert '/dev/VolGroup/lv1' in result
assert '/dev/VolGroup/lv2' in result

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
def test_multiple_backing_devs_are_found(self):
volumes = []
for _type in ['journal', 'db', 'wal']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def test_activate_all_no_osd_found(self,
assert "Was unable to find any OSDs to activate" in stderr
assert "Verify OSDs are present with" in stderr

@patch('ceph_volume.api.lvm.process.call', Mock(return_value=('', '', 0)))
@patch('ceph_volume.systemd.systemctl.osd_is_active', return_value=True)
def test_activate_all_osd_is_active(self,
mock_lvm_direct_report,
Expand Down

0 comments on commit c68fbf0

Please sign in to comment.