]>
Commit | Line | Data |
---|---|---|
3efd9988 FG |
1 | import os |
2 | import pytest | |
3 | from ceph_volume.devices.simple import scan | |
4 | ||
5 | ||
6 | class TestScan(object): | |
7 | ||
8 | def test_main_spits_help_with_no_arguments(self, capsys): | |
9 | scan.Scan([]).main() | |
10 | stdout, stderr = capsys.readouterr() | |
b32b8144 | 11 | assert 'Scan an OSD directory (or data device) for files' in stdout |
3efd9988 FG |
12 | |
13 | ||
14 | class TestGetContents(object): | |
15 | ||
16 | def test_multiple_lines_are_left_as_is(self, tmpfile): | |
17 | magic_file = tmpfile(contents='first\nsecond\n') | |
18 | scanner = scan.Scan([]) | |
19 | assert scanner.get_contents(magic_file) == 'first\nsecond\n' | |
20 | ||
21 | def test_extra_whitespace_gets_removed(self, tmpfile): | |
22 | magic_file = tmpfile(contents='first ') | |
23 | scanner = scan.Scan([]) | |
24 | assert scanner.get_contents(magic_file) == 'first' | |
25 | ||
26 | def test_single_newline_values_are_trimmed(self, tmpfile): | |
27 | magic_file = tmpfile(contents='first\n') | |
28 | scanner = scan.Scan([]) | |
29 | assert scanner.get_contents(magic_file) == 'first' | |
30 | ||
31 | ||
32 | class TestEtcPath(object): | |
33 | ||
34 | def test_directory_is_valid(self, tmpdir): | |
35 | path = str(tmpdir) | |
36 | scanner = scan.Scan([]) | |
37 | scanner._etc_path = path | |
38 | assert scanner.etc_path == path | |
39 | ||
40 | def test_directory_does_not_exist_gets_created(self, tmpdir): | |
41 | path = os.path.join(str(tmpdir), 'subdir') | |
42 | scanner = scan.Scan([]) | |
43 | scanner._etc_path = path | |
44 | assert scanner.etc_path == path | |
45 | assert os.path.isdir(path) | |
46 | ||
47 | def test_complains_when_file(self, tmpfile): | |
48 | path = tmpfile() | |
49 | scanner = scan.Scan([]) | |
50 | scanner._etc_path = path | |
51 | with pytest.raises(RuntimeError): | |
52 | scanner.etc_path | |
b32b8144 FG |
53 | |
54 | ||
55 | class TestParseKeyring(object): | |
56 | ||
57 | def test_newlines_are_removed(self): | |
58 | contents = [ | |
59 | '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', | |
60 | '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] | |
61 | assert '\n' not in scan.parse_keyring('\n'.join(contents)) | |
62 | ||
63 | def test_key_has_spaces_removed(self): | |
64 | contents = [ | |
65 | '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', | |
66 | '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] | |
67 | result = scan.parse_keyring('\n'.join(contents)) | |
68 | assert result.startswith(' ') is False | |
69 | assert result.endswith(' ') is False | |
70 | ||
71 | def test_actual_key_is_extracted(self): | |
72 | contents = [ | |
73 | '[client.osd-lockbox.8d7a8ab2-5db0-4f83-a785-2809aba403d5]', | |
74 | '\tkey = AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==', ''] | |
75 | result = scan.parse_keyring('\n'.join(contents)) | |
76 | assert result == 'AQDtoGha/GYJExAA7HNl7Ukhqr7AKlCpLJk6UA==' |