SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
kamailio-tests
A testing framework for Kamailio
Giacomo Vacca - Kamailio World 2018 Workshop
Why this Workshop
kamailio-tests aims to provide reduce the need for end-to-end tests. “Test
units” target a specific core or module functionality.
It encourages contributors to the Kamailio project to build unit tests whenever
a new feature is published, or a bug fixed.
It’s an open source project published by Daniel-Constantin Mierla, with small
contributions from the presenter of this workshop.
2
About me
I design, build, maintain RTC
platforms based on Open Source
components.
User/Fan/Supporter of Kamailio for
more than a decade now.
Truphone, Libon, Nexmo and more
I live in Sardinia.
(FAQ: No, that’s Sicily; Sardinia is
the one more West.)
3
Giacomo Vacca
@giavac
Agenda
The rationale behind this project
Project structure
The role of Docker
The current test scenarios
Future development
Q&A
https://github.com/kamailio/kamailio-tests
4
“Why do we always end up debugging?”
- Anonymous from the audience
5
Why kamailio-tests
https://github.com/kamailio/kamailio-tests
A “self-contained” environment to test:
- Modules
- Routing scripts
- DB access
- Build requirements (indirectly)
No need to setup permanent test
environments
Allow for (automated) regression testing
Reduce the need for end-to-end testing
“Adding a feature or fixing a
bug? Also add a test for it.”
6
Structure of test units
A script, units/UNIT_NAME/UNIT_NAME.sh
Optionally one or more custom routing scripts,
units/UNIT_NAME/kamailio-NAME.cfg
A README, units/UNIT_NAME/README.md
Name of directory == Name of the unit
Unit name format: txxxxxnnnn
- xxxxx: 5 lowercase chars representing the
test “group”
- nnnn: 4 digits to enumerate the unit in the
group
- Example: tcfgxx0001
7
Structure of a test script
(Optionally) Configure the DB (add a subscriber,
add an ACL, etc)
Run Kamailio with a given configuration (direct
std out to a log file)
Trigger the test, by:
- Just starting Kamailio
- Creating a SIP INVITE (with or w/o auth)
- Creating a SIP OPTIONS to trigger a route
Stop Kamailio
Check the log for the expected items
Determine the test result (typically by grepping
the log file)
8
9
Utilities and ktestsctl
etc/config: shell script with configuration items
VARIABLE = value
KAMBIN=${KAMBIN:-/usr/local/sbin/kamailio}
etc/utils: shell script with some utility functions
- kill_kamailio()
- kill_pidfile()
ktestsctl:
- Executes all the units
- Execute a specific unit
- Starts mysql (if needed)
- Quiet/Verbose mode
ktestsctl will ignore units listed in
etc/excludeunits.txt
10
Current units
tasync0001: Verifies variable values when using
asynchronous routes (async)
tauthx0001: Adds a subscriber to the DB and verifies
authentication (with and without multidomain, auth_db)
tcfgxx0001: Test the default kamailio config file with various
combinations of defines (with and w/o DB, with debug, etc)
tcfgxx0002: Test the default kamailio .cfg file without any
special define (OPTIONS request)
tgeoip0001: Performs a GeoIP (geoip2) look up and verifies
the result
tgroup0001: Adds user to an ACL group, and verifies it
belongs to it (group)
tmodxx0001: Tries to run kamailio with all modules loaded
tphonu0001: Test number normalisation with phonenum
module (phonenum)
tulocx0001: Registers a user and verifies it was added to the
location entries (usrloc)
11
How to add a unit
Minimum work:
- Add a unit folder
- Add a unit script
Optionally:
- Add a custom kamailio .cfg
If a module is needed and is not built, the test will fail:
- Add dependencies for the module
- Remove module from the excluded list (exclude_modules) 12
Test, fail, change the test, rinse and repeat
Raise a PR
Consider supporting the new unit in all the OS distributions
Docker to the rescue
Easy to install in a variety of systems
Allows testing against various OS distributions
Can run on a laptop, server or CI system
Intuitive workflow: 1. Develop, 2. Build a base image with latest
code, 3. Run a container with that image, 4. Run the tests, 5.
Rinse and repeat
Makes it easy to collaborate
(Also as: Build infrastructure for artefacts and Prototyping)
Develop
Change source code or
routing script
Build
the base image
Run
the container
Test
Launch the test scripts
13
Dockerfiles
Install base libraries to build Kamailio
Install mysql (client and server)
Install sipsak, GeoLite2
Copy Kamailio source code (from branch or
fork) into image, and Build Kamailio
Copy kamailio-tests units into image
Define an ENTRYPOINT and a (default) CMD
“A Dockerfile is a text document that
contains all the commands a user could call
on the command line to assemble an
image.”
https://docs.docker.com/engine/reference/
builder/
https://docs.docker.com/develop/develop-images/dockerfile_best-
practices/
14
Build the base image
The Dockerfiles are in kamailio-tests/docker/
Currently supported Debian 9 and CentOS 7 (but
easy to extend)
The kamailio source code is copied inside the
image (so you can test any branch or fork)
The unit tests are copies inside the image (so
you can easily add new units or test a unit in
isolation, and without re-building kamailio)
Change tag (-t TAG) to store various versions
$ docker build -t kamailio-tests-deb9x .
$ docker build -t kamailio-tests-deb9x -f
kamailio-tests/docker/Dockerfiles.debian9 .
15
More about the Docker build
Docker images can be kept small with proper actions
- Perform all installations in the same command, to build a single layer
- Clean up yum/apt repos
Docker builds use caching: if a layer doesn’t change than the existing one is used
- Explicitly invalidate the cache: --no-cache=true
- By changing an ENV variable at some point in the Dockerfile
- By changing the files that will be COPYed (or ADDed)
e.g. if you just change the test unit, Docker build will use the cache for the previous layers, and won’t
rebuild Kamailio 16
Run the container and launch the tests
The Dockerfiles define an ENTRYPOINT (default
action that can be overridden at runtime)
The mysql DB is created optionally
You can run all the units or just one
Quiet/Verbose mode (based on ktestsctl)
$ docker run kamailio-tests-deb9x
$ docker run kamailio-tests-deb9x -q run
tasync0001
17
18
Launch a specific unit
Handy during test development: launch a
specific unit (instead of the full suite)
In this example, with -q flag for less verbose
output.
$ docker run kamailio-tests-deb9x run -q tasync0001
19
Exclude a specific unit
There can be reasons to exclude a unit from the list, e.g.:
- Availability of the related module
- Maturity of the unit
- Libraries depending on OS
Add the unit (on a dedicated line) to etc/excludeunits.txt.DISTRIBUTION, eg.:
- etc/excludeunits.txt.debian9
- etc/excludeunits.txt.centos7
20
Future
development
More unit tests
More complex scenarios (sipp
and HTTP)
Integration with Jenkins and
others
Additional OS support
<Your idea here>
21
Kamailio is a complex framework typically
interacting with complex systems.
With kamailio-tests we can reduce the
amount of end-to-end testing, by defining
proper, isolated unit tests.
22
See also...
The work done in evosip (Presentations from Paolo and Alex in
the next days)
My previous work in kamailio_ci project:
https://github.com/giavac/kamailio_ci
My workshop at Kamailio World 2016:
https://www.slideshare.net/GiacomoVacca/continuous-integrati
on-and-kamailio
23
Thanks!
Giacomo Vacca
@giavac
https://github.com/giavac
https://www.linkedin.com/in/giacomovacca/
Q&A
24

Contenu connexe

Tendances

Docker workshop
Docker workshopDocker workshop
Docker workshop
Evans Ye
 
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShiftKubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
Mihai Criveti
 

Tendances (20)

How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
Vagrant + Docker
Vagrant + DockerVagrant + Docker
Vagrant + Docker
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
HP Advanced Technology Group: Docker and Ansible
HP Advanced Technology Group: Docker and AnsibleHP Advanced Technology Group: Docker and Ansible
HP Advanced Technology Group: Docker and Ansible
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
 
Kubernetes Story - Day 1: Build and Manage Containers with Podman
Kubernetes Story - Day 1: Build and Manage Containers with PodmanKubernetes Story - Day 1: Build and Manage Containers with Podman
Kubernetes Story - Day 1: Build and Manage Containers with Podman
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
Learn docker in 90 minutes
Learn docker in 90 minutesLearn docker in 90 minutes
Learn docker in 90 minutes
 
Using docker to develop NAS applications
Using docker to develop NAS applicationsUsing docker to develop NAS applications
Using docker to develop NAS applications
 
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShiftKubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
Kubernetes Story - Day 3: Deploying and Scaling Applications on OpenShift
 
Intro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and WindowsIntro- Docker Native for OSX and Windows
Intro- Docker Native for OSX and Windows
 
Vagrant and docker
Vagrant and dockerVagrant and docker
Vagrant and docker
 
Rapid Development With Docker Compose
Rapid Development With Docker ComposeRapid Development With Docker Compose
Rapid Development With Docker Compose
 
Ansible docker
Ansible dockerAnsible docker
Ansible docker
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Tech Talk - Vagrant
Tech Talk - VagrantTech Talk - Vagrant
Tech Talk - Vagrant
 
The state of the swarm
The state of the swarmThe state of the swarm
The state of the swarm
 
Immutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkitImmutable kubernetes architecture by linuxkit
Immutable kubernetes architecture by linuxkit
 

Similaire à Kamailio World 2018 - Workshop: kamailio-tests

kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting started
Munish Mehta
 
Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?
Tobias Schneck
 

Similaire à Kamailio World 2018 - Workshop: kamailio-tests (20)

Docker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshopDocker and Kubernetes 101 workshop
Docker and Kubernetes 101 workshop
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
 
kubernetes for beginners
kubernetes for beginnerskubernetes for beginners
kubernetes for beginners
 
Kamailio on Docker
Kamailio on DockerKamailio on Docker
Kamailio on Docker
 
Docker containers & the Future of Drupal testing
Docker containers & the Future of Drupal testing Docker containers & the Future of Drupal testing
Docker containers & the Future of Drupal testing
 
Why so continuous
Why so continuousWhy so continuous
Why so continuous
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 
Flowable on Kubenetes
Flowable on KubenetesFlowable on Kubenetes
Flowable on Kubenetes
 
kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting started
 
Kash Kubernetified
Kash KubernetifiedKash Kubernetified
Kash Kubernetified
 
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
IBM Index 2018 Conference Workshop: Modernizing Traditional Java App's with D...
 
Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?Testing - Selenium? Rich-Clients? Containers?
Testing - Selenium? Rich-Clients? Containers?
 
Improving the Accumulo User Experience
 Improving the Accumulo User Experience Improving the Accumulo User Experience
Improving the Accumulo User Experience
 
Scala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouScala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camou
 
Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate Everything
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New Virtualization
 
CMake_Tutorial.pdf
CMake_Tutorial.pdfCMake_Tutorial.pdf
CMake_Tutorial.pdf
 

Plus de Giacomo Vacca

Plus de Giacomo Vacca (9)

STUN protocol
STUN protocolSTUN protocol
STUN protocol
 
Modern VoIP in modern infrastructures
Modern VoIP in modern infrastructuresModern VoIP in modern infrastructures
Modern VoIP in modern infrastructures
 
RIPP Notes
RIPP NotesRIPP Notes
RIPP Notes
 
Modern VoIP in Modern Infrastructures
Modern VoIP in Modern InfrastructuresModern VoIP in Modern Infrastructures
Modern VoIP in Modern Infrastructures
 
An SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environmentsAn SFU/MCU integration for heterogeneous environments
An SFU/MCU integration for heterogeneous environments
 
Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017Homer - Workshop at Kamailio World 2017
Homer - Workshop at Kamailio World 2017
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Top 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP PlatformTop 5 Challenges To Add Web Calls to Truphone VoIP Platform
Top 5 Challenges To Add Web Calls to Truphone VoIP Platform
 
Automatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With PuppetAutomatic Kamailio Deployments With Puppet
Automatic Kamailio Deployments With Puppet
 

Dernier

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

Kamailio World 2018 - Workshop: kamailio-tests

  • 1. kamailio-tests A testing framework for Kamailio Giacomo Vacca - Kamailio World 2018 Workshop
  • 2. Why this Workshop kamailio-tests aims to provide reduce the need for end-to-end tests. “Test units” target a specific core or module functionality. It encourages contributors to the Kamailio project to build unit tests whenever a new feature is published, or a bug fixed. It’s an open source project published by Daniel-Constantin Mierla, with small contributions from the presenter of this workshop. 2
  • 3. About me I design, build, maintain RTC platforms based on Open Source components. User/Fan/Supporter of Kamailio for more than a decade now. Truphone, Libon, Nexmo and more I live in Sardinia. (FAQ: No, that’s Sicily; Sardinia is the one more West.) 3 Giacomo Vacca @giavac
  • 4. Agenda The rationale behind this project Project structure The role of Docker The current test scenarios Future development Q&A https://github.com/kamailio/kamailio-tests 4
  • 5. “Why do we always end up debugging?” - Anonymous from the audience 5
  • 6. Why kamailio-tests https://github.com/kamailio/kamailio-tests A “self-contained” environment to test: - Modules - Routing scripts - DB access - Build requirements (indirectly) No need to setup permanent test environments Allow for (automated) regression testing Reduce the need for end-to-end testing “Adding a feature or fixing a bug? Also add a test for it.” 6
  • 7. Structure of test units A script, units/UNIT_NAME/UNIT_NAME.sh Optionally one or more custom routing scripts, units/UNIT_NAME/kamailio-NAME.cfg A README, units/UNIT_NAME/README.md Name of directory == Name of the unit Unit name format: txxxxxnnnn - xxxxx: 5 lowercase chars representing the test “group” - nnnn: 4 digits to enumerate the unit in the group - Example: tcfgxx0001 7
  • 8. Structure of a test script (Optionally) Configure the DB (add a subscriber, add an ACL, etc) Run Kamailio with a given configuration (direct std out to a log file) Trigger the test, by: - Just starting Kamailio - Creating a SIP INVITE (with or w/o auth) - Creating a SIP OPTIONS to trigger a route Stop Kamailio Check the log for the expected items Determine the test result (typically by grepping the log file) 8
  • 9. 9
  • 10. Utilities and ktestsctl etc/config: shell script with configuration items VARIABLE = value KAMBIN=${KAMBIN:-/usr/local/sbin/kamailio} etc/utils: shell script with some utility functions - kill_kamailio() - kill_pidfile() ktestsctl: - Executes all the units - Execute a specific unit - Starts mysql (if needed) - Quiet/Verbose mode ktestsctl will ignore units listed in etc/excludeunits.txt 10
  • 11. Current units tasync0001: Verifies variable values when using asynchronous routes (async) tauthx0001: Adds a subscriber to the DB and verifies authentication (with and without multidomain, auth_db) tcfgxx0001: Test the default kamailio config file with various combinations of defines (with and w/o DB, with debug, etc) tcfgxx0002: Test the default kamailio .cfg file without any special define (OPTIONS request) tgeoip0001: Performs a GeoIP (geoip2) look up and verifies the result tgroup0001: Adds user to an ACL group, and verifies it belongs to it (group) tmodxx0001: Tries to run kamailio with all modules loaded tphonu0001: Test number normalisation with phonenum module (phonenum) tulocx0001: Registers a user and verifies it was added to the location entries (usrloc) 11
  • 12. How to add a unit Minimum work: - Add a unit folder - Add a unit script Optionally: - Add a custom kamailio .cfg If a module is needed and is not built, the test will fail: - Add dependencies for the module - Remove module from the excluded list (exclude_modules) 12 Test, fail, change the test, rinse and repeat Raise a PR Consider supporting the new unit in all the OS distributions
  • 13. Docker to the rescue Easy to install in a variety of systems Allows testing against various OS distributions Can run on a laptop, server or CI system Intuitive workflow: 1. Develop, 2. Build a base image with latest code, 3. Run a container with that image, 4. Run the tests, 5. Rinse and repeat Makes it easy to collaborate (Also as: Build infrastructure for artefacts and Prototyping) Develop Change source code or routing script Build the base image Run the container Test Launch the test scripts 13
  • 14. Dockerfiles Install base libraries to build Kamailio Install mysql (client and server) Install sipsak, GeoLite2 Copy Kamailio source code (from branch or fork) into image, and Build Kamailio Copy kamailio-tests units into image Define an ENTRYPOINT and a (default) CMD “A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.” https://docs.docker.com/engine/reference/ builder/ https://docs.docker.com/develop/develop-images/dockerfile_best- practices/ 14
  • 15. Build the base image The Dockerfiles are in kamailio-tests/docker/ Currently supported Debian 9 and CentOS 7 (but easy to extend) The kamailio source code is copied inside the image (so you can test any branch or fork) The unit tests are copies inside the image (so you can easily add new units or test a unit in isolation, and without re-building kamailio) Change tag (-t TAG) to store various versions $ docker build -t kamailio-tests-deb9x . $ docker build -t kamailio-tests-deb9x -f kamailio-tests/docker/Dockerfiles.debian9 . 15
  • 16. More about the Docker build Docker images can be kept small with proper actions - Perform all installations in the same command, to build a single layer - Clean up yum/apt repos Docker builds use caching: if a layer doesn’t change than the existing one is used - Explicitly invalidate the cache: --no-cache=true - By changing an ENV variable at some point in the Dockerfile - By changing the files that will be COPYed (or ADDed) e.g. if you just change the test unit, Docker build will use the cache for the previous layers, and won’t rebuild Kamailio 16
  • 17. Run the container and launch the tests The Dockerfiles define an ENTRYPOINT (default action that can be overridden at runtime) The mysql DB is created optionally You can run all the units or just one Quiet/Verbose mode (based on ktestsctl) $ docker run kamailio-tests-deb9x $ docker run kamailio-tests-deb9x -q run tasync0001 17
  • 18. 18
  • 19. Launch a specific unit Handy during test development: launch a specific unit (instead of the full suite) In this example, with -q flag for less verbose output. $ docker run kamailio-tests-deb9x run -q tasync0001 19
  • 20. Exclude a specific unit There can be reasons to exclude a unit from the list, e.g.: - Availability of the related module - Maturity of the unit - Libraries depending on OS Add the unit (on a dedicated line) to etc/excludeunits.txt.DISTRIBUTION, eg.: - etc/excludeunits.txt.debian9 - etc/excludeunits.txt.centos7 20
  • 21. Future development More unit tests More complex scenarios (sipp and HTTP) Integration with Jenkins and others Additional OS support <Your idea here> 21
  • 22. Kamailio is a complex framework typically interacting with complex systems. With kamailio-tests we can reduce the amount of end-to-end testing, by defining proper, isolated unit tests. 22
  • 23. See also... The work done in evosip (Presentations from Paolo and Alex in the next days) My previous work in kamailio_ci project: https://github.com/giavac/kamailio_ci My workshop at Kamailio World 2016: https://www.slideshare.net/GiacomoVacca/continuous-integrati on-and-kamailio 23