ci/cd and tdd in deploying kamailio · test-driven development test-driven development is related...
TRANSCRIPT
![Page 1: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/1.jpg)
CI/CD and TDD in deploying Kamailio
Aleksandar Sošić@alexsosic
KWC 2018 - Berlin1
![Page 2: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/2.jpg)
Who am I?I’m a DevOp
Owner of kinetic.hr
Developing web applications for more than a decade
R&D manager at a SIP/VoIP cloud startup
Passionate about the Lean Startup methodology, IoT, Blockchain and Cryptocurrencies
Outdoor enthusiast, photographer and alpinist2
![Page 3: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/3.jpg)
Introduction
● Usage of the DevOps cross-functional mode of working with CI/CD in a complex multilayer microservice SIP infrastructure
● Testing single routes in Kamailio on different layers of the architecture
● Test automation with Jenkins in a containerized environment● Test-driven Development of Kamailio routes
3
![Page 4: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/4.jpg)
Introductory concepts
4
![Page 5: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/5.jpg)
DevOps
Practice that unifies software development (Dev) and software operation (Ops)
● Shorter development cycles● increased deployment frequency● more dependable releases in close
alignment with business objectives
Automation and monitoring of all steps is the key!
5
![Page 6: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/6.jpg)
DevOps
DevOps is intended to be a cross-functional mode of working
6
![Page 7: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/7.jpg)
7
![Page 8: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/8.jpg)
Goals of DevOps
● Improved deployment frequency● Faster time to market● Lower failure rate of new releases● Shortened lead time between fixes● Faster mean time to recovery
8
![Page 9: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/9.jpg)
CI/CD
Continuous integration (CI) is the practice of merging all developer working copies to a shared mainline several times a day.
The main goal is to prevent integration problems, referred to as "integration hell".
9
![Page 10: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/10.jpg)
CI/CD
Continuous delivery (CD) is an approach in which teams produce software in short cycles, ensuring that the software can be reliably released at any time.
Relationship to continuous deployment?
Continuous delivery and DevOps have common goals and are often used in conjunction
10
![Page 11: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/11.jpg)
Microservice Infrastructure
AKA microservice architecture
● Structures an application as a collection of loosely coupled services● Enables the continuous delivery/deployment of large, complex
applications● Enables an organization to evolve its technology stack● Services are fine-grained and the protocols are lightweight● Improves modularity● Makes the application easier to understand, develop and test● Enable continuous delivery and deployment
11
![Page 12: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/12.jpg)
Our project architecture
12
![Page 13: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/13.jpg)
Project features and technologies used
● Containerized environment● Stateless Kamailio instances● Multi layer infrastructure● K8S as container orchestrator● Custom API for SIP infrastructure orchestration● External Clustered DB
13
![Page 14: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/14.jpg)
Project architecture
● Kamailio proxy and “routing” layer● Asterisk as TPS● RTPEngine● Custom API SIP orchestration
14
![Page 15: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/15.jpg)
Proxy and Router rolesProxy:
● Proxy load balancing (callid path maintained)● First security layer (ua/pike)
Router:
● User registration & management● Session control● Security (user authentication/ip filtering etc.)● Billing● Number normalization● E2E routing (LCR & Carrier / Failover & Re-routing)
15
![Page 16: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/16.jpg)
Testing Kamailio Routes
16
![Page 17: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/17.jpg)
kamailio.cfg
#!ifdef TESTINGinclude_file "kamailio-test.cfg"#!endif...request_route {#!ifdef TESTING if ($hdr(X-evosip-Test) =~ "^TEST_") { route($(hdr(X-evosip-Test){s.rm,"})); exit; }#!endif...
17
![Page 18: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/18.jpg)
18
![Page 19: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/19.jpg)
SIPp
Free Open Source test tool traffic generator for the SIP protocol
● establishes and releases multiple calls● custom XML scenario files describing call flows● dynamic display of statistics about running tests (call rate, round trip
delay, and message statistics)● periodic CSV statistics dumps
19
![Page 20: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/20.jpg)
SIPp xml scenario <send retrans="500"> <![CDATA[ OPTIONS sip:[field2]@[remote_ip]:[remote_port] SIP/2.0 Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch] From: "sipvicious" <sip:[field0]@[field1]>;tag=[call_number] User-Agent: sipvicious To: "sipvicious" <sip:[field0]@[field1]:[remote_port]> X-evosip-Test: TEST_IS_SCANNER Call-ID: [call_id] CSeq: [cseq] OPTIONS Contact: sip:[field3]@[local_ip]:[local_port] Max-Forwards: 70 Content-Type: application/sdp Content-Length: [len] ]]> </send> <recv response="222" crlf="true"></recv>
20
![Page 21: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/21.jpg)
Testing Kamailio
route[TEST_IS_SCANNER] { if(route(IS_SCANNER)) { xlog("L_WARNING", "SCANNER $ua BLOCKED!\n"); sl_send_reply("222",
"Test passed, $ua scanner blocked!"); } else { sl_send_reply("500", "Test failed: NOT A SCANNER"); }}
21
![Page 22: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/22.jpg)
Testing Kamailio
#!define SCNR_BLACK_LIST "sipsak|sipvicious|..."...route[IS_SCANNER] { if ($ua =~ SCNR_BLACK_LIST) { return 1; } else { return 0; }}
22
![Page 23: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/23.jpg)
Writing more complex tests
Dynamic dispatcher list example
Route SHOULD_DISPATCHER_RELOAD
● Are the dispatchers already reloaded?● Am I reloading the dispatchers?● Does it take too long to reload the dispatchers?
23
![Page 24: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/24.jpg)
Writing more complex testsroute[SHOULD_DISPATCHER_RELOAD] {
if($sht(dispatcher=>list) == 1) {
return 0;
} else {
$var(todate) = $(sht(dispatcher=>list){s.int}) + 60;
if ($var(todate) < $TV(sn)) {
return 1;
} else {
return 0;
}
}
}
24
![Page 25: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/25.jpg)
Writing more complex tests
route[TEST_SHOULD_DISPATCHER_RELOAD] {$var(TestsPassed) = 0;$var(TestsNum) = 3;
# Dispatcher list has been correctly reloaded# and should not be reloaded again$sht(dispatcher=>list) = 1;if(!route(SHOULD_DISPATCHER_RELOAD)) {
$var(TestsPassed) = $var(TestsPassed) + 1;}
...25
![Page 26: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/26.jpg)
Writing more complex tests
... # The dispatcher list route # has been just triggered # and should not be called again for 60 seconds $sht(dispatcher=>list) = $TV(sn); if(!route(SHOULD_DISPATCHER_RELOAD)) { $var(TestsPassed) = $var(TestsPassed) + 1; }...
26
![Page 27: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/27.jpg)
Writing more complex tests
... # The dispatcher list route has been called # more than 60 seconds ago and should reload $sht(dispatcher=>list) = $(sht(dispatcher=>list){s.int}) - 65; if(route(SHOULD_DISPATCHER_RELOAD)) { $var(TestsPassed) = $var(TestsPassed) + 1; }...
27
![Page 28: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/28.jpg)
Writing more complex tests
... # Tests concluded count test number # and respond via sl_send_reply if($var(TestsPassed) == $var(TestsNum)) {
sl_send_reply("200", "DISPATCHER RELOAD TRIGGER WORKING"); } else { sl_send_reply("500", "DISPATCHER RELOAD TRIGGER NOT WORKING"); }}
28
![Page 29: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/29.jpg)
Automate Tests
29
![Page 30: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/30.jpg)
Jenkins is an open source automation server written in Java.
● Helps us automate the non-human part of the software development process
● Does continuous integration● Facilitates technical aspects of continuous delivery
30
![Page 31: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/31.jpg)
CI/CD Flow
31
![Page 32: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/32.jpg)
SIPp script for jenkins integration#!/bin/bash
NAME="ut_kama_proxy-scanners"SIPP=/usr/local/bin/sippSCENARIOS=/sipp/scenarios/"${NAME}".xmlSETTINGS=/tmp/inf_files/"${NAME}".csvDATE_FILE=$(date '+%Y-%m-%d_%H-%M')NODE_OWNER=$(echo "${POD_NODE}" | cut -d '.' -f 2)NODE_DOMAIN=$(echo "${POD_NODE}" | cut -d '.' -f3-)TARGET="proxy.${NODE_OWNER}.${NODE_DOMAIN}"
"${SIPP}" "${TARGET}" -sf "${SCENARIOS}" -l 1 -m 1 -inf "${SETTINGS}"exit "${?}"
32
![Page 33: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/33.jpg)
Automation with Jenkinsstage('functional tests') { def testPods = getPodsByPrefix("test-") if(testPods.size() < 1) { throw new Exception("No test pods found") } def testPod = testPods[0] echo "----\ntest pod: ${testPod.name}\n----" echo "executing test 'proxy scanners' on pod ${testPod.name}" podExec(testPod, "/sipp/scripts/ut_kama_proxy-scanners.sh", false) updateGitlabCommitStatus name: 'func tests', state: 'success'}
33
![Page 34: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/34.jpg)
Test-driven development
34
![Page 35: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/35.jpg)
Test-driven development
Test-driven development is related to the test-first programming concepts of extreme programming
TDD relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only
“TDD encourages simple designs and inspires confidence”
-- Kent Beck
35
![Page 36: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/36.jpg)
TDD Example
route[TEST_IS_SCANNER] { if(route(IS_SCANNER)) { xlog("L_WARNING", "SCANNER $ua BLOCKED!\n"); sl_send_reply("222",
"Test passed, $ua scanner blocked!"); } else { sl_send_reply("500", "Test failed: NOT A SCANNER"); }}
36
![Page 37: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/37.jpg)
TDD Example
37
<send retrans="500"> <![CDATA[ ... User-Agent: sipvicious ... X-evosip-Test: TEST_IS_SCANNER ... ]]> </send> <recv response="222" crlf="true"></recv>
![Page 38: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/38.jpg)
TDD Example
route[IS_SCANNER] { return 0;}
38
![Page 39: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/39.jpg)
TDD Example
route[IS_SCANNER] { if ($ua == "sipvicious") { return 1; } else { return 0; }}
39
![Page 40: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/40.jpg)
TDD Example
40
#!define SCNR_BLACK_LIST "sipsak|sipvicious|..."...route[IS_SCANNER] { if ($ua =~ SCNR_BLACK_LIST) { return 1; } else { return 0; }}
![Page 41: CI/CD and TDD in deploying Kamailio · Test-driven development Test-driven development is related to the test-first programming concepts of extreme programming TDD relies on the repetition](https://reader036.vdocuments.mx/reader036/viewer/2022070713/5ed29e469c816a0c43326346/html5/thumbnails/41.jpg)
Conclusions
● Custom test routes in Kamailio● Request route condition for access to those routes in a testing
environment● Automation with SIPp scenarios and Jenkins for CI/CD● Ability to do TDD
41