boxgrinder-build 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/Manifest +2 -1
- data/Rakefile +1 -1
- data/boxgrinder-build.gemspec +6 -6
- data/integ/appliances/jeos-f16.appl +9 -0
- data/integ/spec/jeos-spec.rb +5 -0
- data/lib/boxgrinder-build/helpers/ec2-helper.rb +1 -1
- data/lib/boxgrinder-build/helpers/s3-helper.rb +2 -7
- data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +3 -5
- data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +29 -23
- data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +54 -3
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +0 -36
- data/lib/boxgrinder-build/plugins/os/rpm-based/src/motd.init +3 -2
- data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +8 -1
- data/rubygem-boxgrinder-build.spec +11 -3
- data/spec/helpers/ec2-helper-spec.rb +2 -2
- data/spec/helpers/guestfs-helper-spec.rb +3 -1
- data/spec/helpers/s3-helper-spec.rb +2 -19
- data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +18 -21
- data/spec/plugins/delivery/s3/s3-plugin-spec.rb +213 -163
- data/spec/plugins/os/fedora/fedora-plugin-spec.rb +37 -0
- data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +0 -30
- data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +25 -0
- metadata +10 -7
@@ -63,8 +63,8 @@ module BoxGrinder
|
|
63
63
|
AWS.config({:access_key_id => '', :secret_access_key => ''})
|
64
64
|
@ec2 = AWS::EC2.new
|
65
65
|
@s3 = AWS::S3.new
|
66
|
-
@s3helper = S3Helper.new(@ec2, @s3)
|
67
|
-
@ec2helper = EC2Helper.new(@ec2)
|
66
|
+
@s3helper = S3Helper.new(@ec2, @s3, :log => LogHelper.new(:level => :trace, :type => :stdout))
|
67
|
+
@ec2helper = EC2Helper.new(@ec2, :log => LogHelper.new(:level => :trace, :type => :stdout))
|
68
68
|
|
69
69
|
@plugin.instance_variable_set(:@ec2, @ec2)
|
70
70
|
@plugin.instance_variable_set(:@s3, @s3)
|
@@ -89,7 +89,7 @@ module BoxGrinder
|
|
89
89
|
supported_oses['fedora'].should == ['13', '14', '15']
|
90
90
|
supported_oses['centos'].should == ['5']
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should adjust fstab" do
|
94
94
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
95
95
|
|
@@ -99,7 +99,6 @@ module BoxGrinder
|
|
99
99
|
|
100
100
|
@plugin.adjust_fstab(guestfs)
|
101
101
|
end
|
102
|
-
#
|
103
102
|
|
104
103
|
describe '.free_device_suffix' do
|
105
104
|
it "should get a new free device" do
|
@@ -110,7 +109,7 @@ module BoxGrinder
|
|
110
109
|
|
111
110
|
@plugin.free_device_suffix.should == "f"
|
112
111
|
end
|
113
|
-
|
112
|
+
|
114
113
|
it "should get a new free device next in order" do
|
115
114
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
116
115
|
|
@@ -122,7 +121,7 @@ module BoxGrinder
|
|
122
121
|
@plugin.free_device_suffix.should == "g"
|
123
122
|
end
|
124
123
|
end
|
125
|
-
|
124
|
+
|
126
125
|
describe ".valid_platform?" do
|
127
126
|
it "should return true if on EC2" do
|
128
127
|
prepare_plugin do |plugin|
|
@@ -133,7 +132,7 @@ module BoxGrinder
|
|
133
132
|
end
|
134
133
|
@plugin.valid_platform?.should == true
|
135
134
|
end
|
136
|
-
|
135
|
+
|
137
136
|
it "should return false if NOT on EC2" do
|
138
137
|
prepare_plugin do |plugin|
|
139
138
|
plugin.stub!(:after_init)
|
@@ -142,53 +141,51 @@ module BoxGrinder
|
|
142
141
|
end
|
143
142
|
@plugin.valid_platform?.should == false
|
144
143
|
end
|
145
|
-
#
|
146
144
|
end
|
147
|
-
|
145
|
+
|
148
146
|
describe ".ebs_appliance_name" do
|
149
147
|
it "should return basic appliance name" do
|
150
148
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
151
149
|
@plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0/x86_64"
|
152
150
|
end
|
153
|
-
|
151
|
+
|
154
152
|
it "should always return basic appliance name when overwrite is enabled, but snapshot is disabled" do
|
155
153
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
156
154
|
@plugin_config.merge!('overwrite' => true, 'snapshot' => false)
|
157
155
|
@plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0/x86_64"
|
158
156
|
end
|
159
|
-
|
157
|
+
|
160
158
|
it "should still return a valid _initial_ snapshot appliance name, even if overwrite and snapshot are enabled on first ever run" do
|
161
159
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
162
160
|
@plugin_config.merge!('overwrite' => true, 'snapshot' => true)
|
163
161
|
|
164
|
-
@
|
162
|
+
@plugin.should_receive(:ami_by_name).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64")
|
165
163
|
@plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64"
|
166
164
|
end
|
167
|
-
|
165
|
+
|
168
166
|
it "should return 2nd snapshot of appliance" do
|
169
167
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
170
168
|
|
171
169
|
@plugin_config.merge!('snapshot' => true)
|
172
170
|
|
173
|
-
@
|
174
|
-
@
|
171
|
+
@plugin.should_receive(:ami_by_name).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64").and_return("blah")
|
172
|
+
@plugin.should_receive(:ami_by_name).with("appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64").and_return(nil)
|
175
173
|
|
176
174
|
@plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64"
|
177
175
|
end
|
178
|
-
|
176
|
+
|
179
177
|
it "should return the last snapshot name again when OVERWRITE is enabled" do
|
180
178
|
prepare_plugin { |plugin| plugin.stub!(:after_init) }
|
181
179
|
|
182
180
|
@plugin_config.merge!('snapshot' => true, 'overwrite' => true)
|
183
181
|
|
184
|
-
@
|
185
|
-
@
|
182
|
+
@plugin.should_receive(:ami_by_name).with("appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64").and_return("blah")
|
183
|
+
@plugin.should_receive(:ami_by_name).with("appliance_name/fedora/14/1.0-SNAPSHOT-2/x86_64").and_return(nil)
|
186
184
|
|
187
185
|
@plugin.ebs_appliance_name.should == "appliance_name/fedora/14/1.0-SNAPSHOT-1/x86_64"
|
188
186
|
end
|
189
|
-
|
190
|
-
|
191
|
-
#
|
187
|
+
end
|
188
|
+
|
192
189
|
describe ".stomp_ebs" do
|
193
190
|
before(:each) do
|
194
191
|
prepare_plugin
|
@@ -50,21 +50,23 @@ module BoxGrinder
|
|
50
50
|
@appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64', :base_arch => 'x86_64'}))
|
51
51
|
|
52
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)
|
53
|
-
@plugin.validate
|
53
|
+
@plugin.stub!(:validate)
|
54
54
|
|
55
55
|
#Set convenient dummies
|
56
|
+
AWS.stub!
|
56
57
|
AWS.config({:access_key_id => '', :secret_access_key => ''})
|
57
58
|
@ec2 = AWS::EC2.new
|
58
59
|
@s3 = AWS::S3.new
|
59
|
-
@s3helper = S3Helper.new(@ec2, @s3)
|
60
|
-
@ec2helper = EC2Helper.new(@ec2)
|
60
|
+
@s3helper = S3Helper.new(@ec2, @s3, :log => LogHelper.new(:level => :trace, :type => :stdout))
|
61
|
+
@ec2helper = EC2Helper.new(@ec2, :log => LogHelper.new(:level => :trace, :type => :stdout))
|
62
|
+
@bucket = mock(AWS::S3::Bucket)
|
61
63
|
|
62
64
|
@plugin.instance_variable_set(:@ec2, @ec2)
|
63
65
|
@plugin.instance_variable_set(:@s3, @s3)
|
64
66
|
@plugin.instance_variable_set(:@ec2helper, @ec2helper)
|
65
67
|
@plugin.instance_variable_set(:@s3helper, @s3helper)
|
68
|
+
@plugin.instance_variable_set(:@bucket, @bucket)
|
66
69
|
|
67
|
-
@asset_bucket = mock('Bucket')
|
68
70
|
|
69
71
|
@appliance_config = @plugin.instance_variable_get(:@appliance_config)
|
70
72
|
@exec_helper = @plugin.instance_variable_get(:@exec_helper)
|
@@ -80,11 +82,16 @@ module BoxGrinder
|
|
80
82
|
supportes_oses['centos'].should == ['5']
|
81
83
|
supportes_oses['rhel'].should == ['5', '6']
|
82
84
|
supportes_oses['sl'].should == ['5', '6']
|
83
|
-
supportes_oses['fedora'].should == ['13', '14', '15']
|
85
|
+
supportes_oses['fedora'].should == ['13', '14', '15', '16']
|
84
86
|
end
|
85
87
|
|
86
88
|
describe ".ami_key" do
|
87
89
|
|
90
|
+
before(:each) do
|
91
|
+
@key1 = mock('AWS::S3::S3Object-1')
|
92
|
+
@key2 = mock('AWS::S3::S3Object-2')
|
93
|
+
end
|
94
|
+
|
88
95
|
it "should generate valid ami_key" do
|
89
96
|
@plugin.ami_key("name", "this/is/a/path").should == "this/is/a/path/name/fedora/14/1.0/x86_64"
|
90
97
|
end
|
@@ -100,82 +107,56 @@ module BoxGrinder
|
|
100
107
|
it "should generate valid ami_key with snapshot number two" do
|
101
108
|
@config.plugins['s3'].merge!('snapshot' => true)
|
102
109
|
|
103
|
-
@
|
104
|
-
@
|
110
|
+
@key1.should_receive(:exists?).and_return(true)
|
111
|
+
@key2.should_receive(:exists?).and_return(false)
|
105
112
|
|
106
|
-
@s3helper.should_receive(:stub_s3obj).with(@
|
107
|
-
@s3helper.should_receive(:stub_s3obj).with(@
|
113
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-SNAPSHOT-1/x86_64/').and_return(@key1)
|
114
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-SNAPSHOT-2/x86_64/').and_return(@key2)
|
108
115
|
|
109
|
-
@plugin.should_receive(:asset_bucket).twice.and_return(@asset_bucket)
|
110
116
|
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-2/x86_64"
|
111
117
|
end
|
112
118
|
|
113
119
|
it "should return valid ami_key with snapshot and overwrite enabled" do
|
114
120
|
@config.plugins['s3'].merge!('snapshot' => true, 'overwrite' => true)
|
115
121
|
|
116
|
-
@
|
117
|
-
@
|
122
|
+
@key1.should_receive(:exists?).and_return(true)
|
123
|
+
@key2.should_receive(:exists?).and_return(false)
|
118
124
|
|
119
|
-
@s3helper.should_receive(:stub_s3obj).with(@
|
120
|
-
@s3helper.should_receive(:stub_s3obj).with(@
|
125
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-SNAPSHOT-1/x86_64/').and_return(@key1)
|
126
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, 'name/fedora/14/1.0-SNAPSHOT-2/x86_64/').and_return(@key2)
|
121
127
|
|
122
|
-
@plugin.should_receive(:asset_bucket).twice.and_return(@asset_bucket)
|
123
128
|
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-1/x86_64"
|
124
129
|
end
|
125
130
|
end
|
126
131
|
|
127
|
-
|
128
|
-
ami_manifest = mock('ami_manifest')
|
129
|
-
ami_manifest.should_receive(:read).and_return("!sdfrthty54623r2gertyhe(stdin)= wf34r32tewrgeg")
|
130
|
-
|
131
|
-
File.should_receive(:open).with("build/path/s3-plugin/ami/appliance.ec2.manifest.xml").and_return(ami_manifest)
|
132
|
-
|
133
|
-
f = mock('File')
|
134
|
-
f.should_receive(:write).with('!sdfrthty54623r2gertyhewf34r32tewrgeg')
|
135
|
-
|
136
|
-
File.should_receive(:open).with("build/path/s3-plugin/ami/appliance.ec2.manifest.xml", 'w').and_yield(f)
|
137
|
-
|
138
|
-
@plugin.fix_sha1_sum
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should upload to an S3 bucket" do
|
142
|
-
package_helper = mock(PackageHelper)
|
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")
|
144
|
-
|
145
|
-
PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
|
146
|
-
|
147
|
-
s3 = mock(AWS::S3)
|
148
|
-
@plugin.instance_variable_set(:@s3, s3)
|
149
|
-
|
150
|
-
File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
|
132
|
+
describe ".upload_to_bucket" do
|
151
133
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
@s3helper.should_receive(:stub_s3obj).and_return(s3obj)
|
156
|
-
@s3helper.stub!(:object_exists?).and_return(false)
|
134
|
+
before(:each) do
|
135
|
+
@package_helper = mock(PackageHelper)
|
136
|
+
@s3obj = mock(AWS::S3::S3Object)
|
157
137
|
|
158
|
-
|
159
|
-
|
138
|
+
PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(@package_helper)
|
139
|
+
@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")
|
160
140
|
|
161
|
-
|
162
|
-
|
163
|
-
|
141
|
+
File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
|
142
|
+
@s3helper.should_receive(:stub_s3obj).and_return(@s3obj)
|
143
|
+
end
|
164
144
|
|
165
|
-
|
145
|
+
it "should upload to an S3 bucket" do
|
146
|
+
@s3obj.stub!(:exists?).and_return(false)
|
166
147
|
|
167
|
-
|
168
|
-
@plugin.instance_variable_set(:@s3, s3)
|
148
|
+
@s3obj.should_receive(:write).with(:file => "build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz", :acl => :private)
|
169
149
|
|
170
|
-
|
150
|
+
@plugin.upload_to_bucket(:disk => "adisk")
|
151
|
+
end
|
171
152
|
|
172
|
-
|
173
|
-
|
153
|
+
it "should NOT upload to an S3 bucket when the file already exists" do
|
154
|
+
@s3obj.stub!(:exists?).and_return(true)
|
174
155
|
|
175
|
-
|
176
|
-
@s3helper.stub!(:object_exists?).and_return(true)
|
156
|
+
@s3obj.should_not_receive(:write)
|
177
157
|
|
178
|
-
|
158
|
+
@plugin.upload_to_bucket(:disk => "adisk")
|
159
|
+
end
|
179
160
|
end
|
180
161
|
|
181
162
|
it "should bundle the image" do
|
@@ -196,128 +177,206 @@ module BoxGrinder
|
|
196
177
|
end
|
197
178
|
|
198
179
|
describe ".execute" do
|
199
|
-
|
200
180
|
before(:each) do
|
201
181
|
@s3obj = mock(AWS::S3::S3Object)
|
202
|
-
@bucket = mock(AWS::S3::Bucket)
|
203
182
|
FileUtils.stub!(:mkdir_p)
|
204
183
|
end
|
205
|
-
#
|
206
|
-
it "should create an AMI" do
|
207
|
-
@plugin.instance_variable_set(:@type, :ami)
|
208
|
-
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
209
184
|
|
210
|
-
|
185
|
+
context "AMI" do
|
186
|
+
before(:each) do
|
187
|
+
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
188
|
+
@s3helper.should_receive(:stub_s3obj).with(@bucket, "ami/key/appliance.ec2.manifest.xml").and_return(@s3obj)
|
189
|
+
@plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
|
190
|
+
@plugin.instance_variable_set(:@type, :ami)
|
191
|
+
end
|
211
192
|
|
212
|
-
|
213
|
-
@s3helper.stub!(:stub_s3obj).and_return(@s3obj)
|
214
|
-
@s3helper.should_receive(:object_exists?).twice.with(@s3obj).and_return(false)
|
215
|
-
@plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
|
216
|
-
@plugin.should_receive(:fix_sha1_sum)
|
217
|
-
@plugin.should_receive(:upload_image)
|
218
|
-
@plugin.should_receive(:register_image)
|
219
|
-
|
220
|
-
@plugin.execute
|
221
|
-
end
|
222
|
-
#
|
223
|
-
it "should not upload an AMI because it's already there" do
|
224
|
-
@plugin.instance_variable_set(:@type, :ami)
|
193
|
+
it "should create an AMI" do
|
225
194
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
@plugin.should_not_receive(:upload_image)
|
231
|
-
@plugin.should_receive(:register_image)
|
195
|
+
@s3obj.should_receive(:exists?).twice.and_return(false)
|
196
|
+
@plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
|
197
|
+
@plugin.should_receive(:upload_image)
|
198
|
+
@plugin.should_receive(:register_image)
|
232
199
|
|
233
|
-
|
234
|
-
|
235
|
-
#
|
236
|
-
it "should upload an AMI even if one is already present in order to perform a snapshot" do
|
237
|
-
@config.plugins['s3'].merge!('snapshot' => true)
|
200
|
+
@plugin.execute
|
201
|
+
end
|
238
202
|
|
239
|
-
|
240
|
-
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
203
|
+
it "should not upload an AMI because it's already there" do
|
241
204
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
205
|
+
@s3obj.should_receive(:exists?).twice.and_return(true)
|
206
|
+
@plugin.should_not_receive(:upload_image)
|
207
|
+
@plugin.should_receive(:register_image)
|
208
|
+
|
209
|
+
@plugin.execute
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should upload an AMI even if one is already present in order to perform a snapshot" do
|
213
|
+
@config.plugins['s3'].merge!('snapshot' => true)
|
214
|
+
|
215
|
+
@s3obj.should_receive(:exists?).twice.and_return(false)
|
216
|
+
@plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
|
217
|
+
@plugin.should_receive(:upload_image)
|
218
|
+
@plugin.should_receive(:register_image)
|
219
|
+
|
220
|
+
@plugin.execute
|
221
|
+
end
|
259
222
|
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
223
|
+
|
224
|
+
context "s3" do
|
225
|
+
it "should upload image to s3" do
|
226
|
+
@plugin.instance_variable_set(:@type, :s3)
|
227
|
+
@plugin.instance_variable_set(:@previous_deliverables, :disk => 'a/disk')
|
228
|
+
@plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'})
|
229
|
+
@plugin.execute
|
230
|
+
end
|
266
231
|
end
|
267
232
|
|
233
|
+
context "cloudfront" do
|
234
|
+
it "should upload image to cloudfront" do
|
235
|
+
@plugin.instance_variable_set(:@type, :cloudfront)
|
236
|
+
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
237
|
+
@plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'}, :public_read)
|
238
|
+
@plugin.execute
|
239
|
+
end
|
240
|
+
end
|
268
241
|
end
|
269
|
-
|
242
|
+
|
270
243
|
describe ".validate" do
|
271
|
-
|
272
|
-
|
273
|
-
@plugin.
|
274
|
-
@plugin.
|
275
|
-
|
244
|
+
before(:each) do
|
245
|
+
@plugin.unstub!(:validate)
|
246
|
+
@plugin.stub!(:asset_bucket).and_return(nil)
|
247
|
+
@plugin.stub!(:asset_bucket).and_return(@bucket)
|
248
|
+
end
|
276
249
|
|
277
|
-
|
250
|
+
context "bucket is not already in existence" do
|
251
|
+
before(:each) do
|
252
|
+
@plugin.should_receive(:set_default_config_value).with('overwrite', false)
|
253
|
+
@plugin.should_receive(:set_default_config_value).with('path', '/')
|
254
|
+
@plugin.should_receive(:set_default_config_value).with('region', 'us-east-1')
|
255
|
+
end
|
278
256
|
|
279
|
-
|
280
|
-
end
|
281
|
-
#
|
282
|
-
it "should validate basic and additional ami params" do
|
283
|
-
@plugin.instance_variable_set(:@type, :ami)
|
257
|
+
it "should validate only basic params" do
|
284
258
|
|
285
|
-
|
286
|
-
@plugin.should_receive(:set_default_config_value).with('path', '/')
|
287
|
-
@plugin.should_receive(:set_default_config_value).with('region', 'us-east-1')
|
288
|
-
@plugin.should_receive(:set_default_config_value).with('snapshot', false)
|
259
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
289
260
|
|
290
|
-
|
291
|
-
|
261
|
+
@plugin.validate
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should validate basic and additional ami params" do
|
265
|
+
@plugin.instance_variable_set(:@type, :ami)
|
266
|
+
|
267
|
+
@plugin.should_receive(:set_default_config_value).with('snapshot', false)
|
268
|
+
|
269
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
270
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
271
|
+
|
272
|
+
File.stub!(:expand_path)
|
273
|
+
File.stub!(:exists?)
|
274
|
+
File.should_receive(:expand_path).with('/path/to/cert/file').and_return('path1')
|
275
|
+
File.should_receive(:exists?).with('path1').and_return(true)
|
276
|
+
File.should_receive(:expand_path).with('/path/to/key/file').and_return('path2')
|
277
|
+
File.should_receive(:exists?).with('path2').and_return(true)
|
278
|
+
|
279
|
+
@plugin.should_receive(:asset_bucket).with(false).and_return(nil)
|
280
|
+
@plugin.should_receive(:asset_bucket).with(true).and_return(@bucket)
|
281
|
+
|
282
|
+
@plugin.validate
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should raise because key file doesn't exists" do
|
286
|
+
@plugin.instance_variable_set(:@type, :ami)
|
287
|
+
|
288
|
+
@plugin.should_receive(:set_default_config_value).with('snapshot', false)
|
289
|
+
|
290
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
291
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
292
|
+
|
293
|
+
File.stub!(:expand_path)
|
294
|
+
File.stub!(:exists?)
|
295
|
+
File.should_receive(:expand_path).with('/path/to/cert/file').and_return('path1')
|
296
|
+
File.should_receive(:exists?).with('path1').and_return(true)
|
297
|
+
File.should_receive(:expand_path).with('/path/to/key/file').and_return('path2')
|
298
|
+
File.should_receive(:exists?).with('path2').and_return(false)
|
299
|
+
|
300
|
+
lambda { @plugin.validate }.should raise_error(PluginValidationError, "AWS key file doesn't exists, please check the path: '/path/to/key/file'.")
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should raise because key file doesn't exists" do
|
304
|
+
@plugin.instance_variable_set(:@type, :ami)
|
305
|
+
|
306
|
+
@plugin.should_receive(:set_default_config_value).with('snapshot', false)
|
307
|
+
|
308
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
309
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
310
|
+
|
311
|
+
File.stub!(:expand_path)
|
312
|
+
File.stub!(:exists?)
|
313
|
+
File.should_receive(:expand_path).with('/path/to/cert/file').and_return('path1')
|
314
|
+
File.should_receive(:exists?).with('path1').and_return(false)
|
315
|
+
|
316
|
+
lambda { @plugin.validate }.should raise_error(PluginValidationError, "AWS certificate file doesn't exists, please check the path: '/path/to/cert/file'.")
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should raise an error if an invalid region is specified" do
|
320
|
+
@plugin.instance_variable_set(:@type, :ami)
|
321
|
+
|
322
|
+
@config.plugins['s3']['region'] = 'near-spain-1'
|
323
|
+
|
324
|
+
@plugin.should_receive(:set_default_config_value).with('snapshot', false)
|
325
|
+
|
326
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
327
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
292
328
|
|
293
|
-
|
329
|
+
File.stub!(:expand_path)
|
330
|
+
File.stub!(:exists?)
|
331
|
+
File.should_receive(:expand_path).with('/path/to/cert/file').and_return('path1')
|
332
|
+
File.should_receive(:exists?).with('path1').and_return(true)
|
333
|
+
File.should_receive(:expand_path).with('/path/to/key/file').and_return('path2')
|
334
|
+
File.should_receive(:exists?).with('path2').and_return(true)
|
335
|
+
|
336
|
+
lambda { @plugin.validate }.should raise_error(PluginValidationError, "Invalid region specified: near-spain-1. This plugin is only aware of the following regions: us-west-1, ap-southeast-1, eu-west-1, us-east-1, ap-northeast-1.")
|
337
|
+
end
|
294
338
|
end
|
295
|
-
#
|
296
|
-
it "should raise an error if an invalid region is specified" do
|
297
|
-
@plugin.instance_variable_set(:@type, :ami)
|
298
339
|
|
299
|
-
|
340
|
+
context "bucket exists (AMI mode)" do
|
341
|
+
|
342
|
+
before(:each) do
|
343
|
+
@plugin.instance_variable_set(:@type, :ami)
|
344
|
+
@plugin.stub!(:set_default_config_value)
|
345
|
+
|
346
|
+
File.stub!(:expand_path)
|
347
|
+
File.stub!(:exists?)
|
348
|
+
File.should_receive(:expand_path).with('/path/to/cert/file').and_return('path1')
|
349
|
+
File.should_receive(:exists?).with('path1').and_return(true)
|
350
|
+
File.should_receive(:expand_path).with('/path/to/key/file').and_return('path2')
|
351
|
+
File.should_receive(:exists?).with('path2').and_return(true)
|
352
|
+
|
353
|
+
@plugin.should_receive(:validate_plugin_config).with(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
354
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should succeed if the bucket location constraint and region match" do
|
358
|
+
@plugin.should_receive(:asset_bucket).and_return(@bucket)
|
359
|
+
@bucket.should_receive(:location_constraint).and_return(nil)
|
300
360
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
361
|
+
@plugin.validate
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should raise an error if bucket location constraint and region do not match" do
|
365
|
+
@plugin.should_receive(:asset_bucket).and_return(@bucket)
|
366
|
+
@bucket.should_receive(:location_constraint).and_return('eu-west-1')
|
305
367
|
|
306
|
-
|
307
|
-
|
368
|
+
lambda { @plugin.validate }.should raise_error(PluginValidationError, "Existing bucket bucket has a location constraint that does not match the region selected. AMI region and bucket location constraint must match.")
|
369
|
+
end
|
308
370
|
|
309
|
-
lambda { @plugin.validate }.should raise_error(PluginValidationError)
|
310
371
|
end
|
311
|
-
#
|
312
372
|
end
|
313
|
-
#
|
314
|
-
describe ".bucket" do
|
315
373
|
|
374
|
+
describe ".bucket" do
|
316
375
|
it "should create the asset bucket by default" do
|
317
376
|
@config.plugins['s3'].merge!('region' => 'ap-southeast-1')
|
318
377
|
|
319
378
|
@s3helper.should_receive(:bucket).with(:bucket => 'bucket', :acl => :private,
|
320
|
-
:
|
379
|
+
:create_if_missing => true, :location_constraint => 'ap-southeast-1')
|
321
380
|
|
322
381
|
@plugin.asset_bucket
|
323
382
|
end
|
@@ -326,17 +385,14 @@ module BoxGrinder
|
|
326
385
|
@config.plugins['s3'].merge!('region' => 'ap-southeast-1')
|
327
386
|
|
328
387
|
@s3helper.should_receive(:bucket).with(:bucket => 'bucket', :acl => :private,
|
329
|
-
:
|
388
|
+
:create_if_missing => false, :location_constraint => 'ap-southeast-1')
|
330
389
|
|
331
390
|
@plugin.asset_bucket(false)
|
332
391
|
end
|
333
|
-
|
334
392
|
end
|
335
|
-
#
|
336
|
-
describe ".upload_image" do
|
337
393
|
|
394
|
+
describe ".upload_image" do
|
338
395
|
it "should upload image for default region" do
|
339
|
-
@plugin.should_receive(:asset_bucket)
|
340
396
|
@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"])
|
341
397
|
@plugin.upload_image("ami/key")
|
342
398
|
end
|
@@ -344,15 +400,12 @@ module BoxGrinder
|
|
344
400
|
it "should upload image for us-west-1 region" do
|
345
401
|
@config.plugins['s3'].merge!('region' => 'us-west-1')
|
346
402
|
|
347
|
-
@plugin.should_receive(:asset_bucket)
|
348
403
|
@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"])
|
349
404
|
@plugin.upload_image("ami/key")
|
350
405
|
end
|
351
|
-
|
352
406
|
end
|
353
|
-
#
|
354
|
-
describe ".register_image" do
|
355
407
|
|
408
|
+
describe ".register_image" do
|
356
409
|
before(:each) do
|
357
410
|
@ami = mock(AWS::EC2::Image)
|
358
411
|
@ami.stub!(:id).and_return('ami-1234')
|
@@ -363,7 +416,7 @@ module BoxGrinder
|
|
363
416
|
@ec2.stub!(:images)
|
364
417
|
@ec2helper.stub!(:wait_for_image_state)
|
365
418
|
end
|
366
|
-
|
419
|
+
|
367
420
|
context "when the AMI has not been registered" do
|
368
421
|
before(:each) do
|
369
422
|
@plugin.stub!(:ami_by_manifest_key).and_return(nil)
|
@@ -376,12 +429,12 @@ module BoxGrinder
|
|
376
429
|
@plugin.register_image(@manifest_key)
|
377
430
|
end
|
378
431
|
end
|
379
|
-
|
432
|
+
|
380
433
|
context "when the AMI has been registered" do
|
381
434
|
before(:each) do
|
382
435
|
@plugin.stub!(:ami_by_manifest_key).and_return(@ami)
|
383
436
|
end
|
384
|
-
|
437
|
+
|
385
438
|
it "should not register the AMI" do
|
386
439
|
@plugin.should_receive(:ami_by_manifest_key).with(@manifest_key)
|
387
440
|
@ec2.images.should_not_receive(:create)
|
@@ -389,11 +442,9 @@ module BoxGrinder
|
|
389
442
|
@plugin.register_image(@manifest_key)
|
390
443
|
end
|
391
444
|
end
|
392
|
-
|
393
445
|
end
|
394
446
|
|
395
447
|
describe ".deregister_image" do
|
396
|
-
|
397
448
|
before(:each) do
|
398
449
|
@ami = mock(AWS::EC2::Image)
|
399
450
|
@plugin.stub!(:ami_by_manifest_key).and_return(@ami)
|
@@ -411,7 +462,6 @@ module BoxGrinder
|
|
411
462
|
@ec2helper.should_receive(:wait_for_image_death).with(@ami)
|
412
463
|
@plugin.deregister_image(@manifest_key)
|
413
464
|
end
|
414
|
-
|
415
465
|
end
|
416
466
|
|
417
467
|
end
|