Class: KitchenHooks::App

Inherits:
Sinatra::Application
  • Object
show all
Defined in:
lib/kitchen_hooks/app.rb,
lib/kitchen_hooks/helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply_constraints(constraints, environment, knife) ⇒ Object



306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/kitchen_hooks/helpers.rb', line 306

def self.apply_constraints constraints, environment, knife
  # Ripped from Berkshelf::Cli::apply and Berkshelf::Lockfile::apply
  # https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/cli.rb
  # https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/lockfile.rb
  $stdout.puts 'started apply_constraints environment=%s, knife=%s' % [
    environment.inspect, knife.inspect
  ]
  chef_environment = get_environment environment, knife
  raise 'Could not find environment "%s"' % environment if chef_environment.nil?
  chef_environment.cookbook_versions = constraints
  chef_environment.save
  $stdout.puts 'finished apply_constraints: %s' % environment
end

.author(event) ⇒ Object



421
422
423
# File 'lib/kitchen_hooks/helpers.rb', line 421

def self.author event
  event['user_name']
end

.backlog!Object



38
39
40
41
42
43
44
45
46
# File 'lib/kitchen_hooks/app.rb', line 38

def self.backlog!
  @@backlog = Queue.new
  @@backlog_worker = Thread.new do
    loop do
      event = @@backlog.shift
      App.process event
    end
  end
end

.berks_install(berksfile, knife = nil) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/kitchen_hooks/helpers.rb', line 194

def self.berks_install berksfile, knife=nil
  $stdout.puts 'started berks_install berksfile=%s' % berksfile.inspect
  env_git_dir = ENV.delete 'GIT_DIR'
  env_git_work_tree = ENV.delete 'GIT_WORK_TREE'

  knife_args = if knife
    '--config %s' % Shellwords::escape(berkshelf_config knife)
  end

  cmd = 'berks install --debug --berksfile %s %s 2>&1' % [
    Shellwords::escape(berksfile), knife_args
  ]
  begin
    $stdout.puts "berks_install: %s" % cmd
    system cmd
    raise unless $?.exitstatus.zero?
  rescue
    raise 'Could not perform berks_install with config %s' % [
      berksfile.inspect
    ]
  end

  ENV['GIT_DIR'] = env_git_dir
  ENV['GIT_WORK_TREE'] = env_git_work_tree
  $stdout.puts 'finished berks_install: %s' % berksfile
end

.berks_upload(berksfile, knife, options = {}) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/kitchen_hooks/helpers.rb', line 222

def self.berks_upload berksfile, knife, options={}
  $stdout.puts 'started berks_upload berksfile=%s, knife=%s' % [
    berksfile.inspect, knife.inspect
  ]
  config_path = berkshelf_config(knife)

  cmd = 'berks upload --debug --berksfile %s --config %s 2>&1' % [
    Shellwords::escape(berksfile), Shellwords::escape(config_path)
  ]

  begin
    $stdout.puts "berks_upload: %s" % cmd
    system cmd
    raise unless $?.exitstatus.zero?
  rescue
    raise 'Could not perform berks_upload with config %s, knife %s' % [
      berksfile.inspect, knife.inspect
    ]
  end

  FileUtils.rm_rf config_path
  $stdout.puts 'finished berks_upload: %s' % berksfile
end

.berkshelf_config(knife) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/kitchen_hooks/helpers.rb', line 173

def self.berkshelf_config knife
  ridley = Ridley::from_chef_config knife
  config = {
    chef: {
      node_name: ridley.client_name,
      client_key: ridley.client_key,
      chef_server_url: ridley.server_url
    },
    ssl: {
      verify: false
    }
  }
  $stdout.puts 'Berkshelf config: %s' % JSON::pretty_generate(config)
  config_path = File.join tmp, "#{SecureRandom.hex}-berkshelf.json"
  File.open(config_path, 'w') do |f|
    f.puts JSON::generate(config)
  end
  return config_path
end

.close!Object



31
32
33
34
35
36
# File 'lib/kitchen_hooks/app.rb', line 31

def self.close!
  @@sync_worker.kill if defined? @@sync_worker
  @@backlog_worker.kill
  @@db.flush
  @@db.close
end

.commit_to_kitchen?(event) ⇒ Boolean

Returns:

  • (Boolean)


489
490
491
# File 'lib/kitchen_hooks/helpers.rb', line 489

def self.commit_to_kitchen? event
  repo_name(event) == 'kitchen' && not_deleted?(event)
end

.commit_to_master?(event) ⇒ Boolean

Returns:

  • (Boolean)


479
480
481
# File 'lib/kitchen_hooks/helpers.rb', line 479

def self.commit_to_master? event
  event['ref'] == 'refs/heads/master'
end

.config!(config) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kitchen_hooks/app.rb', line 59

def self.config! config
  $stderr.puts 'ENV: %s' % JSON::pretty_generate(ENV.to_hash)
  @@config = config
  @@hipchat = nil
  if config['hipchat']
    @@hipchat = HipChat::Client.new config['hipchat']['token']
    @@hipchat_nick = config['hipchat']['nick'] || raise('No HipChat "nick" provided')
    @@hipchat_room = config['hipchat']['room'] || raise('No HipChat "room" provided')
  end
  @@knives = config['knives'].map do |_, knife|
    Pathname.new(knife).expand_path.realpath.to_s
  end
  @@sync_interval = config['sync_interval']
end

.cookbook_name(event) ⇒ Object



431
432
433
# File 'lib/kitchen_hooks/helpers.rb', line 431

def self.cookbook_name event
  repo_name(event).sub /^(app|base|realm|fork)_/, 'bjn_'
end

.cookbook_repo?(event) ⇒ Boolean

Returns:

  • (Boolean)


436
437
438
# File 'lib/kitchen_hooks/helpers.rb', line 436

def self.cookbook_repo? event
  repo_name(event) =~ /^(app|base|realm|fork)_/
end

.dbObject



111
# File 'lib/kitchen_hooks/app.rb', line 111

def self.db ; @@db end

.db!(path = @@db_path) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/kitchen_hooks/app.rb', line 20

def self.db! path=@@db_path
  if defined? @@db
    @@db.flush
    @@db.close
  end
  @@db_path = path
  @@db = Daybreak::DB.new path
end

.generic_details(event) ⇒ Object



403
404
405
406
407
408
# File 'lib/kitchen_hooks/helpers.rb', line 403

def self.generic_details event
  return if event.nil?
  %Q|
    <i>#{author(event)}</i> pushed #{push_details(event)}
  |.strip
end

.get_environment(environment, knife) ⇒ Object



288
289
290
291
# File 'lib/kitchen_hooks/helpers.rb', line 288

def self.get_environment environment, knife
  ridley = Ridley::from_chef_config knife
  ridley.environment.find environment
end

.git_daemon_style_url(event) ⇒ Object



446
447
448
# File 'lib/kitchen_hooks/helpers.rb', line 446

def self.git_daemon_style_url event
  event['repository']['url'].sub(':', '/').sub('@', '://')
end

.gitlab_tag_url(event) ⇒ Object



457
458
459
460
# File 'lib/kitchen_hooks/helpers.rb', line 457

def self.gitlab_tag_url event
  url = git_daemon_style_url(event).sub(/^git/, 'http').sub(/\.git$/, '')
  "#{url}/commits/#{tag_name(event)}"
end

.gitlab_url(event) ⇒ Object



451
452
453
454
# File 'lib/kitchen_hooks/helpers.rb', line 451

def self.gitlab_url event
  url = git_daemon_style_url(event).sub(/^git/, 'http').sub(/\.git$/, '')
  "#{url}/commit/#{event['after']}"
end

.hipchat(message, color) ⇒ Object



117
118
119
120
121
# File 'lib/kitchen_hooks/app.rb', line 117

def self.hipchat message, color
  return if @@hipchat.nil?
  @@hipchat[@@hipchat_room].send @@hipchat_nick, message, \
    color: color, notify: false, message_format: 'html'
end

.humanize_seconds(secs) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kitchen_hooks/helpers.rb', line 30

