boxgrinder-core 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.3.10
2
+
3
+ * [BGBUILD-324] Add wildcard to packages schema
4
+ * [BGBUILD-320] Support variable substitution in any string value field of appliance definition
5
+ * [BGBUILD-327] Resolve appliance definition variables in ENV if they are not defined
6
+
1
7
  v0.3.9
2
8
 
3
9
  * [BGBUILD-312] Discover which user to switch to after root dependent sections have been executed
data/Manifest CHANGED
@@ -1,44 +0,0 @@
1
- CHANGELOG
2
- LICENSE
3
- Manifest
4
- README
5
- Rakefile
6
- boxgrinder-core.gemspec
7
- lib/boxgrinder-core.rb
8
- lib/boxgrinder-core/appliance-parser.rb
9
- lib/boxgrinder-core/appliance-validator.rb
10
- lib/boxgrinder-core/errors.rb
11
- lib/boxgrinder-core/helpers/appliance-config-helper.rb
12
- lib/boxgrinder-core/helpers/appliance-definition-helper.rb
13
- lib/boxgrinder-core/helpers/appliance-transformation-helper.rb
14
- lib/boxgrinder-core/helpers/exec-helper.rb
15
- lib/boxgrinder-core/helpers/log-helper.rb
16
- lib/boxgrinder-core/models/appliance-config.rb
17
- lib/boxgrinder-core/models/config.rb
18
- lib/boxgrinder-core/models/task.rb
19
- lib/boxgrinder-core/schemas/appliance_schema_0.8.0.yaml
20
- lib/boxgrinder-core/schemas/appliance_schema_0.9.0.yaml
21
- lib/boxgrinder-core/schemas/appliance_schema_0.9.6.yaml
22
- rubygem-boxgrinder-core.spec
23
- spec/appliance-parser-spec.rb
24
- spec/appliance-validator-spec.rb
25
- spec/helpers/appliance-config-helper-spec.rb
26
- spec/helpers/appliance-definition-helper-spec.rb
27
- spec/helpers/appliance-transformation-helper-spec.rb
28
- spec/helpers/exec-helper-spec.rb
29
- spec/helpers/log-helper-spec.rb
30
- spec/models/appliance-config-spec.rb
31
- spec/models/config-spec.rb
32
- spec/rspec/ls/one
33
- spec/rspec/ls/two
34
- spec/rspec/src/appliances/0.8.x.appl
35
- spec/rspec/src/appliances/0.9.x-invalid.appl
36
- spec/rspec/src/appliances/0.9.x.appl
37
- spec/rspec/src/appliances/comments.appl
38
- spec/rspec/src/appliances/ephemeral-repo.appl
39
- spec/rspec/src/appliances/full.appl
40
- spec/rspec/src/appliances/invalid-yaml.appl
41
- spec/rspec/src/appliances/legacy.appl
42
- spec/rspec/src/appliances/repo.appl
43
- spec/rspec/src/config/empty
44
- spec/rspec/src/config/valid
@@ -1,25 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{boxgrinder-core}
5
- s.version = "0.3.9"
4
+ s.name = "boxgrinder-core"
5
+ s.version = "0.3.10"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marek Goldmann"]
9
- s.date = %q{2011-11-15}
10
- s.description = %q{Core library for BoxGrinder}
11
- s.email = %q{info@boxgrinder.org}
9
+ s.date = "2011-12-19"
10
+ s.description = "Core library for BoxGrinder"
11
+ s.email = "info@boxgrinder.org"
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/appliance-parser.rb", "lib/boxgrinder-core/appliance-validator.rb", "lib/boxgrinder-core/errors.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-definition-helper.rb", "lib/boxgrinder-core/helpers/appliance-transformation-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/schemas/appliance_schema_0.8.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.6.yaml"]
13
13
  s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "boxgrinder-core.gemspec", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/appliance-parser.rb", "lib/boxgrinder-core/appliance-validator.rb", "lib/boxgrinder-core/errors.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-definition-helper.rb", "lib/boxgrinder-core/helpers/appliance-transformation-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/schemas/appliance_schema_0.8.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.6.yaml", "rubygem-boxgrinder-core.spec", "spec/appliance-parser-spec.rb", "spec/appliance-validator-spec.rb", "spec/helpers/appliance-config-helper-spec.rb", "spec/helpers/appliance-definition-helper-spec.rb", "spec/helpers/appliance-transformation-helper-spec.rb", "spec/helpers/exec-helper-spec.rb", "spec/helpers/log-helper-spec.rb", "spec/models/appliance-config-spec.rb", "spec/models/config-spec.rb", "spec/rspec/ls/one", "spec/rspec/ls/two", "spec/rspec/src/appliances/0.8.x.appl", "spec/rspec/src/appliances/0.9.x-invalid.appl", "spec/rspec/src/appliances/0.9.x.appl", "spec/rspec/src/appliances/comments.appl", "spec/rspec/src/appliances/ephemeral-repo.appl", "spec/rspec/src/appliances/full.appl", "spec/rspec/src/appliances/invalid-yaml.appl", "spec/rspec/src/appliances/legacy.appl", "spec/rspec/src/appliances/repo.appl", "spec/rspec/src/config/empty", "spec/rspec/src/config/valid"]
