Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-volume / ceph_volume / tests / systemd / test_main.py
1 import pytest
2 from ceph_volume import exceptions, conf
3 from ceph_volume.systemd import main
4
5
6 class TestParseSubcommand(object):
7
8     def test_no_subcommand_found(self):
9         with pytest.raises(exceptions.SuffixParsingError):
10             main.parse_subcommand('')
11
12     def test_sub_command_is_found(self):
13         result = main.parse_subcommand('lvm-1-sha-1-something-0')
14         assert result == 'lvm'
15
16
17 class Capture(object):
18
19     def __init__(self, *a, **kw):
20         self.a = a
21         self.kw = kw
22         self.calls = []
23
24     def __call__(self, *a, **kw):
25         self.calls.append(a)
26         self.calls.append(kw)
27
28
29 class TestMain(object):
30
31     def setup(self):
32         conf.log_path = '/tmp/'
33
34     def test_no_arguments_parsing_error(self):
35         with pytest.raises(RuntimeError):
36             main.main(args=[])
37
38     def test_parsing_suffix_error(self):
39         with pytest.raises(exceptions.SuffixParsingError):
40             main.main(args=['asdf'])
41
42     def test_correct_command(self, monkeypatch):
43         run = Capture()
44         monkeypatch.setattr(main.process, 'run', run)
45         main.main(args=['ceph-volume-systemd', 'lvm-8715BEB4-15C5-49DE-BA6F-401086EC7B41-0' ])
46         command = run.calls[0][0]
47         assert command == [
48             'ceph-volume',
49             'lvm', 'trigger',
50             '8715BEB4-15C5-49DE-BA6F-401086EC7B41-0'
51         ]