]>
Commit | Line | Data |
---|---|---|
d2e6a577 FG |
1 | import os |
2 | import pytest | |
3 | from ceph_volume import main | |
4 | ||
5 | ||
6 | class TestVolume(object): | |
7 | ||
8 | def test_main_spits_help_with_no_arguments(self, capsys): | |
91327a77 AA |
9 | with pytest.raises(SystemExit): |
10 | main.Volume(argv=[]) | |
d2e6a577 FG |
11 | stdout, stderr = capsys.readouterr() |
12 | assert 'Log Path' in stdout | |
13 | ||
14 | def test_warn_about_using_help_for_full_options(self, capsys): | |
91327a77 AA |
15 | with pytest.raises(SystemExit): |
16 | main.Volume(argv=[]) | |
d2e6a577 FG |
17 | stdout, stderr = capsys.readouterr() |
18 | assert 'See "ceph-volume --help" for full list' in stdout | |
19 | ||
20 | def test_environ_vars_show_up(self, capsys): | |
21 | os.environ['CEPH_CONF'] = '/opt/ceph.conf' | |
91327a77 AA |
22 | with pytest.raises(SystemExit): |
23 | main.Volume(argv=[]) | |
d2e6a577 FG |
24 | stdout, stderr = capsys.readouterr() |
25 | assert 'CEPH_CONF' in stdout | |
26 | assert '/opt/ceph.conf' in stdout | |
27 | ||
28 | def test_flags_are_parsed_with_help(self, capsys): | |
29 | with pytest.raises(SystemExit): | |
30 | main.Volume(argv=['ceph-volume', '--help']) | |
31 | stdout, stderr = capsys.readouterr() | |
32 | assert '--cluster' in stdout | |
33 | assert '--log-path' in stdout | |
b32b8144 FG |
34 | |
35 | def test_log_ignoring_missing_ceph_conf(self, caplog): | |
36 | with pytest.raises(SystemExit) as error: | |
37 | main.Volume(argv=['ceph-volume', '--cluster', 'barnacle', 'lvm', '--help']) | |
38 | # make sure we aren't causing an actual error | |
39 | assert error.value.code == 0 | |
494da23a | 40 | log = caplog.records[-1] |
b32b8144 | 41 | assert log.message == 'ignoring inability to load ceph.conf' |
2a845540 | 42 | assert log.levelname == 'WARNING' |
3a9019d9 FG |
43 | |
44 | def test_logs_current_command(self, caplog): | |
45 | with pytest.raises(SystemExit) as error: | |
46 | main.Volume(argv=['ceph-volume', '--cluster', 'barnacle', 'lvm', '--help']) | |
47 | # make sure we aren't causing an actual error | |
48 | assert error.value.code == 0 | |
494da23a | 49 | log = caplog.records[-2] |
3a9019d9 FG |
50 | assert log.message == 'Running command: ceph-volume --cluster barnacle lvm --help' |
51 | assert log.levelname == 'INFO' | |
f91f0fd5 | 52 | |
2a845540 | 53 | def test_logs_set_level_warning(self, caplog): |
f91f0fd5 | 54 | with pytest.raises(SystemExit) as error: |
2a845540 | 55 | main.Volume(argv=['ceph-volume', '--log-level', 'warning', '--cluster', 'barnacle', 'lvm', '--help']) |
f91f0fd5 TL |
56 | # make sure we aren't causing an actual error |
57 | assert error.value.code == 0 | |
58 | assert caplog.records | |
2a845540 | 59 | # only log levels of 'WARNING' |
f91f0fd5 | 60 | for log in caplog.records: |
2a845540 | 61 | assert log.levelname == 'WARNING' |
f91f0fd5 TL |
62 | |
63 | def test_logs_incorrect_log_level(self, capsys): | |
64 | with pytest.raises(SystemExit) as error: | |
65 | main.Volume(argv=['ceph-volume', '--log-level', 'foo', '--cluster', 'barnacle', 'lvm', '--help']) | |
66 | # make sure this is an error | |
67 | assert error.value.code != 0 | |
68 | stdout, stderr = capsys.readouterr() | |
69 | assert "invalid choice" in stderr |