boxgrinder-build 0.6.5 → 0.7.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+
2
+ v0.7.0
3
+
4
+ * [BGBUILD-119] Fix SElinux issues on EC2 appliances
5
+ * [BGBUILD-118] Enable SElinux in guestfs
6
+ * [BGBUILD-80] VMware .tgz Bundle Should Expand Into Subdirectory, Not Current Directory
7
+ * [BGBUILD-113] Allow to specify supported file formats for operating system plugin
8
+ * [BGBUILD-73] Add support for kickstart files
9
+
1
10
  v0.6.5
2
11
 
3
12
  * Release bump required for plugins
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ Echoe.new("boxgrinder-build") do |p|
26
26
  p.summary = "A tool for creating appliances from simple plain text files for various virtual environments."
27
27
  p.url = "http://www.jboss.org/boxgrinder"
28
28
  p.email = "info@boxgrinder.org"
29
- p.runtime_dependencies = ["commander ~>4.0.3", "boxgrinder-core ~>0.1.4"]
29
+ p.runtime_dependencies = ["commander ~>4.0.3", "boxgrinder-core ~>0.1.5"]
30
30
  end
31
31
 
32
32
  desc "Run all tests"
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-build}
5
- s.version = "0.6.5"
5
+ s.version = "0.7.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-12-03}
9
+ s.date = %q{2010-12-17}
10
10
  s.default_executable = %q{boxgrinder-build}
11
11
  s.description = %q{A tool for creating appliances from simple plain text files for various virtual environments.}
12
12
  s.email = %q{info@boxgrinder.org}
13
13
  s.executables = ["boxgrinder-build"]
14
14
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "bin/boxgrinder-build", "lib/boxgrinder-build/appliance.rb", "lib/boxgrinder-build/helpers/appliance-customize-helper.rb", "lib/boxgrinder-build/helpers/augeas-helper.rb", "lib/boxgrinder-build/helpers/guestfs-helper.rb", "lib/boxgrinder-build/helpers/image-helper.rb", "lib/boxgrinder-build/helpers/linux-helper.rb", "lib/boxgrinder-build/helpers/package-helper.rb", "lib/boxgrinder-build/helpers/plugin-helper.rb", "lib/boxgrinder-build/managers/plugin-manager.rb", "lib/boxgrinder-build/plugins/base-plugin.rb"]
15
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "bin/boxgrinder-build", "boxgrinder-build.gemspec", "lib/boxgrinder-build/appliance.rb", "lib/boxgrinder-build/helpers/appliance-customize-helper.rb", "lib/boxgrinder-build/helpers/augeas-helper.rb", "lib/boxgrinder-build/helpers/guestfs-helper.rb", "lib/boxgrinder-build/helpers/image-helper.rb", "lib/boxgrinder-build/helpers/linux-helper.rb", "lib/boxgrinder-build/helpers/package-helper.rb", "lib/boxgrinder-build/helpers/plugin-helper.rb", "lib/boxgrinder-build/managers/plugin-manager.rb", "lib/boxgrinder-build/plugins/base-plugin.rb", "rubygem-boxgrinder-build.spec", "spec/Rakefile", "spec/appliance-spec.rb", "spec/helpers/appliance-customize-helper-spec.rb", "spec/helpers/augeas-helper-spec.rb", "spec/helpers/guestfs-helper-spec.rb", "spec/helpers/image-helper-spec.rb", "spec/helpers/linux-helper-spec.rb", "spec/helpers/package-helper-spec.rb", "spec/helpers/plugin-helper-spec.rb", "spec/managers/plugin-manager-spec.rb", "spec/plugins/base-plugin-spec.rb", "spec/rspec/src/appliances/jeos-f13.appl"]
15
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "bin/boxgrinder-build", "boxgrinder-build.gemspec", "lib/boxgrinder-build/appliance.rb", "lib/boxgrinder-build/helpers/appliance-customize-helper.rb", "lib/boxgrinder-build/helpers/augeas-helper.rb", "lib/boxgrinder-build/helpers/guestfs-helper.rb", "lib/boxgrinder-build/helpers/image-helper.rb", "lib/boxgrinder-build/helpers/linux-helper.rb", "lib/boxgrinder-build/helpers/package-helper.rb", "lib/boxgrinder-build/helpers/plugin-helper.rb", "lib/boxgrinder-build/managers/plugin-manager.rb", "lib/boxgrinder-build/plugins/base-plugin.rb", "rubygem-boxgrinder-build.spec", "spec/Rakefile", "spec/appliance-spec.rb", "spec/helpers/appliance-customize-helper-spec.rb", "spec/helpers/augeas-helper-spec.rb", "spec/helpers/guestfs-helper-spec.rb", "spec/helpers/image-helper-spec.rb", "spec/helpers/linux-helper-spec.rb", "spec/helpers/package-helper-spec.rb", "spec/helpers/plugin-helper-spec.rb", "spec/managers/plugin-manager-spec.rb", "spec/plugins/base-plugin-spec.rb", "spec/rspec/src/appliances/jeos-f13.appl", "spec/rspec/src/appliances/jeos-f13.ks"]
16
16
  s.homepage = %q{http://www.jboss.org/boxgrinder}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Boxgrinder-build", "--main", "README"]
18
18
  s.require_paths = ["lib"]
@@ -26,13 +26,13 @@ Gem::Specification.new do |s|
26
26
 
27
27
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
28
  s.add_runtime_dependency(%q<commander>, ["~> 4.0.3"])
29
- s.add_runtime_dependency(%q<boxgrinder-core>, ["~> 0.1.4"])
29
+ s.add_runtime_dependency(%q<boxgrinder-core>, ["~> 0.1.5"])
30
30
  else
31
31
  s.add_dependency(%q<commander>, ["~> 4.0.3"])
32
- s.add_dependency(%q<boxgrinder-core>, ["~> 0.1.4"])
32
+ s.add_dependency(%q<boxgrinder-core>, ["~> 0.1.5"])
33
33
  end
34
34
  else
35
35
  s.add_dependency(%q<commander>, ["~> 4.0.3"])
36
- s.add_dependency(%q<boxgrinder-core>, ["~> 0.1.4"])
36
+ s.add_dependency(%q<boxgrinder-core>, ["~> 0.1.5"])
37
37
  end
38
38
  end
@@ -29,32 +29,45 @@ module BoxGrinder
29
29
  class Appliance
30
30
 
31
31
  def initialize(appliance_definition_file, options = {})
32
- @config = Config.new
32
+ @config = Config.new
33
33
  @appliance_definition_file = appliance_definition_file
34
- @log = options[:log] || Logger.new(STDOUT)
35
- @options = options[:options]
34
+ @log = options[:log] || Logger.new(STDOUT)
35
+ @options = options[:options]
36
36
 
37
- @config.name = @options.name
38
- @config.version.version = @options.version
39
- @config.version.release = nil
37
+ @config.name = @options.name
38
+ @config.version.version = @options.version
39
+ @config.version.release = nil
40
40
  end
41
41
 
42
42
  def read_definition
43
- appliance_configs, appliance_config = ApplianceHelper.new(:log => @log).read_definitions(@appliance_definition_file)
44
- appliance_config_helper = ApplianceConfigHelper.new(appliance_configs)
43
+ begin
44
+ # first try to read as appliance definition file
45
+ appliance_configs, appliance_config = ApplianceHelper.new(:log => @log).read_definitions(@appliance_definition_file)
46
+ rescue
47
+ # then try to read OS plugin specific format
48
+ PluginManager.instance.plugins[:os].each_value do |info|
49
+ plugin = info[:class].new
50
+ appliance_config = plugin.read_file(@appliance_definition_file) if plugin.respond_to?(:read_file)
51
+ break unless appliance_config.nil?
52
+ end
53
+ appliance_configs = [appliance_config]
54
+ end
45
55
 
46
- @appliance_config = appliance_config_helper.merge(appliance_config.clone.init_arch).initialize_paths
56
+ raise "Couldn't read appliance definition file: #{File.basename(@appliance_definition_file)}" if appliance_config.nil?
57
+
58
+ appliance_config_helper = ApplianceConfigHelper.new(appliance_configs)
59
+ @appliance_config = appliance_config_helper.merge(appliance_config.clone.init_arch).initialize_paths
47
60
  end
48
61
 
49
62
  def validate_definition
50
63
  ApplianceConfigValidator.new(@appliance_config).validate
51
64
 
52
- 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?
65
+ abort "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?
53
66
 
54
67
  os_plugin = PluginManager.instance.plugins[:os][@appliance_config.os.name.to_sym]
55
68
 
56
- 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?
57
- 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)
69
+ abort "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?
70
+ abort "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)
58
71
  end
59
72
 
60
73
  def remove_old_builds
@@ -66,10 +79,7 @@ module BoxGrinder
66
79
  def execute_plugin_chain
67
80
  @log.info "Building '#{@appliance_config.name}' appliance for #{@appliance_config.hardware.arch} architecture."
68
81
 
69
- base_plugin_output = execute_os_plugin
70
- platform_plugin_output = execute_platform_plugin(base_plugin_output)
71
-
72
- execute_delivery_plugin(platform_plugin_output)
82
+ execute_delivery_plugin(execute_platform_plugin(execute_os_plugin))
73
83
  end
74
84
 
75
85
  def create
@@ -96,7 +106,7 @@ module BoxGrinder
96
106
  end
97
107
 
98
108
  @log.debug "Executing operating system plugin for #{@appliance_config.os.name}..."
99
- os_plugin.run
109
+ os_plugin.run(@appliance_definition_file)
100
110
  @log.debug "Operating system plugin executed."
101
111
 
102
112
  {:deliverables => os_plugin.deliverables, :plugin_info => os_plugin_info}
@@ -62,6 +62,7 @@ module BoxGrinder
62
62
  end
63
63
 
