Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-volume / ceph_volume / tests / devices / lvm / test_prepare.py
1 import pytest
2 from ceph_volume.devices import lvm
3
4
5 class TestLVM(object):
6
7     def test_main_spits_help_with_no_arguments(self, capsys):
8         lvm.main.LVM([]).main()
9         stdout, stderr = capsys.readouterr()
10         assert 'Use LVM and LVM-based technologies like dmcache to deploy' in stdout
11
12     def test_main_shows_activate_subcommands(self, capsys):
13         lvm.main.LVM([]).main()
14         stdout, stderr = capsys.readouterr()
15         assert 'activate ' in stdout
16         assert 'Discover and mount' in stdout
17
18     def test_main_shows_prepare_subcommands(self, capsys):
19         lvm.main.LVM([]).main()
20         stdout, stderr = capsys.readouterr()
21         assert 'prepare ' in stdout
22         assert 'Format an LVM device' in stdout
23
24
25 class TestPrepareDevice(object):
26
27     def test_cannot_use_device(self):
28         with pytest.raises(RuntimeError) as error:
29             lvm.prepare.Prepare([]).prepare_device(
30                     '/dev/var/foo', 'data', 'asdf', '0')
31         assert 'Cannot use device (/dev/var/foo)' in str(error)
32         assert 'A vg/lv path or an existing device is needed' in str(error)
33
34 class TestPrepare(object):
35
36     def test_main_spits_help_with_no_arguments(self, capsys):
37         lvm.prepare.Prepare([]).main()
38         stdout, stderr = capsys.readouterr()
39         assert 'Prepare an OSD by assigning an ID and FSID' in stdout
40
41     def test_main_shows_full_help(self, capsys):
42         with pytest.raises(SystemExit):
43             lvm.prepare.Prepare(argv=['--help']).main()
44         stdout, stderr = capsys.readouterr()
45         assert 'Use the filestore objectstore' in stdout
46         assert 'Use the bluestore objectstore' in stdout
47         assert 'A physical device or logical' in stdout
48
49
50 class TestGetJournalLV(object):
51
52     @pytest.mark.parametrize('arg', ['', '///', None, '/dev/sda1'])
53     def test_no_journal_on_invalid_path(self, monkeypatch, arg):
54         monkeypatch.setattr(lvm.prepare.api, 'get_lv', lambda **kw: False)
55         prepare = lvm.prepare.Prepare([])
56         assert prepare.get_lv(arg) is None
57
58     def test_no_journal_lv_found(self, monkeypatch):
59         # patch it with 0 so we know we are getting to get_lv
60         monkeypatch.setattr(lvm.prepare.api, 'get_lv', lambda **kw: 0)
61         prepare = lvm.prepare.Prepare([])
62         assert prepare.get_lv('vg/lv') == 0
63
64
65 class TestActivate(object):
66
67     def test_main_spits_help_with_no_arguments(self, capsys):
68         lvm.activate.Activate([]).main()
69         stdout, stderr = capsys.readouterr()
70         assert 'Activate OSDs by discovering them with' in stdout
71
72     def test_main_shows_full_help(self, capsys):
73         with pytest.raises(SystemExit):
74             lvm.activate.Activate(argv=['--help']).main()
75         stdout, stderr = capsys.readouterr()
76         assert 'optional arguments' in stdout
77         assert 'positional arguments' in stdout
78