boxgrinder-build 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGELOG +14 -0
  2. data/README.md +136 -0
  3. data/Rakefile +11 -6
  4. data/bin/boxgrinder-build +199 -0
  5. data/boxgrinder-build.gemspec +26 -14
  6. data/lib/boxgrinder-build/appliance.rb +6 -6
  7. data/lib/boxgrinder-build/helpers/guestfs-helper.rb +5 -3
  8. data/lib/boxgrinder-build/helpers/image-helper.rb +6 -0
  9. data/lib/boxgrinder-build/helpers/plugin-helper.rb +15 -4
  10. data/lib/boxgrinder-build/plugins/base-plugin.rb +1 -0
  11. data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +280 -0
  12. data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +66 -0
  13. data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +242 -0
  14. data/lib/boxgrinder-build/plugins/delivery/s3/src/cert-ec2.pem +23 -0
  15. data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +152 -0
  16. data/lib/boxgrinder-build/plugins/delivery/usb/usb-plugin.rb +43 -0
  17. data/lib/boxgrinder-build/plugins/os/centos/centos-plugin.rb +46 -0
  18. data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +61 -0
  19. data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +67 -0
  20. data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +118 -0
  21. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +202 -0
  22. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +153 -0
  23. data/lib/boxgrinder-build/plugins/os/rpm-based/src/appliance.ks.erb +37 -0
  24. data/lib/boxgrinder-build/plugins/os/rpm-based/src/base.repo +4 -0
  25. data/lib/boxgrinder-build/plugins/os/rpm-based/src/motd.init +21 -0
  26. data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +239 -0
  27. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_32bit +7 -0
  28. data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_64bit +7 -0
  29. data/lib/boxgrinder-build/plugins/platform/ec2/src/ifcfg-eth0 +7 -0
  30. data/lib/boxgrinder-build/plugins/platform/ec2/src/menu.lst +6 -0
  31. data/lib/boxgrinder-build/plugins/platform/ec2/src/rc_local +19 -0
  32. data/lib/boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin.rb +62 -0
  33. data/lib/boxgrinder-build/plugins/platform/vmware/src/README-enterprise +18 -0
  34. data/lib/boxgrinder-build/plugins/platform/vmware/src/README-personal +16 -0
  35. data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmdk +20 -0
  36. data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmx +45 -0
  37. data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +194 -0
  38. data/rubygem-boxgrinder-build.spec +73 -10
  39. data/spec/appliance-spec.rb +2 -2
  40. data/spec/helpers/guestfs-helper-spec.rb +4 -2
  41. data/spec/helpers/image-helper-spec.rb +4 -0
  42. data/spec/helpers/plugin-helper-spec.rb +0 -38
  43. data/spec/managers/plugin-manager-spec.rb +6 -6
  44. data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +230 -0
  45. data/spec/plugins/delivery/ebs/ebs.yaml +3 -0
  46. data/spec/plugins/delivery/local/local-plugin-spec.rb +133 -0
  47. data/spec/plugins/delivery/s3/s3-plugin-spec.rb +351 -0
  48. data/spec/plugins/delivery/sftp/sftp-plugin-spec.rb +26 -0
  49. data/spec/plugins/os/centos/centos-plugin-spec.rb +52 -0
  50. data/spec/plugins/os/fedora/fedora-plugin-spec.rb +73 -0
  51. data/spec/plugins/os/rhel/rhel-plugin-spec.rb +158 -0
  52. data/spec/plugins/os/rpm-based/kickstart-spec.rb +129 -0
  53. data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +162 -0
  54. data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +50 -0
  55. data/spec/plugins/os/rpm-based/src/jeos-f13-plain.ks +20 -0
  56. data/spec/plugins/os/rpm-based/src/jeos-f13-without-version.ks +22 -0
  57. data/spec/plugins/os/rpm-based/src/jeos-f13.ks +23 -0
  58. data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +339 -0
  59. data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +118 -0
  60. data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +299 -0
  61. metadata +149 -25
  62. data/README +0 -7
  63. data/bin/boxgrinder +0 -128
  64. data/lib/boxgrinder-build/helpers/thor-helper.rb +0 -85
