boxgrinder-core 0.1.5 → 0.2.0

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.
@@ -17,7 +17,6 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'boxgrinder-core/validators/errors'
20
- require 'boxgrinder-core/defaults'
21
20
 
22
21
  module BoxGrinder
23
22
  class ApplianceConfigValidator
@@ -5,12 +5,13 @@
5
5
 
6
6
  Summary: Core library for BoxGrinder
7
7
  Name: rubygem-%{gemname}
8
- Version: 0.1.5
8
+ Version: 0.2.0
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
12
12
  URL: http://www.jboss.org/boxgrinder
13
13
  Source0: http://rubygems.org/gems/%{gemname}-%{version}.gem
14
+ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
14
15
 
15
16
  Requires: ruby(abi) = %{rubyabi}
16
17
  Requires: rubygem(open4)
@@ -73,6 +74,22 @@ popd
73
74
  %{gemdir}/doc/%{gemname}-%{version}
74
75
 
75
76
  %changelog
77
+ * Tue Jan 04 2011 <mgoldman@redhat.com> - 0.2.0-1
78
+ - Upstream release: 0.2.0
79
+ - Added BuildRoot tag to build for EPEL 5
80
+ - [BGBUILD-79] Allow to use BoxGrinder Build as a library
81
+ - [BGBUILD-127] Use appliance definition object instead of a file when using BG as a library
82
+ - [BGBUILD-68] Global .boxgrinder/config or rc style file for config
83
+ - [BGBUILD-93] Add Red Hat Enterprise Linux 6 support
84
+ - [BGBUILD-133] Support a consolidated configuration file
85
+ - [BGBUILD-101] Don't use 'includes' subsection when specifying packages
86
+ - [BGBUILD-60] Post section merging pattern for appliances depending on the same appliance
87
+ - [BGBUILD-151] Overriding hardware partitions via inclusion in Appliance Definition File causes build failure
88
+
89
+ * Tue Dec 21 2010 <mgoldman@redhat.com> - 0.1.6-1
90
+ - Updated to upstream version: 0.1.6
91
+ - [BGBUILD-100] Enable boxgrinder_build to create a Fedora image with encrypted partition(s)
92
+
76
93
  * Sun Dec 12 2010 <mgoldman@redhat.com> - 0.1.5-1
77
94
  - Updated to upstream version: 0.1.5
78
95
  - [BGBUILD-73] Add support for kickstart files
@@ -74,6 +74,38 @@ module BoxGrinder
74
74
  config.post['base'].should == ['3_1', '3_2', '2_1', '2_2', '1_1', '1_2']
75
75
  end
76
76
 
77
+ # https://issues.jboss.org/browse/BGBUILD-60
78
+ it "should merge post sections in right order for appliances depending on same base appliance" do
79
+ config_a = ApplianceConfig.new
80
+ config_a.name = 'a'
81
+ config_a.post['base'] = ["1_1", "1_2"]
82
+ config_a.appliances << 'b1'
83
+ config_a.appliances << 'b2'
84
+
85
+ config_b1 = ApplianceConfig.new
86
+ config_b1.name = 'b1'
87
+ config_b1.post['base'] = ["2_1", "2_2"]
88
+ config_b1.appliances << 'c'
89
+
90
+ config_b2 = ApplianceConfig.new
91
+ config_b2.name = 'b2'
92
+ config_b2.post['base'] = ["3_1", "3_2"]
93
+ config_b2.appliances << 'c'
94
+
95
+ config_c = ApplianceConfig.new
96
+ config_c.name = 'c'
97
+ config_c.post['base'] = ["4_1", "4_2"]
98
+
99
+ prepare_helper([config_a, config_b1, config_c, config_b2, config_c])
100
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
101
+
102
+ @helper.merge_post_operations
103
+
104
+ config = @helper.instance_variable_get(:@appliance_config)
105
+ config.post['base'].size.should == 8
106
+ config.post['base'].should == ['4_1', '4_2', '3_1', '3_2', '2_1', '2_2', '1_1', '1_2']
107
+ end
108
+
77
109
  it "should merge post sections in right order with even more and more complicated inheritance" do