14
- s.homepage = %q{http://boxgrinder.org}
14
+ s.homepage = "http://boxgrinder.org"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Boxgrinder-core", "--main", "README"]
16
16
  s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{BoxGrinder}
18
- s.rubygems_version = %q{1.3.7}
19
- s.summary = %q{Core library for BoxGrinder}
17
+ s.rubyforge_project = "BoxGrinder"
18
+ s.rubygems_version = "1.8.11"
19
+ s.summary = "Core library for BoxGrinder"
20
20
 
21
21
  if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
22
  s.specification_version = 3
24
23
 
25
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -22,6 +22,8 @@ require 'set'
22
22
  module BoxGrinder
23
23
  class ApplianceConfigHelper
24
24
 
25
+ VAR_SUBSTITUTION_MAX_DEPTH = 20
26
+
25
27
  def initialize(appliance_configs)
26
28
  @appliance_configs = appliance_configs.reverse
27
29
  end
@@ -39,6 +41,7 @@ module BoxGrinder
39
41
  merge_packages
40
42
  merge_files
41
43
  merge_post_operations
44
+ substitute_variables
42
45
 
43
46
  @appliance_config
44
47
  end
@@ -90,6 +93,33 @@ module BoxGrinder
90
93
  end
91
94
  end
92
95
 
96
+ # Get all leaf text values in the appliance definition, then substitute any
97
+ # variable values.
98
+ def substitute_variables
99
+ @appliance_config.all_values.each do |value|
100
+ substitute(value.clone, value, 0)
101
+ end
102
+ end
103
+
104
+ # Replace variables with values. This will occur recursively upto a limited
105
+ # depth if the resolved values themselves contain variables.
106
+ def substitute(init, value, depth)
107
+ if depth > VAR_SUBSTITUTION_MAX_DEPTH
108
+ raise SystemStackError, "Maximal recursive depth (#{VAR_SUBSTITUTION_MAX_DEPTH})
109
+ reached for resolving variable #{init}, reached #{value} before stopping."
110
+ end
111
+ original = value.clone
112
+ value.gsub!(/(#(.*?)#)+?/) do
113
+ # 1. Match pre-defined variable, or variable defined in appliance definition.
114
+ next @appliance_config.variables[$2] if @appliance_config.variables.has_key?($2)
115
+ # 2. Match from environment variables.
116
+ next ENV[$2] unless ENV[$2].nil?
117
+ # 3. No match, replace the original string.
118
+ $1
119
+ end
120
+ substitute(init, value, depth+1) unless original == value
121
+ end
122
+
93
123
  def merge_hardware
94
124
  merge_cpus
95
125
  merge_partitions
@@ -162,25 +192,12 @@ module BoxGrinder
162
192
  @appliance_config.repos.clear
163
193
 
164
194
  @appliance_configs.each do |appliance_config|
165
- for repo in appliance_config.repos
166
- repo['name'] = substitute_vars(repo['name'])
167
- ['baseurl', 'mirrorlist'].each do |type|
168
- repo[type] = substitute_vars(repo[type]) unless repo[type].nil?
169
- end
170
-
195
+ appliance_config.repos.each do |repo|
171
196
  @appliance_config.repos << repo
172
197
  end
173
198
  end
174
199
  end
175
200
 
176
- def substitute_vars(str)
177
- return if str.nil?
178
- @appliance_config.variables.keys.each do |var|
179
- str = str.gsub("##{var}#", @appliance_config.variables[var])
180
- end
181
- str
182
- end
183
-
184
201
  def merge_packages
185
202
  @appliance_config.packages.clear
186
203
 
@@ -202,7 +219,7 @@ module BoxGrinder
202
219
  next if included.include?(appliance_config)
203
220
  appliance_config.files.each do |dir, files|
204
221
  @appliance_config.files[dir] = [] if @appliance_config.files[dir].nil?
205
- files.each { |f| @appliance_config.files[dir] << substitute_vars(f) }
222
+ files.each { |f| @appliance_config.files[dir] << f }
206
223
  end
207
224
  included << appliance_config
208
225
  end
@@ -217,7 +234,7 @@ module BoxGrinder
217
234
  next if included.include?(appliance_config)
218
235
  appliance_config.post.each do |platform, cmds|
219
236
  @appliance_config.post[platform] = [] if @appliance_config.post[platform].nil?
220
- cmds.each { |cmd| @appliance_config.post[platform] << substitute_vars(cmd) }
237
+ cmds.each { |cmd| @appliance_config.post[platform] << cmd }
221
238
  end
222
239
  included << appliance_config
223
240
  end
@@ -94,6 +94,25 @@ module BoxGrinder
94
94
  self
95
95
  end
96
96
 
97
+ def all_values(input=nil)
98
+ avoid = ['@variables']
99
+ input = (self.instance_variables - avoid).
100
+ collect{ |v| self.instance_variable_get(v) } if input.nil?
101
+
102
+ vars = input.inject([]) do |arr, var|
103
+ case var
104
+ when Hash
105
+ arr.concat(all_values(var.values))
106
+ when Array
107
+ arr.concat(all_values(var))
108
+ when String
109
+ arr.push var
110
+ end
111
+ arr
112
+ end
113
+ vars
114
+ end
115
+
97
116
  # Returns default filesystem type for current OS
98
117
  def default_filesystem_type
99
118
  fs = 'ext4'
@@ -60,7 +60,7 @@ mapping:
60
60
  type: seq
61
61
  sequence:
62
62
  - type: str # Now allowing spaces due to group labels (these map to real groups with no spaces, but confuses users) https://issues.jboss.org/browse/BGBUILD-220
63
- pattern: /^[\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
63
+ pattern: /^[\*\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
64
64
  length: { min: 1 }
65
65
  "excludes": *pkg
66
66
  "default_repos":
@@ -57,7 +57,7 @@ mapping:
57
57
  type: seq
58
58
  sequence:
59
59
  - type: str # Now allowing spaces due to group labels (these map to real groups with no spaces, but confuses users) https://issues.jboss.org/browse/BGBUILD-220
60
- pattern: /^[\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
60
+ pattern: /^[\*\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
61
61
  length: { min: 1 }
62
62
  "default_repos":
63
63
  type: bool
@@ -57,7 +57,7 @@ mapping:
57
57
  type: seq
58
58
  sequence:
59
59
  - type: str # Now allowing spaces due to group labels (these map to real groups with no spaces, but confuses users) https://issues.jboss.org/browse/BGBUILD-220
60
- pattern: /^[\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
60
+ pattern: /^[\*\w\-+.@#\s]+$/ #fedora packaging standard http://bit.ly/h0JN9u (plus a few more, disallow symbols)
61
61
  length: { min: 1 }
62
62
  "default_repos":
63
63
  type: bool
@@ -5,7 +5,7 @@
5
5
 
6
6
  Summary: Core library for BoxGrinder
7
7
  Name: rubygem-%{gemname}
8
- Version: 0.3.9
8
+ Version: 0.3.10
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
@@ -76,6 +76,12 @@ popd
76
76
  %{gemdir}/doc/%{gemname}-%{version}
77
77
 
78
78
  %changelog
79
+ * Thu Dec 1 2011 Marc Savy <mgoldman@redhat.com> - 0.3.10
80
+ - Upstream release: 0.3.10
81
+ - [BGBUILD-324] Add wildcard to packages schema
82
+ - [BGBUILD-320] Support variable substitution in any string value field of appliance definition
83
+ - [BGBUILD-327] Resolve appliance definition variables in ENV if they are not defined
84
+
79
85
  * Fri Oct 14 2011 Marc Savy <msavy@redhat.com> - 0.3.9-1
80
86
  - Upstream release: 0.3.9
81
87
  - [BGBUILD-312] Discover which user to switch to after root dependent sections have been executed
@@ -405,6 +405,7 @@ module BoxGrinder
405
405
 
406
406
  @helper.merge_variables
407
407
  @helper.merge_repos
408
+ @helper.substitute_variables
408
409
 
409
410
  config = @helper.instance_variable_get(:@appliance_config)
410
411
  config.repos.size.should == 1
@@ -425,6 +426,7 @@ module BoxGrinder
425
426
 
426
427
  @helper.merge_variables
427
428
  @helper.merge_post_operations
429
+ @helper.substitute_variables
428
430
 
429
431
  config = @helper.instance_variable_get(:@appliance_config)
430
432
  config.post.size.should == 2
@@ -447,12 +449,82 @@ module BoxGrinder
447
449
 
448
450
  @helper.merge_variables
449
451
  @helper.merge_post_operations
452
+ @helper.substitute_variables
450
453
 
451
454
  config = @helper.instance_variable_get(:@appliance_config)
452
455
  config.post.size.should == 1
453
456
  config.post['base'].should == [@arch, @base_arch, '12', 'fedora', 'AAA', 'BBB']
454
457
  end
455
458
 
459
+ it "should allow variable substitution for any string value" do
460
+ config_a = ApplianceConfig.new
461
+ config_a.name = 'a'
462
+ config_a.os.name = "fedora-#CUSTOM_B#"
463
+ config_a.summary = "boxgrinder-#CUSTOM_A#"
464
+ config_a.os.version = '12'
465
+ config_a.variables['CUSTOM_A'] = "AAA"
466
+ config_a.variables['CUSTOM_B'] = "BBB"
467
+ config_a.init_arch
468
+
469
+ prepare_helper([config_a])
470
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
471
+
472
+ @helper.merge_variables
473
+ @helper.merge_post_operations
474
+ @helper.substitute_variables
475
+
476
+ config = @helper.instance_variable_get(:@appliance_config)
477
+ config.os.name.should == "fedora-BBB"
478
+ config.summary.should == "boxgrinder-AAA"
479
+ end
480
+
481
+ it "should allow recursive variable substitution" do
482
+ config_a = ApplianceConfig.new
483
+ config_a.name = 'a'
484
+ config_a.os.name = "fedora-#CUSTOM_B#"
485
+ config_a.summary = "boxgrinder-#CUSTOM_A#"
486
+ config_a.os.version = '#CUSTOM_A#'
487
+ config_a.variables['CUSTOM_A'] = "#CUSTOM_B#"
488
+ config_a.variables['CUSTOM_B'] = "ni-ni-ni"
489
+ config_a.post['base'] = ['#ARCH#', '#BASE_ARCH#', '#OS_VERSION#', '#OS_NAME#', '#CUSTOM_A#', '#CUSTOM_B#']
490
+ config_a.init_arch
491
+
492
+ prepare_helper([config_a])
493
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
494
+
495
+ @helper.merge_variables
496
+ @helper.merge_post_operations
497
+ @helper.substitute_variables
498
+
499
+ config = @helper.instance_variable_get(:@appliance_config)
500
+ config.os.name.should == "fedora-ni-ni-ni"
501
+ config.summary.should == "boxgrinder-ni-ni-ni"
502
+ config.post['base'].should == [@arch, @base_arch, 'ni-ni-ni', 'fedora-ni-ni-ni', 'ni-ni-ni', 'ni-ni-ni']
503
+ end
504
+
505
+ it "should fall back onto ENV if no variable is explicitly defined in the appliance" do
506
+ config_a = ApplianceConfig.new
507
+ config_a.name = 'a'
508
+ config_a.os.name = "fedora-#CUSTOM_B#"
509
+ config_a.os.version = '#CUSTOM_A#'
510
+ ENV['CUSTOM_A'] = 'shrubbery'
511
+ config_a.variables['CUSTOM_B'] = "ni-ni-ni"
512
+ config_a.post['base'] = ['#ARCH#', '#BASE_ARCH#', '#OS_VERSION#', '#OS_NAME#', '#CUSTOM_A#',
513
+ '#CUSTOM_B#', '#CUSTOM_A#-#NOT_DEF#', '#NOT_DEF#-#CUSTOM_A#', "##"]
514
+ config_a.init_arch
515
+
516
+ prepare_helper([config_a])
517
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
518
+
519
+ @helper.merge_variables
520
+ @helper.merge_post_operations
521
+ @helper.substitute_variables
522
+
523
+ config = @helper.instance_variable_get(:@appliance_config)
524
+ config.post['base'].should == [@arch, @base_arch, 'shrubbery', 'fedora-ni-ni-ni', 'shrubbery',
525
+ 'ni-ni-ni', 'shrubbery-#NOT_DEF#', '#NOT_DEF#-shrubbery', '##']
526
+ end
527
+
456
528
  describe ".merge_default_repos" do
457
529
  it "should set default_repos option to true when not specified" do
458
530
  config_a = ApplianceConfig.new
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxgrinder-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 9
10
- version: 0.3.9
9
+ - 10
10
+ version: 0.3.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek Goldmann
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-15 00:00:00 +01:00
19
- default_executable:
18
+ date: 2011-12-19 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: hashery
@@ -136,7 +135,6 @@ files:
136
135
  - spec/rspec/src/appliances/repo.appl
137
136
  - spec/rspec/src/config/empty
138
137
  - spec/rspec/src/config/valid
139
- has_rdoc: true
140
138
  homepage: http://boxgrinder.org
141
139
  licenses: []
142
140
 
@@ -172,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
170
  requirements: []
173
171
 
174
172
  rubyforge_project: BoxGrinder
175
- rubygems_version: 1.3.7
173
+ rubygems_version: 1.8.11
176
174
  signing_key:
177
175
  specification_version: 3
178
176
  summary: Core library for BoxGrinder