boxgrinder-build 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGELOG +11 -0
  2. data/README.md +32 -34
  3. data/Rakefile +7 -1
  4. data/bin/boxgrinder-build +10 -17
  5. data/boxgrinder-build.gemspec +7 -4
  6. data/lib/boxgrinder-build/appliance.rb +13 -16
  7. data/lib/boxgrinder-build/helpers/guestfs-helper.rb +84 -40
  8. data/lib/boxgrinder-build/helpers/image-helper.rb +54 -85
  9. data/lib/boxgrinder-build/helpers/linux-helper.rb +29 -9
  10. data/lib/boxgrinder-build/helpers/plugin-helper.rb +1 -0
  11. data/lib/boxgrinder-build/plugins/base-plugin.rb +3 -2
  12. data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +13 -42
  13. data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +209 -0
  14. data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +8 -4
  15. data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +0 -7
  16. data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +4 -1
  17. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +52 -9
  18. data/lib/boxgrinder-build/plugins/os/rpm-based/src/appliance.ks.erb +6 -2
  19. data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +4 -44
  20. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_32bit +1 -1
  21. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_64bit +1 -1
  22. data/lib/boxgrinder-build/plugins/platform/ec2/src/menu.lst +2 -2
  23. data/lib/boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin.rb +24 -13
  24. data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmx +2 -2
  25. data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +0 -1
  26. data/rubygem-boxgrinder-build.spec +23 -1
  27. data/spec/appliance-spec.rb +5 -79
  28. data/spec/helpers/augeas-helper-spec.rb +1 -0
  29. data/spec/helpers/guestfs-helper-spec.rb +79 -62
  30. data/spec/helpers/image-helper-spec.rb +88 -129
  31. data/spec/helpers/linux-helper-spec.rb +22 -5
  32. data/spec/helpers/package-helper-spec.rb +1 -0
  33. data/spec/helpers/plugin-helper-spec.rb +1 -0
  34. data/spec/managers/plugin-manager-spec.rb +3 -2
  35. data/spec/plugins/base-plugin-spec.rb +1 -1
  36. data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +21 -13
  37. data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +320 -0
  38. data/spec/plugins/delivery/local/local-plugin-spec.rb +1 -0
  39. data/spec/plugins/delivery/s3/s3-plugin-spec.rb +1 -0
  40. data/spec/plugins/delivery/sftp/sftp-plugin-spec.rb +1 -0
  41. data/spec/plugins/os/centos/centos-plugin-spec.rb +1 -0
  42. data/spec/plugins/os/fedora/fedora-plugin-spec.rb +13 -1
  43. data/spec/plugins/os/rhel/rhel-plugin-spec.rb +1 -15
  44. data/spec/plugins/os/rpm-based/kickstart-spec.rb +1 -0
  45. data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +75 -15
  46. data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +1 -0
  47. data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +10 -43
  48. data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +89 -10
  49. data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +3 -2
  50. metadata +21 -7
  51. data/lib/boxgrinder-build/helpers/appliance-customize-helper.rb +0 -45
  52. data/spec/helpers/appliance-customize-helper-spec.rb +0 -74
@@ -16,13 +16,20 @@
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 'rubygems'
19
20
  require 'boxgrinder-build/helpers/guestfs-helper'
20
21
 
21
22
  module BoxGrinder
22
23
  describe GuestFSHelper do
23
24
  before(:each) do
24
25
  @log = Logger.new('/dev/null')
25
- @helper = GuestFSHelper.new('a/raw/disk', :log => @log)
26
+ @appliance_config = mock('ApplianceConfig')
27
+ @appliance_config.stub!(:hardware).and_return(:partitions => {})
28
+
29
+ @config = mock('Config')
30
+ @config.stub!(:dir).and_return(:tmp => '/tmp')
31
+
32
+ @helper = GuestFSHelper.new('a/raw/disk', @appliance_config, @config, :log => @log)
26
33
  end
27
34
 
28
35
  describe ".execute" do
@@ -39,11 +46,13 @@ module BoxGrinder
39
46
  guestfs.should_receive(:add_drive).with('a/raw/disk')
40
47
  guestfs.should_receive(:set_network).with(1)
41
48
  guestfs.should_receive(:launch)
42
- guestfs.should_receive(:list_partitions).and_return(['/', '/boot'])
49
+
50
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
51
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
43
52
 
44
53
  Guestfs.should_receive(:create).and_return(guestfs)