78
110
  config_a = ApplianceConfig.new
79
111
  config_a.name = 'a'
@@ -137,148 +169,200 @@ module BoxGrinder
137
169
  config.post['ec2'].should == ['2_1', '2_2']
138
170
  end
139
171
 
140
- it "should merge partitions for default fs_types without options for Fedora 13 (ext4)" do
141
- config_a = ApplianceConfig.new
142
- config_a.name = 'a'
143
- config_a.appliances << 'b'
144
- config_a.hardware.partitions = {"/" => {'size' => '2'}}
145
- config_a.os.name = 'fedora'
146
- config_a.os.version = '13'
172
+ describe ".merge_partitions" do
173
+ it "should merge partitions for default fs_types without options for Fedora 13 (ext4)" do
174
+ config_a = ApplianceConfig.new
175
+ config_a.name = 'a'
176
+ config_a.appliances << 'b'
177
+ config_a.hardware.partitions = {"/" => {'size' => '2'}}
178
+ config_a.os.name = 'fedora'
179
+ config_a.os.version = '13'
147
180
 
148
- config_b = ApplianceConfig.new
149
- config_b.name = 'b'
150
- config_b.hardware.partitions = {"/" => {'size' => '4'}, "/home" => {'size' => '2'}}
151
- config_b.os.name = 'fedora'
152
- config_b.os.version = '13'
181
+ config_b = ApplianceConfig.new
182
+ config_b.name = 'b'
183
+ config_b.hardware.partitions = {"/" => {'size' => '4'}, "/home" => {'size' => '2'}}
184
+ config_b.os.name = 'fedora'
185
+ config_b.os.version = '13'
153
186
 
154
- prepare_helper([config_a, config_b])
155
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
187
+ prepare_helper([config_a, config_b])
188
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
156
189
 
157
- @helper.merge_partitions
190
+ @helper.merge_partitions
158
191
 
159
- config = @helper.instance_variable_get(:@appliance_config)
160
- config.hardware.partitions.size.should == 2
161
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
162
- end
192
+ config = @helper.instance_variable_get(:@appliance_config)
193
+ config.hardware.partitions.size.should == 2
194
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
195
+ end
163
196
 
164
- it "should merge partitions for default fs_types without options for Fedora 13 (ext4) and specified options" do
165
- config_a = ApplianceConfig.new
166
- config_a.name = 'a'
167
- config_a.appliances << 'b'
168
- config_a.hardware.partitions = {"/" => {'size' => '2'}}
169
- config_a.os.name = 'fedora'
170
- config_a.os.version = '13'
197
+ it "should merge partitions for default fs_types without options for Fedora 13 (ext4) and specified options" do
198
+ config_a = ApplianceConfig.new
199
+ config_a.name = 'a'
200
+ config_a.appliances << 'b'
201
+ config_a.hardware.partitions = {"/" => {'size' => '2'}}
202
+ config_a.os.name = 'fedora'
203
+ config_a.os.version = '13'
171
204
 
172
- config_b = ApplianceConfig.new
173
- config_b.name = 'b'
174
- config_b.hardware.partitions = {"/" => {'size' => '4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}, "/home" => {'size' => '2'}}
175
- config_b.os.name = 'fedora'
176
- config_b.os.version = '13'
205
+ config_b = ApplianceConfig.new
206
+ config_b.name = 'b'
207
+ config_b.hardware.partitions = {"/" => {'size' => '4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}, "/home" => {'size' => '2'}}
208
+ config_b.os.name = 'fedora'
209
+ config_b.os.version = '13'
177
210
 
178
- prepare_helper([config_a, config_b])
179
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
211
+ prepare_helper([config_a, config_b])
212
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
180
213
 
181
- @helper.merge_partitions
214
+ @helper.merge_partitions
182
215
 
183
- config = @helper.instance_variable_get(:@appliance_config)
184
- config.hardware.partitions.size.should == 2
185
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4', "options"=>"barrier=0,nodelalloc,nobh,noatime"}, "/home" => {'size' => '2', 'type' => 'ext4'}}
186
- end
216
+ config = @helper.instance_variable_get(:@appliance_config)
217
+ config.hardware.partitions.size.should == 2
218
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4', "options"=>"barrier=0,nodelalloc,nobh,noatime"}, "/home" => {'size' => '2', 'type' => 'ext4'}}
219
+ end
187
220
 
188
- it "should merge partitions for default fs_types without options for Fedora 11 (ext3)" do
189
- config_a = ApplianceConfig.new
190
- config_a.name = 'a'
191
- config_a.appliances << 'b'
192
- config_a.hardware.partitions = {"/" => {'size' => '2'}}
193
- config_a.os.name = 'fedora'
194
- config_a.os.version = '11'
221
+ it "should merge partitions for default fs_types without options for RHEL 5 (ext3)" do
222
+ config_a = ApplianceConfig.new
223
+ config_a.name = 'a'
224
+ config_a.appliances << 'b'
225
+ config_a.hardware.partitions = {"/" => {'size' => '2'}}
226
+ config_a.os.name = 'rhel'
227
+ config_a.os.version = '5'
195
228
 
196
- config_b = ApplianceConfig.new
197
- config_b.name = 'b'
198
- config_b.hardware.partitions = {"/" => {'size' => '4'}, "/home" => {'size' => '2'}}
199
- config_b.os.name = 'fedora'
200
- config_b.os.version = '11'
229
+ config_b = ApplianceConfig.new
230
+ config_b.name = 'b'
231
+ config_b.hardware.partitions = {"/" => {'size' => '4'}, "/home" => {'size' => '2'}}
232
+ config_b.os.name = 'rhel'
233
+ config_b.os.version = '5'
201
234
 
202
- prepare_helper([config_a, config_b])
203
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
235
+ prepare_helper([config_a, config_b])
236
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
204
237
 
205
- @helper.merge_partitions
238
+ @helper.merge_partitions
206
239
 
207
- config = @helper.instance_variable_get(:@appliance_config)
208
- config.hardware.partitions.size.should == 2
209
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext3'}, "/home" => {'size' => '2', 'type' => 'ext3'}}
210
- end
240
+ config = @helper.instance_variable_get(:@appliance_config)
241
+ config.hardware.partitions.size.should == 2
242
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext3'}, "/home" => {'size' => '2', 'type' => 'ext3'}}
243
+ end
211
244
 
212
- it "should merge partitions with different filesystem types" do
213
- config_a = ApplianceConfig.new
214
- config_a.name = 'a'
215
- config_a.appliances << 'b'
216
- config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4'}}
217
- config_a.os.name = 'fedora'
218
- config_a.os.version = '12'
245
+ it "should merge partitions with different filesystem types" do
246
+ config_a = ApplianceConfig.new
247
+ config_a.name = 'a'
248
+ config_a.appliances << 'b'
249
+ config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4'}}
250
+ config_a.os.name = 'fedora'
251
+ config_a.os.version = '13'
219
252
 
220
- config_b = ApplianceConfig.new
221
- config_b.name = 'b'
222
- config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3'}, "/home" => {'size' => '2'}}
223
- config_b.os.name = 'fedora'
224
- config_b.os.version = '11'
253
+ config_b = ApplianceConfig.new
254
+ config_b.name = 'b'
255
+ config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3'}, "/home" => {'size' => '2'}}
256
+ config_b.os.name = 'rhel'
257
+ config_b.os.version = '5'
225
258
 
226
- prepare_helper([config_a, config_b])
227
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
259
+ prepare_helper([config_a, config_b])
260
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
228
261
 
229
- @helper.merge_partitions
262
+ @helper.merge_partitions
230
263
 
231
- config = @helper.instance_variable_get(:@appliance_config)
232
- config.hardware.partitions.size.should == 2
233
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext3'}}
234
- end
264
+ config = @helper.instance_variable_get(:@appliance_config)
265
+ config.hardware.partitions.size.should == 2
266
+ config.os.name.should == 'fedora'
267
+ config.os.version.should == '13'
268
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
269
+ end
235
270
 
236
- it "should merge partitions with different options" do
237
- config_a = ApplianceConfig.new
238
- config_a.name = 'a'
239
- config_a.appliances << 'b'
240
- config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}}
241
- config_a.os.name = 'fedora'
242
- config_a.os.version = '13'
271
+ it "should merge partitions with different options" do
272
+ config_a = ApplianceConfig.new
273
+ config_a.name = 'a'
274
+ config_a.appliances << 'b'
275
+ config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}}
276
+ config_a.os.name = 'fedora'
277
+ config_a.os.version = '13'
243
278
 
