Verified Commit 09dd20cd authored by Michal Mladek's avatar Michal Mladek
Browse files

Refactor - unify returned value from backup_delete and backup_ondemand

parent 147654ac
Pipeline #36672 passed with stage
in 52 seconds
......@@ -389,15 +389,24 @@ def backup_delete(reg_code, url, backup_id):
:param reg_code: router registration code(16 bytes length)
:param url: url of remote REST API
:param backup_id: id of backup stored in remote database
:return: dictionary
:return: None
:raises: SSBackupsException: when anything went wrong
"""
call_rest_api(
res = call_rest_api(
reg_code,
url,
'delete',
backup_id=backup_id
backup_id=backup_id,
fail=False,
content_type=True
)
status_code = res.split('\n')[-2]
if int(status_code) / 100 != 2:
raise SSBackupsException(
"Could not delete backup.",
ERR_CODE_API_CALL
)
def backup_ondemand(reg_code, url, backup_id):
......@@ -406,22 +415,21 @@ def backup_ondemand(reg_code, url, backup_id):
:param reg_code: router registration code(16 bytes length)
:param url: url of remote REST API
:param backup_id: id of backup stored in remote database
:return: string: JSON response {"id":x}, when x is positive integer
:return: None
:raises: SSBackupsException: when anything went wrong
"""
res = call_rest_api(
reg_code,
url,
'ondemand',
backup_id=backup_id
backup_id=backup_id,
fail=False,
content_type=True
)
try:
return json.loads(res)
except Exception as exc:
status_code = res.split('\n')[-2]
if int(status_code) / 100 != 2:
raise SSBackupsException(
"JSON decoding response on ondemand call ended with this error << {msg} >>.".format(
msg=exc.message
),
"Could not mark backup as on-demand.",
ERR_CODE_API_CALL
)
......@@ -644,8 +652,7 @@ if __name__ == '__main__':
)
elif cli_args.action == 'ondemand':
# returns JSON {"id": x}
response = backup_ondemand(
backup_ondemand(
registration_code,
cli_args.url,
cli_args.backup_id
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment