boxgrinder-build 0.9.5.3 → 0.9.6

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ v0.9.6
2
+
3
+ * [BGBUILD-298] Fedora 16 or newer has networking issue on platforms different than EC2 because of biosdevname not disabled
4
+ * [BGBUILD-299] Wrong filenames in GRUB discovery
5
+ * [BGBUILD-276] Import files into appliance via appliance definition file (Files section)
6
+ * [BGBUILD-300] Add support for swap partitions
7
+ * [BGBUILD-301] Swap feature not working properly
8
+
1
9
  v0.9.5.3
2
10
 
3
11
  * What a shame, fixing the mocks again...
data/Manifest CHANGED
@@ -91,4 +91,12 @@ spec/plugins/os/centos/centos-plugin-spec.rb
91
91
  spec/plugins/os/fedora/fedora-plugin-spec.rb
92
92
  spec/plugins/os/rhel/rhel-plugin-spec.rb
93
93
  spec/plugins/os/rpm-based/kickstart-spec.rb
94
- spec/plugins/os/rpm-ba
94
+ spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb
95
+ spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb
96
+ spec/plugins/os/rpm-based/src/jeos-f13-plain.ks
97
+ spec/plugins/os/rpm-based/src/jeos-f13-without-version.ks
98
+ spec/plugins/os/rpm-based/src/jeos-f13.ks
99
+ spec/plugins/os/sl/sl-plugin-spec.rb
100
+ spec/plugins/platform/ec2/ec2-plugin-spec.rb
101
+ spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb
102
+ spec/plugins/platform/vmware/vmware-plugin-spec.rb
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-build}
5
- s.version = "0.9.5.3"
5
+ s.version = "0.9.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marek Goldmann"]
9
- s.date = %q{2011-08-27}
9
+ s.date = %q{2011-09-02}
10
10
  s.default_executable = %q{boxgrinder-build}
11
11
  s.description = %q{A tool for creating appliances from simple plain text files for various virtual environments.}
12
12
  s.email = %q{info@boxgrinder.org}
@@ -102,7 +102,6 @@ module BoxGrinder
102
102
 
103
103
  def execute_plugin_chain
104
104
  @log.info "Building '#{@appliance_config.name}' appliance for #{@appliance_config.hardware.arch} architecture."
105
-
106
105
  @plugin_chain.each { |p| execute_plugin(p[:plugin], p[:param]) }
107
106
  end
108
107
 
@@ -257,14 +257,16 @@ module BoxGrinder
257
257
  partitions.each_index { |i| mount_partition(partitions[i], mount_points[i], mount_prefix) }
258
258
  end
259
259
 