244
- config_b = ApplianceConfig.new
245
- config_b.name = 'b'
246
- config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear'}, "/home" => {'size' => '2'}}
247
- config_b.os.name = 'fedora'
248
- config_b.os.version = '13'
279
+ config_b = ApplianceConfig.new
280
+ config_b.name = 'b'
281
+ config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear'}, "/home" => {'size' => '2'}}
282
+ config_b.os.name = 'fedora'
283
+ config_b.os.version = '13'
249
284
 
250
- prepare_helper([config_a, config_b])
251
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
285
+ prepare_helper([config_a, config_b])
286
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
252
287
 
253
- @helper.merge_partitions
288
+ @helper.merge_partitions
254
289
 
255
- config = @helper.instance_variable_get(:@appliance_config)
256
- config.hardware.partitions.size.should == 2
257
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
258
- end
290
+ config = @helper.instance_variable_get(:@appliance_config)
291
+ config.hardware.partitions.size.should == 2
292
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
293
+ end
259
294
 
260
- it "should merge partitions with different options, another case where type is changing - options should be vanished" do
261
- config_a = ApplianceConfig.new
262
- config_a.name = 'a'
263
- config_a.appliances << 'b'
264
- config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4'}}
265
- config_a.os.name = 'fedora'
266
- config_a.os.version = '13'
295
+ it "should merge partitions with different options, another case where type is changing - options should be vanished" do
296
+ config_a = ApplianceConfig.new
297
+ config_a.name = 'a'
298
+ config_a.appliances << 'b'
299
+ config_a.hardware.partitions = {"/" => {'size' => '2', 'type' => 'ext4'}}
300
+ config_a.os.name = 'fedora'
301
+ config_a.os.version = '13'
267
302
 
268
- config_b = ApplianceConfig.new
269
- config_b.name = 'b'
270
- config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear'}, "/home" => {'size' => '2'}}
271
- config_b.os.name = 'fedora'
272
- config_b.os.version = '13'
303
+ config_b = ApplianceConfig.new
304
+ config_b.name = 'b'
305
+ config_b.hardware.partitions = {"/" => {'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear'}, "/home" => {'size' => '2'}}
306
+ config_b.os.name = 'fedora'
307
+ config_b.os.version = '13'
273
308
 
274
- prepare_helper([config_a, config_b])
275
- @helper.instance_variable_set(:@appliance_config, config_a.clone)
309
+ prepare_helper([config_a, config_b])
310
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
276
311
 
277
- @helper.merge_partitions
312
+ @helper.merge_partitions
278
313
 
