boxgrinder-build 0.9.8 → 0.10.0

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 +15 -0
  2. data/Manifest +7 -22
  3. data/Rakefile +3 -1
  4. data/bin/boxgrinder-build +1 -1
  5. data/boxgrinder-build.gemspec +17 -13
  6. data/integ/appliances/jeos-centos6.appl +4 -0
  7. data/lib/boxgrinder-build/appliance.rb +61 -23
  8. data/lib/boxgrinder-build/helpers/ec2-helper.rb +18 -0
  9. data/lib/boxgrinder-build/helpers/linux-helper.rb +41 -2
  10. data/lib/boxgrinder-build/helpers/plugin-helper.rb +3 -0
  11. data/lib/boxgrinder-build/helpers/s3-helper.rb +18 -0
  12. data/lib/boxgrinder-build/helpers/sftp-helper.rb +124 -0
  13. data/lib/boxgrinder-build/managers/plugin-manager.rb +5 -3
  14. data/lib/boxgrinder-build/plugins/base-plugin.rb +2 -22
  15. data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +26 -15
  16. data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +2 -1
  17. data/lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-capabilities.rb +164 -0
  18. data/lib/boxgrinder-build/plugins/delivery/libvirt/libvirt-plugin.rb +313 -0
  19. data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +2 -1
  20. data/lib/boxgrinder-build/plugins/delivery/openstack/openstack-plugin.rb +133 -0
  21. data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +15 -2
  22. data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +20 -106
  23. data/lib/boxgrinder-build/plugins/os/centos/centos-plugin.rb +3 -3
  24. data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +2 -1
  25. data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +2 -1
  26. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +6 -64
  27. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +2 -1
  28. data/lib/boxgrinder-build/plugins/os/sl/sl-plugin.rb +1 -2
  29. data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +15 -1
  30. data/lib/boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin.rb +2 -1
  31. data/lib/boxgrinder-build/plugins/platform/virtualpc/virtualpc-plugin.rb +58 -0
  32. data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +2 -1
  33. data/rubygem-boxgrinder-build.spec +25 -1
  34. data/spec/appliance-spec.rb +1 -58
  35. data/spec/helpers/linux-helper-spec.rb +70 -0
  36. data/spec/managers/plugin-manager-spec.rb +4 -13
  37. data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +6 -14
  38. data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +5 -6
  39. data/spec/plugins/delivery/libvirt/libvirt-plugin-spec.rb +300 -0
  40. data/spec/plugins/delivery/libvirt/libvirt_modified.xml +25 -0
  41. data/spec/plugins/delivery/libvirt/libvirt_modify.sh +18 -0
  42. data/spec/plugins/delivery/libvirt/libvirt_test.xml +24 -0
  43. data/spec/plugins/delivery/local/local-plugin-spec.rb +3 -6
  44. data/spec/plugins/delivery/openstack/openstack-plugin-spec.rb +103 -0
  45. data/spec/plugins/delivery/s3/s3-plugin-spec.rb +16 -5
  46. data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +2 -80
  47. data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +15 -1
  48. data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +6 -6
  49. data/spec/plugins/platform/virtualpc/virtualpc-plugin-spec.rb +90 -0
  50. data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +5 -9
  51. data/spec/rspec-plugin-helper.rb +47 -0
  52. metadata +54 -10
@@ -44,13 +44,12 @@ module BoxGrinder
44
44
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => :fedora, :version => '13'}))
45
45
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:cpus => 1, :arch => 'x86_64', :partitions => {'/' => {'size' => 1}, '/home' => {'size' => 2}}, :memory => 512))
46
46
 
47
- options = {:log => LogHelper.new(:level => :trace, :type => :stdout), :previous_plugin => OpenCascade.new(:plugin_info => {:type => :os})}.merge(options)
47
+ options = {
48
+ :previous_plugin => OpenCascade.new(:plugin_info => {:type => :os}, :deliverables => {:disk => 'a/base/image/path.raw'}),
49
+ :plugin_info => {:class => BoxGrinder::ElasticHostsPlugin, :type => :delivery, :name => :elastichosts, :full_name => "ElasticHosts"}
50
+ }.merge(options)
48
51
 
49
- @plugin = ElasticHostsPlugin.new.init(@config, @appliance_config,
50
- {:class => BoxGrinder::ElasticHostsPlugin, :type => :delivery, :name => :elastichosts, :full_name => "ElasticHosts"},
51
- options
52
-
53
- )
52
+ @plugin = RSpecPluginHelper.new(ElasticHostsPlugin).prepare(@config, @appliance_config, options)
54
53
 
55
54
  @plugin_config = @config.plugins['elastichosts']
56
55
  @exec_helper = @plugin.instance_variable_get(:@exec_helper)
@@ -0,0 +1,300 @@
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/delivery/libvirt/libvirt-plugin'
20
+
21
+ module BoxGrinder
22
+ describe LibvirtPlugin do
23
+
24
+ def prepare_plugin
25
+ @plugin = LibvirtPlugin.new
26
+
27
+ @config = Config.new('plugins' => { 'libvirt' => {}})
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('appliance')
33
+ @appliance_config.stub!(:summary).and_return('boxgrinder-rocks')
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 => '13'}))
37
+ @appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64', :memory => 256, :cpu => 5}))
38
+
39
+ @previous_plugin_info = OpenCascade.new(:type => :os, :deliverables => {:disk => "/flo/bble.raw", :metadata => 'metadata.xml'})
40
+ @libvirt_capabilities = mock('libvirt_capabilities').as_null_object
41
+ @log = mock('logger').as_null_object
42
+
43
+ @plugin = RSpecPluginHelper.new(LibvirtPlugin).prepare(@config, @appliance_config,
44
+ :previous_plugin => @previous_plugin_info,
45
+ :plugin_info => {:class => BoxGrinder::LibvirtPlugin, :type => :delivery, :name => :libvirt, :full_name => "libvirt Virtualisation API"}
46
+ ) { |plugin| yield plugin, @config.plugins['libvirt'] if block_given? }
47
+
48
+ @plugin.instance_variable_set(:@libvirt_capabilities, @libvirt_capabilities)
49
+ @plugin.instance_variable_set(:@log, @log)
50
+ end
51
+
52
+ describe ".execute" do
53
+ it "should upload disk via sftp" do
54
+ prepare_plugin do |p, c|
55
+ c['image_delivery_uri'] = 'sftp://root@example.com/boxgrinder/images'
56
+ p.stub!(:determine_remotely)
57
+ p.stub!(:write_xml)
58
+ end
59
+ @plugin.should_receive(:upload_image)
60
+ @plugin.execute
61
+ end
62
+
63
+ it "should copy disk locally when not sftp" do
64
+ prepare_plugin do |p, c|
65
+ c['image_delivery_uri'] = '/bacon/butties'
66
+ p.stub!(:determine_remotely)
67
+ p.stub!(:write_xml)
68
+ end
69
+ FileUtils.should_receive(:cp).with('/flo/bble.raw', '/bacon/butties')
70
+ @plugin.execute
71
+ end
72
+
73
+ it "should determine xml locally when xml_only is set" do
74
+ prepare_plugin do |p, c|
75
+ c['image_delivery_uri'] = '/stottie/cake'
76
+ c['xml_only'] = 'true'
77
+ p.stub!(:write_xml)
78
+ end
79
+ FileUtils.should_receive(:cp).with('/flo/bble.raw', '/stottie/cake')
80
+ @plugin.should_receive(:determine_locally).and_return('xml')
81
+ @plugin.execute
82
+ end
83
+
84
+ it "should write the xml to file after generating it" do
85
+ prepare_plugin do |p, c|
86
+ c['xml_only'] = 'true'
87
+ FileUtils.stub!(:cp)
88
+ p.stub!(:determine_locally).and_return('xml')
89
+ end
90
+ @plugin.should_receive(:write_xml).with('xml')
91
+ @plugin.execute
92
+ end
93
+ end
94
+
95
+ describe ".determine_remotely" do
96
+ before(:each) do
97
+ @conn = mock('conn').as_null_object
98
+ @conn.stub!(:closed?).and_return(false)
99
+ @guest = mock('guest').as_null_object
100
+ @domain = mock('domain').as_null_object
101
+ end
102
+
103
+ context "uri handling" do
104
+ it "should handle and connect to the default empty uri" do
105
+ prepare_plugin do |p, c|
106
+ p.stub!(:get_existing_domain).and_return(false)
107
+ p.stub!(:generate_xml)
108
+ end
109
+
110
+ Libvirt.should_receive(:open_auth).
111
+ with('', [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]).
112
+ and_return(@conn)
113
+
114
+ @plugin.determine_remotely
115
+ end
116
+
117
+ it "should remove the password element from the userinfo, as libvirt does not support this" do
118
+ prepare_plugin do |p, c|
119
+ c['connection_uri'] = 'qemu+ssh://user:PASSWORD@example.com/system'
120
+ p.stub!(:get_existing_domain).and_return(false)
121
+ p.stub!(:generate_xml)
122
+ end
123
+
124
+ # Note that the password field should have been removed!
125
+ Libvirt.should_receive(:open_auth).
126
+ with('qemu+ssh://user@example.com/system', [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]).
127
+ and_return(@conn)
128
+
129
+ @plugin.determine_remotely
130
+ end
131
+
132
+ it "should re-construct scheme, userinfo, host, path, query in uri" do
133
+ prepare_plugin do |p, c|
134
+ c['connection_uri'] = 'qemu+ssh://user:pass@example.com/system?some_elem=1&other=2'
135
+ p.stub!(:get_existing_domain).and_return(false)
136
+ p.stub!(:generate_xml)
137
+ end
138
+
139
+ Libvirt.should_receive(:open_auth).
140
+ with('qemu+ssh://user@example.com/system?some_elem=1&other=2', [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]).
141
+ and_return(@conn)
142
+
143
+ @plugin.determine_remotely
144
+ end
145
+ end
146
+
147
+ context "there is an existing domain" do
148
+ it "should raise an error if a domain already exists" do
149
+ prepare_plugin do |p, c|
150
+ p.stub!(:get_existing_domain).and_return(@domain)
151
+ p.stub!(:generate_xml)
152
+ Libvirt.stub!(:open_auth).and_return(@conn)
153
+ end
154
+
155
+ lambda{ @plugin.determine_remotely }.should raise_error(RuntimeError)
156
+ end
157
+
158
+ it "should undefine the domain if overwrite is set, and domain exists" do
159
+ prepare_plugin do |p, c|
160
+ c['overwrite'] = true
161
+ p.stub!(:get_existing_domain).and_return(@domain)
162
+ p.stub!(:generate_xml)
163
+ Libvirt.stub!(:open_auth).and_return(@conn)
164
+ end
165
+
166
+ @plugin.should_receive(:undefine_domain).with(@domain)
167
+ @plugin.determine_remotely
168
+ end
169
+ end
170
+
171
+ context "capabilities" do
172
+ let(:capabilities){ mock('capabilities') }
173
+ let(:capability_xml){ mock('capability_xml') }
174
+
175
+ it "should determine capabilities" do
176
+ prepare_plugin do |p, c|
177
+ p.stub!(:get_existing_domain).and_return(false)
178
+ p.stub!(:generate_xml)
179
+ Libvirt.stub!(:open_auth).and_return(@conn)
180
+ end
181
+ capabilities.stub!(:nil?).and_return(false)
182
+
183
+ @libvirt_capabilities.should_receive(:determine_capabilities).
184
+ with(@conn, {}).and_return(capabilities)
185
+ @plugin.determine_remotely
186
+ end
187
+
188
+ it "should request xml using derived capabilities" do
189
+ prepare_plugin do |p, c|
190
+ p.stub!(:get_existing_domain).and_return(false)
191
+ Libvirt.stub!(:open_auth).and_return(@conn)
192
+ end
193
+
194
+ @libvirt_capabilities.stub!(:determine_capabilities).
195
+ and_return(capabilities)
196
+
197
+ @plugin.should_receive(:generate_xml).with(capabilities)
198
+ @plugin.determine_remotely
199
+ end
200
+
201
+ it "should define the domain with capabilities generated xml" do
202
+ prepare_plugin do |p, c|
203
+ p.stub!(:get_existing_domain).and_return(false)
204
+ p.stub!(:generate_xml).and_return(capability_xml)
205
+ Libvirt.stub!(:open_auth).and_return(@conn)
206
+ end
207
+
208
+ @libvirt_capabilities.stub!(:determine_capabilities).
209
+ and_return(capabilities)
210
+
211
+ @conn.should_receive(:define_domain_xml).with(capability_xml)
212
+ @plugin.determine_remotely
213
+ end
214
+ end
215
+ end
216
+
217
+ describe ".determine_locally" do
218
+ let(:domain){ mock('domain') }
219
+ let(:plugin){ mock('plugin').as_null_object }
220
+
221
+ it "should look up static capabilities by getting safest ranked domain" do
222
+ prepare_plugin do |p, c|
223
+ @libvirt_capabilities.stub!(:get_plugin).and_return(plugin)
224
+ plugin.stub_chain(:domain_rank, :last).and_return(domain)
225
+ # Values, as would be returned by a domain object
226
+ domain.stub!(:name).and_return('d')
227
+ domain.stub_chain(:virt_rank, :last).and_return('o')
228
+ domain.stub!(:bus).and_return('n')
229
+ end
230
+
231
+ @plugin.should_receive(:generate_xml).with(OpenStruct.new({
232
+ :domain_type => 'd',
233
+ :os_type => 'o',
234
+ :bus => 'n'
235
+ }))
236
+ @plugin.determine_locally
237
+ end
238
+ end
239
+
240
+ describe ".upload_image" do
241
+ let(:uploader){ mock('sftp_uploader').as_null_object }
242
+
243
+ before(:each) do
244
+ SFTPHelper.stub!(:new).and_return(uploader)
245
+ end
246
+
247
+ it "should connect to the image delivery uri" do
248
+ prepare_plugin do |p, c|
249
+ c['image_delivery_uri'] = 'sftp://user:pass@example.com/a/directory'
250
+ end
251
+
252
+ uploader.should_receive(:connect).
253
+ with('example.com', 'user', :password => 'pass')
254
+
255
+ @plugin.upload_image
256
+ end
257
+
258
+ it "should upload files to the specified path at the uri" do
259
+ prepare_plugin do |p, c|
260
+ c['image_delivery_uri'] = 'sftp://user:pass@example.com/a/directory'
261
+ end
262
+
263
+ uploader.should_receive(:upload_files).
264
+ with('/a/directory', 0770, false, 'bble.raw' => '/flo/bble.raw')
265
+
266
+ @plugin.upload_image
267
+ end
268
+
269
+ it "should disconnect after finishing" do
270
+ prepare_plugin do |p, c|
271
+ uploader.stub!(:connected).and_return(true)
272
+ c['image_delivery_uri'] = 'sftp://user:pass@example.com/a/directory'
273
+ end
274
+
275
+ uploader.should_receive(:disconnect)
276
+ @plugin.upload_image
277
+ end
278
+ end
279
+
280
+ # Fuller combinatorial coverage in cucumber required
281
+ describe ".build_xml" do
282
+ it "should build an xml definition from appliance config & user options" do
283
+ prepare_plugin do |p, c|
284
+ end
285
+
286
+ @plugin.build_xml(:bus => 'bus', :os_type => :box, :domain_type => :grinder).
287
+ should == open("#{File.dirname(__FILE__)}/libvirt_test.xml").read
288
+ end
289
+
290
+ it "should allow modification of the xml definition via script" do
291
+ prepare_plugin do |p, c|
292
+ c['script'] = "#{File.dirname(__FILE__)}/libvirt_modify.sh"
293
+ end
294
+
295
+ @plugin.build_xml(:bus => 'bus', :os_type => :box, :domain_type => :grinder).
296
+ should == open("#{File.dirname(__FILE__)}/libvirt_modified.xml").read
297
+ end
298
+ end
299
+ end
300
+ end
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0"?>
2
+ <domain type="grinder">
3
+ <name>appliance-1-0-fedora-13-x86_64-raw</name>
4
+ <description>boxgrinder-rocks</description>
5
+ <memory>262144</memory>
6
+ <vcpu/>
7
+ <os>
8
+ <type arch="x86_64">box</type>
9
+ <boot dev="hd"/>
10
+ </os>
11
+ <devices>
12
+ <disk type="file" device="disk">
13
+ <source file="/var/lib/libvirt/images/bble.raw"/>
14
+ <target dev="hda" bus="bus"/>
15
+ </disk>
16
+ <interface type="br">
17
+ <source network="default"/>
18
+ </interface>
19
+ <console type="pty"/>
20
+ <graphics type="vnc" port="-1"/>
21
+ </devices>
22
+ <features>
23
+ <pae/>
24
+ </features>
25
+ </domain>
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'nokogiri'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+
10
+ opts.on("-d", "--domain STRING", String, :required, "Domain XML") do |v|
11
+ options[:domain] = v
12
+ end
13
+
14
+ end.parse!
15
+
16
+ doc = Nokogiri::XML(options[:domain])
17
+ doc.xpath('//devices/interface/@type').first.value = "br"
18
+ STDOUT.puts doc.to_s
@@ -0,0 +1,24 @@
1
+ <domain type="grinder">
2
+ <name>appliance-1-0-fedora-13-x86_64-raw</name>
3
+ <description>boxgrinder-rocks</description>
4
+ <memory>262144</memory>
5
+ <vcpu/>
6
+ <os>
7
+ <type arch="x86_64">box</type>
8
+ <boot dev="hd"/>
9
+ </os>
10
+ <devices>
11
+ <disk type="file" device="disk">
12
+ <source file="/var/lib/libvirt/images/bble.raw"/>
13
+ <target dev="hda" bus="bus"/>
14
+ </disk>
15
+ <interface type="network">
16
+ <source network="default"/>
17
+ </interface>
18
+ <console type="pty"/>
19
+ <graphics type="vnc" port="-1"/>
20
+ </devices>
21
+ <features>
22
+ <pae/>
23
+ </features>
24
+ </domain>
@@ -36,14 +36,11 @@ module BoxGrinder
36
36
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => :fedora, :version => '13'}))
37
37
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64'}))
38
38
 