45
54
 
46
- @helper.should_receive(:mount_partitions).with(no_args)
55
+ @helper.should_receive(:mount_partitions).with('/dev/vda', '')
47
56
  @helper.execute.should == @helper
48
57
  end
49
58
 
@@ -60,11 +69,12 @@ module BoxGrinder
60
69
  guestfs.should_receive(:add_drive_with_if).with('a/raw/disk', 'ide')
61
70
  guestfs.should_receive(:set_network).with(1)
62
71
  guestfs.should_receive(:launch)
63
- guestfs.should_receive(:list_partitions).and_return(['/', '/boot'])
72
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
73
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
64
74
 
65
75
  Guestfs.should_receive(:create).and_return(guestfs)
66
76
 
67
- @helper.should_receive(:mount_partitions).with(no_args)
77
+ @helper.should_receive(:mount_partitions).with('/dev/vda', '')
68
78
  @helper.execute(nil, :ide_disk => true).should == @helper
69
79
  end
70
80
 
@@ -85,11 +95,12 @@ module BoxGrinder
85
95
  guestfs.should_receive(:add_drive).with('a/raw/disk')
86
96
  guestfs.should_receive(:set_network).with(1)
87
97
  guestfs.should_receive(:launch)
88
- guestfs.should_receive(:list_partitions).and_return(['/', '/boot'])
98
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
99
+ guestfs.should_receive(:list_partitions).and_return([])
89
100
 
90
101
  Guestfs.should_receive(:create).and_return(guestfs)
91
102
 
92
- @helper.should_receive(:mount_partitions).with(no_args)
103
+ @helper.should_receive(:mount_partition).with('/dev/vda', '/', '')
93
104
  @helper.execute.should == @helper
94
105
  end
95
106
 
@@ -110,15 +121,18 @@ module BoxGrinder
110
121
  guestfs.should_receive(:add_drive).with('a/raw/disk')
111
122
  guestfs.should_receive(:set_network).with(1)
112
123
  guestfs.should_receive(:launch)
113
- guestfs.should_receive(:list_partitions).and_return(['/', '/boot'])
124
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
125
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
114
126
 
115
127
  Guestfs.should_receive(:create).and_return(guestfs)
116
128
 
117
- @helper.should_receive(:mount_partitions).with(no_args)
129
+ @helper.should_receive(:mount_partitions).with('/dev/vda', '')
118
130
  @helper.execute.should == @helper
119
131
  end
120
132
 
121
133
  it "should prepare and run guestfs with one partition" do
134
+ @appliance_config.stub!(:hardware).and_return(:partitions => {'/' => nil})
135
+
122
136
  guestfs = mock('Guestfs')
123
137
  guestfs.should_receive(:set_append).with('noapic')
124
138
  guestfs.should_receive(:set_verbose)
@@ -131,12 +145,15 @@ module BoxGrinder
131
145
  guestfs.should_receive(:add_drive).with('a/raw/disk')
132
146
  guestfs.should_receive(:set_network).with(1)
133
147
  guestfs.should_receive(:launch)
134
- guestfs.should_receive(:list_partitions).and_return(['/'])
148
+ guestfs.should_receive(:list_devices).and_return(['/dev/vda'])
149
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1'])
135
150
 
136
151
  Guestfs.should_receive(:create).and_return(guestfs)
137
152
 
138
- guestfs.should_receive(:list_partitions).and_return(['/'])
139
- @helper.should_receive(:mount_partition).with("/", "/")
153
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1'])
154
+ @helper.should_receive(:mount_partition).with("/dev/vda1", "/", '')
155
+
156
+ guestfs.should_receive(:set_e2label).with("/dev/vda1", "79d3d2d4")
140
157
 
141
158
  @helper.execute.should == @helper
142
159
  end
@@ -159,7 +176,7 @@ module BoxGrinder
159
176
  Guestfs.should_receive(:create).and_return(guestfs)
160
177
 
161
178
  guestfs.should_receive(:list_devices).and_return(['/dev/sda'])
162
- @helper.should_receive(:mount_partition).with("/dev/sda", "/")
179
+ @helper.should_receive(:mount_partition).with("/dev/sda", "/", '')
163
180
 
164
181
  @helper.execute.should == @helper
165
182
  end
@@ -186,62 +203,39 @@ module BoxGrinder
186
203
  @helper.mount_partition("/dev/sda", "/")
187
204
  end