def self.humanize_seconds secs
  [
    [ 60, :seconds ],
    [ 60, :minutes ],
    [ 24, :hours ],
    [ 1000, :days ]
  ].map { |count, name|
    if secs > 0
      secs, n = secs.divmod(count)
      "#{n.to_i} #{name}"
    end
  }.compact.reverse.join(' ')
end

.kitchen_upload(knives) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/kitchen_hooks/helpers.rb', line 139

def self.kitchen_upload knives
  if Dir.exist? 'data_bags'
    $stdout.puts 'Uploading data_bags'
    begin
      with_each_knife_do 'upload data_bags --chef-repo-path .', knives
    rescue
      raise 'Could not upload data bags'
    end
  end

  if Dir.exist? 'roles'
    $stdout.puts 'Uploading roles'
    begin
      with_each_knife_do 'upload roles --chef-repo-path .', knives
    rescue
      raise 'Could not upload roles'
    end
  end

  if Dir.exist? 'environments'
    $stdout.puts 'Uploading environments'
    Dir['environments/*'].each do |e|
      knives.each do |k|
        begin
          upload_environment e, k
        rescue
          raise 'Could not upload environments'
        end
      end
    end
  end
end

.knivesObject



115
# File 'lib/kitchen_hooks/app.rb', line 115

def self.knives ; @@knives ||= [] end

.latest_commit(event) ⇒ Object



463
464
465
# File 'lib/kitchen_hooks/helpers.rb', line 463

def self.latest_commit event
  event['commits'].last['id']
end

.lockfile_constraints(lockfile_path) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/kitchen_hooks/helpers.rb', line 321

def self.lockfile_constraints lockfile_path
  # Ripped from Berkshelf::Cli::apply and Berkshelf::Lockfile::apply
  # https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/cli.rb
  # https://github.com/berkshelf/berkshelf/blob/master/lib/berkshelf/lockfile.rb
  lockfile = Berkshelf::Lockfile.from_file lockfile_path
  constraints = lockfile.graph.locks.inject({}) do |hash, (name, dependency)|
    hash[name] = "= #{dependency.locked_version.to_s}"
    hash
  end
  $stdout.puts 'constraints: %s -> %s' % [ lockfile_path, constraints ]
  return constraints
end

.mark(event, type, error = nil) ⇒ Object

error == nil => success error == true => success error == false => nop otherwise => failure



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/kitchen_hooks/app.rb', line 139

def self.mark event, type, error=nil
  return if error == false
  error = nil if error == true
  entry = { type: type, event: event }
  entry.merge!(error: error, type: 'failure') if error
  db.lock do
    db[Time.now.to_f] = entry
  end
  db.flush
  $stderr.puts '*********************************************'
  $stderr.puts '#############################################'
  $stderr.puts 'MARK "%s": event=%s error=%s' % [
    type, event.inspect, error.inspect
  ]
  $stderr.puts '#############################################'
  $stderr.puts '*********************************************'
  notify entry
end

.not_deleted?(event) ⇒ Boolean

Returns:

  • (Boolean)


484
485
486
# File 'lib/kitchen_hooks/helpers.rb', line 484

def self.not_deleted? event
  event['after'] != '0000000000000000000000000000000000000000'
end

.notification(entry) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/kitchen_hooks/helpers.rb', line 370

def self.notification entry
  return entry[:error] if entry[:error]
  event = entry[:event]

  case entry[:type]
  when 'synced', 'unsynced'
    if event.is_a? String
      event
    else
      num_deletions = event[:num_deletions].to_i
      deletions = '%s, ' % pluralize(num_deletions, 'deletion')
      deletions = '' unless num_deletions > 0
      'Synced <b>%d</b> of <b>%d</b> nodes (%s%s elapsed)' % [
        event[:num_successes],
        event[:num_nodes],
        deletions,
        humanize_seconds(event[:elapsed])
      ]
    end
  when 'kitchen upload'
    %Q| <i>#{author(event)}</i> updated <a href="#{gitlab_url(event)}">the Kitchen</a> |
  when 'cookbook upload'
    %Q| <i>#{author(event)}</i> released <a href="#{gitlab_tag_url(event)}">#{tag_name(event)}</a> of <a href="#{gitlab_url(event)}">#{cookbook_name(event)}</a> |
  when 'constraint application'
    %Q| <i>#{author(event)}</i> constrained <a href="#{gitlab_tag_url(event)}">#{tag_name(event)}</a> with <a href="#{gitlab_url(event)}">#{cookbook_name(event)}</a> |
  when 'release'
    %Q| Kitchen Hooks <b>v#{event}</b> released! |
  end.strip
