From 16a7dd9fedc798a79ad0457130d43cba99891e46 Mon Sep 17 00:00:00 2001 From: Darius Stefan Date: Tue, 19 Nov 2024 16:03:55 +0200 Subject: [PATCH] Add new opensips-mi task --- sipssert/tasks/opensips-mi.py | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 sipssert/tasks/opensips-mi.py diff --git a/sipssert/tasks/opensips-mi.py b/sipssert/tasks/opensips-mi.py new file mode 100644 index 0000000..afce72e --- /dev/null +++ b/sipssert/tasks/opensips-mi.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +## +## This file is part of the SIPssert Testing Framework project +## Copyright (C) 2023 OpenSIPS Solutions +## +## 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 . +## + +import os +from sipssert.task import Task + +class OpenSIPSMITask(Task): + + default_image = "opensips/python-opensips" + default_mount_point = "/home" + default_daemon = False + + default_port = 8888 + default_ip = '127.0.0.1' + default_comm_type = 'http' + + def __init__(self, test_dir, config): + super().__init__(test_dir, config) + self.script = config.get("script") + + if self.script and not os.path.isabs(self.script): + self.script = os.path.join(self.mount_point, self.script) + + def get_task_env(self): + env_dict = super().get_task_env() + env_dict["MI_TYPE"] = self.config.get("mi_type", self.default_comm_type) + self.mi_type = env_dict["MI_TYPE"] + env_dict["MI_IP"] = self.config.get("mi_ip", self.default_ip) + self.mi_ip = env_dict["MI_IP"] + env_dict["MI_PORT"] = self.config.get("mi_port", self.default_port) + self.mi_port = env_dict["MI_PORT"] + return env_dict + + def get_task_args(self): + + args = [] + + if self.script: + args.append(self.script) + else: + self.mi_type = self.config.get("mi_type", self.default_comm_type) + self.mi_ip = self.config.get("mi_ip", self.default_ip) + self.mi_port = self.config.get("mi_port", self.default_port) + args.append("-t") + args.append(self.mi_type) + args.append("-i") + args.append(self.mi_ip) + args.append("-p") + args.append(str(self.mi_port)) + + return args + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4