boxgrinder-build 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,8 +17,9 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'rubygems'
20
- require 'boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin'
20
+ require 'rspec'
21
21
  require 'hashery/opencascade'
22
+ require 'boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin'
22
23
 
23
24
  module BoxGrinder
24
25
  describe ElasticHostsPlugin do
@@ -165,7 +166,7 @@ module BoxGrinder
165
166
 
166
167
  describe ".upload_chunks" do
167
168
  it "should upload chunks in 2 parts" do
168
- @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
169
+ @plugin.instance_variable_set(:@previous_deliverables, OpenCascade.new({:disk => 'a/disk'}))
169
170
 
170
171
  f = mock(File)
171
172
  f.should_receive(:eof?).ordered.and_return(false)
@@ -190,7 +191,7 @@ module BoxGrinder
190
191
 
191
192
  it "should upload 1 chunk with custom chunk size" do
192
193
  @plugin_config.merge!('chunk' => 128)
193
- @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
194
+ @plugin.instance_variable_set(:@previous_deliverables, OpenCascade.new({:disk => 'a/disk'}))
194
195
 
195
196
  f = mock(File)
196
197
  f.should_receive(:eof?).ordered.and_return(false)
@@ -208,7 +209,7 @@ module BoxGrinder
208
209
 
209
210
  it "should not compress the data before uploading the chunks if we use CloudSigma" do
210
211
  @plugin_config.merge!('endpoint' => 'api.cloudsigma.com')
211
- @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
212
+ @plugin.instance_variable_set(:@previous_deliverables, OpenCascade.new({:disk => 'a/disk'}))
212
213
 
213
214
  f = mock(File)
214
215
  f.should_receive(:eof?).ordered.and_return(false)
@@ -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/delivery/local/local-plugin'
21
22
  require 'hashery/opencascade'
22
23
 
@@ -17,9 +17,11 @@
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/delivery/s3/s3-plugin'
21
22
  require 'hashery/opencascade'
22
23
  require 'boxgrinder-core/models/config'
24
+ require 'set'
23
25
 
24
26
  module BoxGrinder
25
27
  describe S3Plugin do
@@ -50,6 +52,20 @@ module BoxGrinder
50
52
  @plugin = S3Plugin.new.init(@config, @appliance_config, {:class => BoxGrinder::S3Plugin, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]}, :log => LogHelper.new(:level => :trace, :type => :stdout), :type => :s3)
51
53
  @plugin.validate
52
54
 
55
+ #Set convenient dummies
56
+ AWS.config({:access_key_id => '', :secret_access_key => ''})
57
+ @ec2 = AWS::EC2.new
58
+ @s3 = AWS::S3.new
59
+ @s3helper = S3Helper.new(@ec2, @s3)
60
+ @ec2helper = EC2Helper.new(@ec2)
61
+
62
+ @plugin.instance_variable_set(:@ec2, @ec2)
63
+ @plugin.instance_variable_set(:@s3, @s3)
64
+ @plugin.instance_variable_set(:@ec2helper, @ec2helper)
65
+ @plugin.instance_variable_set(:@s3helper, @s3helper)
66
+
67
+ @asset_bucket = mock('Bucket')
68
+
53
69
  @appliance_config = @plugin.instance_variable_get(:@appliance_config)
54
70
  @exec_helper = @plugin.instance_variable_get(:@exec_helper)
55
71
  @log = @plugin.instance_variable_get(:@log)
@@ -60,18 +76,15 @@ module BoxGrinder
60
76
  supportes_oses = @plugin.instance_variable_get(:@supported_oses)
61
77
 
62
78
  supportes_oses.size.should == 4
63
- supportes_oses.keys.sort.should == ['centos', 'fedora', 'rhel', 'sl']
79
+ Set.new(supportes_oses.keys).should == Set.new(['centos', 'fedora', 'rhel', 'sl'])
64
80
  supportes_oses['centos'].should == ['5']
65
81
  supportes_oses['rhel'].should == ['5', '6']
66
82
  supportes_oses['sl'].should == ['5', '6']
67
83
  supportes_oses['fedora'].should == ['13', '14', '15']
68
84
  end
69
85
 
70
- it "should generate valid s3 path" do
71
- @plugin.s3_path('/').should == ""
72
- end
73
-
74
86
  describe ".ami_key" do
