boxgrinder-core 0.0.22 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ v0.1.0
3
+
4
+ * [BGBUILD-58] Add ability to substitute custom variables in appliance definition file
5
+ * [BGBUILD-52] Wrong post section inheritance
6
+ * [BGBUILD-48] Hint about missing plugins
7
+ * [BGBUILD-46] Allow building 32 bit images on 64 bit arch
8
+
2
9
  v0.0.22
3
10
 
4
11
  * [BGBUILD-44] ExecHelper should raise exception if execution fails
data/Manifest CHANGED
@@ -1,29 +0,0 @@
1
- CHANGELOG
2
- LICENSE
3
- Manifest
4
- README
5
- Rakefile
6
- lib/boxgrinder-core.rb
7
- lib/boxgrinder-core/defaults.rb
8
- lib/boxgrinder-core/helpers/appliance-config-helper.rb
9
- lib/boxgrinder-core/helpers/appliance-helper.rb
10
- lib/boxgrinder-core/helpers/exec-helper.rb
11
- lib/boxgrinder-core/helpers/log-helper.rb
12
- lib/boxgrinder-core/helpers/queue-helper.rb
13
- lib/boxgrinder-core/models/appliance-config.rb
14
- lib/boxgrinder-core/models/config.rb
15
- lib/boxgrinder-core/models/task.rb
16
- lib/boxgrinder-core/validators/appliance-config-validator.rb
17
- lib/boxgrinder-core/validators/errors.rb
18
- lib/openhash/openhash.rb
19
- spec/Rakefile
20
- spec/helpers/appliance-config-helper-spec.rb
21
- spec/helpers/appliance-helper-spec.rb
22
- spec/helpers/exec-helper-spec.rb
23
- spec/helpers/log-helper-spec.rb
24
- spec/helpers/queue-helper-spec.rb
25
- spec/rspec/rspec-config-helper.rb
26
- spec/rspec/src/appliances/ephemeral-repo.appl
27
- spec/rspec/src/appliances/full.appl
28
- spec/rspec/src/appliances/repo.appl
29
- spec/validators/appliance-config-validator-spec.rb
@@ -2,27 +2,27 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-core}
5
- s.version = "0.0.22"
5
+ s.version = "0.1.0"
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{2010-08-23}
9
+ s.date = %q{2010-10-12}
10
10
  s.description = %q{Core files for BoxGrinder.}
11
11
  s.email = %q{info@boxgrinder.org}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/helpers/queue-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "lib/openhash/openhash.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/helpers/queue-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "lib/openhash/openhash.rb", "spec/Rakefile", "spec/helpers/appliance-config-helper-spec.rb", "spec/helpers/appliance-helper-spec.rb", "spec/helpers/exec-helper-spec.rb", "spec/helpers/log-helper-spec.rb", "spec/helpers/queue-helper-spec.rb", "spec/rspec/rspec-config-helper.rb", "spec/rspec/src/appliances/ephemeral-repo.appl", "spec/rspec/src/appliances/full.appl", "spec/rspec/src/appliances/repo.appl", "spec/validators/appliance-config-validator-spec.rb", "boxgrinder-core.gemspec"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/helpers/queue-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "lib/openhash/openhash.rb", "spec/Rakefile", "spec/helpers/appliance-config-helper-spec.rb", "spec/helpers/appliance-helper-spec.rb", "spec/helpers/exec-helper-spec.rb", "spec/helpers/log-helper-spec.rb", "spec/helpers/queue-helper-spec.rb", "spec/rspec/ls/one", "spec/rspec/ls/two", "spec/rspec/rspec-config-helper.rb", "spec/rspec/src/appliances/ephemeral-repo.appl", "spec/rspec/src/appliances/full.appl", "spec/rspec/src/appliances/repo.appl", "spec/validators/appliance-config-validator-spec.rb", "boxgrinder-core.gemspec"]
