Class: Vagabond::Kitchen

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

included

Constructor Details

#initialize(*args) ⇒ Kitchen

Returns a new instance of Kitchen.



30
31
32
# File 'lib/vagabond/kitchen.rb', line 30

def initialize(*args)
  super
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



28
29
30
# File 'lib/vagabond/kitchen.rb', line 28

def action
  @action
end

#kitchenObject (readonly)

Returns the value of attribute kitchen.



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

def kitchen
  @kitchen
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/vagabond/kitchen.rb', line 27

def name
  @name
end

#uiObject (readonly)

Returns the value of attribute ui.



26
27
28
# File 'lib/vagabond/kitchen.rb', line 26

def ui
  @ui
end

#vagabondfileObject (readonly)

Returns the value of attribute vagabondfile.



25
26
27
# File 'lib/vagabond/kitchen.rb', line 25

def vagabondfile
  @vagabondfile
end

Class Method Details

.basenameObject



16
17
18
# File 'lib/vagabond/kitchen.rb', line 16

def basename
  'vagabond kitchen'
end

Instance Method Details

#teardown(cookbook) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/vagabond/kitchen.rb', line 43

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

#test(cookbook) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
# File 'lib/vagabond/kitchen.rb', line 77

def test(cookbook)
  setup(cookbook, :test)
  ui.info "#{ui.color('Vagabond:', :bold)} - Kitchen testing for cookbook #{ui.color(name, :cyan)}"
  results = Mash.new
  platforms = [options[:platform] || platform_map.keys].flatten
  if(options[:cluster])
    ui.info ui.color("  -> Cluster Testing #{options[:cluster]}!", :yellow)
    if(kitchen[:clusters].nil? || kitchen[:clusters][options[:cluster]].nil?)
      ui.fatal "Requested cluster is not defined: #{options[:cluster]}"
      exit EXIT_CODES[:cluster_invalid]
    end
    serv = Server.new
    serv.options = options
    serv.auto_upload # upload everything : make optional?
    suites = kitchen[:clusters][options[:cluster]]
    platforms.each do |platform|
      %w(local_server_provision test destroy).each do |action|
        suites.each do |suite_name|
          res = self.send("#{action}_node", platform, suite_name)
          if(action == 'test')
            results[platform] ||=[]
            results[platform] << {
              :suite_name => suite_name,
              :result => res
            }
          end
        end
      end
    end
  else
    suites = options[:suites] ? options[:suites].split(',') : ['default']
    platforms.each do |platform|
      suites.each do |suite_name|
        provision_node(platform, suite_name)
        results[platform] ||= []
        results[platform] << {
          :suite_name => suite_name,
          :result => test_node(platform, suite_name)
        }
        destroy_node(platform, suite_name)
      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|
      ui.info "    Suite: #{res[:suite_name]} -> #{res[:result] ? ui.color('SUCCESS!', :green) : ui.color('FAILED!', :red)}"
    end
  end
end