boxgrinder-build 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/CHANGELOG +7 -0
  2. data/Manifest +0 -0
  3. data/Rakefile +11 -0
  4. data/bin/boxgrinder-build +33 -27
  5. data/boxgrinder-build.gemspec +38 -0
  6. data/lib/boxgrinder-build/appliance.rb +32 -41
  7. data/lib/boxgrinder-build/helpers/appliance-customize-helper.rb +3 -48
  8. data/lib/boxgrinder-build/helpers/guestfs-helper.rb +98 -12
  9. data/lib/boxgrinder-build/helpers/linux-helper.rb +69 -0
  10. data/lib/boxgrinder-build/helpers/package-helper.rb +20 -11
  11. data/lib/boxgrinder-build/helpers/plugin-helper.rb +32 -32
  12. data/lib/boxgrinder-build/managers/plugin-manager.rb +98 -0
  13. data/lib/boxgrinder-build/plugins/base-plugin.rb +70 -17
  14. data/spec/Rakefile +13 -0
  15. data/spec/appliance-spec.rb +195 -0
  16. data/spec/helpers/appliance-customize-helper-spec.rb +30 -0
  17. data/spec/helpers/guestfs-helper-spec.rb +129 -0
  18. data/spec/helpers/linux-helper-spec.rb +50 -0
  19. data/spec/helpers/package-helper-spec.rb +6 -0
  20. data/spec/helpers/plugin-helper-spec.rb +63 -0
  21. data/spec/managers/plugin-manager-spec.rb +27 -0
  22. data/spec/plugins/base-plugin-spec.rb +89 -0
  23. data/spec/rspec/src/appliances/jeos-f13.appl +27 -0
  24. metadata +60 -157
  25. data/docs/examples/appliances/appliances.appl +0 -5
  26. data/docs/examples/appliances/minimal.appl +0 -9
  27. data/docs/examples/appliances/mix.appl +0 -8
  28. data/docs/examples/appliances/packages.appl +0 -13
  29. data/docs/node-info/pom.xml +0 -31
  30. data/docs/node-info/src/main/webapp/META-INF/MANIFEST.MF +0 -3
  31. data/docs/node-info/src/main/webapp/WEB-INF/web.xml +0 -7
  32. data/docs/node-info/src/main/webapp/index.jsp +0 -70
  33. data/lib/boxgrinder-build/helpers/rake-helper.rb +0 -71
  34. data/lib/boxgrinder-build/managers/base-plugin-manager.rb +0 -62
  35. data/lib/boxgrinder-build/managers/delivery-plugin-manager.rb +0 -39
  36. data/lib/boxgrinder-build/managers/operating-system-plugin-manager.rb +0 -6
  37. data/lib/boxgrinder-build/managers/platform-plugin-manager.rb +0 -26
  38. data/lib/boxgrinder-build/plugins/delivery/base/base-delivery-plugin.rb +0 -43
  39. data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +0 -57
  40. data/lib/boxgrinder-build/plugins/delivery/s3/aws-helper.rb +0 -64
  41. data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +0 -190
  42. data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +0 -159
  43. data/lib/boxgrinder-build/plugins/os/base/kickstart.rb +0 -148
  44. data/lib/boxgrinder-build/plugins/os/base/rhel-based-os-plugin.rb +0 -51
  45. data/lib/boxgrinder-build/plugins/os/base/rpm-based-os-plugin.rb +0 -134
  46. data/lib/boxgrinder-build/plugins/os/base/src/appliance.ks.erb +0 -41
  47. data/lib/boxgrinder-build/plugins/os/base/src/base.repo +0 -4
  48. data/lib/boxgrinder-build/plugins/os/base/src/motd.init +0 -21
  49. data/lib/boxgrinder-build/plugins/os/base/validators/rpm-dependency-validator.rb +0 -162
  50. data/lib/boxgrinder-build/plugins/os/base-operating-system-plugin.rb +0 -37
  51. data/lib/boxgrinder-build/plugins/os/centos/centos-plugin.rb +0 -52
  52. data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +0 -74
  53. data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +0 -40
  54. data/lib/boxgrinder-build/plugins/platform/base-platform-plugin.rb +0 -37
  55. data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +0 -332
  56. data/lib/boxgrinder-build/plugins/platform/ec2/src/f12/yum.conf +0 -24
  57. data/lib/boxgrinder-build/plugins/platform/ec2/src/f12-i386-boxgrinder.repo +0 -11
  58. data/lib/boxgrinder-build/plugins/platform/ec2/src/f12-x86_64-boxgrinder.repo +0 -11
  59. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_32bit +0 -8
  60. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_64bit +0 -8
  61. data/lib/boxgrinder-build/plugins/platform/ec2/src/ifcfg-eth0 +0 -7
  62. data/lib/boxgrinder-build/plugins/platform/ec2/src/rc_local +0 -29
  63. data/lib/boxgrinder-build/plugins/platform/vmware/src/README +0 -42
  64. data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmdk +0 -19
  65. data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmx +0 -45
  66. data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +0 -181
  67. data/lib/boxgrinder-build/validators/appliance-config-parameter-validator.rb +0 -37
  68. data/lib/boxgrinder-build/validators/appliance-validator.rb +0 -84
  69. data/lib/boxgrinder-build/validators/config-validator.rb +0 -48
  70. data/lib/boxgrinder-build/validators/ssh-validator.rb +0 -35
  71. data/lib/boxgrinder-build/validators/validator.rb +0 -91