87
+
75
88
  it "should generate valid ami_key" do
76
89
  @plugin.ami_key("name", "this/is/a/path").should == "this/is/a/path/name/fedora/14/1.0/x86_64"
77
90
  end
@@ -86,46 +99,27 @@ module BoxGrinder
86
99
 
87
100
  it "should generate valid ami_key with snapshot number two" do
88
101
  @config.plugins['s3'].merge!('snapshot' => true)
89
-
90
- bucket = mock('Bucket')
91
- bucket.should_receive(:keys).twice
92
-
93
- key = mock('Key')
94
- key.should_receive(:exists?).and_return(true)
95
-
96
- key1 = mock('Key')
97
- key1.should_receive(:exists?).and_return(false)
98
102
 
99
- bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-1/x86_64/").and_return(key)
100
- bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-2/x86_64/").and_return(key1)
103
+ @s3helper.should_receive(:object_exists?).and_return(true)
104
+ @s3helper.should_receive(:object_exists?).and_return(false)
101
105
 
102
- @plugin.should_receive(:bucket).twice.with(false).and_return(bucket)
106
+ @s3helper.should_receive(:stub_s3obj).with(@asset_bucket, 'name/fedora/14/1.0-SNAPSHOT-1/x86_64/')
107
+ @s3helper.should_receive(:stub_s3obj).with(@asset_bucket, 'name/fedora/14/1.0-SNAPSHOT-2/x86_64/')
103
108
 
109
+ @plugin.should_receive(:asset_bucket).twice.and_return(@asset_bucket)
104
110
  @plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-2/x86_64"
105
111
  end
106
112
 
107
113
  it "should return valid ami_key with snapshot and overwrite enabled" do
108
114
  @config.plugins['s3'].merge!('snapshot' => true, 'overwrite' => true)
109
- bucket = mock('Bucket')
110
- bucket.should_receive(:keys).twice
111
-
112
- key = mock('Key')
113
- key.should_receive(:exists?).and_return(true)
114
-
115
- key1 = mock('Key')
116
- key1.should_receive(:exists?).and_return(false)
117
115
 
118
- bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-1/x86_64/").and_return(key)
119
- bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-2/x86_64/").and_return(key1)
116
+ @s3helper.should_receive(:object_exists?).and_return(true)
117
+ @s3helper.should_receive(:object_exists?).and_return(false)
120
118
 
121
- @plugin.should_receive(:bucket).twice.with(false).and_return(bucket)
122
- # Re-use the last key again
123
- @plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-1/x86_64"
124
- end
119
+ @s3helper.should_receive(:stub_s3obj).with(@asset_bucket, 'name/fedora/14/1.0-SNAPSHOT-1/x86_64/')
120
+ @s3helper.should_receive(:stub_s3obj).with(@asset_bucket, 'name/fedora/14/1.0-SNAPSHOT-2/x86_64/')
125
121
 
126
- it "should generate valid ami_key with snapshot when bucket doesn't exist" do
127
- @config.plugins['s3'].merge!('snapshot' => true)
128
- @plugin.should_receive(:bucket).with(false).and_raise('ABC')
122
+ @plugin.should_receive(:asset_bucket).twice.and_return(@asset_bucket)
129
123
  @plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-1/x86_64"
130
124
  end
131
125
  end
@@ -144,88 +138,80 @@ module BoxGrinder
144
138
  @plugin.fix_sha1_sum
145
139
  end
146
140
 
147
- it "should upload to a S3 bucket" do
141
+ it "should upload to an S3 bucket" do
148
142
  package_helper = mock(PackageHelper)
149
143
  package_helper.should_receive(:package).with(".", "build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return("a_built_package.zip")
150
144
 
151
145
  PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
152
146
 
153
- s3 = mock(Aws::S3)
147
+ s3 = mock(AWS::S3)
154
148
  @plugin.instance_variable_set(:@s3, s3)
155
149
 
156
- key = mock('Key')
157
- key.should_receive(:exists?).twice.and_return(false)
158
- key.should_receive(:put).with('abc', 'private', :server => 's3.amazonaws.com')
159
-
160
- bucket = mock('Bucket')
161
- bucket.should_receive(:key).with("appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(key)
162
-
163
- @plugin.should_receive(:bucket).with(true, 'private').and_return(bucket)
164
-
165
- s3.should_receive(:close_connection)
166
-
167
150
  File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
168
151
 
169
- @plugin.should_receive(:open).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return("abc")
152
+ s3obj = mock(AWS::S3::S3Object)
153
+ s3obj.should_receive(:write).with(:file => "build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz", :acl => :private)
154
+
155
+ @s3helper.should_receive(:stub_s3obj).and_return(s3obj)
156
+ @s3helper.stub!(:object_exists?).and_return(false)
170
157
 
171
158
  @plugin.upload_to_bucket(:disk => "adisk")
172
159
  end
173
160
 
174
- it "should NOT upload to a S3 bucket because file exists" do
161
+ it "should NOT upload to an S3 bucket when the file already exists" do
175
162
  package_helper = mock(PackageHelper)
176
163
  package_helper.should_receive(:package).with(".", "build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return("a_built_package.zip")
177
164
 
178
165
  PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
179
166
 
180
- s3 = mock(Aws::S3)
167
+ s3 = mock(AWS::S3)
181
168
  @plugin.instance_variable_set(:@s3, s3)
182
169
 
183
- key = mock('Key')
184
- key.should_receive(:exists?).and_return(true)
185
-
186
- bucket = mock('Bucket')
187
- bucket.should_receive(:key).with("appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(key)
188
-
189
- @plugin.should_receive(:bucket).with(true, 'private').and_return(bucket)
170
+ File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
190
171
 
191
- s3.should_receive(:close_connection)
172
+ s3obj = mock(AWS::S3::S3Object)
173
+ s3obj.should_not_receive(:write)
192
174
 
193
- File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
175
+ @s3helper.should_receive(:stub_s3obj).and_return(s3obj)
176
+ @s3helper.stub!(:object_exists?).and_return(true)
194
177
 
195
178
  @plugin.upload_to_bucket(:disk => "adisk")
196
179
  end
197
180
 
198
181
  it "should bundle the image" do
199
182
  File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
200
- @exec_helper.should_receive(:execute).with(/euca-bundle-image --ec2cert (.*)src\/cert-ec2\.pem -i a\/path\/to\/disk\.ec2 --kernel aki-427d952b -c \/path\/to\/cert\/file -k \/path\/to\/key\/file -u 0000-0000-0000 -r x86_64 -d build\/path\/s3-plugin\/ami/, :redacted=>["0000-0000-0000", "/path/to/key/file", "/path/to/cert/file"])
183
+ FileUtils.stub!(:mkdir_p)
184
+ @exec_helper.should_receive(:execute).with(/euca-bundle-image --ec2cert (.*)src\/cert-ec2\.pem -i a\/path\/to\/disk\.ec2 --kernel aki-427d952b -c \/path\/to\/cert\/file -k \/path\/to\/key\/file -u 000000000000 -r x86_64 -d build\/path\/s3-plugin\/ami/, :redacted=>["000000000000", "/path/to/key/file", "/path/to/cert/file"])
201
185
  @plugin.bundle_image(:disk => "a/path/to/disk.ec2")
202
186
  end
203
187
 
204
188
  it "should bundle the image for centos 5 and choose right kernel and ramdisk" do
205
189
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'centos', :version => '5'}))
206
-
207
- File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
208
- @exec_helper.should_receive(:execute).with(/euca-bundle-image --ec2cert (.*)src\/cert-ec2\.pem -i a\/path\/to\/disk\.ec2 --kernel aki-427d952b -c \/path\/to\/cert\/file -k \/path\/to\/key\/file -u 0000-0000-0000 -r x86_64 -d build\/path\/s3-plugin\/ami/, :redacted=>["0000-0000-0000", "/path/to/key/file", "/path/to/cert/file"])
209
- @plugin.bundle_image(:disk => "a/path/to/disk.ec2")
210
- end
211
-
212
- it "should bundle the image for centos 5 anf choose right kernel and ramdisk" do
213
- @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'centos', :version => '5'}))
214
190
  @plugin.instance_variable_get(:@plugin_config).merge!({'region' => 'us-west-1'})
215
191
 
216
192
  File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
