instalatron 0.1.1 → 0.1.2

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.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def usage
4
+ puts "Usage: instalatron-changeterm <vm-name> <term-no>"
5
+ puts "\nvm-name is the name of the VirtualBox VM"
6
+ puts "term-no is the linux terminal number (1,2,3,4,5,...)"
7
+ exit 1
8
+ end
9
+
10
+ vm_name = ARGV[0]
11
+ term = ARGV[1]
12
+ if vm_name.nil? or term.nil?
13
+ usage
14
+ end
15
+
16
+ begin
17
+ term = term.to_i
18
+ rescue Exception
19
+ usage
20
+ end
21
+
22
+ kbd = [
23
+ '1d 38 3b',
24
+ '1d 38 3c',
25
+ '1d 38 3d',
26
+ '1d 38 3e',
27
+ '1d 38 3f',
28
+ '1d 38 40',
29
+ '1d 38 41',
30
+ '1d 38 42'
31
+ ]
32
+
33
+ `VBoxManage controlvm #{vm_name} keyboardputscancode #{kbd[term]}`
data/bin/instalatron-play CHANGED
@@ -4,11 +4,16 @@ require 'instalatron'
4
4
  require 'yaml'
5
5
  require 'mixlib/cli'
6
6
 
7
- def play_session(vm_name, script)
7
+ def play_session(vm_name, script, custom_seq = nil)
8
8
  ctrlc_gap = 0
9
9
  basedir = File.dirname(script)
10
10
  script = YAML.load_file(script)
11
- require 'pp'
11
+ if custom_seq
12
+ new_seq = script[0]
13
+ new_seq[:sequence] = custom_seq
14
+ script[0] = new_seq
15
+ end
16
+ step = 1
12
17
  script.each do |screen|
13
18
  ref_img = "#{basedir}/#{File.basename(screen[:image])}"
14
19
  loop do
@@ -22,7 +27,7 @@ def play_session(vm_name, script)
22
27
  rescue Interrupt, SystemExit
23
28
  if Time.now.to_f - ctrlc_gap < 0.5
24
29
  puts "\n\nDouble Ctrl-c detected. Aborting."
25
- exit
30
+ return
26
31
  else
27
32
  ctrlc_gap = Time.now.to_f
28
33
  end
@@ -30,6 +35,7 @@ def play_session(vm_name, script)
30
35
  break
31
36
  end
32
37
  end
38
+ step += 1
33
39
  end
34
40
  end
35
41
 
@@ -65,6 +71,15 @@ class MyCLI
65
71
  :short => "-s SCRIPT",
66
72
  :long => "--script SCRIPT",
67
73
  :description => "Path to the script file (script.yml) or directory."
74
+
75
+ option :custom_sequence,
76
+ :short => "-c SEQUENCE",
77
+ :long => "--custom-sequence SEQUENCE",
78
+ :description => "Replace first step key sequence"
79
+
80
+ option :destroy_vm,
81
+ :long => "--destroy-vm",
82
+ :description => "Destroy the VM after running the tests"
68
83
 
69
84
  option :help,
70
85
  :short => "-h",
@@ -103,4 +118,9 @@ end
103
118
  Instalatron.create_vm :vm_name => vm_name, :iso_file => iso_file
104
119
 
105
120
  puts "Playing script using VM #{vm_name}\n\n"
106
- play_session vm_name, script
121
+ play_session vm_name, script, cli.config[:custom_sequence]
122
+
123
+ if cli.config[:destroy_vm]
124
+ puts "Unregistering and deleting VM #{vm_name}"
125
+ Instalatron.destroy_vm(vm_name)
126
+ end
data/lib/instalatron.rb CHANGED
@@ -4,7 +4,14 @@ require 'virtualbox'
4
4
 
5
5
  module Instalatron
6
6
 
7
- VERSION = '0.1.1'
7
+ VERSION = '0.1.2'
8
+
9
+ def self.destroy_vm(vm_name)
10
+ `VBoxManage controlvm '#{vm_name}' poweroff > /dev/null 2>&1`
11
+ # dumb
12
+ sleep 1
13
+ `VBoxManage unregistervm '#{vm_name}' --delete > /dev/null 2>&1`
14
+ end
8
15
 
9
16
  def self.create_vm(params = {})
10
17
  vm_name = params[:vm_name] || "instalatron_#{Time.now.to_f}"
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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Rubio
@@ -99,6 +99,7 @@ email: srubio@abiquo.com
99
99
  executables:
100
100
  - print-yaml-keyseq
101
101
  - instalatron-record
102
+ - instalatron-changeterm
102
103
  - instalatron-play
103
104
  - instalatron-monitor
104
105
  extensions: []
@@ -112,6 +113,7 @@ files:
112
113
  - LICENSE.txt
113
114
  - README.rdoc
114
115
  - Rakefile
116
+ - bin/instalatron-changeterm
115
117
  - bin/instalatron-monitor
116
118
  - bin/instalatron-play
117
119
  - bin/instalatron-record