Change in osmo-gsm-tester[master]: resource: Introduce a base class for the modem

Holger Freyther gerrit-no-reply at lists.osmocom.org
Tue Mar 5 15:49:43 UTC 2019


Holger Freyther has submitted this change and it was merged. ( https://gerrit.osmocom.org/13076 )

Change subject: resource: Introduce a base class for the modem
......................................................................

resource: Introduce a base class for the modem

Extract IMSI, KI and authentication algorithm into a base class.

Change-Id: Id547cdcc241a307a2ea59b5fbac6b8d7a9d95639
---
M src/osmo_gsm_tester/modem.py
A src/osmo_gsm_tester/ms.py
2 files changed, 56 insertions(+), 16 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Pau Espin Pedrol: Looks good to me, approved



diff --git a/src/osmo_gsm_tester/modem.py b/src/osmo_gsm_tester/modem.py
index 95ebb6b..e7ce68a 100644
--- a/src/osmo_gsm_tester/modem.py
+++ b/src/osmo_gsm_tester/modem.py
@@ -19,6 +19,7 @@
 
 from . import log, util, sms, process
 from .event_loop import MainLoop
+from .ms import MS
 
 from pydbus import SystemBus, Variant
 import os
@@ -318,8 +319,7 @@
         return self.property_is('Online', True)
 
 
-
-class Modem(log.Origin):
+class Modem(MS):
     'convenience for ofono Modem interaction'
 
     CTX_PROT_IPv4 = 'ip'
@@ -327,16 +327,13 @@
     CTX_PROT_IPv46 = 'dual'
 
     def __init__(self, suite_run, conf):
-        self.suite_run = suite_run
-        self.conf = conf
         self.syspath = conf.get('path')
         self.dbuspath = get_dbuspath_from_syspath(self.syspath)
-        super().__init__(log.C_TST, self.dbuspath)
+        super().__init__(self.dbuspath, conf)
         self.dbg('creating from syspath %s' % self.syspath)
-        self.msisdn = None
         self._ki = None
         self._imsi = None
-        self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name().strip('/')))
+        self.run_dir = util.Dir(suite_run.get_test_run_dir().new_dir(self.name().strip('/')))
         self.sms_received_list = []
         self.dbus = ModemDbusInteraction(self.dbuspath)
         self.register_attempts = 0
@@ -406,9 +403,6 @@
     def is_online(self):
         return self.dbus.is_online()
 
-    def set_msisdn(self, msisdn):
-        self.msisdn = msisdn
-
     def imsi(self):
         if self._imsi is None:
             if 'sim' in self.features():
@@ -423,7 +417,7 @@
                 self.dbg('got SIM properties', props)
                 self._imsi = props.get('SubscriberIdentity', None)
             else:
-                self._imsi = self.conf.get('imsi')
+                self._imsi = super().imsi()
             if self._imsi is None:
                 raise log.Error('No IMSI')
         return self._imsi
@@ -434,13 +428,10 @@
     def ki(self):
         if self._ki is not None:
             return self._ki
-        return self.conf.get('ki')
-
-    def auth_algo(self):
-        return self.conf.get('auth_algo', None)
+        return super().ki()
 
     def features(self):
-        return self.conf.get('features', [])
+        return self._conf.get('features', [])
 
     def _required_ifaces(self):
         req_ifaces = (I_NETREG,)
diff --git a/src/osmo_gsm_tester/ms.py b/src/osmo_gsm_tester/ms.py
new file mode 100644
index 0000000..a361865
--- /dev/null
+++ b/src/osmo_gsm_tester/ms.py
@@ -0,0 +1,49 @@
+# osmo_gsm_tester: Base class for Mobile Stations (MS)
+#
+# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Neels Hofmeyr <neels at hofmeyr.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from abc import ABCMeta, abstractmethod
+from . import log
+
+class MS(log.Origin, metaclass=ABCMeta):
+    """Base for everything about mobile/modem and SIMs."""
+
+    def __init__(self, name, conf):
+        super().__init__(log.C_TST, name)
+        self._conf = conf
+        self.msisdn = None
+
+    def imsi(self):
+        return self._conf.get('imsi')
+
+    def ki(self):
+        return self._conf.get('ki')
+
+    def auth_algo(self):
+        return self._conf.get('auth_algo', None)
+
+    def set_msisdn(self, msisdn):
+        self.msisdn = msisdn
+
+    def msisdn(self):
+        return self.msisdn
+
+    @abstractmethod
+    def cleanup(self):
+        """Cleans up resources allocated."""
+        pass
\ No newline at end of file

-- 
To view, visit https://gerrit.osmocom.org/13076
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id547cdcc241a307a2ea59b5fbac6b8d7a9d95639
Gerrit-Change-Number: 13076
Gerrit-PatchSet: 7
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190305/f7fcd866/attachment.html>


More information about the gerrit-log mailing list