Seite wählen

NETWAYS Blog

RSpec Tests mit rspec-puppet-facts

Auf gefühlt jeder Konferenz gibt es mittlerweile mindestens einen Talk rund um das Thema testing im Configuration Management Umfeld. Obwohl ich bei NETWAYS schon länger mit Puppet arbeite, ist dieses Thema bis jetzt noch nicht so richtig bei mir aufgeschlagen. Jetzt hat es mich aber doch erwischt. Mit dem Icinga2 Chef Cookbook hatte ich meine ersten Berührungspunkte mit RSpec und Serverspec. Das gesammelte Know-How kann ich nun in unserem aktuellen Projekt, einem Rewrite vom Icinga2 Puppet Modul, ganz gut verwenden.
Eine Sache in Verbindung mit RSpec hat mich allerdings gestört: Auch wenn die Tests in der Regel relativ generisch sind, abhängig von Betriebssystem und Version können dennoch unterschiedliche Ergebnisse beim gleichen Test auftreten. Es wäre also hilfreich, alle Tests für alle Betriebssysteme und Versionen auszuführen, die man mit seinem Modul auch unterstützen möchte.
rspec-puppet-facts
Genau das oben genannte kann man mit de Gem rspec-puppet-facts erreichen. Ein kleines Beispiel:
Ein simpler Test für eine Klasse sieht klassischer Weise so aus:

  context "on debian 7" do
    let(:facts) do
      {
        :osfamily                  => 'Debian',
        :operatingsystem           => 'Debian',
        :operatingsystemmajrelease => '7',
      }
      it { is_expected.to compile.with_all_deps }
    end
  end
  context "on centos 6” do
    let(:facts) do
      {
        :osfamily                  => ‘RedHat’,
        :operatingsystem           => ‘CentOS’,
        :operatingsystemmajrelease => '6',
      }
      it { is_expected.to compile.with_all_deps }
    end
  end

So müsste man jetzt für jede Distribution und jede Version jeden Test schreiben/kopieren. Unter Verwendung von rspec-puppet-facts können die unterstützten Betriebssysteme samt Versionen aus der metadata.json angezogen werden. In dieser Datei sollten die Informationen darüber, unter welchen Voraussetzungen das Modul lauffähig sein soll, ohnehin schon stehen. Vorausgesetzt man hat die Datei korrekt befüllt natürlich. Basierend darauf werden dann Puppet Facts bereitgestellt und man kann über diese iterieren. Die oben beschriebenen Tests können dann also so aussehen:

  on_supported_os.each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts
      end
      it { is_expected.to compile.with_all_deps }
    end
  end
Blerim Sheqa
Blerim Sheqa
COO

Blerim ist seit 2013 bei NETWAYS und seitdem schon viel in der Firma rum gekommen. Neben dem Support und diversen internen Projekten hat er auch im Team Infrastruktur tatkräftig mitgewirkt. Hin und wieder lässt er sich auch den ein oder anderen Consulting Termin nicht entgehen. Inzwischen ist Blerim als COO für Icinga tätig und kümmert sich dort um die organisatorische Leitung.

OSDC 2016: More for your datacenter stack

We need more coffee – the first talk of day 2 directly kicked off with automation and challenges. We are using Foreman at NETWAYS and it helps me on a daily basis to deploy development boxes with Opennebula. So it was interesting to find out about insights and challenges by Julien Pivotto with Automating a R&D lab with Foreman: What can be hard?.

#osdc moa 5 starts w/ @roidelapluie from @inuits on managing a R&D lab with @ForemanProject /mif pic.twitter.com/soED2QNoKO

— netways (@netways) April 28, 2016


Sadly the second talk about Interesting things you can do with ZFS by Allan Jude & Benedict Reuschling was at the same time – again one for the conference archive.

Allan Jude and Benedict Reuschling just started their talk "Interesting Things you can do with ZFS" /mn pic.twitter.com/i0J9ub6Rkw

— netways (@netways) April 28, 2016


Decisions decisions. Mesos and the Architecture of the New Datacenter by Jörg Schad or Hybrid Cloud – A Cloud Migration Strategy by Schlomo Shapiro. I guess I’m one of those devops hipsters going for Mesos. Although I hear that its implementation can be tricky (hi Sebastian) we’re using it at NETWAYS and I wanted to learn more about it. Especially since Mesosphere recently announced DC/OS.

.@mesosphere DC/OS #osdc pic.twitter.com/60PdU1Ljq7

— netways (@netways) April 28, 2016


Ingesting Logs with Style sounds like a swiss army knife presentation style. Logs always remind me of the days when there was not Logstash or Graylog around, just some unacceptable expensive Splunk license and your own central syslog server plus some custom handmade scripts. Pere gave an awesome outlook on what’s coming with Elastic Stack 5.0 including hist sports activities as live demos.

Real life @elastic stack demo from @purbon 's sports activities 🙂 #awesome #osdc /mif pic.twitter.com/XAA83HqTCG

— netways (@netways) April 28, 2016


Everyone knows about Docker. Everyone uses it in production already? Or at least tried to until the company’s security team stepped into? Inspecting Security of Docker formatted Container Images to find Peace of Mind provided insights on the most often asked questions when it comes to production deployments.
Right after lunch David Schmitt gave an interesting Introduction to Testing Puppet Modules. Being a developer and writing tests? Meh. The least exciting part right after the documentation bits. Though tests will make your life easier especially with Puppet modules ensuring they won’t break. The talk’s topic also reminds me of Tom de Vylder maintaining the Icinga puppet modules and insisting on rspec tests on every single PR – chapeau 🙂

@dev_el_ops talking about @puppetize testing at #osdc (rspec, rspec-puppet, beaker) pic.twitter.com/J8ZA7LIPqT

— mika (@mikagrml) April 28, 2016


Coming from MariaDB Colin Charles provided tipps and tricks on Tuning Linux for your Database.

. @bytebot from @mariadb is now on stage, talking about Tuning Linux for your Database! /mn pic.twitter.com/F6bQtRIM8p

— netways (@netways) April 28, 2016


An Introduction to Software Defined Networking (SDN) by Martin Loschwitz or Bareos Backup Integration with Standard Open Source Tools with Maik Aussendorf?

An introduction into SDN with @madkissTM at #osdc/be pic.twitter.com/InUn6I6Klp

— netways (@netways) April 28, 2016


Finally the last talks for this years OSDC. We already learned about Puppet and Salt, now it is time for Kaiten Zushi – Chef at Goodgame Studios by Jan Ulferts. Florian Lautenschlager with Chronix – A fast and efficient time series storage based on Apache Solr was again my favourite for the conference archive.
 

Thank you and see you in 2017

The conference archive will be made available in the next couple of days. Save the date – 16.-18.5.2017 🙂
PS: Everything is a freaking DNS problem!

@dnsmichi @bortzmeyer @jpmens I`m actually writing a book on the topic pic.twitter.com/uRhqhNV1J2

— Kris Buytaert (@KrisBuytaert) April 28, 2016