spec/appliance-spec.rb in boxgrinder-build-0.6.4 vs spec/appliance-spec.rb in boxgrinder-build-0.6.5
- old
+ new
@@ -16,19 +16,18 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
require 'rubygems'
require 'boxgrinder-build/appliance'
-#require 'rspec/rspec-config-helper'
require 'ostruct'
require 'logger'
module BoxGrinder
describe Appliance do
def prepare_appliance(options = OpenStruct.new)
- options.name = 'boxgrinder'
- options.version = '1.0'
+ options.name = 'boxgrinder'
+ options.version = '1.0'
@options = options
@log = Logger.new('/dev/null')
@plugin_manager = mock(PluginManager)
@@ -48,20 +47,20 @@
@appliance_config.stub!(:release).and_return(0)
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '11'}))
@appliance_config.stub!(:hardware).and_return(
OpenCascade.new({
- :partitions =>
- {
- '/' => {'size' => 2},
- '/home' => {'size' => 3},
- },
- :arch => 'i686',
- :base_arch => 'i386',
- :cpus => 1,
- :memory => 256,
- })
+ :partitions =>
+ {
+ '/' => {'size' => 2},
+ '/home' => {'size' => 3},
+ },
+ :arch => 'i686',
+ :base_arch => 'i386',
+ :cpus => 1,
+ :memory => 256,
+ })
)
@appliance_config
end
@@ -75,11 +74,12 @@
plugin_helper = mock(PluginHelper)
plugin_helper.should_receive(:load_plugins)
PluginHelper.should_receive(:new).with(:options => @options, :log => @log).and_return(plugin_helper)
- @appliance.should_receive(:read_and_validate_definition)
+ @appliance.should_receive(:read_definition)
+ @appliance.should_receive(:validate_definition)
@appliance.should_not_receive(:remove_old_builds)
@appliance.should_receive(:execute_plugin_chain)
@appliance.create
end
@@ -90,18 +90,19 @@
plugin_helper = mock(PluginHelper)
plugin_helper.should_receive(:load_plugins)
PluginHelper.should_receive(:new).with(:options => @options, :log => @log).and_return(plugin_helper)
- @appliance.should_receive(:read_and_validate_definition)
+ @appliance.should_receive(:read_definition)
+ @appliance.should_receive(:validate_definition)
@appliance.should_receive(:remove_old_builds)
@appliance.should_receive(:execute_plugin_chain)
@appliance.create
end
- it "should read and validate definition" do
+ it "should read definition" do
prepare_appliance
appliance_config = ApplianceConfig.new
appliance_helper = mock(ApplianceHelper)
@@ -117,16 +118,102 @@
appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config)
ApplianceConfigHelper.should_receive(:new).with({}).and_return(appliance_config_helper)
- appliance_config_validator = mock(ApplianceConfigValidator)
- appliance_config_validator.should_receive(:validate)
+ @appliance.read_definition
+ end
- ApplianceConfigValidator.should_receive(:new).with(appliance_config).and_return(appliance_config_validator)
+ describe ".validate_definition" do
+ it "should validate definition and pass" do
+ prepare_appliance
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
- @appliance.read_and_validate_definition
+ appliance_config_validator = mock(ApplianceConfigValidator)
+ appliance_config_validator.should_receive(:validate)
+
+ ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
+
+ puts @appliance_config
+
+ plugin_manager = mock(PluginManager)
+ plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}}})
+
+ PluginManager.stub!(:instance).and_return(plugin_manager)
+
+ @appliance.validate_definition
+ end
+
+ it "should validate definition and fail because no operating system plugins are installed" do
+ prepare_appliance
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
+
+ appliance_config_validator = mock(ApplianceConfigValidator)
+ appliance_config_validator.should_receive(:validate)
+
+ ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
+
+ plugin_manager = mock(PluginManager)
+ plugin_manager.stub!(:plugins).and_return({:os => {}})
+
+ PluginManager.stub!(:instance).and_return(plugin_manager)
+
+ begin
+ @appliance.validate_definition
+ raise "Shouldn't raise"
+ rescue => e
+ e.message.should == "No operating system plugins installed. Install one or more operating system plugin. See http://community.jboss.org/docs/DOC-15081 and http://community.jboss.org/docs/DOC-15214 for more info"
+ end
+ end
+
+ it "should validate definition and fail because no supported operating system plugins is installed" do
+ prepare_appliance
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
+
+ appliance_config_validator = mock(ApplianceConfigValidator)
+ appliance_config_validator.should_receive(:validate)
+
+ ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
+
+ puts @appliance_config
+
+ plugin_manager = mock(PluginManager)
+ plugin_manager.stub!(:plugins).and_return({:os => {:rhel => {}}})
+
+ PluginManager.stub!(:instance).and_return(plugin_manager)
+
+ begin
+ @appliance.validate_definition
+ raise "Shouldn't raise"
+ rescue => e
+ e.message.should == "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: rhel"
+ end
+ end
+
+ it "should validate definition and fail because no supported operating system version plugins is installed" do
+ prepare_appliance
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
+
+ appliance_config_validator = mock(ApplianceConfigValidator)
+ appliance_config_validator.should_receive(:validate)
+
+ ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
+
+ puts @appliance_config
+
+ plugin_manager = mock(PluginManager)
+ plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["xyz"]}}})
+
+ PluginManager.stub!(:instance).and_return(plugin_manager)
+
+ begin
+ @appliance.validate_definition
+ raise "Shouldn't raise"
+ rescue => e
+ e.message.should == "Not supported operating system version selected: 11. Supported versions are: xyz"
+ end
+ end
end
it "should remove old builds" do
prepare_appliance
@@ -145,11 +232,11 @@
os_plugin.should_receive(:deliverables_exists?).and_return(false)
os_plugin.should_receive(:run)
os_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
@plugin_manager.should_receive(:plugins).and_return({:os => "something"})
- @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
+ @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
@appliance.execute_plugin_chain
end
it "should not build base appliance because deliverable already exists" do
@@ -162,11 +249,11 @@
os_plugin.should_receive(:deliverables_exists?).and_return(true)
os_plugin.should_not_receive(:run)
os_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
@plugin_manager.should_receive(:plugins).and_return({:os => "something"})
- @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
+ @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
@appliance.execute_plugin_chain
end
it "should build appliance and convert it to VMware format" do
@@ -180,11 +267,11 @@
platform_plugin.should_receive(:deliverables_exists?).and_return(false)
platform_plugin.should_receive(:run)
platform_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
@plugin_manager.should_receive(:plugins).and_return({:platform => "something"})
- @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
+ @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
@appliance.execute_plugin_chain
end
it "should build appliance and convert it to VMware format because deliverable already exists" do
@@ -198,11 +285,11 @@
platform_plugin.should_receive(:deliverables_exists?).and_return(true)
platform_plugin.should_not_receive(:run)
platform_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
@plugin_manager.should_receive(:plugins).and_return({:platform => "something"})
- @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
+ @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
@appliance.execute_plugin_chain
end
it "should build appliance, convert it to EC2 format and deliver it using S3 ami type" do
@@ -215,11 +302,11 @@
delivery_plugin = mock('S3 Plugin')
delivery_plugin.should_receive(:init)
delivery_plugin.should_receive(:run).with(:ami)
@plugin_manager.should_receive(:plugins).and_return({:delivery => "something"})
- @plugin_manager.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]}])
+ @plugin_manager.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]}])
@appliance.execute_plugin_chain
end
it "should build appliance, convert it to EC2 format and deliver it using delivery plugin with only one delivery type" do
@@ -232,10 +319,10 @@
delivery_plugin = mock('S3 Plugin')
delivery_plugin.should_receive(:init)
delivery_plugin.should_receive(:run).with(:same)
@plugin_manager.should_receive(:plugins).and_return({:delivery => "something"})
- @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :same).and_return([delivery_plugin, {:class => Appliance, :type => :delivery, :name => :same, :full_name => "A plugin"}])
+ @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :same).and_return([delivery_plugin, {:class => Appliance, :type => :delivery, :name => :same, :full_name => "A plugin"}])
@appliance.execute_plugin_chain
end
end
end