]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: add tests for tags
authorMohamad Gebai <mgebai@suse.com>
Tue, 2 Apr 2019 10:44:10 +0000 (06:44 -0400)
committerJan Fajerski <jfajerski@suse.com>
Wed, 8 Jan 2020 09:35:38 +0000 (10:35 +0100)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
(cherry picked from commit c88a6a8ad38410c60ea4945b46da6b3d458c0ff6)

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

index 5a8af8279d9cc444ba144b6131f918e623394f23..6e057c02fe4693584751992551e17f5c2cd84ca3 100644 (file)
@@ -594,6 +594,87 @@ class TestCreateLV(object):
         assert len(result) == 40
 
 
+class TestTags(object):
+
+    def setup(self):
+        self.foo_volume_clean = api.Volume(lv_name='foo_clean', lv_path='/pathclean',
+            vg_name='foo_group',
+            lv_tags='')
+        self.foo_volume = api.Volume(lv_name='foo', lv_path='/path',
+            vg_name='foo_group',
+            lv_tags='ceph.foo0=bar0,ceph.foo1=bar1,ceph.foo2=bar2')
+
+    def test_set_tag(self, monkeypatch, capture):
+        monkeypatch.setattr(process, 'run', capture)
+        monkeypatch.setattr(process, 'call', capture)
+        self.foo_volume_clean.set_tag('foo', 'bar')
+        expected = ['lvchange', '--addtag', 'foo=bar', '/pathclean']
+        assert capture.calls[0]['args'][0] == expected
+        assert self.foo_volume_clean.tags == {'foo': 'bar'}
+
+    def test_set_clear_tag(self, monkeypatch, capture):
+        monkeypatch.setattr(process, 'run', capture)
+        monkeypatch.setattr(process, 'call', capture)
+        self.foo_volume_clean.set_tag('foo', 'bar')
+        assert self.foo_volume_clean.tags == {'foo': 'bar'}
+        self.foo_volume_clean.clear_tag('foo')
+        expected = ['lvchange', '--deltag', 'foo=bar', '/pathclean']
+        assert self.foo_volume_clean.tags == {}
+        assert capture.calls[1]['args'][0] == expected
+
+    def test_set_tags(self, monkeypatch, capture):
+        monkeypatch.setattr(process, 'run', capture)
+        monkeypatch.setattr(process, 'call', capture)
+        tags = {'ceph.foo0': 'bar0', 'ceph.foo1': 'bar1', 'ceph.foo2': 'bar2'}
+        assert self.foo_volume.tags == tags
+
+        tags = {'ceph.foo0': 'bar0', 'ceph.foo1': 'baz1', 'ceph.foo2': 'baz2'}
+        self.foo_volume.set_tags(tags)
+        assert self.foo_volume.tags == tags
+
+        self.foo_volume.set_tag('ceph.foo1', 'other1')
+        tags['ceph.foo1'] = 'other1'
+        assert self.foo_volume.tags == tags
+
+        expected = [
+            ['lvchange', '--deltag', 'ceph.foo0=bar0', '/path'],
+            ['lvchange', '--addtag', 'ceph.foo0=bar0', '/path'],
+            ['lvchange', '--deltag', 'ceph.foo1=bar1', '/path'],
+            ['lvchange', '--addtag', 'ceph.foo1=baz1', '/path'],
+            ['lvchange', '--deltag', 'ceph.foo2=bar2', '/path'],
+            ['lvchange', '--addtag', 'ceph.foo2=baz2', '/path'],
+            ['lvchange', '--deltag', 'ceph.foo1=baz1', '/path'],
+            ['lvchange', '--addtag', 'ceph.foo1=other1', '/path'],
+        ]
+        # The order isn't guaranted
+        for call in capture.calls:
+            assert call['args'][0] in expected
+        assert len(capture.calls) == len(expected)
+
+    def test_clear_tags(self, monkeypatch, capture):
+        monkeypatch.setattr(process, 'run', capture)
+        monkeypatch.setattr(process, 'call', capture)
+        tags = {'ceph.foo0': 'bar0', 'ceph.foo1': 'bar1', 'ceph.foo2': 'bar2'}
+
+        self.foo_volume_clean.set_tags(tags)
+        assert self.foo_volume_clean.tags == tags
+        self.foo_volume_clean.clear_tags()
+        assert self.foo_volume_clean.tags == {}
+
+        expected = [
+            ['lvchange', '--addtag', 'ceph.foo0=bar0', '/pathclean'],
+            ['lvchange', '--addtag', 'ceph.foo1=bar1', '/pathclean'],
+            ['lvchange', '--addtag', 'ceph.foo2=bar2', '/pathclean'],
+            ['lvchange', '--deltag', 'ceph.foo0=bar0', '/pathclean'],
+            ['lvchange', '--deltag', 'ceph.foo1=bar1', '/pathclean'],
+            ['lvchange', '--deltag', 'ceph.foo2=bar2', '/pathclean'],
+        ]
+        # The order isn't guaranted
+        for call in capture.calls:
+            assert call['args'][0] in expected
+        assert len(capture.calls) == len(expected)
+
+
 class TestExtendVG(object):
 
     def setup(self):