boxgrinder-build 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG +12 -0
  2. data/Manifest +6 -5
  3. data/README.md +1 -1
  4. data/Rakefile +13 -20
  5. data/boxgrinder-build.gemspec +7 -10
  6. data/lib/boxgrinder-build/helpers/aws-helper.rb +81 -0
  7. data/lib/boxgrinder-build/helpers/ec2-helper.rb +182 -0
  8. data/lib/boxgrinder-build/helpers/guestfs-helper.rb +5 -1
  9. data/lib/boxgrinder-build/helpers/s3-helper.rb +124 -0
  10. data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +95 -299
  11. data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +2 -1
  12. data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +67 -133
  13. data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +15 -14
  14. data/rubygem-boxgrinder-build.spec +23 -28
  15. data/spec/appliance-spec.rb +1 -0
  16. data/spec/helpers/augeas-helper-spec.rb +1 -0
  17. data/spec/helpers/ec2-helper-spec.rb +260 -0
  18. data/spec/helpers/guestfs-helper-spec.rb +34 -7
  19. data/spec/helpers/image-helper-spec.rb +1 -0
  20. data/spec/helpers/linux-helper-spec.rb +1 -0
  21. data/spec/helpers/package-helper-spec.rb +1 -0
  22. data/spec/helpers/plugin-helper-spec.rb +1 -0
  23. data/spec/helpers/s3-helper-spec.rb +168 -0
  24. data/spec/managers/plugin-manager-spec.rb +1 -0
  25. data/spec/plugins/base-plugin-spec.rb +1 -1
  26. data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +115 -204
  27. data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +5 -4
  28. data/spec/plugins/delivery/local/local-plugin-spec.rb +1 -0
  29. data/spec/plugins/delivery/s3/s3-plugin-spec.rb +143 -134
  30. data/spec/plugins/delivery/sftp/sftp-plugin-spec.rb +1 -0
  31. data/spec/plugins/os/centos/centos-plugin-spec.rb +1 -0
  32. data/spec/plugins/os/fedora/fedora-plugin-spec.rb +1 -0
  33. data/spec/plugins/os/rhel/rhel-plugin-spec.rb +1 -0
  34. data/spec/plugins/os/rpm-based/kickstart-spec.rb +5 -1
  35. data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +9 -7
  36. data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +1 -0
  37. data/spec/plugins/os/sl/sl-plugin-spec.rb +1 -0
  38. data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +1 -0
  39. data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +1 -0
  40. data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +1 -0
  41. metadata +17 -23
@@ -17,6 +17,7 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'rubygems'
20
+ require 'rspec'
20
21
  require 'boxgrinder-build/managers/plugin-manager'
21
22
 
22
23
  module BoxGrinder
@@ -17,6 +17,7 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'rubygems'
20
+ require 'rspec'
20
21
  require 'boxgrinder-build/plugins/base-plugin'
21
22
  require 'boxgrinder-core/helpers/log-helper'
22
23
  require 'yaml'
@@ -99,7 +100,6 @@ module BoxGrinder
99
100
 
100
101
  File.should_receive(:exists?).once.with(any_args()).and_return(true)
101
102
  File.should_receive(:exists?).once.with(any_args()).and_return(false)
102
- File.should_not_receive(:exists?)
103
103
 
104
104
  @plugin.deliverables_exists?.should == false
105
105
  end
@@ -16,11 +16,12 @@
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 'boxgrinder-build/plugins/delivery/ebs/ebs-plugin'
19
20
  require 'rubygems'
21
+ require 'rspec'
20
22
  require 'ostruct'
21
23
  require 'logger'
22
- require 'boxgrinder-build/plugins/delivery/ebs/ebs-plugin'
23
- require 'hashery/opencascade'
24
+ require 'set'
24
25
 
25
26
  module BoxGrinder
26
27
 
@@ -37,7 +38,7 @@ module BoxGrinder
37
38
  @config = Config.new('plugins' => { 'ebs' => {
38
39
  'access_key' => 'access_key',
39
40
  'secret_access_key' => 'secret_access_key',
40
- 'account_number' => '0000-0000-0000'
41
+ 'account_number' => '000000000000'
41
42
  }})
