Skip to content

Commit

Permalink
Merge branch 'dariusstefan-pull-req'
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Nov 20, 2024
2 parents 44c4e88 + 7ceae02 commit b1a3cc2
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions docs/tasks/opensips-mi.md
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`
```
69 changes: 69 additions & 0 deletions sipssert/tasks/opensips-mi.py
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

0 comments on commit b1a3cc2

Please sign in to comment.