Improve handling of modem error state
Change-Id: I1e8abdf6bf904b9df63b0a5649e5a0eb27b06d40
diff --git a/VERSION b/VERSION
index fcbaa84..6769f67 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.6.14
+0.6.15
diff --git a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
index cabad1e..20678ca 100755
--- a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
+++ b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
@@ -347,17 +347,31 @@
logging.error("Failed to report for %s", e)
pass
time.sleep(CONF.report_interval)
+
def reset_usb():
- cmd = "/usr/sbin/uhubctl -a 0 -l 2" # -a 0 = action is shutdown -l 2 location = bus 2 on pi controls power to all hubs
- ret = subprocess.call(cmd,shell=True)
- logging.info("Shutting down usb hub 2 results %s" , ret)
- time.sleep(10)# let power down process settle out
- cmd = "/usr/sbin/uhubctl -a 1 -l 2" # -a 1 = action is start -l 2 location = bus 2 on pi controls power to all hubs
- ret = subprocess.call(cmd,shell=True)
- logging.info("Starting up usb hub 2 results %s" , ret)
- time.sleep(10) #allow dbus to finish
- global cycles
- cycles = 0
+ try:
+ # Attempt to run uhubctl
+ if (int(subprocess.call("which uhubctl",shell=True)) == 0):
+ cmd = "/usr/sbin/uhubctl -a 0 -l 2" # -a 0 = action is shutdown -l 2 location = bus 2 on pi controls power to all hubs
+ ret = subprocess.call(cmd,shell=True)
+ logging.info("Shutting down usb hub 2 results %s" , ret)
+ time.sleep(10)# let power down process settle out
+ cmd = "/usr/sbin/uhubctl -a 1 -l 2" # -a 1 = action is start -l 2 location = bus 2 on pi controls power to all hubs
+ ret = subprocess.call(cmd,shell=True)
+ logging.info("Starting up usb hub 2 results %s" , ret)
+ time.sleep(10) #allow dbus to finish
+ global cycles
+ cycles = 0
+ else:
+ reboot(120)
+ except Exception as e:
+ logging.error("Failed to run uhubctl: %s", e)
+ reboot(120)
+
+def reboot(delay):
+ logging.error("Failed to run uhubctl. Reboot system in " + str(delay) + " second(s).")
+ time.sleep(delay)
+ subprocess.check_output("sudo shutdown -r now", shell=True)
@@ -372,7 +386,7 @@
ip, CONF.modem.ip_addr), shell=True)
except subprocess.CalledProcessError as e:
logging.error("Failed to add routes", e.returncode, e.output)
- reset_usb()
+ time.sleep(10) # Sleep for 10 seconds before retry
sys.exit(1)
modem = Modem(CONF.modem.port, CONF.modem.baud)