@@ -0,0 +1,339 @@
1
+ #
2
+ # Copyright 2010 Red Hat, Inc.
3
+ #
4
+ # This is free software; you can redistribute it and/or modify it
5
+ # under the terms of the GNU Lesser General Public License as
6
+ # published by the Free Software Foundation; either version 3 of
7
+ # the License, or (at your option) any later version.
8
+ #
9
+ # This software is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this software; if not, write to the Free
16
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
+
19
+ require 'boxgrinder-build/plugins/platform/ec2/ec2-plugin'
20
+ require 'boxgrinder-core/helpers/log-helper'
21
+ require 'hashery/opencascade'
22
+
23
+ module BoxGrinder
24
+ describe EC2Plugin do
25
+ before(:each) do
26
+ @config = mock('Config')
27
+ @config.stub!(:platform_config).and_return({})
28
+ plugins = mock('Plugins')
29
+ plugins.stub!(:[]).with('ec2').and_return({})
30
+ @config.stub!(:[]).with(:plugins).and_return(plugins)
31
+
32
+ @appliance_config = mock('ApplianceConfig')
33
+
34
+ @appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
35
+ @appliance_config.stub!(:name).and_return('full')
36
+ @appliance_config.stub!(:version).and_return(1)
37
+ @appliance_config.stub!(:release).and_return(0)
38
+ @appliance_config.stub!(:packages).and_return(["gcc-c++", "wget"])
39
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '13'}))
40
+ @appliance_config.stub!(:is64bit?).and_return(false)
41
+ @appliance_config.stub!(:post).and_return(OpenCascade.new)
42
+
43
+ @appliance_config.stub!(:hardware).and_return(
44
+ OpenCascade.new({
45
+ :partitions =>
46
+ {
47
+ '/' => {'size' => 2, 'type' => 'ext4'},
48
+ '/home' => {'size' => 3, 'type' => 'ext4'},
49
+ },
50
+ :arch => 'i686',
51
+ :base_arch => 'i386',
52
+ :cpus => 1,
53
+ :memory => 256,
54
+ })
55
+ )
56
+
57
+ @plugin = EC2Plugin.new.init(@config, @appliance_config, :previous_deliverables => OpenCascade.new(:disk => 'a/disk.raw'), :log => LogHelper.new(:level => :trace, :type => :stdout), :plugin_info => {:class => BoxGrinder::EC2Plugin, :type => :platform, :name => :ec2, :full_name => "Amazon Elastic Compute Cloud (Amazon EC2)"})
58
+
59
+ @config = @plugin.instance_variable_get(:@config)
60
+ @appliance_config = @plugin.instance_variable_get(:@appliance_config)
61
+ @image_helper = @plugin.instance_variable_get(:@image_helper)
62
+ @exec_helper = @plugin.instance_variable_get(:@exec_helper)
63
+ @log = @plugin.instance_variable_get(:@log)
64
+ end
65
+
66
+ it "should create devices" do
67
+ guestfs = mock("guestfs")
68
+
69
+ guestfs.should_receive(:exists).with("/sbin/MAKEDEV").and_return(1)
70
+ guestfs.should_receive(:sh).once.with("/sbin/MAKEDEV -d /dev -x console")
71
+ guestfs.should_receive(:sh).once.with("/sbin/MAKEDEV -d /dev -x null")
72
+ guestfs.should_receive(:sh).once.with("/sbin/MAKEDEV -d /dev -x zero")
73
+
74
+ @log.should_receive(:debug).once.with("Creating required devices...")
75
+ @log.should_receive(:debug).once.with("Devices created.")
76
+
77
+ @plugin.create_devices(guestfs)
78
+ end
79
+
80
+ it "should upload fstab" do
81
+ guestfs = mock("guestfs")
82
+
83
+ guestfs.should_receive(:upload).once.with(any_args(), "/etc/fstab")
84
+
85
+ @log.should_receive(:debug).once.with("Uploading '/etc/fstab' file...")
86
+ @log.should_receive(:debug).once.with("'/etc/fstab' file uploaded.")
87
+
88
+ @plugin.upload_fstab(guestfs)
89
+ end
90
+
91
+ it "should enable networking" do
92
+ guestfs = mock("guestfs")
93
+
94
+ guestfs.should_receive(:sh).once.with("/sbin/chkconfig network on")
95
+ guestfs.should_receive(:upload).once.with(any_args(), "/etc/sysconfig/network-scripts/ifcfg-eth0")
96
+
97
+ @log.should_receive(:debug).once.with("Enabling networking...")
98
+ @log.should_receive(:debug).once.with("Networking enabled.")
99
+
100
+ @plugin.enable_networking(guestfs)
101
+ end
102
+
103
+ it "should upload rc_local" do
104
+ guestfs = mock("guestfs")
105
+ tempfile = mock("tempfile")
106
+
107
+ Tempfile.should_receive(:new).with("rc_local").and_return(tempfile)
108
+ File.should_receive(:read).with(any_args()).and_return("with other content")
109
+
110
+ guestfs.should_receive(:read_file).once.ordered.with("/etc/rc.local").and_return("content ")
111
+ tempfile.should_receive(:<<).once.ordered.with("content with other content")
112
+ tempfile.should_receive(:flush).once.ordered
113
+ tempfile.should_receive(:path).once.ordered.and_return("path")
114
+ guestfs.should_receive(:upload).once.ordered.with("path", "/etc/rc.local")
115
+ tempfile.should_receive(:close).once.ordered
116
+
117
+ @log.should_receive(:debug).once.with("Uploading '/etc/rc.local' file...")
118
+ @log.should_receive(:debug).once.with("'/etc/rc.local' file uploaded.")
119
+
120
+ @plugin.upload_rc_local(guestfs)
121
+ end
122
+
123
+ it "should change configuration" do
124
+ guestfs_helper = mock("GuestFSHelper")
125
+
126
+ guestfs_helper.should_receive(:augeas).and_yield do |block|
127
+ block.should_receive(:set).with("/etc/ssh/sshd_config", "PasswordAuthentication", "no")
128
+ block.should_receive(:set).with("/etc/ssh/sshd_config", "PermitRootLogin", "no")
129
+ end
130
+
131
+ @plugin.change_configuration(guestfs_helper)
132
+ end
133
+
134
+ it "should install GRUB menu.lst" do
135
+ guestfs = mock("guestfs")
136
+
137
+ guestfs.should_receive(:upload).with('path/menu.lst', "/boot/grub/menu.lst")
138
+
139
+ linux_helper = mock("LinuxHelper")
140
+
141
+ linux_helper.should_receive(:kernel_version).with(guestfs).and_return('2.6.18')
142
+ linux_helper.should_receive(:kernel_image_name).with(guestfs).and_return('vmlinuz')
143
+
144
+ @plugin.instance_variable_set(:@linux_helper, linux_helper)
145
+
146
+ tempfile = mock(Tempfile)
147
+ tempfile.should_receive(:<<).with("default=0\ntimeout=0\ntitle full\n root (hd0)\n kernel /boot/vmlinuz-2.6.18 ro root=LABEL=/ rd_NO_PLYMOUTH\n initrd /boot/vmlinuz-2.6.18.img")
148
+ tempfile.should_receive(:flush)
149
+ tempfile.should_receive(:path).and_return('path/menu.lst')
150
+ tempfile.should_receive(:close)
151
+
152
+ Tempfile.should_receive(:new).with('menu_lst').and_return(tempfile)
153
+
154
+ @plugin.install_menu_lst(guestfs)
155
+ end
156
+
157
+ describe ".disk_device_prefix" do
158
+ it "should use xvda disks for Fedora 13" do
159
+ @appliance_config.os.version = '13'
160
+ @plugin.disk_device_prefix.should == 'xv'
161
+ end
162
+
163
+ it "should use xvda disks for Fedora 12" do
164
+ @appliance_config.os.version = '12'
165
+ @plugin.disk_device_prefix.should == 'xv'
166
+ end
167
+
168
+ it "should use sda disks for RHEL/CentOS 5" do
169
+ @appliance_config.os.name = 'rhel'
170
+ @appliance_config.os.version = '5'
171
+ @plugin.disk_device_prefix.should == 's'
172
+ end
173
+ end
174
+
175
+ it "should enable nosegneg flag" do
176
+ guestfs = mock("guestfs")
177
+
178
+ guestfs.should_receive(:sh).with("echo \"hwcap 1 nosegneg\" > /etc/ld.so.conf.d/libc6-xen.conf")
179
+ guestfs.should_receive(:sh).with("/sbin/ldconfig")
180
+
181
+ @plugin.enable_nosegneg_flag(guestfs)
182
+ end
183
+
184
+ it "should add ec2-user account" do
185
+ guestfs = mock("guestfs")
186
+
187
+ guestfs.should_receive(:sh).with("useradd ec2-user")
188
+ guestfs.should_receive(:sh).with("echo -e 'ec2-user\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers")
189
+
190
+ @plugin.add_ec2_user(guestfs)
191
+ end
192
+
193
+ describe ".execute" do
194
+ it "should convert the appliance to EC2 format" do
195
+ linux_helper = mock(LinuxHelper)
196
+
197
+ LinuxHelper.should_receive(:new).with(:log => @log).and_return(linux_helper)
198
+
199
+ @image_helper.should_receive(:convert_disk).with("a/disk.raw").with("a/disk.raw", "raw", "build/path/ec2-plugin/tmp/full.raw")
200
+
201
+ @image_helper.should_receive(:create_disk).with("build/path/ec2-plugin/tmp/full.ec2", 10)
202
+ @image_helper.should_receive(:create_filesystem).with("build/path/ec2-plugin/tmp/full.ec2")
203
+ @image_helper.should_receive(:mount_image).twice
204
+ @image_helper.should_receive(:sync_files)
205
+ @image_helper.should_receive(:umount_image).twice
206
+
207
+ guestfs = mock("guestfs")
208
+ guestfs_helper = mock("guestfsHelper")
209
+
210
+ @image_helper.should_receive(:customize).with("build/path/ec2-plugin/tmp/full.ec2").and_yield(guestfs, guestfs_helper)
211
+
212
+ guestfs.should_receive(:upload).with("/etc/resolv.conf", "/etc/resolv.conf")
213
+ @plugin.should_receive(:create_devices).with(guestfs)
214
+ @plugin.should_receive(:upload_fstab).with(guestfs)
215
+
216
+
217
+ @plugin.should_receive(:enable_networking).with(guestfs)
218
+ @plugin.should_receive(:upload_rc_local).with(guestfs)
219
+ @plugin.should_receive(:enable_nosegneg_flag).with(guestfs)
220
+ @plugin.should_receive(:add_ec2_user).with(guestfs)
221
+ @plugin.should_receive(:change_configuration).with(guestfs_helper)
222
+ @plugin.should_receive(:install_menu_lst).with(guestfs)
223
+ @plugin.should_receive(:execute_post).with(guestfs_helper)
224
+
225
+ linux_helper.should_not_receive(:recreate_kernel_image)
226
+
227
+ @plugin.execute
228
+ end
229
+
230
+ it "should recreate kernel image while converting to EC2 format for RHEL/CentOS 5" do
231
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
232
+ @appliance_config.stub!(:is64bit?).and_return(true)
233
+
234
+ linux_helper = mock(LinuxHelper)
235
+
236
+ LinuxHelper.should_receive(:new).with(:log => @log).and_return(linux_helper)
237
+
238
+ @image_helper.should_receive(:convert_disk).with("a/disk.raw").with("a/disk.raw", "raw", "build/path/ec2-plugin/tmp/full.raw")
239
+
240
+ @image_helper.should_receive(:create_disk).with("build/path/ec2-plugin/tmp/full.ec2", 10)
241
+ @image_helper.should_receive(:create_filesystem).with("build/path/ec2-plugin/tmp/full.ec2")
242
+ @image_helper.should_receive(:mount_image).twice
243
+ @image_helper.should_receive(:sync_files)
244
+ @image_helper.should_receive(:umount_image).twice
245
+
246
+ guestfs = mock("guestfs")
247
+ guestfs_helper = mock("guestfsHelper")
248
+
249
+ @image_helper.should_receive(:customize).with("build/path/ec2-plugin/tmp/full.ec2").and_yield(guestfs, guestfs_helper)
250
+
251
+ guestfs.should_receive(:upload).with("/etc/resolv.conf", "/etc/resolv.conf")
252
+ guestfs.should_receive(:mkdir).with("/data")
253
+ guestfs.should_receive(:sh).with("yum -y remove kernel")
254
+ guestfs.should_receive(:sh).with("yum -y install kernel-xen")
255
+
256
+ @plugin.should_receive(:create_devices).with(guestfs)
257
+ @plugin.should_receive(:upload_fstab).with(guestfs)
258
+
259
+ @plugin.should_receive(:recreate_journal).with(guestfs)
260
+ @plugin.should_receive(:enable_networking)
261
+ @plugin.should_receive(:upload_rc_local).with(guestfs)
262
+ @plugin.should_receive(:add_ec2_user).with(guestfs)
263
+ @plugin.should_receive(:change_configuration).with(guestfs_helper)
264
+ @plugin.should_receive(:install_menu_lst).with(guestfs)
265
+ @plugin.should_receive(:execute_post).with(guestfs_helper)
266
+
267
+ @plugin.should_not_receive(:enable_nosegneg_flag)
268
+
269
+ linux_helper.should_receive(:recreate_kernel_image).with(guestfs, ['xenblk', 'xennet'])
270
+
271
+ @plugin.execute
272
+ end
273
+
274
+ it "should fail because preparing disk failed" do
275
+ linux_helper = mock(LinuxHelper)
276
+
277
+ LinuxHelper.should_receive(:new).with(:log => @log).and_return(linux_helper)
278
+
279
+ @image_helper.should_receive(:create_disk).and_raise("This error is expected!")
280
+ @image_helper.should_not_receive(:create_filesystem)
281
+ @image_helper.should_not_receive(:mount_image)
282
+
283
+ @image_helper.should_not_receive(:customize)
284
+
285
+ lambda {
286
+ @plugin.execute
287
+ }.should raise_error(RuntimeError, "Error while preparing EC2 disk image. See logs for more info.")
288
+ end
289
+
290
+ it "should fail because mounting or unmounting failed" do
291
+ linux_helper = mock(LinuxHelper)
292
+
293
+ LinuxHelper.should_receive(:new).with(:log => @log).and_return(linux_helper)
294
+
295
+ @image_helper.should_receive(:convert_disk).with("a/disk.raw").with("a/disk.raw", "raw", "build/path/ec2-plugin/tmp/full.raw")
296
+
297
+ @image_helper.should_receive(:create_disk).with("build/path/ec2-plugin/tmp/full.ec2", 10)
298
+ @image_helper.should_receive(:create_filesystem).with("build/path/ec2-plugin/tmp/full.ec2")
299
+ @image_helper.should_receive(:mount_image).and_raise("This error is expected!")
300
+
301
+ @image_helper.should_not_receive(:customize)
302
+
303
+ lambda {
304
+ @plugin.execute
305
+ }.should raise_error(RuntimeError, "Error while mounting image. See logs for more info.")
306
+ end
307
+ end
308
+
309
+ describe ".execute_post" do
310
+ it "should execute post commands" do
311
+ @appliance_config.stub!(:post).and_return(OpenCascade.new({'ec2' => ['ls /']}))
312
+
313
+ guestfs_helper = mock("guestfsHelper")
314
+ guestfs_helper.should_receive(:sh).with('ls /', :arch => 'i686')
315
+
316
+ @plugin.execute_post(guestfs_helper)
317
+ end
318
+
319
+ it "should not execute post commands because there are no commands to execute :)" do
320
+ @appliance_config.stub!(:post).and_return(OpenCascade.new)
321
+
322
+ guestfs_helper = mock("guestfsHelper")
323
+ guestfs_helper.should_not_receive(:sh)
324
+
325
+ @plugin.execute_post(guestfs_helper)
326
+ end
327
+ end
328
+
329
+ it "should recreate journal" do
330
+ guestfs = mock("guestfs")
331
+
332
+ guestfs.should_receive(:list_devices).and_return(['/dev/sda'])
333
+ guestfs.should_receive(:sh).with("tune2fs -j /dev/sda")
334
+
335
+ @plugin.recreate_journal(guestfs)
336
+ end
337
+ end
338
+ end
339
+
@@ -0,0 +1,118 @@
1
+ #
2
+ # Copyright 2010 Red Hat, Inc.
3
+ #
4
+ # This is free software; you can redistribute it and/or modify it
5
+ # under the terms of the GNU Lesser General Public License as
6
+ # published by the Free Software Foundation; either version 3 of
7
+ # the License, or (at your option) any later version.
8
+ #
9
+ # This software is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this software; if not, write to the Free
16
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
+
19
+ require 'boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin'
20
+ require 'hashery/opencascade'
21
+
22
+ module BoxGrinder
23
+ describe VirtualBoxPlugin do
24
+ def prepare_image(options = {})
25
+ @config = mock('Config')
26
+ @config.stub!(:version).and_return('0.1.2')
27
+ @config.stub!(:platform_config).and_return({})
28
+
29
+ @appliance_config = mock('ApplianceConfig')
30
+
31
+ @appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
32
+ @appliance_config.stub!(:name).and_return('full')
33
+ @appliance_config.stub!(:summary).and_return('asd')
34
+ @appliance_config.stub!(:version).and_return(1)
35
+ @appliance_config.stub!(:release).and_return(0)
36
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '14'}))
37
+ @appliance_config.stub!(:post).and_return(OpenCascade.new({:virtualbox => []}))
38
+
39
+ @appliance_config.stub!(:hardware).and_return(
40
+ OpenCascade.new({
41
+ :partitions =>
42
+ {
43
+ '/' => {'size' => 2},
44
+ '/home' => {'size' => 3},
45
+ },
46
+ :arch => 'i686',
47
+ :base_arch => 'i386',
48
+ :cpus => 1,
49
+ :memory => 256,
50
+ })
51
+ )
52
+
53
+ options[:log] = LogHelper.new(:level => :trace, :type => :stdout)
54
+ options[:plugin_info] = {:class => BoxGrinder::VirtualBoxPlugin, :type => :platform, :name => :virtualbox, :full_name => "VirtualBox"}
55
+ @plugin = VirtualBoxPlugin.new
56
+
57
+ @plugin.should_receive(:read_plugin_config)
58
+ @plugin.init(@config, @appliance_config, options)
59
+
60
+ @exec_helper = @plugin.instance_variable_get(:@exec_helper)
61
+ @image_helper = @plugin.instance_variable_get(:@image_helper)
62
+ end
63
+
64
+ describe ".build_virtualbox" do
65
+ it "should build virtualbox image on new qemu-img" do
66
+ prepare_image(:previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
67
+
68
+ @image_helper.should_receive(:convert_disk).with("a/base/image/path.raw", :vmdk, "build/path/virtualbox-plugin/tmp/full.vmdk")
69
+
70
+ @plugin.build_virtualbox
71
+ end
72
+
73
+ it "should build virtualbox image on old qemu-img" do
74
+ prepare_image(:previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
75
+
76
+ @image_helper.should_receive(:convert_disk).with("a/base/image/path.raw", :vmdk, "build/path/virtualbox-plugin/tmp/full.vmdk")
77
+
78
+ @plugin.build_virtualbox
79
+ end
80
+ end
81
+
82
+ describe ".customize" do
83
+ it "should customize the image" do
84
+ prepare_image
85
+
86
+ @appliance_config.post['virtualbox'] = ["one", "two", "three"]
87
+
88
+ guestfs_mock = mock("GuestFS")
89
+ guestfs_helper_mock = mock("GuestFSHelper")
90
+
91
+ @image_helper.should_receive(:customize).with("build/path/virtualbox-plugin/tmp/full.vmdk").and_yield(guestfs_mock, guestfs_helper_mock)
92
+
93
+ guestfs_helper_mock.should_receive(:sh).once.ordered.with("one", :arch => 'i686')
94
+ guestfs_helper_mock.should_receive(:sh).once.ordered.with("two", :arch => 'i686')
95
+ guestfs_helper_mock.should_receive(:sh).once.ordered.with("three", :arch => 'i686')
96
+
97
+ @plugin.customize
98
+ end
99
+
100
+ it "should not customize the image if no commands are specified" do
101
+ prepare_image
102
+
103
+ @image_helper.should_not_receive(:customize)
104
+
105
+ @plugin.customize
106
+ end
107
+ end
108
+
109
+ it "should execute the conversion" do
110
+ prepare_image
111
+
112
+ @plugin.should_receive(:build_virtualbox)
113
+ @plugin.should_receive(:customize)
114
+
115
+ @plugin.execute
116
+ end
117
+ end
118
+ end