diff options
author | Prashanth Pai <ppai@redhat.com> | 2015-02-24 14:40:25 +0530 |
---|---|---|
committer | Thiago da Silva <thiago@redhat.com> | 2015-06-17 12:58:49 -0700 |
commit | 658ebecb84951fd8e418f15a5c8e2c8b1901b9d4 (patch) | |
tree | 1d60080d82fa66218081481965c322aef361e854 /test/functional/libgfapi-python-tests.py | |
parent | 904ca8ff630cb81fbd35ba337de12643376e058e (diff) |
Refactor volume initialization code
* Validate inputs during initialization of Volume object.
* Move glfs_new() and glfs_init() into mount() method.
* Provide user consumable unmount() method.
* Provide "mounted" property to Volume object. Users can now check state
whether a volume is virtual mounted or not.
Change-Id: Idc53ee7f9386ed995315bd5fb492a7d36f44875f
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/functional/libgfapi-python-tests.py')
-rw-r--r-- | test/functional/libgfapi-python-tests.py | 81 |
1 files changed, 68 insertions, 13 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index 1519426..c0e760a 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -15,8 +15,10 @@ import types import errno from gluster import gfapi +from gluster.exceptions import LibgfapiException from test import get_test_config from ConfigParser import NoSectionError, NoOptionError +from uuid import uuid4 config = get_test_config() if config: @@ -42,14 +44,10 @@ class BinFileOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.vol = gfapi.Volume(HOST, VOLNAME) - cls.vol.set_logging("/dev/null", 7) ret = cls.vol.mount() if ret == 0: # Cleanup volume cls.vol.rmtree("/", ignore_errors=True) - else: - raise Exception("Initializing volume %s:%s failed." % - (HOST, VOLNAME)) @classmethod def tearDownClass(cls): @@ -80,14 +78,10 @@ class FileOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.vol = gfapi.Volume(HOST, VOLNAME) - cls.vol.set_logging("/dev/null", 7) ret = cls.vol.mount() if ret == 0: # Cleanup volume cls.vol.rmtree("/", ignore_errors=True) - else: - raise Exception("Initializing volume %s:%s failed." % - (HOST, VOLNAME)) @classmethod def tearDownClass(cls): @@ -253,15 +247,10 @@ class DirOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.vol = gfapi.Volume(HOST, VOLNAME) - cls.vol.set_logging("/dev/null", 7) - cls.vol.mount() ret = cls.vol.mount() if ret == 0: # Cleanup volume cls.vol.rmtree("/", ignore_errors=True) - else: - raise Exception("Initializing volume %s:%s failed." % - (HOST, VOLNAME)) cls.testfile = "testfile" @classmethod @@ -323,3 +312,69 @@ class DirOpsTest(unittest.TestCase): self.vol.rmtree(self.dir_path, True) self.assertRaises(OSError, self.vol.lstat, f) self.assertRaises(OSError, self.vol.lstat, self.dir_path) + + +class TestVolumeInit(unittest.TestCase): + + def test_mount_unmount_default(self): + # Create volume object instance + vol = gfapi.Volume(HOST, VOLNAME) + # Check attribute init + self.assertEqual(vol.log_file, None) + self.assertEqual(vol.log_level, 7) + self.assertEqual(vol.host, HOST) + self.assertEqual(vol.volname, VOLNAME) + self.assertEqual(vol.port, 24007) + self.assertFalse(vol.mounted) + # Mount the volume + vol.mount() + # Check mounted property + self.assertTrue(vol.mounted) + # Unmount the volume + vol.unmount() + # Check mounted property again + self.assertFalse(vol.mounted) + # Do a double unmount - should not crash or raise exception + vol.unmount() + self.assertFalse(vol.mounted) + # Do a double mount - should not crash or raise exception + vol.mount() + vol.mount() + self.assertTrue(vol.mounted) + # Unmount the volume + vol.unmount() + self.assertFalse(vol.mounted) + + def test_mount_err(self): + # Volume does not exist + fake_volname = str(uuid4().hex)[:10] + vol = gfapi.Volume(HOST, fake_volname) + self.assertRaises(LibgfapiException, vol.mount) + self.assertFalse(vol.mounted) + + # Invalid host - glfs_set_volfile_server will fail + fake_hostname = str(uuid4().hex)[:10] + vol = gfapi.Volume(fake_hostname, VOLNAME) + self.assertRaises(LibgfapiException, vol.mount) + self.assertFalse(vol.mounted) + + def test_set_logging(self): + # Create volume object instance + vol = gfapi.Volume(HOST, VOLNAME) + # Call set_logging before mount() + log_file = "/tmp/%s" % (uuid4().hex) + vol.set_logging(log_file, 7) + # Mount the volume + vol.mount() + self.assertTrue(vol.mounted) + self.assertEqual(vol.log_file, log_file) + self.assertEqual(vol.log_level, 7) + # Check that log has been created and exists + self.assertTrue(os.path.exists(log_file)) + # Change the logging after mounting + log_file2 = "/tmp/%s" % (uuid4().hex) + vol.set_logging(log_file2, 7) + self.assertEqual(vol.log_file, log_file2) + # Unmount the volume + vol.unmount() + self.assertFalse(vol.mounted) |