Obsolete:Puppet/Testing

From Wikitech

Puppet CI

  • Lints
    • [done] Puppet-typos
    • [done] Puppet-validate
    • [ongoing] Misc language-specific stuff, e.g. pep8
    • Puppet-lint, someday?
      • Easy to implement, but can probably never actually block.
  • Unit Tests
  • Compile Tests
    • [ON HOLD] --noop tests within modules
      • Mostly done
      • Insecure
    • Run compiles for expressly-written test manifests
      • Probably safe to run on gallium if we use a fake node with ready-made facts
    • Enumerate node definitions, run compile test on each (?)
      • Do this later or never
      • Need way to inject/mock up facts
  • Integration Tests
    • Build VMs from short list of test node definitions
    • Can test successfull puppet runs, but not really test that the servers work
      • This might be easy once we figure out vagrant/labs integration for Compile tests.
    • Build VMs from every existing test node definition (?)
      • This will be insanely expensive, probably can't happen per patch.

Isolation requirements: - VM must not have access network - VM must have a predefined time to live

Local testing

It is possible to run some Puppet tests locally. To do that, you will need an environment setup.

Getting the source

Source code: operations/puppet

$ git clone --recursive https://gerrit.wikimedia.org/r/operations/puppet

Prerequisites

The instructions below refer to rbenv and .ruby-version. The latter file is gone (it was outdated for a long time) and the former may have better replacements. This documentation should be updated accordingly. Until then, if your system has the same Ruby version as the puppet masters, things will likely be okay.

You need to make sure that you have a ruby version installed that matches the version in production (see the .ruby-version file in the puppet repo). If your system version of ruby differs from that, you may use rbenv to build the required version for you.

macOS
Via macports:
# port install rbenv ruby-build
# port search tox
# port install py<ver>-tox
Via Homebrew:
# brew install tox rbenv
Debian/Ubuntu
If using the ruby system package:
$ sudo apt install ruby bundler tox
If not using the ruby system package:
$ sudo apt install rbenv ruby-build tox

Application environment

  1. Either run rbenv init to hook rbenv to your shell or follow instructions from here https://github.com/rbenv/rbenv#how-rbenv-hooks-into-your-shell.
  2. Go to your local puppet repo to have rbenv install the appropriate ruby version
    $ rbenv install
  3. List versions available (including your system version):
    $ rbenv versions
  4. Install bundler (skip this if using the bundler system package):
    $ rbenv exec gem install bundler
  5. Install dependencies:
    rbenv exec bundle install
  6. If using ruby/bundler system package:
    $ bundle install --path vendor/bundle

Test that it is ok, the following will show you a list of tasks:

 $ rbenv exec bundle exec rake --tasks

Done, your env is ready!