@@ -18,22 +18,22 @@
18
18
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
19
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
20
 
21
- require 'boxgrinder-build/managers/operating-system-plugin-manager'
22
- require 'boxgrinder-build/managers/platform-plugin-manager'
23
- require 'boxgrinder-build/managers/delivery-plugin-manager'
21
+ require 'boxgrinder-build/managers/plugin-manager'
22
+ require 'rubygems'
24
23
 
25
24
  module BoxGrinder
26
25
  class PluginHelper
27
26
  def initialize( options = {} )
28
- @log = options[:log] || Logger.new(STDOUT)
27
+ @log = options[:log] || Logger.new(STDOUT)
28
+ @options = options[:options]
29
29
  end
30
30
 
31
31
  def load_plugins
32
- Dir["#{File.dirname( __FILE__ )}/../plugins/**/*-plugin.rb"].each { |file| require "boxgrinder-build/plugins/#{file.scan(/\/plugins\/(.*)\.rb$/).to_s}" }
32
+ read_and_require
33
33
 
34
- @os_plugins = OperatingSystemPluginManager.instance.initialize_plugins( :log => @log ).plugins
35
- @platform_plugins = PlatformPluginManager.instance.initialize_plugins( :log => @log ).plugins
36
- @delivery_plugins = DeliveryPluginManager.instance.initialize_plugins( :log => @log ).plugins
34
+ @os_plugins = PluginManager.instance.plugins[:os]
35
+ @platform_plugins = PluginManager.instance.plugins[:platform]
36
+ @delivery_plugins = PluginManager.instance.plugins[:delivery]
37
37
 
38
38
  print_plugins( 'os' ) { @os_plugins }
39
39
  print_plugins( 'platform' ) { @platform_plugins }
@@ -42,44 +42,44 @@ module BoxGrinder
42
42
  self
43
43
  end
44
44
 
45
- def print_plugins( type )
46
- @log.debug "Loading #{type} plugins..."
47
-
48
- plugins = yield
45
+ def parse_plugin_list
46
+ plugins = []
49
47
 
50
- @log.debug "We have #{plugins.size} #{type} plugin(s) registered"
51
-
52
- plugins.each_value do |plugin|
53
- @log.debug "- plugin for #{plugin.info[:full_name]}."
48
+ unless @options.plugins.nil?
49
+ plugins = @options.plugins.gsub('\'', '').gsub('"', '').split(',')
50
+ plugins.each { |plugin| plugin.chomp!; plugin.strip! }
54
51
  end
55
52
 
56
- @log.debug "Plugins loaded."
53
+ plugins
57
54
  end
58
55
 
59
- def deliverables_exists?( deliverables )
60
- return false unless File.exists?(deliverables[:disk])
56
+ def read_and_require
57
+ plugins = %w(boxgrinder-build-fedora-os-plugin boxgrinder-build-rhel-os-plugin boxgrinder-build-centos-os-plugin boxgrinder-build-ec2-platform-plugin boxgrinder-build-vmware-platform-plugin boxgrinder-build-s3-delivery-plugin boxgrinder-build-sftp-delivery-plugin boxgrinder-build-local-delivery-plugin) + parse_plugin_list
58
+
59
+ plugins.flatten.each do |plugin|
60
+ @log.trace "Requiring plugin '#{plugin}'..."
61
61
 