260
- def mountable_partitions(device)
261
- partitions = @guestfs.list_partitions.reject { |i| !(i =~ /^#{device}/) }
260
+ def mountable_partitions(device, options = {})
261
+ options = {:list_swap => false}.merge(options)
262
+
263
+ partitions = @guestfs.list_partitions
262
264
 
263
265
  # we need to remove extended partition
264
266
  # extended partition is always #3
265
267
  partitions.delete_at(3) if partitions.size > 4
266
268
 
267
- partitions
269
+ partitions.reject { |i| !(i =~ /^#{device}/) or (@guestfs.vfs_type(i) == 'swap' and !options[:list_swap]) }
268
270
  end
269
271
 
270
272
  def umount_partition(part)
@@ -276,7 +278,7 @@ module BoxGrinder
276
278
  # Unmounts partitions in reverse order.
277
279
  #
278
280
  def umount_partitions(device)
279
- partitions = @guestfs.list_partitions.reject { |i| !(i =~ /^#{device}/) }
281
+ partitions = mountable_partitions(device)
280
282
 
281
283
  @log.trace "Unmounting partitions..."
282
284
  partitions.reverse.each { |part| umount_partition(part) }
@@ -295,4 +297,4 @@ module BoxGrinder
295
297
  AugeasHelper.new(@guestfs, self, :log => @log).edit(&block)
296
298
  end
297
299
  end
298
- end
300
+ end
@@ -27,19 +27,24 @@ module BoxGrinder
27
27
  # Returns valid array of sorted mount points
28
28
  #
29
29
  # ['/', '/home'] => ['/', '/home']
30
+ # ['swap', '/', '/home'] => ['/', '/home', 'swap']
30
31
  # ['/tmp-eventlog', '/', '/ubrc', '/tmp-config'] => ['/', '/ubrc', '/tmp-config', '/tmp-eventlog']
31
32
  #
32
33
  def partition_mount_points(partitions)
33
34
  partitions.keys.sort do |a, b|
34
- if a.count('/') > b.count('/')
35
- v = 1
35
+ a_count = a.count('/')
36
+ b_count = b.count('/')
37
+
38
+ if a_count > b_count
39
+ v = (b_count == 0 ? -1 : 1)
36
40
  else
37
- if a.count('/') < b.count('/')
41
+ if a_count < b_count
38
42
  v = -1
39
43
  else
40
44
  v = a.length <=> b.length
41
45
  end
42
46
  end
47
+
43
48
  v
44
49
  end
45
50
  end
@@ -45,12 +45,12 @@ module BoxGrinder
45
45
  build_with_appliance_creator(appliance_definition_file, @repos) do |guestfs, guestfs_helper|
46
46
  if @appliance_config.os.version >= "15"
47
47
  disable_biosdevname(guestfs)
48
+ # https://issues.jboss.org/browse/BGBUILD-298
49
+ switch_to_grub2(guestfs, guestfs_helper) if @appliance_config.os.version >= "16"
48
50
  change_runlevel(guestfs)
49
51
  disable_netfs(guestfs)
50
52
  link_mtab(guestfs)
51
53
  end
52
-
53
- switch_to_grub2(guestfs, guestfs_helper) if @appliance_config.os.version >= "16"
54
54
  end
55
55
  end
56
56
 
@@ -86,7 +86,7 @@ module BoxGrinder
86
86
  def disable_biosdevname(guestfs)
87
87
  @log.debug "Disabling biosdevname..."
88
88
  guestfs.write("/etc/default/grub", "GRUB_CMDLINE_LINUX=\"quiet rhgb biosdevname=0\"\n") if guestfs.exists("/boot/grub2/grub.cfg") != 0
89
- guestfs.sh('sed -i "s/kernel\(.*\)/kernel\1 biosdevname=0/g" /boot/grub/grub.conf') if guestfs.exists("/boot/grub/grub.cfg") != 0
89
+ guestfs.sh('sed -i "s/kernel\(.*\)/kernel\1 biosdevname=0/g" /boot/grub/grub.conf') if guestfs.exists("/boot/grub/grub.conf") != 0
90
90
  @log.debug "Biosdevname disabled."
91
91
  end
92
92
 
@@ -113,6 +113,8 @@ module BoxGrinder
113
113
  end
114
114
 
115
115
  def build_with_appliance_creator(appliance_definition_file, repos = {})
116
+ @appliance_definition_file = appliance_definition_file
117
+
116
118
  if File.extname(appliance_definition_file).eql?('.ks')
117
119
  kickstart_file = appliance_definition_file
118
120
  else
@@ -137,10 +139,12 @@ module BoxGrinder
137
139
  change_configuration(guestfs_helper)
138
140
  # TODO check if this is still required
139
141
  apply_root_password(guestfs)
142
+ set_label_for_swap_partitions(guestfs, guestfs_helper)
140
143
  use_labels_for_partitions(guestfs)
141
144
  disable_firewall(guestfs)
142
145
  set_motd(guestfs)
143
146
  install_repos(guestfs)
147
+ install_files(guestfs)
144
148
 
145
149
  guestfs.sh("chkconfig firstboot off") if guestfs.exists('/etc/init.d/firstboot') != 0
146
150
 
@@ -238,22 +242,35 @@ module BoxGrinder
238
242
  @log.debug "Firewall disabled."
239
243
  end
240
244
 
245
+ # https://issues.jboss.org/browse/BGBUILD-301
246
+ def set_label_for_swap_partitions(guestfs, guestfs_helper)
247
+ @log.trace "Searching for swap partition to set label..."
248
+
249
+ guestfs_helper.mountable_partitions(guestfs.list_devices.first, :list_swap => true).each do |p|
250
+ if guestfs.vfs_type(p).eql?('swap')
251
+ @log.debug "Setting 'swap' label for partiiton '#{p}'."
252
+ guestfs.mkswap_L('swap', p)
253
+ @log.debug "Label set."
254
+ # We assume here that nobody will want to have two swap partitions
255
+ break
256
+ end
257
+ end
258
+ end
259
+
241
260
  def use_labels_for_partitions(guestfs)
261
+ @log.debug "Using labels for partitions..."
242
262
  device = guestfs.list_devices.first
243
263
 
244
264
  # /etc/fstab
245
- if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" }
265
+ if fstab = guestfs.read_file('/etc/fstab').gsub!(/^(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" }
246
266
  guestfs.write_file('/etc/fstab', fstab, 0)
247
267
  end
248
268
 
249
269
  # /boot/grub/grub.conf
250
- if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{read_label(guestfs, path.gsub('/dev/sda', device))}" }
270
+ if grub = guestfs.read_file('/boot/grub/grub.conf').gsub!(/(\/dev\/sda.)/) { |path| "LABEL=#{guestfs.vfs_label(path.gsub('/dev/sda', device))}" }
251
271
  guestfs.write_file('/boot/grub/grub.conf', grub, 0)
252
272
  end
253
- end
254
-
255
- def read_label(guestfs, partition)
256
- (guestfs.respond_to?(:vfs_label) ? guestfs.vfs_label(partition) : guestfs.sh("/sbin/e2label #{partition}").chomp.strip).gsub('_', '')
273
+ @log.debug "Done."
257
274
  end
258
275
 
259
276
  def apply_root_password(guestfs)
@@ -307,5 +324,55 @@ module BoxGrinder
307
324
  @log.debug "Repositories installed."
308
325
  end
309
326
 
327
+ # Copies specified files into appliance.
328
+ #
329
+ # There are two types of paths:
330
+ # 1. remote - starting with http:// or https:// or ftp://
331
+ # 2. local - all other.
332
+ #
333
+ # Please use relative paths. Relative means relative to the appliance definition file.
334
+ # Using absolute paths will cause creating whole directory structure in appliance,
335
+ # which is most probably not exactly what you want.
336
+ #
337
+ # https://issues.jboss.org/browse/BGBUILD-276
338
+ def install_files(guestfs)
339
+ @log.debug "Installing files specified in appliance definition file..."
340
+
341
+ @appliance_config.files.each do |dir, files|
342
+
343
+ @log.debug "Proceding files for '#{dir}' destination directory..."
344
+
345
+ local_files = []
346
+
347
+ # Create the directory if it doesn't exists
348
+ guestfs.mkdir_p(dir) unless guestfs.exists(dir) != 0
349
+
350
+ files.each do |f|
351
+ if f.match(/^(http|ftp|https):\/\//)
352
+ # Remote url provided
353
+ @log.trace "Remote url detected: '#{f}'."
354
+
355
+ # We have a remote file, try to download it using curl!
356
+ guestfs.sh("cd #{dir} && curl -O -L #{f}")
357
+ else
358
+ @log.trace "Local path detected: '#{f}'."
359
+
360
+ local_files << (f.match(/^\//) ? f : "#{File.dirname(@appliance_definition_file)}/#{f}")
361
+ end
362
+ end
363
+
364
+ next if local_files.empty?
365
+
366
+ @log.trace "Tarring files..."
367
+ @exec_helper.execute("tar -cvf /tmp/bg_install_files.tar --wildcards #{local_files.join(' ')}")
368
+ @log.trace "Files tarred."
369
+
370
+ @log.trace "Uploading and unpacking..."
371
+ guestfs.tar_in("/tmp/bg_install_files.tar", dir)
372
+ @log.trace "Files uploaded."
373
+
374
+ end
375
+ @log.debug "Files installed."
376
+ end
310
377
  end
311
378
  end
@@ -22,7 +22,7 @@ rootpw --iscrypted <%= appliance_config.os.password.crypt((0...8).map { 65.+(ran
22
22
 
23
23
  <% mount_points.each do |root| %>
24
24
  <% partition = appliance_config.hardware.partitions[root]%>
25
- part <%= root %> --size <%= (partition['size'].to_f * 1024).to_i %> --fstype <%= partition['type'] %> <% unless partition['options'].nil? %> --fsoptions '<%= partition['options'] %>' <% end %> <% if partition['passphrase'] %> --encrypted --passphrase='<%= partition['passphrase'] %>' <% end %> --ondisk sda<% end %>
25
+ part <%= root %> --size <%= (partition['size'].to_f * 1024).to_i %> --fstype <%= root.eql?('swap') ? 'swap' : partition['type'] %> <% unless partition['options'].nil? %> --fsoptions '<%= partition['options'] %>' <% end %> <% if partition['passphrase'] %> --encrypted --passphrase='<%= partition['passphrase'] %>' <% end %> --ondisk sda<% end %>
26
26
 
27
27
  <% for repo in repos %>
28
28
  <%= repo %><% end %>
@@ -5,7 +5,7 @@
5
5
 
6
6
  Summary: A tool for creating appliances from simple plain text files
7
7
  Name: rubygem-%{gemname}
8
- Version: 0.9.5.3
8
+ Version: 0.9.6
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
@@ -130,6 +130,14 @@ popd
130
130
  %{gemdir}/doc/%{gemname}-%{version}
131
131
 
132
132
  %changelog
133
+ * Sat Aug 27 2011 Marek Goldmann <mgoldman@redhat.com> - 0.9.6-1
134
+ - Upstream release: 0.9.6
135
+ - [BGBUILD-298] Fedora 16 or newer has networking issue on platforms different than EC2 because of biosdevname not disabled
136
+ - [BGBUILD-299] Wrong filenames in GRUB discovery
137
+ - [BGBUILD-276] Import files into appliance via appliance definition file (Files section)
138
+ - [BGBUILD-300] Add support for swap partitions
139
+ - [BGBUILD-301] Swap feature not working properly
140
+
133
141
  * Sat Aug 27 2011 Marek Goldmann <mgoldman@redhat.com> - 0.9.5.3-1
134
142
  - Upstream release: 0.9.5.3
135
143
 
@@ -26,7 +26,7 @@ module BoxGrinder
26
26
  before(:each) do
27
27
  ENV.delete("LIBGUESTFS_MEMSIZE")
28
28
 
29
- @log = Logger.new('/dev/null')
29
+ @log = LogHelper.new(:level => :trace, :type => :stdout)
30
30
  @appliance_config = mock('ApplianceConfig')
31
31
  @appliance_config.stub!(:hardware).and_return(:partitions => {})
32
32
 
@@ -228,6 +228,24 @@ module BoxGrinder
228
228
 
229
229
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:partitions => {'/' => nil, '/home' => nil}))
230
230
  guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
231
+ guestfs.should_receive(:vfs_type).with('/dev/vda1').and_return('ext3')
232
+ guestfs.should_receive(:vfs_type).with('/dev/vda2').and_return('ext3')
233
+
234
+ @helper.should_receive(:mount_partition).with('/dev/vda1', '/', '')
235
+ @helper.should_receive(:mount_partition).with('/dev/vda2', '/home', '')
236
+
237
+ @helper.instance_variable_set(:@guestfs, guestfs)
238
+ @helper.mount_partitions('/dev/vda')
239
+ end
240
+
241
+ it "should mount two partitions from three where one is a swap partition" do
242
+ guestfs = mock('Guestfs')
243
+
244
+ @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:partitions => {'/' => nil, '/home' => nil, 'swap' => nil}))
245
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2', '/dev/vda3'])
246
+ guestfs.should_receive(:vfs_type).with('/dev/vda1').and_return('ext3')
247
+ guestfs.should_receive(:vfs_type).with('/dev/vda2').and_return('ext3')
248
+ guestfs.should_receive(:vfs_type).with('/dev/vda3').and_return('swap')
231
249
 
232
250
  @helper.should_receive(:mount_partition).with('/dev/vda1', '/', '')
233
251
  @helper.should_receive(:mount_partition).with('/dev/vda2', '/home', '')
@@ -241,6 +259,10 @@ module BoxGrinder
241
259
 
242
260
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:partitions => {'/' => nil, '/home' => nil, '/var/www' => nil, '/var/mock' => nil}))
243
261
  guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2', '/dev/vda3', '/dev/vda4', '/dev/vda5'])
262
+ guestfs.should_receive(:vfs_type).with('/dev/vda1').and_return('ext3')
263
+ guestfs.should_receive(:vfs_type).with('/dev/vda2').and_return('ext3')
264
+ guestfs.should_receive(:vfs_type).with('/dev/vda3').and_return('ext4')
265
+ guestfs.should_receive(:vfs_type).with('/dev/vda5').and_return('ext4')
244
266
 
245
267
  @helper.should_receive(:mount_partition).with('/dev/vda1', '/', '')
246
268
  @helper.should_receive(:mount_partition).with('/dev/vda2', '/home', '')
@@ -340,6 +362,8 @@ module BoxGrinder
340
362
  @helper.instance_variable_set(:@guestfs, guestfs)
341
363
 
342
364
  guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
365
+ guestfs.should_receive(:vfs_type).with('/dev/vda1').and_return('ext3')
366
+ guestfs.should_receive(:vfs_type).with('/dev/vda2').and_return('ext3')
343
367
 
344
368
  @helper.should_receive(:umount_partition).ordered.with('/dev/vda2')
345
369
  @helper.should_receive(:umount_partition).ordered.with('/dev/vda1')
@@ -398,5 +422,42 @@ module BoxGrinder
398
422
  @helper.log_hack
399
423
  end
400
424
  end
425
+
426
+ describe ".mountable_partitions" do
427
+ it "return list of partitions to mount without swap" do
428
+ guestfs = mock('Guestfs')
429
+ @helper.instance_variable_set(:@guestfs, guestfs)
430
+
431
+ guestfs.should_receive(:list_partitions).and_return(['/dev/sda1', '/dev/sda2'])
432
+ guestfs.should_receive(:vfs_type).with('/dev/sda1').and_return('ext3')
433
+ guestfs.should_receive(:vfs_type).with('/dev/sda2').and_return('swap')
434
+
435
+ @helper.mountable_partitions('/dev/sda').should == ['/dev/sda1']
436
+ end
437
+
438
+ it "return list of partitions to mount with swap" do
439
+ guestfs = mock('Guestfs')
440
+ @helper.instance_variable_set(:@guestfs, guestfs)
441
+
442
+ guestfs.should_receive(:list_partitions).and_return(['/dev/sda1', '/dev/sda2'])
443
+ guestfs.should_receive(:vfs_type).with('/dev/sda1').and_return('ext3')
444
+ guestfs.should_receive(:vfs_type).with('/dev/sda2').and_return('swap')
445
+
446
+ @helper.mountable_partitions('/dev/sda', :list_swap => true).should == ['/dev/sda1', '/dev/sda2']
447
+ end
448
+
449
+ it "return list of partitions to mount without extended partitions" do
450
+ guestfs = mock('Guestfs')
451
+ @helper.instance_variable_set(:@guestfs, guestfs)
452
+
453
+ guestfs.should_receive(:list_partitions).and_return(['/dev/sda1', '/dev/sda2', '/dev/sda3', '/dev/sda4', '/dev/sda5'])
454
+ guestfs.should_receive(:vfs_type).with('/dev/sda1').and_return('ext3')
455
+ guestfs.should_receive(:vfs_type).with('/dev/sda2').and_return('ext3')
456
+ guestfs.should_receive(:vfs_type).with('/dev/sda3').and_return('ext3')
457
+ guestfs.should_receive(:vfs_type).with('/dev/sda5').and_return('ext3')
458
+
459
+ @helper.mountable_partitions('/dev/sda').should == ['/dev/sda1', '/dev/sda2', '/dev/sda3', '/dev/sda5']
460
+ end
461
+ end
401
462
  end
402
463
  end
@@ -71,6 +71,11 @@ module BoxGrinder
71
71
  @helper.partition_mount_points(hash).should == ['/', '/home']
72
72
  end
73
73
 
74
+ it "should return ['/', '/home', 'swap']" do
75
+ hash = {'swap' => {"size" => 1}, "/"=>{"size"=>2, "type"=>"ext3"}, "/home"=>{"size"=>2, "type"=>"ext3"}}
76
+ @helper.partition_mount_points(hash).should == ['/', '/home', 'swap']
77
+ end
78
+
74
79
  it "should return ['/', '/ubrc', '/tmp-config', '/tmp-eventlog']" do
75
80
  hash = {"/tmp-eventlog"=>{"size"=>0.01, "type"=>"ext3"}, "/"=>{"size"=>2, "type"=>"ext3"}, "/ubrc"=>{"size"=>0.02, "type"=>"ext3"}, "/tmp-config"=>{"size"=>0.26}}
76
81
  @helper.partition_mount_points(hash).should == ["/", "/ubrc", "/tmp-config", "/tmp-eventlog"]
@@ -39,6 +39,7 @@ module BoxGrinder
39
39
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '13'}))
40
40
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64'}))
41
41
  @appliance_config.stub!(:is64bit?).and_return(true)
42
+ @appliance_config.stub!(:packages).and_return(['mc'])
42
43
 
43
44
  @plugin = FedoraPlugin.new.init(@config, @appliance_config, {:class => BoxGrinder::FedoraPlugin, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}, :log => LogHelper.new(:level => :trace, :type => :stdout))
44
45
 
@@ -92,7 +93,7 @@ module BoxGrinder
92
93
  it "should disable bios device name hints for GRUB legacy" do
93
94
  guestfs = mock("GuestFS")
94
95
  guestfs.should_receive(:exists).with("/boot/grub2/grub.cfg").and_return(0)
95
- guestfs.should_receive(:exists).with("/boot/grub/grub.cfg").and_return(1)
96
+ guestfs.should_receive(:exists).with("/boot/grub/grub.conf").and_return(1)
96
97
  guestfs.should_receive(:sh).with("sed -i \"s/kernel\\(.*\\)/kernel\\1 biosdevname=0/g\" /boot/grub/grub.conf")
97
98
  @plugin.disable_biosdevname(guestfs)
98
99
  end
@@ -100,7 +101,7 @@ module BoxGrinder
100
101
  it "should disable bios device name hints for GRUB2" do
101
102
  guestfs = mock("GuestFS")
102
103
  guestfs.should_receive(:exists).with("/boot/grub2/grub.cfg").and_return(1)
103
- guestfs.should_receive(:exists).with("/boot/grub/grub.cfg").and_return(0)
104
+ guestfs.should_receive(:exists).with("/boot/grub/grub.conf").and_return(0)
104
105
  guestfs.should_receive(:write).with("/etc/default/grub", "GRUB_CMDLINE_LINUX=\"quiet rhgb biosdevname=0\"\n")
105
106
  @plugin.disable_biosdevname(guestfs)
106
107
  end
@@ -124,6 +125,51 @@ module BoxGrinder
124
125
  guestfs.should_receive(:ln_sf).with("/proc/self/mounts", "/etc/mtab")
125
126
  @plugin.link_mtab(guestfs)
126
127
  end
128
+
129
+ it "should replace GRUB legacy with GRUB2" do
130
+ guestfs = mock("GuestFS")
131
+ guestfs_helper = mock("GuestFSHelper")
132
+ guestfs_helper.should_receive(:sh).ordered.with("yum -y remove grub")
133
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
134
+ guestfs.should_receive(:sh).ordered.with("cd / && grub2-install --force /dev/vda")
135
+ guestfs.should_receive(:sh).ordered.with("cd / && grub2-mkconfig -o /boot/grub2/grub.cfg")
136
+ @plugin.switch_to_grub2(guestfs, guestfs_helper)
137
+ end
138
+ describe ".execute" do
139
+ it "should make Fedora 15 or higher work" do
140
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '15'}))
141
+
142
+ guestfs = mock("GuestFS")
143
+ guestfs_helper = mock("GuestFSHelper")
144
+
145
+ @plugin.should_receive(:normalize_packages).ordered
146
+ @plugin.should_receive(:disable_biosdevname).ordered.with(guestfs)
147
+ @plugin.should_receive(:change_runlevel).ordered.with(guestfs)
148
+ @plugin.should_receive(:disable_netfs).ordered.with(guestfs)
149
+ @plugin.should_receive(:link_mtab).ordered.with(guestfs)
150
+
151
+ @plugin.should_receive(:build_with_appliance_creator).with("file", an_instance_of(Hash)).and_yield(guestfs, guestfs_helper)
152
+ @plugin.execute("file")
153
+ end
154
+
155
+ # https://issues.jboss.org/browse/BGBUILD-298
156
+ it "should for Fedora 16 or higher first install GRUB2 then look after it" do
157
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '16'}))
158
+
159
+ guestfs = mock("GuestFS")
160
+ guestfs_helper = mock("GuestFSHelper")
161
+
162
+ @plugin.should_receive(:normalize_packages).ordered
163
+ @plugin.should_receive(:disable_biosdevname).ordered.with(guestfs)
164
+ @plugin.should_receive(:switch_to_grub2).ordered.with(guestfs, guestfs_helper)
165
+ @plugin.should_receive(:change_runlevel).ordered.with(guestfs)
166
+ @plugin.should_receive(:disable_netfs).ordered.with(guestfs)
167
+ @plugin.should_receive(:link_mtab).ordered.with(guestfs)
168
+
169
+ @plugin.should_receive(:build_with_appliance_creator).with("file", an_instance_of(Hash)).and_yield(guestfs, guestfs_helper)
170
+ @plugin.execute("file")
171
+ end
172
+ end
127
173
  end
