From 3433f0698a01ce89d99e1bc104072576b1f9c2cf Mon Sep 17 00:00:00 2001 From: Stefan Darius Date: Tue, 12 Nov 2024 15:05:14 +0200 Subject: [PATCH 1/4] Use pip to install SIPssert in Docker image (#31) --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 83313e6..b74ea27 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,7 +6,7 @@ RUN apt update && apt install -y git WORKDIR /usr/src RUN git clone https://github.com/OpenSIPS/SIPssert.git &&\ cd SIPssert &&\ - python3 setup.py install + pip install . FROM python:3.12-slim-bookworm AS sipssert LABEL maintainer="darius.stefan@opensips.org" From 5e40fdc948794cf23937bac1813ca60c5daf8fb0 Mon Sep 17 00:00:00 2001 From: Stefan Darius Date: Tue, 19 Nov 2024 16:20:01 +0200 Subject: [PATCH 2/4] Add new opensips-mi task (#32) --- 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 From 269e344d1cc895a2f8a7c0a7a9d06fccf20a81c5 Mon Sep 17 00:00:00 2001 From: Darius Stefan Date: Wed, 20 Nov 2024 11:27:24 +0200 Subject: [PATCH 3/4] Add documentation about opensips-mi task --- docs/tasks/opensips-mi.md | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 docs/tasks/opensips-mi.md diff --git a/docs/tasks/opensips-mi.md b/docs/tasks/opensips-mi.md new file mode 100644 index 0000000..3ef82cf --- /dev/null +++ b/docs/tasks/opensips-mi.md @@ -0,0 +1,45 @@ +# SIPssert Testing Framework OpenSIPS MI Task + +Task used to run a MI command using the [OpenSIPSMI Python module](https://github.com/OpenSIPS/python-opensips). It is designed to be more lightweight than its alternative, the [OpenSIPS CLI](./opensips-cli.md) task, stripping down the unnecessary features and focusing on the MI commands. + +## Behavior + +The task is able to communicate with one or more OpenSIPS instances using the +[OpenSIPSMI Python module](https://github.com/OpenSIPS/python-opensips/blob/main/docs/mi.md) over HTTP, Datagrams or FIFO files. It has two different working modes: running a single command, or +running a script, either with the `.sh` (executed with bash), either a `.py` +file (executed with Python). + +## Defaults + +The variables overwritten by default by the task are: + +* `image`: default image to run is `opensips/python-opensips` + +## Settings + +Additional settings that can be passed to the task: + +* `script`: optional, a path to a `.sh` or `.py` script that can be executed; +if missing, the `opensips-mi` tool will execute the command that is passed through the `args` parameter (see the example below) +* `mi_ip`: optional, the IP to the OpenSIPS MI listener; if missing, +`127.0.0.1` is used +* `mi_port`: optional, the port to the OpenSIPS MI listener; if missing, +`8888` is used +* `mi_type`: optional, the type of the MI connection; if missing, `http` is used + +## Examples + +``` + - name: Reset Statistics + type: opensips-mi + args: reset_all_statistics +``` + +``` + - name: Check Domain + type: opensips-mi + script: check_domain.py + args: domain.sip + + # check_domain.py is a Python script that uses the OpenSIPSMI module to execute the MI command `domain_dump` and search for `domain.sip` +``` \ No newline at end of file From 7ceae02adaa87583e893ab4f3cbf973f8dc75c09 Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Wed, 20 Nov 2024 11:34:00 +0200 Subject: [PATCH 4/4] README: add opensips-mi doc on main page --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 44a1da4..a3a020d 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,8 @@ The current tasks types available in the framework are * [OpenSIPS](docs/tasks/opensips.md): Runs OpenSIPS SIP Server * [OpenSIPS CLI](docs/tasks/opensips-cli.md): Executes commands using the [OpenSIPS CLI](https://github.com/OpenSIPS/opensips-cli) tool + * [OpenSIPS MI](docs/tasks/opensips-mi.md): Executes MI commands using the +[Python OpenSIPS](https://github.com/OpenSIPS/python-opensips) module * [SIPp](docs/tasks/sipp.md): Runs [SIPp](https://sipp.sourceforge.net/) scenarios * [UAC SIPp](docs/tasks/uac-sipp.md): Executes a