42
43
 
43
44
  @appliance_config = mock('ApplianceConfig')
@@ -58,7 +59,21 @@ module BoxGrinder
58
59
  :log => LogHelper.new(:level => :trace, :type => :stdout)
59
60
  )
60
61
 
62
+ #Set convenient dummies
63
+ AWS.config({:access_key_id => '', :secret_access_key => ''})
64
+ @ec2 = AWS::EC2.new
65
+ @s3 = AWS::S3.new
66
+ @s3helper = S3Helper.new(@ec2, @s3)
67
+ @ec2helper = EC2Helper.new(@ec2)
68
+
69
+ @plugin.instance_variable_set(:@ec2, @ec2)
70
+ @plugin.instance_variable_set(:@s3, @s3)
71
+ @plugin.instance_variable_set(:@ec2helper, @ec2helper)
72
+ @plugin.instance_variable_set(:@s3helper, @s3helper)
73
+
61
74
  @plugin_config = @config.plugins['ebs']
75
+
76
+ @plugin.instance_variable_set(:@plugin_config, @plugin_config)
62
77
  end
63
78
 
64
79
  it "should register all operating systems with specific versions" do
@@ -69,288 +84,184 @@ module BoxGrinder
69
84
  supported_oses = @plugin.instance_variable_get(:@supported_oses)
70
85
 
71
86
  supported_oses.size.should == 3
72
- supported_oses.keys.sort.should == ['fedora', 'rhel', 'centos'].sort
87
+ Set.new(supported_oses.keys).should == Set.new(['fedora', 'rhel', 'centos'])
73
88
  supported_oses['rhel'].should == ['6']
74
89
  supported_oses['fedora'].should == ['13', '14', '15']
75
90
  supported_oses['centos'].should == ['5']
76
91
  end
77
-
78
- describe ".after_init" do
79
- it "should set the region" do
80
- prepare_plugin do |plugin|
81
- plugin.instance_variable_set(:@current_availability_zone, 'us-east-1a')
82
- end
83
-
84
- @plugin.instance_variable_get(:@region).should == 'us-east-1'
85
- end
86
- end
87
-
88
- describe '.ami_info' do
89
-
90
- it "should check if image is already registered and return false if there are no images registered for this account" do
91
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
92
-
93
- plugin_config = mock('PluginConfig')
94
- plugin_config.should_receive(:[]).with('account_number').and_return('0000-0000-0000')
95
-
96
- @plugin.instance_variable_set(:@plugin_config, plugin_config)
97
-
98
- ec2 = mock('EC2')
99
- ec2.should_receive(:describe_images).with(:owner_id => '000000000000')
100
-
101
- @plugin.instance_variable_set(:@ec2, ec2)
102
-
103
- @plugin.ami_info('aname').should == false
104
- end
105
-
106
- it "should check if image is already registered and return false if there are no images with name aname_new" do
107
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
108
-
109
- plugin_config = mock('PluginConfig')
110
- plugin_config.should_receive(:[]).with('account_number').and_return('0000-0000-0000')
111
-
112
- @plugin.instance_variable_set(:@plugin_config, plugin_config)
113
-
114
- ec2 = mock('EC2')
115
- ec2.should_receive(:describe_images).with(:owner_id => '000000000000').and_return({'imagesSet' => {'item' => [{'name' => 'abc', 'imageId' => '1'}, {'name' => 'aname', 'imageId' => '2'}]}})
116
-
117
- @plugin.instance_variable_set(:@ec2, ec2)
118
-
119
- @plugin.ami_info('aname_new').should == false
120
- end
121
-
122
- it "should return valid AMI information map for a single matching image when a valid imageId exists" do
123
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
124
-
125
- plugin_config = mock('PluginConfig')
126
- plugin_config.should_receive(:[]).with('account_number').and_return('0000-0000-0000')
127
-
128
- @plugin.instance_variable_set(:@plugin_config, plugin_config)
129
-
130
- ec2 = mock('EC2')
131
- ec2.should_receive(:describe_images).with(:owner_id => '000000000000').and_return({'imagesSet' => {'item' => [{'name' => 'abc', 'imageId' => '1'}, {'name' => 'aname', 'imageId' => '2'}]}})
132
-
133
- @plugin.instance_variable_set(:@ec2, ec2)
134
-
135
- @plugin.ami_info('aname').should == {'name' => 'aname', 'imageId' => '2'}
136
- end
137
-
138
- end
139
-
140
- describe '.already_registered?' do
141
-
142
- it "should check if image is already registered and return true image is registered" do
143
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
144
-
145
- plugin_config = mock('PluginConfig')
146
- plugin_config.should_receive(:[]).with('account_number').and_return('0000-0000-0000')
147
-
148
- @plugin.instance_variable_set(:@plugin_config, plugin_config)
149
-
150
- ec2 = mock('EC2')
151
- ec2.should_receive(:describe_images).with(:owner_id => '000000000000').and_return({'imagesSet' => {'item' => [{'name' => 'abc', 'imageId' => '1'}, {'name' => 'aname', 'imageId' => '2'}]}})
152
-
153
- @plugin.instance_variable_set(:@ec2, ec2)
154
-
155
- @plugin.already_registered?('aname').should == '2'
156
- end
157
-
158
- end
159
-
92
+ #
160
93
  it "should adjust fstab" do
161
94
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
162
95
 
163
96
  guestfs = mock('GuestFS')
164
-
165
97
  guestfs.should_receive(:sh).with("cat /etc/fstab | grep -v '/mnt' | grep -v '/data' | grep -v 'swap' > /etc/fstab.new")
166
98
  guestfs.should_receive(:mv).with("/etc/fstab.new", "/etc/fstab")
167
99
 
168
100
  @plugin.adjust_fstab(guestfs)
169
101
  end
102
+ #
170
103
 
171
- it "should get a new free device" do
172
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
173
-
174
- File.should_receive(:exists?).with("/dev/sdf").and_return(false)
175
- File.should_receive(:exists?).with("/dev/xvdf").and_return(false)
104
+ describe '.free_device_suffix' do
105
+ it "should get a new free device" do
106
+ prepare_plugin { |plugin| plugin.stub!(:after_init) }
176
107
 
177
- @plugin.free_device_suffix.should == "f"
178
- end
108
+ File.should_receive(:exists?).with("/dev/sdf").and_return(false)
109
+ File.should_receive(:exists?).with("/dev/xvdf").and_return(false)
179
110
 
180
- it "should get a new free device next in order" do
181
- prepare_plugin { |plugin| plugin.stub!(:after_init) }
111
+ @plugin.free_device_suffix.should == "f"
112
+ end
113
+ #
114
+ it "should get a new free device next in order" do
115
+ prepare_plugin { |plugin| plugin.stub!(:after_init) }
182
116
 
183
- File.should_receive(:exists?).with("/dev/sdf").and_return(false)
184
- File.should_receive(:exists?).with("/dev/xvdf").and_return(true)
185
- File.should_receive(:exists?).with("/dev/sdg").and_return(false)
186
- File.should_receive(:exists?).with("/dev/xvdg").and_return(false)
117
+ File.should_receive(:exists?).with("/dev/sdf").and_return(false)
118
+ File.should_receive(:exists?).with("/dev/xvdf").and_return(true)
119
+ File.should_receive(:exists?).with("/dev/sdg").and_return(false)
120
+ File.should_receive(:exists?).with("/dev/xvdg").and_return(false)
187
121
 
188
- @plugin.free_device_suffix.should == "g"
122
+ @plugin.free_device_suffix.should == "g"
123
+ end
189
124
  end
190
-
125
+ #
191
126
  describe ".valid_platform?" do
192
127
  it "should return true if on EC2" do
193
128
  prepare_plugin do |plugin|
194
129
  plugin.stub!(:after_init)