279
- config = @helper.instance_variable_get(:@appliance_config)
280
- config.hardware.partitions.size.should == 2
281
- config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
314
+ config = @helper.instance_variable_get(:@appliance_config)
315
+ config.hardware.partitions.size.should == 2
316
+ config.hardware.partitions.should == {"/" => {'size' => '4', 'type' => 'ext4'}, "/home" => {'size' => '2', 'type' => 'ext4'}}
317
+ end
318
+
319
+ it "should encrypt the partition while merging the partition" do
320
+ config_a = ApplianceConfig.new
321
+ config_a.name = 'a'
322
+ config_a.appliances << 'b'
323
+ config_a.hardware.partitions = {"/" => {'size' => '2'}}
324
+ config_a.os.name = 'fedora'
325
+ config_a.os.version = '13'
326
+
327
+ config_b = ApplianceConfig.new
328
+ config_b.name = 'b'
329
+ config_b.hardware.partitions = {"/" => {'size' => '4'}}
330
+ config_b.os.name = 'fedora'
331
+ config_b.os.version = '13'
332
+
333
+ prepare_helper([config_a, config_b])
334
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
335
+
336
+ @helper.merge_partitions
337
+
338
+ config = @helper.instance_variable_get(:@appliance_config)
339
+ config.hardware.partitions.size.should == 1
340
+ config.hardware.partitions['/']['passphrase'].should == nil
341
+ end
342
+
343
+ it "should use encrypted partitions while merging the partition" do
344
+ config_a = ApplianceConfig.new
345
+ config_a.name = 'a'
346
+ config_a.appliances << 'b'
347
+ config_a.hardware.partitions = {"/" => {'size' => '2', 'passphrase' => 'marek'}}
348
+ config_a.os.name = 'fedora'
349
+ config_a.os.version = '13'
350
+
351
+ config_b = ApplianceConfig.new
352
+ config_b.name = 'b'
353
+ config_b.hardware.partitions = {"/" => {'size' => '4'}}
354
+ config_b.os.name = 'fedora'
355
+ config_b.os.version = '13'
356
+
357
+ prepare_helper([config_a, config_b])
358
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
359
+
360
+ @helper.merge_partitions
361
+
362
+ config = @helper.instance_variable_get(:@appliance_config)
363
+ config.hardware.partitions.size.should == 1
364
+ config.hardware.partitions['/']['passphrase'].should == 'marek'
365
+ end
282
366
  end
283
367
 
284
368
  it "should substitute variables in repos" do
@@ -25,79 +25,194 @@ module BoxGrinder
25
25
  @helper = ApplianceHelper.new(:log => Logger.new('/dev/null'))
26
26
  end
27
27
 
28
- it "should read definition from one file" do
29
- appliance_config = ApplianceConfig.new
30
- @helper.should_receive(:read_yaml).with('file.appl').and_return(appliance_config)
31
- @helper.read_definitions("file.appl").should == [[appliance_config], appliance_config]
32
- end
28
+ describe ".read_definitions" do
29
+ it "should read definition from files with different extensions" do
30
+ appliance_config = ApplianceConfig.new
31
+
32
+ ['appl', 'yml', 'yaml'].each do |ext|
33
+ File.should_receive(:exists?).with("file.#{ext}").and_return(true)
34
+ @helper.should_receive(:read_yaml_file).with("file.#{ext}").and_return(appliance_config)
35
+ @helper.read_definitions("file.#{ext}").should == [[appliance_config], appliance_config]
36
+ end
37
+ end
38
+
39
+ it "should read YAML definition from files with different content types" do
40
+ appliance_config = ApplianceConfig.new
41
+
42
+ ['application/x-yaml', 'text/yaml'].each do |type|
43
+ File.should_receive(:exists?).with("file").and_return(true)
44
+ @helper.should_receive(:read_yaml_file).with("file").and_return(appliance_config)
45
+ @helper.read_definitions("file", type).should == [[appliance_config], appliance_config]
46
+ end
47
+ end
33
48
 
34
- it "should read definition from two files" do
35
- appliance_a = ApplianceConfig.new
36
- appliance_a.name = 'a'
37
- appliance_a.appliances << "b"
49
+ it "should read XML definition from files with different content types" do
50
+ appliance_config = ApplianceConfig.new
38
51
 
