Class: Kitchen::LifecycleHook::Local

Inherits:
Base
  • Object
show all
Includes:
Kitchen::Logging, ShellOut
Defined in:
lib/kitchen/lifecycle_hook/local.rb

Instance Attribute Summary

Attributes inherited from Base

#hook, #lifecycle_hooks, #phase

Instance Method Summary collapse

Methods included from Kitchen::Logging

#banner, #debug, #error, #fatal, #info, #warn

Methods included from ShellOut

#run_command

Methods inherited from Base

#initialize, #logger, #should_run?

Constructor Details

This class inherits a constructor from Kitchen::LifecycleHook::Base

Instance Method Details

#runvoid

This method returns an undefined value.

Execute a specific local command hook.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kitchen/lifecycle_hook/local.rb', line 14

def run
  state = state_file.read
  # set up empty user variable
  user = {}
  # Set up some environment variables with instance info.
  environment = {
    "KITCHEN_INSTANCE_NAME" => instance.name,
    "KITCHEN_SUITE_NAME" => instance.suite.name,
    "KITCHEN_PLATFORM_NAME" => instance.platform.name,
    "KITCHEN_INSTANCE_HOSTNAME" => state[:hostname].to_s,
  }
  # If the user specified env vars too, fix them up because symbol keys
  # make mixlib-shellout sad.
  hook[:environment]&.each do |k, v|
    environment[k.to_s] = v.to_s
  end

  # add user to user hash for later merging
  user[:user] = hook[:user] if hook[:user]

  # Default the cwd to the kitchen root and resolve a relative input cwd against that.
  cwd = if hook[:cwd]
          File.expand_path(hook[:cwd], config[:kitchen_root])
        else
          config[:kitchen_root]
        end
  # Build the options for mixlib-shellout.
  opts = {}.merge(user).merge(cwd: cwd, environment: environment)
  run_command(command, opts)
end