62
- [:metadata, :other].each do |deliverable_type|
63
- deliverables[deliverable_type].each_value do |file|
64
- return false unless File.exists?(file)
62
+ begin
63
+ gem plugin
64
+ require plugin
65
+ rescue Gem::LoadError
66
+ @log.warn "Specified gem: '#{plugin}' wasn't found. Make sure its name is correct, skipping..." unless plugin.match(/^boxgrinder-build-(.*)-plugin/)
65
67
  end
66
68
  end
67
-
68
- true
69
69
  end
70
70
 
71
- def deliverables_array( deliverables )
72
- files = []
71
+ def print_plugins( type )
72
+ @log.debug "Loading #{type} plugins..."
73
+
74
+ plugins = yield
73
75
 
74
- files << deliverables[:disk]
76
+ @log.debug "We have #{plugins.size} #{type} plugin(s) registered"
75
77
 
76
- [:metadata, :other].each do |deliverable_type|
77
- deliverables[deliverable_type].each_value do |file|
78
- file << file
79
- end
78
+ plugins.each do |plugin_name_or_type, plugin_info|
79
+ @log.debug "- #{plugin_name_or_type} plugin for #{plugin_info[:full_name]}."
80
80
  end
81
81
 
82
- files
82
+ @log.debug "Plugins loaded."
83
83
  end
84
84
 
85
85
  attr_reader :os_plugins
@@ -0,0 +1,98 @@
1
+ # JBoss, Home of Professional Open Source
2
+ # Copyright 2009, Red Hat Middleware LLC, and individual contributors
3
+ # by the @authors tag. See the copyright.txt in the distribution for a
4
+ # full listing of individual contributors.
5
+ #
6
+ # This is free software; you can redistribute it and/or modify it
7
+ # under the terms of the GNU Lesser General Public License as
8
+ # published by the Free Software Foundation; either version 2.1 of
9
+ # the License, or (at your option) any later version.
10
+ #
11
+ # This software is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this software; if not, write to the Free
18
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
+
21
+ require 'singleton'
22
+
23
+ module BoxGrinder
24
+ module Plugins
25
+ def plugin( args )
26
+ PluginManager.instance.register_plugin( args )
27
+ end
28
+ end
29
+ end
30
+
31
+ include BoxGrinder::Plugins
32
+
33
+ # TODO consider removing singleton pattern
34
+ module BoxGrinder
35
+ class PluginManager
36
+ include Singleton
37
+
38
+ def initialize
39
+ @plugins = { :delivery => {}, :os => {}, :platform => {}}
40
+ end
41
+
42
+ def register_plugin( info )
43
+ validate_plugin_info( info )
44
+
45
+ raise "We already have registered plugin for #{info[:name]}." unless @plugins[info[:name]].nil?
46
+
47
+ unless info[:types].nil?
48
+ info[:types].each do |type|
49
+ @plugins[info[:type]][type] = info
50
+ end
51
+ else
52
+ @plugins[info[:type]][info[:name]] = info
53
+ end
54
+
55
+ self
56
+ end
57
+
58
+ def validate_plugin_info( info )
59
+ raise "No name specified for your plugin" if info[:name].nil?
60
+ raise "No class specified for your plugin" if info[:class].nil?
61
+ raise "No type specified for your plugin" if info[:type].nil?
62
+ end
63
+
64
+ def initialize_plugin( type, name )
65
+ plugins = @plugins[type]
66
+ # this should never happen
67
+ raise "There are no #{type} plugins." if plugins.nil?
68
+ plugin_info = plugins[name]
69
+ raise "There is no #{type} plugin registered for '#{name}' type/name." if plugin_info.nil?
70
+
71
+ begin
72
+ plugin = plugin_info[:class].new
73
+ rescue => e
74
+ raise "Error while initializing #{plugin_info[:class]} plugin.", e
75
+ end
76
+
77
+ [ plugin, plugin_info ]
78
+ end
79
+
80
+ def plugin_types( type )
81
+ types = []
82
+
83
+ available_plugins_for_selected_type = @plugins[type]
84
+
85
+ unless available_plugins_for_selected_type.nil?
86
+ available_plugins_for_selected_type.each_value do |info|
87
+ types << info[:types] unless info[:types].nil?
88
+ types << info[:name]
89
+ end
90
+ end
91
+
92
+ types.flatten
93
+ end
94
+
95
+ attr_reader :plugins
96
+ attr_accessor :log
97
+ end
98
+ end
@@ -19,7 +19,10 @@
19
19
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
20
 
21
21
  require 'boxgrinder-core/helpers/exec-helper'
22
- require 'boxgrinder-build/helpers/plugin-helper'
22
+ require 'boxgrinder-build/helpers/guestfs-helper'
23
+ require 'ostruct'
24
+ require 'openhash/openhash'
25
+ require 'fileutils'
23
26
  require 'logger'
24
27
 
25
28
  module BoxGrinder
@@ -31,28 +34,40 @@ module BoxGrinder
31
34
 
32
35
  @log = options[:log] || Logger.new(STDOUT)
33
36
  @exec_helper = options[:exec_helper] || ExecHelper.new( :log => @log )
34
- @plugin_helper = options[:plugin_helper] || PluginHelper.new( :log => @log )
35
37
 
36
- @plugin_config = {}
37
- @deliverables = Hash.new({})
38
+ @plugin_info = options[:plugin_info]
39
+ @previous_plugin_info = options[:previous_plugin_info]
38
40
 
39
- if self.respond_to?(:info)
40
- @config_file = "#{ENV['HOME']}/.boxgrinder/plugins/#{self.info[:name]}"
41
+ @previous_deliverables = options[:previous_deliverables] || {}
42
+ @plugin_config = {}
41
43
 
42
- read_plugin_config
44
+ @deliverables = OpenHash.new
45
+ @target_deliverables = OpenHash.new
46
+ @dir = OpenHash.new
43
47
 
44
- @deliverables[:disk] = nil
45
- @deliverables[:platform] = self.info[:name]
46
- end
48
+ @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
49
+ @dir.tmp = "#{@dir.base}/tmp"
47
50
 
48
- after_init
51
+ @config_file = "#{ENV['HOME']}/.boxgrinder/plugins/#{@plugin_info[:name]}"
52
+
53
+ read_plugin_config
49
54
 
50
55
  @initialized = true
51
56
 
57
+ after_init
58
+
52
59
  self
53
60
  end
54
61
 
55
- attr_reader :deliverables
62
+ def register_deliverable( deliverable )
63
+ raise "You can only register deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
64
+ raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
65
+
66
+ deliverable.each do |name, path|
67
+ @deliverables[name] = "#{@dir.tmp}/#{path}"
68
+ @target_deliverables[name] = "#{@dir.base}/#{path}"
69
+ end
70
+ end
56
71
 
57
72
  def validate_plugin_config(fields = [], doc = nil)
58
73
  more_info = doc.nil? ? '' : "See #{doc} for more info"
@@ -60,17 +75,54 @@ module BoxGrinder
60
75
  raise "Not valid configuration file for #{info[:name]} plugin. Please create valid '#{@config_file}' file. #{more_info}" if @plugin_config.nil?
61
76
 
62
77
  fields.each do |field|
63
- raise "Please specify a valid #{field} in plugin configuration file: '#{@config_file}'. #{more_info}" if @plugin_config[field].nil?
78
+ raise "Please specify a valid '#{field}' key in plugin configuration file: '#{@config_file}'. #{more_info}" if @plugin_config[field].nil?
64
79
  end
65
80
  end
66
81
 
67
82
  def execute(args = nil)
68
- raise "Execute operation for #{self.class} plugin is not implemented"
83
+ raise "You can only execute the plugin after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
84
+ end
85
+
86
+ def run( *args )
87
+ FileUtils.rm_rf @dir.tmp
88
+ FileUtils.mkdir_p @dir.tmp
89
+
90
+ execute( *args )
91
+
92
+ after_execute
69
93
  end
70
94
 
71
95
  def after_init
72
96
  end
73
97
 
98
+ def after_execute
99
+ @deliverables.each do |name, path|
100
+ @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
101
+ FileUtils.mv( path, @target_deliverables[name] )
102
+ end
103
+
104
+ FileUtils.rm_rf @dir.tmp
105
+ end
106
+
107
+ def deliverables_exists?
108
+ raise "You can only check deliverables after the plugin is initialized, please initialize the plugin using init method." if @initialized.nil?
109
+
110
+ exists = true
111
+
112
+ @target_deliverables.each_value do |file|
113
+ unless File.exists?(file)
114
+ exists = false
115
+ break
116
+ end
117
+ end
118
+
119
+ exists
120
+ end
121
+
122
+ def deliverables
123
+ @target_deliverables
124
+ end
125
+
74
126
  def set_default_config_value(key, value)
75
127
  @plugin_config[key] = @plugin_config[key].nil? ? value : @plugin_config[key]
76
128
  end
@@ -83,14 +135,15 @@ module BoxGrinder
83
135
  begin
84
136
  @plugin_config = YAML.load_file(@config_file)
85
137
  rescue
86
- raise "An error occurred while reading configuration file #{@config_file} for #{self.class.name}. It is a valid YAML file?"
138
+ raise "An error occurred while reading configuration file #{@config_file} for #{self.class.name}. Is it a valid YAML file?"
87
139
  end
88
140
  end
89
141
 
90
- def customize(disk_path)
142
+ # TODO consider removing this from BasePlugin and moving to another base class
143
+ def customize( disk_path )
91
144
  raise "Customizing cannot be started until the plugin isn't initialized" if @initialized.nil?
92
145
 
93
- ApplianceCustomizeHelper.new(@config, @appliance_config, disk_path, :log => @log).customize do |guestfs, guestfs_helper|
146
+ GuestFSHelper.new( disk_path, :log => @log ).customize do |guestfs, guestfs_helper|
94
147
  yield guestfs, guestfs_helper
95
148
  end
96
149
  end
data/spec/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all examples"
5
+ Spec::Rake::SpecTask.new(:default) do |t|
6
+ t.libs.unshift "../../boxgrinder-core/lib"
7
+ t.libs.unshift "../../boxgrinder-core/spec"
8
+
9
+ t.spec_files = FileList['**/*-spec.rb']
10
+ t.rcov = true
11
+ t.rcov_opts = ['--exclude', 'spec' ]
12
+ t.spec_opts = [ '--format', 's']
13
+ end
@@ -0,0 +1,195 @@
1
+ require 'boxgrinder-build/appliance'
2
+ require 'rspec/rspec-config-helper'
3
+ require 'rbconfig'
4
+ require 'ostruct'
5
+
6
+ module BoxGrinder
7
+ describe Appliance do
8
+ include RSpecConfigHelper
9
+
10
+ before(:all) do
11
+ @arch = RbConfig::CONFIG['host_cpu']
12
+ end
13
+
14
+ def prepare_appliance( options = OpenStruct.new )
15
+ options.name = 'boxgrinder'
16
+ options.version = '1.0'
17
+
18
+ @appliance = Appliance.new( "#{File.dirname( __FILE__ )}/rspec/src/appliances/jeos-f13.appl", :log => Logger.new('/dev/null'), :options => options )
19
+ end
20
+
21
+ before(:each) do
22
+ prepare_appliance
23
+ end
24
+
25
+ it "should create only base image" do
26
+ validator = mock(ApplianceConfigValidator)
27
+ validator.should_receive(:validate)
28
+
29
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
30
+
31
+ plugin_manager_first_call = mock('PluginManagerOne')
32
+ plugin_manager_first_call.should_receive(:plugins).and_return({})
33
+
34
+ PluginManager.should_receive(:instance).and_return(plugin_manager_first_call)
35
+
36
+ os_plugin = mock('OS Plugin')
37
+ os_plugin.should_receive(:init)
38
+ os_plugin.should_receive(:deliverables_exists?).and_return(false)
39
+ os_plugin.should_receive(:run)
40
+ os_plugin.should_receive(:deliverables).and_return({ :disk => 'abc'})
41
+
42
+ plugin_manager_second_call = mock('PluginManagerTwo')
43
+ plugin_manager_second_call.should_receive(:initialize_plugin).with(:os, :fedora).and_return([ os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"] } ] )
44
+
45
+ PluginManager.should_receive(:instance).and_return(plugin_manager_second_call)
46
+
47
+ @appliance.create
48
+ end
49
+
50
+ it "should build appliance and convert it to VMware format" do
51
+ prepare_appliance( OpenStruct.new({ :platform => :vmware }) )
52
+
53
+ validator = mock(ApplianceConfigValidator)
54
+ validator.should_receive(:validate)
55
+
56
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
57
+
58
+ os_plugin_output = {}
59
+
60
+ @appliance.should_receive(:execute_os_plugin).and_return(os_plugin_output)
61
+
62
+ plugin_manager_first_call = mock('PluginManagerOne')
63
+ plugin_manager_first_call.should_receive(:plugins).and_return({})
64
+
65
+ PluginManager.should_receive(:instance).and_return(plugin_manager_first_call)
66
+
67
+ platform_plugin = mock('VMware Plugin')
68
+ platform_plugin.should_receive(:init)
69
+ platform_plugin.should_receive(:deliverables_exists?).and_return(false)
70
+ platform_plugin.should_receive(:run)
71
+ platform_plugin.should_receive(:deliverables).and_return({ :disk => 'abc'})
72
+
73
+ plugin_manager_second_call = mock('PluginManagerTwo')
74
+ plugin_manager_second_call.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([ platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"} ] )
75
+
76
+ PluginManager.should_receive(:instance).and_return(plugin_manager_second_call)
77
+
78
+ @appliance.create
79
+ end
80
+
81
+ it "should build appliance, convert it to EC2 format and deliver it using S3 ami type" do
82
+ prepare_appliance( OpenStruct.new({ :platform => :ec2, :delivery => :ami }) )
83
+
84
+ validator = mock(ApplianceConfigValidator)
85
+ validator.should_receive(:validate)
86
+
87
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
88
+
89
+ os_plugin_output = { :abc => 'def'}
90
+ platform_plugin_output = { :abc => 'def'}
91
+
92
+ @appliance.should_receive(:execute_os_plugin).and_return(os_plugin_output)
93
+ @appliance.should_receive(:execute_platform_plugin).and_return(platform_plugin_output)
94
+
95
+ plugin_manager_first_call = mock('PluginManagerOne')
96
+ plugin_manager_first_call.should_receive(:plugins).and_return({})
97
+
98
+ PluginManager.should_receive(:instance).and_return(plugin_manager_first_call)
99
+
100
+ delivery_plugin = mock('S3 Plugin')
101
+ delivery_plugin.should_receive(:init)
102
+ delivery_plugin.should_receive(:run).with(:ami)
103
+
104
+ plugin_manager_second_call = mock('PluginManagerTwo')
105
+ plugin_manager_second_call.should_receive(:initialize_plugin).with(:delivery, :ami).and_return([ delivery_plugin, {:class => Appliance, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]} ] )
106
+
107
+ PluginManager.should_receive(:instance).and_return(plugin_manager_second_call)
108
+
109
+ @appliance.create
110
+ end
111
+ it "should build appliance, convert it to vmware format and deliver it using sftp ami type" do
112
+ prepare_appliance( OpenStruct.new({ :platform => :vmware, :delivery => :sftp }) )
113
+
114
+ validator = mock(ApplianceConfigValidator)
115
+ validator.should_receive(:validate)
116
+
117
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
118
+
119
+ os_plugin_output = { :abc => 'def'}
120
+ platform_plugin_output = { :abc => 'def'}
121
+
122
+ @appliance.should_receive(:execute_os_plugin).and_return(os_plugin_output)
123
+ @appliance.should_receive(:execute_platform_plugin).and_return(platform_plugin_output)
124
+
125
+ plugin_manager_first_call = mock('PluginManagerOne')
126
+ plugin_manager_first_call.should_receive(:plugins).and_return({})
127
+
128
+ PluginManager.should_receive(:instance).and_return(plugin_manager_first_call)
129
+
130
+ delivery_plugin = mock('S3 Plugin')
131
+ delivery_plugin.should_receive(:init)
132
+ delivery_plugin.should_receive(:run).with(no_args)
133
+
134
+ plugin_manager_second_call = mock('PluginManagerTwo')
135
+ plugin_manager_second_call.should_receive(:initialize_plugin).with(:delivery, :sftp).and_return([ delivery_plugin, {:class => Appliance, :type => :delivery, :name => :sftp, :full_name => "SSH File Transfer Protocol"} ] )
136
+
137
+ PluginManager.should_receive(:instance).and_return(plugin_manager_second_call)
138
+
139
+ @appliance.create
140
+ end
141
+
142
+ it "should remove previous build when force is specified" do
143
+ prepare_appliance( OpenStruct.new( :force => true ) )
144
+
145
+ validator = mock(ApplianceConfigValidator)
146
+ validator.should_receive(:validate)
147
+
148
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
149
+
150
+ @appliance.should_receive(:execute_os_plugin).and_return(nil)
151
+ @appliance.should_receive(:execute_platform_plugin).and_return(nil)
152
+ @appliance.should_receive(:execute_delivery_plugin).and_return(nil)
153
+
154
+ FileUtils.should_receive(:rm_rf).with("build/appliances/#{@arch}/fedora/13/jeos-f13")
155
+
156
+ @appliance.create
157
+ end
158
+
159
+ it "should not execute plugins when deliverables exists" do
160
+ prepare_appliance( OpenStruct.new({ :platform => :vmware }) )
161
+
162
+ validator = mock(ApplianceConfigValidator)
163
+ validator.should_receive(:validate)
164
+
165
+ ApplianceConfigValidator.should_receive(:new).with(any_args).and_return(validator)
166
+
167
+ os_plugin = mock('OS Plugin')
168
+ os_plugin.should_receive(:init)
169
+ os_plugin.should_receive(:deliverables_exists?).and_return(true)
170
+ os_plugin.should_receive(:deliverables).and_return({ :disk => 'abc'})
171
+
172
+ plugin_manager_first_call = mock('PluginManagerOne')
173
+ plugin_manager_first_call.should_receive(:plugins).and_return({})
174
+
175
+ PluginManager.should_receive(:instance).and_return(plugin_manager_first_call)
176
+
177
+ plugin_manager_second_call = mock('PluginManagerTwo')
178
+ plugin_manager_second_call.should_receive(:initialize_plugin).with(:os, :fedora).and_return([ os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"] } ] )
179
+
180
+ PluginManager.should_receive(:instance).and_return(plugin_manager_second_call)
181
+
182
+ platform_plugin = mock('Platform Plugin')
183
+ platform_plugin.should_receive(:init)
184
+ platform_plugin.should_receive(:deliverables_exists?).and_return(true)
185
+ platform_plugin.should_receive(:deliverables).and_return({ :disk => 'def'})
186
+
187
+ platform_plugin_manager_second_call = mock('PlatformPluginManagerOne')
188
+ platform_plugin_manager_second_call.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([ platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"} ] )
189
+
190
+ PluginManager.should_receive(:instance).and_return(platform_plugin_manager_second_call)
191
+
192
+ @appliance.create
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,30 @@
1
+ require 'boxgrinder-build/helpers/appliance-customize-helper'
2
+ require 'rspec/rspec-config-helper'
3
+
4
+ module BoxGrinder
5
+ describe ApplianceCustomizeHelper do
6
+ include RSpecConfigHelper
7
+
8
+ before(:each) do
9
+ @helper = ApplianceCustomizeHelper.new(generate_config, generate_appliance_config, 'a/disk', :log => Logger.new('/dev/null'))
10
+
11
+ @log = @helper.instance_variable_get(:@log)
12
+ end
13
+
14
+ it "should properly prepare guestfs for customization" do
15
+
16
+ guestfs_helper = mock('guestfs_helper')
17
+ guestfs = mock('guestfs')
18
+ guestfs_helper.should_receive(:run).and_return(guestfs_helper)
19
+ guestfs_helper.should_receive(:guestfs).and_return(guestfs)
20
+ guestfs_helper.should_receive(:clean_close)
21
+
22
+ GuestFSHelper.should_receive(:new).with('a/disk', :log => @log ).and_return(guestfs_helper)
23
+
24
+ @helper.customize do |gf, gf_helper|
25
+ gf_helper.should == guestfs_helper
26
+ gf.should == guestfs
27
+ end
28
+ end
29
+ end
30
+ end