]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume tests verify behavior of get_lv_from_argument
authorAlfredo Deza <adeza@redhat.com>
Fri, 20 Oct 2017 12:49:32 +0000 (08:49 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 27 Oct 2017 14:44:20 +0000 (10:44 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit adabbd462bcb19a6da65211e24dfb2b9b5043ef4)

src/ceph-volume/ceph_volume/tests/api/test_lvm.py

index 8d96c5d6942416d5e1330f7e171980a25680f805..e7e9015ce817185f5bc55a4f31c2d4f37c8a49ce 100644 (file)
@@ -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):