diff options
Diffstat (limited to 'ufo/test/unit')
-rw-r--r-- | ufo/test/unit/common/data/README.rings | 3 | ||||
-rw-r--r-- | ufo/test/unit/common/data/account.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/account.ring.gz | bin | 0 -> 183 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/backups/1365124498.account.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/backups/1365124498.container.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/backups/1365124498.object.builder | bin | 0 -> 228 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/backups/1365124499.object.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/container.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/container.ring.gz | bin | 0 -> 185 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/object.builder | bin | 0 -> 537 bytes | |||
-rw-r--r-- | ufo/test/unit/common/data/object.ring.gz | bin | 0 -> 182 bytes | |||
-rw-r--r-- | ufo/test/unit/common/test_ring.py | 74 | ||||
-rw-r--r-- | ufo/test/unit/common/test_utils.py | 24 |
13 files changed, 39 insertions, 62 deletions
diff --git a/ufo/test/unit/common/data/README.rings b/ufo/test/unit/common/data/README.rings new file mode 100644 index 00000000000..6457501fb38 --- /dev/null +++ b/ufo/test/unit/common/data/README.rings @@ -0,0 +1,3 @@ +The unit tests expect certain ring data built using the following command: + + ../../../../bin/gluster-swift-gen-builders test iops
\ No newline at end of file diff --git a/ufo/test/unit/common/data/account.builder b/ufo/test/unit/common/data/account.builder Binary files differnew file mode 100644 index 00000000000..090ba4b74ff --- /dev/null +++ b/ufo/test/unit/common/data/account.builder diff --git a/ufo/test/unit/common/data/account.ring.gz b/ufo/test/unit/common/data/account.ring.gz Binary files differnew file mode 100644 index 00000000000..6d4c8547437 --- /dev/null +++ b/ufo/test/unit/common/data/account.ring.gz diff --git a/ufo/test/unit/common/data/backups/1365124498.account.builder b/ufo/test/unit/common/data/backups/1365124498.account.builder Binary files differnew file mode 100644 index 00000000000..090ba4b74ff --- /dev/null +++ b/ufo/test/unit/common/data/backups/1365124498.account.builder diff --git a/ufo/test/unit/common/data/backups/1365124498.container.builder b/ufo/test/unit/common/data/backups/1365124498.container.builder Binary files differnew file mode 100644 index 00000000000..733d27dd9e3 --- /dev/null +++ b/ufo/test/unit/common/data/backups/1365124498.container.builder diff --git a/ufo/test/unit/common/data/backups/1365124498.object.builder b/ufo/test/unit/common/data/backups/1365124498.object.builder Binary files differnew file mode 100644 index 00000000000..ff877ec957d --- /dev/null +++ b/ufo/test/unit/common/data/backups/1365124498.object.builder diff --git a/ufo/test/unit/common/data/backups/1365124499.object.builder b/ufo/test/unit/common/data/backups/1365124499.object.builder Binary files differnew file mode 100644 index 00000000000..8b8cd6c1e34 --- /dev/null +++ b/ufo/test/unit/common/data/backups/1365124499.object.builder diff --git a/ufo/test/unit/common/data/container.builder b/ufo/test/unit/common/data/container.builder Binary files differnew file mode 100644 index 00000000000..733d27dd9e3 --- /dev/null +++ b/ufo/test/unit/common/data/container.builder diff --git a/ufo/test/unit/common/data/container.ring.gz b/ufo/test/unit/common/data/container.ring.gz Binary files differnew file mode 100644 index 00000000000..592b84bab9f --- /dev/null +++ b/ufo/test/unit/common/data/container.ring.gz diff --git a/ufo/test/unit/common/data/object.builder b/ufo/test/unit/common/data/object.builder Binary files differnew file mode 100644 index 00000000000..8b8cd6c1e34 --- /dev/null +++ b/ufo/test/unit/common/data/object.builder diff --git a/ufo/test/unit/common/data/object.ring.gz b/ufo/test/unit/common/data/object.ring.gz Binary files differnew file mode 100644 index 00000000000..d2f7192b6ce --- /dev/null +++ b/ufo/test/unit/common/data/object.ring.gz diff --git a/ufo/test/unit/common/test_ring.py b/ufo/test/unit/common/test_ring.py index 48ed9520b81..8b7509ccea8 100644 --- a/ufo/test/unit/common/test_ring.py +++ b/ufo/test/unit/common/test_ring.py @@ -13,69 +13,43 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import unittest import gluster.swift.common.constraints -from gluster.swift.common.ring import * -from gluster.swift.common.Glusterfs import SWIFT_DIR +import swift.common.utils +from gluster.swift.common.ring import Ring -def _mock_ring_data(): - return [{'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1', 'port': 6012, \ - 'meta': '', 'device': 'test', 'id': 0}, - {'zone': 2, 'weight': 100.0, 'ip': '127.0.0.1', 'id': 1, \ - 'meta': '', 'device': 'iops', 'port': 6012}] class TestRing(unittest.TestCase): """ Tests for common.utils """ def setUp(self): - self.ring = Ring(SWIFT_DIR, ring_name='object') + swift.common.utils.HASH_PATH_SUFFIX = 'endcap' + swiftdir = os.path.join(os.getcwd(), "common", "data") + self.ring = Ring(swiftdir, ring_name='object') def test_first_device(self): - try: - __devs = self.ring._devs - self.ring._devs = _mock_ring_data() - - part, node = self.ring.get_nodes('test') - assert node[0]['device'] == 'test' - node = self.ring.get_part_nodes(0) - assert node[0]['device'] == 'test' - for node in self.ring.get_more_nodes(0): - assert node['device'] == 'volume_not_in_ring' - finally: - self.ring._devs = __devs + part, node = self.ring.get_nodes('test') + assert node[0]['device'] == 'test' + node = self.ring.get_part_nodes(0) + assert node[0]['device'] == 'test' + for node in self.ring.get_more_nodes(0): + assert node['device'] == 'volume_not_in_ring' def test_invalid_device(self): - try: - __devs = self.ring._devs - self.ring._devs = _mock_ring_data() - - part, node = self.ring.get_nodes('test2') - assert node[0]['device'] == 'volume_not_in_ring' - node = self.ring.get_part_nodes(0) - assert node[0]['device'] == 'volume_not_in_ring' - finally: - self.ring._devs = __devs + part, node = self.ring.get_nodes('test2') + assert node[0]['device'] == 'volume_not_in_ring' + node = self.ring.get_part_nodes(0) + assert node[0]['device'] == 'volume_not_in_ring' def test_second_device(self): - try: - __devs = self.ring._devs - self.ring._devs = _mock_ring_data() - - part, node = self.ring.get_nodes('iops') - assert node[0]['device'] == 'iops' - node = self.ring.get_part_nodes(0) - assert node[0]['device'] == 'iops' - for node in self.ring.get_more_nodes(0): - assert node['device'] == 'volume_not_in_ring' - finally: - self.ring._devs = __devs + part, node = self.ring.get_nodes('iops') + assert node[0]['device'] == 'iops' + node = self.ring.get_part_nodes(0) + assert node[0]['device'] == 'iops' + for node in self.ring.get_more_nodes(0): + assert node['device'] == 'volume_not_in_ring' def test_second_device_with_reseller_prefix(self): - try: - __devs = self.ring._devs - self.ring._devs = _mock_ring_data() - - part, node = self.ring.get_nodes('AUTH_iops') - assert node[0]['device'] == 'iops' - finally: - self.ring._devs = __devs + part, node = self.ring.get_nodes('AUTH_iops') + assert node[0]['device'] == 'iops' diff --git a/ufo/test/unit/common/test_utils.py b/ufo/test/unit/common/test_utils.py index dd89bd5e4ef..92ce9aef30f 100644 --- a/ufo/test/unit/common/test_utils.py +++ b/ufo/test/unit/common/test_utils.py @@ -41,7 +41,7 @@ _xattr_rem_err = {} def _xkey(path, key): return "%s:%s" % (path, key) -def _setxattr(path, key, value): +def _setxattr(path, key, value, *args, **kwargs): _xattr_op_cnt['set'] += 1 xkey = _xkey(path, key) if xkey in _xattr_set_err: @@ -51,7 +51,7 @@ def _setxattr(path, key, value): global _xattrs _xattrs[xkey] = value -def _getxattr(path, key): +def _getxattr(path, key, *args, **kwargs): _xattr_op_cnt['get'] += 1 xkey = _xkey(path, key) if xkey in _xattr_get_err: @@ -67,7 +67,7 @@ def _getxattr(path, key): raise e return ret_val -def _removexattr(path, key): +def _removexattr(path, key, *args, **kwargs): _xattr_op_cnt['remove'] += 1 xkey = _xkey(path, key) if xkey in _xattr_rem_err: @@ -93,20 +93,20 @@ def _initxattr(): _xattr_rem_err = {} # Save the current methods - global _xattr_set; _xattr_set = xattr.set - global _xattr_get; _xattr_get = xattr.get - global _xattr_remove; _xattr_remove = xattr.remove + global _xattr_set; _xattr_set = xattr.setxattr + global _xattr_get; _xattr_get = xattr.getxattr + global _xattr_remove; _xattr_remove = xattr.removexattr # Monkey patch the calls we use with our internal unit test versions - xattr.set = _setxattr - xattr.get = _getxattr - xattr.remove = _removexattr + xattr.setxattr = _setxattr + xattr.getxattr = _getxattr + xattr.removexattr = _removexattr def _destroyxattr(): # Restore the current methods just in case - global _xattr_set; xattr.set = _xattr_set - global _xattr_get; xattr.get = _xattr_get - global _xattr_remove; xattr.remove = _xattr_remove + global _xattr_set; xattr.setxattr = _xattr_set + global _xattr_get; xattr.getxattr = _xattr_get + global _xattr_remove; xattr.removexattr = _xattr_remove # Destroy the stored values and global _xattrs; _xattrs = None |