188
205
 
189
- it "should mount partitions" do
190
- guestfs = mock('Guestfs')
191
-
192
- guestfs.should_receive(:list_partitions).and_return(['/boot', '/'])
193
-
194
- @helper.should_receive(:mount_partition).with('/boot', '/')
195
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(0)
196
- guestfs.should_receive(:umount).with('/boot')
197
- @helper.should_receive(:mount_partition).with('/', '/')
198
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(1)
199
-
200
- guestfs.should_receive(:list_partitions).and_return(['/boot', '/'])
201
- guestfs.should_receive(:sh).with('/sbin/e2label /boot').and_return('/boot')
202
- @helper.should_receive(:mount_partition).with('/boot', '/boot')
203
-
204
- @helper.instance_variable_set(:@guestfs, guestfs)
205
- @helper.mount_partitions
206
- end
207
-
208
- it "should mount partitions with new type of labels" do
209
- guestfs = mock('Guestfs')
210
-
211
- guestfs.should_receive(:list_partitions).and_return(['/boot', '/'])
212
-
213
- @helper.should_receive(:mount_partition).with('/boot', '/')
214
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(0)
215
- guestfs.should_receive(:umount).with('/boot')
216
- @helper.should_receive(:mount_partition).with('/', '/')
217
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(1)
206
+ describe ".mount_partitions" do
207
+ it "should mount partitions" do
208
+ guestfs = mock('Guestfs')
218
209
 
219
- guestfs.should_receive(:list_partitions).and_return(['/boot', '/'])
220
- guestfs.should_receive(:sh).with('/sbin/e2label /boot').and_return('_/boot')
221
- @helper.should_receive(:mount_partition).with('/boot', '/boot')
210
+ @appliance_config.stub!(:hardware).and_return(:partitions => {'/' => nil, '/home' => nil})
211
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
222
212
 
223
- @helper.instance_variable_set(:@guestfs, guestfs)
224
- @helper.mount_partitions
225
- end
213
+ @helper.should_receive(:mount_partition).with('/dev/vda1', '/', '')
214
+ guestfs.should_receive(:set_e2label).with("/dev/vda1", "79d3d2d4")
215
+ @helper.should_receive(:mount_partition).with('/dev/vda2', '/home', '')
216
+ guestfs.should_receive(:set_e2label).with("/dev/vda2", "d5219c04")
226
217
 
227
- it "should raise when no root partition is found" do
228
- guestfs = mock('Guestfs')
218
+ @helper.instance_variable_set(:@guestfs, guestfs)
219
+ @helper.mount_partitions('/dev/vda')
220
+ end
229
221
 
230
- guestfs.should_receive(:list_partitions).and_return(['/boot', '/'])
222
+ it "should mount partitions with extended partitions" do
223
+ guestfs = mock('Guestfs')
231
224
 
232
- @helper.should_receive(:mount_partition).with('/boot', '/')
233
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(0)
234
- guestfs.should_receive(:umount).with('/boot')
235
- @helper.should_receive(:mount_partition).with('/', '/')
236
- guestfs.should_receive(:exists).with('/sbin/e2label').and_return(0)
237
- guestfs.should_receive(:umount).with('/')
225
+ @appliance_config.stub!(:hardware).and_return(:partitions => {'/' => nil, '/home' => nil, '/var/www' => nil, '/var/mock' => nil})
226
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2', '/dev/vda3', '/dev/vda4', '/dev/vda5'])
238
227
 
239
- @helper.instance_variable_set(:@guestfs, guestfs)
228
+ @helper.should_receive(:mount_partition).with('/dev/vda1', '/', '')
229
+ guestfs.should_receive(:set_e2label).with("/dev/vda1", "79d3d2d4")
230
+ @helper.should_receive(:mount_partition).with('/dev/vda2', '/home', '')
231
+ guestfs.should_receive(:set_e2label).with("/dev/vda2", "d5219c04")
232
+ @helper.should_receive(:mount_partition).with('/dev/vda3', '/var/www', '')
233
+ guestfs.should_receive(:set_e2label).with("/dev/vda3", "8d86efc1")
234
+ @helper.should_receive(:mount_partition).with('/dev/vda5', '/var/mock', '')
235
+ guestfs.should_receive(:set_e2label).with("/dev/vda5", "e7b3b1f2")
240
236
 