39
- appliance_b = ApplianceConfig.new
40
- appliance_b.name = 'b'
52
+ ['application/xml', 'text/xml', 'application/x-xml'].each do |type|
53
+ File.should_receive(:exists?).with("file").and_return(true)
54
+ @helper.should_receive(:read_xml_file).with("file").and_return(appliance_config)
55
+ @helper.read_definitions("file", type).should == [[appliance_config], appliance_config]
56
+ end
57
+ end
41
58
 
42
- @helper.should_receive(:read_yaml).ordered.with('a.appl').and_return(appliance_a)
43
- @helper.should_receive(:read_yaml).ordered.with('./b.appl').and_return(appliance_b)
59
+ it "should read definition from two files" do
60
+ appliance_a = ApplianceConfig.new
61
+ appliance_a.name = 'a'
62
+ appliance_a.appliances << "b"
44
63
 
45
- @helper.read_definitions("a.appl").should == [[appliance_a, appliance_b], appliance_a]
46
- end
64
+ appliance_b = ApplianceConfig.new
65
+ appliance_b.name = 'b'
66
+
67
+ File.should_receive(:exists?).ordered.with('a.appl').and_return(true)
68
+ File.should_receive(:exists?).ordered.with('./b.appl').and_return(true)
69
+
70
+ @helper.should_receive(:read_yaml_file).ordered.with('a.appl').and_return(appliance_a)
71
+ @helper.should_receive(:read_yaml_file).ordered.with('./b.appl').and_return(appliance_b)
72
+
73
+ @helper.read_definitions("a.appl").should == [[appliance_a, appliance_b], appliance_a]
74
+ end
75
+
76
+ it "should read definitions from a tree file structure" do
77
+ appliance_a = ApplianceConfig.new
78
+ appliance_a.name = 'a'
79
+ appliance_a.appliances << "b1"
80
+ appliance_a.appliances << "b2"
81
+
82
+ appliance_b1 = ApplianceConfig.new
83
+ appliance_b1.name = 'b1'
84
+ appliance_b1.appliances << "c1"
85
+
86
+ appliance_b2 = ApplianceConfig.new
87
+ appliance_b2.name = 'b2'
88
+ appliance_b2.appliances << "c2"
89
+
90
+ appliance_c1 = ApplianceConfig.new
91
+ appliance_c1.name = 'c1'
92
+
93
+ appliance_c2 = ApplianceConfig.new
94
+ appliance_c2.name = 'c2'
47
95
 
48
- it "should read definitions from a tree file structure" do
49
- appliance_a = ApplianceConfig.new
50
- appliance_a.name = 'a'
51
- appliance_a.appliances << "b1"
52
- appliance_a.appliances << "b2"
96
+ File.should_receive(:exists?).ordered.with('a.appl').and_return(true)
97
+ File.should_receive(:exists?).ordered.with('./b2.appl').and_return(true)
98
+ File.should_receive(:exists?).ordered.with('./c2.appl').and_return(true)
99
+ File.should_receive(:exists?).ordered.with('./b1.appl').and_return(true)
100
+ File.should_receive(:exists?).ordered.with('./c1.appl').and_return(true)
53
101
 
54
- appliance_b1 = ApplianceConfig.new
55
- appliance_b1.name = 'b1'
56
- appliance_b1.appliances << "c1"
102
+ @helper.should_receive(:read_yaml_file).ordered.with('a.appl').and_return(appliance_a)
103
+ @helper.should_receive(:read_yaml_file).ordered.with('./b2.appl').and_return(appliance_b2)
104
+ @helper.should_receive(:read_yaml_file).ordered.with('./c2.appl').and_return(appliance_c2)
105
+ @helper.should_receive(:read_yaml_file).ordered.with('./b1.appl').and_return(appliance_b1)
106
+ @helper.should_receive(:read_yaml_file).ordered.with('./c1.appl').and_return(appliance_c1)
57
107
 