14
14
  s.homepage = %q{http://www.jboss.org/stormgrind/projects/boxgrinder.html}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Boxgrinder-core", "--main", "README"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{BoxGrinder Core}
18
- s.rubygems_version = %q{1.3.6}
18
+ s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{Core files for BoxGrinder.}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
23
  s.specification_version = 3
24
24
 
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
26
  s.add_runtime_dependency(%q<open4>, [">= 1.0.0"])
27
27
  else
28
28
  s.add_dependency(%q<open4>, [">= 1.0.0"])
@@ -19,12 +19,13 @@
19
19
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
20
20
 
21
21
  require 'boxgrinder-core/validators/errors'
22
+ require 'set'
22
23
 
23
24
  module BoxGrinder
24
25
  class ApplianceConfigHelper
25
26
 
26
- def initialize(appliance_configs)
27
- @appliance_configs = appliance_configs.values.reverse
27
+ def initialize( appliance_configs )
28
+ @appliance_configs = appliance_configs.reverse
28
29
  end
29
30
 
30
31
  def merge(appliance_config)
@@ -33,6 +34,7 @@ module BoxGrinder
33
34
  prepare_os
34
35
  prepare_appliances
35
36
 
37
+ merge_variables
36
38
  merge_hardware
37
39
  merge_repos
38
40
  merge_packages
@@ -41,7 +43,41 @@ module BoxGrinder
41
43
  @appliance_config
42
44
  end
43
45
 
44
- protected
46
+ def merge_variables
47
+ @appliance_config.variables = {} if @appliance_config.variables.nil?
48
+ @appliance_configs.each do |appliance_config|
49
+ appliance_config.variables.each do |var, val|
50
+ @appliance_config.variables[var] = val
51
+ end
52
+ end
53
+
54
+ @appliance_config.variables["OS_NAME"] = @appliance_config.os.name
55
+ @appliance_config.variables["OS_VERSION"] = @appliance_config.os.version
56
+ @appliance_config.variables["ARCH"] = @appliance_config.hardware.arch
57
+ @appliance_config.variables["BASE_ARCH"] = @appliance_config.hardware.base_arch
58
+
59
+ resolve
60
+ end
61
+
62
+ def resolve(resolve_stack = nil, resolved_set = Set.new())
63
+ if resolve_stack.nil?
64
+ @appliance_config.variables.keys.each { |var| resolve([var], resolved_set) }
65
+ else
66
+ var = resolve_stack.last
67
+ refs = @appliance_config.variables.keys.delete_if { |k|
68
+ @appliance_config.variables[k].nil? ||
69
+ @appliance_config.variables[k].index("##{k}#").nil? ||
70
+ resolve_stack.index(k).nil?
71
+ }
72
+ refs.each do |ref|
73
+ resolve(Arrays.new(resolve_stack).push(ref), resolved_set) unless resolved_set.include?(ref)
74
+ while @appliance_config.variables[var].include? "##{ref}#" do
75
+ @appliance_config.variables[var].gsub!("##{ref}#", @appliance_config.variables[ref])
76
+ end
77
+ end
78
+ resolved_set << var
79
+ end
80
+ end
45
81
 
46
82
  def merge_hardware
47
83
  merge_cpus
@@ -61,6 +97,12 @@ module BoxGrinder
61
97
  parts.each do |root, partition|
62
98
  if partitions.keys.include?(root)
63
99
  partitions[root]['size'] = partition['size'] if partitions[root]['size'] < partition['size']
100
+
101
+ unless partition['type'].nil?
102
+ partitions[root].delete('options') if partitions[root]['type'] != partition['type']
103
+ partitions[root]['type'] = partition['type']
104
+ end
105
+ partitions[root]['options'] = partition['options'] unless partition['options'].nil? and partitions[root]['type'] == partition['type']
64
106
  else
65
107
  partitions[root] = partition
66
108
  end
@@ -95,9 +137,9 @@ module BoxGrinder
95
137
 
96
138
  @appliance_configs.each do |appliance_config|
97
139
  for repo in appliance_config.repos
98
- repo['name'] = substitute_repo_parameters(repo['name'])
140
+ repo['name'] = substitute_vars(repo['name'])
99
141
  ['baseurl', 'mirrorlist'].each do |type|
100
- repo[type] = substitute_repo_parameters(repo[type]) unless repo[type].nil?
142
+ repo[type] = substitute_vars(repo[type]) unless repo[type].nil?
101
143
  end
102
144
 
103
145
  @appliance_config.repos << repo
@@ -105,9 +147,12 @@ module BoxGrinder
105
147
  end
106
148
  end
107
149
 
108
- def substitute_repo_parameters(str)
150
+ def substitute_vars(str)
109
151
  return if str.nil?
110
- str.gsub(/#OS_NAME#/, @appliance_config.os.name).gsub(/#OS_VERSION#/, @appliance_config.os.version).gsub(/#ARCH#/, @appliance_config.hardware.arch)
152
+ @appliance_config.variables.keys.each do |var|
153
+ str = str.gsub("##{var}#", @appliance_config.variables[var])
154
+ end
155
+ str
111
156
  end
112
157
 
113
158
  def merge_packages
@@ -130,7 +175,8 @@ module BoxGrinder
130
175
 
131
176
  @appliance_configs.each do |appliance_config|
132
177
  appliance_config.post.each do |platform, cmds|
133
- cmds.each { |cmd| @appliance_config.post[platform] << cmd }
178
+ @appliance_config.post[platform] = [] if @appliance_config.post[platform].nil?
179
+ cmds.each { |cmd| @appliance_config.post[platform] << substitute_vars(cmd) }
134
180
  end
135
181
  end
136
182
  end
@@ -30,11 +30,11 @@ module BoxGrinder
30
30
  @log.debug "Reading definition from '#{definition_file}' file..."
31
31
 
32
32
  definition_file_extension = File.extname(definition_file)
33
- configs = {}
33
+ configs = []
34
34
 
35
35
  appliance_config =
36
36
  case definition_file_extension
37
- when '.appl', '.yml'
37
+ when '.appl', '.yml', '.yaml'
38
38
  read_yaml(definition_file)
39
39
  when '.xml'
40
40
  read_xml(definition_file)
@@ -51,13 +51,13 @@ module BoxGrinder
51
51
  end
52
52
  end
53
53
 
54
- configs[appliance_config.name] = appliance_config
54
+ configs << appliance_config
55
55
 
56
- appliance_config.appliances.each do |appliance_name|
57
- configs.merge!(read_definitions("#{File.dirname(definition_file)}/#{appliance_name}#{definition_file_extension}").first)
56
+ appliance_config.appliances.reverse.each do |appliance_name|
57
+ configs << read_definitions("#{File.dirname(definition_file)}/#{appliance_name}#{definition_file_extension}").first
58
58
  end unless appliance_config.appliances.nil? or !appliance_config.appliances.is_a?(Array)
59
59
 
60
- [ configs, appliance_config ]
60
+ [ configs.flatten, appliance_config ]
61
61
  end
62
62
 
63
63
  def read_yaml(file)
@@ -74,6 +74,9 @@ module BoxGrinder
74
74
 
75
75
  appliance_config.name = definition['name'] unless definition['name'].nil?
76
76
  appliance_config.summary = definition['summary'] unless definition['summary'].nil?
77
+
78
+ definition['variables'].each { |key, value| appliance_config.variables[key] = value } unless definition['variables'].nil?
79
+
77
80
  appliance_config.appliances = definition['appliances'] unless definition['appliances'].nil?
78
81
  appliance_config.repos = definition['repos'] unless definition['repos'].nil?
79
82
 
@@ -20,7 +20,6 @@
20
20
 
21
21
  require 'boxgrinder-core/defaults'
22
22
  require 'openhash/openhash'
23
- require 'rbconfig'
24
23
 
25
24
  module BoxGrinder
26
25
  class ApplianceConfig
@@ -28,6 +27,8 @@ module BoxGrinder
28
27
  @name = nil
29
28
  @summary = nil
30
29
 
30
+ @variables = {}
31
+
31
32
  @os = OpenHash.new
32
33
 
33
34
  @os.name = nil
@@ -53,6 +54,7 @@ module BoxGrinder
53
54
  @release = 0
54
55
  end
55
56
 
57
+ attr_reader :variables
56
58
  attr_reader :os
57
59
  attr_reader :hardware
58
60
  attr_reader :path
@@ -74,7 +76,8 @@ module BoxGrinder
74
76
  end
75
77
 
76
78
  def init_arch
77
- @hardware.arch = RbConfig::CONFIG['target_cpu']
79
+ @hardware.arch = `uname -m`.chomp.strip
80
+ @hardware.base_arch = is64bit? ? "x86_64" : "i386"
78
81
  self
79
82
  end
80
83
 
@@ -20,7 +20,6 @@
20
20
 
21
21
  require 'boxgrinder-core/defaults'
22
22
  require 'ostruct'
23
- require 'rbconfig'
24
23
 
25
24
  module BoxGrinder
26
25
  class Config
@@ -52,6 +51,8 @@ module BoxGrinder
52
51
  if File.exists?( @config_file )
53
52
  @data = YAML.load_file( @config_file )
54
53
  @data['gpg_password'].gsub!(/\$/, "\\$") unless @data['gpg_password'].nil? or @data['gpg_password'].length == 0
54
+ @dir.rpms_cache = @data['rpms_cache'] || @dir.rpms_cache
55
+ @dir.src_cache = @data['src_cache'] || @dir.src_cache
55
56
  end
56
57
  end
57
58
 
@@ -44,14 +44,13 @@ module BoxGrinder
44
44
  end
45
45
 
46
46
  def validate_os
47
- raise ApplianceValidationError, "No operating system selected" if @appliance_config.os.name.nil?
47
+ raise "No operating system plugins installed. Install one or more operating system plugin. See http://community.jboss.org/docs/DOC-15081 and http://community.jboss.org/docs/DOC-15214 for more info" if PluginManager.instance.plugins[:os].empty?
48
48
 
49
- unless @options[:os_plugins].nil?
50
- os_plugin = @options[:os_plugins][@appliance_config.os.name.to_sym]
49
+ os_plugin = PluginManager.instance.plugins[:os][@appliance_config.os.name.to_sym]
51
50
 
52
- raise ApplianceValidationError, "Not supported operating system selected: #{@appliance_config.os.name}. Supported OSes are: #{@options[:os_plugins].keys.join(", ")}" if os_plugin.nil?
53
- raise ApplianceValidationError, "Not supported operating system version selected: #{@appliance_config.os.version}. Supported versions are: #{os_plugin[:versions].join(", ")}" unless @appliance_config.os.version.nil? or os_plugin[:versions].include?( @appliance_config.os.version )
54
- end
51
+ raise ApplianceValidationError, "No operating system selected" if @appliance_config.os.name.nil?
52
+ raise ApplianceValidationError, "Not supported operating system selected: #{@appliance_config.os.name}. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: #{PluginManager.instance.plugins[:os].keys.join(", ")}" if os_plugin.nil?
53
+ raise ApplianceValidationError, "Not supported operating system version selected: #{@appliance_config.os.version}. Supported versions are: #{os_plugin[:versions].join(", ")}" unless @appliance_config.os.version.nil? or os_plugin[:versions].include?( @appliance_config.os.version )
55
54
  end
56
55
 
57
56
  def validate_hardware
data/spec/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
  require 'spec/rake/spectask'
3
3
 
4
4
  desc "Run all examples"
5
- Spec::Rake::SpecTask.new('examples') do |t|
5
+ Spec::Rake::SpecTask.new(:default) do |t|
6
6
  t.spec_files = FileList['**/*-spec.rb']
7
7
  t.rcov = true
8
8
  t.spec_opts = ['--colour', '--format', 'nested']
@@ -1,6 +1,267 @@
1
1
  require 'boxgrinder-core/helpers/appliance-config-helper'
2
+ require 'rspec/rspec-config-helper'
2
3
 
3
4
  module BoxGrinder
4
5
  describe ApplianceConfigHelper do
6
+ include RSpecConfigHelper
7
+
8
+ before(:all) do
9
+ @arch = `uname -m`.chomp.strip
10
+ @base_arch = @arch.eql?("x86_64") ? "x86_64" : "i386"
11
+ end
12
+
13
+ def prepare_helper( configs )
14
+ @helper = ApplianceConfigHelper.new( configs )
15
+ end
16
+
17
+ it "should merge post sections in right order" do
18
+ config_a = ApplianceConfig.new
19
+ config_a.name = 'a'
20
+ config_a.post['base'] = [ "1_1", "1_2" ]
21
+ config_a.appliances << 'b'
22
+
23
+ config_b = ApplianceConfig.new
24
+ config_b.name = 'b'
25
+ config_b.post['base'] = [ "2_1", "2_2" ]
26
+
27
+ prepare_helper( [ config_a, config_b ] )
28
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
29
+
30
+ @helper.merge_post_operations
31
+
32
+ config = @helper.instance_variable_get(:@appliance_config)
33
+ config.post['base'].size.should == 4
34
+ config.post['base'].should == ['2_1', '2_2', '1_1', '1_2']
35
+ end
36
+
37
+ it "should merge post sections in right order with more complicated inheritance" do
38
+ config_a = ApplianceConfig.new
39
+ config_a.name = 'a'
40
+ config_a.post['base'] = [ "1_1", "1_2" ]
41
+ config_a.appliances << 'b1'
42
+ config_a.appliances << 'b2'
43
+
44
+ config_b1 = ApplianceConfig.new
45
+ config_b1.name = 'b1'
46
+ config_b1.post['base'] = [ "2_1", "2_2" ]
47
+
48
+ config_b2 = ApplianceConfig.new
49
+ config_b2.name = 'b2'
50
+ config_b2.post['base'] = [ "3_1", "3_2" ]
51
+
52
+ prepare_helper( [ config_a, config_b1, config_b2 ] )
53
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
54
+
55
+ @helper.merge_post_operations
56
+
57
+ config = @helper.instance_variable_get(:@appliance_config)
58
+ config.post['base'].size.should == 6
59
+ config.post['base'].should == ['3_1', '3_2', '2_1', '2_2', '1_1', '1_2']
60
+ end
61
+
62
+ it "should merge post sections in right order with even more and more complicated inheritance" do
63
+ config_a = ApplianceConfig.new
64
+ config_a.name = 'a'
65
+ config_a.post['base'] = [ "1_1", "1_2" ]
66
+ config_a.appliances << 'b1'
67
+ config_a.appliances << 'b2'
68
+
69
+ config_b1 = ApplianceConfig.new
70
+ config_b1.name = 'b1'
71
+ config_b1.appliances << 'c1'
72
+ config_b1.post['base'] = [ "2_1", "2_2" ]
73
+
74
+ config_b2 = ApplianceConfig.new
75
+ config_b2.name = 'b2'
76
+ config_b2.appliances << 'c2'
77
+ config_b2.post['base'] = [ "3_1", "3_2" ]
78
+
79
+ config_c1 = ApplianceConfig.new
80
+ config_c1.name = 'c1'
81
+ config_c1.post['base'] = [ "4_1", "4_2" ]
82
+
83
+ config_c2 = ApplianceConfig.new
84
+ config_c2.name = 'c2'
85
+ config_c2.post['base'] = [ "5_1", "5_2" ]
86
+
87
+ prepare_helper( [
88
+ config_a,
89
+ config_b1,
90
+ config_c1,
91
+ config_b2,
92
+ config_c2
93
+ ] )
94
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
95
+
96
+ @helper.merge_post_operations
97
+
98
+ config = @helper.instance_variable_get(:@appliance_config)
99
+ config.post['base'].size.should == 10
100
+ config.post['base'].should == ['5_1', '5_2', '3_1', '3_2', '4_1', '4_2', '2_1', '2_2', '1_1', '1_2']
101
+ end
102
+
103
+ it "should merge post sections when dependent appliance has post section for platform for which we haven't specified post operations" do
104
+ config_a = ApplianceConfig.new
105
+ config_a.name = 'a'
106
+ config_a.post['base'] = [ "1_1", "1_2" ]
107
+ config_a.appliances << 'b'
108
+
109
+ config_b = ApplianceConfig.new
110
+ config_b.name = 'b'
111
+ config_b.post['ec2'] = [ "2_1", "2_2" ]
112
+
113
+ prepare_helper( [ config_a, config_b ] )
114
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
115
+
116
+ @helper.merge_post_operations
117
+
118
+ config = @helper.instance_variable_get(:@appliance_config)
119
+ config.post['base'].size.should == 2
120
+ config.post['base'].should == ['1_1', '1_2']
121
+ config.post['ec2'].size.should == 2
122
+ config.post['ec2'].should == ['2_1', '2_2']
123
+ end
124
+
125
+ it "should merge partitions" do
126
+ config_a = ApplianceConfig.new
127
+ config_a.name = 'a'
128
+ config_a.appliances << 'b'
129
+ config_a.hardware.partitions = { "/" => { 'size' => '2' } }
130
+
131
+ config_b = ApplianceConfig.new
132
+ config_b.name = 'b'
133
+ config_b.hardware.partitions = { "/" => { 'size' => '4' }, "/home" => { 'size' => '2' } }
134
+
135
+ prepare_helper( [ config_a, config_b ] )
136
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
137
+
138
+ @helper.merge_partitions
139
+
140
+ config = @helper.instance_variable_get(:@appliance_config)
141
+ config.hardware.partitions.size.should == 2
142
+ config.hardware.partitions.should == { "/" => { 'size' => '4' }, "/home" => { 'size' => '2' } }
143
+ end
144
+
145
+ it "should merge partitions with different filesystem types" do
146
+ config_a = ApplianceConfig.new
147
+ config_a.name = 'a'
148
+ config_a.appliances << 'b'
149
+ config_a.hardware.partitions = { "/" => { 'size' => '2', 'type' => 'ext4' } }
150
+
151
+ config_b = ApplianceConfig.new
152
+ config_b.name = 'b'
153
+ config_b.hardware.partitions = { "/" => { 'size' => '4', 'type' => 'ext3' }, "/home" => { 'size' => '2' } }
154
+
155
+ prepare_helper( [ config_a, config_b ] )
156
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
157
+
158
+ @helper.merge_partitions
159
+
160
+ config = @helper.instance_variable_get(:@appliance_config)
161
+ config.hardware.partitions.size.should == 2
162
+ config.hardware.partitions.should == { "/" => { 'size' => '4', 'type' => 'ext4' }, "/home" => { 'size' => '2' } }
163
+ end
164
+
165
+ it "should merge partitions with different options" do
166
+ config_a = ApplianceConfig.new
167
+ config_a.name = 'a'
168
+ config_a.appliances << 'b'
169
+ config_a.hardware.partitions = { "/" => { 'size' => '2', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime' } }
170
+
171
+ config_b = ApplianceConfig.new
172
+ config_b.name = 'b'
173
+ config_b.hardware.partitions = { "/" => { 'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear' }, "/home" => { 'size' => '2' } }
174
+
175
+ prepare_helper( [ config_a, config_b ] )
176
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
177
+
178
+ @helper.merge_partitions
179
+
180
+ config = @helper.instance_variable_get(:@appliance_config)
181
+ config.hardware.partitions.size.should == 2
182
+ config.hardware.partitions.should == { "/" => { 'size' => '4', 'type' => 'ext4', 'options' => 'barrier=0,nodelalloc,nobh,noatime' }, "/home" => { 'size' => '2' } }
183
+ end
184
+
185
+ it "should merge partitions with different options, another case where type is changing - options should be vanished" do
186
+ config_a = ApplianceConfig.new
187
+ config_a.name = 'a'
188
+ config_a.appliances << 'b'
189
+ config_a.hardware.partitions = { "/" => { 'size' => '2', 'type' => 'ext4' } }
190
+
191
+ config_b = ApplianceConfig.new
192
+ config_b.name = 'b'
193
+ config_b.hardware.partitions = { "/" => { 'size' => '4', 'type' => 'ext3', 'options' => 'shouldnt appear' }, "/home" => { 'size' => '2' } }
194
+
195
+ prepare_helper( [ config_a, config_b ] )
196
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
197
+
198
+ @helper.merge_partitions
199
+
200
+ config = @helper.instance_variable_get(:@appliance_config)
201
+ config.hardware.partitions.size.should == 2
202
+ config.hardware.partitions.should == { "/" => { 'size' => '4', 'type' => 'ext4' }, "/home" => { 'size' => '2' } }
203
+ end
204
+
205
+ it "should substitute variables in repos" do
206
+ config_a = ApplianceConfig.new
207
+ config_a.name = 'a'
208
+ config_a.os.name = 'fedora'
209
+ config_a.os.version = '12'
210
+ config_a.repos << { 'name' => '#ARCH#', 'baseurl' => '#BASE_ARCH#', 'mirrorlist' => '#OS_NAME#-#OS_VERSION#' }
211
+ config_a.init_arch
212
+
213
+ prepare_helper( [ config_a ] )
214
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
215
+
216
+ @helper.merge_variables
217
+ @helper.merge_repos
218
+
219
+ config = @helper.instance_variable_get(:@appliance_config)
220
+ config.repos.size.should == 1
221
+ config.repos.first.should == { 'name' => "#{@arch}", 'baseurl' => "#{@base_arch}", 'mirrorlist' => 'fedora-12' }
222
+ end
223
+
224
+ it "should substitute variables in post section" do
225
+ config_a = ApplianceConfig.new
226
+ config_a.name = 'a'
227
+ config_a.os.name = 'fedora'
228
+ config_a.os.version = '12'
229
+ config_a.post['base'] = ['#ARCH#', '#BASE_ARCH#', '#OS_VERSION#', '#OS_NAME#']
230
+ config_a.post['ec2'] = ['#ARCH#', '#BASE_ARCH#', '#OS_VERSION#', '#OS_NAME#']
231
+ config_a.init_arch
232
+
233
+ prepare_helper( [ config_a ] )
234
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
235
+
236
+ @helper.merge_variables
237
+ @helper.merge_post_operations
238
+
239
+ config = @helper.instance_variable_get(:@appliance_config)
240
+ config.post.size.should == 2
241
+ config.post['base'].should == [@arch, @base_arch, '12', 'fedora']
242
+ config.post['ec2'].should == [@arch, @base_arch, '12', 'fedora']
243
+ end
244
+
245
+ it "should substitute custom variables" do
246
+ config_a = ApplianceConfig.new
247
+ config_a.name = 'a'
248
+ config_a.os.name = 'fedora'
249
+ config_a.os.version = '12'
250
+ config_a.variables['CUSTOM_A'] = "AAA"
251
+ config_a.variables['CUSTOM_B'] = "BBB"
252
+ config_a.post['base'] = ['#ARCH#', '#BASE_ARCH#', '#OS_VERSION#', '#OS_NAME#', '#CUSTOM_A#', '#CUSTOM_B#']
253
+ config_a.init_arch
254
+
255
+ prepare_helper( [ config_a ] )
256
+ @helper.instance_variable_set(:@appliance_config, config_a.clone)
257
+
258
+ @helper.merge_variables
259
+ @helper.merge_post_operations
260
+
261
+ config = @helper.instance_variable_get(:@appliance_config)
262
+ config.post.size.should == 1
263
+ config.post['base'].should == [@arch, @base_arch, '12', 'fedora', 'AAA', 'BBB']
264
+ end
265
+
5
266
  end
6
267
  end
@@ -1,6 +1,62 @@
1
1
  require 'boxgrinder-core/helpers/appliance-helper'
2
+ require 'rspec/rspec-config-helper'
2
3
 
3
4
  module BoxGrinder
4
5
  describe ApplianceHelper do
6
+ include RSpecConfigHelper
7
+
8
+ before(:each) do
9
+ @helper = ApplianceHelper.new( :log => Logger.new('/dev/null') )
10
+ end
11
+
12
+ it "should read definition from one file" do
13
+ appliance_config = ApplianceConfig.new
14
+ @helper.should_receive(:read_yaml).with('file.appl').and_return( appliance_config )
15
+ @helper.read_definitions( "file.appl" ).should == [ [ appliance_config ], appliance_config ]
16
+ end
17
+
18
+ it "should read definition from two files" do
19
+ appliance_a = ApplianceConfig.new
20
+ appliance_a.name = 'a'
21
+ appliance_a.appliances << "b"
22
+
23
+ appliance_b = ApplianceConfig.new
24
+ appliance_b.name = 'b'
25
+
26
+ @helper.should_receive(:read_yaml).ordered.with('a.appl').and_return( appliance_a )
27
+ @helper.should_receive(:read_yaml).ordered.with('./b.appl').and_return( appliance_b )
28
+
29
+ @helper.read_definitions( "a.appl" ).should == [ [ appliance_a, appliance_b ], appliance_a ]
30
+ end
31
+
32
+ it "should read definitions from a tree file structure" do
33
+ appliance_a = ApplianceConfig.new
34
+ appliance_a.name = 'a'
35
+ appliance_a.appliances << "b1"
36
+ appliance_a.appliances << "b2"
37
+
38
+ appliance_b1 = ApplianceConfig.new
39
+ appliance_b1.name = 'b1'
40
+ appliance_b1.appliances << "c1"
41
+
42
+ appliance_b2 = ApplianceConfig.new
43
+ appliance_b2.name = 'b2'
44
+ appliance_b2.appliances << "c2"
45
+
46
+ appliance_c1 = ApplianceConfig.new
47
+ appliance_c1.name = 'c1'
48
+
49
+ appliance_c2 = ApplianceConfig.new
50
+ appliance_c2.name = 'c2'
51
+
52
+ @helper.should_receive(:read_yaml).ordered.with('a.appl').and_return( appliance_a )
53
+ @helper.should_receive(:read_yaml).ordered.with('./b2.appl').and_return( appliance_b2 )
54
+ @helper.should_receive(:read_yaml).ordered.with('./c2.appl').and_return( appliance_c2 )
55
+ @helper.should_receive(:read_yaml).ordered.with('./b1.appl').and_return( appliance_b1 )
56
+ @helper.should_receive(:read_yaml).ordered.with('./c1.appl').and_return( appliance_c1 )
57
+
58
+ @helper.read_definitions( "a.appl" ).should == [ [ appliance_a, appliance_b2, appliance_c2, appliance_b1, appliance_c1 ], appliance_a ]
59
+ end
60
+
5
61
  end
6
62
  end
@@ -31,11 +31,11 @@ module BoxGrinder
31
31
  end
32
32
 
33
33
  it "should execute the command and return output" do
34
- @helper.execute("ls rspec/ls | wc -l").should == "2"
34
+ @helper.execute("ls #{File.dirname( __FILE__ )}/../rspec/ls | wc -l").should == "2"
35
35
  end
36
36
 
37
37
  it "should execute the command and return multi line output" do
38
- @helper.execute("ls -1 rspec/ls").should == "one\ntwo"
38
+ @helper.execute("ls -1 #{File.dirname( __FILE__ )}/../rspec/ls").should == "one\ntwo"
39
39
  end
40
40
  end
41
41
  end
data/spec/rspec/ls/one ADDED
File without changes
data/spec/rspec/ls/two ADDED
File without changes
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxgrinder-core
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 22
9
- version: 0.0.22
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Marek Goldmann
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-23 00:00:00 +02:00
18
+ date: 2010-10-12 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: open4
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 23
27
30
  segments:
28
31
  - 1
29
32
  - 0
@@ -79,6 +82,8 @@ files:
79
82
  - spec/helpers/exec-helper-spec.rb
80
83
  - spec/helpers/log-helper-spec.rb
81
84
  - spec/helpers/queue-helper-spec.rb
85
+ - spec/rspec/ls/one
86
+ - spec/rspec/ls/two
82
87
  - spec/rspec/rspec-config-helper.rb
83
88
  - spec/rspec/src/appliances/ephemeral-repo.appl
84
89
  - spec/rspec/src/appliances/full.appl
@@ -100,16 +105,20 @@ rdoc_options:
100
105
  require_paths:
101
106
  - lib
102
107
  required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
103
109
  requirements:
104
110
  - - ">="
105
111
  - !ruby/object:Gem::Version
112
+ hash: 3
106
113
  segments:
107
114
  - 0
108
115
  version: "0"
109
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
110
118
  requirements:
111
119
  - - ">="
112
120
  - !ruby/object:Gem::Version
121
+ hash: 11
113
122
  segments:
114
123
  - 1
115
124
  - 2
@@ -117,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
126
  requirements: []
118
127
 
119
128
  rubyforge_project: BoxGrinder Core
120
- rubygems_version: 1.3.6
129
+ rubygems_version: 1.3.7
121
130
  signing_key:
122
131
  specification_version: 3
123
132
  summary: Core files for BoxGrinder.