Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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...
commit af42eb9f2819fddf3eea54a7a2cd3158abedcb74 1 parent f45412e
Marc Savy authored
22  Rakefile
@@ -40,7 +40,7 @@ desc "Run all integration tests"
40 40
 RSpec::Core::RakeTask.new('integ') do |t|
41 41
   t.rcov = false
42 42
   t.pattern = "integ/**/*-spec.rb"
43  
-  t.rspec_opts = ['--colour', '--format', 'doc', '-b']
  43
+  t.rspec_opts = ['-r boxgrinder-core', '--colour', '--format', 'doc', '-b']
44 44
   t.verbose = true
45 45
 end
46 46
 
@@ -49,16 +49,26 @@ RSpec::Core::RakeTask.new('spec') do |t|
49 49
   t.ruby_opts = "-I ../boxgrinder-core/lib"
50 50
   t.rcov = false
51 51
   t.pattern = "spec/**/*-spec.rb"
52  
-  t.rspec_opts = ['--colour', '--format', 'doc', '-b']
  52
+  t.rspec_opts = ['-r boxgrinder-core', '--colour', '--format', 'doc', '-b']
53 53
   t.verbose = true
54 54
 end
55 55
 
56  
-desc "Run all tests and generate code coverage report"
  56
+def coverage18(t)
  57
+  require 'rcov'
  58
+  t.rcov = true
  59
+  t.rcov_opts = ['--exclude', 'spec,teamcity/*,/usr/lib/ruby/,.gem/ruby,/boxgrinder-core/,/gems/']
  60
+end
  61
+
57 62
 RSpec::Core::RakeTask.new('spec:coverage') do |t|
58 63
   t.ruby_opts = "-I ../boxgrinder-core/lib"
59 64
   t.pattern = "spec/**/*-spec.rb"
60  
-  t.rspec_opts = ['--colour', '--format', 'html', '--out', 'pkg/rspec_report.html', '-b']
61  
-  t.rcov = true
62  
-  t.rcov_opts = ['--exclude', 'spec,teamcity/*,/usr/lib/ruby/,.gem/ruby,/boxgrinder-core/,/gems/']
  65
+  t.rspec_opts = ['-r spec_helper', '-r boxgrinder-core', '--colour', 
  66
+    '--format', 'html', '--out', 'pkg/rspec_report.html', '-b']
63 67
   t.verbose = true
  68
+
  69
+  if RUBY_VERSION =~ /^1.8/
  70
+    coverage18(t) 
  71
+  else
  72
+    ENV['COVERAGE'] = 'true'
  73
+  end
64 74
 end
3  lib/boxgrinder-build.rb
@@ -16,4 +16,5 @@
16 16
 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 17
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18 18
 
19  
-require 'boxgrinder-build/appliance'
  19
+require 'boxgrinder-core'
  20
+require 'boxgrinder-build/appliance'
2  lib/boxgrinder-build/helpers/guestfs-helper.rb
@@ -27,7 +27,7 @@
27 27
 module BoxGrinder
28 28
   class GuestFSHelper
29 29
     def initialize(disks, appliance_config, config, options = {})
30  
-      @disks = disks
  30
+      @disks = Array(disks)
31 31
       @appliance_config = appliance_config
32 32
       @config = config
33 33
       @log = options[:log] || LogHelper.new
6  lib/boxgrinder-build/plugins/delivery/openstack/openstack-plugin.rb
@@ -68,12 +68,12 @@ def disk_and_container_format
68 68
 
69 69
       if @previous_plugin_info[:type] == :platform
70 70
         case @previous_plugin_info[:name]
71  
-          when :ec2:
  71
+          when :ec2
72 72
             disk_format = :ami
73 73
             container_format = :ami
74  
-          when :vmware:
  74
+          when :vmware
75 75
             disk_format = :vmdk
76  
-          when :virtualbox:
  76
+          when :virtualbox
77 77
             disk_format = :vmdk
78 78
         end
79 79
       end
6  lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb
@@ -37,7 +37,7 @@ def initialize(config, appliance_config, dir, options = {})
37 37
 
38 38
     def create
39 39
       template = "#{File.dirname(__FILE__)}/src/appliance.ks.erb"
40  
-      kickstart = ERB.new(File.read(template)).result(build_definition.send(:binding))
  40
+      kickstart = ERB.new(File.read(template)).result(build_definition.get_binding)
41 41
       File.open(@kickstart_file, 'w') { |f| f.write(kickstart) }
42 42
 
43 43
       @kickstart_file
@@ -54,6 +54,10 @@ def definition.method_missing(sym, * args)
54 54
         self[sym.to_s]
55 55
       end
56 56
 
  57
+      def definition.get_binding
  58
+        binding 
  59
+      end
  60
+
57 61
       cost = 40
58 62
 
59 63
       definition['mount_points'] = @linux_helper.partition_mount_points(@appliance_config.hardware.partitions)
2  lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb
@@ -147,7 +147,7 @@ def cleanup_after_appliance_creator(pid)
147 147
       @log.debug "Cleaning appliance-creator mount points..."
148 148
 
149 149
       Dir["#{@dir.tmp}/imgcreate-*"].each do |dir|
150  
-        dev_mapper = @exec_helper.execute "mount | grep #{dir} | awk '{print $1}'"
  150
+        dev_mapper = @exec_helper.execute("mount | grep #{dir} | awk '{print $1}'").split("\n")
151 151
 
152 152
         mappings = {}
153 153
 
2  lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb
@@ -80,7 +80,7 @@ def invalid_names( repo_list, package_list )
80 80
       for name in package_list
81 81
         found = false
82 82
 
83  
-        repoquery_output.each do |line|
  83
+        repoquery_output.each_line do |line|
84 84
           line = line.strip
85 85
 
86 86
           package = line.match( /^([\S]+)-\d+:/ )
33  spec/appliance-spec.rb
@@ -233,6 +233,11 @@ def prepare_appliance_config
233 233
 
234 234
     describe ".initialize_plugins" do
235 235
       let(:os_plugin){ mock("OSPlugin") }
  236
+
  237
+      let(:os_plugin_info_mock){ mock('os_plugin_info_mock', :[] => 'os').as_null_object }
  238
+      let(:platform_plugin_info_mock){ mock('platform_plugin_info_mock', :[] => 'plat').as_null_object }
  239
+      let(:delivery_plugin_info_mock){ mock('delivery_plugin_info_mock', :[] => 'deliver').as_null_object }
  240
+
236 241
       let(:platform_plugin){ mock("PlatformPlugin", :deliverables => OpenCascade.new(:disk => 'a/disk.vmdk')) }
237 242
       let(:delivery_plugin){ mock("DeliveryPlugin", :deliverables => {}) }
238 243
 
@@ -240,12 +245,12 @@ def prepare_appliance_config
240 245
         prepare_appliance(:platform => :vmware)
241 246
         @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
242 247
 
243  
-        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
244  
-        @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
  248
+        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
  249
+        @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, platform_plugin_info_mock])
245 250
         @plugin_manager.should_not_receive(:initialize_plugin).with(:delivery, anything)
246 251
 
247  
-        os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
248  
-        platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
  252
+        os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
  253
+        platform_plugin.should_receive(:init).with(@config, @appliance_config, platform_plugin_info_mock, :log => @log, :previous_plugin => os_plugin)
249 254
 
250 255
         @appliance.initialize_plugins
251 256
 
@@ -257,13 +262,13 @@ def prepare_appliance_config
257 262
         prepare_appliance(:platform => :vmware, :delivery => :s3)
258 263
         @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
259 264
 
260  
-        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
261  
-        @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
262  
-        @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
  265
+        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
  266
+        @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, platform_plugin_info_mock])
  267
+        @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, delivery_plugin_info_mock])
263 268
 
264  
-        os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
265  
-        platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
266  
-        delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => platform_plugin, :type => :s3)
  269
+        os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
  270
+        platform_plugin.should_receive(:init).with(@config, @appliance_config, platform_plugin_info_mock, :log => @log, :previous_plugin => os_plugin)
  271
+        delivery_plugin.should_receive(:init).with(@config, @appliance_config, delivery_plugin_info_mock, :log => @log, :previous_plugin => platform_plugin, :type => :s3)
267 272
 
268 273
         @appliance.initialize_plugins
269 274
 
@@ -275,12 +280,12 @@ def prepare_appliance_config
275 280
         prepare_appliance(:delivery => :s3)
276 281
         @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
277 282
 
278  
-        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
279  
-        @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
  283
+        @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, os_plugin_info_mock])
  284
+        @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, delivery_plugin_info_mock])
280 285
         @plugin_manager.should_not_receive(:initialize_plugin).with(:platform, anything)
281 286
 
282  
-        os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
283  
-        delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => os_plugin, :type => :s3)
  287
+        os_plugin.should_receive(:init).with(@config, @appliance_config, os_plugin_info_mock, :log => @log)
  288
+        delivery_plugin.should_receive(:init).with(@config, @appliance_config, delivery_plugin_info_mock, :log => @log, :previous_plugin => os_plugin, :type => :s3)
284 289
 
285 290
         @appliance.initialize_plugins
286 291
       end
2  spec/helpers/guestfs-helper-spec.rb
@@ -56,7 +56,7 @@ module BoxGrinder
56 56
         end
57 57
       end
58 58
 
59  
-      it "should prepare and run guestfs wid IDE disk" do
  59
+      it "should prepare and run guestfs with IDE disk" do
60 60
         guestfs = mock('Guestfs')
61 61
         @helper.instance_variable_set(:@guestfs, guestfs)
62 62
 
2  spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb
@@ -20,7 +20,7 @@
20 20
 require 'rspec'
21 21
 require 'boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin'
22 22
 require 'hashery/opencascade'
23  
-require 'spec/rspec-plugin-helper.rb'
  23
+require 'rspec-plugin-helper'
24 24
 
25 25
 module BoxGrinder
26 26
   describe VirtualBoxPlugin do
47  spec/plugins/platform/vmware/vmware-plugin-spec.rb
@@ -122,7 +122,7 @@ def prepare_image(plugin_config, options = {})
122 122
 
123 123
         vmdk_image = @plugin.change_vmdk_values("vmfs")
124 124
 
125  
-        vmdk_image.scan(/^createType="(.*)"\s?$/).to_s.should == "vmfs"
  125
+        vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "vmfs"
126 126
 
127 127
         disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
128 128
 
@@ -131,11 +131,11 @@ def prepare_image(plugin_config, options = {})
131 131
         disk_attributes[2].should == "full"
132 132
         disk_attributes[3].should == ""
133 133
 
134  
-        vmdk_image.scan(/^ddb.geometry.cylinders = "(.*)"\s?$/).to_s.should == "652"
135  
-        vmdk_image.scan(/^ddb.geometry.heads = "(.*)"\s?$/).to_s.should == "255"
136  
-        vmdk_image.scan(/^ddb.geometry.sectors = "(.*)"\s?$/).to_s.should == "63"
  134
+        vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
  135
+        vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
  136
+        vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
137 137
 
138  
-        vmdk_image.scan(/^ddb.virtualHWVersion = "(.*)"\s?$/).to_s.should == "7"
  138
+        vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
139 139
       end
140 140
 
141 141
       it "should change vmdk data (flat)" do
@@ -145,7 +145,7 @@ def prepare_image(plugin_config, options = {})
145 145
 
146 146
         vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
147 147
 
148  
-        vmdk_image.scan(/^createType="(.*)"\s?$/).to_s.should == "monolithicFlat"
  148
+        vmdk_image.match(/^createType="(.*)"\s?$/)[1].should == "monolithicFlat"
149 149
 
150 150
         disk_attributes = vmdk_image.scan(/^RW (.*) (.*) "(.*).raw" (.*)\s?$/)[0]
151 151
 
@@ -154,12 +154,12 @@ def prepare_image(plugin_config, options = {})
154 154
         disk_attributes[2].should == "full"
155 155
         disk_attributes[3].should == "0"
156 156
 
157  
-        vmdk_image.scan(/^ddb.geometry.cylinders = "(.*)"\s?$/).to_s.should == "652"
158  
-        vmdk_image.scan(/^ddb.geometry.heads = "(.*)"\s?$/).to_s.should == "255"
159  
-        vmdk_image.scan(/^ddb.geometry.sectors = "(.*)"\s?$/).to_s.should == "63"
  157
+        vmdk_image.match(/^ddb.geometry.cylinders = "(.*)"\s?$/)[1].should == "652"
  158
