boxgrinder-build 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -203,6 +203,23 @@ module BoxGrinder
203
203
  File.should_receive(:open).with('a/disk', 'rb').and_yield(f)
204
204
  @plugin.upload_chunks
205
205
  end
206
+
207
+ it "should not compress the data before uploading the chunks if we use CloudSigma" do
208
+ merge_config('endpoint' => 'api.cloudsigma.com')
209
+ @plugin.instance_variable_set(:@previous_deliverables, {:disk => 'a/disk'})
210
+
211
+ f = mock(File)
212
+ f.should_receive(:eof?).ordered.and_return(false)
213
+ f.should_receive(:seek).ordered.with(0, File::SEEK_SET)
214
+ f.should_receive(:read).ordered.with(67108864).and_return("data")
215
+ f.should_receive(:eof?).ordered.and_return(true)
216
+
217
+ @plugin.should_not_receive(:compress)
218
+ @plugin.should_receive(:upload_chunk).ordered.with("data", 0)
219
+
220
+ File.should_receive(:open).with('a/disk', 'rb').and_yield(f)
221
+ @plugin.upload_chunks
222
+ end
206
223
  end
207
224
 
208
225
  describe ".upload_chunk" do
@@ -247,6 +264,15 @@ module BoxGrinder
247
264
  @plugin.upload_chunk("data", 0)
248
265
  }.should raise_error(PluginError, "Couldn't upload appliance, boom.")
249
266
  end
267
+
268
+ it "should not specify add content-encoding header if uplaoding to cloudsigma" do
269
+ merge_config('endpoint' => 'api.cloudsigma.com')
270
+
271
+ @plugin.should_receive(:api_url).with('/drives/drive-uuid/write/0').and_return('url')
272
+ RestClient.should_receive(:post).with('url', 'data', :content_type=>"application/octet-stream")
273
+
274
+ @plugin.upload_chunk("data", 0)
275
+ end
250
276
  end
251
277
 
252
278
  describe ".create_server" do
@@ -29,10 +29,12 @@ module BoxGrinder
29
29
  plugins.stub!(:[]).with('rpm_based').and_return({})
30
30
  @config.stub!(:[]).with(:plugins).and_return(plugins)
31
31
  @config.stub!(:dir).and_return(OpenCascade.new(:tmp => 'tmpdir', :cache => 'cachedir'))
32
+ @config.stub!(:os).and_return(OpenCascade.new(:name => 'fedora', :version => '14'))
32
33
 
33
34
  @appliance_config.stub!(:name).and_return('full')
34
35
  @appliance_config.stub!(:version).and_return(1)
35
36
  @appliance_config.stub!(:release).and_return(0)
37
+ @appliance_config.stub!(:post).and_return({})
36
38
  @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '11'}))
37
39
  @appliance_config.stub!(:hardware).and_return(OpenCascade.new(:cpus => 1, :memory => 512, :partitions => {'/' => nil, '/home' => nil}))
38
40
  @appliance_config.stub!(:path).and_return(OpenCascade.new(:build => 'build/path', :main => 'mainpath'))
@@ -106,6 +108,50 @@ module BoxGrinder
106
108
  @plugin.read_kickstart("#{File.dirname(__FILE__)}/src/jeos-f13-without-version.ks")
107
109
  }.should raise_error("No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14")
108
110
  end