58
- appliance_b2 = ApplianceConfig.new
59
- appliance_b2.name = 'b2'
60
- appliance_b2.appliances << "c2"
108
+ @helper.read_definitions("a.appl").should == [[appliance_a, appliance_b2, appliance_c2, appliance_b1, appliance_c1], appliance_a]
109
+ end
110
+
111
+ # https://issues.jboss.org/browse/BGBUILD-60
112
+ it "should read definitions from a tree file structure based on same appliance" do
113
+ appliance_a = ApplianceConfig.new
114
+ appliance_a.name = 'a'
115
+ appliance_a.appliances << "b1"
116
+ appliance_a.appliances << "b2"
117
+
118
+ appliance_b1 = ApplianceConfig.new
119
+ appliance_b1.name = 'b1'
120
+ appliance_b1.appliances << "c"
121
+
122
+ appliance_b2 = ApplianceConfig.new
123
+ appliance_b2.name = 'b2'
124
+ appliance_b2.appliances << "c"
125
+
126
+ appliance_c = ApplianceConfig.new
127
+ appliance_c.name = 'c'
128
+
129
+ File.should_receive(:exists?).ordered.with('a.appl').and_return(true)
130
+ File.should_receive(:exists?).ordered.with('./b2.appl').and_return(true)
131
+ File.should_receive(:exists?).ordered.with('./c.appl').and_return(true)
132
+ File.should_receive(:exists?).ordered.with('./b1.appl').and_return(true)
133
+ File.should_receive(:exists?).ordered.with('./c.appl').and_return(true)
134
+
135
+ @helper.should_receive(:read_yaml_file).ordered.with('a.appl').and_return(appliance_a)
136
+ @helper.should_receive(:read_yaml_file).ordered.with('./b2.appl').and_return(appliance_b2)
137
+ @helper.should_receive(:read_yaml_file).ordered.with('./c.appl').and_return(appliance_c)
138
+ @helper.should_receive(:read_yaml_file).ordered.with('./b1.appl').and_return(appliance_b1)
139
+ @helper.should_receive(:read_yaml_file).ordered.with('./c.appl').and_return(appliance_c)
140
+
141
+ @helper.read_definitions("a.appl").should == [[appliance_a, appliance_b2, appliance_c, appliance_b1, appliance_c], appliance_a]
142
+ end
143
+
144
+ it "should read a YAML content instead of a loading a file" do
145
+ yaml = "name: abc\nos:\n name: fedora\n version: 13\npackages:\n - @core\nhardware:\n partitions:\n \"/\":\n size: 6"
146
+ appliance = @helper.read_definitions(yaml).last
147
+
148
+ appliance.name.should == 'abc'
149
+ appliance.os.version.should == '13'
150
+ appliance.hardware.partitions['/']['size'].should == 6
151
+ end
61
152
 
62
- appliance_c1 = ApplianceConfig.new
63
- appliance_c1.name = 'c1'
153
+ it "should read invalid YAML content" do
154
+ lambda { @helper.read_definitions("@$FEWYERTH") }.should raise_error(RuntimeError, 'Provided definition is not a Hash.')
155
+ end
64
156
 
65
- appliance_c2 = ApplianceConfig.new
66
- appliance_c2.name = 'c2'
157
+ it "should catch exception if YAML parsing raises it" do
158
+ lambda { @helper.read_definitions("!!") }.should raise_error(RuntimeError, 'Provided definition could not be read.')
159
+ end
67
160
 
