blob: 3a0d92f17ee067b50cfb8190b213a393eabe2153 [file] [log] [blame]
Petr Michalec57dcfb72017-01-10 23:53:54 +01001
2Continuous Integration
3======================
4
5Check your formulas locally before you create pull request.
6
7
8Usage
9------------------
10
11Update pillars in tests/pillar/\*.sls with test data.
12Executed tests with:
13
14.. code-block:: shell
15
16 kitchen list
17 kitchen test
18
19
20Test Kitchen
21------------------
22
23Use Travis/Jenkins to spin a kitchen instances in Docker or OpenStack environment.
24Default configuration is defined by ``.kitchen.yml`` and ``tests/pillar/*.sls``
25
26Override your specific needs with ``.kitchen.<backend|local>.yml`` that you may load as:
27``KITCHEN_LOCAL_YAML=.kitchen.<driver>.yml kitchen <action> <suite>``.
28
29Example: ``KITCHEN_LOCAL_YAML=.kitchen.local kitchen verify server-ubuntu-1404 -t tests/integration``.
30
31Base kitchen-test actions:
32
331. *create*, provision an test instance (VM, container)
342. *converge*, run a provisioner (shell script, kitchen-salt)
353. *verify*, run a verification (inspec, other may be added)
364. *destroy*
37
38
39Verifier
40~~~~~~~~
41
42The `Busser <https://github.com/test-kitchen/busser>`_ *Verifier* goes with test-kitchen by default.
43It is used to setup and run tests implemented in ``<repo>/test/integration``. It guess and installs the particular driver to tested instance.
44By default `InSpec <https://github.com/chef/kitchen-inspec>`_ is expected.
45
46You 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
51If 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
57Implement integration tests under ``<repo>/tests/integration/<suite>/<busser>/*`` directory with ``_spec.rb`` filename
58suffix.
59
60Docs:
61
62* https://github.com/chef/inspec
63* https://github.com/chef/kitchen-inspec
64
65Requirements
66~~~~~~~~~~~~
67
68Use latest stable kitchen-salt and kitchen-test.
69Minimal supported version of kitchen-salt is >= v0.0.25.
70
71
72
73Jinja templates
74---------------
75To 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
102Intstall Test Kitchen
103---------------------
104See http://kitchen.ci/ for more details.
105
106To 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
117First you have to install ruby package manager `gem <https://rubygems.org/>`_.
118
119One may be satisfied installing it system-wide right from OS package manager which is preferred installation method.
120For 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
125An 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
154An optional ``Gemfile`` in the main directory may contain fine tuned dependencies for specific workflows.
155To install Gefmfile dependencies run ``gem install bundler`` and then run ``bundler install``.
156