241
- begin
242
- @helper.mount_partitions
243
- rescue => e
244
- e.message.should == "No root partition found for 'disk' disk!"
237
+ @helper.instance_variable_set(:@guestfs, guestfs)
238
+ @helper.mount_partitions('/dev/vda')
245
239
  end
246
240
  end
247
241
 
@@ -315,5 +309,28 @@ module BoxGrinder
315
309
  @helper.load_selinux_policy
316
310
  end
317
311
  end
312
+
313
+ describe ".umount_partitions" do
314
+ it "should umount partitions" do
315
+ guestfs = mock('Guestfs')
316
+ @helper.instance_variable_set(:@guestfs, guestfs)
317
+
318
+ guestfs.should_receive(:list_partitions).and_return(['/dev/vda1', '/dev/vda2'])
319
+
320
+ @helper.should_receive(:umount_partition).ordered.with('/dev/vda2')
321
+ @helper.should_receive(:umount_partition).ordered.with('/dev/vda1')
322
+
323
+ @helper.umount_partitions('/dev/vda')
324
+ end
325
+ end
326
+
327
+ describe ".umount_partition" do
328
+ it "should umount partition" do
329
+ guestfs = mock('Guestfs')
330
+ @helper.instance_variable_set(:@guestfs, guestfs)
331
+ guestfs.should_receive(:umount).with('/dev/vda1')
332
+ @helper.umount_partition('/dev/vda1')
333
+ end
334
+ end
318
335
  end
319
336
  end
@@ -16,6 +16,7 @@
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 'rubygems'
19
20
  require 'boxgrinder-build/helpers/image-helper'
20
21
 
21
22
  module BoxGrinder
@@ -48,131 +49,6 @@ module BoxGrinder
48
49
  @exec_helper = @helper.instance_variable_get(:@exec_helper)
49
50
  end
50
51
 
