PyGrunn: testing your infrastructure code - Ruben Homs

Tags: pygrunn, python

(One of my summaries of a talk at the 2019 PyGrunn conference).

Servers used to be managed by proper wizards. But even wizards can be killed by a balrog. So… what happens when your sysadmin leaves?

  • The point of failure is the sysadmin.

  • Knowledge about infrastructure is centralised.

  • It is non-reproducible.

A solution is configuration management. Chef, ansible, saltstack, puppet. Configuration that’s in source control instead of information in a sysadmin’s head.

  • It is a reproducible way to build your infrastructure.

  • Source code, so everyone can see how a system works.

  • You can even version your infrastructure.

He’ll use saltstack as an example, that’s what they’re using in his company. It is a master/minion system. So a central master pushes out commands to the minion systems.

For testing, he uses a tool called “kitchen”, originally intended for puppet, which can however also be used with saltstack: https://kitchen.saltstack.com/ . He showed a demo where he created a couple of virtualbox machines and automatically ran the salt scripts on them.

You can then ssh to those boxes and check if they’re OK.

But… that’s manual work. So he started using testinfra and pytest. Testinfra helps you test infrastructure. There are build-in tests for checking if a package has been installed, for instance:

def test_emacs_installed(host):
    assert host.package("emacs").is_installed

You can run those tests via “kitchen”. They use that to test their infrastructure setup from travis-ci.com.

 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):