| Petr Ruzicka | ba0a49d | 2018-01-31 22:16:20 +0100 | [diff] [blame] | 1 |  | 
|  | 2 | Continuous Integration | 
|  | 3 | ====================== | 
|  | 4 |  | 
|  | 5 | We are using Jenkins to spin a kitchen instances in Docker or OpenStack environment. | 
|  | 6 |  | 
|  | 7 | If you would like to repeat, then you may use ``.kitchen.<backend>.yml`` configuration yaml in the main directory | 
|  | 8 | to override ``.kitchen.yml`` at some points. | 
|  | 9 | Usage: ``KITCHEN_LOCAL_YAML=.kitchen.<driver>.yml kitchen verify server-ubuntu-1404 -t tests/integration``. | 
|  | 10 | Example: ``KITCHEN_LOCAL_YAML=.kitchen.docker.yml kitchen verify server-ubuntu-1404 -t tests/integration``. | 
|  | 11 |  | 
|  | 12 | Be aware of fundamental differences of backends. The formula verification scripts are primarily tested with | 
|  | 13 | Vagrant driver. | 
|  | 14 |  | 
|  | 15 | CI uses a tuned `make kitchen` target defined in `Makefile` to perform following (Kitchen Test) actions: | 
|  | 16 |  | 
|  | 17 | 1. *create*, provision an test instance (VM, container) | 
|  | 18 | 2. *converge*, run a provisioner (shell script, kitchen-salt) | 
|  | 19 | 3. *verify*, run a verification (inspec, other may be added) | 
|  | 20 | 4. *destroy* | 
|  | 21 |  | 
|  | 22 |  | 
|  | 23 | Test Kitchen | 
|  | 24 | ------------ | 
|  | 25 |  | 
|  | 26 |  | 
|  | 27 | To install Test Kitchen is as simple as: | 
|  | 28 |  | 
|  | 29 | .. code-block:: shell | 
|  | 30 |  | 
|  | 31 | # install kitchen | 
|  | 32 | gem install test-kitchen | 
|  | 33 |  | 
|  | 34 | # install required plugins | 
|  | 35 | gem install kitchen-vagrant kitchen-docker kitchen-salt | 
|  | 36 |  | 
|  | 37 | # install additional plugins & tools | 
|  | 38 | gem install kitchen-openstack kitchen-inspec busser-serverspec | 
|  | 39 |  | 
|  | 40 | kitchen list | 
|  | 41 | kitchen test | 
|  | 42 |  | 
|  | 43 | of course you have to have installed Ruby and it's package manager `gem <https://rubygems.org/>`_ first. | 
|  | 44 |  | 
|  | 45 | One may be satisfied installing it system-wide right from OS package manager which is preferred installation method. | 
|  | 46 | For advanced users or the sake of complex environments you may use `rbenv <https://github.com/rbenv/rbenv>`_ for user side ruby installation. | 
|  | 47 |  | 
|  | 48 | * https://github.com/rbenv/rbenv | 
|  | 49 | * http://kitchen.ci/docs/getting-started/installing | 
|  | 50 |  | 
|  | 51 | An example steps then might be: | 
|  | 52 |  | 
|  | 53 | .. code-block:: shell | 
|  | 54 |  | 
|  | 55 | # get rbenv | 
|  | 56 | git clone https://github.com/rbenv/rbenv.git ~/.rbenv | 
|  | 57 |  | 
|  | 58 | # configure | 
|  | 59 | cd ~/.rbenv && src/configure && make -C src     # don't worry if it fails | 
|  | 60 | echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>> ~/.bash_profile | 
|  | 61 | # Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile. | 
|  | 62 | cd ~/.rbenv; git fetch | 
|  | 63 |  | 
|  | 64 | # install ruby-build, which provides the rbenv install command | 
|  | 65 | git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build | 
|  | 66 |  | 
|  | 67 | # list all available versions: | 
|  | 68 | rbenv install -l | 
|  | 69 |  | 
|  | 70 | # install a Ruby version | 
|  | 71 | # maybe you will need additional packages: libssl-dev, libreadline-dev, zlib1g-dev | 
|  | 72 | rbenv install 2.0.0-p648 | 
|  | 73 |  | 
|  | 74 | # activate | 
|  | 75 | rbenv local 2.0.0-p648 | 
|  | 76 |  | 
|  | 77 | # install test kitchen | 
|  | 78 | gem install test-kitchen | 
|  | 79 |  | 
|  | 80 |  | 
|  | 81 | An optional ``Gemfile`` in the main directory may contain Ruby dependencies to be required for Test Kitchen workflow. | 
|  | 82 | To install them you have to install first ``gem install bundler`` and then run ``bundler install``. | 
|  | 83 |  | 
|  | 84 |  | 
|  | 85 |  | 
|  | 86 | Verifier | 
|  | 87 | -------- | 
|  | 88 |  | 
|  | 89 | The `Busser <https://github.com/test-kitchen/busser>`_ *Verifier* goes with test-kitchen by default. | 
|  | 90 | It is used to setup and run tests implemented in `<repo>/test/integration`. It guess and installs the particular driver to tested instance. | 
|  | 91 | By default `InSpec <https://github.com/chef/kitchen-inspec>`_ is expected. | 
|  | 92 |  | 
|  | 93 | You may avoid to install busser framework if you configure specific verifier in `.kitchen.yml` and install it kitchen plugin locally: | 
|  | 94 |  | 
|  | 95 | verifier: | 
|  | 96 | name: serverspec | 
|  | 97 |  | 
|  | 98 | If you would to write another verification scripts than InSpec store them in ``<repo>/tests/integration/<suite>/<busser>/*``. | 
|  | 99 | ``Busser <https://github.com/test-kitchen/busser>`` is a test setup and execution framework under test kitchen. | 
|  | 100 |  | 
|  | 101 |  | 
|  | 102 |  | 
|  | 103 | InSpec | 
|  | 104 | ~~~~~~ | 
|  | 105 |  | 
|  | 106 | Implement integration tests under ``<repo>/tests/integration/<suite>/<busser>/*`` directory with ``_spec.rb`` filename | 
|  | 107 | suffix. | 
|  | 108 |  | 
|  | 109 | Docs: | 
|  | 110 |  | 
|  | 111 | * https://github.com/chef/inspec | 
|  | 112 | * https://github.com/chef/kitchen-inspec | 
|  | 113 |  | 
|  | 114 |  |