Skip to content

Commit

Permalink
Update storage.py
Browse files Browse the repository at this point in the history
Just updating the way error messages are handled. This is a suggestion.
  • Loading branch information
cmickeyb authored Apr 23, 2024
1 parent aa6b7e6 commit 5416289
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions python/pdo/test/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ def verify_store_signature(store_response, duration, verifying_key) :
result = client.store_blocks([block_data], duration=default_duration)

r = verify_store_signature(result, default_duration, client.verifying_key)
if 1 != r:
raise ValueError("verify_store_signature error: {}".format(r))

if 'block_ids' not in result:
raise ValueError("block_ids not in result")

block_ids = result['block_ids']
if r < 0 :
raise RuntimeError("unknown error occured during signature verification; {}".format(r))
if r == 0 :
raise ValueError("storage signature verification failed")

block_ids = result.get('block_ids')
if block_ids is None or type(block_ids) != list :
raise RuntimeError('invalid response from block store')

if len(block_ids) != 1:
raise ValueError("len of block_ids is not 1: {}".format(len(block_ids)))
if list != type(result['block_ids']):
raise ValueError("block_ids not a list")
if len(result['block_ids']) < 1:
raise ValueError("no block in block_ids")
raise ValueError("too many blocks stored, expected 1 got {}".format(len(block_ids)))

block_id = result['block_ids'][0]

Expand Down Expand Up @@ -117,19 +115,20 @@ def verify_store_signature(store_response, duration, verifying_key) :
block_data.append(os.urandom(10))
block_data.append(os.urandom(10))
result = client.store_blocks(block_data, duration=default_duration)

r = verify_store_signature(result, default_duration, client.verifying_key)
if 1 != r:
raise ValueError("verify_store_signature error: {}".format(r))

if 'block_ids' not in result:
raise ValueError("block_ids not in result")

block_ids = result['block_ids']
logger.info('RESULT: %s', result)

r = verify_store_signature(result, default_duration, client.verifying_key)
if r < 0 :
raise RuntimeError("unknown error occured during signature verification; {}".format(r))
if r == 0 :
raise ValueError("storage signature verification failed")

block_ids = result.get('block_ids')
if block_ids is None or type(block_ids) != list :
raise RuntimeError('invalid response from block store')

if len(block_ids) != 3:
raise ValueError("block_ids should contain 3 blocks: {}".format(len(block_ids)))
raise ValueError("too many blocks stored, expected 3 got {}".format(len(block_ids)))

except Exception as e :
logger.error('bulk upload test failed; %s', str(e))
Expand Down

0 comments on commit 5416289

Please sign in to comment.