instalatron 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
  Requirements:
2
2
 
3
- VirtualBox 4.0.8
3
+ VirtualBox >= 4.0.8
4
4
  ImageMagick >= 6.6.4
data/bin/instalatron-play CHANGED
@@ -3,6 +3,7 @@ require 'fileutils'
3
3
  require 'instalatron'
4
4
  require 'yaml'
5
5
  require 'mixlib/cli'
6
+ require 'logger'
6
7
 
7
8
  def play_session(vm_name, script, custom_seq = nil, key_press_delay = 0)
8
9
  ctrlc_gap = 0
@@ -90,7 +91,21 @@ class MyCLI
90
91
  :long => "--key-press-delay SECS",
91
92
  :description => "Delay between key presses",
92
93
  :default => 0
93
-
94
+
95
+ option :nic_config,
96
+ :long => "--nic-config CFG",
97
+ :description => "VM NIC config (nic:device:mode)"
98
+
99
+ option :vm_memory,
100
+ :long => "--vm-memory MEM",
101
+ :description => "VM Memory",
102
+ :default => 512
103
+
104
+ option :vm_disk_size,
105
+ :long => "--vm-disk-size SIZE",
106
+ :description => "VM Disk Size in MB",
107
+ :default => 10024
108
+
94
109
  option :help,
95
110
  :short => "-h",
96
111
  :long => "--help",
@@ -102,6 +117,8 @@ class MyCLI
102
117
 
103
118
  end
104
119
 
120
+ Log = Logger.new($stdout)
121
+
105
122
  cli = MyCLI.new
106
123
  cli.parse_options
107
124
 
@@ -125,11 +142,20 @@ if not File.exist?(iso_file)
125
142
  end
126
143
 
127
144
  # Create VBox VM first
128
- Instalatron.create_vm :vm_name => vm_name, :iso_file => iso_file, :headless => cli.config[:headless]
129
-
145
+
146
+ Log.debug "Creating VM #{vm_name}"
147
+ Instalatron.create_vm :vm_disk_size => cli.config[:vm_disk_size], :vm_memory => cli.config[:vm_memory], :vm_name => vm_name, :iso_file => iso_file, :headless => cli.config[:headless]
148
+
149
+ nic_config = cli.config[:nic_config]
150
+ if nic_config
151
+ nic, device, mode = nic_config.split ':'
152
+ Log.debug "Setting nic mode #{nic} #{device} #{mode}"
153
+ Instalatron.set_nic_mode(vm_name, nic, device, mode)
154
+ end
130
155
  puts "Playing script using VM #{vm_name}\n\n"
131
156
  play_session vm_name, script, cli.config[:custom_sequence], cli.config[:key_press_delay]
132
157
 
158
+
133
159
  if cli.config[:destroy_vm]
134
160
  puts "Unregistering and deleting VM #{vm_name}"
135
161
  Instalatron.destroy_vm(vm_name)
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'rubygems'
2
3
  require 'fileutils'
3
4
  require 'instalatron'
4
5
  require 'yaml'
6
+ require 'mixlib/cli'
5
7
 
6
8
  def record_session(vm_name, session_name = "instalatron_rec_" + Time.now.strftime("%F_%H%M"))
7
9
  puts "Recording session #{session_name}\n\n"
@@ -47,19 +49,75 @@ def record_session(vm_name, session_name = "instalatron_rec_" + Time.now.strftim
47
49
  end
48
50
  end
49
51
 
50
- vm_name = ARGV[0]
51
- running_vms = []
52
- `VBoxManage list runningvms`.each_line do |l|
53
- vm = l.split[0].gsub('"', '')
54
- running_vms << vm
52
+ class MyCLI
53
+ include Mixlib::CLI
54
+
55
+ option :vm_name,
56
+ :short => "-n NAME",
57
+ :long => "--vm-name NAME",
58
+ :description => "Virtual Machine Name",
59
+ :default => "instalatron_#{Time.now.strftime('%s')}"
60
+
61
+ option :iso_file,
62
+ :short => "-i ISO",
63
+ :long => "--iso-file ISO",
64
+ :description => "ISO file to boot the VM with"
65
+
66
+ option :destroy_vm,
67
+ :long => "--destroy-vm",
68
+ :description => "Destroy the VM after running the tests"
69
+
70
+ option :vm_memory,
71
+ :long => "--vm-memory MEM",
72
+ :description => "VM Memory",
73
+ :default => 512
74
+
75
+ option :version,
76
+ :long => "--version",
77
+ :short => "-v",
78
+ :description => "Instalatron Version",
79
+ :proc => Proc.new { puts Instalatron::VERSION; exit 0 }
80
+
81
+ option :help,
82
+ :short => "-h",
83
+ :long => "--help",
84
+ :description => "Show this message",
85
+ :on => :tail,
86
+ :boolean => true,
87
+ :show_options => true,
88
+ :exit => 0
89
+
55
90
  end
56
- if not running_vms.include?(vm_name)
57
- $stderr.puts "Running VM #{vm_name} not found.\n\n"
58
91
 
59
- $stderr.puts "Usage: instalatron-record <vm_name> [session_name]"
92
+ def usage(cli)
93
+ $stderr.puts cli.opt_parser.help
60
94
  exit 1
61
95
  end
62
96
 
63
- session_name = ARGV[1] || "instalatron_rec_" + Time.now.strftime("%F_%H%M")
97
+ def required_option(cli, opt)
98
+ if cli.config[opt].nil?
99
+ $stderr.puts "\n#{opt.to_s} argument requied.\n\n"
100
+ $stderr.puts cli.opt_parser.help
101
+ exit 1
102
+ end
103
+ return cli.config[opt]
104
+ end
105
+
106
+ cli = MyCLI.new
107
+ cli.parse_options
108
+
109
+ vm_name = cli.config[:vm_name]
110
+
111
+ iso_file = required_option(cli, :iso_file)
112
+ if not File.exist?(iso_file)
113
+ $stderr.puts "Invalid ISO file.\n\n"
114
+ usage(cli)
115
+ end
116
+
117
+ session_name = "instalatron_rec_" + Time.now.strftime("%F_%H%M")
118
+
119
+ # Create VBox VM first
120
+ $stdout.puts "Creating VM #{vm_name}..."
121
+ Instalatron.create_vm :vm_memory => cli.config[:vm_memory], :vm_name => vm_name, :iso_file => iso_file
64
122
 
65
123
  record_session vm_name, session_name
data/lib/instalatron.rb CHANGED
@@ -4,7 +4,29 @@ require 'virtualbox'
4
4
 
5
5
  module Instalatron
6
6
 
7
- VERSION = '0.1.3'
7
+ VERSION = '0.1.4'
8
+
9
+ #
10
+ # NIC is nic1, nic2, etc
11
+ # device is eth0, eth1, etc
12
+ # mode is either :nat, :bridged, :hostonly
13
+ #
14
+ def self.set_nic_mode(vm_name, nic, device, mode)
15
+ err = `VBoxManage controlvm #{vm_name} #{nic} #{mode.to_s} #{device} 2>&1`
16
+ puts err
17
+ raise Exception.new(err) if $? != 0
18
+ end
19
+
20
+ def self.add_ssh_nat_mapping(vm_name, guest_port, host_port)
21
+ vm=VirtualBox::VM.find(vm_name)
22
+ port = VirtualBox::NATForwardedPort.new
23
+ port.name = "guestssh"
24
+ port.guestport = guest_port
25
+ port.hostport = host_port
26
+ vm.network_adapters[0].nat_driver.forwarded_ports << port
27
+ port.save
28
+ vm.save
29
+ end
8
30
 
9
31
  def self.destroy_vm(vm_name)
10
32
  `VBoxManage controlvm '#{vm_name}' poweroff > /dev/null 2>&1`
@@ -23,6 +45,7 @@ module Instalatron
23
45
  vboxcmd = params[:vboxcmd] || 'VBoxManage'
24
46
  vm_memory = params[:vm_memory] || 512
25
47
  vm_cpus = params[:vm_cpus] || 1
48
+ vm_disk_size = params[:vm_disk_size].to_i || 8192
26
49
  if params[:headless].nil?
27
50
  params[:headless] = false
28
51
  end
@@ -44,7 +67,7 @@ module Instalatron
44
67
  end
45
68
 
46
69
  vm=VirtualBox::VM.find(vm_name)
47
- vm.memory_size= vm_memory
70
+ vm.memory_size = vm_memory.to_i
48
71
  vm.os_type_id = os_type
49
72
  vm.cpu_count = vm_cpus
50
73
  vm.name = vm_name
@@ -60,7 +83,7 @@ module Instalatron
60
83
  place = `#{vboxcmd} list systemproperties|grep '^Default machine'|cut -d ':' -f 2|sed -e 's/^[ ]*//'`.strip.chomp
61
84
  disk_file = "#{place}/#{vm_name}/#{vm_name}.vdi"
62
85
 
63
- `#{vboxcmd} createhd --filename '#{disk_file}' --size 8192 --format VDI >/dev/null 2>&1`
86
+ `#{vboxcmd} createhd --filename '#{disk_file}' --size #{vm_disk_size} --format VDI >/dev/null 2>&1`
64
87
 
65
88
  # Add IDE/Sata Controllers
66
89
  `#{vboxcmd} storagectl '#{vm_name}' --name 'SATA Controller' --add sata --hostiocache off >/dev/null 2>&1`
@@ -83,7 +106,7 @@ module Instalatron
83
106
  keycodes.split.each do |k|
84
107
  `VBoxManage controlvm #{vm_name} keyboardputscancode '#{k}' >/dev/null 2>&1`
85
108
  end
86
- sleep key_press_delay.to_i
109
+ sleep key_press_delay.to_f
87
110
  end
88
111
  end
89
112
 
@@ -94,7 +117,7 @@ module Instalatron
94
117
  `VBoxManage controlvm #{vm_name} screenshotpng #{dest_file} >/dev/null 2>&1`
95
118
  end
96
119
 
97
- def self.same_image?(ref_image, new_img, threshold = 1500)
120
+ def self.same_image?(ref_image, new_img, threshold = 2000)
98
121
  `file #{ref_image}` =~ /(\d+\sx\s\d+)/
99
122
  geom1 = $1
100
123
  `file #{new_img}` =~ /(\d+\sx\s\d+)/
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instalatron
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Rubio
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-15 00:00:00 Z
18
+ date: 2011-07-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
24
  - - ~>
@@ -29,12 +29,12 @@ dependencies:
29
29
  - 0
30
30
  - 0
31
31
  version: 1.0.0
32
- version_requirements: *id001
33
- name: bundler
34
- prerelease: false
35
32
  type: :development
33
+ requirement: *id001
34
+ prerelease: false
35
+ name: bundler
36
36
  - !ruby/object:Gem::Dependency
37
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
40
  - - ~>
@@ -45,12 +45,12 @@ dependencies:
45
45
  - 5
46
46
  - 2
47
47
  version: 1.5.2
48
- version_requirements: *id002
49
- name: jeweler
50
- prerelease: false
51
48
  type: :development
49
+ requirement: *id002
50
+ prerelease: false
51
+ name: jeweler
52
52
  - !ruby/object:Gem::Dependency
53
- requirement: &id003 !ruby/object:Gem::Requirement
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ">="
@@ -60,12 +60,12 @@ dependencies:
60
60
  - 1
61
61
  - 2
62
62
  version: "1.2"
63
- version_requirements: *id003
64
- name: mixlib-cli
65
- prerelease: false
66
63
  type: :runtime
64
+ requirement: *id003
65
+ prerelease: false
66
+ name: mixlib-cli
67
67
  - !ruby/object:Gem::Dependency
68
- requirement: &id004 !ruby/object:Gem::Requirement
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
71
71
  - - ">="
@@ -75,12 +75,12 @@ dependencies:
75
75
  - 1
76
76
  - 2
77
77
  version: "1.2"
78
- version_requirements: *id004
79
- name: mixlib-cli
80
- prerelease: false
81
78
  type: :runtime
79
+ requirement: *id004
80
+ prerelease: false
81
+ name: mixlib-cli
82
82
  - !ruby/object:Gem::Dependency
83
- requirement: &id005 !ruby/object:Gem::Requirement
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ">="
@@ -90,10 +90,10 @@ dependencies:
90
90
  - 0
91
91
  - 8
92
92
  version: "0.8"
93
- version_requirements: *id005
94
- name: virtualbox
95
- prerelease: false
96
93
  type: :runtime
94
+ requirement: *id005
95
+ prerelease: false
96
+ name: virtualbox
97
97
  description: Tests graphical installers using VirtualBox, keyboard driven input and image recognition technics
98
98
  email: srubio@abiquo.com
99
99
  executables:
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements: []
149
149
 
150
150
  rubyforge_project:
151
- rubygems_version: 1.7.2
151
+ rubygems_version: 1.8.5
152
152
  signing_key:
153
153
  specification_version: 3
154
154
  summary: Abiquo Installer Testing Framework