Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-volume / ceph_volume / tests / devices / simple / test_scan.py
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()
11         assert 'Scan an OSD directory for files' in stdout
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