boxgrinder-build 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/CHANGELOG +21 -0
  2. data/Manifest +92 -0
  3. data/Rakefile +9 -0
  4. data/boxgrinder-build.gemspec +4 -4
  5. data/integ/appliances/_hardware_cpus.appl +13 -0
  6. data/integ/appliances/_hardware_memory.appl +13 -0
  7. data/integ/appliances/_hardware_partitions_home.appl +15 -0
  8. data/integ/appliances/_hardware_partitions_root.appl +15 -0
  9. data/integ/appliances/_os_password.appl +15 -0
  10. data/integ/appliances/_packages_groups_base.appl +13 -0
  11. data/integ/appliances/_packages_groups_core.appl +13 -0
  12. data/integ/appliances/_packages_squid.appl +13 -0
  13. data/integ/appliances/_packages_utils.appl +7 -0
  14. data/integ/appliances/_repos_boxgrinder_permanent_noarch.appl +14 -0
  15. data/integ/appliances/_repos_testlocal_ephemeral_noarch.appl +17 -0
  16. data/integ/appliances/_test_base.appl +22 -0
  17. data/integ/appliances/gnome-fedora.appl +19 -0
  18. data/integ/appliances/jeos-centos.appl +4 -0
  19. data/integ/appliances/jeos-fedora.appl +5 -0
  20. data/integ/appliances/modular.appl +16 -0
  21. data/integ/packages/ephemeral-repo-test-0.1-1.noarch.rpm +0 -0
  22. data/integ/packages/local-repo-test.spec +20 -0
  23. data/integ/spec/jeos-spec.rb +69 -0
  24. data/integ/spec/modular-spec.rb +71 -0
  25. data/lib/boxgrinder-build/appliance.rb +48 -48
  26. data/lib/boxgrinder-build/helpers/guestfs-helper.rb +11 -8
  27. data/lib/boxgrinder-build/helpers/plugin-helper.rb +1 -0
  28. data/lib/boxgrinder-build/helpers/qemu.wrapper +1 -1
  29. data/lib/boxgrinder-build/plugins/base-plugin.rb +55 -14
  30. data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +270 -54
  31. data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +3 -4
  32. data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +20 -16
  33. data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +57 -20
  34. data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +6 -4
  35. data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +2 -1
  36. data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +2 -32
  37. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +29 -4
  38. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +15 -46
  39. data/lib/boxgrinder-build/plugins/os/sl/sl-plugin.rb +56 -0
  40. data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +1 -0
  41. data/lib/boxgrinder-build/plugins/platform/ec2/src/rc_local +15 -8
  42. data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +8 -6
  43. data/rubygem-boxgrinder-build.spec +23 -3
  44. data/spec/appliance-spec.rb +114 -73
  45. data/spec/helpers/guestfs-helper-spec.rb +12 -3
  46. data/spec/plugins/base-plugin-spec.rb +24 -18
  47. data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +206 -67
  48. data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +228 -225
  49. data/spec/plugins/delivery/local/local-plugin-spec.rb +13 -34
  50. data/spec/plugins/delivery/s3/s3-plugin-spec.rb +107 -50
  51. data/spec/plugins/os/centos/centos-plugin-spec.rb +1 -1
  52. data/spec/plugins/os/fedora/fedora-plugin-spec.rb +14 -8
  53. data/spec/plugins/os/rhel/rhel-plugin-spec.rb +1 -1
  54. data/spec/plugins/os/rpm-based/kickstart-spec.rb +0 -44
  55. data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +31 -2
  56. data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +20 -7
  57. data/spec/plugins/os/sl/sl-plugin-spec.rb +44 -0
  58. data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +1 -1
  59. data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +6 -6
  60. data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +14 -13
  61. metadata +27 -5
  62. data/spec/Rakefile +0 -32
