Skip to content

Commit

Permalink
replace assert's with raise's
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vavala <[email protected]>
  • Loading branch information
bvavala committed Apr 23, 2024
1 parent 3999658 commit e6e5088
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions python/pdo/test/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@ def verify_store_signature(store_response, duration, verifying_key) :
try :
block_data = os.urandom(1000)
result = client.store_blocks([block_data], duration=default_duration)
assert result

assert (1 == verify_store_signature(result, default_duration, client.verifying_key))
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['block_ids']
assert block_ids and len(block_ids) == 1
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("too many blocks stored, expected 1 got {}".format(len(block_ids)))

block_id = result['block_ids'][0]
assert block_id

except Exception as e :
logger.error('put test failed; %s', str(e))
Expand All @@ -94,7 +100,8 @@ def verify_store_signature(store_response, duration, verifying_key) :
# -----------------------------------------------------------------
try :
verify_block_data = client.get_block(block_id)
assert block_data == verify_block_data
if block_data != verify_block_data:
raise ValueError("retrieved block data different than expected")
except Exception as e :
logger.error('verify put test failed; %s', str(e))
sys.exit(-1)
Expand All @@ -108,13 +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)
assert result
logger.info('RESULT: %s', result)

assert (1 == verify_store_signature(result, default_duration, client.verifying_key))
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['block_ids']
logger.info('RESULT: %s', result)
assert block_ids and len(block_ids) == 3
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("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 All @@ -126,7 +140,8 @@ def verify_store_signature(store_response, duration, verifying_key) :
try :
for i in range(len(block_ids)) :
verify_block_data = client.get_block(block_ids[i])
assert block_data[i] == verify_block_data
if block_data[i] != verify_block_data:
raise ValueError("retrieved block data different than expected: index {}".format(i))
except Exception as e :
logger.error('failed to verify bulk upload; %s', str(e))
sys.exit(-1)
Expand All @@ -137,7 +152,8 @@ def verify_store_signature(store_response, duration, verifying_key) :
try :
verify_block_data_list = client.get_blocks(block_ids)
for i in range(len(block_ids)) :
assert block_data[i] == verify_block_data_list[i]
if block_data[i] != verify_block_data_list[i]:
raise ValueError("retrieved block data different than expected in list: index {}".format(i))
except Exception as e :
logger.error('failed to verify bulk upload; %s', str(e))
sys.exit(-1)
Expand All @@ -149,8 +165,10 @@ def verify_store_signature(store_response, duration, verifying_key) :
status = client.check_blocks(block_ids)
assert status and len(status) == 3
for s in status :
assert s['size'] == 10
assert 0 < s['duration'] and s['duration'] <= default_duration
if s['size'] != 10:
raise ValueError("status size not 10: {}".format(s['size']))
if 0 >= s['duration'] and s['duration'] > default_duration:
raise ValueError("block status duration not within range: {}".format(s['duration']))

except Exception as e :
logger.exception('bulk status failed; %s', str(e))
Expand Down

0 comments on commit e6e5088

Please sign in to comment.