51
- it "should mount image with one root partition" do
52
- @helper.should_receive(:calculate_disk_offsets).with('disk.raw').and_return(['0'])
53
- FileUtils.should_receive(:mkdir_p).with('mount_dir')
54
- @helper.should_receive(:get_loop_device).and_return('/dev/loop0')
55
- @exec_helper.should_receive(:execute).with("losetup -o 0 /dev/loop0 'disk.raw'")
56
- @exec_helper.should_receive(:execute).with('e2label /dev/loop0').and_return('/')
57
- @exec_helper.should_receive(:execute).with("mount /dev/loop0 'mount_dir'")
58
- @helper.should_receive(:sleep).with(2)
59
-
60
- @helper.mount_image('disk.raw', 'mount_dir').should == {"/"=>"/dev/loop0"}
61
- end
62
-
63
- it "should mount image with two partitions with support for new livecd-tools partitions labels starting with '_'" do
64
- @helper.should_receive(:calculate_disk_offsets).with('disk.raw').and_return(['322', '562'])
65
- FileUtils.should_receive(:mkdir_p).with('mount_dir')
66
- @helper.should_receive(:get_loop_device).and_return('/dev/loop0')
67
- @exec_helper.should_receive(:execute).with("losetup -o 322 /dev/loop0 'disk.raw'")
68
- @exec_helper.should_receive(:execute).with('e2label /dev/loop0').and_return('_/home')
69
- @helper.should_receive(:get_loop_device).and_return('/dev/loop1')
70
- @exec_helper.should_receive(:execute).with("losetup -o 562 /dev/loop1 'disk.raw'")
71
- @exec_helper.should_receive(:execute).with('e2label /dev/loop1').and_return('_/')
72
-
73
- @exec_helper.should_receive(:execute).with("mount /dev/loop1 'mount_dir'")
74
- @exec_helper.should_receive(:execute).with("mount /dev/loop0 'mount_dir/home'")
75
- @helper.should_receive(:sleep).with(2)
76
-
77
- @helper.mount_image('disk.raw', 'mount_dir').should == {"/"=>"/dev/loop1", "/home"=>"/dev/loop0"}
78
- end
79
-
80
- it "should umount the image" do
81
- @exec_helper.should_receive(:execute).ordered.with('umount -d /dev/loop0')
82
- @exec_helper.should_receive(:execute).ordered.with('umount -d /dev/loop1')
83
- FileUtils.should_receive(:rm_rf).with('mount_dir')
84
-
85
- @helper.should_receive(:sleep).with(2)
86
-
87
- @helper.umount_image('disk.raw', 'mount_dir', {"/"=>"/dev/loop1", "/home"=>"/dev/loop0"})
88
- end
89
-
90
- it "should get free loop device" do
91
- @exec_helper.should_receive(:execute).with('losetup -f 2>&1').and_return("/dev/loop0\n")
92
-
93
- @helper.get_loop_device.should == '/dev/loop0'
94
- end
95
-
96
- it "shouldn't get free loop device because there are no free loop devices left" do
97
- @exec_helper.should_receive(:execute).with('losetup -f 2>&1').and_raise('boom')
98
-
99
- begin
100
- @helper.get_loop_device
101
- raise "Shouldn't raise"
102
- rescue => e
103
- e.message.should == "No free loop devices available, please free at least one. See 'losetup -d' command."
104
- end
105
- end
106
-
107
- it "should calculate disks offsets" do
108
- @helper.should_receive(:get_loop_device).and_return('/dev/loop0')
109
- @exec_helper.should_receive(:execute).ordered.with("losetup /dev/loop0 'disk.raw'")
110
- @exec_helper.should_receive(:execute).ordered.with("parted /dev/loop0 'unit B print' | grep -e '^ [0-9]' | awk '{ print $2 }'").and_return("0B\n1234B\n")
111
- @exec_helper.should_receive(:execute).ordered.with('losetup -d /dev/loop0')
112
- @helper.should_receive(:sleep).with(1)
113
-
114
- @helper.calculate_disk_offsets('disk.raw').should == ["0", "1234"]
115
- end
116
-
117
- it "should create a new empty disk image" do
118
- @exec_helper.should_receive(:execute).with("dd if=/dev/zero of='disk.raw' bs=1 count=0 seek=10240M")
119
-
120
- @helper.create_disk('disk.raw', 10)
121
- end
122
-
123
- describe ".create_filesystem" do
124
-
125
- it "should create default filesystem on selected device" do
126
- @exec_helper.should_receive(:execute).with("mke2fs -T ext4 -L '/' -F /dev/loop0")
127
-
128
- @helper.create_filesystem('/dev/loop0')
129
- end
130
-
131
- it "should create ext4 filesystem on selected device" do
132
- @appliance_config.should_receive(:hardware).and_return(
133
- OpenCascade.new({
134
- :partitions =>
135
- {
136
- '/' => {'size' => 2, 'type' => 'ext3'},
137
- '/home' => {'size' => 3, 'type' => 'ext3'},
138
- },
139
- :arch => 'i686',
140
- :base_arch => 'i386',
141
- :cpus => 1,
142
- :memory => 256,
143
- })
144
- )
145
-
146
- @exec_helper.should_receive(:execute).with("mke2fs -T ext3 -L '/' -F /dev/loop0")
147
-
148
- @helper.create_filesystem('/dev/loop0')
149
- end
150
-
151
- it "should create ext4 filesystem on selected device with a label" do
152
- @exec_helper.should_receive(:execute).with("mke2fs -T ext4 -L '/home' -F /dev/loop0")
153
-
154
- @helper.create_filesystem('/dev/loop0', :type => 'ext4', :label => '/home')
155
- end
156
-
157
- it "should create ext4 filesystem on selected device with a label" do
158
- lambda {
159
- @helper.create_filesystem('/dev/loop0', :type => 'ext256', :label => '/home')
160
- }.should raise_error(RuntimeError, "Unsupported filesystem specified: ext256")
161
- end
162
- end
163
-
164
- describe ".sync_files" do
165
- it "should sync files" do
166
- @exec_helper.should_receive(:execute).with("rsync -Xura from_dir/* 'to_dir'")
167
- @helper.sync_files('from_dir', 'to_dir')
168
- end
169
-
170
- it "should sync files with a space in path" do
171
- @exec_helper.should_receive(:execute).with("rsync -Xura from\\ /dir/* 'to_dir'")
172
- @helper.sync_files('from /dir', 'to_dir')
173
- end
174
- end
175
-
176
52
  describe ".customize" do
177
53
  it "should customize the disk image using GuestFS" do
178
54
  guestfs = mock('GuestFS')
@@ -182,9 +58,9 @@ module BoxGrinder
182
58
  guestfs_helper.should_receive(:customize).with(:ide_disk => false).ordered.and_yield(guestfs, guestfs_helper)
183
59
  guestfs_helper.should_receive(:def)
184
60
 
