From adabbd462bcb19a6da65211e24dfb2b9b5043ef4 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Fri, 20 Oct 2017 08:49:32 -0400 Subject: [PATCH] ceph-volume tests verify behavior of get_lv_from_argument Signed-off-by: Alfredo Deza --- .../ceph_volume/tests/api/test_lvm.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py index 8d96c5d6942..e7e9015ce81 100644 --- a/src/ceph-volume/ceph_volume/tests/api/test_lvm.py +++ b/src/ceph-volume/ceph_volume/tests/api/test_lvm.py @@ -73,6 +73,9 @@ def volumes(monkeypatch): monkeypatch.setattr(process, 'call', lambda x: ('', '', 0)) volumes = api.Volumes() volumes._purge() + # also patch api.Volumes so that when it is called, it will use the newly + # created fixture, with whatever the test method wants to append to it + monkeypatch.setattr(api, 'Volumes', lambda: volumes) return volumes @@ -325,6 +328,31 @@ class TestVolumeGroups(object): volume_groups.filter() +class TestGetLVFromArgument(object): + + def setup(self): + self.foo_volume = api.Volume( + lv_name='foo', lv_path='/path/to/lv', + vg_name='foo_group', lv_tags='' + ) + + def test_non_absolute_path_is_not_valid(self, volumes): + volumes.append(self.foo_volume) + assert api.get_lv_from_argument('foo') is None + + def test_too_many_slashes_is_invalid(self, volumes): + volumes.append(self.foo_volume) + assert api.get_lv_from_argument('path/to/lv') is None + + def test_absolute_path_is_not_lv(self, volumes): + volumes.append(self.foo_volume) + assert api.get_lv_from_argument('/path') is None + + def test_absolute_path_is_lv(self, volumes): + volumes.append(self.foo_volume) + assert api.get_lv_from_argument('/path/to/lv') == self.foo_volume + + class TestCreateLV(object): def setup(self): -- 2.39.5