]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: tests shouldn't require lvm2 to pass 58086/head
authorGuillaume Abrioux <gabrioux@ibm.com>
Mon, 17 Jun 2024 13:14:56 +0000 (15:14 +0200)
committerGuillaume Abrioux <gabrioux@ibm.com>
Mon, 17 Jun 2024 13:14:56 +0000 (15:14 +0200)
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 <gabrioux@ibm.com>
src/ceph-volume/ceph_volume/tests/devices/lvm/test_listing.py
src/ceph-volume/ceph_volume/tests/devices/lvm/test_migrate.py
src/ceph-volume/ceph_volume/tests/devices/lvm/test_zap.py
src/ceph-volume/ceph_volume/tests/objectstore/test_lvmbluestore.py

index 7e4d963c8b450f1a813a03bcd80544b747e1230d..062ea511a8ec3da0b60f105219664f5d5324f27b 100644 (file)
@@ -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
@@ -68,6 +69,7 @@ class TestList(object):
         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)
@@ -79,6 +81,7 @@ class TestList(object):
         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):
@@ -86,6 +89,7 @@ class TestList(object):
 
 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',
@@ -98,6 +102,7 @@ class TestFullReport(object):
         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",
@@ -113,6 +118,7 @@ class TestFullReport(object):
         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'
@@ -134,6 +140,7 @@ class TestFullReport(object):
         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'
@@ -151,6 +158,7 @@ class TestFullReport(object):
         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,'
@@ -168,6 +176,7 @@ class TestFullReport(object):
 
 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',
@@ -178,6 +187,7 @@ class TestSingleReport(object):
         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'
@@ -194,6 +204,7 @@ class TestSingleReport(object):
         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,' + \
@@ -242,6 +253,7 @@ class TestSingleReport(object):
         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',
@@ -256,6 +268,7 @@ class TestSingleReport(object):
         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',
@@ -270,6 +283,7 @@ class TestSingleReport(object):
         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'
@@ -298,7 +312,7 @@ class TestSingleReport(object):
         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'
@@ -320,6 +334,7 @@ class TestSingleReport(object):
         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')
@@ -329,6 +344,7 @@ class TestSingleReport(object):
         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',
index 99aba1285c3c55a62ed81ae140195849e596a561..19e61f7e371b13e044cab164cf2127e0424d6893 100644 (file)
@@ -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
@@ -535,6 +535,7 @@ class TestNew(object):
         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=[
index 51f66abfc78053a3e277542581cdf02a5adc8b4f..d630a7a6bf887b474b0e2cb47571fcb708dda030 100644 (file)
@@ -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
@@ -100,6 +100,7 @@ class TestFindAssociatedDevices(object):
 
 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)
@@ -148,6 +149,7 @@ class TestEnsureAssociatedLVs(object):
         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 = []
@@ -160,6 +162,7 @@ class TestEnsureAssociatedLVs(object):
         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 = []
@@ -172,6 +175,7 @@ class TestEnsureAssociatedLVs(object):
         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 = []
@@ -184,6 +188,7 @@ class TestEnsureAssociatedLVs(object):
         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']:
index 45fbd3005b6dd00f379524c8d7882e27871973c4..346e5f455632ec1b8e5336aec738f49e6d215086 100644 (file)
@@ -477,6 +477,7 @@ class TestLvmBlueStore:
         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,