[AETHER-3114] Handle 500 error when making ROC request
Change-Id: If920152a426ba079e3acaacfe96691cc6897b3b0
diff --git a/roc.py b/roc.py
index be609bf..87ba152 100644
--- a/roc.py
+++ b/roc.py
@@ -3,6 +3,7 @@
SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
"""
+import sys
import requests
import json
# noinspection PyUnresolvedReferences
@@ -99,7 +100,11 @@
def get_devicegroups(self):
url = URL + "device-group"
- response = requests.get(url, headers=self.headers())
+ try:
+ response = requests.get(url, headers=self.headers(), timeout=10)
+ except requests.ReadTimeout as e:
+ log.error("ROC request timeout, error={}".format(e))
+ sys.exit()
if response.status_code != 200:
log.error("get_devicegroups() failed, status_code: {}".format(response.status_code))
return None
@@ -123,14 +128,15 @@
def update_devices(self, devices):
new = {}
dgs = self.get_devicegroups()
- for dg in dgs:
- for d in dg['imsis']:
- imsi_id = str(d['imsi-id'])
- imsi = str(d['imsi-range-from'])
- last_reachable = datetime.min
- if imsi_id in devices:
- last_reachable = devices[imsi_id].last_reachable
- new[imsi_id] = Device(imsi_id, imsi, last_reachable)
+ if dgs is not None:
+ for dg in dgs:
+ for d in dg['imsis']:
+ imsi_id = str(d['imsi-id'])
+ imsi = str(d['imsi-range-from'])
+ last_reachable = datetime.min
+ if imsi_id in devices:
+ last_reachable = devices[imsi_id].last_reachable
+ new[imsi_id] = Device(imsi_id, imsi, last_reachable)
return new
def get_subnet(self):