111
+
112
+ it "should read kickstart and populate partitions" do
113
+ appliance_config = @plugin.read_kickstart("#{File.dirname(__FILE__)}/src/jeos-f13.ks")
114
+ appliance_config.should be_an_instance_of(ApplianceConfig)
115
+ appliance_config.hardware.partitions.should == {'/' => {'size' => 2.0, 'type' => 'ext4'}, '/home' => {'size' => 3.0, 'type' => 'ext3', "options" => "abc,def,gef"}}
116
+ end
117
+
118
+ it "should read kickstart and populate partitions" do
119
+ appliance_config = @plugin.read_kickstart("#{File.dirname(__FILE__)}/src/jeos-f13.ks")
120
+ appliance_config.should be_an_instance_of(ApplianceConfig)
121
+ appliance_config.hardware.partitions.should == {'/' => {'size' => 2.0, 'type' => 'ext4'}, '/home' => {'size' => 3.0, 'type' => 'ext3', "options" => "abc,def,gef"}}
122
+ end
123
+
124
+ it "should read kickstart and raise because of no partition size specified" do
125
+ File.should_receive(:read).with("jeos-f13.ks").and_return("# bg_os_name: fedora\n# bg_os_version: 14\npart /")
126
+
127
+ lambda {
128
+ @plugin.read_kickstart("jeos-f13.ks")
129
+ }.should raise_error("Partition size not specified for / partition in jeos-f13.ks")
130
+ end
131
+
132
+ it "should read kickstart and raise because no os name is specified" do
133
+ File.should_receive(:read).with("jeos-f13.ks").and_return("")
134
+
135
+ lambda {
136
+ @plugin.read_kickstart("jeos-f13.ks")
137
+ }.should raise_error("No operating system name specified, please add comment to you kickstrt file like this: # bg_os_name: fedora")
138
+ end
139
+
140
+ it "should read kickstart and raise because no os version is specified" do
141
+ File.should_receive(:read).with("jeos-f13.ks").and_return("# bg_os_name: rhel")
142
+
143
+ lambda {
144
+ @plugin.read_kickstart("jeos-f13.ks")
145
+ }.should raise_error("No operating system version specified, please add comment to you kickstrt file like this: # bg_os_version: 14")
146
+ end
147
+
148
+ it "should read kickstart and raise because no partitions are specified" do
149
+ File.should_receive(:read).with("jeos-f13.ks").and_return("# bg_os_name: fedora\n# bg_os_version: 14")
150
+
151
+ lambda {
152
+ @plugin.read_kickstart("jeos-f13.ks")
153
+ }.should raise_error("No partitions specified in your kickstart file jeos-f13.ks")
154
+ end
109
155
  end
110
156
 
111
157
  describe ".use_labels_for_partitions" do
@@ -150,7 +196,7 @@ module BoxGrinder
150
196
  end
151
197
 
152
198
  describe ".build_with_appliance_creator" do
153
- it "should build appliance" do
199
+ def do_build
154
200
  kickstart = mock(Kickstart)
155
201
  kickstart.should_receive(:create).and_return('kickstart.ks')
156
202
 
@@ -165,7 +211,42 @@ module BoxGrinder
165
211
  FileUtils.should_receive(:mv)
166
212
  FileUtils.should_receive(:rm_rf)
167
213
 
168
- @image_helper.should_receive(:customize).with(["build/path/rpm_based-plugin/tmp/full-sda.raw"])
214
+ guestfs = mock("GuestFS")
215
+ guestfs_helper = mock("GuestFSHelper")
216
+
217
+ @image_helper.should_receive(:customize).with(["build/path/rpm_based-plugin/tmp/full-sda.raw"]).and_yield(guestfs, guestfs_helper)
218
+
219
+ guestfs.should_receive(:upload).with("/etc/resolv.conf", "/etc/resolv.conf")
220
+
221
+ @plugin.should_receive(:change_configuration).with(guestfs_helper)
222
+ @plugin.should_receive(:apply_root_password).with(guestfs)
223
+ @plugin.should_receive(:use_labels_for_partitions).with(guestfs)
224
+ @plugin.should_receive(:disable_firewall).with(guestfs)
225
+ @plugin.should_receive(:set_motd).with(guestfs)
226
+ @plugin.should_receive(:install_repos).with(guestfs)
227
+
228
+ guestfs.should_receive(:exists).with('/etc/init.d/firstboot').and_return(1)
229
+ guestfs.should_receive(:sh).with('chkconfig firstboot off')
230
+
231
+ yield guestfs, guestfs_helper if block_given?
232
+ end
233
+
234
+ it "should build appliance" do
235
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '14'}))
236
+ do_build
237
+ @plugin.build_with_appliance_creator('jeos.appl')
238
+ end
239
+
240
+ it "should execute additional steps for Fedora 15" do
241
+ @appliance_config.stub!(:os).and_return(OpenCascade.new({:name => 'fedora', :version => '15'}))
242
+
243
+ do_build do |guestfs, guestfs_helper|
244
+ @plugin.should_receive(:disable_biosdevname).with(guestfs)
245
+ @plugin.should_receive(:change_runlevel).with(guestfs)
246
+ @plugin.should_receive(:disable_netfs).with(guestfs)
247
+ @plugin.should_receive(:link_mtab).with(guestfs)
248
+ @plugin.should_receive(:recreate_rpm_database).with(guestfs, guestfs_helper)
249
+ end
169
250
 
170
251
  @plugin.build_with_appliance_creator('jeos.appl')
171
252
  end
@@ -217,6 +298,47 @@ module BoxGrinder
217
298
  @plugin.cleanup_after_appliance_creator(12345)