@@ -0,0 +1,56 @@
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/os/rhel/rhel-plugin'
20
+
21
+ module BoxGrinder
22
+ class ScientificLinuxPlugin < RHELPlugin
23
+
24
+ SL_REPOS = {
25
+ "5" => {
26
+ "base" => {
27
+ "baseurl" => "http://ftp.scientificlinux.org/linux/scientific/#OS_VERSION#x/#BASE_ARCH#/SL/"
28
+ },
29
+ "security" => {
30
+ "baseurl" => "http://ftp.scientificlinux.org/linux/scientific/#OS_VERSION#x/#BASE_ARCH#/updates/security/"
31
+ }
32
+ },
33
+ "6" => {
34
+ "base" => {
35
+ "baseurl" => "http://ftp.scientificlinux.org/linux/scientific/#OS_VERSION#x/#BASE_ARCH#/os/"
36
+ },
37
+ "security" => {
38
+ "baseurl" => "http://ftp.scientificlinux.org/linux/scientific/#OS_VERSION#x/#BASE_ARCH#/updates/security/"
39
+ }
40
+ }
41
+ }
42
+
43
+ def after_init
44
+ super
45
+ register_supported_os('sl', ['5', '6'])
46
+ end
47
+
48
+ def execute(appliance_definition_file)
49
+ build_rhel(appliance_definition_file, SL_REPOS)
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ plugin :class => BoxGrinder::ScientificLinuxPlugin, :type => :os, :name => :sl, :full_name => "Scientific Linux", :versions => ["5", "6"]
56
+
@@ -27,6 +27,7 @@ module BoxGrinder
27
27
 
28
28
  register_supported_os('fedora', ['13', '14', '15'])
29
29
  register_supported_os('centos', ['5'])
30
+ register_supported_os('sl', ['5', '6'])
30
31
  register_supported_os('rhel', ['5', '6'])
31
32
  end
32
33
 
@@ -1,19 +1,26 @@
1
- curl http://169.254.169.254/2009-04-04/meta-data/public-keys/0/openssh-key 2>/dev/null >/tmp/my-key
1
+ key=`curl http://169.254.169.254/2009-04-04/meta-data/public-keys/0/openssh-key 2>/dev/null`
2
2
 
3
3
  if [ $? -eq 0 ] ; then
4
- for home in `find /home/* -maxdepth 0 -type d 2>/dev/null | tr '\n' ' '`; do
5
- user=`echo $home | awk -F '/' '{ print $3 }'`
4
+ for home in `find /home/* -maxdepth 0 -type d 2>/dev/null | tr '\n' ' '`; do
5
+ user=`echo $home | awk -F '/' '{ print $3 }'`
6
6
 
7
- if [ ! -d $home/.ssh ] ; then
7
+ if [ ! -d $home/.ssh ] ; then
8
8
  mkdir -p $home/.ssh
9
9
  chmod 700 $home/.ssh
10
10
  chown $user $home/.ssh
11
11
  fi
12
12
 
13
- cat /tmp/my-key >> $home/.ssh/authorized_keys
14
- chmod 600 $home/.ssh/authorized_keys
15
- chown $user $home/.ssh/authorized_keys
13
+ actual_key=`echo $key | awk '{ print $2 }'`
16
14
 
15
+ if [ -f $home/.ssh/authorized_keys ]; then
16
+ if [ "`grep $actual_key $home/.ssh/authorized_keys | wc -l`" -gt 0 ]; then
17
+ continue
18
+ fi
19
+ fi
20
+
21
+ echo $key >> $home/.ssh/authorized_keys
22
+ chmod 600 $home/.ssh/authorized_keys
23
+ chown $user $home/.ssh/authorized_keys
17
24
  done
18
- rm /tmp/my-key
19
25
  fi
26
+
@@ -21,10 +21,7 @@ require 'boxgrinder-build/plugins/base-plugin'
21
21
  module BoxGrinder
22
22
  class VMwarePlugin < BasePlugin
23
23
  def after_init
24
- set_default_config_value('thin_disk', false)
25
- validate_plugin_config(['type'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#VMware_Platform_Plugin')
26
-
27
- register_deliverable(:vmx => "#{@appliance_config.name}.vmx",
24
+ register_deliverable(:vmx => "#{@appliance_config.name}.vmx",
28
25
  :readme => "README")
29
26
 
30
27
  if @plugin_config['type'].eql?('personal') and @plugin_config['thin_disk']
@@ -35,6 +32,11 @@ module BoxGrinder
35
32
  end
36
33
  end
37
34
 
35
+ def validate
36
+ set_default_config_value('thin_disk', false)
37
+ validate_plugin_config(['type'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#VMware_Platform_Plugin')
38
+ end
39
+
38
40
  def execute
39
41
  @log.info "Converting image to VMware #{@plugin_config['type']} format..."
40
42
 
@@ -79,7 +81,7 @@ module BoxGrinder
79
81
  end
80
82
  end
81
83
 
82
- c = disk_size / (h*s*512)
84
+ c = disk_size / (h*s*512)
83
85
  total_sectors = disk_size / 512
84
86
 
85
87
  [c.to_i, h.to_i, s.to_i, total_sectors.to_i]
@@ -188,4 +190,4 @@ module BoxGrinder
188
190
  end
189
191
  end
190
192
 
191
- plugin :class => BoxGrinder::VMwarePlugin, :type => :platform, :name => :vmware, :full_name => "VMware"
193
+ plugin :class => BoxGrinder::VMwarePlugin, :type => :platform, :name => :vmware, :full_name => "VMware"
@@ -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.2
8
+ Version: 0.9.3
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
@@ -22,8 +22,6 @@ Requires: e2fsprogs
22
22
  # Fix for rubygem-aws package
23
23
  Requires: rubygem(activesupport)
24
24
 
25
- # For EL5
26
- BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
27
25
  BuildArch: noarch
28
26
 
29
27
  BuildRequires: rubygem(rake)
@@ -143,12 +141,34 @@ popd
143
141
  %files doc
144
142
  %defattr(-, root, root, -)
145
143
  %{geminstdir}/spec
144
+ %{geminstdir}/integ
146
145
  %{geminstdir}/Rakefile
147
146
  %{geminstdir}/rubygem-%{gemname}.spec
148
147
  %{geminstdir}/%{gemname}.gemspec
149
148
  %{gemdir}/doc/%{gemname}-%{version}
150
149
 
151
150
  %changelog
151
+ * Fri Jun 17 2011 Marc Savy <msavy@redhat.com> - 0.9.3-1
152
+ - Upstream release: 0.9.3
153
+ - [BGBUILD-232] boxgrinder doesn't validate config early enough
154
+ - [BGBUILD-237] Tilde characters break creation of yum.conf
155
+ - [BGBUILD-223] BoxGrinder hangs because qemu.wrapper does not detect x86_64 properly on CentOS 5.6
156
+ - [BGBUILD-241] Add Scientific Linux support
157
+ - [BGBUILD-220] Group names have spaces (to the user), this breaks schema rules for packages
158
+ - [BGBUILD-222] Allow overwrite of uploaded ec2 image
159
+ - [BGBUILD-225] Move PAE configuration parameter to operating system configuration
160
+ - [BGBUILD-224] EBS Plugin Support for CentOS v5.5 and fix for non-integer EBS disk sizes
161
+ - [BGBUILD-231] Cannot register Fedora 15 EC2 AMI with S3 delivery plugin in eu-west-1 availability zone
162
+ - [BGBUILD-193] EBS delivery plugin timing/concurrency issues
163
+ - [BGBUILD-247] ap-northeast-1 end-point is missing in S3 plugin (added Tokyo region)
164
+ - [BGBUILD-251] Add ap-northeast-1 (tokyo) region for EBS plugin
165
+ - [BGBUILD-248] Throw error in S3 plugin if invalid region is specified
166
+ - [BGBUILD-252] rc.local script fills ~/.ssh/authorized_keys with a duplicate key every boot
167
+ - [BGBUILD-250] EBS plugin incorrectly determines that non-US regions are not EC2 instances
168
+ - [BGBUILD-254] Not able to deliver EBS AMIs to regions other than us-east-1
169
+ - [BGBUILD-260] Wrong EC2 discovery causing libguestfs errors on non US regions
170
+ - [BGBUILD-261] Decrease amount of debug log when downloading or uploading file using guestfs
171
+
152
172
  * Thu May 05 2011 Marek Goldmann <mgoldman@redhat.com> - 0.9.2-1
153
173
  - Upstream release: 0.9.2
154
174
  - [BGBUILD-148] Add support for building CentOS/RHEL images on Fedora
@@ -68,9 +68,27 @@ module BoxGrinder
68
68
  config.size.should == 1
69
69
  config[:log].should == nil
70
70
  end
71
+
72
+ describe ".validate_definition" do
73
+ before(:each) do
74
+ prepare_appliance
75
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
76
+ end
71
77
 
72
- describe ".create" do
78
+ it "should raise if we use unsupported OS" do
79
+ PluginManager.stub(:instance).and_return(OpenCascade.new(:plugins => {:os => {:centos => {}}}))
80
+ lambda {
81
+ @appliance.validate_definition
82
+ }.should raise_error(RuntimeError, "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#Operating_system_plugins. Supported OSes are: centos")
83
+ end
73
84
 
85
+ it "should NOT raise if we use supported OS" do
86
+ PluginManager.stub(:instance).and_return(OpenCascade.new(:plugins => {:os => {:fedora => {:versions => ['11']}}}))
87
+ @appliance.validate_definition
88
+ end
89
+ end
90
+
91
+ describe ".create" do
74
92
  it "should prepare appliance to build" do
75
93
  prepare_appliance
76
94
 
@@ -81,6 +99,7 @@ module BoxGrinder
81
99
 
82
100
  @appliance.should_receive(:read_definition)
83
101
  @appliance.should_receive(:validate_definition)
102
+ @appliance.should_receive(:initialize_plugins)
84
103
  @appliance.should_not_receive(:remove_old_builds)
85
104
  @appliance.should_receive(:execute_plugin_chain)
86
105
 
@@ -96,6 +115,7 @@ module BoxGrinder
96
115
  PluginHelper.should_receive(:new).with(@config, :log => @log).and_return(plugin_helper)
97
116
 
98
117
  @appliance.should_receive(:read_definition)
118
+ @appliance.should_receive(:initialize_plugins)
99
119
  @appliance.should_receive(:validate_definition)
100
120
  @appliance.should_receive(:remove_old_builds)
101
121
  @appliance.should_receive(:execute_plugin_chain)
@@ -199,114 +219,135 @@ module BoxGrinder
199
219
 
200
220
  it "should remove old builds" do
201
221
  prepare_appliance
202
-
203
222
  @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
223
+
204
224
  FileUtils.should_receive(:rm_rf).with("build/path")
205
225
  @appliance.remove_old_builds
206
226
  end
207
227
 
208
- it "should build base appliance" do
209
- prepare_appliance
228
+ describe ".execute_plugin_chain" do
229
+ before(:each) do
230
+ prepare_appliance
231
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
232
+ end
210
233
 
211
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
234
+ it "should not fail when plugin chain is empty" do
235
+ @appliance.instance_variable_set(:@plugin_chain, [])
236
+ @appliance.execute_plugin_chain
237
+ end
212
238
 
213
- os_plugin = mock('FedoraPlugin')
214
- os_plugin.should_receive(:init)
215
- os_plugin.should_receive(:deliverables_exists?).and_return(false)
216
- os_plugin.should_receive(:run)
217
- os_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
239
+ it "should execute the whole plugin chain" do
240
+ @appliance.instance_variable_set(:@plugin_chain, [{:plugin => :plugin1, :param => 'definition'}, {:plugin => :plugin2}, {:plugin => :plugin3}])
218
241
 
219
- @plugin_manager.should_receive(:plugins).and_return({:os => "something"})
220
- @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
242
+ @appliance.should_receive(:execute_plugin).ordered.with(:plugin1, 'definition')
243
+ @appliance.should_receive(:execute_plugin).ordered.with(:plugin2, nil)
244
+ @appliance.should_receive(:execute_plugin).ordered.with(:plugin3, nil)
221
245
 
222
- @appliance.execute_plugin_chain
246
+ @appliance.execute_plugin_chain
247
+ end
223
248
  end
224
249
 
225
- it "should not build base appliance because deliverable already exists" do
226
- prepare_appliance
250
+ describe ".initialize_plugins" do
251
+ it "should prepare the plugin chain to create an appliance and convert it to VMware format" do
252
+ prepare_appliance(:platform => :vmware)
253
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
227
254
 
228
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
255
+ os_plugin = mock("OSPlugin")
256
+ platform_plugin = mock("PlatformPlugin", :deliverables => OpenCascade.new(:disk => 'a/disk.vmdk'))
229
257
 
230
- os_plugin = mock('FedoraPlugin')
231
- os_plugin.should_receive(:init)
232
- os_plugin.should_receive(:deliverables_exists?).and_return(true)
233
- os_plugin.should_not_receive(:run)
234
- os_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
258
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
259
+ @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
260
+ @plugin_manager.should_not_receive(:initialize_plugin).with(:delivery, anything)
235
261
 
236
- @plugin_manager.should_receive(:plugins).and_return({:os => "something"})
237
- @plugin_manager.should_receive(:initialize_plugin).once.with(:os, :fedora).and_return([os_plugin, {:class => Appliance, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "rawhide"]}])
262
+ os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
263
+ platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
238
264
 
239
- @appliance.execute_plugin_chain
240
- end
265
+ @appliance.initialize_plugins
241
266
 
242
- it "should build appliance and convert it to VMware format" do
243
- prepare_appliance(:platform => :vmware)
267
+ @appliance.plugin_chain.size.should == 2
268
+ @appliance.plugin_chain.last[:plugin].deliverables.should == {:disk=>"a/disk.vmdk"}
269
+ end
244
270
 
245
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
246
- @appliance.should_receive(:execute_os_plugin).and_return({})
271
+ it "should prepare the plugin chain to create an appliance and convert it to VMware format and deliver to S3" do
272
+ prepare_appliance(:platform => :vmware, :delivery => :s3)
273
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
247
274
 
248
- platform_plugin = mock('VMware Plugin')
249
- platform_plugin.should_receive(:init)
250
- platform_plugin.should_receive(:deliverables_exists?).and_return(false)
251
- platform_plugin.should_receive(:run)
252
- platform_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
275
+ os_plugin = mock("OSPlugin")
276
+ platform_plugin = mock("PlatformPlugin")
277
+ delivery_plugin = mock("DeliveryPlugin", :deliverables => {})
253
278
 
254
- @plugin_manager.should_receive(:plugins).and_return({:platform => "something"})
255
- @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
279
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
280
+ @plugin_manager.should_receive(:initialize_plugin).with(:platform, :vmware).and_return([platform_plugin, "platform_plugin_info"])
281
+ @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
256
282
 
257
- @appliance.execute_plugin_chain
258
- end
283
+ os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
284
+ platform_plugin.should_receive(:init).with(@config, @appliance_config, "platform_plugin_info", :log => @log, :previous_plugin => os_plugin)
285
+ delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => platform_plugin, :type => :s3)
259
286
 
260
- it "should build appliance and convert it to VMware format because deliverable already exists" do
261
- prepare_appliance(:platform => :vmware)
287
+ @appliance.initialize_plugins
262
288
 
263
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
264
- @appliance.should_receive(:execute_os_plugin).and_return({})
289
+ @appliance.plugin_chain.size.should == 3
290
+ @appliance.plugin_chain.last[:plugin].deliverables.size.should == 0
291
+ end
292
+
293
+ it "should prepare the plugin chain to create an appliance and without conversion deliver to S3" do
294
+ prepare_appliance(:delivery => :s3)
295
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
265
296
 
266
- platform_plugin = mock('VMware Plugin')
267
- platform_plugin.should_receive(:init)
268
- platform_plugin.should_receive(:deliverables_exists?).and_return(true)
269
- platform_plugin.should_not_receive(:run)
270
- platform_plugin.should_receive(:deliverables).and_return({:disk => 'abc'})
297
+ os_plugin = mock("OSPlugin")
298
+ delivery_plugin = mock("DeliveryPlugin")
271
299
 
272
- @plugin_manager.should_receive(:plugins).and_return({:platform => "something"})
273
- @plugin_manager.should_receive(:initialize_plugin).once.with(:platform, :vmware).and_return([platform_plugin, {:class => Appliance, :type => :platform, :name => :vmware, :full_name => "VMware"}])
300
+ @plugin_manager.should_receive(:initialize_plugin).with(:os, :fedora).and_return([os_plugin, "os_plugin_info"])
301
+ @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :s3).and_return([delivery_plugin, "delivery_plugin_info"])
302
+ @plugin_manager.should_not_receive(:initialize_plugin).with(:platform, anything)
274
303
 
275
- @appliance.execute_plugin_chain
304
+ os_plugin.should_receive(:init).with(@config, @appliance_config, "os_plugin_info", :log => @log)
305
+ delivery_plugin.should_receive(:init).with(@config, @appliance_config, "delivery_plugin_info", :log => @log, :previous_plugin => os_plugin, :type => :s3)
306
+
307
+ @appliance.initialize_plugins
308
+ end
276
309
  end
277
310
 
278
- it "should build appliance, convert it to EC2 format and deliver it using S3 ami type" do
279
- prepare_appliance(:platform => :ec2, :delivery => :ami)
311
+ describe ".execute_plugin" do
312
+ before(:each) do
313
+ prepare_appliance
314
+ @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
315
+ end
280
316
 
281
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
282
- @appliance.should_receive(:execute_os_plugin).and_return({:abc => 'def'})
283
- @appliance.should_receive(:execute_platform_plugin).with({:abc => 'def'}).and_return({:def => 'ghi'})
317
+ it "should not execute the plugin because deliverable already exists" do
318
+ plugin = mock('APlugin', :deliverables_exists? => true, :plugin_info => {:name => :ec2, :type => :platform})
284
319
 
285
- delivery_plugin = mock('S3 Plugin')
286
- delivery_plugin.should_receive(:init)
287
- delivery_plugin.should_receive(:run).with(:ami)
320
+ @appliance.execute_plugin(plugin)
321
+ end
288
322
 
289
- @plugin_manager.should_receive(:plugins).and_return({:delivery => "something"})
290
- @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :ami).and_return([delivery_plugin, {:class => Appliance, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]}])
323
+ it "should execute the plugin" do
324
+ plugin = mock('APlugin', :deliverables_exists? => false, :plugin_info => {:name => :ec2, :type => :platform})
325
+ plugin.should_receive(:run).with(:s3)
291
326
 
