summaryrefslogtreecommitdiffstats
path: root/test/unit/common
diff options
context:
space:
mode:
authorLuis Pabon <lpabon@redhat.com>2013-06-11 14:28:48 -0400
committerPeter Portante <pportant@redhat.com>2013-06-11 13:39:53 -0700
commitb00e479637955cec8a58a81db934d2ddf743a219 (patch)
treedbfee95b7ff7eabac34f91d3acc2b3045cf15453 /test/unit/common
parenta88accbe275d9d86d4626244ddd60653d5a9b6ab (diff)
Return correct status when deleting non-existing container
The code was raising an exception when the container (which happens to be a directory) did not exist. To be compatible with OpenStack Swift, we need to handle an object which its container/directory does not exist. BUG: 960944 (https://bugzilla.redhat.com/show_bug.cgi?id=960944) Change-Id: Ibb2db354a655e040fb70ebbe6a7d8f815d33dc0f Signed-off-by: Luis Pabon <lpabon@redhat.com> Reviewed-on: http://review.gluster.org/5201 Reviewed-by: Peter Portante <pportant@redhat.com> Tested-by: Peter Portante <pportant@redhat.com>
Diffstat (limited to 'test/unit/common')
-rw-r--r--test/unit/common/test_diskdir.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/unit/common/test_diskdir.py b/test/unit/common/test_diskdir.py
index 580e76a..be0c922 100644
--- a/test/unit/common/test_diskdir.py
+++ b/test/unit/common/test_diskdir.py
@@ -344,6 +344,22 @@ class TestDiskCommon(unittest.TestCase):
del dc.metadata['X-Container-Meta-foo']
assert dc.metadata == md_copy
+ def test_empty_dir_is_not_empty(self):
+ dc = dd.DiskCommon(self.td, self.fake_drives[0],
+ self.fake_accounts[0], self.fake_logger)
+ os.makedirs(os.path.join(self.td, self.fake_drives[0], 'aaabbbccc'))
+ self.assertFalse(dc.empty())
+
+ def test_empty_dir_is_empty(self):
+ dc = dd.DiskCommon(self.td, self.fake_drives[0],
+ self.fake_accounts[0], self.fake_logger)
+ self.assertTrue(dc.empty())
+
+ def test_empty_dir_does_not_exist(self):
+ dc = dd.DiskCommon(self.td, 'non_existent_drive',
+ self.fake_accounts[0], self.fake_logger)
+ self.assertTrue(dc.empty())
+
class TestContainerBroker(unittest.TestCase):
"""
@@ -498,6 +514,24 @@ class TestContainerBroker(unittest.TestCase):
self.assertEquals(info['x_container_sync_point1'], -1)
self.assertEquals(info['x_container_sync_point2'], -1)
+ def test_get_info_nonexistent_container(self):
+ broker = dd.DiskDir(self.path, self.drive, account='no_account',
+ container='no_container', logger=FakeLogger())
+ info = broker.get_info()
+
+ #
+ # Because broker._dir_exists is False and _update_object_count()
+ # has not been called yet, the values returned for
+ # object_count, bytes_used, and put_timestamp are '0' as
+ # a string. OpenStack Swift handles this situation by
+ # passing the value to float().
+ #
+ self.assertEquals(info['account'], 'no_account')
+ self.assertEquals(info['container'], 'no_container')
+ self.assertEquals(info['object_count'], '0')
+ self.assertEquals(info['bytes_used'], '0')
+ self.assertEquals(info['put_timestamp'], '0')
+
def test_set_x_syncs(self):
broker = self._get_broker(account='test1',
container='test2')