From 8acb5a7585a8e155cf0c9d0a60d76e75cdd725f7 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Thu, 10 Apr 2014 16:49:05 +0530 Subject: Fix functional tests * The order of elements in list returned by listdir() can vary and may not be sorted. This caused assertEqual in "test_listdir" to fail. * Also, some systems may have xattrs belonging to selinux. So, a listxattr can list them too. * Allow hostname/ip and volume name to be configured easily by setting it in test.conf. This enables functional tests to use a non-local volume. * Cleanup volume before and after running functional tests. * Added MANIFEST.in and LICENSE file Change-Id: Icfa6eb60e8d8e7ed4d6ab8190a2a2c80688999a3 Signed-off-by: Prashanth Pai --- test/__init__.py | 32 +++++++++++++++++++ test/functional/libgfapi-python-tests.py | 53 +++++++++++++++++++++++++++----- test/test.conf | 3 ++ 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 test/test.conf (limited to 'test') diff --git a/test/__init__.py b/test/__init__.py index e69de29..821f5e3 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1,32 @@ +# Copyright (c) 2012-2014 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import ConfigParser + + +def get_test_config(): + """ + Reads test.conf config file which contains configurable options + to run functional tests. + + :returns: ConfigParser instance if test.conf found, None otherwise. + """ + dirname = os.path.dirname(__file__) + conf_file = dirname + "/test.conf" + if os.path.exists(conf_file): + config = ConfigParser.ConfigParser() + config.read(conf_file) + return config + return None diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py index 3ef2401..5af7d70 100644 --- a/test/functional/libgfapi-python-tests.py +++ b/test/functional/libgfapi-python-tests.py @@ -20,6 +20,22 @@ import loremipsum import errno from glusterfs import gfapi +from test import get_test_config +from ConfigParser import NoSectionError, NoOptionError + +config = get_test_config() +if config: + try: + HOST = config.get('func_test', 'gfs_host') + except (NoSectionError, NoOptionError): + HOST = 'gfshost' + try: + VOLNAME = config.get('func_test', 'gfs_volname') + except (NoSectionError, NoOptionError): + VOLNAME = 'test' +else: + HOST = 'gfshost' + VOLNAME = 'test' class BinFileOpsTest(unittest.TestCase): @@ -30,12 +46,19 @@ class BinFileOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.vol = gfapi.Volume("gfshost", "test") + 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)) @classmethod def tearDownClass(cls): + cls.vol.rmtree("/", ignore_errors=True) cls.vol = None def setUp(self): @@ -61,12 +84,19 @@ class FileOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.vol = gfapi.Volume("gfshost", "test") + 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)) @classmethod def tearDownClass(cls): + cls.vol.rmtree("/", ignore_errors=True) cls.vol = None def setUp(self): @@ -195,7 +225,7 @@ class FileOpsTest(unittest.TestCase): xattrs = self.vol.listxattr(self.path) self.assertFalse(isinstance(xattrs, types.IntType)) - self.assertEqual(xattrs, ["trusted.key1", "trusted.key2"]) + self.assertTrue(set(["trusted.key1", "trusted.key2"]) <= set(xattrs)) buf = self.vol.getxattr(self.path, "trusted.key1", 32) self.assertFalse(isinstance(buf, types.IntType)) @@ -206,7 +236,7 @@ class FileOpsTest(unittest.TestCase): xattrs = self.vol.listxattr(self.path) self.assertFalse(isinstance(xattrs, types.IntType)) - self.assertEqual(xattrs, ["trusted.key2"]) + self.assertTrue(["trusted.key1"] not in xattrs) class DirOpsTest(unittest.TestCase): @@ -217,13 +247,21 @@ class DirOpsTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.vol = gfapi.Volume("gfshost", "test") + 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 def tearDownClass(cls): + cls.vol.rmtree("/", ignore_errors=True) cls.vol = None cls.testfile = None @@ -254,6 +292,7 @@ class DirOpsTest(unittest.TestCase): def test_listdir(self): dir_list = self.vol.listdir(self.dir_path) + dir_list.sort() self.assertEqual(dir_list, ["testfile0", "testfile1", "testfile2"]) def test_makedirs(self): diff --git a/test/test.conf b/test/test.conf new file mode 100644 index 0000000..4bf4dff --- /dev/null +++ b/test/test.conf @@ -0,0 +1,3 @@ +[func_test] +gfs_host = gfshost +gfs_volname = test -- cgit