185
- GuestFSHelper.should_receive(:new).with('disk.raw', :log => @log).and_return(guestfs_helper)
61
+ GuestFSHelper.should_receive(:new).with(['disk.raw'], @appliance_config, @config, :log => @log).and_return(guestfs_helper)
186
62
 
187
- @helper.customize('disk.raw') do |guestfs, guestfs_helper|
63
+ @helper.customize(['disk.raw']) do |guestfs, guestfs_helper|
188
64
  guestfs.abc
189
65
  guestfs_helper.def
190
66
  end
@@ -200,9 +76,9 @@ module BoxGrinder
200
76
  guestfs_helper.should_receive(:customize).with(:ide_disk => true).ordered.and_yield(guestfs, guestfs_helper)
201
77
  guestfs_helper.should_receive(:def)
202
78
 
203
- GuestFSHelper.should_receive(:new).with('disk.raw', :log => @log).and_return(guestfs_helper)
79
+ GuestFSHelper.should_receive(:new).with(['disk.raw'], @appliance_config, @config, :log => @log).and_return(guestfs_helper)
204
80
 
205
- @helper.customize('disk.raw') do |guestfs, guestfs_helper|
81
+ @helper.customize(['disk.raw']) do |guestfs, guestfs_helper|
206
82
  guestfs.abc
207
83
  guestfs_helper.def
208
84
  end
@@ -243,6 +119,89 @@ module BoxGrinder
243
119
  @helper.convert_disk('a/disk', :vmdk, 'destination')
244
120
  end
245
121
  end
122
+
123
+ describe ".sync_filesystem" do
124
+ it "should sync filesystems between raw disk with two partitions and a partition image" do
125
+ guestfs = mock('GuestFS')
126
+ guestfs_helper = mock(GuestFSHelper)
127
+
128
+ guestfs.should_receive(:list_devices).once.times.ordered.and_return(['/dev/vda', '/dev/vdb'])
129
+ guestfs.should_receive(:list_partitions).once.ordered.and_return(['/dev/vda1', '/dev/vda2'])
130
+
131
+ guestfs_helper.should_receive(:mount_partitions).with('/dev/vda')
132
+ guestfs_helper.should_receive(:load_selinux_policy)
133
+ guestfs_helper.should_receive(:umount_partitions).with('/dev/vda')
134
+
135
+ @appliance_config.stub!(:default_filesystem_type).and_return('ext4')
136
+
137
+ guestfs.should_receive(:mkmountpoint).ordered.with('/in')
138
+ guestfs.should_receive(:mkmountpoint).ordered.with('/out')
139
+ guestfs.should_receive(:mkmountpoint).ordered.with('/out/in')
140
+
141
+ guestfs.should_receive(:mkfs).ordered.with("ext4", "/dev/vdb")
142
+ guestfs.should_receive(:set_e2label).ordered.with("/dev/vdb", '79d3d2d4')
143
+
144
+ guestfs_helper.should_receive(:mount_partition).ordered.with("/dev/vdb", '/out/in')
145
+ guestfs_helper.should_receive(:mount_partitions).ordered.with('/dev/vda', '/in')
146
+
147
+ guestfs.should_receive(:cp_a).ordered.with("/in/", "/out")
148
+ guestfs.should_receive(:sync).ordered
149
+
150
+ guestfs_helper.should_receive(:umount_partition).ordered.with('/dev/vdb')
151
+ guestfs_helper.should_receive(:umount_partitions).ordered.with('/dev/vda')
152
+
153
+ guestfs.should_receive(:rmmountpoint).ordered.with('/out/in')
154
+ guestfs.should_receive(:rmmountpoint).ordered.with('/out')
155
+ guestfs.should_receive(:rmmountpoint).ordered.with('/in')
156
+
157
+ guestfs_helper.should_receive(:mount_partition).ordered.with("/dev/vdb", '/')
158
+
159
+ @helper.sync_filesystem(guestfs, guestfs_helper)
160
+ end
161
+
162
+ it "should sync filesystems between partition image and another partition image" do
163
+ guestfs = mock('GuestFS')
164
+ guestfs_helper = mock(GuestFSHelper)
165
+
166
+ guestfs.should_receive(:list_devices).once.times.ordered.and_return(['/dev/vda', '/dev/vdb'])
167
+ guestfs.should_receive(:list_partitions).once.ordered.and_return([])
168
+
169
+ guestfs_helper.should_receive(:mount_partition).with('/dev/vda', '/')
170
+ guestfs_helper.should_receive(:load_selinux_policy)
171
+ guestfs_helper.should_receive(:umount_partition).with('/dev/vda')
172
+
173
+ @appliance_config.stub!(:default_filesystem_type).and_return('ext4')
174
+
175
+ guestfs.should_receive(:mkmountpoint).ordered.with('/in')
176
+ guestfs.should_receive(:mkmountpoint).ordered.with('/out')
177
+ guestfs.should_receive(:mkmountpoint).ordered.with('/out/in')
178
+
179
+ guestfs.should_receive(:mkfs).ordered.with("ext4", "/dev/vdb")
180
+ guestfs.should_receive(:set_e2label).ordered.with("/dev/vdb", '79d3d2d4')
181
+
182
+ guestfs_helper.should_receive(:mount_partition).ordered.with("/dev/vdb", '/out/in')
183
+ guestfs_helper.should_receive(:mount_partition).ordered.with('/dev/vda', '/in')
184
+
185
+ guestfs.should_receive(:cp_a).ordered.with("/in/", "/out")
186
+ guestfs.should_receive(:sync).ordered
187
+
188
+ guestfs_helper.should_receive(:umount_partition).ordered.with('/dev/vdb')
189
+ guestfs_helper.should_receive(:umount_partition).ordered.with('/dev/vda')
190
+
191
+ guestfs.should_receive(:rmmountpoint).ordered.with('/out/in')
192
+ guestfs.should_receive(:rmmountpoint).ordered.with('/out')
193
+ guestfs.should_receive(:rmmountpoint).ordered.with('/in')
194
+
195
+ guestfs_helper.should_receive(:mount_partition).ordered.with("/dev/vdb", '/')
196
+
197
+ @helper.sync_filesystem(guestfs, guestfs_helper)
198
+ end
199
+ end
200
+
201
+ it "should create a 10GB disk" do
202
+ @exec_helper.should_receive(:execute).with("dd if=/dev/zero of='/path/disk.raw' bs=1 count=0 seek=10240M")
203
+ @helper.create_disk('/path/disk.raw', 10)
204
+ end
246
205
  end
