Blog |Follow Nick on Mastodon| About
 

Crassh build status

I think I have started to get my head around unit tests for CRASSH; recently my initial implementation of paramiko's “ssh_session.recv_ready" was ballsed up, python3 was forgiving python2 would bork, creating an issue for many. My first unit test was a basic "print" which I ran on Travis-CI against both python2 and python3 if the build passed then syntax checking for both versions would pass, nice!

Unit tests that check the internal functions of CRASSH are all well and good, but the purpose of the script is to log into routers and do stuff, so I really wanted to spin up a router and check the script against that.

Travis-CI's infrastructure comes in two flavors, Standard and Container Based, which essential boils down to one that allows sudo and one that doesn't*; using the standard environment I have managed to spin up a dynamips router for testing CRASSH against.

If you take a look at my .travis.yml, I'll step you through how this works:

sudo: required

By default all builds are Container Based, this forces the Standard build.

 python:
- '2.6'
- '3.5'

Currently tests all run on linux, I plan to add OSX tests in the future but here we instruct Travis-CI to perform the tests twice, once against each version.

before_install:
- ifconfig -a
- sudo /sbin/modprobe tun
- sudo apt-get update -qq
- sudo apt-get install -qq dynamips

The first thing I do is prepare the OS, the ifconfig -a is for troublehooting so I can see the network stack before I start; then I install the Tun/Tap kernel driver, update the OS and install dynamips.

 install:
- pip install .
- pip install paramiko

Next I install CRASSH onto Travis-CI and it's dependency paramiko. The pip install . basically reads setup.py

Now all the dependencies are installed, the router needs to be loaded...

before_script:
- wget -q $IOS_URL
- ls -l
- sudo dynamips -s 0:0:tap:tap0 -P 3725 -T 2001 --idle-pc=0x607081e0 -C tests/r1.txt c3725-advsecurityk9-mz.124-25c.bin &
- sleep 90
- sudo ifconfig tap0 inet 1.1.1.1 netmask 255.255.255.252
- ifconfig -a
- ping -c 4 1.1.1.2

$IOS_URL is a secure variable so that charlatan's cannot download the Cisco IOS; so wget downloads the IOS from my secret location and dynamips starts up (and backrounds, note: &).

Once dynamips is running we wait 90secs to give time for the router to boot, we configure an interface to connect to the router with sudo ifconfig tap0 and I ping it to make sure it works.

Now that the router is running, standard python unit tests start with script: py.test --cisco

Inside the test config you'll see that --cisco is an optional switch that runs test_cisco_shver inside test_crassh.py.

The magic of test_cisco_shver is that dynamips was booted with the config in r1.txt the test logs into the r1 router and compares a show ver to an expected output if they match (line for line) then the test passes and Travis-CI shuts everything down; if the test fails I get notified.

Status of builds can be reviewed on the CRASSH Travis Page: https://travis-ci.org/linickx/crassh or is shown in the readme.

[*] I have an issue logged to see if this could be done on a Container Based server

 

 
Nick Bettison ©