modem: Identify modems by sysfs path instead of ofono dbus path

ofono dbus paths are non-deterministic and can change over time for a
given modem. For instance when ofono is restartd or if a modem crashes
and the object is destroyed and re-announced by udev.

Requires at least ofono 1df92289d4e09a1e2db0b189b5153a4c238f98f1, which
implemented the feature to export the sysfs path to modem properties.

Related: OS#2509

Change-Id: Ibc45a196abadded2706dc9d57b6a3a796b43a201
diff --git a/src/osmo_gsm_tester/modem.py b/src/osmo_gsm_tester/modem.py
index 5afd2d1..96b65d8 100644
--- a/src/osmo_gsm_tester/modem.py
+++ b/src/osmo_gsm_tester/modem.py
@@ -92,6 +92,14 @@
     root = systembus_get('/')
     return sorted(root.GetModems())
 
+def get_dbuspath_from_syspath(syspath):
+    modems = list_modems()
+    for dbuspath, props in modems:
+        if props.get('SystemPath', '') == syspath:
+            return dbuspath
+    raise ValueError('could not find %s in modem list: %s' % (syspath, modems))
+
+
 def _async_result_handler(obj, result, user_data):
     '''Generic callback dispatcher called from glib loop when an async method
     call has returned. This callback is set up by method dbus_async_call.'''
@@ -341,10 +349,12 @@
 
     def __init__(self, conf):
         self.conf = conf
-        self.path = conf.get('path')
-        super().__init__(log.C_TST, self.path)
+        self.syspath = conf.get('path')
+        self.dbuspath = get_dbuspath_from_syspath(self.syspath)
+        super().__init__(log.C_TST, self.dbuspath)
+        self.dbg('creating from syspath %s', self.syspath)
         self.sms_received_list = []
-        self.dbus = ModemDbusInteraction(self.path)
+        self.dbus = ModemDbusInteraction(self.dbuspath)
         self.register_attempts = 0
         self.call_list = []
         # one Cancellable can handle several concurrent methods.