blob: 0069d7efa71469a2e6227a401874bd9ff1695793 [file] [log] [blame]
Jakub Josef25c0ea52017-04-27 17:46:27 +02001package com.mirantis.mk
2
3/**
4 * Ruby functions
5 */
6
Jakub Josefad59b2f2017-04-28 16:08:40 +02007/**
8 * Ensures Ruby environment with given version (install it if necessary)
Jakub Josef7ad08f32017-05-03 13:23:42 +02009 * @param rubyVersion target ruby version (optional, default 2.2.3)
Jakub Josefad59b2f2017-04-28 16:08:40 +020010 */
Jakub Josef7ad08f32017-05-03 13:23:42 +020011def ensureRubyEnv(rubyVersion="2.2.3"){
Jakub Josefad59b2f2017-04-28 16:08:40 +020012 if(!fileExists("/var/lib/jenkins/.rbenv/versions/${rubyVersion}/bin/ruby")){
13 sh "rbenv install ${rubyVersion}";
14 }
15 sh "rbenv local ${rubyVersion};rbenv exec gem update --system"
Jakub Josef25c0ea52017-04-27 17:46:27 +020016}
Jakub Josefad59b2f2017-04-28 16:08:40 +020017
18/**
19 * Install kitchen tools
20 */
Jakub Josef25c0ea52017-04-27 17:46:27 +020021def installKitchen(){
22 sh """rbenv exec gem install bundler;
Jakub Josef4cda59e2017-04-28 21:00:01 +020023 rbenv exec gem install test-kitchen;"""
24 sh """ test -e Gemfile || cat <<EOF > Gemfile
25 source 'https://rubygems.org'
26 gem 'rake'
27 gem 'test-kitchen'
28 gem 'kitchen-docker'
29 gem 'kitchen-inspec'
30 gem 'inspec'
Jakub Josef698c6122017-05-19 20:57:33 +020031 gem 'kitchen-salt', :git => 'https://github.com/salt-formulas/kitchen-salt.git'"""
Jakub Josef4cda59e2017-04-28 21:00:01 +020032 sh "rbenv exec bundler install --path vendor/bundle"
Jakub Josef25c0ea52017-04-27 17:46:27 +020033}
34
Jakub Josefad59b2f2017-04-28 16:08:40 +020035/**
36 * Run kitchen tests in tests/integration
37 */
Jakub Josef6b73f6c2017-05-19 11:53:04 +020038def runKitchenTests(platform=""){
Jakub Josef785d9f92017-05-18 17:58:59 +020039 runKitchenCommand("converge ${platform}")
40 runKitchenCommand("verify -t tests/integration ${platform}")
41 runKitchenCommand("destroy ${platform}");
Jakub Josef25c0ea52017-04-27 17:46:27 +020042}
43
Jakub Josefad59b2f2017-04-28 16:08:40 +020044/**
45 * Run kitchen command
46 * @param cmd kitchen command
47 */
Jakub Josef785d9f92017-05-18 17:58:59 +020048def runKitchenCommand(cmd, platform = null){
49 if(platform){
50 sh "PLATFORM=${platform} rbenv exec bundler exec kitchen ${cmd}"
51 }else{
52 sh "rbenv exec bundler exec kitchen ${cmd}"
53 }
Jakub Josef25c0ea52017-04-27 17:46:27 +020054}
55
56
57