Skip to content

Commit

Permalink
raise proper storage manager exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
yehiyam committed Aug 25, 2020
1 parent 615d7bc commit 3ef338f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
32 changes: 24 additions & 8 deletions hkube_python_wrapper/storage/base_storage_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ def __init__(self, adpter):
self.adapter = adpter

def put(self, options):
return self.adapter.put(options)
try:
return self.adapter.put(options)
except Exception:
raise Exception('Failed to write data to storage')

def get(self, options):
data = self.adapter.get(options)
if(data is None):
return None
return data
try:
data = self.adapter.get(options)
if(data is None):
return None
return data
except Exception:
raise Exception('Failed to read data from storage')


def list(self, options):
return self.adapter.list(options)
try:
return self.adapter.list(options)
except Exception:
raise Exception('Failed to list storage data')

def listPrefix(self, options):
return self.adapter.listPrefix(options)
try:
return self.adapter.listPrefix(options)
except Exception:
raise Exception('Failed to listPrefix storage data')

def delete(self, options):
self.adapter.delete(options)
try:
self.adapter.delete(options)
except Exception:
raise Exception('Failed to delete storage data')
3 changes: 0 additions & 3 deletions hkube_python_wrapper/storage/fs_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def put(self, options):

def get(self, options):
filePath = self.getPath(self.basePath, options['path'])
if not (os.path.exists(filePath)):
return None

result = None
with open(filePath, 'rb') as f:
result = f.read()
Expand Down
5 changes: 2 additions & 3 deletions tests/test_storage_manager_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def test_put_get():

def test_fail_to_get():
options = {'path': dir1 + os.path.sep + 'no_such_path.txt', 'data': encoded}
a = sm.storage.get(options)
assert a == None

with pytest.raises(Exception, match='Failed to read data from storage'):
sm.storage.get(options)

def test_list():
options = {'path': dir1 + os.path.sep + 'a.txt', 'data': encoded}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_storage_manager_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_put_get():
def test_fail_to_get():
options = {'path': bucket + os.path.sep + 'no_such_key', 'data': encoded}

with pytest.raises(Exception, match='The specified key does not exist'):
with pytest.raises(Exception, match='Failed to read data from storage'):
sm.storage.get(options)


Expand Down

0 comments on commit 3ef338f

Please sign in to comment.