292
- @appliance.execute_plugin_chain
327
+ @appliance.execute_plugin(plugin, :s3)
328
+ end
293
329
  end
294
330
 
295
- it "should build appliance, convert it to EC2 format and deliver it using delivery plugin with only one delivery type" do
296
- prepare_appliance(:platform => :ec2, :delivery => :same)
297
-
298
- @appliance.instance_variable_set(:@appliance_config, prepare_appliance_config)
299
- @appliance.should_receive(:execute_os_plugin).and_return({:abc => 'def'})
300
- @appliance.should_receive(:execute_platform_plugin).with({:abc => 'def'}).and_return({:def => 'ghi'})
331
+ context "preparations" do
332
+ it "should return true if we have selected a platform" do
333
+ prepare_appliance(:platform => :vmware)
334
+ @appliance.platform_selected?.should == true
335
+ end
301
336
 
302
- delivery_plugin = mock('S3 Plugin')
303
- delivery_plugin.should_receive(:init)
304
- delivery_plugin.should_receive(:run).with(:same)
337
+ it "should return false if we haven't selected a platform" do
338
+ prepare_appliance
339
+ @appliance.platform_selected?.should == false
340
+ end
305
341
 
306
- @plugin_manager.should_receive(:plugins).and_return({:delivery => "something"})
307
- @plugin_manager.should_receive(:initialize_plugin).with(:delivery, :same).and_return([delivery_plugin, {:class => Appliance, :type => :delivery, :name => :same, :full_name => "A plugin"}])
342
+ it "should return true if we have selected a delivery" do
343
+ prepare_appliance(:delivery => :s3)
344
+ @appliance.delivery_selected?.should == true
345
+ end
308
346
 