247
206
  end
248
207
 
@@ -16,13 +16,14 @@
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 'rubygems'
19
20
  require 'boxgrinder-build/helpers/linux-helper'
20
21
 
21
22
  module BoxGrinder
22
23
  describe LinuxHelper do
23
24
 
24
25
  before(:each) do
25
- @helper = LinuxHelper.new( :log => Logger.new('/dev/null') )
26
+ @helper = LinuxHelper.new(:log => Logger.new('/dev/null'))
26
27
 
27
28
  @log = @helper.instance_variable_get(:@log)
28
29
  end
@@ -30,13 +31,13 @@ module BoxGrinder
30
31
  it "should return valid kernel version" do
31
32
  guestfs = mock("guestfs")
32
33
  guestfs.should_receive(:ls).with('/lib/modules').and_return(['2.6.33.6-147.fc13.i686'])
33
- @helper.kernel_version( guestfs ).should == '2.6.33.6-147.fc13.i686'
34
+ @helper.kernel_version(guestfs).should == '2.6.33.6-147.fc13.i686'
34
35
  end
35
36
 
36
37
  it "should return valid PAE kernel version" do
37
38
  guestfs = mock("guestfs")
38
39
  guestfs.should_receive(:ls).with('/lib/modules').and_return(['2.6.33.6-147.fc13.i686.PAE', '2.6.33.6-147.fc13.i686'])
39
- @helper.kernel_version( guestfs ).should == '2.6.33.6-147.fc13.i686.PAE'
40
+ @helper.kernel_version(guestfs).should == '2.6.33.6-147.fc13.i686.PAE'
40
41
  end
41
42
 
42
43
  it "should recreate initramfs kernel image using dracut and add xennet module" do
@@ -48,7 +49,7 @@ module BoxGrinder
48
49
  guestfs.should_receive(:exists).with('/sbin/dracut').and_return(1)
49
50
  guestfs.should_receive(:sh).with("/sbin/dracut -f -v --add-drivers xennet /boot/initramfs-2.6.33.6-147.fc13.i686.PAE.img 2.6.33.6-147.fc13.i686.PAE")
50
51
 
51
- @helper.recreate_kernel_image( guestfs, ['xennet'] )
52
+ @helper.recreate_kernel_image(guestfs, ['xennet'])
52
53
  end
53
54
 
