summaryrefslogtreecommitdiffstats
path: root/src/ceph-volume/ceph_volume/tests/systemd/test_main.py
blob: 0af52e8d141c7d7a5a30a570c33645bc5494d40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest
from ceph_volume import exceptions, conf
from ceph_volume.systemd.main import parse_subcommand, main, process


class TestParseSubcommand(object):

    def test_no_subcommand_found(self):
        with pytest.raises(exceptions.SuffixParsingError):
            parse_subcommand('')

    def test_sub_command_is_found(self):
        result = parse_subcommand('lvm-1-sha-1-something-0')
        assert result == 'lvm'


class Capture(object):

    def __init__(self, *a, **kw):
        self.a = a
        self.kw = kw
        self.calls = []

    def __call__(self, *a, **kw):
        self.calls.append(a)
        self.calls.append(kw)


class TestMain(object):

    def setup(self):
        conf.log_path = '/tmp/'

    def test_no_arguments_parsing_error(self):
        with pytest.raises(RuntimeError):
            main(args=[])

    def test_parsing_suffix_error(self):
        with pytest.raises(exceptions.SuffixParsingError):
            main(args=['asdf'])

    def test_correct_command(self, monkeypatch):
        run = Capture()
        monkeypatch.setattr(process, 'run', run)
        main(args=['ceph-volume-systemd', 'lvm-8715BEB4-15C5-49DE-BA6F-401086EC7B41-0' ])
        command = run.calls[0][0]
        assert command == [
            'ceph-volume',
            'lvm', 'trigger',
            '8715BEB4-15C5-49DE-BA6F-401086EC7B41-0'
        ]