218
299
  end
219
300
  end
301
+
302
+ describe ".recreate_rpm_database" do
303
+ it "should recreate RPM database" do
304
+ guestfs = mock("GuestFS")
305
+ guestfs_helper = mock("GuestFSHelper")
306
+
307
+ guestfs.should_receive(:download).with("/var/lib/rpm/Packages", "build/path/rpm_based-plugin/tmp/Packages")
308
+ @exec_helper.should_receive(:execute).with("/usr/lib/rpm/rpmdb_dump build/path/rpm_based-plugin/tmp/Packages > build/path/rpm_based-plugin/tmp/Packages.dump")
309
+ guestfs.should_receive(:upload).with("build/path/rpm_based-plugin/tmp/Packages.dump", "/tmp/Packages.dump")
310
+ guestfs.should_receive(:sh).with("rm -rf /var/lib/rpm/*")
311
+ guestfs_helper.should_receive(:sh).with("cd /var/lib/rpm/ && cat /tmp/Packages.dump | /usr/lib/rpm/rpmdb_load Packages")
312
+ guestfs_helper.should_receive(:sh).with("rpm --rebuilddb")
313
+
314
+ @plugin.recreate_rpm_database(guestfs, guestfs_helper)
315
+ end
316
+ end
317
+
318
+ context "BGBUILD-204" do
319
+ it "should disable bios device name hints" do
320
+ guestfs = mock("GuestFS")
321
+ guestfs.should_receive(:sh).with("sed -i \"s/kernel\\(.*\\)/kernel\\1 biosdevname=0/g\" /boot/grub/grub.conf")
322
+ @plugin.disable_biosdevname(guestfs)
323
+ end
324
+
325
+ it "should change to runlevel 3 by default" do
326
+ guestfs = mock("GuestFS")
327
+ guestfs.should_receive(:rm).with("/etc/systemd/system/default.target")
328
+ guestfs.should_receive(:ln_sf).with("/lib/systemd/system/multi-user.target", "/etc/systemd/system/default.target")
329
+ @plugin.change_runlevel(guestfs)
330
+ end
331
+
332
+ it "should disable netfs" do
333
+ guestfs = mock("GuestFS")
334
+ guestfs.should_receive(:sh).with("chkconfig netfs off")
335
+ @plugin.disable_netfs(guestfs)
336
+ end
337
+ end
338
+ it "should link /etc/mtab to /proc/self/mounts" do
339
+ guestfs = mock("GuestFS")
340
+ guestfs.should_receive(:ln_sf).with("/proc/self/mounts", "/etc/mtab")
341
+ @plugin.link_mtab(guestfs)
342
+ end
220
343
  end
221
344
  end
222
-
@@ -14,6 +14,7 @@ services --enabled=network
14
14
  rootpw boxgrinder
15
15
 
16
16
  part / --size 2048 --fstype ext4 --ondisk sda
17
+ part /home --size 3072 --fstype ext3 --fsoptions=abc,def,gef --ondisk sda
17
18
 
18
19
  repo --name=fedora-14-base --cost=40 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-13&arch=x86_64
19
20
  repo --name=fedora-14-updates --cost=41 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f13&arch=x86_64
@@ -244,7 +244,6 @@ module BoxGrinder
244
244
  @plugin.should_receive(:create_devices).with(guestfs)
245
245
  @plugin.should_receive(:upload_fstab).with(guestfs)
246
246
 
247
- @plugin.should_receive(:recreate_journal).with(guestfs)
248
247
  @plugin.should_receive(:enable_networking)
249
248
  @plugin.should_receive(:upload_rc_local).with(guestfs)
250
249
  @plugin.should_receive(:add_ec2_user).with(guestfs)
@@ -292,15 +291,6 @@ module BoxGrinder
292
291
  @plugin.execute_post(guestfs_helper)
293
292
  end
294
293
  end
295
-
296
- it "should recreate journal" do
297
- guestfs = mock("guestfs")
298
-
299
- guestfs.should_receive(:list_devices).and_return(['/dev/sda'])
300
- guestfs.should_receive(:sh).with("tune2fs -j /dev/sda")
301
-
302
- @plugin.recreate_journal(guestfs)
303
- end
304
294
  end
305
295
  end
306
296
 
@@ -65,9 +65,11 @@ module BoxGrinder
65
65
  end
66
66
 
67
67
  it "should calculate good CHS value for 0.5GB disk" do
68
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
68
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
69
+
70
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 536870912))
69
71
 