54
55
  it "should recreate initrd kernel image using mkinitrd and add xenblk and xennet module" do
@@ -60,9 +61,25 @@ module BoxGrinder
60
61
  guestfs.should_receive(:exists).with('/sbin/dracut').and_return(0)
61
62
  guestfs.should_receive(:sh).with("/sbin/mkinitrd -f -v --preload=xenblk --preload=xennet /boot/initrd-2.6.33.6-147.fc13.i686.PAE.img 2.6.33.6-147.fc13.i686.PAE")
62
63
 
63
- @helper.recreate_kernel_image( guestfs, ['xenblk', 'xennet'] )
64
+ @helper.recreate_kernel_image(guestfs, ['xenblk', 'xennet'])
64
65
  end
65
66
 
67
+ describe ".partition_mount_points" do
68
+ it "should return ['/', '/home']" do
69
+ hash = {"/"=>{"size"=>2, "type"=>"ext3"}, "/home"=>{"size"=>2, "type"=>"ext3"}}
70
+ @helper.partition_mount_points(hash).should == ['/', '/home']
71
+ end
72
+
73
+ it "should return ['/', '/ubrc', '/tmp-config', '/tmp-eventlog']" do
74
+ hash = {"/tmp-eventlog"=>{"size"=>0.01, "type"=>"ext3"}, "/"=>{"size"=>2, "type"=>"ext3"}, "/ubrc"=>{"size"=>0.02, "type"=>"ext3"}, "/tmp-config"=>{"size"=>0.26}}
75
+ @helper.partition_mount_points(hash).should == ["/", "/ubrc", "/tmp-config", "/tmp-eventlog"]
76
+ end
77
+
78
+ it "should return ['/', '/tmp-config', '/tmp-eventlog', '/var/www']" do
79
+ hash = {"/tmp-eventlog"=>{}, "/"=>{}, "/var/www"=>{}, "/tmp-config"=>{}}
80
+ @helper.partition_mount_points(hash).should == ['/', '/tmp-config', '/tmp-eventlog', '/var/www']
81
+ end
82
+ end
66
83
  end
67
84
  end
68
85
 
@@ -16,6 +16,7 @@
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 'rubygems'
19
20
  require 'logger'
20
21
  require 'boxgrinder-build/helpers/package-helper'
21
22
 
@@ -16,6 +16,7 @@
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 'rubygems'
19
20
  require 'boxgrinder-core/helpers/log-helper'
20
21
  require 'boxgrinder-build/helpers/plugin-helper'
21
22
  require 'ostruct'
@@ -16,6 +16,7 @@
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 'rubygems'
19
20
  require 'boxgrinder-build/managers/plugin-manager'
20
21
 
21
22
  module BoxGrinder
@@ -28,14 +29,14 @@ module BoxGrinder
28
29
  it "should register simple plugin" do
29
30
  @manager.register_plugin({:class => PluginManager, :type => :delivery, :name => :abc, :full_name => "Amazon Simple Storage Service (Amazon S3)"})
30
31
 
31
- @manager.plugins[:delivery].size.should == 7
32
+ @manager.plugins[:delivery].size.should == 8
32
33
  @manager.plugins[:delivery][:abc][:class].should == PluginManager
33
34
  end
34
35
 
35
36
  it "should register plugin with many types" do
36
37
  @manager.register_plugin({:class => PluginManager, :type => :delivery, :name => :def, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:aaa, :bbb, :ccc]})
37
38
 
38
- @manager.plugins[:delivery].size.should == 10
39
+ @manager.plugins[:delivery].size.should == 11
39
40
  @manager.plugins[:delivery][:abc][:class].should == PluginManager
40
41
  @manager.plugins[:delivery][:aaa][:class].should == PluginManager
41
42
  @manager.plugins[:delivery][:bbb][:class].should == PluginManager
@@ -212,7 +212,7 @@ module BoxGrinder
212
212
 
213
213
  lambda {
214
214
  @plugin.validate_plugin_config(['one', 'two', 'three'])
215
- }.should raise_error(RuntimeError, "Please specify a valid 'three' key in BoxGrinder configuration file: '/home/abc/boxgrinder_config_file' or use CLI '---config three:DATA' argument. ")
215
+ }.should raise_error(PluginValidationError, "Please specify a valid 'three' key in BoxGrinder configuration file: '/home/abc/boxgrinder_config_file' or use CLI '---config three:DATA' argument. ")
216
216
  end
217
217
  end
218
218