]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/tests/test_main.py
3 from ceph_volume
import main
6 class TestVolume(object):
8 def test_main_spits_help_with_no_arguments(self
, capsys
):
9 with pytest
.raises(SystemExit):
11 stdout
, stderr
= capsys
.readouterr()
12 assert 'Log Path' in stdout
14 def test_warn_about_using_help_for_full_options(self
, capsys
):
15 with pytest
.raises(SystemExit):
17 stdout
, stderr
= capsys
.readouterr()
18 assert 'See "ceph-volume --help" for full list' in stdout
20 def test_environ_vars_show_up(self
, capsys
):
21 os
.environ
['CEPH_CONF'] = '/opt/ceph.conf'
22 with pytest
.raises(SystemExit):
24 stdout
, stderr
= capsys
.readouterr()
25 assert 'CEPH_CONF' in stdout
26 assert '/opt/ceph.conf' in stdout
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
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
40 log
= caplog
.records
[-1]
41 assert log
.message
== 'ignoring inability to load ceph.conf'
42 assert log
.levelname
== 'ERROR'
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
49 log
= caplog
.records
[-2]
50 assert log
.message
== 'Running command: ceph-volume --cluster barnacle lvm --help'
51 assert log
.levelname
== 'INFO'
53 def test_logs_set_level_error(self
, caplog
):
54 with pytest
.raises(SystemExit) as error
:
55 main
.Volume(argv
=['ceph-volume', '--log-level', 'error', '--cluster', 'barnacle', 'lvm', '--help'])
56 # make sure we aren't causing an actual error
57 assert error
.value
.code
== 0
59 # only log levels of 'ERROR' or above should be captured
60 for log
in caplog
.records
:
61 assert log
.levelname
in ['ERROR', 'CRITICAL']
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