kitchen-salt 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 603063a5f1b59537f46424ca4cd62cdadc7fcd2a666ca00137592f9d8fc82bc6
4
- data.tar.gz: 2ad2433565df3ad9d109094f10dbad63bc13246a15ced4dbbd52ab51ed25e8a9
3
+ metadata.gz: f8bdce74b7821d2d2649710602094447aff55c3c930dae522cd02627d3345328
4
+ data.tar.gz: b056a29408144b366d9f048db41134633ee4460963d451a0ed63911b657098e2
5
5
  SHA512:
6
- metadata.gz: 970af9e45fb7c8adadcfede939438bcfc5a37b9aafd42cb2b0214e9ae9192a4cb6cac409bf56c1a5001e52fb8da2222adfbc5faad6a661e28c04014cd41f134a
7
- data.tar.gz: 46172738dc22bdcd461a75a4d44f8462fe5dc265cc4aad1d5e687e79fef7bfb90c26ca479331167f8212d8e15e9d29c02a40899f0a57ec849f4bf3e3b74b2443
6
+ metadata.gz: 3c6c19e87b2c8f144c92a992cc204163a7f396a3643b07e360ea7be51c7971a5c44ac7937e5d2864f903c7bb809c8f2444092f5d8b7f9a1557d0ba9361ab1623
7
+ data.tar.gz: cfacb475cab20ede8926a31977b7a9e5b1f116ef8d95a706d7a2b578896989c3c71c7fa61307935e6ce2aea1f9d69d48704e450bdada54cd88542ce5f5df8f01
@@ -7,7 +7,12 @@ module Kitchen
7
7
  info("Preparing pillars into #{config[:salt_pillar_root]}")
8
8
 
9
9
  pillars = config[:pillars]
10
- pillars_from_files = config[:'pillars-from-files']
10
+ if config.key?(:'pillars-from-files')
11
+ info("pillars-from-files is deprecated in favor of pillars_from_files")
12
+ pillars_from_files = config[:'pillars-from-files']
13
+ else
14
+ pillars_from_files = config[:'pillars_from_files']
15
+ end
11
16
  pillars_from_directories = config[:pillars_from_directories]
12
17
 
13
18
  debug("Pillars Directories: #{pillars_from_directories}")
@@ -1,5 +1,5 @@
1
1
  module Kitchen
2
2
  module Salt
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ <%= safe_hash.to_yaml %>
@@ -32,7 +32,7 @@ def install_dependencies
32
32
  # setup ppa
33
33
  config[:vendor_repo].select{|x| x[:type]=='ppa'}.each do |repo|
34
34
  script += <<-INSTALL
35
- #{sudo('add-apt-repository')} "ppa:#{repo[:name]}" -y;
35
+ add-apt-repository "ppa:#{repo[:name]}" -y;
36
36
  INSTALL
37
37
  end
38
38
 
@@ -43,17 +43,17 @@ def install_dependencies
43
43
  case type
44
44
  when 'apt'
45
45
  script += <<-INSTALL
46
- #{sudo('apt-get')} update -q;
46
+ apt-get update -q;
47
47
  sleep 10;
48
48
  INSTALL
49
49
  when 'yum'
50
50
  script += <<-INSTALL
51
- #{sudo('yum')} update;
51
+ yum update;
52
52
  sleep 10;
53
53
  INSTALL
54
54
  when 'spm'
55
55
  script += <<-INSTALL
56
- #{sudo('spm')} update_repo;
56
+ spm update_repo;
57
57
  INSTALL
58
58
  end
59
59
  end
@@ -69,21 +69,21 @@ def install_dependencies
69
69
  when 'spm'
70
70
  if formula[:package].nil?
71
71
  script += <<-INSTALL
72
- #{sudo('spm')} -c #{config[:root_path]}/etc/salt install -y #{formula[:name]};
72
+ spm -c #{config[:root_path]}/etc/salt install -y #{formula[:name]};
73
73
  INSTALL
74
74
  else
75
75
  script += <<-INSTALL
76
- #{sudo('curl')} -O #{formula[:package]};
77
- #{sudo('spm')} -c #{config[:root_path]}/etc/salt local install -y "$(basename #{formula[:package]})";
76
+ curl -O #{formula[:package]};
77
+ spm -c #{config[:root_path]}/etc/salt local install -y "$(basename #{formula[:package]})";
78
78
  INSTALL
