]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | import pytest |
2 | from mock.mock import patch | |
3 | from ceph_volume.api import lvm | |
4 | from ceph_volume.devices.lvm import deactivate | |
5 | ||
6 | class TestDeactivate(object): | |
7 | ||
8 | @patch("ceph_volume.devices.lvm.deactivate.get_lvs_by_tag") | |
9 | def test_no_osd(self, p_get_lvs): | |
10 | p_get_lvs.return_value = [] | |
11 | with pytest.raises(StopIteration): | |
12 | deactivate.deactivate_osd(0) | |
13 | ||
14 | @patch("ceph_volume.devices.lvm.deactivate.get_lvs_by_tag") | |
15 | @patch("ceph_volume.util.system.unmount_tmpfs") | |
16 | def test_unmount_tmpfs_called_osd_id(self, p_u_tmpfs, p_get_lvs): | |
17 | FooVolume = lvm.Volume( | |
18 | lv_name='foo', lv_path='/dev/vg/foo', | |
19 | lv_tags="ceph.osd_id=0,ceph.cluster_name=foo,ceph.type=data") | |
20 | p_get_lvs.return_value = [FooVolume] | |
21 | ||
22 | deactivate.deactivate_osd(0) | |
23 | p_u_tmpfs.assert_called_with( | |
24 | '/var/lib/ceph/osd/{}-{}'.format('foo', 0)) | |
25 | ||
26 | @patch("ceph_volume.devices.lvm.deactivate.get_lvs_by_tag") | |
27 | @patch("ceph_volume.util.system.unmount_tmpfs") | |
28 | def test_unmount_tmpfs_called_osd_uuid(self, p_u_tmpfs, p_get_lvs): | |
29 | FooVolume = lvm.Volume( | |
30 | lv_name='foo', lv_path='/dev/vg/foo', | |
31 | lv_tags="ceph.osd_fsid=0,ceph.osd_id=1,ceph.cluster_name=foo,ceph.type=data") | |
32 | p_get_lvs.return_value = [FooVolume] | |
33 | ||
34 | deactivate.deactivate_osd(None, 0) | |
35 | p_u_tmpfs.assert_called_with( | |
36 | '/var/lib/ceph/osd/{}-{}'.format('foo', 1)) | |
37 | ||
38 | @patch("ceph_volume.devices.lvm.deactivate.get_lvs_by_tag") | |
39 | @patch("ceph_volume.util.system.unmount_tmpfs") | |
40 | @patch("ceph_volume.util.encryption.dmcrypt_close") | |
41 | def test_no_crypt_no_dmclose(self, p_dm_close, p_u_tmpfs, p_get_lvs): | |
42 | FooVolume = lvm.Volume( | |
43 | lv_name='foo', lv_path='/dev/vg/foo', | |
44 | lv_tags="ceph.osd_id=0,ceph.cluster_name=foo,ceph.type=data") | |
45 | p_get_lvs.return_value = [FooVolume] | |
46 | ||
47 | deactivate.deactivate_osd(0) | |
48 | ||
49 | @patch("ceph_volume.devices.lvm.deactivate.get_lvs_by_tag") | |
50 | @patch("ceph_volume.util.system.unmount_tmpfs") | |
51 | @patch("ceph_volume.util.encryption.dmcrypt_close") | |
52 | def test_crypt_dmclose(self, p_dm_close, p_u_tmpfs, p_get_lvs): | |
53 | FooVolume = lvm.Volume( | |
54 | lv_name='foo', lv_path='/dev/vg/foo', lv_uuid='123', | |
55 | lv_tags="ceph.osd_id=0,ceph.encrypted=1,ceph.cluster_name=foo,ceph.type=data") | |
56 | p_get_lvs.return_value = [FooVolume] | |
57 | ||
58 | deactivate.deactivate_osd(0) | |
aee94f69 | 59 | p_dm_close.assert_called_with(mapping='123', skip_path_check=True) |