195
- plugin.stub!(:get_ec2_availability_zone).and_return("eu-west-1a")
196
- plugin.stub!(:availability_zone_to_region).and_return("eu-west-1")
130
+ @plugin.instance_variable_set(:@ec2_endpoints, EC2Helper::endpoints)
131
+ EC2Helper::stub!(:current_availability_zone).and_return('eu-west-1a')
132
+ EC2Helper::stub!(:availability_zone_to_region).with('eu-west-1a').and_return('eu-west-1')
197
133
  end
198
134
  @plugin.valid_platform?.should == true
199
135
  end
200
-
136
+ #
201
137
  it "should return false if NOT on EC2" do
202
138
  prepare_plugin do |plugin|
203
139
  plugin.stub!(:after_init)
204
- plugin.stub!(:get_ec2_availability_zone).and_raise(Timeout::Error)
140
+ @plugin.instance_variable_set(:@ec2_endpoints, EC2Helper::endpoints)
141
+ EC2Helper::stub!(:current_availability_zone).and_raise(Timeout::Error)
205
142
  end
206
143
  @plugin.valid_platform?.should == false
207
144
  end
208
-
209
- it "should return false if the EC2 zone returned is not supported" do
210
- prepare_plugin do |plugin|
211
- plugin.stub!(:after_init)
212
- plugin.stub!(:get_ec2_availability_zone).and_return("moon-west-7a")
213
- plugin.stub!(:availability_zone_to_region).and_return("moon-west-7")
214
- end
215
- @plugin.valid_platform?.should == false
216
- end
217
-
145
+ #
218
146
  end
219
-
147
+ #
220
148
  describe ".ebs_appliance_name" do
221
149
  it "should return basic appliance name" do
222
150
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
223
151
  @plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0/x86_64"
224
152
  end
225
-
153
+ #
226
154
  it "should always return basic appliance name when overwrite is enabled, but snapshot is disabled" do
227
155
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
228
156
  @plugin_config.merge!('overwrite' => true, 'snapshot' => false)
229
157
  @plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0/x86_64"
230
158
  end
231
-
159
+ #
232
160
  it "should still return a valid _initial_ snapshot appliance name, even if overwrite and snapshot are enabled on first ever run" do
233
161
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
234
-
235
162
  @plugin_config.merge!('overwrite' => true, 'snapshot' => true)
236
163
 
237
- ec2 = mock('EC2')
238
- ec2.should_receive(:describe_images).once.with(:owner_id => '000000000000').and_return(nil)#should be nothing
239
-
240
- @plugin.instance_variable_set(:@ec2, ec2)
241
-
164
+ @ec2helper.should_receive(:already_registered?).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64")
242
165
  @plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64"
243
166
  end
244
-
167
+ #
245
168
  it "should return 2nd snapshot of appliance" do
246
169
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
247
170
 
248
171
  @plugin_config.merge!('snapshot' => true)
249
172
 
250
- ec2 = mock('EC2')
251
- ec2.should_receive(:describe_images).twice.with(:owner_id => '000000000000').and_return({'imagesSet' => {'item' => [
252
- {'imageId' => '1', 'name' => 'appliance_name/fedora/14/1.0/x86_64'},
253
- {'imageId' => '2', 'name' => 'appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64'}
254
- ]}})
255
-
256
- @plugin.instance_variable_set(:@ec2, ec2)
173
+ @ec2helper.should_receive(:already_registered?).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64").and_return(true)
174
+ @ec2helper.should_receive(:already_registered?).with("appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64").and_return(false)
257
175
 
258
176
  @plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64"
259
177
  end
260
-
178
+ #
261
179
  it "should return the last snapshot name again when OVERWRITE is enabled" do
262
180
  prepare_plugin { |plugin| plugin.stub!(:after_init) }
263
181
 
264
182
  @plugin_config.merge!('snapshot' => true, 'overwrite' => true)
265
183
 
266
- ec2 = mock('EC2')
267
- ec2.should_receive(:describe_images).twice.with(:owner_id => '000000000000').and_return({'imagesSet' => {'item' => [
268
- {'imageId' => '1', 'name' => 'appliance_name/fedora/14/1.0/x86_64'},
269
- {'imageId' => '2', 'name' => 'appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64'}
270
- ]}})
271
-
272
- @plugin.instance_variable_set(:@ec2, ec2)
184
+ @ec2helper.should_receive(:already_registered?).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64").and_return(true)
185
+ @ec2helper.should_receive(:already_registered?).with("appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64").and_return(false)
273
186
 
