pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/20601 )
Change subject: {enb,epc,ms}_srs: refactor start/stop and KPI helpers ...................................................................... {enb,epc,ms}_srs: refactor start/stop and KPI helpers refactor some of the functionality to srslte_common Change-Id: I2ff36df6f1a07ed8ddac39d296d62fe44a215283 --- M src/osmo_gsm_tester/obj/enb_srs.py M src/osmo_gsm_tester/obj/epc_srs.py M src/osmo_gsm_tester/obj/ms_srs.py M src/osmo_gsm_tester/obj/srslte_common.py 4 files changed, 57 insertions(+), 24 deletions(-) Approvals: pespin: Looks good to me, approved; Verified diff --git a/src/osmo_gsm_tester/obj/enb_srs.py b/src/osmo_gsm_tester/obj/enb_srs.py index 13d18f3..ec2d1fc 100644 --- a/src/osmo_gsm_tester/obj/enb_srs.py +++ b/src/osmo_gsm_tester/obj/enb_srs.py @@ -51,6 +51,7 @@ def __init__(self, testenv, conf): super().__init__(testenv, conf, srsENB.BINFILE) + srslte_common.__init__(self) self.ue = None self.run_dir = None self.gen_conf = None @@ -73,6 +74,7 @@ self.metrics_file = None self.stop_sleep_time = 6 # We require at most 5s to stop self.testenv = testenv + self.kpis = None self._additional_args = [] if not rf_type_valid(conf.get('rf_dev_type', None)): raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None)) @@ -100,12 +102,6 @@ # Collect KPIs for each TC self.testenv.test().set_kpis(self.get_kpis()) - def sleep_after_stop(self): - # Only sleep once - if self.stop_sleep_time > 0: - MainLoop.sleep(self.stop_sleep_time) - self.stop_sleep_time = 0 - def start(self, epc): self.log('Starting srsENB') self._epc = epc diff --git a/src/osmo_gsm_tester/obj/epc_srs.py b/src/osmo_gsm_tester/obj/epc_srs.py index 44e06a5..dae8a56 100644 --- a/src/osmo_gsm_tester/obj/epc_srs.py +++ b/src/osmo_gsm_tester/obj/epc_srs.py @@ -23,6 +23,7 @@ from ..core import log, util, config, template, process, remote from ..core import schema from . import epc +from .srslte_common import srslte_common def on_register_schemas(): config_schema = { @@ -31,7 +32,7 @@ } schema.register_config_schema('epc', config_schema) -class srsEPC(epc.EPC): +class srsEPC(epc.EPC, srslte_common): REMOTE_DIR = '/osmo-gsm-tester-srsepc' BINFILE = 'srsepc' @@ -42,6 +43,7 @@ def __init__(self, testenv, run_node): super().__init__(testenv, run_node, 'srsepc') + srslte_common.__init__(self) self.run_dir = None self.config_file = None self.db_file = None @@ -55,6 +57,7 @@ self.remote_log_file = None self.remote_pcap_file = None self.enable_pcap = False + self.kpis = None self.subscriber_list = [] def cleanup(self): diff --git a/src/osmo_gsm_tester/obj/ms_srs.py b/src/osmo_gsm_tester/obj/ms_srs.py index 1c0f728..b5f5d70 100644 --- a/src/osmo_gsm_tester/obj/ms_srs.py +++ b/src/osmo_gsm_tester/obj/ms_srs.py @@ -24,7 +24,6 @@ from ..core import log, util, config, template, process, remote from ..core import schema from .run_node import RunNode -from ..core.event_loop import MainLoop from .ms import MS from .srslte_common import srslte_common @@ -77,6 +76,7 @@ def __init__(self, testenv, conf): self._run_node = RunNode.from_conf(conf.get('run_node', {})) super().__init__('srsue_%s' % self.addr(), conf) + srslte_common.__init__(self) self.enb = None self.run_dir = None self.config_file = None @@ -92,9 +92,9 @@ self.remote_log_file = None self.remote_pcap_file = None self.remote_metrics_file = None - self.stop_sleep_time = 6 # We require at most 5s to stop self.enable_pcap = False self.num_carriers = 1 + self.kpis = None self.testenv = testenv self._additional_args = [] if not rf_type_valid(conf.get('rf_dev_type', None)): @@ -150,16 +150,6 @@ def netns(self): return "srsue1" - def sleep_after_stop(self): - # Only sleep once - if self.stop_sleep_time > 0: - MainLoop.sleep(self.stop_sleep_time) - self.stop_sleep_time = 0 - - def stop(self): - self.testenv.stop_process(self.process) - self.sleep_after_stop() - def connect(self, enb): self.log('Starting srsue') self.enb = enb diff --git a/src/osmo_gsm_tester/obj/srslte_common.py b/src/osmo_gsm_tester/obj/srslte_common.py index 33f12d4..9619fb6 100644 --- a/src/osmo_gsm_tester/obj/srslte_common.py +++ b/src/osmo_gsm_tester/obj/srslte_common.py @@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from ..core import log +from ..core.event_loop import MainLoop class srslte_common(): # don't inherit from log.Origin here but instead use .name() from whoever inherits from us @@ -25,21 +26,64 @@ self.log_file = None self.process = None self.metrics_file = None + self.stop_sleep_time = 6 # We require at most 5s to stop + self.kpis = None + + def sleep_after_stop(self): + # Only sleep once + if self.stop_sleep_time > 0: + MainLoop.sleep(self.stop_sleep_time) + self.stop_sleep_time = 0 + + def stop(self): + self.testenv.stop_process(self.process) + self.sleep_after_stop() def get_kpis(self): + ''' Return all KPI ''' + if self.kpis is None: + self.extract_kpis() + return self.kpis + + def get_log_kpis(self): + ''' Return KPIs extracted from log ''' + if self.kpis is None: + self.extract_kpis() + + # Use log KPIs if they exist for this node + if "log_" + self.name() in self.kpis: + log_kpi = self.kpis["log_" + self.name()] + else: + log_kpi = {} + + # Make sure we have the errors and warnings counter in the dict + if 'total_errors' not in log_kpi: + log_kpi['total_errors'] = 0 + if 'total_warnings' not in log_kpi: + log_kpi['total_warnings'] = 0 + return log_kpi + + def extract_kpis(self): ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs ''' - kpis = {} + + # Stop application, copy back logs and process them + if self.running(): + self.stop() + self.cleanup() + + self.kpis = {} try: # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable from kpi_analyzer import kpi_analyzer analyzer = kpi_analyzer(self.name()) if self.log_file is not None: - kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file) + self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file) if self.process.get_output_file('stdout') is not None: - kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout')) + self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout')) if self.metrics_file is not None: - kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file) + self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file) except ImportError: self.log("Can't load KPI analyzer module.") + self.kpis = {} - return kpis + return self.kpis -- To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/20601 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Change-Id: I2ff36df6f1a07ed8ddac39d296d62fe44a215283 Gerrit-Change-Number: 20601 Gerrit-PatchSet: 1 Gerrit-Owner: srs_andre <an...@softwareradiosystems.com> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin <pes...@sysmocom.de> Gerrit-MessageType: merged