39
- @plugin = LocalPlugin.new.init(@config, @appliance_config,
40
- {:class => BoxGrinder::LocalPlugin, :type => :delivery, :name => :local, :full_name => "Local file system"},
41
- :log => LogHelper.new(:level => :trace, :type => :stdout),
42
- :previous_plugin => OpenCascade.new(:deliverables => {:disk => "a_disk.raw", :metadata => 'metadata.xml'})
39
+ @plugin = RSpecPluginHelper.new(LocalPlugin).prepare(@config, @appliance_config,
40
+ :previous_plugin => OpenCascade.new(:type => :os, :deliverables => {:disk => "a_disk.raw", :metadata => 'metadata.xml'}),
41
+ :plugin_info => {:class => BoxGrinder::LocalPlugin, :type => :delivery, :name => :local, :full_name => "Local file system"}
43
42
  )
44
43
 
45
- @plugin.validate
46
-
47
44
  @plugin_config = @config.plugins['local']
48
45
  @appliance_config = @plugin.instance_variable_get(:@appliance_config)
49
46
  @exec_helper = @plugin.instance_variable_get(:@exec_helper)
@@ -0,0 +1,103 @@
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/delivery/openstack/openstack-plugin'
20
+
21
+ module BoxGrinder
22
+ describe OpenStackPlugin do
23
+ before(:each) do
24
+ @config = Config.new #('plugins' => {'openstack' => {'host' => 'a/path'}})
25
+
26
+ @appliance_config = mock('ApplianceConfig')
27
+
28
+ @appliance_config.stub!(:name).and_return('appliance_name')
29
+ @appliance_config.stub!(:version).and_return(1)
30
+ @appliance_config.stub!(:release).and_return(0)
31
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '14'}))
32
+ @appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64', :base_arch => 'x86_64'}))
33
+ @appliance_config.stub!(:path).and_return(OpenCascade.new({:build => '/a/build/path'}))
34
+
35
+ @plugin = RSpecPluginHelper.new(OpenStackPlugin).prepare(@config, @appliance_config,
36
+ :previous_plugin => OpenCascade.new(:type => :os, :deliverables => {:disk => "a_disk.raw", :metadata => 'metadata.xml'}),
37
+ :plugin_info => {:class => BoxGrinder::OpenStackPlugin, :type => :delivery, :name => :openstack, :full_name => "OpenStack" }
38
+ )
39
+ end
40
+
41
+ describe ".get_images" do
42
+ it "should get list of all images" do
43
+
44
+ RestClient.stub!(:get)
45
+ RestClient.should_receive(:get).with('http://localhost:9292/v1/images', :params => {}).and_return({"images" => [{"id" => 1}]}.to_json)
46
+
47
+ @plugin.get_images.should == [{"id" => 1}]
48
+ end
49
+
50
+ it "should get list of filtered images" do
51
+
52
+ RestClient.stub!(:get)
53
+ RestClient.should_receive(:get).with('http://localhost:9292/v1/images', :params => {:name => 'xyz'}).and_return({"images" => [{"id" => 1}]}.to_json)
54
+
55
+ @plugin.get_images(:name => "xyz").should == [{"id" => 1}]
56
+ end
57
+ end
58
+
59
+ describe ".delete_image" do
60
+ it "should delete selected image" do
61
+ RestClient.stub!(:delete)
62
+ RestClient.should_receive(:delete).with('http://localhost:9292/v1/images/1')
63
+ @plugin.delete_image(1)
64
+ end
65
+ end
66
+
67
+ describe ".disk_and_container_format" do
68
+ it "should specify valid disk and container format for vmware" do
69
+ @plugin.instance_variable_set(:@previous_plugin_info, :type => :platform, :name => :vmware)
70
+ @plugin.disk_and_container_format.should == [:vmdk, :bare]
71
+ end
72
+
73
+ it "should specify valid disk and container format for ec2" do
74
+ @plugin.instance_variable_set(:@previous_plugin_info, :type => :platform, :name => :ec2)
75
+ @plugin.disk_and_container_format.should == [:ami, :ami]
76
+ end
77
+
78
+ it "should specify valid disk and container format for virtualbox" do
79
+ @plugin.instance_variable_set(:@previous_plugin_info, :type => :platform, :name => :virtualbox)
80
+ @plugin.disk_and_container_format.should == [:vmdk, :bare]
81
+ end
82
+
83
+ it "should specify valid disk and container format for deliverables of os plugin" do
84
+ @plugin.instance_variable_set(:@previous_plugin_info, :type => :os, :name => :fedora)
85
+ @plugin.disk_and_container_format.should == [:raw, :bare]
86
+ end
87
+ end
88
+
89
+ describe ".post_image" do
90
+ it "should post the image" do
91
+ File.stub!(:new)
92
+ File.stub!(:size)
93
+ File.should_receive(:new).with('a_disk.raw', 'rb').and_return('file')
94
+ File.should_receive(:size).with('a_disk.raw').and_return(12345)
95
+ RestClient.stub!(:post)
96
+ RestClient.should_receive(:post).with('http://localhost:9292/v1/images', 'file', "x-image-meta-name"=>"appliance_name-1.0-raw", :content_type=>"application/octet-stream", "x-image-meta-is-public"=>"true", "x-image-meta-size"=>12345, "x-image-meta-property-distro"=>"Fedora 14", "x-image-meta-container-format"=>:bare, "x-image-meta-disk-format"=>:raw).and_return({"image" => {"id" => 1}}.to_json)
97
+
98
+ @plugin.post_image
99
+ end
100
+ end
101
+ end
102
+ end
103
+