]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | import pytest |
2 | from textwrap import dedent | |
3 | import json | |
4 | from ceph_volume.util import prepare | |
5 | from ceph_volume.util.prepare import system | |
6 | from ceph_volume import conf | |
7 | from ceph_volume.tests.conftest import Factory | |
8 | ||
9 | ||
10 | class TestCheckID(object): | |
11 | ||
12 | def test_false_if_id_is_none(self): | |
13 | assert not prepare.check_id(None) | |
14 | ||
15 | def test_returncode_is_not_zero(self, monkeypatch): | |
16 | monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: ('', '', 1)) | |
17 | with pytest.raises(RuntimeError): | |
18 | prepare.check_id(1) | |
19 | ||
20 | def test_id_does_exist(self, monkeypatch): | |
21 | stdout = dict(nodes=[ | |
22 | dict(id=0), | |
23 | ]) | |
24 | stdout = ['', json.dumps(stdout)] | |
25 | monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0)) | |
26 | result = prepare.check_id(0) | |
27 | assert result | |
28 | ||
29 | def test_id_does_not_exist(self, monkeypatch): | |
30 | stdout = dict(nodes=[ | |
31 | dict(id=0), | |
32 | ]) | |
33 | stdout = ['', json.dumps(stdout)] | |
34 | monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0)) | |
35 | result = prepare.check_id(1) | |
36 | assert not result | |
37 | ||
38 | def test_invalid_osd_id(self, monkeypatch): | |
39 | stdout = dict(nodes=[ | |
40 | dict(id=0), | |
41 | ]) | |
42 | stdout = ['', json.dumps(stdout)] | |
43 | monkeypatch.setattr('ceph_volume.process.call', lambda *a, **kw: (stdout, '', 0)) | |
44 | result = prepare.check_id("foo") | |
45 | assert not result | |
46 | ||
47 | ||
48 | class TestFormatDevice(object): | |
49 | ||
50 | def test_include_force(self, fake_run, monkeypatch): | |
51 | monkeypatch.setattr(conf, 'ceph', Factory(get_list=lambda *a, **kw: [])) | |
52 | prepare.format_device('/dev/sxx') | |
53 | flags = fake_run.calls[0]['args'][0] | |
54 | assert '-f' in flags | |
55 | ||
56 | def test_device_is_always_appended(self, fake_run, conf_ceph): | |
57 | conf_ceph(get_list=lambda *a, **kw: []) | |
58 | prepare.format_device('/dev/sxx') | |
59 | flags = fake_run.calls[0]['args'][0] | |
60 | assert flags[-1] == '/dev/sxx' | |
61 | ||
62 | def test_extra_flags_are_added(self, fake_run, conf_ceph): | |
63 | conf_ceph(get_list=lambda *a, **kw: ['--why-yes']) | |
64 | prepare.format_device('/dev/sxx') | |
65 | flags = fake_run.calls[0]['args'][0] | |
66 | assert '--why-yes' in flags | |
67 | ||
68 | def test_default_options(self, conf_ceph_stub, fake_run): | |
69 | conf_ceph_stub(dedent("""[global] | |
70 | fsid = 1234lkjh1234""")) | |
71 | conf.cluster = 'ceph' | |
72 | prepare.format_device('/dev/sda1') | |
73 | expected = [ | |
74 | 'mkfs', '-t', 'xfs', | |
75 | '-f', '-i', 'size=2048', # default flags | |
76 | '/dev/sda1'] | |
77 | assert expected == fake_run.calls[0]['args'][0] | |
78 | ||
79 | def test_multiple_options_are_used(self, conf_ceph_stub, fake_run): | |
80 | conf_ceph_stub(dedent("""[global] | |
81 | fsid = 1234lkjh1234 | |
82 | [osd] | |
83 | osd mkfs options xfs = -f -i size=1024""")) | |
84 | conf.cluster = 'ceph' | |
85 | prepare.format_device('/dev/sda1') | |
86 | expected = [ | |
87 | 'mkfs', '-t', 'xfs', | |
88 | '-f', '-i', 'size=1024', | |
89 | '/dev/sda1'] | |
90 | assert expected == fake_run.calls[0]['args'][0] | |
91 | ||
92 | def test_multiple_options_will_get_the_force_flag(self, conf_ceph_stub, fake_run): | |
93 | conf_ceph_stub(dedent("""[global] | |
94 | fsid = 1234lkjh1234 | |
95 | [osd] | |
96 | osd mkfs options xfs = -i size=1024""")) | |
97 | conf.cluster = 'ceph' | |
98 | prepare.format_device('/dev/sda1') | |
99 | expected = [ | |
100 | 'mkfs', '-t', 'xfs', | |
101 | '-f', '-i', 'size=1024', | |
102 | '/dev/sda1'] | |
103 | assert expected == fake_run.calls[0]['args'][0] | |
104 | ||
105 | def test_underscore_options_are_used(self, conf_ceph_stub, fake_run): | |
106 | conf_ceph_stub(dedent("""[global] | |
107 | fsid = 1234lkjh1234 | |
108 | [osd] | |
109 | osd_mkfs_options_xfs = -i size=128""")) | |
110 | conf.cluster = 'ceph' | |
111 | prepare.format_device('/dev/sda1') | |
112 | expected = [ | |
113 | 'mkfs', '-t', 'xfs', | |
114 | '-f', '-i', 'size=128', | |
115 | '/dev/sda1'] | |
116 | assert expected == fake_run.calls[0]['args'][0] | |
117 | ||
118 | ||
119 | class TestOsdMkfsBluestore(object): | |
120 | ||
121 | def test_keyring_is_added(self, fake_call, monkeypatch): | |
122 | monkeypatch.setattr(system, 'chown', lambda path: True) | |
123 | prepare.osd_mkfs_bluestore(1, 'asdf', keyring='secret') | |
124 | assert '--keyfile' in fake_call.calls[0]['args'][0] | |
125 | ||
126 | def test_keyring_is_not_added(self, fake_call, monkeypatch): | |
127 | monkeypatch.setattr(system, 'chown', lambda path: True) | |
128 | prepare.osd_mkfs_bluestore(1, 'asdf') | |
129 | assert '--keyfile' not in fake_call.calls[0]['args'][0] | |
130 | ||
131 | def test_wal_is_added(self, fake_call, monkeypatch): | |
132 | monkeypatch.setattr(system, 'chown', lambda path: True) | |
133 | prepare.osd_mkfs_bluestore(1, 'asdf', wal='/dev/smm1') | |
134 | assert '--bluestore-block-wal-path' in fake_call.calls[0]['args'][0] | |
135 | assert '/dev/smm1' in fake_call.calls[0]['args'][0] | |
136 | ||
137 | def test_db_is_added(self, fake_call, monkeypatch): | |
138 | monkeypatch.setattr(system, 'chown', lambda path: True) | |
139 | prepare.osd_mkfs_bluestore(1, 'asdf', db='/dev/smm2') | |
140 | assert '--bluestore-block-db-path' in fake_call.calls[0]['args'][0] | |
141 | assert '/dev/smm2' in fake_call.calls[0]['args'][0] | |
142 | ||
143 | ||
144 | class TestMountOSD(object): | |
145 | ||
146 | def test_default_options(self, conf_ceph_stub, fake_run): | |
147 | conf_ceph_stub(dedent("""[global] | |
148 | fsid = 1234lkjh1234""")) | |
149 | conf.cluster = 'ceph' | |
150 | prepare.mount_osd('/dev/sda1', 1) | |
151 | expected = [ | |
152 | 'mount', '-t', 'xfs', '-o', | |
153 | 'rw', 'noatime', 'inode64', # default flags | |
154 | '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] | |
155 | assert expected == fake_run.calls[0]['args'][0] | |
156 | ||
157 | def test_mount_options_are_used(self, conf_ceph_stub, fake_run): | |
158 | conf_ceph_stub(dedent("""[global] | |
159 | fsid = 1234lkjh1234 | |
160 | [osd] | |
161 | osd mount options xfs = rw""")) | |
162 | conf.cluster = 'ceph' | |
163 | prepare.mount_osd('/dev/sda1', 1) | |
164 | expected = [ | |
165 | 'mount', '-t', 'xfs', '-o', | |
166 | 'rw', | |
167 | '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] | |
168 | assert expected == fake_run.calls[0]['args'][0] | |
169 | ||
170 | def test_multiple_options_are_used(self, conf_ceph_stub, fake_run): | |
171 | conf_ceph_stub(dedent("""[global] | |
172 | fsid = 1234lkjh1234 | |
173 | [osd] | |
174 | osd mount options xfs = rw auto exec""")) | |
175 | conf.cluster = 'ceph' | |
176 | prepare.mount_osd('/dev/sda1', 1) | |
177 | expected = [ | |
178 | 'mount', '-t', 'xfs', '-o', | |
179 | 'rw', 'auto', 'exec', | |
180 | '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] | |
181 | assert expected == fake_run.calls[0]['args'][0] | |
182 | ||
183 | def test_underscore_mount_options_are_used(self, conf_ceph_stub, fake_run): | |
184 | conf_ceph_stub(dedent("""[global] | |
185 | fsid = 1234lkjh1234 | |
186 | [osd] | |
187 | osd mount options xfs = rw""")) | |
188 | conf.cluster = 'ceph' | |
189 | prepare.mount_osd('/dev/sda1', 1) | |
190 | expected = [ | |
191 | 'mount', '-t', 'xfs', '-o', | |
192 | 'rw', | |
193 | '/dev/sda1', '/var/lib/ceph/osd/ceph-1'] | |
194 | assert expected == fake_run.calls[0]['args'][0] |