Tag Archives: testing

Automated testing of ansible roles

What is this?

Basic idea: whenever most things happen in your ansible repository (for example commit, pull request or release) then you want to automatically test the ansible code.

The basic tools:

  • syntax-checking
  • lint / codying style adherence
  • actually running the code
  • is it idempotent
  • does the end result look like you want it to?

How it should be done

Use something like molecule https://github.com/metacloud/molecule which can launch your container/virtual machine, run ansible, check for lint and also run some testing framework like serverspec/testinfra.

How I currently to do it

I use travis to test many ansible roles and playbooks. From travis you basically get an Ubuntu machine and in that you can run whatever you want.

Basic process I’ve used for ansible testing:

  • Configure docker on the Ubuntu machine (or LXC in some roles)
  • Launch a docker with the OS you want to test on (in my case mostly CentOS 7, but sometimes Debian)
  • Run ansible-playbook with –syntax-check, –check and twice to check for idempotency
  • Run some manual commands at the end to test whatever was configured / or at least print some config files to make sure they look OK

All of the above and more should be doable now with molecule, first and last time I tried I couldn’t get it to work but it’s looking better.

Actual commands to test

  • ansible-playbook –syntax-check
  • ansible-lint
  • ansible-playbook
  • ansible-playbook
  • ansible-playbook –check

Order Matters

Do you want to run it in noop mode ( –check ) before or after the role has first run at least once to configure all the things?

How to actually set this up

Official travis documentation

Login with your github account on travis.org (or travis.com if it’s a private repo) ( and connect your github organization ).

Enable the repository, for example https://travis-ci.org/CSCfi/ansible-role-dhcp_server

Add some files to your repo. I usually copy .travis.yml and tests/ directory from an existing repository like ansible-role-cvmfs .

Modify the test playbook – tests/test.yml to include the new role, maybe change some default variables and have a look in test-in-docker-image.sh script if there are anything you want to add or remove from there too.

Push to github and watch the build log :)

Working Fighting with Travis

Fighting with docker took a lot of my time when getting this working the first time. Especially as I use ansible to configure servers that run multiple services and want to have a full systemd inside the container.

Commands to run on an Ubuntu 14.04 VM to get a kind of similar environment as in travis:

sudo apt update
sudo apt upgrade
sudo apt install build-essential libssl-dev libffi-dev python-dev git
sudo apt install docker.io cgroup-lite
/usr/share/docker.io/contrib/check-config.sh 
echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s devicemapper"' | sudo tee /etc/default/docker > /dev/null
sudo cgroups-mount

And then from there run the commands you have in .travis.yml

openstack testing day

Only one day late!

I actually started installing this on the 8th but I forgot to install it to hdd so the ‘yum update’ failed and broke the machine with I/O errors :)

Installing it in a VMWare Workstation (fedora 64-bit type, 2, cores, 4G RAM, 20G disk).

http://fedoraproject.org/wiki/Test_Day:2012-03-08_OpenStack_Test_Day

Basic Setup

1

http://fedoraproject.org/wiki/QA:Testcase_install_OpenStack_packages – No problem.

2

http://fedoraproject.org/wiki/QA:Testcase_setup_OpenStack_Nova –

Says that if you are doing this in a VM you need to “configure nova to use qemu without KVM and hardware virtualization:”. This is not true, as VMWare Workstation 8 has virtualization pass-through.

[root@localhost mart]# vgcreate nova-volumes $(sudo losetup --show -f /var/lib/nova/nova-volumes.img)
  No physical volume label read from /dev/loop0
  Writing physical volume data to disk "/dev/loop0"
  Physical volume "/dev/loop0" successfully created
  Volume group "nova-volumes" successfully created
openstack-nova-db-setup

Gives this error, which already is reported:

Verified connectivity to MySQL.
Creating 'nova' database.
Asking openstack-nova to sync the databse.
2012-03-09 07:28:26 WARNING nova.utils [-] /usr/lib/python2.7/site-packages/nova/db/sqlalchemy/migrate_repo/versions/075_convert_bw_usage_to_store_network_id.py:49: SADeprecationWarning: useexisting is deprecated.  Use extend_existing.
  useexisting=True)

2012-03-09 07:28:28 WARNING nova.utils [-] /usr/lib/python2.7/site-packages/nova/db/sqlalchemy/migrate_repo/versions/081_drop_instance_id_bw_cache.py:40: SADeprecationWarning: useexisting is deprecated.  Use extend_existing.
  useexisting=True)

Complete!

3

[root@localhost nova]# ADMIN_PASSWORD=$OS_PASSWORD openstack-keystone-sample-data
The default service password has been detected.  Please consider
setting an actual password in environment variable SERVICE_PASSWORD

But after that it generates users.

4

No problems, should ‘glance index’ return anything at this stage?

5

No problems.

6 Add SSH keypair

No problems, just do exactly what the instructions say (don’t try to be smart and put them in .sh files for example :P).

7 Register Guest Images

At this point the wiki went down :/

[root@localhost ~]# glance add name=f16 is_public=true disk_format=qcow2 container_format=ovf copy_from=http://berrange.fedorapeople.org/images/2012-02-29/f16-x86_64-openstack-sda.qcow2
Failed to add image. Got error:
Unexpected response: 500
Note: Your image metadata may still be in the registry, but the image's status will likely be 'killed'.

Yes, this is where it fall short. Manpage for clance doesn’t even have the ‘copy_from’. Maybe it could be downloaded? ‘glance index’ doesn’t work either.

 