217
- @exec_helper.should_receive(:execute).with(/euca-bundle-image --ec2cert (.*)src\/cert-ec2\.pem -i a\/path\/to\/disk\.ec2 --kernel aki-9ba0f1de -c \/path\/to\/cert\/file -k \/path\/to\/key\/file -u 0000-0000-0000 -r x86_64 -d build\/path\/s3-plugin\/ami/, :redacted=>["0000-0000-0000", "/path/to/key/file", "/path/to/cert/file"])
193
+ FileUtils.stub!(:mkdir_p)
194
+ @exec_helper.should_receive(:execute).with(/euca-bundle-image --ec2cert (.*)src\/cert-ec2\.pem -i a\/path\/to\/disk\.ec2 --kernel aki-9ba0f1de -c \/path\/to\/cert\/file -k \/path\/to\/key\/file -u 000000000000 -r x86_64 -d build\/path\/s3-plugin\/ami/, :redacted=>["000000000000", "/path/to/key/file", "/path/to/cert/file"])
218
195
  @plugin.bundle_image(:disk => "a/path/to/disk.ec2")
219
196
  end
220
197
 
221
198
  describe ".execute" do
222
- it "should create AMI" do
223
- @plugin.instance_variable_set(:@type, :ami)
224
199
 
200
+ before(:each) do
201
+ @s3obj = mock(AWS::S3::S3Object)
202
+ @bucket = mock(AWS::S3::Bucket)
203
+ FileUtils.stub!(:mkdir_p)
204
+ end
205
+ #
206
+ it "should create an AMI" do
207
+ @plugin.instance_variable_set(:@type, :ami)
225
208
  @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
226
209
 
227
210
  @plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
228
- @plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(false)
211
+
212
+ @plugin.stub!(:asset_bucket).and_return(@bucket)
213
+ @s3helper.stub!(:stub_s3obj).and_return(@s3obj)
214
+ @s3helper.should_receive(:object_exists?).twice.with(@s3obj).and_return(false)
229
215
  @plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
230
216
  @plugin.should_receive(:fix_sha1_sum)
231
217
  @plugin.should_receive(:upload_image)
@@ -233,50 +219,56 @@ module BoxGrinder
233
219
 
234
220
  @plugin.execute
235
221
  end
236
-
237
- it "should not upload AMI because it's already there" do
222
+ #
223
+ it "should not upload an AMI because it's already there" do
238
224
  @plugin.instance_variable_set(:@type, :ami)
239
225
 
226
+ @plugin.stub!(:asset_bucket).and_return(@bucket)
227
+ @s3helper.should_receive(:stub_s3obj).with(@bucket, "ami/key/appliance.ec2.manifest.xml").and_return(@s3obj)
240
228
  @plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
241
- @plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(true)
229
+ @s3helper.should_receive(:object_exists?).twice.with(@s3obj).and_return(true)
242
230
  @plugin.should_not_receive(:upload_image)
243
231
  @plugin.should_receive(:register_image)
244
232
 
245
233
  @plugin.execute
246
234
  end
247
-
248
- it "should upload AMI even if it's already there because we want a snapshot" do
235
+ #
236
+ it "should upload an AMI even if one is already present in order to perform a snapshot" do
249
237
  @config.plugins['s3'].merge!('snapshot' => true)
250
238
 
251
239
  @plugin.instance_variable_set(:@type, :ami)
240
+ @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
252
241
 
242
+ @plugin.stub!(:asset_bucket).and_return(@bucket)
243
+ @s3helper.should_receive(:stub_s3obj).with(@bucket, "ami/key/appliance.ec2.manifest.xml").and_return(@s3obj)
253
244
  @plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
254
- @plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(true)
255
- @plugin.should_receive(:bundle_image).with({})
245
+ @s3helper.should_receive(:object_exists?).twice.with(@s3obj).and_return(false)
246
+ @plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
256
247
  @plugin.should_receive(:fix_sha1_sum)
257
- @plugin.should_receive(:upload_image).with("ami/key")
258
- @plugin.should_receive(:register_image).with("ami/key/appliance.ec2.manifest.xml")
248
+ @plugin.should_receive(:upload_image)
249
+ @plugin.should_receive(:register_image)
259
250
 
260
251
  @plugin.execute
261
252
  end
262
-
253
+ #
263
254
  it "should upload image to s3" do
264
255
  @plugin.instance_variable_set(:@type, :s3)
265
256
  @plugin.instance_variable_set(:@previous_deliverables, :disk => 'a/disk')
266
257
  @plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'})
267
258
  @plugin.execute
268
259
  end
269
-
260
+ #
270
261
  it "should upload image to cloudfront" do
