From 48c83a89396152c1b2c7772cf19ec8ed7e831f88 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 27 Feb 2019 08:27:46 +0000 Subject: resource: Introduce a base class for the modem Extract IMSI, KI and authentication algorithm into a base class. Change-Id: Id547cdcc241a307a2ea59b5fbac6b8d7a9d95639 --- src/osmo_gsm_tester/modem.py | 23 +++++++-------------- src/osmo_gsm_tester/ms.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 src/osmo_gsm_tester/ms.py 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 @@ class ModemDbusInteraction(log.Origin): 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 @@ class Modem(log.Origin): 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 @@ class Modem(log.Origin): 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 @@ class Modem(log.Origin): 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 @@ class Modem(log.Origin): 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 +# +# 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 . + +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 -- cgit v1.2.3