79
79
  end
80
80
  when 'yum'
81
81
  script += <<-INSTALL
82
- #{sudo('yum')} install -y #{formula[:package]||formula[:name]};
82
+ yum install -y #{formula[:package]||formula[:name]};
83
83
  INSTALL
84
84
  when 'apt'
85
85
  script += <<-INSTALL
86
- #{sudo('apt-get')} install -y #{formula[:package]||formula[:name]};
86
+ apt-get install -y #{formula[:package]||formula[:name]};
87
87
  INSTALL
88
88
  end
89
89
  elsif formula.key?(:path)
@@ -92,8 +92,7 @@ def install_dependencies
92
92
  end
93
93
  script += <<-INSTALL
94
94
  linkFormulas "$SALT_ROOT"
95
- #{sudo('chown')} kitchen.kitchen -R "${SALT_SHARE_DIR}";
96
- #{sudo('chown')} kitchen.kitchen -R "${SALT_ROOT}";
95
+ chown -R "${SUDO_USER:-$USER}" "${SALT_SHARE_DIR}" "${SALT_ROOT}";
97
96
  echo "Content of $SALT_ROOT :";
98
97
  ls -la "$SALT_ROOT";
99
98
  INSTALL
@@ -73,7 +73,9 @@ function linkFormulas() {
73
73
  for formula in $GIT_FORMULA_LIST
74
74
  do
75
75
  name=$(basename "$formula")
76
- ln -fs "$formula/$name" "$SALT_ROOT/$name"
76
+ if [[ ! -L "$SALT_ROOT/$name" ]]; then
77
+ ln -fs "$formula/$name" "$SALT_ROOT/$name"
78
+ fi
77
79
  find "$formula" -maxdepth 1 -mindepth 1 -type d |grep -E "_(modules|states|grains|renderers|returners)" | xargs -I{} \
78
80
  basename {}| xargs -I{} cp -rs "$formula"/{} "$SALT_ROOT"/
79
81
  done
@@ -1,8 +1,8 @@
1
1
  <%=
2
2
  salt_install = config[:salt_install]
3
3
  salt_url = config[:salt_bootstrap_url]
4
- bootstrap_options = config[:salt_bootstrap_options]
5
4
  salt_version = config[:salt_version]
5
+ bootstrap_options = config[:salt_bootstrap_options] % [salt_version]
6
6
  salt_apt_repo = config[:salt_apt_repo]
7
7
  salt_apt_repo_key = config[:salt_apt_repo_key]
8
8
  salt_ppa = config[:salt_ppa]
@@ -15,16 +15,24 @@ if (-Not $installed_version -And "#{salt_install}" -eq "bootstrap") {
15
15
  (New-Object net.webclient).DownloadFile("#{salt_url}", "c:\\temp\\salt_bootstrap.ps1")
16
16
  #{sudo('powershell')} c:\\temp\\salt_bootstrap.ps1 #{bootstrap_options}
17
17
  }
18
- $installed_version = $(c:\\salt\\salt-call.bat --version).split(' ')[1]
19
- if (-Not $installed_version) {
18
+ $FULL_SALT_VERSION = $(c:\\salt\\salt-call.bat --version).split(' ')[1]
19
+ if ($FULL_SALT_VERSION) {
20
+ $YEAR = $FULL_SALT_VERSION.split('.')[0]
21
+ $MONTH = $FULL_SALT_VERSION.split('.')[1]
22
+ $SALT_VERSION = "$YEAR.$MONTH"
23
+ }
24
+
25
+ if (-Not $SALT_VERSION) {
20
26
  write-host "No salt-minion installed, install must have failed!!"
21
27
  write-host "salt_install = #{salt_install}"
22
28
  write-host "salt_url = #{salt_url}"
23
29
  write-host "bootstrap_options = #{bootstrap_options}"
24
- } elseif ($installed_version -And "#{salt_install}" -eq "bootstrap") {
25
- write-host "You asked for bootstrap install and you have got $installed_version, hope that's ok!"
30
+ } elseif ($SALT_VERSION -eq "#{salt_version}" -Or "#{salt_version}" -eq "latest" -Or "#{salt_version}" -eq "$FULL_SALT_VERSION") {
31
+ write-host "You asked for #{salt_version} and you have ${FULL_SALT_VERSION} installed, sweet!"
32
+ } elseif ($SALT_VERSION -And "#{salt_install}" -eq "bootstrap") {
33
+ write-host "You asked for bootstrap install and you have got $SALT_VERSION, hope that's ok!"
26
34
  } else {
27
- write-host "You asked for #{salt_version} and you have got $installed_version installed, dunno ho to fix that, sorry!"
35
+ write-host "You asked for #{salt_version} and you have got $SALT_VERSION installed, dunno how to fix that, sorry!"
28
36
  exit 2
29
37
  }
30
38
  #{install_chef}
@@ -5,10 +5,16 @@ root_dir: <%= config[:root_path] %>
5
5
 
6
6
  file_roots:
7
7
  <%= config[:salt_env] %>:
8
- - <%= File.join(config[:root_path], (windows_os? ? config[:salt_file_root].gsub('/', '\\') : config[:salt_file_root])) %>
9
- - <%= File.join(config[:root_path], (windows_os? ? config[:salt_spm_root].gsub('/', '\\') : config[:salt_spm_root])) %>/salt
8
+ - <%= os_join(config[:root_path], config[:salt_file_root]) %>
9
+ - <%= os_join(config[:root_path], config[:salt_spm_root], 'salt') %>
10
10
 
11
11
  pillar_roots:
12
12
  <%= config[:salt_env] %>:
13
- - <%= File.join(config[:root_path], (windows_os? ? config[:salt_pillar_root].gsub('/', '\\') : config[:salt_pillar_root])) %>
14
- - <%= File.join(config[:root_path], (windows_os? ? config[:salt_spm_root].gsub('/', '\\') : config[:salt_spm_root])) %>/pillar
13
+ - <%= os_join(config[:root_path], config[:salt_pillar_root]) %>
14
+ - <%= os_join(config[:root_path], config[:salt_spm_root], 'pillar') %>
15
+
16
+ <% if windows_os? %>
17
+ file_client: local
18
+ winrepo_dir: <%= os_join(config[:root_path], config[:salt_file_root], 'win', 'repo') %>
19
+ winrepo_dir_ng: <%= os_join(config[:root_path], config[:salt_file_root], 'win', 'repo-ng') %>
20
+ <% end %>
@@ -1,4 +1,4 @@
1
- # -*- encoding: utf-8 -*-
1
+
2
2
  #
3
3
  # Author:: Simon McCartney <simon.mccartney@hp.com>
4
4
  #
@@ -16,11 +16,12 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- require 'kitchen/provisioner/base'
20
- require 'kitchen-salt/util'
19
+ require 'fileutils'
20
+ require 'hashie'
21
21
  require 'kitchen-salt/pillars'
22
22
  require 'kitchen-salt/states'
23
- require 'fileutils'
23
+ require 'kitchen-salt/util'
24
+ require 'kitchen/provisioner/base'
24
25
  require 'yaml'
25
26
 
26
27
  module Kitchen
@@ -35,50 +36,57 @@ module Kitchen
35
36
  include Kitchen::Salt::States
36
37
 
37
38
  DEFAULT_CONFIG = {
39
+ bootstrap_url: 'https://raw.githubusercontent.com/saltstack/kitchen-salt/master/assets/install.sh',
40
+ chef_bootstrap_url: 'https://www.chef.io/chef/install.sh',
41
+ dependencies: [],
38
42
  dry_run: false,
39
- salt_version: 'latest',
40
- salt_install: 'bootstrap',
41
- salt_bootstrap_url: 'https://bootstrap.saltstack.com',
42
- salt_bootstrap_options: '',
43
- salt_apt_repo: 'https://repo.saltstack.com/apt/ubuntu/16.04/amd64/',
43
+ install_after_init_environment: false,
44
+ is_file_root: false,
45
+ local_salt_root: nil,
46
+ omnibus_cachier: false,
47
+ pillars_from_directories: [],
48
+ pip_bin: 'pip',
49
+ pip_editable: false,
50
+ pip_extra_index_url: [],
51
+ pip_index_url: 'https://pypi.python.org/simple/',
52
+ pip_pkg: 'salt==%s',
53
+ remote_states: nil,
54
+ require_chef: true,
44
55
  salt_apt_repo_key: 'https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub',
45
- salt_ppa: 'ppa:saltstack/salt',
46
- bootstrap_url: 'https://raw.githubusercontent.com/saltstack/kitchen-salt/master/assets/install.sh',
47
- chef_bootstrap_url: 'https://www.getchef.com/chef/install.sh',
56
+ salt_apt_repo: 'https://repo.saltstack.com/apt/ubuntu/16.04/amd64/',
57
+ salt_bootstrap_options: '',
58
+ salt_bootstrap_url: 'https://bootstrap.saltstack.com',
48
59
  salt_config: '/etc/salt',
49
- salt_minion_config: '/etc/salt/minion',
50
- salt_minion_config_template: nil,
51
- salt_minion_id: nil,
60
+ salt_copy_filter: [],
52
61
  salt_env: 'base',
53
62
  salt_file_root: '/srv/salt',
63
+ salt_force_color: false,
64
+ salt_install: 'bootstrap',
65
+ salt_minion_config_dropin_files: [],
66
+ salt_minion_config_template: nil,
67
+ salt_minion_config: '/etc/salt/minion',
68
+ salt_minion_extra_config: {},
69
+ salt_minion_id: nil,
54
70
  salt_pillar_root: '/srv/pillar',
71
+ salt_ppa: 'ppa:saltstack/salt',
55
72
  salt_spm_root: '/srv/spm',
56
73
  salt_state_top: '/srv/salt/top.sls',
57
- salt_force_color: false,
74
+ salt_version: 'latest',
75
+ salt_yum_repo_key: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/%s/SALTSTACK-GPG-KEY.pub',
76
+ salt_yum_repo_latest: 'https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm',
77
+ salt_yum_repo: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/%s',
78
+ salt_yum_rpm_key: 'https://repo.saltstack.com/yum/redhat/7/x86_64/archive/%s/SALTSTACK-GPG-KEY.pub',
58
79
  state_collection: false,
59
- state_top: {},
60
80
  state_top_from_file: false,
61
- salt_copy_filter: [],
62
- is_file_root: false,
63
- remote_states: nil,
64
- require_chef: true,
65
- dependencies: [],
81
+ state_top: {},
66
82
  vendor_path: nil,
67
- vendor_repo: {},
68
- omnibus_cachier: false,
69
- local_salt_root: nil,
70
- pillars_from_directories: [],
71
- salt_yum_rpm_key: 'https://repo.saltstack.com/yum/redhat/7/x86_64/archive/%s/SALTSTACK-GPG-KEY.pub',
72
- salt_yum_repo: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/%s',
73
- salt_yum_repo_key: 'https://repo.saltstack.com/yum/redhat/$releasever/$basearch/archive/%s/SALTSTACK-GPG-KEY.pub',
74
- salt_yum_repo_latest: 'https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm',
75
- pip_pkg: 'salt==%s',
76
- pip_editable: false,
77
- pip_index_url: 'https://pypi.python.org/simple/',
78
- pip_extra_index_url: [],
79
- pip_bin: 'pip',
80
- install_after_init_environment: false,
81
- }
83
+ vendor_repo: {}
84
+ }.freeze
85
+
86
+ WIN_DEFAULT_CONFIG = {
87
+ chef_bootstrap_url: 'https://omnitruck.chef.io/install.ps1',
88
+ salt_bootstrap_url: 'https://raw.githubusercontent.com/saltstack/salt-bootstrap/develop/bootstrap-salt.ps1'
89
+ }.freeze
82
90
 
83
91
  # salt-call version that supports the undocumented --retcode-passthrough command
84
92
  RETCODE_VERSION = '0.17.5'.freeze
@@ -87,6 +95,12 @@ module Kitchen
87
95
  default_config k, v
88
96
  end
89
97
 
98
+ WIN_DEFAULT_CONFIG.each_key do |key|
99
+ default_config key do |provisioner|
100
+ provisioner.windows_os? ? WIN_DEFAULT_CONFIG[key] : DEFAULT_CONFIG[key]
101
+ end
102
+ end
103
+
90
104
  def install_command
91
105
  unless config[:salt_install] == 'pip' || config[:install_after_init_environment]
92
106
  setup_salt
@@ -94,9 +108,21 @@ module Kitchen
94
108
  end
95
109
 
96
110
  def prepare_command
111
+ cmd = ''
112
+ unless windows_os?
113
+ cmd += <<-CHOWN
114
+ #{sudo('chown')} -R "${SUDO_USER:-$USER}" "#{config[:root_path]}/#{config[:salt_file_root]}"
115
+ CHOWN
116
+ end
117
+ if config[:prepare_salt_environment]
118
+ cmd += <<-PREPARE
119
+ #{config[:prepare_salt_environment]}
120
+ PREPARE
121
+ end
97
122
  if config[:salt_install] == 'pip' || config[:install_after_init_environment]
98
- setup_salt
123
+ cmd << setup_salt
99
124
  end
125
+ cmd
100
126
  end
101
127
 
102
128
  def setup_salt
@@ -110,14 +136,14 @@ module Kitchen
110
136
  config[:salt_bootstrap_options] = "-P git v#{salt_version}"
111
137
  end
112
138
 
113
- if windows_os?
114
- install_template = File.expand_path("./../install_win.erb", __FILE__)
115
- else
116
- install_template = File.expand_path("./../install.erb", __FILE__)
117
- end
139
+ install_template = if windows_os?
140
+ File.expand_path('./../install_win.erb', __FILE__)
141
+ else
142
+ File.expand_path('./../install.erb', __FILE__)
143
+ end
118
144
 
119
145
  erb = ERB.new(File.read(install_template)).result(binding)
120
- debug("Install Command:" + erb.to_s)
146
+ debug('Install Command:' + erb.to_s)
121
147
  erb
122
148
  end
123
149
 
@@ -126,20 +152,21 @@ module Kitchen
126
152
  chef_url = config[:chef_bootstrap_url]
127
153
  if windows_os?
128
154
  <<-POWERSHELL
129
- if (-Not $(test-path c:\\opscode\\chef) {
155
+ if (-Not $(test-path c:\\opscode\\chef)) {
130
156
  if (-Not $(Test-Path c:\\temp)) {
131
157
  New-Item -Path c:\\temp -itemtype directory
132
158
  }
159
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
133
160
  (New-Object net.webclient).DownloadFile("#{chef_url}", "c:\\temp\\chef_bootstrap.ps1")
134
161
  write-host "-----> Installing Chef Omnibus (for busser/serverspec ruby support)"
135
162
  #{sudo('powershell')} c:\\temp\\chef_bootstrap.ps1
136
163
  }
137
164
  POWERSHELL
138
165
  else
139
- omnibus_download_dir = config[:omnibus_cachier] ? '/tmp/vagrant-cache/omnibus_chef' : '/tmp'
140
- bootstrap_url = config[:bootstrap_url]
141
- bootstrap_download_dir = '/tmp'
142
- <<-INSTALL
166
+ omnibus_download_dir = config[:omnibus_cachier] ? '/tmp/vagrant-cache/omnibus_chef' : '/tmp'
167
+ bootstrap_url = config[:bootstrap_url]
168
+ bootstrap_download_dir = '/tmp'
169
+ <<-INSTALL
143
170
  echo "-----> Trying to install ruby(-dev) using assets.sh from kitchen-salt"
144
171
  mkdir -p #{bootstrap_download_dir}
145
172
  if [ ! -x #{bootstrap_download_dir}/install.sh ]
@@ -177,24 +204,24 @@ module Kitchen
177
204
  def prepare_install
178
205
  salt_version = config[:salt_version]
179
206
  if config[:salt_install] == 'pip'
180
- debug("Using pip to install")
207
+ debug('Using pip to install')
181
208
  if File.exist?(config[:pip_pkg])
182
- debug("Installing with pip from sdist")
209
+ debug('Installing with pip from sdist')
183
210
  sandbox_pip_path = File.join(sandbox_path, 'pip')
184
211
  FileUtils.mkdir_p(sandbox_pip_path)
185
212
  FileUtils.cp_r(config[:pip_pkg], sandbox_pip_path)
186
213
  config[:pip_install] = File.join(config[:root_path], 'pip', File.basename(config[:pip_pkg]))
187
214
  else
188
- debug("Installing with pip from download")
215
+ debug('Installing with pip from download')
189
216
  if salt_version != 'latest'
190
- config[:pip_install] = config[:pip_pkg] % [salt_version]
217
+ config[:pip_install] = format(config[:pip_pkg], salt_version)
191
218
  else
192
219
  config[:pip_pkg].slice!('==%s')
193
220
  config[:pip_install] = config[:pip_pkg]
194
221
  end
195
222
  end
196
223
  elsif config[:salt_install] == 'bootstrap'
197
- if File.exists?(config[:salt_bootstrap_url])
224
+ if File.exist?(config[:salt_bootstrap_url])
198
225
  FileUtils.cp_r(config[:salt_bootstrap_url], File.join(sandbox_path, 'bootstrap.sh'))
199
226
  end
200
227
  end
@@ -202,44 +229,50 @@ module Kitchen
202
229
 
203
230
  def init_command
204
231
  debug("Initialising Driver #{name}")
205
- if windows_os?
206
- cmd = "mkdir -Force -Path ""#{config[:root_path]}""\n"
207
- else
208
- cmd = "mkdir -p '#{config[:root_path]}';"
209
- end
232
+ cmd = if windows_os?
233
+ 'mkdir -Force -Path '"#{config[:root_path]}""\n"
234
+ else
235
+ "mkdir -p '#{config[:root_path]}';"
236
+ end
210
237
  cmd += <<-INSTALL
211
238
  #{config[:init_environment]}
212
239
  INSTALL
213
240
  cmd
214
241
  end
215
242
 
243
+ def os_join(*args)
244
+ if windows_os?
245
+ File.join(*args).tr('/', '\\')
246
+ else
247
+ File.join(*args)
248
+ end
249
+ end
250
+
216
251
  def salt_command
217
252
  salt_version = config[:salt_version]
218
253
 
219
- cmd = ""
254
+ cmd = ''
220
255
  if windows_os?
221
256
  salt_call = "c:\\salt\\salt-call.bat"
222
- salt_config_path = config[:salt_config].gsub('/', '\\')
223
- cmd << "(get-content #{File.join(config[:root_path], salt_config_path, 'minion').gsub('/', '\\')}).replace(\"`$env`:TEMP\", $env:TEMP) | set-content #{File.join(config[:root_path], salt_config_path, 'minion').gsub('/', '\\')} ;"
257
+ salt_config_path = config[:salt_config]
258
+ cmd << "(get-content #{os_join(config[:root_path], salt_config_path, 'minion')}) -replace '\\$env:TEMP', $env:TEMP | set-content #{os_join(config[:root_path], salt_config_path, 'minion')} ;"
224
259
  else
225
260
  # install/update dependencies
226
261
  cmd << sudo("chmod +x #{config[:root_path]}/*.sh;")
227
262
  cmd << sudo("#{config[:root_path]}/dependencies.sh;")
228
263
  salt_config_path = config[:salt_config]
229
- salt_call = "salt-call"
264
+ salt_call = 'salt-call'
230
265
  end
231
- cmd << sudo("#{salt_call} --state-output=changes --config-dir=#{File.join(config[:root_path], salt_config_path)} --local state.highstate")
266
+ cmd << sudo("#{salt_call} --state-output=changes --config-dir=#{os_join(config[:root_path], salt_config_path)} state.highstate")
232
267
  cmd << " --log-level=#{config[:log_level]}" if config[:log_level]
233
268
  cmd << " --id=#{config[:salt_minion_id]}" if config[:salt_minion_id]
234
269
  cmd << " test=#{config[:dry_run]}" if config[:dry_run]
235
- cmd << " --force-color" if config[:salt_force_color]
270
+ cmd << ' --force-color' if config[:salt_force_color]
236
271
  if salt_version > RETCODE_VERSION || salt_version == 'latest'
237
272
  # hope for the best and hope it works eventually
238
273
  cmd << ' --retcode-passthrough'
239
274
  end
240
- if windows_os?
241
- cmd << ' ; exit $LASTEXITCODE'
242
- end
275
+ cmd << ' 2>&1 ; exit $LASTEXITCODE' if windows_os?
243
276
  cmd
244
277
  end
245
278
 
@@ -282,20 +315,18 @@ module Kitchen
282
315
  cp_r_with_filter(config[:data_path], tmpdata_dir, config[:salt_copy_filter])
283
316
  end
284
317
 
285
- def prepare_minion
286
- info('Preparing salt-minion')
287
-
318
+ def prepare_minion_base_config
288
319
  if config[:salt_minion_config_template]
289
320
  minion_template = File.expand_path(config[:salt_minion_config_template], Kitchen::Config.new.kitchen_root)
290
321
  else
291
- minion_template = File.expand_path("./../minion.erb", __FILE__)
322
+ minion_template = File.expand_path('./../minion.erb', __FILE__)
292
323
  end
293
324
 
294
- if File.extname(minion_template) == ".erb"
295
- minion_config_content = ERB.new(File.read(minion_template)).result(binding)
296
- else
297
- minion_config_content = File.read(minion_template)
298
- end
325
+ minion_config_content = if File.extname(minion_template) == '.erb'
326
+ ERB.new(File.read(minion_template)).result(binding)
327
+ else
328
+ File.read(minion_template)
329
+ end
299
330
 
300
331
  # create the temporary path for the salt-minion config file
301
332
  debug("sandbox is #{sandbox_path}")
@@ -304,6 +335,39 @@ module Kitchen
304
335
  write_raw_file(sandbox_minion_config_path, minion_config_content)
305
336
  end
306
337
 
338
+ def prepare_minion_extra_config
339
+ minion_template = File.expand_path('./../99-minion.conf.erb', __FILE__)
340
+
341
+ safe_hash = Hashie.stringify_keys(config[:salt_minion_extra_config])
342
+ minion_extra_config_content = ERB.new(File.read(minion_template)).result(binding)
343
+
344
+ sandbox_dropin_path = File.join(sandbox_path, 'etc/salt/minion.d')
345
+
346
+ write_raw_file(File.join(sandbox_dropin_path, '99-minion.conf'), minion_extra_config_content)
347
+ end
348
+
349
+ def insert_minion_config_dropins
350
+ sandbox_dropin_path = File.join(sandbox_path, 'etc/salt/minion.d')
351
+ FileUtils.mkdir_p(sandbox_dropin_path)
352
+
353
+ config[:salt_minion_config_dropin_files].each_index do |i|
354
+ filename = File.basename(config[:salt_minion_config_dropin_files][i])
355
+ index = (99 - config[:salt_minion_config_dropin_files].count + i).to_s.rjust(2, '0')
356
+
357
+ file = File.expand_path(config[:salt_minion_config_dropin_files][i])
358
+ data = File.read(file)
359
+
360
+ write_raw_file(File.join(sandbox_dropin_path, [index, filename].join('-')), data)
361
+ end
362
+ end
363
+
364
+ def prepare_minion
365
+ info('Preparing salt-minion')
366
+ prepare_minion_base_config
367
+ prepare_minion_extra_config if config[:salt_minion_extra_config].keys.any?
368
+ insert_minion_config_dropins if config[:salt_minion_config_dropin_files].any?
369
+ end
370
+
307
371
  def prepare_grains
308
372
  debug("Grains Hash: #{config[:grains]}")
309
373
 
@@ -326,14 +390,14 @@ module Kitchen
326
390
  # PLACEHOLDER, git formulas might be fetched locally to temp and uploaded
327
391
 
328
392
  # setup spm
329
- spm_template = File.expand_path("./../spm.erb", __FILE__)
393
+ spm_template = File.expand_path('./../spm.erb', __FILE__)
330
394
  spm_config_content = ERB.new(File.read(spm_template)).result(binding)
331
395
  sandbox_spm_config_path = File.join(sandbox_path, config[:salt_config], 'spm')
332
396
  write_raw_file(sandbox_spm_config_path, spm_config_content)
333
397
 
334
- spm_repos = config[:vendor_repo].select{|x| x[:type]=='spm'}.each{|x| x[:url]}.map {|x| x[:url] }
398
+ spm_repos = config[:vendor_repo].select { |x| x[:type] == 'spm' }.each { |x| x[:url] }.map { |x| x[:url] }
335
399
  spm_repos.each do |url|
336
- id=url.gsub(/[htp:\/.]/,'')
400
+ id = url.gsub(/[htp:\/.]/, '')
337
401
  spmreposd = File.join(sandbox_path, 'etc', 'salt', 'spm.repos.d')
338
402
  repo_spec = File.join(spmreposd, 'spm.repo')
339
403
  FileUtils.mkdir_p(spmreposd)
@@ -345,13 +409,12 @@ module Kitchen
345
409
  end
346
410
 
347
411
  # upload scripts
348
- %w(formula-fetch.sh repository-setup.sh).each do |script|
412
+ %w[formula-fetch.sh repository-setup.sh].each do |script|
349
413
  write_raw_file(File.join(sandbox_path, script), File.read(File.expand_path("../#{script}", __FILE__)))
350
414
  end
351
- dependencies_script = File.expand_path("./../dependencies.erb", __FILE__)
415
+ dependencies_script = File.expand_path('./../dependencies.erb', __FILE__)
352
416
  dependencies_content = ERB.new(File.read(dependencies_script)).result(binding)
353
417
  write_raw_file(File.join(sandbox_path, 'dependencies.sh'), dependencies_content)
354
-
355
418
  end
356
419
  end
357
420
  end
@@ -23,7 +23,10 @@ module Kitchen
23
23
 
24
24
  def call(state)
25
25
  info("[#{name}] Verify on instance #{instance.name} with state=#{state}")
26
- root_path = (config[:windows] ? '$env:TEMP\\kitchen' : '/tmp/kitchen')
26
+ root_path = (config[:windows] ? '%TEMP%\\kitchen' : '/tmp/kitchen')
27
+ if ENV['KITCHEN_TESTS']
28
+ ENV['KITCHEN_TESTS'].split(' ').each{|test| config[:tests].push(test)}
29
+ end
27
30
  command = [
28
31
  (config[:windows] ? 'python.exe' : config[:python_bin]),
29
32
  File.join(root_path, config[:testingdir], '/tests/runtests.py'),
@@ -31,18 +34,25 @@ module Kitchen
31
34
  '--output-columns=80',
32
35
  (config[:windows] ? "--names-file=#{root_path}\\testing\\tests\\whitelist.txt" : ''),
33
36
  (config[:transport] ? "--transport=#{config[:transport]}" : ''),
34
- (config[:verbose] ? '-v' : ''),
37
+ (config[:verbose] ? '-vv' : '-v'),
35
38
  (config[:run_destructive] ? "--run-destructive" : ''),
36
39
  (config[:coverage_xml] ? "--coverage-xml=#{config[:coverage_xml]}" : ''),
37
40
  (config[:xml] ? "--xml=#{config[:xml]}" : ''),
38
41
  config[:types].collect{|type| "--#{type}"}.join(' '),
39
42
  config[:tests].collect{|test| "-n #{test}"}.join(' '),
43
+ '2>&1',
40
44
  ].join(' ')
45
+ if config[:windows]
46
+ command = "cmd.exe /c \"#{command}\" 2>&1"
47
+ end
41
48
  info("Running Command: #{command}")
42
49
  instance.transport.connection(state) do |conn|
43
50
  begin
44
51
  if config[:windows]
45
52
  conn.execute('$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")')
53
+ conn.execute("$env:PythonPath = [Environment]::ExpandEnvironmentVariables(\"#{root_path}\\testing\")")
54
+ else
55
+ conn.execute(sudo("chown -R $USER #{root_path}"))
46
56
  end
47
57
  conn.execute(sudo(command))
48
58
  ensure
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SaltStack Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: test-kitchen
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,19 +39,19 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.4'
27
41
  - !ruby/object:Gem::Dependency
28
- name: pry
42
+ name: coderay
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 0.10.1
47
+ version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 0.10.1
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: gem-release
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,21 +67,21 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: 0.7.3
55
69
  - !ruby/object:Gem::Dependency
56
- name: coderay
70
+ name: kitchen-sync
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '2.2'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '2.2'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rake
84
+ name: maruku
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -81,7 +95,21 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: yard
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: maruku
126
+ name: yard
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -119,6 +147,7 @@ files:
119
147
  - lib/kitchen-salt/states.rb
120
148
  - lib/kitchen-salt/util.rb
121
149
  - lib/kitchen-salt/version.rb
150
+ - lib/kitchen/provisioner/99-minion.conf.erb
122
151
  - lib/kitchen/provisioner/dependencies.erb
123
152
  - lib/kitchen/provisioner/formula-fetch.sh
124
153
  - lib/kitchen/provisioner/install.erb