128
174
  end
129
175
 
@@ -39,6 +39,7 @@ module BoxGrinder
39
39
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '11'}))
40
40
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:cpus => 1, :memory => 512, :partitions => {'/' => nil, '/home' => nil}))
41
41
  @appliance_config.stub!(:path).and_return(OpenCascade.new(:build => 'build/path', :main => 'mainpath'))
42
+ @appliance_config.stub!(:files).and_return({})
42
43
 
43
44
  @plugin = RPMBasedOSPlugin.new
44
45
 
@@ -221,6 +222,7 @@ module BoxGrinder
221
222
 
222
223
  @plugin.should_receive(:change_configuration).with(guestfs_helper)
223
224
  @plugin.should_receive(:apply_root_password).with(guestfs)
225
+ @plugin.should_receive(:set_label_for_swap_partitions).with(guestfs, guestfs_helper)
224
226
  @plugin.should_receive(:use_labels_for_partitions).with(guestfs)
225
227
  @plugin.should_receive(:disable_firewall).with(guestfs)
226
228
  @plugin.should_receive(:set_motd).with(guestfs)
@@ -341,5 +343,91 @@ module BoxGrinder
341
343
  @plugin.recreate_rpm_database(guestfs, guestfs_helper)
342
344
  end
343
345
  end