64
64
  @guestfs.aug_save
65
+ @guestfs.aug_close
65
66
 
66
67
  @log.debug "Augeas changes saved."
67
68
  end
@@ -25,8 +25,8 @@ require 'rbconfig'
25
25
  module BoxGrinder
26
26
  class SilencerProxy
27
27
  def initialize(o, destination)
28
- @o = o
29
- @destination = destination
28
+ @o = o
29
+ @destination = destination
30
30
  end
31
31
 
32
32
  def method_missing(m, *args, &block)
@@ -82,7 +82,7 @@ module BoxGrinder
82
82
  class GuestFSHelper
83
83
  def initialize(raw_disk, options = {})
84
84
  @raw_disk = raw_disk
85
- @log = options[:log] || Logger.new(STDOUT)
85
+ @log = options[:log] || Logger.new(STDOUT)
86
86
 
87
87
  @partitions = {}
88
88
  end
@@ -145,8 +145,11 @@ module BoxGrinder
145
145
  @guestfs.set_verbose(1)
146
146
  @guestfs.set_trace(1)
147
147
 
148
+ @log.trace "Enabling SElinux support in guestfs..."
149
+ @guestfs.set_selinux(1)
150
+
148
151
  unless hw_virtualization_available?
149
- qemu_wrapper = (RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? "/usr/bin/qemu-system-x86_64" : "/usr/bin/qemu")
152
+ qemu_wrapper = (RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? "/usr/bin/qemu-system-x86_64" : "/usr/bin/qemu")
150
153
 
151
154
  if File.exists?(qemu_wrapper)
152
155
  @log.trace "Setting QEMU wrapper to #{qemu_wrapper}..."
@@ -176,11 +179,30 @@ module BoxGrinder
176
179
  mount_partitions
177
180
  end
178
181
 
182
+ load_selinux_policy
183
+
179
184
  @log.trace "Guestfs launched."
180
185
 
181
186
  self
182
187
  end
183
188
 
189
+ def load_selinux_policy
190
+ return unless @guestfs.exists('/etc/sysconfig/selinux') != 0
191
+
192
+ @log.trace "Loading SElinux policy..."
193
+
194
+ @guestfs.aug_init("/", 32)
195
+ @guestfs.aug_rm("/augeas/load//incl[. != '/etc/sysconfig/selinux']")
196
+ @guestfs.aug_load
197
+
198
+ selinux = @guestfs.aug_get("/files/etc/sysconfig/selinux/SELINUX")
199
+
200
+ @guestfs.sh("/usr/sbin/load_policy") if !selinux.nil? and !selinux.eql?('disabled')
201
+ @guestfs.aug_close
202
+
203
+ @log.trace "SElinux policy loaded."
204
+ end
205
+
184
206
  def clean_close
185
207
  @log.trace "Closing guestfs..."
186
208
 
@@ -117,7 +117,7 @@ module BoxGrinder
117
117
 
118
118
  def sync_files(from_dir, to_dir)
119
119
  @log.debug "Syncing files between #{from_dir} and #{to_dir}..."
120
- @exec_helper.execute "rsync -u -r -a #{from_dir}/* #{to_dir}"
120
+ @exec_helper.execute "rsync -Xura #{from_dir}/* #{to_dir}"
121
121
  @log.debug "Sync finished."
122
122
  end
123
123
 
@@ -27,25 +27,26 @@ module BoxGrinder
27
27
  @exec_helper = options[:exec_helper] || ExecHelper.new({:log => @log})
28
28
  end
29
29
 
30
- def package(deliverables, package, type = :tar)
31
- files = []
32
-
33
- deliverables.each_value do |file|
34
- files << File.basename(file)
35
- end
36
-
30
+ def package(dir, package, type = :tar)
37
31
  if File.exists?(package)
38
32
  @log.info "Package of #{type} type for #{@appliance_config.name} appliance already exists, skipping."
39
33
  return package
40
34
  end
41
35
 
42
- FileUtils.mkdir_p(File.dirname(package))
43
-
44
36
  @log.info "Packaging #{@appliance_config.name} appliance to #{type}..."
45
37
 
46
38
  case type
47
39
  when :tar
48
- @exec_helper.execute "tar -C #{File.dirname(deliverables[:disk])} -cvzf '#{package}' #{files.join(' ')}"
40
+ package_name = File.basename(package, '.tgz')
41
+ symlink = "#{File.dirname(package)}/#{package_name}"
42
+
43
+ FileUtils.ln_s(File.expand_path(dir), symlink)
44
+
45
+ Dir.chdir(File.dirname(package)) do
46
+ @exec_helper.execute "tar -hcvzf #{package_name}.tgz #{package_name}"
47
+ end
48
+
49
+ FileUtils.rm(symlink)
49
50
  else
50
51
  raise "Only tar format is currently supported."
51
52
  end
@@ -58,9 +58,8 @@ module BoxGrinder
58
58
  @log.trace "Requiring plugin '#{plugin}'..."
59
59
 
60
60
  begin
61
- gem plugin
62
61
  require plugin
63
- rescue Gem::LoadError
62
+ rescue LoadError
64
63
  @log.warn "Specified gem: '#{plugin}' wasn't found. Make sure its name is correct, skipping..." unless plugin.match(/^boxgrinder-build-(.*)-plugin/)
65
64
  end
66
65
  end
@@ -27,34 +27,35 @@ require 'logger'
27
27
 
28
28
  module BoxGrinder
29
29
  class BasePlugin
30
- def init(config, appliance_config, options = {})
31
- @config = config
32
- @appliance_config = appliance_config
33
- @options = options
34
-
35
- @log = options[:log] || Logger.new(STDOUT)
36
- @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
37
- @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
38
-
39
- @plugin_info = options[:plugin_info]
40
- @previous_plugin_info = options[:previous_plugin_info]
30
+ def initialize
31
+ @plugin_config = {}
41
32
 
42
- @previous_deliverables = options[:previous_deliverables] || {}
43
- @plugin_config = {}
33
+ @deliverables = OpenCascade.new
34
+ @supported_oses = OpenCascade.new
35
+ @target_deliverables = OpenCascade.new
36
+ @dir = OpenCascade.new
37
+ end
44
38
 
45
- @deliverables = OpenCascade.new
46
- @supported_oses = OpenCascade.new
47
- @target_deliverables = OpenCascade.new
48
- @dir = OpenCascade.new
39
+ def init(config, appliance_config, options = {})
40
+ @config = config
41
+ @appliance_config = appliance_config
42
+ @options = options
43
+ @log = options[:log] || Logger.new(STDOUT)
44
+ @exec_helper = options[:exec_helper] || ExecHelper.new(:log => @log)
45
+ @image_helper = options[:image_helper] || ImageHelper.new(@config, @appliance_config, :log => @log)
46
+ @plugin_info = options[:plugin_info]
47
+ @previous_plugin_info = options[:previous_plugin_info]
48
+ @previous_deliverables = options[:previous_deliverables] || {}
49
49
 
50
- @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
51
- @dir.tmp = "#{@dir.base}/tmp"
50
+ @dir.base = "#{@appliance_config.path.build}/#{@plugin_info[:name]}-plugin"
51
+ @dir.tmp = "#{@dir.base}/tmp"
52
52
 
53
- @config_file = "#{ENV['HOME']}/.boxgrinder/plugins/#{@plugin_info[:name]}"
53
+ @config_file = "#{ENV['HOME']}/.boxgrinder/plugins/#{@plugin_info[:name]}"
54
54
 
55
55
  read_plugin_config
56
56
 
57
- @initialized = true
57
+ @move_deliverables = true
58
+ @initialized = true
58
59
 
59
60
  after_init
60
61
 
@@ -66,8 +67,8 @@ module BoxGrinder
66
67
  raise "Please specify deliverables as Hash, not #{deliverable.class}." unless deliverable.is_a?(Hash)
67
68
 
68
69
  deliverable.each do |name, path|
69
- @deliverables[name] = "#{@dir.tmp}/#{path}"
70
- @target_deliverables[name] = "#{@dir.base}/#{path}"
70
+ @deliverables[name] = "#{@dir.tmp}/#{path}"
71
+ @target_deliverables[name] = "#{@dir.base}/#{path}"
71
72
  end
72
73
  end
73
74
 
@@ -134,7 +135,7 @@ module BoxGrinder
134
135
  @deliverables.each do |name, path|
135
136
  @log.trace "Moving '#{path}' deliverable to target destination '#{@target_deliverables[name]}'..."
136
137
  FileUtils.mv(path, @target_deliverables[name])
137
- end
138
+ end if @move_deliverables
138
139
 
139
140
  FileUtils.rm_rf @dir.tmp
140
141
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Summary: A tool for creating appliances from simple plain text files
7
7
  Name: rubygem-%{gemname}
8
- Version: 0.6.5
8
+ Version: 0.7.0
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
@@ -14,14 +14,14 @@ Source0: http://rubygems.org/gems/%{gemname}-%{version}.gem
14
14
 
15
15
  Requires: ruby(abi) = %{rubyabi}
16
16
  Requires: rubygem(commander)
17
- Requires: rubygem(boxgrinder-core)
17
+ Requires: rubygem(boxgrinder-core) >= 0.1.5
18
18
  Requires: ruby-libguestfs
19
19
  Requires: parted
20
20
  Requires: e2fsprogs
21
21
 
22
22
  BuildRequires: rubygem(rake)
23
23
  BuildRequires: rubygem(rspec)
24
- BuildRequires: rubygem(boxgrinder-core)
24
+ BuildRequires: rubygem(boxgrinder-core) >= 0.1.5
25
25
  BuildRequires: rubygem(echoe)
26
26
  BuildRequires: ruby-libguestfs
27
27
 
@@ -85,6 +85,14 @@ popd
85
85
  %{gemdir}/doc/%{gemname}-%{version}
86
86
 
87
87
  %changelog
88
+ * Fri Dec 17 2010 <mgoldman@redhat.com> - 0.7.0-1
89
+ - Updated to upstream version: 0.7.0
90
+ - [BGBUILD-113] Allow to specify supported file formats for operating system plugin
91
+ - [BGBUILD-73] Add support for kickstart files
92
+ - [BGBUILD-80] VMware .tgz Bundle Should Expand Into Subdirectory, Not Current Directory
93
+ - [BGBUILD-118] Enable SElinux in guestfs
94
+ - [BGBUILD-119] Fix SElinux issues on EC2 appliances
95
+
88
96
  * Thu Dec 02 2010 <mgoldman@redhat.com> - 0.6.5-1
89
97
  - Updated to new upstream release: 0.6.5
90
98
 
@@ -23,18 +23,18 @@ require 'logger'
23
23
 
24
24
  module BoxGrinder
25
25
  describe Appliance do
26
- def prepare_appliance(options = OpenStruct.new)
27
- options.name = 'boxgrinder'
26
+ def prepare_appliance(options = OpenStruct.new, definition_file = "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl")
27
+ options.name = 'boxgrinder'
28
28
  options.version = '1.0'
29
29
 
30
- @options = options
31
- @log = Logger.new('/dev/null')
30
+ @options = options
31
+ @log = Logger.new('/dev/null')
32
32
 
33
33
  @plugin_manager = mock(PluginManager)
34
34
 
35
35
  PluginManager.stub!(:instance).and_return(@plugin_manager)
36
36
 
37
- @appliance = Appliance.new("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl", :log => @log, :options => @options)
37
+ @appliance = Appliance.new(definition_file, :log => @log, :options => @options)
38
38
  end
39
39
 
40
40
  def prepare_appliance_config
@@ -51,13 +51,13 @@ module BoxGrinder
51
51
  OpenCascade.new({
52
52
  :partitions =>
53
53
  {
54
- '/' => {'size' => 2},
54
+ '/' => {'size' => 2},
55
55
  '/home' => {'size' => 3},
56
56
  },
57
- :arch => 'i686',
58
- :base_arch => 'i386',
59
- :cpus => 1,
60
- :memory => 256,
57
+ :arch => 'i686',
58
+ :base_arch => 'i386',
59
+ :cpus => 1,
60
+ :memory => 256,
61
61
  })
62
62
  )
63
63
 
@@ -100,27 +100,84 @@ module BoxGrinder
100
100
  @appliance.create
101
101
  end
102
102
 
103
- it "should read definition" do
104
- prepare_appliance
103
+ describe ".validate_definition" do
104
+ it "should read definition with standard appliance definition file" do
105
+ prepare_appliance
106
+
107
+ appliance_config = ApplianceConfig.new
108
+
109
+ appliance_helper = mock(ApplianceHelper)
110
+ appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl").and_return([{}, appliance_config])
111
+
112
+ ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper)
113
+
114
+ appliance_config_helper = mock(ApplianceConfigHelper)
115
+
116
+ appliance_config.should_receive(:clone).and_return(appliance_config)
117
+ appliance_config.should_receive(:init_arch).and_return(appliance_config)
118
+ appliance_config.should_receive(:initialize_paths).and_return(appliance_config)
119
+
120
+ appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config)
121
+
122
+ ApplianceConfigHelper.should_receive(:new).with({}).and_return(appliance_config_helper)
123
+
124
+ @appliance.read_definition
125
+ end
126
+
127
+ it "should read definition with kickstart appliance definition file" do
128
+ prepare_appliance(OpenStruct.new, "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks")
129
+
130
+ appliance_config = ApplianceConfig.new
131
+
132
+ appliance_helper = mock(ApplianceHelper)
133
+ appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks").and_raise("Unknown format")
134
+
135
+ clazz = mock('PluginClass')
105
136
 
106
- appliance_config = ApplianceConfig.new
137
+ plugin_manager = mock(PluginManager)
138
+ plugin_manager.should_receive(:plugins).and_return({:os => {:fedora => {:class => clazz, :type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}}})
139
+
140
+ plugin = mock('Plugin')
141
+ plugin.should_receive(:respond_to?).with(:read_file).and_return(true)
142
+ plugin.should_receive(:read_file).and_return(appliance_config)
143
+
144
+ clazz.should_receive(:new).and_return(plugin)
145
+
146
+ PluginManager.should_receive(:instance).and_return(plugin_manager)
147
+
148
+ ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper)
149
+
150
+ appliance_config_helper = mock(ApplianceConfigHelper)
151
+
152
+ appliance_config.should_receive(:clone).and_return(appliance_config)
153
+ appliance_config.should_receive(:init_arch).and_return(appliance_config)
154
+ appliance_config.should_receive(:initialize_paths).and_return(appliance_config)
155
+
156
+ appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config)
107
157
 
108
- appliance_helper = mock(ApplianceHelper)
109
- appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.appl").and_return([{}, appliance_config])
158
+ ApplianceConfigHelper.should_receive(:new).with([appliance_config]).and_return(appliance_config_helper)
110
159
 
111
- ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper)
160
+ @appliance.read_definition
161
+ end
162
+
163
+ it "should read definition with kickstart appliance definition file and fail because there was no plugin able to read .ks" do
164
+ prepare_appliance(OpenStruct.new, "#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks")
112
165
 
113
- appliance_config_helper = mock(ApplianceConfigHelper)
166
+ appliance_helper = mock(ApplianceHelper)
167
+ appliance_helper.should_receive(:read_definitions).with("#{File.dirname(__FILE__)}/rspec/src/appliances/jeos-f13.ks").and_raise("Unknown format")
168
+
169
+ plugin_manager = mock(PluginManager)
170
+ plugin_manager.should_receive(:plugins).and_return({:os => {}})
114
171
 
115
- appliance_config.should_receive(:clone).and_return(appliance_config)
116
- appliance_config.should_receive(:init_arch).and_return(appliance_config)
117
- appliance_config.should_receive(:initialize_paths).and_return(appliance_config)
118
172
 
119
- appliance_config_helper.should_receive(:merge).with(appliance_config).and_return(appliance_config)
173
+ PluginManager.should_receive(:instance).and_return(plugin_manager)
120
174
 
121
- ApplianceConfigHelper.should_receive(:new).with({}).and_return(appliance_config_helper)
175
+ ApplianceHelper.should_receive(:new).with(:log => @log).and_return(appliance_helper)
122
176
 
123
- @appliance.read_definition
177
+ lambda {
178
+ @appliance.read_definition
179
+ }.should raise_error("Couldn't read appliance definition file: jeos-f13.ks")
180
+ end
124
181
  end
125
182
 
126
183
  describe ".validate_definition" do
@@ -133,8 +190,6 @@ module BoxGrinder
133
190
 
134
191
  ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
135
192
 
136
- puts @appliance_config
137
-
138
193
  plugin_manager = mock(PluginManager)
139
194
  plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["11", "12", "13", "14", "rawhide"]}}})
140
195
 
@@ -157,12 +212,9 @@ module BoxGrinder
157
212
 
158
213
  PluginManager.stub!(:instance).and_return(plugin_manager)
159
214
 
160
- begin
215
+ lambda {
161
216
  @appliance.validate_definition
162
- raise "Shouldn't raise"
163
- rescue => e
164
- e.message.should == "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"
165
- end
217
+ }.should raise_error(SystemExit, "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")
166
218
  end
167
219
 
168
220
  it "should validate definition and fail because no supported operating system plugins is installed" do
@@ -174,19 +226,14 @@ module BoxGrinder
174
226
 
175
227
  ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
176
228
 
177
- puts @appliance_config
178
-
179
229
  plugin_manager = mock(PluginManager)
180
230
  plugin_manager.stub!(:plugins).and_return({:os => {:rhel => {}}})
181
231
 
182
232
  PluginManager.stub!(:instance).and_return(plugin_manager)
183
233
 
184
- begin
234
+ lambda {
185
235
  @appliance.validate_definition
186
- raise "Shouldn't raise"
187
- rescue => e
188
- e.message.should == "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: rhel"
189
- end
236
+ }.should raise_error(SystemExit, "Not supported operating system selected: fedora. Make sure you have installed right operating system plugin, see http://community.jboss.org/docs/DOC-15214. Supported OSes are: rhel")
190
237
  end
191
238
 
192
239
  it "should validate definition and fail because no supported operating system version plugins is installed" do
@@ -198,19 +245,14 @@ module BoxGrinder
198
245
 
199
246
  ApplianceConfigValidator.should_receive(:new).with(@appliance_config).and_return(appliance_config_validator)
200
247
 
201
- puts @appliance_config
202
-
203
248
  plugin_manager = mock(PluginManager)
204
249
  plugin_manager.stub!(:plugins).and_return({:os => {:fedora => {:type => :os, :name => :fedora, :full_name => "Fedora", :versions => ["xyz"]}}})
205
250
 
206
251
  PluginManager.stub!(:instance).and_return(plugin_manager)
207
252
 
208
- begin
253
+ lambda {
209
254
  @appliance.validate_definition
210
- raise "Shouldn't raise"
211
- rescue => e
212
- e.message.should == "Not supported operating system version selected: 11. Supported versions are: xyz"
213
- end
255
+ }.should raise_error(SystemExit, "Not supported operating system version selected: 11. Supported versions are: xyz")
214
256
  end
215
257
  end
216
258
 
@@ -44,6 +44,7 @@ module BoxGrinder
44
44
  @guestfs.should_receive(:aug_load)
45
45
  @guestfs.should_receive(:aug_set).with("/files/etc/ssh/sshd_config/UseDNS", "no")
46
46
  @guestfs.should_receive(:aug_save)
47
+ @guestfs.should_receive(:aug_close)
47
48
 
48
49
  @helper.edit do
49
50
  set('/etc/ssh/sshd_config', 'UseDNS', 'no')
@@ -61,6 +62,7 @@ module BoxGrinder
61
62
  @guestfs.should_receive(:aug_set).with("/files/etc/ssh/sshd_config/UseDNS", "no")
62
63
  @guestfs.should_receive(:aug_set).with("/files/etc/sysconfig/selinux/SELINUX", "permissive")
63
64
  @guestfs.should_receive(:aug_save)
65
+ @guestfs.should_receive(:aug_close)
64
66
 
65
67
  @helper.edit do
66
68
  set('/etc/ssh/sshd_config', 'UseDNS', 'no')
@@ -78,6 +80,7 @@ module BoxGrinder
78
80
  @guestfs.should_receive(:aug_load)
79
81
  @guestfs.should_receive(:aug_set).with("/files/etc/ssh/sshd_config/UseDNS", "no")
80
82
  @guestfs.should_receive(:aug_save)
83
+ @guestfs.should_receive(:aug_close)
81
84
 
82
85
  @helper.edit do
83
86
  set('/etc/ssh/sshd_config', 'UseDNS', 'no')
@@ -94,6 +97,7 @@ module BoxGrinder
94
97
  @guestfs.should_receive(:aug_load)
95
98
  @guestfs.should_receive(:aug_set).with("/files/etc/ssh/sshd_config/UseDNS", "no")
96
99
  @guestfs.should_receive(:aug_save)
100
+ @guestfs.should_receive(:aug_close)
97
101
 
98
102
  @helper.edit do
99
103
  set('/etc/ssh/sshd_config', 'UseDNS', 'no')
@@ -26,7 +26,7 @@ module BoxGrinder
26
26
  end
27
27
 
28
28
  before(:each) do
29
- @log = Logger.new('/dev/null')
29
+ @log = Logger.new('/dev/null')
30
30
  @helper = GuestFSHelper.new('a/raw/disk', :log => @log)
31
31
  end
32
32
 
@@ -35,8 +35,10 @@ module BoxGrinder
35
35
  guetfs.should_receive(:set_append).with('noapic')
36
36
  guetfs.should_receive(:set_verbose)
37
37
  guetfs.should_receive(:set_trace)
38
+ guetfs.should_receive(:set_selinux).with(1)
38
39
 
39
40
  @helper.should_receive(:hw_virtualization_available?).and_return(true)
41
+ @helper.should_receive(:load_selinux_policy)
40
42
 
41
43
  guetfs.should_receive(:set_qemu).with(wrapper) unless wrapper.nil?
42
44
  guetfs.should_receive(:add_drive).with('a/raw/disk')
@@ -190,5 +192,37 @@ module BoxGrinder
190
192
  @helper.hw_virtualization_available?.should == false
191
193
  end
192
194
  end
195
+
196
+ describe ".load_selinux_policy" do
197
+ it "should load SElinux policy for SElinux enabled guests" do
198
+ guestfs = mock('Guestfs')
199
+ @helper.instance_variable_set(:@guestfs, guestfs)
200
+
201
+ guestfs.should_receive(:exists).with('/etc/sysconfig/selinux').and_return(1)
202
+ guestfs.should_receive(:aug_init).with("/", 32)
203
+ guestfs.should_receive(:aug_rm).with("/augeas/load//incl[. != '/etc/sysconfig/selinux']")
204
+ guestfs.should_receive(:aug_load)
205
+ guestfs.should_receive(:aug_get).with("/files/etc/sysconfig/selinux/SELINUX").and_return('permissive')
206
+ guestfs.should_receive(:sh).with("/usr/sbin/load_policy")
207
+ guestfs.should_receive(:aug_close)
208
+
209
+ @helper.load_selinux_policy
210
+ end
211
+
212
+ it "should not load SElinux policy for SElinux disabled guests" do
213
+ guestfs = mock('Guestfs')
214
+ @helper.instance_variable_set(:@guestfs, guestfs)
215
+
216
+ guestfs.should_receive(:exists).with('/etc/sysconfig/selinux').and_return(1)
217
+ guestfs.should_receive(:aug_init).with("/", 32)
218
+ guestfs.should_receive(:aug_rm).with("/augeas/load//incl[. != '/etc/sysconfig/selinux']")
219
+ guestfs.should_receive(:aug_load)
220
+ guestfs.should_receive(:aug_get).with("/files/etc/sysconfig/selinux/SELINUX").and_return('disabled')
221
+ guestfs.should_not_receive(:sh).with("/usr/sbin/load_policy")
222
+ guestfs.should_receive(:aug_close)
223
+
224
+ @helper.load_selinux_policy
225
+ end
226
+ end
193
227
  end
194
228
  end
@@ -149,7 +149,7 @@ module BoxGrinder
149
149
 
150
150
 
151
151
  it "should sync files" do
152
- @exec_helper.should_receive(:execute).with("rsync -u -r -a from_dir/* to_dir")
152
+ @exec_helper.should_receive(:execute).with("rsync -Xura from_dir/* to_dir")
153
153
 
154
154
  @helper.sync_files('from_dir', 'to_dir')
155
155
  end
@@ -27,7 +27,7 @@ module BoxGrinder
27
27
  end
28
28
 
29
29
  before(:each) do
30
- @plugin_helper = PluginHelper.new( :options => OpenStruct.new )
30
+ @plugin_helper = PluginHelper.new(:options => OpenStruct.new)
31
31
  end
32
32
 
33
33
  it "should parse plugin list and return empty array when no plugins are provided" do
@@ -35,23 +35,22 @@ module BoxGrinder
35
35
  end
36
36
 
37
37
  it "should parse plugin list with double quotes" do
38
- @plugin_helper = PluginHelper.new( :options => OpenStruct.new( :plugins => '"abc,def"' ) )
38
+ @plugin_helper = PluginHelper.new(:options => OpenStruct.new(:plugins => '"abc,def"'))
39
39
  @plugin_helper.parse_plugin_list.should == ['abc', 'def']
40
40
  end
41
41
 
42
42
  it "should parse plugin list with single quotes" do
43
- @plugin_helper = PluginHelper.new( :options => OpenStruct.new( :plugins => "'abc,def'" ) )
43
+ @plugin_helper = PluginHelper.new(:options => OpenStruct.new(:plugins => "'abc,def'"))
44
44
  @plugin_helper.parse_plugin_list.should == ['abc', 'def']
45
45
  end
46
46
 
47
47
  it "should parse plugin list with single quotes and clean up it" do
48
- @plugin_helper = PluginHelper.new( :options => OpenStruct.new( :plugins => "' abc , def'" ) )
48
+ @plugin_helper = PluginHelper.new(:options => OpenStruct.new(:plugins => "' abc , def'"))
49
49
  @plugin_helper.parse_plugin_list.should == ['abc', 'def']
50
50
  end
51
51
 
52
52
  it "should require default plugins" do
53
53
  @plugin_array.each do |plugin|
54
- @plugin_helper.should_receive(:gem).ordered.with(plugin)
55
54
  @plugin_helper.should_receive(:require).once.with(plugin)
56
55
  end
57
56
 
@@ -59,16 +58,13 @@ module BoxGrinder
59
58
  end
60
59
 
61
60
  it "should read plugins specified in command line" do
62
- @plugin_helper = PluginHelper.new( :options => OpenStruct.new( :plugins => 'abc,def' ) )
61
+ @plugin_helper = PluginHelper.new(:options => OpenStruct.new(:plugins => 'abc,def'))
63
62
 
64
63
  @plugin_array.each do |plugin|
65
- @plugin_helper.should_receive(:gem).ordered.with(plugin)
66
64
  @plugin_helper.should_receive(:require).once.with(plugin)
67
65
  end
68
66
 
69
- @plugin_helper.should_receive(:gem).ordered.with('abc')
70
67
  @plugin_helper.should_receive(:require).ordered.with('abc')
71
- @plugin_helper.should_receive(:gem).ordered.with('def')
72
68
  @plugin_helper.should_receive(:require).ordered.with('def')
73
69
 
74
70
  @plugin_helper.read_and_require
@@ -0,0 +1,23 @@
1
+ # bg_os_name: fedora
2
+ # bg_os_version: 13
3
+
4
+ lang en_US.UTF-8
5
+ keyboard us
6
+ timezone US/Eastern
7
+ auth --useshadow --enablemd5
8
+ selinux --permissive
9
+ firewall --disabled
10
+ bootloader --timeout=1 --append="acpi=force scsi_mod.scan=sync"
11
+ firstboot --disabled
12
+ network --bootproto=dhcp --device=eth0 --onboot=on
13
+ services --enabled=network
14
+ rootpw boxgrinder
15
+
16
+ part / --size 2048 --fstype ext4 --ondisk sda
17
+
18
+ repo --name=fedora-14-base --cost=40 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-13&arch=x86_64
19
+ repo --name=fedora-14-updates --cost=41 --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f13&arch=x86_64
20
+
21
+ %packages --excludedocs --nobase
22
+ @core
23
+ %end
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: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 5
10
- version: 0.6.5
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
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: 2010-12-03 00:00:00 +01:00
18
+ date: 2010-12-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- hash: 19
45
+ hash: 17
46
46
  segments:
47
47
  - 0
48
48
  - 1
49
- - 4
50
- version: 0.1.4
49
+ - 5
50
+ version: 0.1.5
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  description: A tool for creating appliances from simple plain text files for various virtual environments.
@@ -102,6 +102,7 @@ files:
102
102
  - spec/managers/plugin-manager-spec.rb
103
103
  - spec/plugins/base-plugin-spec.rb
104
104
  - spec/rspec/src/appliances/jeos-f13.appl
105
+ - spec/rspec/src/appliances/jeos-f13.ks
105
106
  has_rdoc: true
106
107
  homepage: http://www.jboss.org/boxgrinder
107
108
  licenses: []