From: Alfredo Deza Date: Wed, 8 Nov 2017 17:49:31 +0000 (-0500) Subject: ceph-volume tests.util add tests for OSDPath validator X-Git-Tag: v13.0.1~256^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d7fc26ab4e2cebe485647510119ea300d47db184;p=ceph.git ceph-volume tests.util add tests for OSDPath validator Signed-off-by: Alfredo Deza --- diff --git a/src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py b/src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py index a280e9368fdc..22b962b1d52d 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py @@ -1,5 +1,6 @@ import pytest import argparse +from ceph_volume import exceptions from ceph_volume.util import arg_validators @@ -26,3 +27,27 @@ class TestLVPath(object): def test_abspath_is_valid(self): path = '/' assert self.validator(path) == path + + +class TestOSDPath(object): + + def setup(self): + self.validator = arg_validators.OSDPath() + + def test_is_not_root(self): + with pytest.raises(exceptions.SuperUserError): + self.validator('') + + def test_path_is_not_a_directory(self, is_root, tmpfile, monkeypatch): + monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False) + validator = arg_validators.OSDPath() + with pytest.raises(argparse.ArgumentError): + validator(tmpfile()) + + def test_files_are_missing(self, is_root, tmpdir, monkeypatch): + tmppath = str(tmpdir) + monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False) + validator = arg_validators.OSDPath() + with pytest.raises(argparse.ArgumentError) as error: + validator(tmppath) + assert 'Required file (ceph_fsid) was not found in OSD' in str(error)