Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / ceph-volume / ceph_volume / tests / util / test_arg_validators.py
1 import pytest
2 import argparse
3 from ceph_volume import exceptions
4 from ceph_volume.util import arg_validators
5
6
7 invalid_lv_paths = [
8     '', 'lv_name', '/lv_name', 'lv_name/',
9     '/dev/lv_group/lv_name'
10 ]
11
12
13 class TestLVPath(object):
14
15     def setup(self):
16         self.validator = arg_validators.LVPath()
17
18     @pytest.mark.parametrize('path', invalid_lv_paths)
19     def test_no_slash_is_an_error(self, path):
20         with pytest.raises(argparse.ArgumentError):
21             self.validator(path)
22
23     def test_is_valid(self):
24         path = 'vg/lv'
25         assert self.validator(path) == path
26
27     def test_abspath_is_valid(self):
28         path = '/'
29         assert self.validator(path) == path
30
31
32 class TestOSDPath(object):
33
34     def setup(self):
35         self.validator = arg_validators.OSDPath()
36
37     def test_is_not_root(self):
38         with pytest.raises(exceptions.SuperUserError):
39             self.validator('')
40
41     def test_path_is_not_a_directory(self, is_root, tmpfile, monkeypatch):
42         monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False)
43         validator = arg_validators.OSDPath()
44         with pytest.raises(argparse.ArgumentError):
45             validator(tmpfile())
46
47     def test_files_are_missing(self, is_root, tmpdir, monkeypatch):
48         tmppath = str(tmpdir)
49         monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False)
50         validator = arg_validators.OSDPath()
51         with pytest.raises(argparse.ArgumentError) as error:
52             validator(tmppath)
53         assert 'Required file (ceph_fsid) was not found in OSD' in str(error)