346
+
347
+ describe ".install_files" do
348
+ it "should install files with relative paths" do
349
+ @appliance_config.stub!(:files).and_return("/opt" => ['abc', 'def'])
350
+ @plugin.instance_variable_set(:@appliance_definition_file, "file")
351
+
352
+ guestfs = mock("GuestFS")
353
+ guestfs.should_receive(:exists).with("/opt").once.and_return(1)
354
+ guestfs.should_receive(:tar_in).with("/tmp/bg_install_files.tar", "/opt")
355
+
356
+ @exec_helper.should_receive(:execute).with("tar -cvf /tmp/bg_install_files.tar --wildcards ./abc ./def")
357
+
358
+ @plugin.install_files(guestfs)
359
+ end
360
+
361
+ it "should install files with absolute paths" do
362
+ @appliance_config.stub!(:files).and_return("/opt" => ['/opt/abc', '/opt/def'])
363
+ @plugin.instance_variable_set(:@appliance_definition_file, "file")
364
+
365
+ guestfs = mock("GuestFS")
366
+ guestfs.should_receive(:exists).with("/opt").once.and_return(1)
367
+ guestfs.should_receive(:tar_in).with("/tmp/bg_install_files.tar", "/opt")
368
+
369
+ @exec_helper.should_receive(:execute).with("tar -cvf /tmp/bg_install_files.tar --wildcards /opt/abc /opt/def")
370
+
371
+ @plugin.install_files(guestfs)
372
+ end
373
+
374
+ it "should install files with remote paths" do
375
+ @appliance_config.stub!(:files).and_return("/opt" => ['http://somehost/file.zip', 'https://somehost/something.tar.gz', 'ftp://somehost/ftp.txt'])
376
+ @plugin.instance_variable_set(:@appliance_definition_file, "file")
377
+
378
+ guestfs = mock("GuestFS")
379
+
380
+ guestfs.should_receive(:exists).with("/opt").once.and_return(1)
381
+ guestfs.should_receive(:sh).with("cd /opt && curl -O -L http://somehost/file.zip")
382
+ guestfs.should_receive(:sh).with("cd /opt && curl -O -L https://somehost/something.tar.gz")
383
+ guestfs.should_receive(:sh).with("cd /opt && curl -O -L ftp://somehost/ftp.txt")
384
+
385
+ @plugin.install_files(guestfs)
386
+ end
387
+
388
+ it "should create the destination directory if it doesn't exists" do
389
+ @appliance_config.stub!(:files).and_return("/opt/aaa" => ['abc'])
390
+ @plugin.instance_variable_set(:@appliance_definition_file, "file")
391
+
392
+ guestfs = mock("GuestFS")
393
+ guestfs.should_receive(:exists).with("/opt/aaa").and_return(0)
394
+ guestfs.should_receive(:mkdir_p).with("/opt/aaa")
395
+ guestfs.should_receive(:tar_in).with("/tmp/bg_install_files.tar", "/opt/aaa")
396
+
397
+ @exec_helper.should_receive(:execute).with("tar -cvf /tmp/bg_install_files.tar --wildcards ./abc")
398
+
399
+ @plugin.install_files(guestfs)
400
+ end
401
+ end
402
+
403
+ describe ".set_label_for_swap_partitions" do
404
+ it "should NOT set label for any partition" do
405
+ guestfs = mock("GuestFS")
406
+ guestfs_helper = mock("GuestFSHelper")
407
+
408
+ guestfs_helper.should_receive(:mountable_partitions).with('/dev/sda', :list_swap => true).and_return(['/dev/sda1', '/dev/sda2'])
409
+
410
+ guestfs.should_receive(:list_devices).and_return(['/dev/sda'])
411
+ guestfs.should_receive(:vfs_type).with('/dev/sda1').and_return('ext3')
412
+ guestfs.should_receive(:vfs_type).with('/dev/sda2').and_return('ext4')
413
+ guestfs.should_not_receive(:set_e2label)
414
+
415
+ @plugin.set_label_for_swap_partitions(guestfs, guestfs_helper)
416
+ end
417
+
418
+ it "should set label for swap partition" do
419
+ guestfs = mock("GuestFS")
420
+ guestfs_helper = mock("GuestFSHelper")
421
+
422
+ guestfs_helper.should_receive(:mountable_partitions).with('/dev/sda', :list_swap => true).and_return(['/dev/sda1', '/dev/sda2'])
423
+
424
+ guestfs.should_receive(:list_devices).and_return(['/dev/sda'])
425
+ guestfs.should_receive(:vfs_type).with('/dev/sda1').and_return('ext3')
426
+ guestfs.should_receive(:vfs_type).with('/dev/sda2').and_return('swap')
427
+ guestfs.should_receive(:mkswap_L).with('swap', '/dev/sda2')
428
+
429
+ @plugin.set_label_for_swap_partitions(guestfs, guestfs_helper)
430
+ end
431
+ end
344
432
  end
345
433
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxgrinder-build
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 5
10
- - 3
11
- version: 0.9.5.3
9
+ - 6
10
+ version: 0.9.6
12
11
  platform: ruby
13
12
  authors:
14
13
  - Marek Goldmann
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-08-27 00:00:00 +02:00
18
+ date: 2011-09-02 00:00:00 +02:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency