linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Tony Asleson <tasleson@redhat.com>
To: linux-lvm@redhat.com
Subject: [linux-lvm] [PATCH 1/2] python: Make lv addTag/removeTag persistant
Date: Tue,  7 Apr 2015 15:54:01 -0500	[thread overview]
Message-ID: <1428440042-13679-1-git-send-email-tasleson@redhat.com> (raw)

Michael Schmidt posted an email on linux-lvm about this bug.
Posting this patch for review which corrects the issue and
adds a unit test to verify functionality.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 python/liblvm.c             |   17 +++++++-
 test/api/pytest.sh          |    1 +
 test/api/python_lvm_unit.py |   94 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 1 deletions(-)

diff --git a/python/liblvm.c b/python/liblvm.c
index 3828f27..002174f 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -1449,8 +1449,16 @@ static PyObject *_liblvm_lvm_lv_add_tag(lvobject *self, PyObject *args)
 		return NULL;
 	}
 
+    if (lvm_vg_write(self->parent_vgobj->vg) == -1)
+		goto error;
+
 	Py_INCREF(Py_None);
 	return Py_None;
+
+error:
+	PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+
+	return NULL;
 }
 
 static PyObject *_liblvm_lvm_lv_remove_tag(lvobject *self, PyObject *args)
@@ -1467,9 +1475,16 @@ static PyObject *_liblvm_lvm_lv_remove_tag(lvobject *self, PyObject *args)
 		return NULL;
 	}
 
-	Py_INCREF(Py_None);
+    if (lvm_vg_write(self->parent_vgobj->vg) == -1)
+        goto error;
 
+	Py_INCREF(Py_None);
 	return Py_None;
+
+error:
+	PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+
+	return NULL;
 }
 
 static PyObject *_liblvm_lvm_lv_get_tags(lvobject *self)
diff --git a/test/api/pytest.sh b/test/api/pytest.sh
index 36f55fa..00ab051 100644
--- a/test/api/pytest.sh
+++ b/test/api/pytest.sh
@@ -45,6 +45,7 @@ export PY_UNIT_PVS=$(cat DEVICES)
 #python_lvm_unit.py -v -f
 
 # Run individual tests for shorter error trace
+python_lvm_unit.py -v TestLvm.test_lv_persistence
 python_lvm_unit.py -v TestLvm.test_config_find_bool
 python_lvm_unit.py -v TestLvm.test_config_override
 python_lvm_unit.py -v TestLvm.test_config_reload
diff --git a/test/api/python_lvm_unit.py b/test/api/python_lvm_unit.py
index 2f22fae..76f7f8a 100755
--- a/test/api/python_lvm_unit.py
+++ b/test/api/python_lvm_unit.py
@@ -368,6 +368,100 @@ class TestLvm(unittest.TestCase):
 		lv.rename(current_name)
 		vg.close()
 
+	def test_lv_persistence(self):
+		# Make changes to the lv, close the vg and re-open to make sure that
+		# the changes persist
+		lv_name = 'lv_test_persist'
+		TestLvm._create_thick_lv(TestLvm._get_pv_device_names(), lv_name)
+
+		# Test rename
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		current_name = lv.getName()
+		new_name = rs()
+		lv.rename(new_name)
+
+		vg.close()
+		vg = None
+
+		lv, vg = TestLvm._get_lv(None, new_name)
+
+		self.assertTrue(lv is not None)
+		
+		if lv and vg:
+			lv.rename(lv_name)
+			vg.close()
+			vg = None
+
+		# Test lv tag add
+		tag = 'hello_world'
+
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		lv.addTag(tag)
+		vg.close()
+		vg = None
+
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		tags = lv.getTags()
+
+		self.assertTrue(tag in tags)
+		vg.close()
+		vg = None
+
+		# Test lv tag delete
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)
+		
+		if lv and vg:
+			tags = lv.getTags()
+
+			for t in tags:
+				lv.removeTag(t)	
+
+			vg.close()
+			vg = None
+		
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)
+
+		if lv and vg:
+			tags = lv.getTags()
+			
+			if tags:
+				self.assertEqual(len(tags), 0)		
+			vg.close()
+			vg = None
+
+		# Test lv deactivate
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)		
+
+		if lv and vg:
+			lv.deactivate()
+			vg.close()
+			vg = None
+
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)
+		if lv and vg:	
+			self.assertFalse(lv.isActive())		
+			vg.close()
+			vg = None
+
+		# Test lv activate
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)
+		if lv and vg:
+			lv.activate()
+			vg.close()
+			vg = None
+
+		lv, vg = TestLvm._get_lv(None, lv_name)
+		self.assertTrue(lv is not None and vg is not None)
+		if lv and vg:
+			self.assertTrue(lv.isActive())
+			vg.close()
+			vg = None
+
 	def test_lv_snapshot(self):
 
 		thin_lv = 'thin_lv'
-- 
1.7.1

             reply	other threads:[~2015-04-07 20:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 20:54 Tony Asleson [this message]
2015-04-07 20:54 ` [linux-lvm] [PATCH 2/2] python unit test ws fixes Tony Asleson
2015-04-07 21:04 ` [linux-lvm] [PATCH 1/2] python: Make lv addTag/removeTag persistant Alasdair G Kergon
2015-04-07 21:55   ` Tony Asleson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428440042-13679-1-git-send-email-tasleson@redhat.com \
    --to=tasleson@redhat.com \
    --cc=linux-lvm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).