68
- @helper.should_receive(:read_yaml).ordered.with('a.appl').and_return(appliance_a)
69
- @helper.should_receive(:read_yaml).ordered.with('./b2.appl').and_return(appliance_b2)
70
- @helper.should_receive(:read_yaml).ordered.with('./c2.appl').and_return(appliance_c2)
71
- @helper.should_receive(:read_yaml).ordered.with('./b1.appl').and_return(appliance_b1)
72
- @helper.should_receive(:read_yaml).ordered.with('./c1.appl').and_return(appliance_c1)
161
+ it "should catch exception if YAML file parsing raises it" do
162
+ lambda { @helper.read_definitions("#{File.dirname(__FILE__)}/../rspec/src/appliances/invalid_yaml.appl") }.should raise_error(RuntimeError, /File '(.*)' could not be read./)
163
+ end
73
164
 
74
- @helper.read_definitions("a.appl").should == [[appliance_a, appliance_b2, appliance_c2, appliance_b1, appliance_c1], appliance_a]
165
+ it "should raise because xml files aren't supported yet" do
166
+ File.should_receive(:exists?).with("file.xml").and_return(true)
167
+ lambda { @helper.read_definitions("file.xml") }.should raise_error(RuntimeError, "Reading XML files is not supported right now. File 'file.xml' could not be read.")
168
+ end
169
+
170
+ it "should raise because of unsupported file format" do
171
+ File.should_receive(:exists?).with("file.xmdfl").and_return(true)
172
+ lambda { @helper.read_definitions("file.xmdfl") }.should raise_error(RuntimeError, "Unsupported file format for appliance definition file.")
173
+ end
75
174
  end
76
175
 
77
- describe "read_yaml" do
176
+ describe "read_yaml_file" do
78
177
  it "should read default_repos and set to false" do
79
178
  YAML.should_receive(:load_file).with('default_repos_false.appl').and_return({'default_repos'=>false})
80
- @helper.read_yaml('default_repos_false.appl').default_repos.should == false
179
+ @helper.read_yaml_file('default_repos_false.appl').default_repos.should == false
81
180
  end
82
181
 
83
182
  it "should read default_repos and set to true" do
84
183
  YAML.should_receive(:load_file).with('default_repos_true.appl').and_return({'default_repos'=>true})
85
- @helper.read_yaml('default_repos_true.appl').default_repos.should == true
184
+ @helper.read_yaml_file('default_repos_true.appl').default_repos.should == true
86
185
  end
87
186
 
88
187
  it "should read default_repos but not set it" do
89
188
  YAML.should_receive(:load_file).with('default_repos_empty.appl').and_return({})
90
- @helper.read_yaml('default_repos_empty.appl').default_repos.should == nil
189
+ @helper.read_yaml_file('default_repos_empty.appl').default_repos.should == nil
91
190
  end
92
191
 
93
192
  it "should read default_repos and raise" do
94
193
  YAML.should_receive(:load_file).with('default_repos_bad.appl').and_return({'default_repos'=>'something'})
95
194
 
96
- begin
97
- @helper.read_yaml("default_repos_bad.appl")
98
- raise 'Should raise'
99
- rescue => e
100
- e.message.should == 'default_repos_bad.appl: default_repos should be set to true or false'
195
+ lambda {
196
+ @helper.read_yaml_file("default_repos_bad.appl")
197
+ }.should raise_error(RuntimeError, 'default_repos should be set to true or false')
198
+ end
199
+ end
200
+
201
+ describe ".parse_yaml" do
202
+ context "partitions" do
203
+ it "should add default partition when no partitions are specified" do
204
+ appliance_config = @helper.parse_yaml({})
205
+
206
+ appliance_config.hardware.partitions.size.should == 1
207
+ appliance_config.hardware.partitions['/'].should == {'size' => 1}
208
+ end
209
+
210
+ it "should merge partitions with the default one specified in appliance config" do
211
+ appliance_config = @helper.parse_yaml({'hardware' => {'partitions' => {'/home' => {'size' => 1}}}})
212
+
213
+ appliance_config.hardware.partitions.size.should == 2
214
+ appliance_config.hardware.partitions['/'].should == {'size' => 1}
215
+ appliance_config.hardware.partitions['/home'].should == {'size' => 1}
101
216
  end
102
217
  end
103
218
  end