274
187
  @plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64"
275
188
  end
276
-
189
+ #
277
190
  end
278
-
191
+ #
279
192
  describe ".stomp_ebs" do
280
-
281
193
  before(:each) do
282
- @ami_info = recursive_ostruct({'imageId' => 'sleepy', 'blockDeviceMapping' => {'item' => [{'deviceName' => '/dev/sda1', 'ebs' => {'snapshotId' => 'bashful'}}]}})
283
- @dummy_instances = recursive_ostruct([{'instanceId' => 'grumpy'},
284
- {'instanceId' => 'sneezy'}])
285
- @dummy_snapshot = recursive_ostruct({'snapshotId' => 'bashful', 'volumeId' => 'snow-white'})
286
- @dummy_volume_attached = recursive_ostruct({'volumeId' => 'snow-white', 'status' => 'attached'})
287
- @dummy_volume_detached = recursive_ostruct({'volumeId' => 'snow-white', 'status' => 'detached'})
194
+ prepare_plugin
195
+
196
+ @ami = mock(AWS::EC2::Image)
197
+ @ami.stub!(:id).and_return('ami-bratwurst')
198
+ @ami.stub!(:deregister)
199
+ @ami.stub!(:block_device_mappings).and_return({'/dev/sda1' => OpenStruct.new(
200
+ {'snapshot_id' => 'snap-hambiscuit', 'volume_size' => 2})}
201
+ )
202
+ @ami.stub!(:root_device_name).and_return('/dev/sda1')
203
+ instance_1 = mock(AWS::EC2::Instance)
204
+ instance_2 = mock(AWS::EC2::Instance)
205
+ instance_1.stub!(:id).and_return('i-cake')
206
+ instance_1.stub!(:status).and_return(:running)
207
+ instance_2.stub!(:id).and_return('i-bake')
208
+ instance_2.stub!(:status).and_return(:stopped)
209
+
210
+ @instances = [ instance_1, instance_2 ]
211
+
212
+ @snap = mock(AWS::EC2::Snapshot)
288
213
  end
289
214
 
290
- it "should return false if there was no block device found" do
291
- prepare_plugin do |plugin|
292
- plugin.stub!(:after_init)
293
- plugin.stub!(:block_device_from_ami).and_return(nil)
294
- end
295
- @plugin.stomp_ebs(@ami_info).should == false
215
+ it "destroys the preexisting EBS assets and de-registers the image with default settings" do
216
+ @ec2helper.stub!(:live_instances)
217
+ @ec2helper.should_receive(:snapshot_by_id).with('snap-hambiscuit').and_return(@snap)
218
+ @ami.should_receive(:deregister)
219
+ @ec2helper.should_receive(:wait_for_image_death).with(@ami)
220
+ @snap.should_receive(:delete)
221
+ @plugin.stomp_ebs(@ami)
296
222
  end
297
223
 
298
-
299
- it "should throw an exception if there is still an EBS instance[s] running when an overwrite is requested" do
300
- prepare_plugin do |plugin|
301
- plugin.stub!(:after_init)
302
- plugin.stub!(:snapshot_info).and_return(@dummy_snapshot)
303
- plugin.stub!(:get_instances).and_return(@dummy_instances)
304
- plugin.stub!(:get_volume_info).and_return(nil)
224
+ context "there are live running instances" do
225
+ before(:each) do
226
+ @ec2helper.stub!(:snapshot_by_id).and_return(@snap)
227
+ @ec2helper.stub!(:wait_for_image_death)
228
+ @ec2helper.stub!(:snapshot_by_id)
229
+ @ec2helper.stub!(:wait_for_image_death)
230
+ @ami.stub!(:deregister)
231
+ @snap.stub!(:delete)
305
232
  end