70
- c, h, s, total_sectors = @plugin.generate_scsi_chs(0.5)
72
+ c, h, s, total_sectors = @plugin.generate_scsi_chs
71
73
 
72
74
  c.should == 512
73
75
  h.should == 64
@@ -76,9 +78,11 @@ module BoxGrinder
76
78
  end
77
79
 
78
80
  it "should calculate good CHS value for 1GB disk" do
79
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
81
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
82
+
83
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 1073741824))
80
84
 
81
- c, h, s, total_sectors = @plugin.generate_scsi_chs(1)
85
+ c, h, s, total_sectors = @plugin.generate_scsi_chs
82
86
 
83
87
  c.should == 512
84
88
  h.should == 128
@@ -87,9 +91,11 @@ module BoxGrinder
87
91
  end
88
92
 
89
93
  it "should calculate good CHS value for 40GB disk" do
90
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
94
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
95
+
96
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 42949672960))
91
97
 
92
- c, h, s, total_sectors = @plugin.generate_scsi_chs(40)
98
+ c, h, s, total_sectors = @plugin.generate_scsi_chs
93
99
 
94
100
  c.should == 5221
95
101
  h.should == 255
@@ -98,9 +104,11 @@ module BoxGrinder
98
104
  end
99
105
 
100
106
  it "should calculate good CHS value for 160GB disk" do
101
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
107
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
102
108
 
103
- c, h, s, total_sectors = @plugin.generate_scsi_chs(160)
109
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 171798691840))
110
+
111
+ c, h, s, total_sectors = @plugin.generate_scsi_chs
104
112
 
105
113
  c.should == 20886
106
114
  h.should == 255
@@ -110,7 +118,9 @@ module BoxGrinder
110
118
 
111
119
  describe ".change_vmdk_values" do
112
120
  it "should change vmdk data (vmfs)" do
113
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
121
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
122
+
123
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 5368709120))
114
124
 
115
125
  vmdk_image = @plugin.change_vmdk_values("vmfs")
116
126
 
@@ -131,7 +141,9 @@ module BoxGrinder
131
141
  end
132
142
 
133
143
  it "should change vmdk data (flat)" do
134
- prepare_image({'thin_disk' => false, 'type' => 'enterprise'})
144
+ prepare_image({'thin_disk' => false, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
145
+
146
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 5368709120))
135
147
 
136
148
  vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
137
149
 
@@ -153,13 +165,14 @@ module BoxGrinder
153
165
  end
154
166
 
155
167
  it "should change vmdk data (flat) enabling thin disk" do
156
- prepare_image({'thin_disk' => true, 'type' => 'enterprise'})
168
+ prepare_image({'thin_disk' => true, 'type' => 'enterprise'}, :previous_deliverables => OpenStruct.new({:disk => 'a/base/image/path.raw'}))
169
+
170
+ File.should_receive(:stat).with("a/base/image/path.raw").and_return(OpenStruct.new(:size => 5368709120))
157
171
 
158
172
  vmdk_image = @plugin.change_vmdk_values("monolithicFlat")
159
173
 
160
174
  vmdk_image.scan(/^ddb.thinProvisioned = "(.*)"\s?$/).to_s.should == "1"
161
175
  end
162
-
163
176
  end
164
177
 
165
178
  it "should change vmx data" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxgrinder-build
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek Goldmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-27 00:00:00 +02:00
18
+ date: 2011-05-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,7 @@ extra_rdoc_files:
137
137
  - lib/boxgrinder-build/helpers/linux-helper.rb
138
138
  - lib/boxgrinder-build/helpers/package-helper.rb
139
139
  - lib/boxgrinder-build/helpers/plugin-helper.rb
140
+ - lib/boxgrinder-build/helpers/qemu.wrapper
140
141
  - lib/boxgrinder-build/managers/plugin-manager.rb
141
142
  - lib/boxgrinder-build/plugins/base-plugin.rb
142
143
  - lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb
@@ -183,6 +184,7 @@ files:
183
184
  - lib/boxgrinder-build/helpers/linux-helper.rb
184
185
  - lib/boxgrinder-build/helpers/package-helper.rb
185
186
  - lib/boxgrinder-build/helpers/plugin-helper.rb
187
+ - lib/boxgrinder-build/helpers/qemu.wrapper
186
188
  - lib/boxgrinder-build/managers/plugin-manager.rb
187
189
  - lib/boxgrinder-build/plugins/base-plugin.rb
188
190
  - lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb