Petr Michalec | 57dcfb7 | 2017-01-10 23:53:54 +0100 | [diff] [blame] | 1 | |
| 2 | Continuous Integration |
| 3 | ====================== |
| 4 | |
| 5 | Check your formulas locally before you create pull request. |
| 6 | |
| 7 | |
| 8 | Usage |
| 9 | ------------------ |
| 10 | |
| 11 | Update pillars in tests/pillar/\*.sls with test data. |
| 12 | Executed tests with: |
| 13 | |
| 14 | .. code-block:: shell |
| 15 | |
| 16 | kitchen list |
| 17 | kitchen test |
| 18 | |
| 19 | |
| 20 | Test Kitchen |
| 21 | ------------------ |
| 22 | |
| 23 | Use Travis/Jenkins to spin a kitchen instances in Docker or OpenStack environment. |
| 24 | Default configuration is defined by ``.kitchen.yml`` and ``tests/pillar/*.sls`` |
| 25 | |
| 26 | Override your specific needs with ``.kitchen.<backend|local>.yml`` that you may load as: |
| 27 | ``KITCHEN_LOCAL_YAML=.kitchen.<driver>.yml kitchen <action> <suite>``. |
| 28 | |
| 29 | Example: ``KITCHEN_LOCAL_YAML=.kitchen.local kitchen verify server-ubuntu-1404 -t tests/integration``. |
| 30 | |
| 31 | Base kitchen-test actions: |
| 32 | |
| 33 | 1. *create*, provision an test instance (VM, container) |
| 34 | 2. *converge*, run a provisioner (shell script, kitchen-salt) |
| 35 | 3. *verify*, run a verification (inspec, other may be added) |
| 36 | 4. *destroy* |
| 37 | |
| 38 | |
| 39 | Verifier |
| 40 | ~~~~~~~~ |
| 41 | |
| 42 | The `Busser <https://github.com/test-kitchen/busser>`_ *Verifier* goes with test-kitchen by default. |
| 43 | It is used to setup and run tests implemented in ``<repo>/test/integration``. It guess and installs the particular driver to tested instance. |
| 44 | By default `InSpec <https://github.com/chef/kitchen-inspec>`_ is expected. |
| 45 | |
| 46 | You may avoid to install busser framework if you configure specific verifier in ``.kitchen.yml`` and install it kitchen plugin locally: |
| 47 | |
| 48 | verifier: |
| 49 | name: serverspec |
| 50 | |
| 51 | If you would to write another verification scripts than InSpec store them in ``<repo>/tests/integration/<suite>/<busser>/*``. |
| 52 | ``Busser <https://github.com/test-kitchen/busser>`` is a test setup and execution framework under test kitchen. |
| 53 | |
| 54 | |
| 55 | **InSpec** |
| 56 | |
| 57 | Implement integration tests under ``<repo>/tests/integration/<suite>/<busser>/*`` directory with ``_spec.rb`` filename |
| 58 | suffix. |
| 59 | |
| 60 | Docs: |
| 61 | |
| 62 | * https://github.com/chef/inspec |
| 63 | * https://github.com/chef/kitchen-inspec |
| 64 | |
| 65 | Requirements |
| 66 | ~~~~~~~~~~~~ |
| 67 | |
| 68 | Use latest stable kitchen-salt and kitchen-test. |
| 69 | Minimal supported version of kitchen-salt is >= v0.0.25. |
| 70 | |
| 71 | |
| 72 | |
| 73 | Jinja templates |
| 74 | --------------- |
| 75 | To check jinja templates you may use: |
| 76 | |
| 77 | .. code-block:: shell |
| 78 | |
| 79 | cat > check_my_jinja_recursive.py <<-EOF |
| 80 | import sys |
| 81 | import os |
| 82 | from jinja2 import Environment |
| 83 | |
| 84 | |
| 85 | def fileList(path, fileTypes): |
| 86 | matches = [] |
| 87 | for root, dirnames, filenames in os.walk(path): |
| 88 | for filename in filenames: |
| 89 | if filename.endswith(fileTypes): |
| 90 | matches.append(os.path.join(root, filename)) |
| 91 | return matches |
| 92 | |
| 93 | env = Environment() |
| 94 | for path in sys.argv: |
| 95 | for template in fileList(path, ('.conf', '.ini', '.jinja2') ): |
| 96 | with open(template) as t: |
| 97 | print"Checking:", template |
| 98 | env.parse(t.read()) |
| 99 | EOF |
| 100 | |
| 101 | |
| 102 | Intstall Test Kitchen |
| 103 | --------------------- |
| 104 | See http://kitchen.ci/ for more details. |
| 105 | |
| 106 | To install user side use: |
| 107 | |
| 108 | .. code-block:: shell |
| 109 | |
| 110 | # install kitchen |
| 111 | gem install test-kitchen |
| 112 | |
| 113 | # install additional plugins |
| 114 | gem install kitchen-docker kitchen-salt |
| 115 | gem install kitchen-vagrant kitchen-openstack kitchen-inspec busser-serverspec |
| 116 | |
| 117 | First you have to install ruby package manager `gem <https://rubygems.org/>`_. |
| 118 | |
| 119 | One may be satisfied installing it system-wide right from OS package manager which is preferred installation method. |
| 120 | For advanced users or the sake of complex environments you may use `rbenv <https://github.com/rbenv/rbenv>`_ for user side ruby installation. |
| 121 | |
| 122 | * https://github.com/rbenv/rbenv |
| 123 | * http://kitchen.ci/docs/getting-started/installing |
| 124 | |
| 125 | An example steps then might be: |
| 126 | |
| 127 | .. code-block:: shell |
| 128 | |
| 129 | # get rbenv |
| 130 | git clone https://github.com/rbenv/rbenv.git ~/.rbenv |
| 131 | |
| 132 | # configure |
| 133 | cd ~/.rbenv && src/configure && make -C src # don't worry if it fails |
| 134 | echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bash_profile |
| 135 | # Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile. |
| 136 | cd ~/.rbenv; git fetch |
| 137 | |
| 138 | # install ruby-build, which provides the rbenv install command |
| 139 | git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build |
| 140 | |
| 141 | # list all available versions: |
| 142 | rbenv install -l |
| 143 | |
| 144 | # install a Ruby version |
| 145 | # maybe you will need additional packages: libssl-dev, libreadline-dev, zlib1g-dev |
| 146 | rbenv install 2.0.0-p648 |
| 147 | |
| 148 | # activate |
| 149 | rbenv local 2.0.0-p648 |
| 150 | |
| 151 | # install test kitchen |
| 152 | gem install test-kitchen |
| 153 | |
| 154 | An optional ``Gemfile`` in the main directory may contain fine tuned dependencies for specific workflows. |
| 155 | To install Gefmfile dependencies run ``gem install bundler`` and then run ``bundler install``. |
| 156 | |