[root@localhost ~]# glance index
Failed to show index. Got error:
Internal Server error: Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/eventlet/wsgi.py", line 336, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/usr/lib/python2.7/site-packages/webob/dec.py", line 147, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/usr/lib/python2.7/site-packages/webob/dec.py", line 210, in call_func
    return self.func(req, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/glance/common/wsgi.py", line 279, in __
    response = req.get_response(self.application)
  File "/usr/lib/python2.7/site-packages/webob/request.py", line 1086, in get_re
    application, catch_exc_info=False)
  File "/usr/lib/python2.7/site-packages/webob/request.py", line 1055, in call_a
    app_iter = application(self.environ, start_response)
  File "/usr/lib/python2.7/site-packages/keystone/middleware/auth_token.py", lin
    valid = self._validate_claims(claims)
  File "/usr/lib/python2.7/site-packages/keystone/middleware/auth_token.py", lin
    return self._validate_claims(claims, False)
  File "/usr/lib/python2.7/site-packages/keystone/middleware/auth_token.py", lin
    self.admin_password)
  File "/usr/lib/python2.7/site-packages/keystone/middleware/auth_token.py", lin
    return json.loads(data)["access"]["token"]["id"]
  File "/usr/lib64/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

[root@localhost ~]# cd images/
[root@localhost images]# ls
aki-tty  ami-tty  ari-tty
[root@localhost images]# http://berrange.fedorapeople.org/images/2012-02-29/f16-                                                                                        x86_64-openstack-sda.qcow2^C
[root@localhost images]# glance add name=aki-tty is_public=true container_format                                                                                        =aki disk_format=aki < aki-tty/image
=================================================[100%] 7.79M/s, ETA  0h  0m  0s
=[  2%]                                                 1.25M/s, ETA  0h  0m  3s                                                                                        Failed to add image. Got error:
You are not authorized to complete this action.
Details: 401 Unauthorized

This server could not verify that you are authorized to access the document you                                                                                         requested. Either you supplied the wrong credentials (e.g., bad password), or yo                                                                                        ur browser does not understand how to supply the credentials required.


Note: Your image metadata may still be in the registry, but the image's status w                                                                                        =================================================[100%] 20.9M/s, ETA  0h  0m  0s
[root@localhost images]#

Stuck!

Tiny Core Linux

http://distro.ibiblio.org/tinycorelinux/welcome.html

Micro Core Linux!

Like super small!

WOop woop…

http://distro.ibiblio.org/tinycorelinux/downloads.html

Three versions:

Core

Core (8MB) – CLI only

This literally boots in 3 seconds after pressing enter at the boot loader, nice!

To get root access hit: ‘sudo sh’.

Basically nothing is installed, but you can download whatever you need with ‘wget’. You’ll need to compile things from source as there’s no packet manager. Or, after trying out the other versions, there may be a packet manager hidden in there somewhere somehow.

Tiny Core

Tiny Core (12MB) – Good for new users and wired connections.

This one boots into a graphical interface with the mac-style bar at the bottom of the screen with icons that pop out. It also has an appbrowser.

Search for something (perhaps ‘seamonkey’) and press ‘go’. This starts to download things. Lots of things. But in the end it completes and it works.

The appbrowser is missing quite a lot, there’s no progress bar so you have no idea how much needs to be downloaded or how long an install might take. You can see in the ‘depends’ tab which the dependencies are and that might give you a clue.

openssl is not installed by default! This is quite a surprise, to me this is almost the basis of a linux-based distribution. But if you don’t need to connect to it remotely or connect from it to another host then I guess you don’t need it :)

irssi doesn’t work by default.

If the packet manager cannot handle installing irssi I call it a crappy distro.

Nuff is e’nuff.

Core Plus

Core Plus (64MB) – Extra nicestuff, good for beginners, wireless and non-US keyboards.

Wonder if irssi works here? – Not in the default terminal or Eterm no! Xchat works though it is full of shieeet.

core plus has a lot nicer boot manager, and it shows a lot more options, such as fluxbox.

Think about:

It takes a fair amount of time to install something (or, it feels longer because there’s no progress bar) if you run it off the livecd. So, if you decide to try another OS without installing apps on disk, be prepared to reinstall apps.

Windows 8 Consumer Preview in VMWare Workstation

Checking out the new Windows 8 Consumer preview!
Installing in a VM on a host with Windows 7 and Intel Core i7.
Downloading the x64 English version from here: http://windows.microsoft.com/en-US/windows-8/iso
“To snap apps, you need a screen resolution of at least 1366 x 768” so I guess I better increase the resolution! Went with 1680×1050 which seems like an arbitrary number but with the highest (1920×1080) the text was blurry.

Could not detect which OS was on the disk, set it to Win7 x64. 4G RAM and 25G disk.

There’s a funny fish shown during first install.

After this, enter language and hit install, enter license key, custom install, use all disk.

This appears to be the current loading screen while the computer is booting too :)

After windows boots you get to decide hostname, enter your windows account, make some settings if you want to update drivers, safety filters. You can enter some extra security stuff (e-mail, alternative e-mail, security question).

 

Inside

To get to settings move the mouse cursor down to the bottom right corner.

A task bar is available if you move the cursor to the left top corner of the screen.

Xbox games doesn’t work (not allowed to sign in from my region).

Pinball FX starts but it’s lagging, a lot. But, if it’s slow just hit the windows key and you’re back to the block(s). In the end it doesn’t work either.

There’s a messaging square where you can add facebook, there’s also an e-mail square where you can add gmail.

Weather shows temperature as Fahrenheit, even though all my settings in control panel are set to Sweden/Swedish.

So I put some music on the skydrive, and then started it (whereupon it downloads the song). It then starts up a media player that takes up the whole screen. You can tell that this is meant to be used for a tablet where you don’t want clutter or where you want it to look nice.

Also, you go to settings to turn it off.