306
- lambda { @plugin.stomp_ebs(@ami_info) }.should raise_error(RuntimeError)
307
- end
308
233
 
309
- it "should detach and delete the block store, remove the snapshot and deregister the image" do
310
- prepare_plugin do |plugin|
311
- plugin.stub!(:after_init)
312
- plugin.stub!(:snapshot_info).and_return(@dummy_snapshot)
313
- plugin.stub!(:get_instances).and_return(false)
314
- plugin.stub!(:get_volume_info).and_return(@dummy_volume_attached, @dummy_volume_detached)
315
- plugin.stub!(:wait_for_volume_delete)
316
- plugin.stub!(:wait_for_snapshot_status)
317
- plugin.stub!(:wait_for_volume_status)
234
+ context "instance termination is disabled" do
235
+ it "raise an error to alert the user" do
236
+ @ec2helper.should_receive(:live_instances).with(@ami).and_return(@instances)
237
+ lambda { @plugin.stomp_ebs(@ami) }.should raise_error(RuntimeError)
238
+ end
318
239
  end
319
240
 
320
- ec2 = mock('EC2')
321
- ec2.should_receive(:detach_volume).with(:volume_id => 'snow-white', :force => true)
322
- ec2.should_receive(:delete_volume).with(:volume_id => 'snow-white')
323
- ec2.should_receive(:deregister_image).with(:image_id => 'sleepy')
324
- ec2.should_receive(:delete_snapshot).with(:snapshot_id => 'bashful')
325
-
326
-
327
- @plugin.instance_variable_set(:@ec2, ec2)
328
- @plugin.stomp_ebs(@ami_info)
241
+ context "instance termination is enabled" do
242
+ it "terminate any running instances" do
243
+ @plugin_config.merge!('terminate_instances' => true)
244
+ @ec2helper.should_receive(:live_instances).with(@ami).and_return(@instances)
245
+ @plugin.should_receive(:terminate_instances).with(@instances)
246
+ @plugin.stomp_ebs(@ami)
247
+ end
248
+ end
329
249
  end
330
250
 
331
- it "should not delete AWS snapshots when preserve_snapshots is set" do
332
- prepare_plugin do |plugin|
333
- plugin.stub!(:after_init)
334
- plugin.stub!(:snapshot_info).and_return(@dummy_snapshot)
335
- plugin.stub!(:get_instances).and_return(false)
336
- plugin.stub!(:get_volume_info).and_return(@dummy_volume_attached, @dummy_volume_detached)
337
- plugin.stub!(:wait_for_volume_delete)
338
- plugin.stub!(:wait_for_snapshot_status)
339
- plugin.stub!(:wait_for_volume_status)
251
+ context "snapshot preservation" do
252
+ before(:each) do
253
+ @ec2helper.stub!(:live_instances).and_return(false)
340
254
  end
341
255
 
342
- @plugin_config.merge!('preserve_snapshots' => true)
343
-
344
- ec2 = mock('EC2')
345
- ec2.should_receive(:detach_volume).with(:volume_id => 'snow-white', :force => true)
346
- ec2.should_receive(:delete_volume).with(:volume_id => 'snow-white')
347
- ec2.should_receive(:deregister_image).with(:image_id => 'sleepy')
348
- ec2.should_not_receive(:delete_snapshot).with(:snapshot_id => 'bashful')
349
-
350
- @plugin.instance_variable_set(:@ec2, ec2)
351
- @plugin.stomp_ebs(@ami_info)
256
+ it "retains the primary snapshot when preserve_snapshots is enabled" do
257
+ @plugin_config.merge!('preserve_snapshots' => true)
258
+ @ec2helper.should_receive(:snapshot_by_id).with('snap-hambiscuit').and_return(@snap)
259
+ @ami.should_receive(:deregister)
260
+ @ec2helper.should_receive(:wait_for_image_death).with(@ami)
261
+ @snap.should_not_receive(:delete)
262
+ @plugin.stomp_ebs(@ami)
263
+ end
352
264
  end
353
-
354
265
  end
355
266
 
356
267
  #Amazon-EC2 gem uses recursive ostructs, and wont work with opencascade