boxgrinder-build 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -0
- data/README.md +136 -0
- data/Rakefile +11 -6
- data/bin/boxgrinder-build +199 -0
- data/boxgrinder-build.gemspec +26 -14
- data/lib/boxgrinder-build/appliance.rb +6 -6
- data/lib/boxgrinder-build/helpers/guestfs-helper.rb +5 -3
- data/lib/boxgrinder-build/helpers/image-helper.rb +6 -0
- data/lib/boxgrinder-build/helpers/plugin-helper.rb +15 -4
- data/lib/boxgrinder-build/plugins/base-plugin.rb +1 -0
- data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +280 -0
- data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +66 -0
- data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +242 -0
- data/lib/boxgrinder-build/plugins/delivery/s3/src/cert-ec2.pem +23 -0
- data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +152 -0
- data/lib/boxgrinder-build/plugins/delivery/usb/usb-plugin.rb +43 -0
- data/lib/boxgrinder-build/plugins/os/centos/centos-plugin.rb +46 -0
- data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +61 -0
- data/lib/boxgrinder-build/plugins/os/rhel/rhel-plugin.rb +67 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +118 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +202 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +153 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/src/appliance.ks.erb +37 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/src/base.repo +4 -0
- data/lib/boxgrinder-build/plugins/os/rpm-based/src/motd.init +21 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +239 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_32bit +7 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/fstab_64bit +7 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/ifcfg-eth0 +7 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/menu.lst +6 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/rc_local +19 -0
- data/lib/boxgrinder-build/plugins/platform/virtualbox/virtualbox-plugin.rb +62 -0
- data/lib/boxgrinder-build/plugins/platform/vmware/src/README-enterprise +18 -0
- data/lib/boxgrinder-build/plugins/platform/vmware/src/README-personal +16 -0
- data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmdk +20 -0
- data/lib/boxgrinder-build/plugins/platform/vmware/src/base.vmx +45 -0
- data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +194 -0
- data/rubygem-boxgrinder-build.spec +73 -10
- data/spec/appliance-spec.rb +2 -2
- data/spec/helpers/guestfs-helper-spec.rb +4 -2
- data/spec/helpers/image-helper-spec.rb +4 -0
- data/spec/helpers/plugin-helper-spec.rb +0 -38
- data/spec/managers/plugin-manager-spec.rb +6 -6
- data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +230 -0
- data/spec/plugins/delivery/ebs/ebs.yaml +3 -0
- data/spec/plugins/delivery/local/local-plugin-spec.rb +133 -0
- data/spec/plugins/delivery/s3/s3-plugin-spec.rb +351 -0
- data/spec/plugins/delivery/sftp/sftp-plugin-spec.rb +26 -0
- data/spec/plugins/os/centos/centos-plugin-spec.rb +52 -0
- data/spec/plugins/os/fedora/fedora-plugin-spec.rb +73 -0
- data/spec/plugins/os/rhel/rhel-plugin-spec.rb +158 -0
- data/spec/plugins/os/rpm-based/kickstart-spec.rb +129 -0
- data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +162 -0
- data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +50 -0
- data/spec/plugins/os/rpm-based/src/jeos-f13-plain.ks +20 -0
- data/spec/plugins/os/rpm-based/src/jeos-f13-without-version.ks +22 -0
- data/spec/plugins/os/rpm-based/src/jeos-f13.ks +23 -0
- data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +339 -0
- data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +118 -0
- data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +299 -0
- metadata +149 -25
- data/README +0 -7
- data/bin/boxgrinder +0 -128
- data/lib/boxgrinder-build/helpers/thor-helper.rb +0 -85
@@ -0,0 +1,351 @@
|
|
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/s3/s3-plugin'
|
20
|
+
require 'hashery/opencascade'
|
21
|
+
# TODO remove this when it'll become not necessary
|
22
|
+
# quick fix for old active_support require issue in EPEL 5
|
23
|
+
require 'active_support/basic_object'
|
24
|
+
require 'active_support/duration'
|
25
|
+
|
26
|
+
module BoxGrinder
|
27
|
+
describe S3Plugin do
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
@config = mock('Config')
|
31
|
+
@config.stub!(:delivery_config).and_return({})
|
32
|
+
plugins = mock('Plugins')
|
33
|
+
plugins.stub!(:[]).with('s3').and_return({})
|
34
|
+
@config.stub!(:[]).with(:plugins).and_return(plugins)
|
35
|
+
|
36
|
+
@appliance_config = mock('ApplianceConfig')
|
37
|
+
|
38
|
+
@appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
|
39
|
+
@appliance_config.stub!(:name).and_return('appliance')
|
40
|
+
@appliance_config.stub!(:version).and_return(1)
|
41
|
+
@appliance_config.stub!(:release).and_return(0)
|
42
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '14'}))
|
43
|
+
@appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64', :base_arch => 'x86_64'}))
|
44
|
+
|
45
|
+
@plugin = S3Plugin.new.init(@config, @appliance_config, :log => Logger.new('/dev/null'), :plugin_info => {:class => BoxGrinder::S3Plugin, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]})
|
46
|
+
|
47
|
+
@config = @plugin.instance_variable_get(:@config)
|
48
|
+
@appliance_config = @plugin.instance_variable_get(:@appliance_config)
|
49
|
+
@exec_helper = @plugin.instance_variable_get(:@exec_helper)
|
50
|
+
@log = @plugin.instance_variable_get(:@log)
|
51
|
+
@dir = @plugin.instance_variable_get(:@dir)
|
52
|
+
|
53
|
+
@plugin_config = @plugin.instance_variable_get(:@plugin_config).merge(
|
54
|
+
{
|
55
|
+
'access_key' => 'access_key',
|
56
|
+
'secret_access_key' => 'secret_access_key',
|
57
|
+
'bucket' => 'bucket',
|
58
|
+
'account_number' => '0000-0000-0000',
|
59
|
+
'cert_file' => '/path/to/cert/file',
|
60
|
+
'key_file' => '/path/to/key/file',
|
61
|
+
'path' => '/'
|
62
|
+
}
|
63
|
+
)
|
64
|
+
|
65
|
+
@plugin.instance_variable_set(:@plugin_config, @plugin_config)
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should register all operating systems with specific versions" do
|
70
|
+
supportes_oses = @plugin.instance_variable_get(:@supported_oses)
|
71
|
+
|
72
|
+
supportes_oses.size.should == 3
|
73
|
+
supportes_oses.keys.sort.should == ['centos', 'fedora', 'rhel']
|
74
|
+
supportes_oses['centos'].should == ['5']
|
75
|
+
supportes_oses['rhel'].should == ['5', '6']
|
76
|
+
supportes_oses['fedora'].should == ['13', '14', '15']
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should generate valid s3 path" do
|
80
|
+
@plugin.s3_path('/').should == ""
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ".ami_key" do
|
84
|
+
it "should generate valid ami_key" do
|
85
|
+
@plugin.ami_key("name", "this/is/a/path").should == "this/is/a/path/name/fedora/14/1.0/x86_64"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should generate valid ami_key with mixed slashes" do
|
89
|
+
@plugin.ami_key("name", "//this/").should == "this/name/fedora/14/1.0/x86_64"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should generate valid ami_key with root path" do
|
93
|
+
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0/x86_64"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should generate valid ami_key with snapshot number two" do
|
97
|
+
@plugin_config.merge!('snapshot' => true)
|
98
|
+
bucket = mock('Bucket')
|
99
|
+
bucket.should_receive(:keys).twice
|
100
|
+
|
101
|
+
key = mock('Key')
|
102
|
+
key.should_receive(:exists?).and_return(true)
|
103
|
+
|
104
|
+
key1 = mock('Key')
|
105
|
+
key1.should_receive(:exists?).and_return(false)
|
106
|
+
|
107
|
+
bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-1/x86_64/").and_return(key)
|
108
|
+
bucket.should_receive(:key).with("name/fedora/14/1.0-SNAPSHOT-2/x86_64/").and_return(key1)
|
109
|
+
|
110
|
+
@plugin.should_receive(:bucket).twice.with(false).and_return(bucket)
|
111
|
+
|
112
|
+
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-2/x86_64"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should generate valid ami_key with snapshot when bucket doesn't exists" do
|
116
|
+
@plugin_config.merge!('snapshot' => true)
|
117
|
+
@plugin.should_receive(:bucket).with(false).and_raise('ABC')
|
118
|
+
@plugin.ami_key("name", "/").should == "name/fedora/14/1.0-SNAPSHOT-1/x86_64"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should fix sha1 sum" do
|
123
|
+
ami_manifest = mock('ami_manifest')
|
124
|
+
ami_manifest.should_receive(:read).and_return("!sdfrthty54623r2gertyhe(stdin)= wf34r32tewrgeg")
|
125
|
+
|
126
|
+
File.should_receive(:open).with("build/path/s3-plugin/ami/appliance.ec2.manifest.xml").and_return(ami_manifest)
|
127
|
+
|
128
|
+
f = mock('File')
|
129
|
+
f.should_receive(:write).with('!sdfrthty54623r2gertyhewf34r32tewrgeg')
|
130
|
+
|
131
|
+
File.should_receive(:open).with("build/path/s3-plugin/ami/appliance.ec2.manifest.xml", 'w').and_yield(f)
|
132
|
+
|
133
|
+
@plugin.fix_sha1_sum
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should upload to a S3 bucket" do
|
137
|
+
package_helper = mock(PackageHelper)
|
138
|
+
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")
|
139
|
+
|
140
|
+
PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
|
141
|
+
|
142
|
+
s3 = mock(Aws::S3)
|
143
|
+
@plugin.instance_variable_set(:@s3, s3)
|
144
|
+
|
145
|
+
key = mock('Key')
|
146
|
+
key.should_receive(:exists?).and_return(false)
|
147
|
+
key.should_receive(:put).with('abc', 'private', :server => 's3.amazonaws.com')
|
148
|
+
|
149
|
+
bucket = mock('Bucket')
|
150
|
+
bucket.should_receive(:key).with("appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(key)
|
151
|
+
|
152
|
+
@plugin.should_receive(:bucket).with(true, 'private').and_return(bucket)
|
153
|
+
|
154
|
+
s3.should_receive(:close_connection)
|
155
|
+
|
156
|
+
File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
|
157
|
+
|
158
|
+
@plugin.should_receive(:open).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return("abc")
|
159
|
+
|
160
|
+
@plugin.upload_to_bucket(:disk => "adisk")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should NOT upload to a S3 bucket because file exists" do
|
164
|
+
package_helper = mock(PackageHelper)
|
165
|
+
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")
|
166
|
+
|
167
|
+
PackageHelper.should_receive(:new).with(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).and_return(package_helper)
|
168
|
+
|
169
|
+
s3 = mock(Aws::S3)
|
170
|
+
@plugin.instance_variable_set(:@s3, s3)
|
171
|
+
|
172
|
+
key = mock('Key')
|
173
|
+
key.should_receive(:exists?).and_return(true)
|
174
|
+
|
175
|
+
bucket = mock('Bucket')
|
176
|
+
bucket.should_receive(:key).with("appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(key)
|
177
|
+
|
178
|
+
@plugin.should_receive(:bucket).with(true, 'private').and_return(bucket)
|
179
|
+
|
180
|
+
s3.should_receive(:close_connection)
|
181
|
+
|
182
|
+
File.should_receive(:size).with("build/path/s3-plugin/tmp/appliance-1.0-fedora-14-x86_64-raw.tgz").and_return(23234566)
|
183
|
+
|
184
|
+
@plugin.upload_to_bucket(:disk => "adisk")
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should bundle the image" do
|
188
|
+
File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
|
189
|
+
@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"])
|
190
|
+
@plugin.bundle_image(:disk => "a/path/to/disk.ec2")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should bundle the image for centos 5 anf choose right kernel and ramdisk" do
|
194
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'centos', :version => '5'}))
|
195
|
+
|
196
|
+
File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
|
197
|
+
@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"])
|
198
|
+
@plugin.bundle_image(:disk => "a/path/to/disk.ec2")
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should bundle the image for centos 5 anf choose right kernel and ramdisk" do
|
202
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'centos', :version => '5'}))
|
203
|
+
@plugin.instance_variable_get(:@plugin_config).merge!({'region' => 'us-west-1'})
|
204
|
+
|
205
|
+
File.should_receive(:exists?).with('build/path/s3-plugin/ami').and_return(false)
|
206
|
+
@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"])
|
207
|
+
@plugin.bundle_image(:disk => "a/path/to/disk.ec2")
|
208
|
+
end
|
209
|
+
|
210
|
+
describe ".execute" do
|
211
|
+
it "should create AMI" do
|
212
|
+
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
213
|
+
|
214
|
+
@plugin.should_receive(:validate_plugin_config).with(["bucket", "access_key", "secret_access_key"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
215
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
216
|
+
@plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
|
217
|
+
@plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(false)
|
218
|
+
@plugin.should_receive(:bundle_image).with(:disk => 'a/disk')
|
219
|
+
@plugin.should_receive(:fix_sha1_sum)
|
220
|
+
@plugin.should_receive(:upload_image)
|
221
|
+
@plugin.should_receive(:register_image)
|
222
|
+
|
223
|
+
@plugin.execute(:ami)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should not upload AMI because it's already there" do
|
227
|
+
@plugin.should_receive(:validate_plugin_config).with(["bucket", "access_key", "secret_access_key"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
228
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
229
|
+
@plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
|
230
|
+
@plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(true)
|
231
|
+
@plugin.should_not_receive(:upload_image)
|
232
|
+
@plugin.should_receive(:register_image)
|
233
|
+
|
234
|
+
@plugin.execute(:ami)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should upload AMI even if it's already there because we want a snapshot" do
|
238
|
+
@plugin_config.merge!('snapshot' => true)
|
239
|
+
|
240
|
+
@plugin.should_receive(:validate_plugin_config).with(["bucket", "access_key", "secret_access_key"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
241
|
+
@plugin.should_receive(:validate_plugin_config).with(["cert_file", "key_file", "account_number"], "http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin")
|
242
|
+
|
243
|
+
@plugin.should_receive(:ami_key).with("appliance", "/").and_return('ami/key')
|
244
|
+
@plugin.should_receive(:s3_object_exists?).with("ami/key/appliance.ec2.manifest.xml").and_return(true)
|
245
|
+
@plugin.should_receive(:bundle_image).with({})
|
246
|
+
@plugin.should_receive(:fix_sha1_sum)
|
247
|
+
@plugin.should_receive(:upload_image).with("ami/key")
|
248
|
+
@plugin.should_receive(:register_image).with("ami/key/appliance.ec2.manifest.xml")
|
249
|
+
|
250
|
+
@plugin.execute(:ami)
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should upload image to s3" do
|
254
|
+
@plugin.instance_variable_set(:@previous_deliverables, :disk => 'a/disk')
|
255
|
+
@plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'})
|
256
|
+
@plugin.execute(:s3)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should upload image to cludfront" do
|
260
|
+
@plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
|
261
|
+
@plugin.should_receive(:upload_to_bucket).with({:disk => 'a/disk'}, 'public-read')
|
262
|
+
@plugin.execute(:cloudfront)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe ".bucket" do
|
267
|
+
it "should create the bucket" do
|
268
|
+
@plugin_config.merge!('region' => 'ap-southeast-1')
|
269
|
+
s3 = mock(Aws::S3)
|
270
|
+
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)
|
271
|
+
s3.should_receive(:bucket).with("bucket", true, "private", :location => "ap-southeast-1")
|
272
|
+
@plugin.bucket
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should not create the bucket" do
|
276
|
+
@plugin_config.merge!('region' => 'ap-southeast-1')
|
277
|
+
s3 = mock(Aws::S3)
|
278
|
+
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)
|
279
|
+
s3.should_receive(:bucket).with("bucket", false, "private", :location => "ap-southeast-1")
|
280
|
+
@plugin.bucket(false)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe ".upload_image" do
|
285
|
+
it "should upload image for default region" do
|
286
|
+
@plugin.should_receive(:bucket)
|
287
|
+
@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"])
|
288
|
+
@plugin.upload_image("ami/key")
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should upload image for us-west-1 region" do
|
292
|
+
@plugin_config.merge!('region' => 'us-west-1')
|
293
|
+
|
294
|
+
@plugin.should_receive(:bucket)
|
295
|
+
@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"])
|
296
|
+
@plugin.upload_image("ami/key")
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe ".register_image" do
|
301
|
+
before(:each) do
|
302
|
+
@ami_info = mock('AmiInfo')
|
303
|
+
@ami_info.should_receive(:imageId).and_return('ami-1234')
|
304
|
+
|
305
|
+
@ec2 = mock("EC2")
|
306
|
+
@ec2.stub(:register_image).and_return(@ami_info)
|
307
|
+
@plugin.instance_variable_set(:@ec2, @ec2)
|
308
|
+
end
|
309
|
+
|
310
|
+
context "when the AMI has not been registered" do
|
311
|
+
before(:each) do
|
312
|
+
@plugin.stub(:ami_info)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should register the AMI" do
|
316
|
+
@plugin.should_receive(:ami_info).with("ami/manifest/key")
|
317
|
+
@ec2.should_receive(:register_image).with(:image_location => "bucket/ami/manifest/key").and_return(@ami_info)
|
318
|
+
|
319
|
+
@plugin.register_image("ami/manifest/key")
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should report the region where the ami is registed" do
|
323
|
+
@plugin.instance_variable_get(:@plugin_config)['region'] = 'a-region'
|
324
|
+
@plugin.instance_variable_get(:@log).should_receive(:info).with(/a-region/)
|
325
|
+
|
326
|
+
@plugin.register_image("ami/manifest/key")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context "when the AMI has been registered" do
|
331
|
+
before(:each) do
|
332
|
+
@plugin.stub(:ami_info).and_return(@ami_info)
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should not register the AMI" do
|
336
|
+
@plugin.should_receive(:ami_info).with("ami/manifest/key").and_return(@ami_info)
|
337
|
+
@ec2.should_not_receive(:register_image)
|
338
|
+
|
339
|
+
@plugin.register_image("ami/manifest/key")
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should report the region where the ami is registed" do
|
343
|
+
@plugin.instance_variable_get(:@plugin_config)['region'] = 'a-region'
|
344
|
+
@plugin.instance_variable_get(:@log).should_receive(:info).with(/a-region/)
|
345
|
+
|
346
|
+
@plugin.register_image("ami/manifest/key")
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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/sftp/sftp-plugin'
|
20
|
+
|
21
|
+
module BoxGrinder
|
22
|
+
describe SFTPPlugin do
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This is free software; you can redistribute it and/or modify it
|
5
|
+
# under the terms of the GNU Lesser General Public License as
|
6
|
+
# published by the Free Software Foundation; either version 3 of
|
7
|
+
# the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This software is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this software; if not, write to the Free
|
16
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
|
+
|
19
|
+
require 'boxgrinder-build/plugins/os/centos/centos-plugin'
|
20
|
+
require 'hashery/opencascade'
|
21
|
+
|
22
|
+
module BoxGrinder
|
23
|
+
describe CentOSPlugin do
|
24
|
+
before(:each) do
|
25
|
+
@config = mock('Config')
|
26
|
+
@config.stub!(:os_config).and_return({})
|
27
|
+
plugins = mock('Plugins')
|
28
|
+
plugins.stub!(:[]).with('centos').and_return({})
|
29
|
+
@config.stub!(:[]).with(:plugins).and_return(plugins)
|
30
|
+
|
31
|
+
@appliance_config = mock('ApplianceConfig')
|
32
|
+
|
33
|
+
@appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
|
34
|
+
@appliance_config.stub!(:name).and_return('full')
|
35
|
+
|
36
|
+
@plugin = CentOSPlugin.new.init(@config, @appliance_config, :log => Logger.new('/dev/null'), :plugin_info => {:class => BoxGrinder::CentOSPlugin, :type => :os, :name => :centos, :full_name => "CentOS", :versions => ["5"]})
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use basearch instead of arch in repository URLs" do
|
40
|
+
@plugin.should_receive(:build_rhel).with('file', {
|
41
|
+
"5" => {
|
42
|
+
"updates" => {
|
43
|
+
"mirrorlist"=>"http://mirrorlist.centos.org/?release=#OS_VERSION#&arch=#BASE_ARCH#&repo=updates"},
|
44
|
+
"base" => {
|
45
|
+
"mirrorlist"=>"http://mirrorlist.centos.org/?release=#OS_VERSION#&arch=#BASE_ARCH#&repo=os"}}
|
46
|
+
})
|
47
|
+
|
48
|
+
@plugin.execute('file')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This is free software; you can redistribute it and/or modify it
|
5
|
+
# under the terms of the GNU Lesser General Public License as
|
6
|
+
# published by the Free Software Foundation; either version 3 of
|
7
|
+
# the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This software is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this software; if not, write to the Free
|
16
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
|
+
|
19
|
+
require 'boxgrinder-build/plugins/os/fedora/fedora-plugin'
|
20
|
+
require 'hashery/opencascade'
|
21
|
+
|
22
|
+
module BoxGrinder
|
23
|
+
describe FedoraPlugin do
|
24
|
+
before(:each) do
|
25
|
+
@config = mock('Config')
|
26
|
+
@config.stub!(:os_config).and_return({})
|
27
|
+
plugins = mock('Plugins')
|
28
|
+
plugins.stub!(:[]).with('fedora').and_return({})
|
29
|
+
@config.stub!(:[]).with(:plugins).and_return(plugins)
|
30
|
+
|
31
|
+
@appliance_config = mock('ApplianceConfig')
|
32
|
+
|
33
|
+
@appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
|
34
|
+
@appliance_config.stub!(:name).and_return('full')
|
35
|
+
@appliance_config.stub!(:version).and_return(1)
|
36
|
+
@appliance_config.stub!(:release).and_return(0)
|
37
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '13'}))
|
38
|
+
@appliance_config.stub!(:hardware).and_return(OpenCascade.new({:arch => 'x86_64'}))
|
39
|
+
@appliance_config.stub!(:is64bit?).and_return(true)
|
40
|
+
|
41
|
+
@plugin = FedoraPlugin.new.init(@config, @appliance_config, :log => Logger.new('/dev/null'), :plugin_info => {:class => BoxGrinder::FedoraPlugin, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]})
|
42
|
+
|
43
|
+
@config = @plugin.instance_variable_get(:@config)
|
44
|
+
@appliance_config = @plugin.instance_variable_get(:@appliance_config)
|
45
|
+
@exec_helper = @plugin.instance_variable_get(:@exec_helper)
|
46
|
+
@log = @plugin.instance_variable_get(:@log)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should normalize packages for 32bit" do
|
50
|
+
packages = ['abc', 'def', 'kernel']
|
51
|
+
|
52
|
+
@appliance_config.should_receive(:is64bit?).and_return(false)
|
53
|
+
|
54
|
+
@plugin.normalize_packages(packages)
|
55
|
+
packages.should == ["abc", "def", "@core", "system-config-firewall-base", "dhclient", "kernel-PAE"]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should normalize packages for 64bit" do
|
59
|
+
packages = ['abc', 'def', 'kernel']
|
60
|
+
|
61
|
+
@plugin.normalize_packages(packages)
|
62
|
+
packages.should == ["abc", "def", "@core", "system-config-firewall-base", "dhclient", "kernel"]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should add packages for fedora 13" do
|
66
|
+
packages = []
|
67
|
+
|
68
|
+
@plugin.normalize_packages(packages)
|
69
|
+
packages.should == ["@core", "system-config-firewall-base", "dhclient", "kernel"]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,158 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2010 Red Hat, Inc.
|
3
|
+
#
|
4
|
+
# This is free software; you can redistribute it and/or modify it
|
5
|
+
# under the terms of the GNU Lesser General Public License as
|
6
|
+
# published by the Free Software Foundation; either version 3 of
|
7
|
+
# the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This software is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this software; if not, write to the Free
|
16
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
17
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
18
|
+
|
19
|
+
require 'boxgrinder-build/plugins/os/rhel/rhel-plugin'
|
20
|
+
require 'hashery/opencascade'
|
21
|
+
|
22
|
+
module BoxGrinder
|
23
|
+
describe RHELPlugin do
|
24
|
+
before(:each) do
|
25
|
+
@config = mock('Config')
|
26
|
+
@config.stub!(:os_config).and_return({})
|
27
|
+
plugins = mock('Plugins')
|
28
|
+
plugins.stub!(:[]).with('rhel').and_return({})
|
29
|
+
@config.stub!(:[]).with(:plugins).and_return(plugins)
|
30
|
+
|
31
|
+
@appliance_config = mock('ApplianceConfig')
|
32
|
+
|
33
|
+
@appliance_config.stub!(:path).and_return(OpenCascade.new({:build => 'build/path'}))
|
34
|
+
@appliance_config.stub!(:name).and_return('full')
|
35
|
+
@appliance_config.stub!(:version).and_return(1)
|
36
|
+
@appliance_config.stub!(:release).and_return(0)
|
37
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '6'}))
|
38
|
+
|
39
|
+
@plugin = RHELPlugin.new.init(@config, @appliance_config, :log => Logger.new('/dev/null'), :plugin_info => {:class => BoxGrinder::RHELPlugin, :type => :os, :name => :rhel, :full_name => "Red Hat Enterprise Linux", :versions => ['5', '6']})
|
40
|
+
|
41
|
+
@config = @plugin.instance_variable_get(:@config)
|
42
|
+
@appliance_config = @plugin.instance_variable_get(:@appliance_config)
|
43
|
+
@exec_helper = @plugin.instance_variable_get(:@exec_helper)
|
44
|
+
@linux_helper = @plugin.instance_variable_get(:@linux_helper)
|
45
|
+
@log = @plugin.instance_variable_get(:@log)
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".normalize_packages" do
|
49
|
+
it "should add @core to package list" do
|
50
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
|
51
|
+
|
52
|
+
packages = []
|
53
|
+
|
54
|
+
@plugin.normalize_packages(packages)
|
55
|
+
|
56
|
+
packages.size.should == 7
|
57
|
+
packages[0].should == '@core'
|
58
|
+
packages[1].should == 'curl'
|
59
|
+
packages[2].should == 'kernel'
|
60
|
+
packages[3].should == 'system-config-securitylevel-tui'
|
61
|
+
packages[4].should == 'util-linux'
|
62
|
+
packages[5].should == 'setarch'
|
63
|
+
packages[6].should == 'sudo'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not add kernel package if kernel-xen is already choose" do
|
67
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
|
68
|
+
|
69
|
+
packages = ['kernel-xen']
|
70
|
+
|
71
|
+
@plugin.normalize_packages(packages)
|
72
|
+
|
73
|
+
packages.size.should == 7
|
74
|
+
packages[0].should == 'kernel-xen'
|
75
|
+
packages[1].should == '@core'
|
76
|
+
packages[2].should == 'curl'
|
77
|
+
packages[3].should == 'system-config-securitylevel-tui'
|
78
|
+
packages[4].should == 'util-linux'
|
79
|
+
packages[5].should == 'setarch'
|
80
|
+
packages[6].should == 'sudo'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should not add default packages for RHEL 6" do
|
84
|
+
packages = []
|
85
|
+
|
86
|
+
@plugin.normalize_packages(packages)
|
87
|
+
|
88
|
+
packages.size.should == 4
|
89
|
+
packages[0].should == '@core'
|
90
|
+
packages[1].should == 'curl'
|
91
|
+
packages[2].should == 'kernel'
|
92
|
+
packages[3].should == 'system-config-firewall-base'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ".execute" do
|
97
|
+
it "should recreate the kernel and add some modules to RHEL 5 with normal kernel" do
|
98
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
|
99
|
+
|
100
|
+
@appliance_config.stub!(:packages).and_return([])
|
101
|
+
|
102
|
+
@plugin.should_receive(:adjust_partition_table).ordered
|
103
|
+
@plugin.should_receive(:normalize_packages).ordered
|
104
|
+
|
105
|
+
guestfs = mock('guestfs')
|
106
|
+
guestfs_helper = mock('guestfshelper')
|
107
|
+
|
108
|
+
@plugin.should_receive(:build_with_appliance_creator).ordered.and_yield(guestfs, guestfs_helper)
|
109
|
+
|
110
|
+
@linux_helper.should_receive(:recreate_kernel_image).with(guestfs, ['mptspi', 'virtio_pci', 'virtio_blk'])
|
111
|
+
|
112
|
+
@plugin.execute('file')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should NOT recreate the kernel and add some modules to RHEL 5 if kernel-xen is choosen" do
|
116
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
|
117
|
+
|
118
|
+
@appliance_config.stub!(:packages).and_return(['kernel-xen'])
|
119
|
+
|
120
|
+
@plugin.should_receive(:adjust_partition_table).ordered
|
121
|
+
@plugin.should_receive(:normalize_packages).ordered
|
122
|
+
|
123
|
+
guestfs = mock('guestfs')
|
124
|
+
guestfs_helper = mock('guestfshelper')
|
125
|
+
|
126
|
+
@plugin.should_receive(:build_with_appliance_creator).ordered.and_yield(guestfs, guestfs_helper)
|
127
|
+
|
128
|
+
@linux_helper.should_not_receive(:recreate_kernel_image)
|
129
|
+
|
130
|
+
@plugin.execute('file')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should build the appliance" do
|
134
|
+
@appliance_config.should_receive(:packages).and_return(['kernel'])
|
135
|
+
|
136
|
+
@plugin.should_receive(:adjust_partition_table).ordered
|
137
|
+
@plugin.should_receive(:normalize_packages).ordered
|
138
|
+
@plugin.should_receive(:build_with_appliance_creator).ordered
|
139
|
+
|
140
|
+
@linux_helper.should_not_receive(:recreate_kernel_image)
|
141
|
+
|
142
|
+
@plugin.execute('file')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should adjust partition table for RHEL 5" do
|
147
|
+
@appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'rhel', :version => '5'}))
|
148
|
+
|
149
|
+
@appliance_config.stub!(:hardware).and_return(OpenCascade.new(:partitions => {'/' => {'size' => 2}}))
|
150
|
+
|
151
|
+
@plugin.adjust_partition_table
|
152
|
+
|
153
|
+
@appliance_config.hardware.partitions.size.should == 2
|
154
|
+
@appliance_config.hardware.partitions['/']['size'].should == 2
|
155
|
+
@appliance_config.hardware.partitions['/boot']['size'].should == 0.1
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|