Skip to content
Snippets Groups Projects
Commit 4a3028d2 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device Driver MicroWave:

- minor improvement in error checking
parent eb08a47f
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!22Microwave ServiceHandler
...@@ -17,6 +17,12 @@ from device.service.driver_api._Driver import RESOURCE_ENDPOINTS ...@@ -17,6 +17,12 @@ from device.service.driver_api._Driver import RESOURCE_ENDPOINTS
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
HTTP_OK_CODES = {
200, # OK
201, # Created
202, # Accepted
204, # No Content
}
def find_key(resource, key): def find_key(resource, key):
return json.loads(resource[1])[key] return json.loads(resource[1])[key]
...@@ -128,10 +134,10 @@ def create_connectivity_service( ...@@ -128,10 +134,10 @@ def create_connectivity_service(
LOGGER.exception('Exception creating ConnectivityService(uuid={:s}, data={:s})'.format(str(uuid), str(data))) LOGGER.exception('Exception creating ConnectivityService(uuid={:s}, data={:s})'.format(str(uuid), str(data)))
results.append(e) results.append(e)
else: else:
if response.status_code != 201: if response.status_code not in HTTP_OK_CODES:
msg = 'Could not create ConnectivityService(uuid={:s}, data={:s}). status_code={:s} reply={:s}' msg = 'Could not create ConnectivityService(uuid={:s}, data={:s}). status_code={:s} reply={:s}'
LOGGER.error(msg.format(str(uuid), str(data), str(response.status_code), str(response))) LOGGER.error(msg.format(str(uuid), str(data), str(response.status_code), str(response)))
results.append(response.status_code == 201) results.append(response.status_code in HTTP_OK_CODES)
return results return results
def delete_connectivity_service(root_url, timeout, uuid): def delete_connectivity_service(root_url, timeout, uuid):
...@@ -144,8 +150,8 @@ def delete_connectivity_service(root_url, timeout, uuid): ...@@ -144,8 +150,8 @@ def delete_connectivity_service(root_url, timeout, uuid):
LOGGER.exception('Exception deleting ConnectivityService(uuid={:s})'.format(str(uuid))) LOGGER.exception('Exception deleting ConnectivityService(uuid={:s})'.format(str(uuid)))
results.append(e) results.append(e)
else: else:
if response.status_code != 201: if response.status_code not in HTTP_OK_CODES:
msg = 'Could not delete ConnectivityService(uuid={:s}). status_code={:s} reply={:s}' msg = 'Could not delete ConnectivityService(uuid={:s}). status_code={:s} reply={:s}'
LOGGER.error(msg.format(str(uuid), str(response.status_code), str(response))) LOGGER.error(msg.format(str(uuid), str(response.status_code), str(response)))
results.append(response.status_code == 202) results.append(response.status_code in HTTP_OK_CODES)
return results return results
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment