Permalink
Browse files

[BGBUILD-346] Fixes to enable Ruby 1.9 compatibility:

- Include path changes from 1.8 -> 1.9.
- Fix reliance on undefined behaviour/quirk in 1.8.x bindings
  (Kernel#binding).
  - See: http://bugs.ruby-lang.org/issues/2161
- Ensure boxgrinder-core compat patches are included before we do
  anything meaningful.
- Refactor reliance on string #each with implicit \n splitting.
- Refactor broken specs.
- Refactor weird/fragile/undefined code usage.

[BGBUILD-348] Testing changes and fixes:
- Enable simplecov for spec:coverage >=1.9, yay! Rcov will still run
  for Ruby 1.8.
- Ensures that boxgrinder-core compat patches are included before
  tests are run.
  • Loading branch information...
1 parent f45412e commit af42eb9f2819fddf3eea54a7a2cd3158abedcb74 @msavy msavy committed Feb 11, 2012
View
@@ -40,7 +40,7 @@ desc "Run all integration tests"
RSpec::Core::RakeTask.new('integ') do |t|
t.rcov = false
t.pattern = "integ/**/*-spec.rb"
- t.rspec_opts = ['--colour', '--format', 'doc', '-b']
+ t.rspec_opts = ['-r boxgrinder-core', '--colour', '--format', 'doc', '-b']
t.verbose = true
end
@@ -49,16 +49,26 @@ RSpec::Core::RakeTask.new('spec') do |t|
t.ruby_opts = "-I ../boxgrinder-core/lib"
t.rcov = false
t.pattern = "spec/**/*-spec.rb"
- t.rspec_opts = ['--colour', '--format', 'doc', '-b']
+ t.rspec_opts = ['-r boxgrinder-core', '--colour', '--format', 'doc', '-b']
t.verbose = true
end
-desc "Run all tests and generate code coverage report"
+def coverage18(t)
+ require 'rcov'
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec,teamcity/*,/usr/lib/ruby/,.gem/ruby,/boxgrinder-core/,/gems/']
+end
+
RSpec::Core::RakeTask.new('spec:coverage') do |t|
t.ruby_opts = "-I ../boxgrinder-core/lib"
t.pattern = "spec/**/*-spec.rb"
- t.rspec_opts = ['--colour', '--format', 'html', '--out', 'pkg/rspec_report.html', '-b']
- t.rcov = true
- t.rcov_opts = ['--exclude', 'spec,teamcity/*,/usr/lib/ruby/,.gem/ruby,/boxgrinder-core/,/gems/']
+ t.rspec_opts = ['-r spec_helper', '-r boxgrinder-core', '--colour',
+ '--format', 'html', '--out', 'pkg/rspec_report.html', '-b']
t.verbose = true
+
+ if RUBY_VERSION =~ /^1.8/
+ coverage18(t)
+ else
+ ENV['COVERAGE'] = 'true'
+ end
end
@@ -16,4 +16,5 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-require 'boxgrinder-build/appliance'
+require 'boxgrinder-core'
+require 'boxgrinder-build/appliance'
@@ -27,7 +27,7 @@
module BoxGrinder
class GuestFSHelper
def initialize(disks, appliance_config, config, options = {})
- @disks = disks
+ @disks = Array(disks)
@appliance_config = appliance_config
@config = config
@log = options[:log] || LogHelper.new
@@ -68,12 +68,12 @@ def disk_and_container_format
if @previous_plugin_info[:type] == :platform
case @previous_plugin_info[:name]
- when :ec2:
+ when :ec2
disk_format = :ami
container_format = :ami
- when :vmware:
+ when :vmware
disk_format = :vmdk
- when :virtualbox:
+ when :virtualbox
disk_format = :vmdk
end
end
@@ -37,7 +37,7 @@ def initialize(config, appliance_config, dir, options = {})
def create
template = "#{File.dirname(__FILE__)}/src/appliance.ks.erb"
- kickstart = ERB.new(File.read(template)).result(build_definition.send(:binding))
+ kickstart = ERB.new(File.read(template)).result(build_definition.get_binding)
File.open(@kickstart_file, 'w') { |f| f.write(kickstart) }
@kickstart_file
@@ -54,6 +54,10 @@ def definition.method_missing(sym, * args)
self[sym.to_s]
end
+ def definition.get_binding
+ binding
+ end
+
cost = 40
definition['mount_points'] = @linux_helper.partition_mount_points(@appliance_config.hardware.partitions)
@@ -147,7 +147,7 @@ def cleanup_after_appliance_creator(pid)
@log.debug "Cleaning appliance-creator mount points..."
Dir["#{@dir.tmp}/imgcreate-*"].each do |dir|
- dev_mapper = @exec_helper.execute "mount | grep #{dir} | awk '{print $1}'"
+ dev_mapper = @exec_helper.execute("mount | grep #{dir} | awk '{print $1}'").split("\n")
mappings = {}
@@ -80,7 +80,7 @@ def invalid_names( repo_list, package_list )
for name in package_list
found = false
- repoquery_output.each do |line|
+ repoquery_output.each_line do |line|
line = line.strip
package = line.match( /^([\S]+)-\d+:/ )
@@ -233,19 +233,24 @@ def prepare_appliance_config
describe ".initialize_plugins" do
let(:os_plugin){ mock("OSPlugin") }
+
+ let(:os_plugin_info_mock){ mock('os_plugin_info_mock', :[] => 'os').as_null_object }
+ let(:platform_plugin_info_mock){ mock('platform_plugin_info_mock', :[] => 'plat').as_null_object }
+ let(:delivery_plugin_info_mock){ mock('delivery_plugin_info_mock', :[] => 'deliver').as_null_object }
+
let(:platform_plugin){ mock("PlatformPlugin", :deliverables => OpenCascade.new(:disk => 'a/disk.vmdk')) }
let(:delivery_plugin){ mock("DeliveryPlugin", :deliverables => {}) }
it "should prepare the plugin chain to create an appliance and convert it to VMware format" do
prepare_appliance(:platform => :vmware)
@appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
- @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
- @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
+ @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, platform_plugin_info_mock])
@plugin_manager.should_not_receive(:initialize_plugin).with(:delivery, anything)
- os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
- platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
+ os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
+ platform_plugin.should_receive(:init).with(@config, @appliance_config, platform_plugin_info_mock, :log => @log, :previous_plugin => os_plugin)
@appliance.initialize_plugins
@@ -257,13 +262,13 @@ def prepare_appliance_config
prepare_appliance(:platform => :vmware, :delivery => :s3)
@appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
- @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
- @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
- @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
+ @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, platform_plugin_info_mock])
+ @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, delivery_plugin_info_mock])
- os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
- platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
- delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => platform_plugin, :type => :s3)
+ os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
+ platform_plugin.should_receive(:init).with(@config, @appliance_config, platform_plugin_info_mock, :log => @log, :previous_plugin => os_plugin)
+ delivery_plugin.should_receive(:init).with(@config, @appliance_config, delivery_plugin_info_mock, :log => @log, :previous_plugin => platform_plugin, :type => :s3)
@appliance.initialize_plugins
@@ -275,12 +280,12 @@ def prepare_appliance_config
prepare_appliance(:delivery => :s3)
@appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
- @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
- @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
+ @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, delivery_plugin_info_mock])
@plugin_manager.should_not_receive(:initialize_plugin).with(:platform, anything)
- os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
- delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => os_plugin, :type => :s3)
+ os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
+ delivery_plugin.should_receive(:init).with(@config, @appliance_config, delivery_plugin_info_mock, :log => @log, :previous_plugin => os_plugin, :type => :s3)
@appliance.initialize_plugins
end
@@ -56,7 +56,7 @@ module BoxGrinder
end
end
- it "should prepare and run guestfs wid IDE disk" do
+ it "should prepare and run guestfs with IDE disk" do
guestfs = mock('Guestfs')
@helper.instance_variable_set(:@guestfs, guestfs)
@@ -20,7 +20,7 @@
require 'rspec'
require 'boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin'
require 'hashery/opencascade'
-require 'spec/rspec-plugin-helper.rb'
+require 'rspec-plugin-helper'
module BoxGrinder
describe VirtualBoxPlugin do
@@ -122,7 +122,7 @@ def prepare_image(plugin_config, options = {})
vmdk_image = @plugin.change_vmdk_values("vmfs")
- vmdk_image.scan(/^createType="(.*)"\s?$/).to_s.should == "vmfs"
+ vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "vmfs"
disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
@@ -131,11 +131,11 @@ def prepare_image(plugin_config, options = {})
disk_attributes[2].should == "full"
disk_attributes[3].should == ""
- vmdk_image.scan(/^ddb.geometry.cylinders = "(.*)"\s?$/).to_s.should == "652"
- vmdk_image.scan(/^ddb.geometry.heads = "(.*)"\s?$/).to_s.should == "255"
- vmdk_image.scan(/^ddb.geometry.sectors = "(.*)"\s?$/).to_s.should == "63"
+ vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
+ vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
+ vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
- vmdk_image.scan(/^ddb.virtualHWVersion = "(.*)"\s?$/).to_s.should == "7"
+ vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
end
it "should change vmdk data (flat)" do
@@ -145,7 +145,7 @@ def prepare_image(plugin_config, options = {})
vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
- vmdk_image.scan(/^createType="(.*)"\s?$/).to_s.should == "monolithicFlat"
+ vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "monolithicFlat"
disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
@@ -154,12 +154,12 @@ def prepare_image(plugin_config, options = {})
disk_attributes[2].should == "full"
disk_attributes[3].should == "0"
- vmdk_image.scan(/^ddb.geometry.cylinders = "(.*)"\s?$/).to_s.should == "652"
- vmdk_image.scan(/^ddb.geometry.heads = "(.*)"\s?$/).to_s.should == "255"
- vmdk_image.scan(/^ddb.geometry.sectors = "(.*)"\s?$/).to_s.should == "63"
+ vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
+ vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
+ vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
- vmdk_image.scan(/^ddb.virtualHWVersion = "(.*)"\s?$/).to_s.should == "7"
- vmdk_image.scan(/^ddb.thinProvisioned = "(.*)"\s?$/).to_s.should == "0"
+ vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
+ vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "0"
end
it "should change vmdk data (flat) enabling thin disk" do
@@ -169,24 +169,27 @@ def prepare_image(plugin_config, options = {})
vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
- vmdk_image.scan(/^ddb.thinProvisioned = "(.*)"\s?$/).to_s.should == "1"
+ vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "1"
end
end
it "should change vmx data" do
prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
vmx_file = @plugin.change_common_vmx_values
-
- vmx_file.scan(/^guestOS = "(.*)"\s?$/).to_s.should == "linux"
- vmx_file.scan(/^displayName = "(.*)"\s?$/).to_s.should == "full"
- vmx_file.scan(/^annotation = "(.*)"\s?$/).to_s.scan(/^full | Version: 1\.0 | Built by: BoxGrinder 1\.0\.0/).should_not == nil
- vmx_file.scan(/^guestinfo.vmware.product.long = "(.*)"\s?$/).to_s.should == "full"
- vmx_file.scan(/^guestinfo.vmware.product.url = "(.*)"\s?$/).to_s.should == "http://boxgrinder.org"
- vmx_file.scan(/^numvcpus = "(.*)"\s?$/).to_s.should == "1"
- vmx_file.scan(/^memsize = "(.*)"\s?$/).to_s.should == "256"
- vmx_file.scan(/^log.fileName = "(.*)"\s?$/).to_s.should == "full.log"
- vmx_file.scan(/^scsi0:0.fileName = "(.*)"\s?$/).to_s.should == "full.vmdk"
+
+ vmx_file.match(/^guestOS = "(.*)"\s?$/)[1].should == "linux"
+ vmx_file.match(/^displayName = "(.*)"\s?$/)[1].should == "full"
+
+ vmx_file.match(/^annotation = "(.*)"\s?$/)[1].
+ match(/^full | Version: 1\.0 | Built by: BoxGrinder 1\.0\.0/).should_not == nil
+
+ vmx_file.match(/^guestinfo.vmware.product.long = "(.*)"\s?$/)[1].should == "full"
+ vmx_file.match(/^guestinfo.vmware.product.url = "(.*)"\s?$/)[1].should == "http://boxgrinder.org"
+ vmx_file.match(/^numvcpus = "(.*)"\s?$/)[1].should == "1"
+ vmx_file.match(/^memsize = "(.*)"\s?$/)[1].should == "256"
+ vmx_file.match(/^log.fileName = "(.*)"\s?$/)[1].should == "full.log"
+ vmx_file.match(/^scsi0:0.fileName = "(.*)"\s?$/)[1].should == "full.vmdk"
end
describe ".build_vmware_personal" do
View
@@ -0,0 +1,9 @@
+if ENV['COVERAGE']
+ require 'simplecov'
+
+ FILTER_DIRS = ['spec']
+
+ SimpleCov.start do
+ FILTER_DIRS.each{ |f| add_filter f }
+ end
+end

0 comments on commit af42eb9

Please sign in to comment.