+        vmdk_image.match(/^ddb.geometry.heads = "(.*)"\s?$/)[1].should == "255"
  159
+        vmdk_image.match(/^ddb.geometry.sectors = "(.*)"\s?$/)[1].should == "63"
160 160
 
161  
-        vmdk_image.scan(/^ddb.virtualHWVersion = "(.*)"\s?$/).to_s.should == "7"
162  
-        vmdk_image.scan(/^ddb.thinProvisioned = "(.*)"\s?$/).to_s.should == "0"
  161
+        vmdk_image.match(/^ddb.virtualHWVersion = "(.*)"\s?$/)[1].should == "7"
  162
+        vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "0"
163 163
       end
164 164
 
165 165
       it "should change vmdk data (flat) enabling thin disk" do
@@ -169,7 +169,7 @@ def prepare_image(plugin_config, options = {})
169 169
 
170 170
         vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
171 171
 
172  
-        vmdk_image.scan(/^ddb.thinProvisioned = "(.*)"\s?$/).to_s.should == "1"
  172
+        vmdk_image.match(/^ddb.thinProvisioned = "(.*)"\s?$/)[1].should == "1"
173 173
       end
174 174
     end
175 175
 
@@ -177,16 +177,19 @@ def prepare_image(plugin_config, options = {})
177 177
       prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
178 178
 
179 179
       vmx_file = @plugin.change_common_vmx_values
180  
-
181  
-      vmx_file.scan(/^guestOS = "(.*)"\s?$/).to_s.should == "linux"
182  
-      vmx_file.scan(/^displayName = "(.*)"\s?$/).to_s.should == "full"
183  
-      vmx_file.scan(/^annotation = "(.*)"\s?$/).to_s.scan(/^full | Version: 1\.0 | Built by: BoxGrinder 1\.0\.0/).should_not == nil
184  
-      vmx_file.scan(/^guestinfo.vmware.product.long = "(.*)"\s?$/).to_s.should == "full"
185  
-      vmx_file.scan(/^guestinfo.vmware.product.url = "(.*)"\s?$/).to_s.should == "http://boxgrinder.org"
186  
-      vmx_file.scan(/^numvcpus = "(.*)"\s?$/).to_s.should == "1"
187  
-      vmx_file.scan(/^memsize = "(.*)"\s?$/).to_s.should == "256"
188  
-      vmx_file.scan(/^log.fileName = "(.*)"\s?$/).to_s.should == "full.log"
189  
-      vmx_file.scan(/^scsi0:0.fileName = "(.*)"\s?$/).to_s.should == "full.vmdk"
  180
+      
  181
+      vmx_file.match(/^guestOS = "(.*)"\s?$/)[1].should == "linux"
  182
+      vmx_file.match(/^displayName = "(.*)"\s?$/)[1].should == "full"
  183
+
  184
+      vmx_file.match(/^annotation = "(.*)"\s?$/)[1].
  185
+        match(/^full | Version: 1\.0 | Built by: BoxGrinder 1\.0\.0/).should_not == nil
  186
+      
  187
+      vmx_file.match(/^guestinfo.vmware.product.long = "(.*)"\s?$/)[1].should == "full"
  188
+      vmx_file.match(/^guestinfo.vmware.product.url = "(.*)"\s?$/)[1].should == "http://boxgrinder.org"
  189
+      vmx_file.match(/^numvcpus = "(.*)"\s?$/)[1].should == "1"
  190
+      vmx_file.match(/^memsize = "(.*)"\s?$/)[1].should == "256"
  191
+      vmx_file.match(/^log.fileName = "(.*)"\s?$/)[1].should == "full.log"
  192
+      vmx_file.match(/^scsi0:0.fileName = "(.*)"\s?$/)[1].should == "full.vmdk"
190 193
     end
191 194
 
192 195
     describe ".build_vmware_personal" do
9  spec/spec_helper.rb
... ...
@@ -0,0 +1,9 @@
  1
+if ENV['COVERAGE']
  2
+  require 'simplecov'
  3
+
  4
+  FILTER_DIRS = ['spec']
  5
+
  6
+  SimpleCov.start do
  7
+    FILTER_DIRS.each{ |f| add_filter f }
  8
+  end
  9
+end

0 notes on commit af42eb9

Please sign in to comment.
Something went wrong with that request. Please try again.