309
- @appliance.execute_plugin_chain
347
+ it "should return false if we haven't selected a delivery" do
348
+ prepare_appliance
349
+ @appliance.delivery_selected?.should == false
350
+ end
310
351
  end
311
352
  end
312
353
  end
@@ -247,19 +247,28 @@ module BoxGrinder
247
247
 
248
248
  describe ".hw_virtualization_available?" do
249
249
  it "should return true if HW acceleration is available" do
250
- Resolv.should_receive(:getname).with("169.254.169.254").and_return("blah")
250
+ URI.should_receive(:parse).with('http://169.254.169.254/latest/meta-data/ami-id').and_return('parsed')
251
+ Net::HTTP.should_receive(:get_response).with("parsed").and_return(OpenCascade.new(:code => '404'))
251
252
  @helper.should_receive(:`).with("egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l").and_return("2")
252
253
  @helper.hw_virtualization_available?.should == true
253
254
  end
254
255
 
255
256
  it "should return false if no vmx flag is present" do
256
- Resolv.should_receive(:getname).with("169.254.169.254").and_return("blah")
257
+ URI.should_receive(:parse).with('http://169.254.169.254/latest/meta-data/ami-id').and_return('parsed')
258
+ Net::HTTP.should_receive(:get_response).with("parsed").and_return(OpenCascade.new(:code => '404'))
257
259
  @helper.should_receive(:`).with("egrep '^flags.*(vmx|svm)' /proc/cpuinfo | wc -l").and_return("0")
258
260
  @helper.hw_virtualization_available?.should == false
259
261
  end
260
262
 
261
263
  it "should return false if we're on EC2" do
262
- Resolv.should_receive(:getname).with("169.254.169.254").and_return("instance-data.ec2.internal")
264
+ URI.should_receive(:parse).with('http://169.254.169.254/latest/meta-data/ami-id').and_return('parsed')
265
+ Net::HTTP.should_receive(:get_response).with("parsed").and_return(OpenCascade.new(:code => '200'))
266
+ @helper.hw_virtualization_available?.should == false
267
+ end
268
+
269
+ it "should return false if we're NOT on EC2 and AMI id retrieval raised an exception" do
270
+ URI.should_receive(:parse).with('http://169.254.169.254/latest/meta-data/ami-id').and_return('parsed')
271
+ Net::HTTP.should_receive(:get_response).with("parsed").and_raise "Boom"
263
272
  @helper.hw_virtualization_available?.should == false
264
273
  end
265
274
  end