Commit e60e6367 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device - TransportAPIDriver:

- improved HTTP status code checks
parent c0d7bc29
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -17,6 +17,12 @@ from device.service.driver_api._Driver import RESOURCE_ENDPOINTS

LOGGER = logging.getLogger(__name__)

HTTP_OK_CODES = {
    200,    # OK
    201,    # Created
    202,    # Accepted
    204,    # No Content
}

def find_key(resource, key):
    return json.loads(resource[1])[key]
@@ -97,10 +103,10 @@ def create_connectivity_service(
        LOGGER.exception('Exception creating ConnectivityService(uuid={:s}, data={:s})'.format(str(uuid), str(data)))
        results.append(e)
    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}'
            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

def delete_connectivity_service(root_url, timeout, uuid):
@@ -113,8 +119,8 @@ def delete_connectivity_service(root_url, timeout, uuid):
        LOGGER.exception('Exception deleting ConnectivityService(uuid={:s})'.format(str(uuid)))
        results.append(e)
    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}'
            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