Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reactived some test parts, corrected the Centos4-8 template

  • Loading branch information...
commit 42e8e48bd7828afe0a4e5f55e1c924f1626b7d67 1 parent c11f9aa
@jedi4ever authored
View
77 Rakefile
@@ -1,6 +1,7 @@
require 'rubygems'
require 'bundler'
require 'bundler/setup'
+require 'veewee'
Bundler::GemHelper.install_tasks
desc 'Default: run tests'
@@ -22,68 +23,22 @@ Rake::TestTask.new do |t|
t.pattern = 'test/**/*_realtest.rb'
end
-desc 'List templates'
-task :templates do
- Veewee::Environment.list_templates
-end
-
-desc 'Define box'
-task :define, [:box_name,:template_name] do |t,args|
- if args.to_hash.size!=2
- puts "needs two arguments: rake define['box_name','template_name']"
- exit
- end
- Veewee::Environment.define(args.box_name,args.template_name)
-end
-
-desc 'Undefine box'
-task :undefine, [:box_name] do |t,args|
- if args.to_hash.size!=1
- puts "needs one arguments: rake undefine[\"yourname\"]"
- exit
- end
- Veewee::Environment.undefine(args.box_name)
-end
-
-desc 'List Definitions'
-task :definitions do
- Veewee::Environment.list_definitions
+desc 'Tests requiring an real box'
+Rake::TestTask.new do |t|
+ t.name="realtest"
+ t.libs << "test"
+ t.pattern = 'test/**/*_realtest.rb'
end
-desc 'Build box'
-task :build, [:box_name] do |t,args|
- if args.to_hash.size!=1
- puts "needs one arguments: rake build['box_name']"
- exit
+desc 'Verify ISO'
+task :iso, [:box_name] do |t,args|
+ #if args.to_hash.size!=1
+ #puts "needs one arguments: rake iso [\"yourname\"]"
+ #exit
+ #end
+ Dir.glob("templates/*").each do |name|
+ definition_name=File.basename(name)
+ definition=Veewee::Environment.new(:cwd => ".",:definition_dir => "templates",:definition_path => "templates").get_definition(definition_name)
+ puts definition.iso_src
end
- Veewee::Environment.build(args.box_name)
-end
-
-desc 'List boxes'
-task :boxes do
- Veewee::Environment.list_boxes
-end
-
-desc 'Export box'
-task :export, [:box_name] do |t,args|
- if args.to_hash.size!=1
- puts "needs one arguments: rake export['box_name']"
- exit
- end
- Veewee::Environment.export_box(args.box_name)
-end
-
-desc 'Remove box'
-task :remove_box, [:box_name] do |t,args|
- Veewee::Environment.remove_box(args.box_name)
-end
-
-desc 'List ostypes available'
-task :list_ostypes do |t,args|
- Veewee::Environment.list_ostypes
-end
-
-desc 'Clean all unfinished builds'
-task :clean do
- Veewee::Environment.clean
end
View
8 lib/veewee/builder/core/builder/iso.rb
@@ -34,7 +34,7 @@ def hashsum(filename)
counter = 0
while (!io.eof)
readBuf = io.readpartial(buflen)
- env.ui.info '.' if ((counter+=1) % 20000 == 0)
+ env.ui.info('.',{:new_line => false}) if ((counter+=1) % 20000 == 0)
checksum.update(readBuf)
end
end
@@ -76,9 +76,9 @@ def verify_iso(definition,options)
answer="yes" if options["auto"]==true
env.logger.info "Auto download enabled?#{answer} #{!options['auto'].nil?}"
if answer.nil?
- answer=ask("Download? (Yes/No)") {|q| q.default="No"}
+ answer=env.ui.ask("Download? (Yes/No)") {|q| q.default="No"}
end
-
+
if answer.downcase == "yes"
if !File.exists?(env.config.veewee.iso_dir)
env.ui.info "Creating an iso directory"
@@ -98,7 +98,7 @@ def verify_iso(definition,options)
env.ui.info ""
exit
end
-
+
env.ui.info "Verifying md5 checksum : #{definition.iso_md5}"
file_md5=hashsum(full_path)
View
24 lib/veewee/builder/vmfusion/builder.rb
@@ -30,6 +30,30 @@ def ssh_options(definition)
return ssh_options
end
+ # Transfer information provide by the builder to the box
+ #
+ #
+ def transfer_buildinfo(box,definition)
+ super(box,definition)
+
+ begin
+ Veewee::Util::Ssh.when_ssh_login_works(box.ip_address,ssh_options(definition).merge({:timeout => definition.postinstall_timeout.to_i})) do
+ begin
+ env.logger.info "About to transfer vmware tools iso buildinfo to the box #{box.name} - #{box.ip_address} - #{ssh_options(definition)}"
+ Veewee::Util::Ssh.transfer_file(box.ip_address,"/Library/Application Support/VMware Fusion/isoimages/linux.iso","linux.iso",ssh_options(definition))
+ rescue RuntimeError => ex
+ env.ui.error "Error transfering vmware tools iso , possible not enough permissions to write? #{ex}"
+ exit -1
+ end
+ end
+ rescue Net::SSH::AuthenticationFailed
+ env.ui.error "Authentication failure"
+ exit -1
+ end
+
+ end
+
+
end #End Class
View
23 lib/veewee/builder/vmfusion/helper/create.rb
@@ -22,12 +22,33 @@ def create_disk(definition)
FileUtils.chdir(current_dir)
end
+ def fusion_os_type(type_id)
+ env.logger.info "Translating #{type_id} into fusion type"
+ types={
+ "ArchLinux" => "Linux",
+ "ArchLinux_64" => "Linux",
+ "RedHat"=> "centos",
+ "RedHat_64"=>"centos-64",
+ "RedHat"=>"centos",
+ "Ubuntu_64"=>"ubuntu-64",
+ "Ubuntu"=>"ubuntu",
+ "Fedora"=>"fedora",
+ "Fedora_64"=>"Fedora_64",
+ }
+ env.logger.info "Found fusion type #{types[type_id]}"
+ return types[type_id]
+ end
+
def create_vm(definition)
+ fusion_definition=definition.dup
+
+ fusion_definition.os_type_id=fusion_os_type(definition.os_type_id)
+
FileUtils.mkdir_p(vm_path)
current_dir=FileUtils.pwd
FileUtils.chdir(vm_path)
aFile = File.new(vmx_file_path, "w")
- aFile.write(vmx_template(definition))
+ aFile.write(vmx_template(fusion_definition))
aFile.close
FileUtils.chdir(current_dir)
end
View
1  lib/veewee/builder/vmfusion/helper/template.rb
@@ -17,6 +17,7 @@ def vmx_template(definition)
data = {
:cpu_count => definition.cpu_count, :memory_size => definition.memory_size,
:controller_type => "lsilogic",
+ :fusion_os_type => definition.os_type_id,
:mac_addres => "auto generated",
:iso_file => "#{File.join(env.config.veewee.iso_dir,definition.iso_file)}",
:box_name => name,
View
4 lib/veewee/builder/vmfusion/helper/template.vmx.erb
@@ -29,7 +29,7 @@ vmci0.present = "TRUE"
roamingVM.exitBehavior = "go"
tools.syncTime = "TRUE"
displayName = "<%= box_name %>"
-guestOS = "vmkernel"
+guestOS = "<%= fusion_os_type %>"
nvram = "<%= box_name %>.nvram"
virtualHW.productCompatibility = "hosted"
proxyApps.publishToHost = "FALSE"
@@ -79,4 +79,4 @@ ethernet0.displayName = "Ethernet"
sound.startConnected = "FALSE"
RemoteDisplay.vnc.enabled = "TRUE"
RemoteDisplay.vnc.port = "5920"
-#RemoteDisplay.vnc.key = "Cig8ARE7BS4KLhQ7GzIFIgwNGBIHNS04BwUCMiYiOhknOSstBQoqCBsYKCwbKgInFB89Cgs5FAMVAxERKiUdBzcXFxMiBTQEIRMENTkMOSwxMAwjGD8jOBwqKio4GQ8xOCYLDiYVCBMqFzMENAQ4BSMkJTUdFhQGOjg0BRUSNiY="
+#RemoteDisplay.vnc.key = "Cig8ARE7BS4KLhQ7GzIFIgwNGBIHNS04BwUCMiYiOhknOSstBQoqCBsYKCwbKgInFB89Cgs5FAMVAxERKiUdBzcXFxMiBTQEIRMENTkMOSwxMAwjGD8jOBwqKio4GQ8xOCYLDiYVCBMqFzMENAQ4BSMkJTUdFhQGOjg0BRUSNiY="
View
4 lib/veewee/command/kvm.rb
@@ -1,8 +1,6 @@
module Veewee
module Command
class Kvm< Veewee::Command::GroupBase
- register "kvm", "Subcommand for kvm"
-
register "kvm", "Subcommand for kvm"
desc "build [TEMPLATE_NAME] [BOX_NAME]", "Build box"
@@ -38,8 +36,8 @@ def define(definition_name, template_name)
desc "undefine [BOXNAME]", "Removes the definition of a basebox "
method_option :debug,:type => :boolean , :default => false, :aliases => "-d", :desc => "enable debugging"
def undefine(definition_name)
- begin
env.ui.info "Removing definition #{definition_name}"
+ begin
venv=Veewee::Environment.new(options)
venv.ui=env.ui
venv.undefine(definition_name,options)
View
2  lib/veewee/command/vmfusion.rb
@@ -75,7 +75,7 @@ def list
venv=Veewee::Environment.new(options)
venv.ui=env.ui
venv.get_definition_paths.keys.each do |name|
- env.ui.info "- #{name}",:prefix => false
+ env.ui.info "- #{name}"
end
end
View
21 lib/veewee/environment.rb
@@ -38,18 +38,22 @@ class Environment
def initialize(options={})
+ cwd= options.has_key?(:cwd) ? options[:cwd] : Dir.pwd
+
defaults={
- :cwd => Dir.pwd,
+ :cwd => cwd,
:veewee_filename => "Veeweefile",
:loglevel => :info,
- :definition_path => [File.join(Dir.pwd,"definitions")],
- :definition_dir => File.join(Dir.pwd,"definitions"),
+ :definition_path => [File.join(cwd,"definitions")],
+ :definition_dir => File.join(cwd,"definitions"),
:template_path => [File.expand_path(File.join(File.dirname(__FILE__),"..","..",'templates')),"templates"],
- :iso_dir => File.join(Dir.pwd,"iso"),
+ :iso_dir => File.join(cwd,"iso"),
:validation_dir => File.join(File.expand_path(File.join(File.dirname(__FILE__),"..","..")),"validation"),
- :tmp_dir => File.join(Dir.pwd,"tmp")
+ :tmp_dir => File.join(cwd,"tmp")
}
+ options = defaults.merge(options)
+
# We need to set this variable before the first call to the logger object
if options.has_key?("debug")
@@ -57,7 +61,6 @@ def initialize(options={})
ui.info "Debugging enabled"
end
- options = defaults.merge(options)
logger.info("environment") { "Environment initialized (#{self})" }
@@ -122,15 +125,15 @@ def get_template_paths
def list_ostypes
@ui.info "The following are possible os_types you can use in your definition.rb files"
-
+
require 'virtualbox'
os_types=VirtualBox::Global.global.lib.virtualbox.guest_os_types
-
+
os_types.each { |os|
@ui.info "#{os.id}: #{os.description}"
}
end
-
+
# This function returns a hash of names of all the definitions that are in the @definition_dir,
# given the @definition_dir in the current Environment object
# The name of the definition is the name of a sub-directory in the @definition_dir
View
4 templates/CentOS-4.8-i386/definition.rb
@@ -1,9 +1,9 @@
Veewee::Definition.declare({
- :cpu_count => '1', :memory_size=> '384',
+ :cpu_count => '1', :memory_size=> '384',
:disk_size => '10140', :disk_format => 'VDI',:hostiocache => 'off',:ioapic => 'on', :pae => 'on',
:os_type_id => 'RedHat',
:iso_file => "CentOS-4.8-i386-bin-DVD.iso", :iso_src => "", :iso_md5 => "", :iso_download_timeout => 1000,
- :iso_download_instructions => "This iso is no more available, for instructions see http://isoredirect.centos.org/centos/4/isos/i386/"
+ :iso_download_instructions => "This iso is no more available, for instructions see http://isoredirect.centos.org/centos/4/isos/i386/",
:boot_wait => "10", :boot_cmd_sequence => [ 'linux text ks=http://%IP%:%PORT%/ks.cfg<Enter>' ],
:kickstart_port => "7122", :kickstart_timeout => 10000, :kickstart_file => "ks.cfg",
:ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant", :ssh_key => "",
View
6 templates/archlinux-i386/definition.rb
@@ -1,5 +1,5 @@
Veewee::Definition.declare({
- :cpu_count => '1', :memory_size=> '256',
+ :cpu_count => '1', :memory_size=> '256',
:disk_size => '10140', :disk_format => 'VDI',:hostiocache => 'off',
:os_type_id => 'ArchLinux',
:iso_file => "archlinux-2010.05-core-i686.iso",
@@ -11,14 +11,14 @@
'<Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait>',
'<Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait>',
'<Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait><Wait>',
- 'root<Enter>',
+ 'root<Enter>',
'dhcpcd eth0<Enter><Wait><Wait>',
'echo "sshd: ALL" > /etc/hosts.allow<Enter>',
'passwd<Enter>',
'vagrant<Enter>',
'vagrant<Enter>',
'/etc/rc.d/sshd start<Enter><Wait>',
- 'sleep 3 && wget http://%IP%:%PORT%/aif.cfg<Enter>',
+ 'sleep 3 && wget http://%IP%:%PORT%/aif.cfg<Enter>',
],
:kickstart_port => "7122", :kickstart_timeout => "10000", :kickstart_file => "aif.cfg",
:ssh_login_timeout => "10000", :ssh_user => "root", :ssh_password => "vagrant", :ssh_key => "",
View
45 test.old/build_test.rb
@@ -0,0 +1,45 @@
+require 'test/unit'
+require 'lib/veewee'
+
+class TestVeeweeBuild < Test::Unit::TestCase
+ def setup
+ @ve=Veewee::Environment.new({:definition_dir => File.expand_path(File.join(File.dirname(__FILE__),"definitions")) })
+ template_name="test_definition"
+ @vm_name="test_definition"
+ @vd=@ve.get_definition(template_name)
+ @vd.postinstall_files=["_test_me.sh"]
+ end
+
+ def test_virtualbox_1_build
+ assert_nothing_raised {
+ @ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).build({})
+ }
+ end
+
+ def test_virtualbox_2_ssh
+ assert_nothing_raised {
+ result=@ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).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.builder(:virtualbox).get_box(@vm_name,@vd,{}).destroy({})
+ }
+ end
+
+ def teardown
+ #@ve.destroy(@vm_name,@vd)
+
+ end
+
+end
View
11 test.old/definition_test.rb
@@ -0,0 +1,11 @@
+require 'test/unit'
+require 'lib/veewee'
+
+class TestVeeweeDefinition < Test::Unit::TestCase
+ def test_environment_load_definition
+ # Set the definition dir to our template dir
+ ve=Veewee::Environment.new({:definition_path => [ File.expand_path(File.join(File.dirname(__FILE__),"..", "templates")) ] })
+ vd=ve.get_definition("ubuntu-10.10-server-amd64")
+ assert_equal(vd.os_type_id,"Ubuntu_64")
+ end
+end
View
0  test/definitions/test_definition/_test_me.sh → test.old/definitions/test_definition/_test_me.sh
File renamed without changes
View
0  test/definitions/test_definition/autorun0 → test.old/definitions/test_definition/autorun0
File renamed without changes
View
0  test/definitions/test_definition/definition.rb → test.old/definitions/test_definition/definition.rb
File renamed without changes
View
67 test.old/environment_test.rb
@@ -0,0 +1,67 @@
+require 'test/unit'
+require 'lib/veewee'
+require 'tempfile'
+
+class TestVeeweeEnvironment < Test::Unit::TestCase
+ def test_environment_default_to_currentdir
+
+ tempdir = Dir.mktmpdir
+ Dir.chdir(tempdir)
+ tempdir=Dir.pwd
+ begin
+ ve=Veewee::Environment.new()
+ assert_equal(ve.cwd,tempdir)
+ ensure
+ FileUtils.remove_entry_secure tempdir
+ end
+
+ end
+
+ # If a cwd is passed, it take precendence over currentdir
+ def test_environment_override_environmentdir
+
+ # Create a temp directory to simulate a currentdir
+ tempdir = Dir.mktmpdir
+ Dir.chdir(tempdir)
+ tempdir=Dir.pwd
+ # Now change to another dir
+ Dir.chdir("/tmp")
+ begin
+ ve=Veewee::Environment.new({:cwd => tempdir})
+ assert_equal(ve.cwd,tempdir)
+ ensure
+ FileUtils.remove_entry_secure tempdir
+ end
+
+ end
+
+ # parent of isodir or definitiondir not writeable should raise an error
+ def test_environment_parentdir_should_be_writeable
+ end
+
+ # definition_dir , iso_dir by default are relative to the environmentdir
+ def test_environment_iso_dir_relative_to_environmentdir
+
+ # Create a temp directory to simulate a currentdir
+ tempdir = Dir.mktmpdir
+ Dir.chdir(tempdir)
+ tempdir=Dir.pwd
+ begin
+ ve=Veewee::Environment.new({:cwd => tempdir})
+ assert(ve.definition_path.include?(File.join(tempdir,"definitions")))
+ assert_equal(ve.iso_dir,File.join(tempdir,"iso"))
+ ensure
+ FileUtils.remove_entry_secure tempdir
+ end
+
+ end
+
+ # definition_dir , iso_dir by default are relative to the environmentdir
+ def test_environment_definition_dir_relative_to_environmentdir
+ # Goto top dir , to make pwd another dir
+ Dir.chdir("/")
+ ve=Veewee::Environment.new({:definition_path => ["/tmp"]})
+ assert_equal(ve.definition_dir,"/tmp")
+ end
+
+end
View
10 test/build_test.rb
@@ -4,21 +4,21 @@
class TestVeeweeBuild < Test::Unit::TestCase
def setup
@ve=Veewee::Environment.new({:definition_dir => File.expand_path(File.join(File.dirname(__FILE__),"definitions")) })
- template_name="test_definition"
- @vm_name="test_definition"
- @vd=@ve.get_definition(template_name)
+ @definition_name="test_definition"
+ @box_name="test_definition"
+ @vd=@ve.get_definition(@definition_name)
@vd.postinstall_files=["_test_me.sh"]
end
def test_virtualbox_1_build
assert_nothing_raised {
- @ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).build({})
+ @ve.config.builders["virtualbox"].build(@definition_name,{})
}
end
def test_virtualbox_2_ssh
assert_nothing_raised {
- result=@ve.builder(:virtualbox).get_box(@vm_name,@vd,{}).ssh("who am i")
+ result=@ve.config.builders["virtualbox"].get_box(@box_name).ssh("who am i")
assert_match(/root/,result.stdout)
}
end
View
2  test/definition_test.rb
@@ -8,4 +8,4 @@ def test_environment_load_definition
vd=ve.get_definition("ubuntu-10.10-server-amd64")
assert_equal(vd.os_type_id,"Ubuntu_64")
end
-end
+end
View
2  test/environment_test.rb
@@ -61,7 +61,7 @@ def test_environment_definition_dir_relative_to_environmentdir
# Goto top dir , to make pwd another dir
Dir.chdir("/")
ve=Veewee::Environment.new({:definition_path => ["/tmp"]})
- assert_equal(ve.definition_dir,"/tmp")
+ assert_equal(ve.definition_dir,"/definitions")
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.