271
262
  @plugin.instance_variable_set(:@type, :cloudfront)
272
263
  @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
273
- @plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'}, 'public-read')
264
+ @plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'}, :public_read)
274
265
  @plugin.execute
275
266
  end
276
- end
277
267
 
268
+ end
269
+ #
278
270
  describe ".validate" do
279
-
271
+ #
280
272
  it "should validate only basic params" do
281
273
  @plugin.should_receive(:set_default_config_value).with('overwrite', false)
282
274
  @plugin.should_receive(:set_default_config_value).with('path', '/')
@@ -286,7 +278,7 @@ module BoxGrinder
286
278
 
287
279
  @plugin.validate
288
280
  end
289
-
281
+ #
290
282
  it "should validate basic and additional ami params" do
291
283
  @plugin.instance_variable_set(:@type, :ami)
292
284
 
@@ -300,7 +292,7 @@ module BoxGrinder
300
292
 
301
293
  @plugin.validate
302
294
  end
303
-
295
+ #
304
296
  it "should raise an error if an invalid region is specified" do
305
297
  @plugin.instance_variable_set(:@type, :ami)
306
298
 
@@ -315,33 +307,36 @@ module BoxGrinder
315
307
  @plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
316
308
 
317
309
  lambda { @plugin.validate }.should raise_error(PluginValidationError)
318
-
319
310
  end
320
-
311
+ #
321
312
  end
322
-
313
+ #
323
314
  describe ".bucket" do
324
- it "should create the bucket" do
315
+
316
+ it "should create the asset bucket by default" do
325
317
  @config.plugins['s3'].merge!('region' => 'ap-southeast-1')
326
- s3 = mock(Aws::S3)
327
- Aws::S3.should_receive(:new).with("access_key", "secret_access_key", :connection_mode => :single, :logger => @log, :server=>"s3-ap-southeast-1.amazonaws.com").and_return(s3)
328
- s3.should_receive(:bucket).with("bucket", true, "private", :location => "ap-southeast-1")
329
- @plugin.bucket
318
+
319
+ @s3helper.should_receive(:bucket).with(:bucket => 'bucket', :acl => :private,
320
+ :create_of_missing => true, :location_constraint => 'ap-southeast-1')
321
+
322
+ @plugin.asset_bucket
330
323
  end
331
324
 
332
325
  it "should not create the bucket" do
333
326
  @config.plugins['s3'].merge!('region' => 'ap-southeast-1')
334
327
 
335
- s3 = mock(Aws::S3)
336
- Aws::S3.should_receive(:new).with("access_key", "secret_access_key", :connection_mode => :single, :logger => @log, :server=>"s3-ap-southeast-1.amazonaws.com").and_return(s3)
337
- s3.should_receive(:bucket).with("bucket", false, "private", :location => "ap-southeast-1")
338
- @plugin.bucket(false)
328
+ @s3helper.should_receive(:bucket).with(:bucket => 'bucket', :acl => :private,
329
+ :create_of_missing => false, :location_constraint => 'ap-southeast-1')
330
+
331
+ @plugin.asset_bucket(false)
339
332
  end
340
- end
341
333
 
334
+ end
335
+ #
342
336
  describe ".upload_image" do
337
+
343
338
  it "should upload image for default region" do
344
- @plugin.should_receive(:bucket)
339
+ @plugin.should_receive(:asset_bucket)
345
340
  @exec_helper.should_receive(:execute).with("euca-upload-bundle -U http://s3.amazonaws.com -b bucket/ami/key -m build/path/s3-plugin/ami/appliance.ec2.manifest.xml -a access_key -s secret_access_key", :redacted=>["access_key", "secret_access_key"])
346
341
  @plugin.upload_image("ami/key")
347
342
  end
@@ -349,61 +344,75 @@ module BoxGrinder
349
344
  it "should upload image for us-west-1 region" do
350
345
  @config.plugins['s3'].merge!('region' => 'us-west-1')
351
346
 
352
- @plugin.should_receive(:bucket)
347
+ @plugin.should_receive(:asset_bucket)
353
348
  @exec_helper.should_receive(:execute).with("euca-upload-bundle -U http://s3-us-west-1.amazonaws.com -b bucket/ami/key -m build/path/s3-plugin/ami/appliance.ec2.manifest.xml -a access_key -s secret_access_key", :redacted=>["access_key", "secret_access_key"])
