Class: Vagabond::Kitchen

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions, Actions::SSH, Actions::Status, Helpers
Defined in:
lib/vagabond/kitchen.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions::SSH

#_ssh

Methods included from Actions::Status

#_status, included

Methods included from Helpers

included

Constructor Details

#initialize(*args) ⇒ Kitchen

Returns a new instance of Kitchen.



41
42
43
# File 'lib/vagabond/kitchen.rb', line 41

def initialize(*args)
  super
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



38
39
40
# File 'lib/vagabond/kitchen.rb', line 38

def action
  @action
end

#internal_configObject (readonly)

Returns the value of attribute internal_config.



39
40
41
# File 'lib/vagabond/kitchen.rb', line 39

def internal_config
  @internal_config
end

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/vagabond/kitchen.rb', line 37

def name
  @name
end

#uiObject (readonly)

Returns the value of attribute ui.



36
37
38
# File 'lib/vagabond/kitchen.rb', line 36

def ui
  @ui
end

#vagabondfileObject (readonly)

Returns the value of attribute vagabondfile.



35
36
37
# File 'lib/vagabond/kitchen.rb', line 35

def vagabondfile
  @vagabondfile
end

Class Method Details

.basenameObject



22
23
24
# File 'lib/vagabond/kitchen.rb', line 22

def basename
  'vagabond kitchen'
end

Instance Method Details

#status(name = nil) ⇒ Object



188
189
190
191
# File 'lib/vagabond/kitchen.rb', line 188

def status(name=nil)
  setup(name, :status)
  _status
end

#teardown(cookbook = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vagabond/kitchen.rb', line 54

def teardown(cookbook=nil)
  setup(cookbook, :teardown)
  ui.info "#{ui.color('Vagabond:', :bold)} - Kitchen teardown for cookbook #{ui.color(name, :red)}"
  plats = [options[:platform] || platform_map.keys].flatten
  plats.each do |plat|
    validate_platform!(plat)
    ui.info ui.color("  -> Tearing down platform: #{plat}", :red)
    kitchen.suites.map(&:name).each do |suite|
      inst = vagabond_instance(:destroy, plat, :suite_name => suite)
      inst.destroy
    end
    ui.info ui.color("  -> Teardown of platform: #{plat} - COMPLETE!", :red)
  end
end

#test(*args) ⇒ Object

Raises:

  • (VagabondError::KitchenTestFailed)


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
136
137
138
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/vagabond/kitchen.rb', line 97

def test(*args)
  cookbook = args.first
  setup(cookbook, :test)

  ui.info "#{ui.color('Vagabond:', :bold)} - Kitchen testing for cookbook #{ui.color(name, :cyan)}"
  platforms = [options[:platform] || platform_map.keys].flatten
  @results = Mash[*platforms.zip([[]] * platforms.size).flatten(1)]
  if(cluster_name = options.delete(:cluster))
    ui.info ui.color("  -> Cluster Testing #{cluster_name}!", :yellow)
    if(kitchen.clusters.empty? || kitchen.clusters[cluster_name].nil?)
      ui.fatal "Requested cluster is not defined: #{options[:cluster]}"
      raise VagabondError::ClusterInvalid.new(cluster_name)
    end

    setup_server_if_needed

    suites = kitchen.clusters[cluster_name]
    platforms.each do |platform|
      begin
        suites.each do |suite_name|
          unless(local_server_provision_node(platform, suite_name))
            ui.error "Failed to provision #{suite_name} in platform #{platform}"
            @results[platform] << {
              :suite_name => suite_name,
              :result => false
            }
            raise VagabondError::HostProvisionFailed.new("#{platform}[#{suite_name}]")
          end
        end
        suites.each do |suite_name|
          @results[platform] << {
            :suite_name => suite_name,
            :result => test_node(platform, suite_name)
          }
        end
      rescue VagabondError::HostProvisionFailed => e
        debug("Caught failed provision error. Scrubbing nodes. - #{e}")
      ensure
        suites.each do |suite_name|
          destroy_node(platform, suite_name)
        end
      end
    end

    destroy_server_if_needed
  else
    load_cookbooks
    suites = options[:suites] ? options[:suites].split(',') : kitchen.suites.map(&:name)
    runners = []
    platforms.each do |platform|
      suites.each do |suite_name|
        runner = lambda do
          begin
            provision_node(platform, suite_name)
            @results[platform] << {
              :suite_name => suite_name,
              :result => test_node(platform, suite_name)
            }
          ensure
            destroy_node(platform, suite_name)
          end
        end
        if(options[:parallel])
          runners << Thread.new{ runner.call }
        else
          runner.call
        end
      end
    end
    if(options[:parallel])
      until(runners.empty?)
        runners.each do |runner|
          runner.join
          runners.delete(runner)
        end
      end
    end
  end
  ui.info ui.color('Kitchen Test Results:', :bold)
  @results.each do |platform, infos|
    ui.info "  Platform: #{ui.color(platform, :blue, :bold)}"
    infos.each do |res|
      res_out = res[:result] ? ui.color('SUCCESS!', :green) : ui.color('FAILED!', :red)
      res_out = ui.color('No tests', :blue) if res[:result] == :no_tests
      ui.info "    Suite: #{res[:suite_name]} -> #{res_out}"
    end
  end
  raise VagabondError::KitchenTestFailed.new(@results.values.flatten.map{|res| res[:suite_name] unless res[:result]}.compact)
end