Skip to content

Commit 9f817f7

Browse files
committed
Added test and fixed s3 delete error handling.
1 parent 734995d commit 9f817f7

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

datajoint/s3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ def get_size(self, name):
7676
except minio.error.S3Error as e:
7777
if e.code == 'NoSuchKey':
7878
raise errors.MissingExternalFile
79-
else:
8079
raise e
8180

8281
def remove_object(self, name):
8382
logger.debug('remove_object: {}:{}'.format(self.bucket, name))
8483
try:
8584
self.client.remove_object(self.bucket, str(name))
86-
except minio.ResponseError:
87-
return errors.DataJointError('Failed to delete %s from s3 storage' % name)
85+
except minio.error.MinioException:
86+
raise errors.DataJointError('Failed to delete %s from s3 storage' % name)
87+
except ValueError:
88+
raise errors.DataJointError('minIO ValueError')

tests/test_s3.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from . import S3_CONN_INFO
2-
2+
import time
33
from minio import Minio
4+
from minio.objectlockconfig import ObjectLockConfig
5+
from minio.commonconfig import COMPLIANCE, ENABLED, GOVERNANCE
46
import urllib3
57
import certifi
6-
from nose.tools import assert_true
8+
from nose.tools import assert_true, raises
79

10+
from .schema_external import schema, SimpleRemote
11+
from datajoint.errors import DataJointError
812

913
class TestS3:
1014

@@ -29,7 +33,7 @@ def test_connection():
2933
http_client=http_client)
3034

3135
assert_true(minio_client.bucket_exists(S3_CONN_INFO['bucket']))
32-
36+
3337
@staticmethod
3438
def test_connection_secure():
3539

@@ -52,6 +56,31 @@ def test_connection_secure():
5256

5357
assert_true(minio_client.bucket_exists(S3_CONN_INFO['bucket']))
5458
@staticmethod
55-
def test_remove_object():
59+
@raises(DataJointError)
60+
def test_remove_object_exception():
5661
#https://github.com/datajoint/datajoint-python/issues/952
57-
raise Exception("test")
62+
63+
# Initialize httpClient with relevant timeout.
64+
http_client = urllib3.PoolManager(
65+
timeout=30, cert_reqs='CERT_REQUIRED',
66+
ca_certs=certifi.where(),
67+
retries=urllib3.Retry(total=3, backoff_factor=0.2,
68+
status_forcelist=[
69+
500, 502,
70+
503, 504]))
71+
72+
# Initialize minioClient with an endpoint and access/secret keys.
73+
minio_client = Minio(
74+
S3_CONN_INFO['endpoint'],
75+
access_key=S3_CONN_INFO['access_key'],
76+
secret_key=S3_CONN_INFO['secret_key'],
77+
secure=True,
78+
http_client=http_client)
79+
80+
81+
schema.external['share'].s3.bucket = ''
82+
schema.external['share'].s3.remove_object('test')
83+
84+
85+
86+

0 commit comments

Comments
 (0)