end

.notify(entry) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/kitchen_hooks/app.rb', line 124

def self.notify entry
  color = case entry[:type]
  when 'failure' ; 'red'
  when 'release' ; 'purple'
  when 'unsynced' ; 'yellow'
  else ; 'green'
  end
  hipchat notification(entry), color
end

.perform_constraint_application(event, knives) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/kitchen_hooks/helpers.rb', line 55

def self.perform_constraint_application event, knives
  $stdout.puts 'started perform_constraint_application event=%s, knives=%s' % [
    event['after'], knives.inspect
  ]

  tmp_clone event, :tagged_commit do |clone|
    Dir.chdir clone do

      $stdout.puts 'Applying constraints'
      constraints = lockfile_constraints 'Berksfile.lock'
      environment = tag_name event
      knives.each do |k|
        apply_constraints constraints, environment, k
        verify_constraints constraints, environment, k
      end

    end
  end

  $stdout.puts "finished perform_constraint_application: #{event['after']}"
  return # no error
end

.perform_cookbook_upload(event, knives) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/kitchen_hooks/helpers.rb', line 96

def self.perform_cookbook_upload event, knives
  $stdout.puts 'started perform_cookbook_upload event=%s, knives=%s' % [
    event['after'], knives.inspect
  ]

  tmp_clone event, :tagged_commit do |clone|
    tagged_version = tag_name(event).delete('v')
    cookbook_version = File.read(File.join(clone, 'VERSION')).strip
    unless tagged_version == cookbook_version
      raise 'Tagged version does not match cookbook version'
    end

    berksfile = File.join clone, 'Berksfile'

    if File.exist? berksfile
      $stdout.puts 'Uploading dependencies'
      berks_install berksfile
      knives.each do |knife|
        berks_upload berksfile, knife
      end
    end

    Dir.chdir clone do
      $stdout.puts 'Uploading cookbook'
      begin
        outs = with_each_knife_do "cookbook upload #{cookbook_name event} -o .. --freeze", knives
      rescue
        unless outs =~ /is frozen/ # Ignore frozen cookbooks already uploaded
          raise 'Knife exited unsuccessfully. Check out the Kitchen Hooks logs.'
        end
      end

      $stdout.puts 'Uploading bundled roles, environments, and data bags'
      kitchen_upload knives
    end
  end

  $stdout.puts "finished cookbook_upload: #{event['after']}"
  return # no error
end

.perform_kitchen_upload(event, knives) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kitchen_hooks/helpers.rb', line 79

def self.perform_kitchen_upload event, knives
  return false unless commit_to_master?(event)
  $stdout.puts 'started perform_kitchen_upload event=%s, knives=%s' % [
    event['after'], knives.inspect
  ]

  tmp_clone event, :latest_commit do |clone|
    Dir.chdir clone do
      kitchen_upload knives
    end
  end

  $stdout.puts "finished perform_kitchen_upload: #{event['after']}"
  return # no error
end

