Browse files

got some real test running again

  • Loading branch information...
1 parent df94ff5 commit 334a8dc1c05140324fe119247d987596a586a840 @jedi4ever committed Sep 29, 2011
Showing with 101 additions and 96 deletions.
  1. +0 −7 Rakefile
  2. +19 −13 lib/veewee/builder/core/builder/build.rb
  3. +49 −48 lib/veewee/definition.rb
  4. +33 −28 test/build_test.rb
View
7 Rakefile
@@ -23,13 +23,6 @@ Rake::TestTask.new do |t|
t.pattern = 'test/**/*_realtest.rb'
end
-desc 'Tests requiring an real box'
-Rake::TestTask.new do |t|
- t.name="realtest"
- t.libs << "test"
- t.pattern = 'test/**/*_realtest.rb'
-end
-
desc 'Verify ISO'
task :iso, [:box_name] do |t,args|
require 'net/http'
View
32 lib/veewee/builder/core/builder/build.rb
@@ -101,15 +101,19 @@ def filter_postinstall_files(definition,options)
new_definition=definition.clone
env.logger.info "Applying the postinstall excludes"
- options["postinstall_exclude"].each do |p|
- env.logger.info "Exclude pattern #{p}"
- new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^/,"_"): f}
+ unless options["postinstall_exclude"].nil?
+ options["postinstall_exclude"].each do |p|
+ env.logger.info "Exclude pattern #{p}"
+ new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^/,"_"): f}
+ end
end
env.logger.info "Applying the postinstall includes"
- options["postinstall_include"].each do |p|
- env.logger.info "Include pattern #{p}"
- new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^_/,""): f}
+ unless options["postinstall_include"].nil?
+ options["postinstall_include"].each do |p|
+ env.logger.info "Include pattern #{p}"
+ new_definition.postinstall_files.collect! { |f| f.match(p) ? f.gsub(/^_/,""): f}
+ end
end
env.logger.info "filtered postinstall files:"
@@ -158,13 +162,15 @@ def handle_kickstart(definition)
end
# For each kickstart file spinup a webserver and wait for the file to be fetched
- kickstartfiles.each do |kickfile|
- wait_for_http_request(kickfile,{
- :port => definition.kickstart_port,
- :host => definition.kickstart_ip,
- :timeout => definition.kickstart_timeout,
- :web_dir => definition.path
- })
+ unless kickstartfiles.nil?
+ kickstartfiles.each do |kickfile|
+ wait_for_http_request(kickfile,{
+ :port => definition.kickstart_port,
+ :host => definition.kickstart_ip,
+ :timeout => definition.kickstart_timeout,
+ :web_dir => definition.path
+ })
+ end
end
end
View
97 lib/veewee/definition.rb
@@ -5,94 +5,95 @@ class Definition
attr_accessor :name
attr_accessor :env
-
+
attr_accessor :cpu_count,:memory_size,:iso_file
attr_accessor :disk_size, :disk_format
-
+
attr_accessor :os_typ_id
-
+
attr_accessor :boot_wait,:boot_cmd_sequence
-
+
attr_accessor :kickstart_port,:kickstart_ip,:kickstart_timeout, :kickstart_file
- attr_accessor :ssh_login_timeout, :ssh_user , :ssh_password, :ssh_key, :ssh_host_port, :ssh_guest_port
-
+ attr_accessor :ssh_login_timeout, :ssh_user , :ssh_password, :ssh_key, :ssh_host_port, :ssh_guest_port
+
attr_accessor :sudo_cmd
attr_accessor :shutdown_cmd
attr_accessor :postinstall_files, :postinstall_timeout
-
+
attr_accessor :floppy_files
-
+
attr_accessor :path
-
+
attr_accessor :os_type_id,:use_hw_virt_ext,:use_pae,:hostiocache
-
+
attr_accessor :iso_dowload_timeout, :iso_src,:iso_md5 ,:iso_download_instructions
-
+
def initialize(name,env)
@name=name
@env=env
# Default is 1 CPU + 256 Mem of memory
- @cpu_count='1' ; @memory_size='256';
-
+ @cpu_count='1' ; @memory_size='256';
+
# Default there is no ISO file mounted
@iso_file = nil, @iso_src = nil ; @iso_md5 = nil ; @iso_download_timeout=1000 ; @iso_download_instructions = nil
-
+
# Default is no floppy mounted
@floppy_files = nil
-
+
# Default there are no post install files
@postinstall_files=[]; @postinstall_timeout = 10000;
@iso_file=""
@disk_size = '10240'; @disk_format = 'VDI'
-# :hostiocache => 'off' ,
-# :os_type_id => 'Ubuntu',
-# :boot_wait => "10", :boot_cmd_sequence => [ "boot"],
-# :kickstart_port => "7122", :kickstart_ip => "127.0.0.1", :kickstart_timeout => 10000,#
-# :ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant",:ssh_key => "",
-# :ssh_host_port => "2222", :ssh_guest_port => "22", :sudo_cmd => "echo '%p'|sudo -S sh '%f'",
-# :shutdown_cmd => "shutdown -h now",
-# :kickstart_file => nil,
+ # :hostiocache => 'off' ,
+ # :os_type_id => 'Ubuntu',
+ # :boot_wait => "10", :boot_cmd_sequence => [ "boot"],
+ # :kickstart_port => "7122", :kickstart_ip => "127.0.0.1", :kickstart_timeout => 10000,#
+ # :ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant",:ssh_key => "",
+ # :ssh_host_port => "2222", :ssh_guest_port => "22", :sudo_cmd => "echo '%p'|sudo -S sh '%f'",
+ # :shutdown_cmd => "shutdown -h now",
+ # :kickstart_file => nil,
end
-
+
def method_missing(m, *args, &block)
- env.logger.info "There's no attribute #{m} defined for builder #{@name}-- ignoring it"
+ env.logger.info "There's no attribute #{m} defined for builder #{@name}-- ignoring it"
end
-
- def declare(options)
+
+ def declare(options)
options.each do |key, value|
instance_variable_set("@#{key}".to_sym, options[key])
env.logger.info("definition") { " - #{key} : #{options[key]}" }
- end
+ end
verify_ostype
-
+
end
-
+
# Loading a definition
def self.load(name,env)
dir=env.get_definition_paths[name]
-
+
if dir.nil?
env.ui.error "Error loading definition."
+ env.ui.error "could not find the directory of definition #{name}"
exit -1
- end
-
+ end
+
veewee_definition=Veewee::Definition.new(name,env)
veewee_definition.path=dir
-
+
definition_file=File.join(dir,"definition.rb")
if File.exists?(definition_file)
definition_content=File.read(definition_file)
-
+
definition_content.gsub!("Veewee::Session.declare","veewee_definition.declare")
definition_content.gsub!("Veewee::Definition.declare","veewee_definition.declare")
@@ -102,20 +103,20 @@ def self.load(name,env)
cwd=FileUtils.pwd
FileUtils.cd(dir)
self.instance_eval(definition_content)
- env.logger.info("Setting definition path for definition #{name} to #{File.dirname(definition_file)}")
- FileUtils.cd(cwd)
- rescue NameError => ex
- env.ui.error("NameError reading definition from file #{definition_file} #{ex}")
- rescue Exception => ex
- env.ui.error("Error in the definition from file #{definition_file}\n#{ex}")
- exit -1
- end
- else
- env.logger.info "#{definition_file} not found"
- end
- veewee_definition
+ env.logger.info("Setting definition path for definition #{name} to #{File.dirname(definition_file)}")
+ FileUtils.cd(cwd)
+ rescue NameError => ex
+ env.ui.error("NameError reading definition from file #{definition_file} #{ex}")
+ rescue Exception => ex
+ env.ui.error("Error in the definition from file #{definition_file}\n#{ex}")
+ exit -1
+ end
+ else
+ env.logger.info "#{definition_file} not found"
+ end
+ veewee_definition
end
-
+
def verify_ostype
unless env.config.ostypes.has_key?(@os_type_id)
View
61 test/build_test.rb
@@ -3,43 +3,48 @@
class TestVeeweeBuild < Test::Unit::TestCase
def setup
- @ve=Veewee::Environment.new({:definition_dir => File.expand_path(File.join(File.dirname(__FILE__),"definitions")) })
+ definition_dir=File.expand_path(File.join(File.dirname(__FILE__),"definitions"))
+ puts definition_dir
+ @ve=Veewee::Environment.new({
+ :definition_path => [ definition_dir ],
+ :definition_dir => definition_dir
+ })
@definition_name="test_definition"
- @box_name="test_definition"
@vd=@ve.get_definition(@definition_name)
+ @box_name="test_definition"
@vd.postinstall_files=["_test_me.sh"]
end
def test_virtualbox_1_build
assert_nothing_raised {
- @ve.config.builders["virtualbox"].build(@definition_name,{})
- }
- end
-
- def test_virtualbox_2_ssh
- assert_nothing_raised {
- result=@ve.config.builders["virtualbox"].get_box(@box_name).ssh("who am i")
- assert_match(/root/,result.stdout)
- }
- end
-
- def test_virtualbox_3_console_type
- assert_nothing_raised {
- @ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).console_type('echo "bla" > console.txt<Enter>')
- result=@ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).ssh("cat console.txt")
- assert_match(/bla/,result.stdout)
- }
- end
-
- def test_virtualbox_4_destroy
- assert_nothing_raised {
- @ve.config.builders["virtualbox"].get_box(@vm_name,@vd,{}).destroy({})
+ @ve.config.builders["virtualbox"].build(@definition_name,@box_name,{"auto" => true,:force => true})
}
end
- def teardown
- #@ve.destroy(@vm_name,@vd)
-
- end
+# def test_virtualbox_2_ssh
+# assert_nothing_raised {
+# result=@ve.config.builders["virtualbox"].get_box(@box_name).ssh("who am i")
+# assert_match(/root/,result.stdout)
+# }
+# end
+#
+# def test_virtualbox_3_console_type
+# assert_nothing_raised {
+# @ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).console_type('echo "bla" > console.txt<Enter>')
+# result=@ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).ssh("cat console.txt")
+# assert_match(/bla/,result.stdout)
+# }
+# end
+#
+# def test_virtualbox_4_destroy
+# assert_nothing_raised {
+# @ve.config.builders["virtualbox"].get_box(@vm_name,@vd,{}).destroy({})
+# }
+# end
+#
+# def teardown
+# #@ve.destroy(@vm_name,@vd)
+#
+# end
end

0 comments on commit 334a8dc

Please sign in to comment.