conman: survive QCSAPI failures.

QCSAPI occasionally fails for a yet-unknown reason. conman treats the
CalledProcessError as a None result, which is fed into the FrenzyWPACtrl
state machine. This can lead to spurious state transitions. Instead,
skip the update if QCSAPI fails.

Change-Id: I6f248e6ce012b31c9b8044b090a71592e694621c
diff --git a/conman/interface.py b/conman/interface.py
index 82d1506..04c809c 100755
--- a/conman/interface.py
+++ b/conman/interface.py
@@ -2,7 +2,6 @@
 
 """Models wired and wireless interfaces."""
 
-import json
 import logging
 import os
 import re
@@ -479,27 +478,7 @@
     self._events = []
 
   def _qcsapi(self, *command):
-    try:
-      return subprocess.check_output(['qcsapi'] + list(command)).strip()
-    except subprocess.CalledProcessError:
-      return None
-
-  def _wifiinfo_filename(self):
-    return os.path.join(self.WIFIINFO_PATH, self._interface)
-
-  def _get_wifiinfo(self):
-    try:
-      return json.load(open(self._wifiinfo_filename()))
-    except IOError:
-      return None
-
-  def _get_ssid(self):
-    wifiinfo = self._get_wifiinfo()
-    if wifiinfo:
-      return wifiinfo.get('SSID')
-
-  def _check_client_mode(self):
-    return self._qcsapi('get_mode', 'wifi0') == 'Station'
+    return subprocess.check_output(['qcsapi'] + list(command)).strip()
 
   def attach(self):
     self._update()
@@ -517,9 +496,13 @@
 
   def _update(self):
     """Generate and cache events, update state."""
-    client_mode = self._check_client_mode()
-    ssid = self._get_ssid()
-    status = self._qcsapi('get_status', 'wifi0')
+    try:
+      client_mode = self._qcsapi('get_mode', 'wifi0') == 'Station'
+      ssid = self._qcsapi('get_ssid', 'wifi0')
+      status = self._qcsapi('get_status', 'wifi0')
+    except subprocess.CalledProcessError:
+      # If QCSAPI failed, skip update.
+      return
 
     # If we have an SSID and are in client mode, and at least one of those is
     # new, then we have just connected.
diff --git a/conman/interface_test.py b/conman/interface_test.py
index 4283a2a..4c7d52b 100755
--- a/conman/interface_test.py
+++ b/conman/interface_test.py
@@ -2,7 +2,6 @@
 
 """Tests for connection_manager.py."""
 
-import json
 import logging
 import os
 import shutil
@@ -199,16 +198,15 @@
 
   def add_connected_event(self):
     self.fake_qcsapi['get_mode'] = 'Station'
-    json.dump({'SSID': self.ssid_testonly},
-              open(self._wifiinfo_filename(), 'w'))
+    self.fake_qcsapi['get_ssid'] = self.ssid_testonly
 
   def add_disconnected_event(self):
     self.ssid_testonly = None
-    json.dump({'SSID': ''}, open(self._wifiinfo_filename(), 'w'))
+    self.fake_qcsapi['get_ssid'] = None
 
   def add_terminating_event(self):
     self.ssid_testonly = None
-    json.dump({'SSID': ''}, open(self._wifiinfo_filename(), 'w'))
+    self.fake_qcsapi['get_ssid'] = None
     self.fake_qcsapi['get_mode'] = 'AP'
 
   def detach(self):