-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dariusstefan-pull-req'
- Loading branch information
Showing
4 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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="[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
## | ||
|
||
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 |