ievms-ruby 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67de3c3a94c58726ee5a753a1e9c5a1509b7c138
4
+ data.tar.gz: 1e223e62dd5612fb16011419ca67fbfabe5ef73e
5
+ SHA512:
6
+ metadata.gz: 1f372973ee925225d9b9927773ad789ef5baeef43cbb33ef8e9c00dd13e2f681881c6262d918d374e263ccc73e4d461983582bc5404a076e65bd5603db3f5a33
7
+ data.tar.gz: 1a44d4a319fbcda6a60b1b0cbc5310d8945bff70718f2d90741c26ee70567569847e72050378ed334e777c9cc9d5efb15e0e4c512a12e308b1fd3c5d215e210d
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ievms-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Pim Snel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # ievms-ruby
2
+
3
+ Ruby interface for boxes made by ievms.sh
4
+ (http://xdissent.github.com/ievms). Use this Library to provision your
5
+ IE boxes from https://modern.ie.
6
+
7
+ ## Requirements
8
+
9
+ * VirtualBox >= 5.0.4
10
+ * VirtualBox Extension Pack and Guest Additions >= 5.0.4
11
+ * Host Machine: OSX or Linux (only tested on OSX 10.9 & 10.10)
12
+ * Virtual Machines created by .ievms (only tested with a vanilla "IE9 -
13
+ Win7" machine
14
+
15
+ ## Working
16
+
17
+ * Works with Windows 7
18
+ * Upload files to guest machine
19
+ * Execute batch file on guest machine
20
+ * Execute batch file as admin on guest machine
21
+
22
+ ## TODO 0.1
23
+
24
+ * upload files as admin to guest machine
25
+ * more IE platforms
26
+ * more Win platforms
27
+ * Use as CLI
28
+ * Documentation
29
+ * provisioning example
30
+ * Rubycop
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ ```ruby
37
+ gem 'ievms-ruby'
38
+ ```
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install ievms-ruby
44
+
45
+ ## Usage
46
+ Here's an example provising script using the Gem:
47
+
48
+ ```
49
+ TODO
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/mipmip/ievms-ruby/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/test_*.rb"
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
11
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ievms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ievms-ruby"
8
+ spec.version = Ievms::VERSION
9
+ spec.authors = ["Pim Snel"]
10
+ spec.email = ["pim@lingewoud.nl"]
11
+ spec.summary = %q{Ruby interface for boxes made by ievms.sh}
12
+ spec.description = %q{Ruby interface for boxes made by ievms.sh (http://xdissent.github.com/ievms)}
13
+ spec.homepage = "https://github.com/mipmip/ievms-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "simplecov", "~> 0.10"
24
+ spec.add_development_dependency "minitest", "~> 5.1"
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Ievms
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,123 @@
1
+ require "ievms/version"
2
+ require 'open3'
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+
6
+ # VM admin username
7
+ USERNAME='IEUser'
8
+ # VM admin user password
9
+ PASSWD='Passw0rd!'
10
+
11
+ # IEVMS directory
12
+ IEVMS_HOME = ENV['HOME']+'/.ievms'
13
+
14
+
15
+ module Ievms
16
+ class WindowsGuest
17
+ attr_accessor :verbose
18
+
19
+ @verbose = false
20
+
21
+ def initialize(vbox_name)
22
+ @vbox_name = vbox_name
23
+
24
+ is_vm vbox_name
25
+ end
26
+
27
+ # Copy a file to the virtual machine from the ievms home folder.
28
+ def copy_to_vm src ,dest
29
+ print "Copying #{src} to #{dest}\n"
30
+ guestcontrol_exec "cmd.exe", "cmd.exe /c copy \"E:\\#{src}\" \"#{dest}\""
31
+ end
32
+
33
+ def upload_file_to_guest(local_path, guest_path)
34
+
35
+ # 1 copy to tmp location in .ievms
36
+ FileUtils.cp local_path, File.join(IEVMS_HOME,File.basename(local_path))
37
+
38
+ # 2 run cp command in machine
39
+ copy_to_vm File.basename(local_path), guest_path
40
+
41
+ # 3 remove tmp file in .ievms
42
+ FileUtils.rm File.join(IEVMS_HOME,File.basename(local_path))
43
+ end
44
+
45
+ # execute existibg batch file in Windows guest as Administrator
46
+ def run_bat_as_admin(guest_path)
47
+ print "Executing batch file as administrator: #{guest_path}\n"
48
+
49
+ guestcontrol_exec "cmd.exe", "cmd.exe /c \"echo #{guest_path} > C:\\Users\\IEUser\\ievms.bat\""
50
+ guestcontrol_exec "schtasks.exe", "schtasks.exe /run /tn ievms"
51
+
52
+ end
53
+
54
+ # execute existibg batch file in Windows guest as Administrator
55
+ def run_command_as_admin(command)
56
+ print "Executing command as administrator: #{command}\n"
57
+
58
+ run_command 'if exist C:\Users\IEUser\ievms.bat del C:\Users\IEUser\ievms.bat && Exit'
59
+
60
+ #move to method
61
+ tmp = Tempfile.new('ievms.bat')
62
+ tmp.write "#{command}\n"
63
+ path = tmp.path
64
+ tmp.rewind
65
+ tmp.close
66
+ upload_file_to_guest(path, 'C:\Users\IEUser\ievms.bat')
67
+ FileUtils.rm path
68
+
69
+ guestcontrol_exec "schtasks.exe", "schtasks.exe /run /tn ievms"
70
+
71
+ end
72
+
73
+ # execute existing batch file in Windows guest
74
+ def run_command command
75
+ print "Executing command: #{command}\n"
76
+ out, _, _ = guestcontrol_exec "cmd.exe", "cmd.exe /c \"#{command}\""
77
+ return out
78
+ end
79
+
80
+ # execute existibg batch file in Windows guest
81
+ def run_bat guest_path
82
+ print "Executing batch file: #{guest_path}\n"
83
+ out, _, _ = guestcontrol_exec "cmd.exe", "cmd.exe /c \"#{guest_path}\""
84
+ return out
85
+ end
86
+
87
+ private
88
+
89
+ # execute final guest control shell cmd
90
+ # returns [stdout,stderr,status] from capture3
91
+ def guestcontrol_exec image, cmd
92
+ wait_for_guestcontrol(@vbox_name)
93
+ cmd = "VBoxManage guestcontrol \"#{@vbox_name}\" run --username \"#{USERNAME}\" --password '#{PASSWD}' --exe \"#{image}\" -- #{cmd}"
94
+ #print cmd + "\n"
95
+ return Open3.capture3(cmd)
96
+ end
97
+
98
+ # function taken from ievms
99
+ # Pause execution until guest control is available for a virtual machine
100
+ def wait_for_guestcontrol vboxname
101
+ run_level = 0
102
+ while run_level < 3 do
103
+ print "Waiting for #{vboxname} to be available for guestcontrol...\n" if @verbose
104
+ out = `VBoxManage showvminfo "#{vboxname}" | grep 'Additions run level:'`
105
+ run_level = out[-2..-2].to_i
106
+ if run_level < 3
107
+ sleep 3
108
+ end
109
+ end
110
+ end
111
+
112
+ # Is it a virtual machine in VirtualBox?
113
+ def is_vm vboxname
114
+ cmd = "VBoxManage showvminfo \"#{vboxname}\""
115
+
116
+ _, stderr, _ = Open3.capture3(cmd)
117
+ if stderr.include? 'Could not find a registered machine named'
118
+ raise "Virtual Machine #{vboxname} does not exist"
119
+ end
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,2 @@
1
+ echo OFF
2
+ echo. 2> C:\Users\IEUser\EmptyFile.txt
@@ -0,0 +1 @@
1
+ echo. 2> C:\EmptyFile2.txt
@@ -0,0 +1,16 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter '/test/'
5
+ add_filter '/vendor/'
6
+ end
7
+
8
+ require 'minitest'
9
+ require 'minitest/unit'
10
+ require 'minitest/autorun'
11
+ require 'minitest/pride'
12
+ #require 'base64'
13
+
14
+ #tempdir = File.join(File.dirname(__FILE__), 'tmpout')
15
+ #FileUtils.rm_rf(Dir.glob(tempdir+'/*'))
16
+
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+ require 'ievms/windows_guest'
3
+ require 'timeout'
4
+
5
+ class TestWin7 < Minitest::Test
6
+ def setup
7
+ @machine = Ievms::WindowsGuest.new 'IE9 - Win7'
8
+ end
9
+
10
+ def test_non_existing_guest
11
+ assert_raises {
12
+ _ = Ievms::WindowsGuest.new 'Non Existing Guest'
13
+ }
14
+ end
15
+
16
+ def test_not_running_machine_time_out
17
+
18
+ assert_raises {
19
+ _ = Timeout::timeout(5) {
20
+ standbymachine = Ievms::WindowsGuest.new 'standbymachine'
21
+ standbymachine.verbose = true
22
+ standbymachine.run_command "dir"
23
+ }
24
+ }
25
+
26
+ end
27
+
28
+ def test_execute_batch_file
29
+
30
+ @machine.run_command 'if exist C:\Users\IEUser\test.bat del C:\Users\IEUser\test.bat && Exit'
31
+ @machine.run_command 'if exist C:\Users\IEUser\EmptyFile.txt del C:\Users\IEUser\EmptyFile.txt && Exit'
32
+
33
+ @machine.upload_file_to_guest(File.join(File.dirname(__FILE__), '_test.bat'), 'C:\Users\IEUser\test.bat')
34
+ @machine.run_bat('C:\Users\IEUser\test.bat')
35
+ output_file_exists = @machine.run_command 'if exist C:\Users\IEUser\EmptyFile.txt echo EmptyFileExist && Exit'
36
+
37
+ assert_equal true, output_file_exists.include?('EmptyFileExist')
38
+ end
39
+
40
+ def test_execute_command
41
+
42
+ dir_output = @machine.run_command('cd c:\Users\IEUser & dir')
43
+ assert_equal true, dir_output.include?('Desktop')
44
+ end
45
+
46
+ def test_execute_batch_file_as_admin
47
+ @machine.run_command_as_admin 'if exist C:\Users\IEUser\test_as_admin.bat del C:\Users\IEUser\test_as_admin.bat && Exit'
48
+ @machine.run_command_as_admin 'if exist C:\EmptyFile2.txt del C:\EmptyFile2.txt && Exit'
49
+
50
+ @machine.upload_file_to_guest(File.join(File.dirname(__FILE__), '_test_as_admin.bat'), 'C:\Users\IEUser\test_as_admin.bat')
51
+ @machine.run_bat_as_admin('C:\Users\IEUser\test_as_admin.bat')
52
+ output_file_exists = @machine.run_command 'if exist C:\EmptyFile2.txt echo EmptyFile2Exist && Exit'
53
+
54
+ assert_equal true, output_file_exists.include?('EmptyFile2Exist')
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ievms-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pim Snel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.1'
69
+ description: Ruby interface for boxes made by ievms.sh (http://xdissent.github.com/ievms)
70
+ email:
71
+ - pim@lingewoud.nl
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - ievms-ruby.gemspec
82
+ - lib/ievms/version.rb
83
+ - lib/ievms/windows_guest.rb
84
+ - test/_test.bat
85
+ - test/_test_as_admin.bat
86
+ - test/test_helper.rb
87
+ - test/test_ievms_win7.rb
88
+ homepage: https://github.com/mipmip/ievms-ruby
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ruby interface for boxes made by ievms.sh
112
+ test_files:
113
+ - test/_test.bat
114
+ - test/_test_as_admin.bat
115
+ - test/test_helper.rb
116
+ - test/test_ievms_win7.rb