.pluralize(n, singular, plural = nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/kitchen_hooks/helpers.rb', line 22

def self.pluralize n, singular, plural=nil
  plural = "#{singular}s" if plural.nil?
  return "no #{plural}" if n.zero?
  return "1 #{singular}" if n == 1
  "#{n} #{plural}"
end

.process(event) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/kitchen_hooks/app.rb', line 179

def self.process event
  if event.nil? # JSON parse failed
    mark event, 'failure', 'Could not parse WebHook payload'
    return
  end

  if commit_to_kitchen?(event)
    possible_error = begin
      perform_kitchen_upload event, knives
    rescue Exception => e
      report_error e, 'Could not perform kitchen upload: <i>%s</i>' % e.message.lines.first
    end
    mark event, 'kitchen upload', possible_error
  end

  if tagged_commit_to_cookbook?(event) &&
     tag_name(event) =~ /^v\d+/ # Cookbooks tagged with a version
    possible_error = begin
      perform_cookbook_upload event, knives
    rescue Exception => e
      report_error e, 'Could not perform cookbook upload: <i>%s</i>' % e.message.lines.first
    end
    mark event, 'cookbook upload', possible_error
  end

  if tagged_commit_to_realm?(event) &&
     tag_name(event) =~ /^bjn_/ # Realms tagged with an environment
    possible_error = begin
      perform_constraint_application event, knives
    rescue Exception => e
      report_error e, 'Could not apply constraints: <i>%s</i>' % e.message.lines.first
    end
    mark event, 'constraint application', possible_error
  end
end

.process_release(version = KitchenHooks::VERSION) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/kitchen_hooks/app.rb', line 159

def self.process_release version=KitchenHooks::VERSION
  return if db['meta_version'] == version
  db.lock do
    db.set! 'meta_version', version
  end
  mark version, 'release'
end

.process_syncObject



168
169
170
171
172
173
174
175
176
# File 'lib/kitchen_hooks/app.rb', line 168

def self.process_sync
  db!
  sync_servers = SyncServers.new knives
  sync = sync_servers.status
  puts 'Sync completed'
  sync_tag = sync[:num_failures].zero? ? 'synced' : 'unsynced'
  mark sync, sync_tag
  db!
end

.push_details(event) ⇒ Object



413
414
415
416
417
418
# File 'lib/kitchen_hooks/helpers.rb', line 413

def self.push_details event
  return if event.nil?
  %Q|
    <a href="#{gitlab_url(event)}">#{event['after']}</a> to <a href="#{repo_url(event)}">#{repo_name(event)}</a>
  |.strip
end

.repo_name(event) ⇒ Object



426
427
428
# File 'lib/kitchen_hooks/helpers.rb', line 426

def self.repo_name event
  File::basename event['repository']['url'], '.git'
end

.repo_url(event) ⇒ Object



441
442
443
# File 'lib/kitchen_hooks/helpers.rb', line 441

def self.repo_url event
  git_daemon_style_url(event).sub(/^git/, 'http').sub(/\.git$/, '')
end

.report_error(e, msg = nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/kitchen_hooks/helpers.rb', line 45

def self.report_error e, msg=nil
  msg = e.message if msg.nil?
  $stdout.puts msg
  $stdout.puts e.message
  $stdout.puts e.backtrace.inspect
  msg
end

.sync!Object



48
49
50
51
52
53
54
55
56
# File 'lib/kitchen_hooks/app.rb', line 48

def self.sync!
  return if @@sync_interval.nil?
  @@sync_worker = Thread.new do
    loop do
      sleep @@sync_interval
      process_sync
    end
  end
end

.tag_name(event) ⇒ Object



474
475
476
# File 'lib/kitchen_hooks/helpers.rb', line 474

def self.tag_name event
  tagged_commit event
end

.tagged_commit(event) ⇒ Object



468
469
470
471
# File 'lib/kitchen_hooks/helpers.rb', line 468

def self.tagged_commit event
  event['ref'] =~ %r{/tags/(.*)$}
  return $1 # First regex capture
end

.tagged_commit_to_cookbook?(event) ⇒ Boolean

Returns:

  • (Boolean)


494
495
496
497
498
# File 'lib/kitchen_hooks/helpers.rb', line 494

def self.tagged_commit_to_cookbook? event
  cookbook_repo?(event) &&
  event['ref'] =~ %r{/tags/} &&
  not_deleted?(event)
end

.tagged_commit_to_realm?(event) ⇒ Boolean

Returns:

  • (Boolean)


501
502
503
504
# File 'lib/kitchen_hooks/helpers.rb', line 501

def self.tagged_commit_to_realm? event
  tagged_commit_to_cookbook?(event) &&
  repo_name(event) =~ /^realm_/
end

.tmpObject



113
# File 'lib/kitchen_hooks/app.rb', line 113

def self.tmp ; @@tmp ||= '/tmp' end

.tmp!(dir) ⇒ Object



29
# File 'lib/kitchen_hooks/app.rb', line 29

def self.tmp! dir ; @@tmp = dir end

.tmp_clone(event, commit_method) {|dir| ... } ⇒ Object

Yields:

  • (dir)


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/kitchen_hooks/helpers.rb', line 247

def self.tmp_clone event, commit_method, &block
  $stdout.puts 'starting tmp_clone event=%s, commit_method=%s' % [
    event['after'], commit_method.inspect
  ]

  root = File::join tmp, SecureRandom.hex
  dir = File::join root, Time.now.to_f.to_s, cookbook_name(event)
  FileUtils.mkdir_p dir

  repo = Git.clone git_daemon_style_url(event), dir, log: $stdout

  commit = self.send(commit_method, event)

  $stdout.puts 'creating tmp_clone dir=%s, commit=%s' % [
    dir.inspect, commit.inspect
  ]

  repo.checkout commit

  yield dir

  FileUtils.rm_rf root
  $stdout.puts 'finished tmp_clone'
end

.upload_environment(environment, knife) ⇒ Object



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/kitchen_hooks/helpers.rb', line 335

def self.upload_environment environment, knife
  $stdout.puts 'started upload_environment environment=%s, knife=%s' % [
    environment.inspect, knife.inspect
  ]
  # Load the local environment from a JSON file
  local_environment = JSON::parse File.read(environment)
  local_environment.delete 'chef_type'
  local_environment.delete 'json_class'
  local_environment.delete 'cookbook_versions'

  # Load existing environment object on Chef server
  Celluloid.logger = nil
  ridley = Ridley::from_chef_config knife
  chef_environment = ridley.environment.find(local_environment['name'])

  # Create environment object if it doesn't exist
  if chef_environment.nil?
    chef_environment = ridley.environment.create(local_environment)
  end

  # Merge the local environment into the existing object
  local_environment.each do |k, v|
    chef_environment.send "#{k}=".to_sym, v
  end

  # Make it so!
  chef_environment.save
  $stdout.puts 'finished upload_environment: %s' % environment
rescue
  raise 'Could not upload environment, check your syntax'
end

.verify_constraints(constraints, environment, knife) ⇒ Object



294
295
296
297
298
299
300
301
302
303
# File 'lib/kitchen_hooks/helpers.rb', line 294

def self.verify_constraints constraints, environment, knife
  $stdout.puts 'started verify_constraints environment=%s, knife=%s' % [
    environment.inspect, knife.inspect
  ]
  chef_environment = get_environment environment, knife
  unless constraints == chef_environment.cookbook_versions
    raise 'Environment did not match constraints'
  end
  $stdout.puts 'finished verify_constraints: %s' % environment
end

.with_each_knife(command, knives) ⇒ Object



277
278
279
280
281
282
283
284
285
# File 'lib/kitchen_hooks/helpers.rb', line 277

def self.with_each_knife command, knives
  knives.map do |k|
    cmd = "#{command} 2>&1" % { knife: Shellwords::escape(k) }
    $stdout.puts 'with_each_knife: %s' % cmd
    out = system cmd
    raise out unless $?.exitstatus.zero?
    out
  end
end

.with_each_knife_do(command, knives) ⇒ Object



273
274
275
# File 'lib/kitchen_hooks/helpers.rb', line 273

def self.with_each_knife_do command, knives
  with_each_knife "knife #{command} --config %{knife}", knives
end

Instance Method Details

#generic_details(e) ⇒ Object



401
# File 'lib/kitchen_hooks/helpers.rb', line 401

def generic_details e ; App.generic_details e end

#notification(e) ⇒ Object



368
# File 'lib/kitchen_hooks/helpers.rb', line 368

def notification e ; App.notification e end

#push_details(e) ⇒ Object



411
# File 'lib/kitchen_hooks/helpers.rb', line 411

def push_details e ; App.push_details e end