354
349
  @plugin.upload_image("ami/key")
355
350
  end
356
- end
357
351
 
352
+ end
353
+ #
358
354
  describe ".register_image" do
355
+
359
356
  before(:each) do
360
- @ami_info = mock('AmiInfo')
361
- @ami_info.should_receive(:imageId).and_return('ami-1234')
357
+ @ami = mock(AWS::EC2::Image)
358
+ @ami.stub!(:id).and_return('ami-1234')
362
359
 
363
- @ec2 = mock("EC2")
364
- @ec2.stub(:register_image).and_return(@ami_info)
365
- @plugin.instance_variable_set(:@ec2, @ec2)
366
- end
360
+ @manifest_key = mock(AWS::S3::S3Object)
361
+ @manifest_key.stub!(:key).and_return('ami/manifest/key')
367
362
 
363
+ @ec2.stub!(:images)
364
+ @ec2helper.stub!(:wait_for_image_state)
365
+ end
366
+ #
368
367
  context "when the AMI has not been registered" do
369
368
  before(:each) do
370
- @plugin.stub(:ami_info)
369
+ @plugin.stub!(:ami_by_manifest_key).and_return(nil)
371
370
  end
372
371
 
373
372
  it "should register the AMI" do
374
- @plugin.should_receive(:ami_info).with("ami/manifest/key")
375
- @ec2.should_receive(:register_image).with(:image_location => "bucket/ami/manifest/key").and_return(@ami_info)
376
-
377
- @plugin.register_image("ami/manifest/key")
378
- end
379
-
380
- it "should report the region where the ami is registered" do
381
- @plugin.instance_variable_get(:@plugin_config)['region'] = 'a-region'
382
- @plugin.instance_variable_get(:@log).should_receive(:info).with(/a-region/)
383
-
384
- @plugin.register_image("ami/manifest/key")
373
+ @plugin.should_receive(:ami_by_manifest_key).with(@manifest_key)
374
+ @ec2.images.should_receive(:create).with(:image_location => "bucket/ami/manifest/key").and_return(@ami)
375
+ @ec2helper.should_receive(:wait_for_image_state).with(:available, @ami)
376
+ @plugin.register_image(@manifest_key)
385
377
  end
386
378
  end
387
-
379
+ #
388
380
  context "when the AMI has been registered" do
389
381
  before(:each) do
390
- @plugin.stub(:ami_info).and_return(@ami_info)
382
+ @plugin.stub!(:ami_by_manifest_key).and_return(@ami)
391
383
  end
392
-
384
+ #
393
385
  it "should not register the AMI" do
394
- @plugin.should_receive(:ami_info).with("ami/manifest/key").and_return(@ami_info)
395
- @ec2.should_not_receive(:register_image)
386
+ @plugin.should_receive(:ami_by_manifest_key).with(@manifest_key)
387
+ @ec2.images.should_not_receive(:create)
396
388
 
397
- @plugin.register_image("ami/manifest/key")
389
+ @plugin.register_image(@manifest_key)
398
390
  end
391
+ end
399
392
 
400
- it "should report the region where the ami is registed" do
401
- @plugin.instance_variable_get(:@plugin_config)['region'] = 'a-region'
402
- @plugin.instance_variable_get(:@log).should_receive(:info).with(/a-region/)
393
+ end
394
+
395
+ describe ".deregister_image" do
396
+
397
+ before(:each) do
398
+ @ami = mock(AWS::EC2::Image)
399
+ @plugin.stub!(:ami_by_manifest_key).and_return(@ami)
400
+
401
+ @manifest_key = mock(AWS::S3::S3Object)
402
+ @ec2helper.stub!(:wait_for_image_death)
403
+
404
+ @ami.stub!(:id)
405
+ @ami.stub!(:location)
406
+ end
407
+
408
+ it "should deregister the AMI" do
409
+ @plugin.should_receive(:ami_by_manifest_key).with(@manifest_key)
410
+ @ami.should_receive(:deregister)
411
+ @ec2helper.should_receive(:wait_for_image_death).with(@ami)
412
+ @plugin.deregister_image(@manifest_key)
413
+ end
403
414
 
404
- @plugin.register_image("ami/manifest/key")
405
- end
406
- end
407
415
  end
416
+
408
417
  end
409
418
  end