summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/common/test_diskfile.py48
1 files changed, 45 insertions, 3 deletions
diff --git a/test/unit/common/test_diskfile.py b/test/unit/common/test_diskfile.py
index 76a9d1a..410f113 100644
--- a/test/unit/common/test_diskfile.py
+++ b/test/unit/common/test_diskfile.py
@@ -21,18 +21,21 @@ import errno
import unittest
import tempfile
import shutil
+import mock
from mock import patch
from hashlib import md5
-from swift.common.utils import normalize_timestamp
-from swift.common.exceptions import DiskFileNotExist, DiskFileError
-import gluster.swift.common.DiskFile
+
import gluster.swift.common.utils
+import gluster.swift.common.DiskFile
+from swift.common.utils import normalize_timestamp
from gluster.swift.common.DiskFile import Gluster_DiskFile
+from swift.common.exceptions import DiskFileNotExist, DiskFileError
from gluster.swift.common.utils import DEFAULT_UID, DEFAULT_GID, X_TYPE, \
X_OBJECT_TYPE, DIR_OBJECT
from test_utils import _initxattr, _destroyxattr
from test.unit import FakeLogger
+from gluster.swift.common.exceptions import *
_metadata = {}
@@ -569,6 +572,45 @@ class TestDiskFile(unittest.TestCase):
finally:
shutil.rmtree(td)
+
+ def test_put_ENOSPC(self):
+ td = tempfile.mkdtemp()
+ the_cont = os.path.join(td, "vol0", "bar")
+ try:
+ os.makedirs(the_cont)
+ gdf = Gluster_DiskFile(td, "vol0", "p57", "ufo47", "bar",
+ "z", self.lg)
+ assert gdf._obj == "z"
+ assert gdf._obj_path == ""
+ assert gdf.name == "bar"
+ assert gdf.datadir == the_cont
+ assert gdf.data_file is None
+
+ body = '1234\n'
+ etag = md5()
+ etag.update(body)
+ etag = etag.hexdigest()
+ metadata = {
+ 'X-Timestamp': '1234',
+ 'Content-Type': 'file',
+ 'ETag': etag,
+ 'Content-Length': '5',
+ }
+ def mock_open(*args, **kwargs):
+ raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC))
+
+ with mock.patch("os.open", mock_open):
+ try:
+ with gdf.mkstemp() as fd:
+ assert gdf.tmppath is not None
+ tmppath = gdf.tmppath
+ os.write(fd, body)
+ gdf.put(fd, metadata)
+ except DiskFileNoSpace:
+ pass
+ finally:
+ shutil.rmtree(td)
+
def test_put_obj_path(self):
the_obj_path = os.path.join("b", "a")
the_file = os.path.join(the_obj_path, "z")