vagrant-winrm 0.0.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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 210c89d4530fcbed54ae1c14abfb7296eac6a39f
4
+ data.tar.gz: 26bd2ffbf4d1b9aebedd4f3dd5e8c2c14ef6b4ef
5
+ SHA512:
6
+ metadata.gz: 376ec1e96ba09e7edb537c4d813b9e39bff4dff4a14024c4ad95d89a5c47bbb2bd2cc82951ead06258da431e0ebc0fbc822a7b338cf30a2931b88d59227885d9
7
+ data.tar.gz: 6a14eee48918be937014f323f63f1d9ca5c8554c7c3452963d1a480626009416964c9ce836e50efe9d44792b52a5c2699e63f3cec554423730c21e81959393a7
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: rake spec
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', :tag => 'v1.6.3'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Baptiste Courtois (<b.courtois@criteo.com>)
2
+
3
+ Copyright (C) 2014, Baptiste Courtois
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,78 @@
1
+ # <a name="title"></a> Vagrant-WinRM
2
+
3
+ This is a [Vagrant][vagrant_dl] 1.6+ plugin that adds new command to extends WinRM communication features.
4
+
5
+ **NOTE:** This plugin requires Vagrant 1.6+
6
+
7
+ ## <a name="features"></a> Features
8
+
9
+ * Execute remote command
10
+ * Upload files
11
+ * Retrieve WinRM configuration
12
+
13
+ ## <a name="installation"></a> Installation
14
+
15
+ Install using standard Vagrant plugin installation methods:
16
+
17
+ vagrant plugin install vagrant-winrm
18
+
19
+ Please read the [Plugin usage][plugin_usage] page for more details.
20
+
21
+ ## <a name="usage"></a> Usage
22
+
23
+ ### <a name="usage-winrm"> winrm
24
+
25
+ This command allows you to execute arbitrary remote commands through WinRM.
26
+
27
+ vagrant winrm -c "pre-install.bat" -c "install.bat" -c "post-install.bat" Windows2008VM
28
+
29
+ ### <a name="usage-winrm-upload"> winrm-upload
30
+
31
+ This command allows you to upload a file or a directory to your machine through WinRM.
32
+
33
+ vagrant winrm-upload "c:\mylocalFolder" "d:\" Windows2008VM
34
+
35
+ ## <a name="usage-winrm-config"> winrm-config
36
+
37
+ This command prints the current WinRM configuration of your machine.
38
+
39
+ ```bash
40
+ $ vagrant winrm-config --host "CustomHostname" Windows2008VM
41
+ Host CustomHostname
42
+ HostName Windows2008VM.vagrant.up
43
+ Port 5985
44
+ User vagrant
45
+ Password vagrant
46
+ ```
47
+
48
+ ## <a name="development"></a> Development
49
+
50
+ * Source hosted at [Gitlab][repo]
51
+ * Report issues/questions/feature requests on [Gitlab Issues][issues]
52
+
53
+ Pull requests are very welcome! Make sure your patches are well tested.
54
+ Ideally create a topic branch for every separate change you make. For
55
+ example:
56
+
57
+ 1. Fork the repo
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
62
+
63
+ ## <a name="authors"></a> Authors
64
+
65
+ Created and maintained by [Baptiste Courtois][author] (<b.courtois@criteo.com>)
66
+
67
+ ## <a name="license"></a> License
68
+
69
+ Apache 2.0 (see [LICENSE][license])
70
+
71
+
72
+ [author]: https://github.com/Annih
73
+ [issues]: https://gitlab.criteois.lan/ruby-gems/kitchen-vagrant_winrm/issues
74
+ [license]: https://gitlab.criteois.lan/ruby-gems/kitchen-vagrant_winrm/blob/master/LICENSE
75
+ [repo]: https://gitlab.criteois.lan/ruby-gems/kitchen-vagrant_winrm
76
+ [plugin_usage]: http://docs.vagrantup.com/v2/plugins/usage.html
77
+
78
+ [vagrant_dl]: http://downloads.vagrantup.com/
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Change to the directory of this file.
6
+ Dir.chdir(File.expand_path('../', __FILE__))
7
+
8
+ # For gem creation and bundling
9
+ require 'bundler/gem_tasks'
10
+
11
+ # Run the unit test suite
12
+ RSpec::Core::RakeTask.new do |task|
13
+ task.pattern = 'spec/**/*_spec.rb'
14
+ task.rspec_opts = ['--color', '-f documentation']
15
+ task.rspec_opts << '-tunit'
16
+ end
17
+
18
+ # Default task is to run tests
19
+ task :default => 'spec'
@@ -0,0 +1,22 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module VagrantWinRM
5
+
6
+ # This returns the path to the source of this plugin.
7
+ #
8
+ # @return [Pathname]
9
+ def self.source_root
10
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
11
+ end
12
+
13
+ # This initializes the internationalization strings.
14
+ def self.setup_i18n
15
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
16
+ I18n.reload!
17
+ end
18
+ end
19
+ end
20
+
21
+ VagrantPlugins::VagrantWinRM.setup_i18n()
22
+ require 'vagrant-winrm/plugin'
@@ -0,0 +1,63 @@
1
+ require 'optparse'
2
+ require 'vagrant/util/safe_puts'
3
+
4
+ module VagrantPlugins
5
+ module VagrantWinRM
6
+ class WinRM < Vagrant.plugin('2', :command)
7
+ def self.synopsis
8
+ 'connects to machine via WinRM'
9
+ end
10
+
11
+ def execute
12
+ options = {}
13
+
14
+ opts = OptionParser.new do |o|
15
+ o.banner = 'Usage: vagrant winrm [options] [name]'
16
+ o.separator ''
17
+ o.separator 'Options:'
18
+ o.separator ''
19
+
20
+ o.on('-c', '--command COMMAND', 'Execute a WinRM command directly') do |c|
21
+ options[:command] = Array.new if options[:command].nil?
22
+ options[:command].push c
23
+ end
24
+
25
+ o.on('--plugin-version', 'Print the version of the plugin and exit') do
26
+ options[:version] = true
27
+ end
28
+ end
29
+
30
+ # Parse the options and return if we don't have any target.
31
+ argv = parse_options(opts)
32
+ return unless argv
33
+
34
+ if options[:version]
35
+ require "#{VagrantPlugins::VagrantWinRM.source_root}/lib/version"
36
+ safe_puts "Vagrant-winrm plugin #{VERSION}"
37
+ return 0
38
+ end
39
+
40
+ return 0 unless options[:command]
41
+
42
+ # Execute the actual WinRM command
43
+ with_target_vms(argv, single_target: true) do |vm|
44
+
45
+ raise Errors::ConfigurationError, { :communicator => vm.config.vm.communicator } if vm.config.vm.communicator != :winrm
46
+
47
+ exit_code = 0
48
+ @logger.debug("Executing a batch of #{options[:command].length} on remote machine")
49
+
50
+ options[:command].each do |c|
51
+ @logger.debug("Executing command: #{c}")
52
+ c.gsub! '"', '\"' if c.include? '`' or c.include? '$(' # Powershell is so strange sometimes!
53
+ exit_code |= vm.communicate.execute(c) do |type, data|
54
+ $stdout.print data if type == :stdout
55
+ $stderr.print data if type == :stderr
56
+ end
57
+ end
58
+ return exit_code
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,52 @@
1
+ require 'optparse'
2
+ require 'vagrant/util/safe_puts'
3
+
4
+ module VagrantPlugins
5
+ module VagrantWinRM
6
+ class WinRMConfig < Vagrant.plugin('2', :command)
7
+ include Vagrant::Util::SafePuts
8
+
9
+ def self.synopsis
10
+ 'outputs winrm configuration to connect to the machine like ssh-config'
11
+ end
12
+
13
+ def execute
14
+ options = {}
15
+
16
+ opts = OptionParser.new do |o|
17
+ o.banner = 'Usage: vagrant winrm-config [options] [name]'
18
+ o.separator ''
19
+ o.separator 'Options:'
20
+ o.separator ''
21
+
22
+ o.on('--host NAME', 'Name the host for the config') do |h|
23
+ options[:host] = h
24
+ end
25
+ end
26
+
27
+ # Parse the options and return if we don't have any target.
28
+ argv = parse_options(opts)
29
+ return unless argv
30
+
31
+ with_target_vms(argv) do |machine|
32
+
33
+ variables = {
34
+ host_key: options[:host] || machine.name || 'vagrant',
35
+ winrm_host: machine.config.winrm.host,
36
+ winrm_port: machine.config.winrm.port,
37
+ winrm_user: machine.config.winrm.username,
38
+ winrm_password: machine.config.winrm.password
39
+ }
40
+
41
+ # Render the template and output directly to STDOUT
42
+ template = "#{VagrantPlugins::VagrantWinRM.source_root}/templates/winrm_config/config"
43
+ safe_puts(Vagrant::Util::TemplateRenderer.render(template, variables))
44
+ safe_puts
45
+ end
46
+
47
+ # Success, exit status 0
48
+ 0
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ require 'optparse'
2
+
3
+ module VagrantPlugins
4
+ module VagrantWinRM
5
+ class WinRMUpload < Vagrant.plugin('2', :command)
6
+ def self.synopsis
7
+ 'upload file or directory to machine via WinRM'
8
+ end
9
+
10
+ def execute
11
+
12
+ opts = OptionParser.new do |o|
13
+ o.banner = 'Usage: vagrant winrm-upload <source> <destination> [name]'
14
+ end
15
+
16
+ # Parse the options and return if we don't have any target.
17
+ argv = parse_options opts
18
+ return unless argv
19
+
20
+ if argv.empty? || argv.length > 3 || argv.length < 2
21
+ raise Vagrant::Errors::CLIInvalidUsage,
22
+ help: opts.help.chomp
23
+ end
24
+
25
+ source = argv[0]
26
+ destination = argv[1]
27
+ argv = argv.drop(2)
28
+
29
+ # Execute the actual WinRM
30
+ with_target_vms(argv, single_target: true) do |vm|
31
+
32
+ raise Errors::ConfigurationError, { :communicator => vm.config.vm.communicator } if vm.config.vm.communicator != :winrm
33
+
34
+ @logger.debug("Uploading #{source} to #{destination}")
35
+ return vm.communicate.upload(source, destination)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module VagrantWinRM
3
+ module Errors
4
+ # A convenient superclass for all our errors.
5
+ class WinRMError < Vagrant::Errors::VagrantError
6
+ error_namespace('vagrant_winrm.errors')
7
+ end
8
+
9
+ class ConfigurationError < WinRMError
10
+ error_key(:config_error)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module VagrantWinRM
5
+ autoload :Errors, File.expand_path('../errors', __FILE__)
6
+
7
+ class Plugin < Vagrant.plugin('2')
8
+ name 'winrm'
9
+ description <<-DESC
10
+ This plugin extends Vagrant WinRM features and add new commands.
11
+ DESC
12
+
13
+ command 'winrm-config' do
14
+ require_relative 'commands/winrm_config'
15
+ WinRMConfig
16
+ end
17
+
18
+ command 'winrm-upload' do
19
+ require_relative 'commands/winrm_upload'
20
+ WinRMUpload
21
+ end
22
+
23
+ command 'winrm' do
24
+ require_relative 'commands/winrm'
25
+ WinRM
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module VagrantWinRM
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ en:
2
+ vagrant_winrm:
3
+ errors:
4
+ config_error: |-
5
+ The current machine is not configured to communicate through WinRM.
6
+
7
+ Communicator: %{communicator}
@@ -0,0 +1,24 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ require 'rspec'
7
+ require './lib/vagrant-winrm.rb'
8
+ require './lib/vagrant-winrm/plugin.rb'
9
+ require './lib/vagrant-winrm/plugin.rb'
10
+ require './lib/vagrant-winrm/commands/winrm.rb'
11
+ require './lib/vagrant-winrm/commands/winrm_config.rb'
12
+ require './lib/vagrant-winrm/commands/winrm_upload.rb'
13
+
14
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
+ RSpec.configure do |config|
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe VagrantPlugins::VagrantWinRM::WinRMConfig, :unit => true do
5
+
6
+ =begin ############
7
+ # Here we mock!
8
+ =end ##############
9
+
10
+ let(:idx) { double('idx') }
11
+ let(:winrm_config) { double('winrm_config', host: 'winrm_super_host', port: 32424, username: 'usern@me', password: 'p4ssw0rd') }
12
+ let(:machine_config) { double('machine_config', winrm: winrm_config) }
13
+ let(:machine) { double('machine', config: machine_config, name: 'vagrant', provider: 'virtualbox', config: machine_config, ui: double('ui', opts: {})) }
14
+ let(:env) { double('env', root_path: '', home_path: '', ui_class: '', machine_names: [machine.name], active_machines: [machine], machine_index: idx, default_provider: 'virtualbox') }
15
+
16
+ before do
17
+ # Mock the local env creation
18
+ allow(machine).to receive(:vagrant_env).with('', { :ui_class => '' }).and_return env
19
+
20
+ # Mock the index to include only our machine
21
+ allow(idx).to receive(:release).with machine
22
+ allow(idx).to receive(:include?).with(any_args) do |name|
23
+ 'vagrant' == name
24
+ end
25
+ allow(idx).to receive(:get).with(any_args) do |name|
26
+ env.machine(name.to_sym, :virtualbox)
27
+ end
28
+
29
+ # Add our machine to the environment
30
+ allow(env).to receive(:machine).with(any_args, :virtualbox) do |name, provider|
31
+ machine if :vagrant == name
32
+ end
33
+ end
34
+
35
+ =begin ############
36
+ # Here we test!
37
+ =end ##############
38
+ describe 'execute' do
39
+
40
+ it 'displays help message with option --help' do
41
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new(['--help'], env)
42
+ expect {
43
+ expect(c.execute).to be_nil
44
+ }.to output.to_stdout
45
+ end
46
+
47
+ it 'raises error on unknown target' do
48
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new(['unknownTarget'], env)
49
+ expect { c.execute }.to raise_error(Vagrant::Errors::VMNotFoundError)
50
+ end
51
+
52
+ it 'raises error ''invalid options'' on unknown option' do
53
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new(['--unknown'], env)
54
+ expect { c.execute }.to raise_error(Vagrant::Errors::CLIInvalidOptions)
55
+ end
56
+
57
+ it 'ouputs the WinRMConfig with no Target' do
58
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new([], env)
59
+ begin
60
+ $stdout = StringIO.new
61
+ expect(c.execute).to be_zero
62
+ expect($stdout.string).to match(/#{machine.name}/)
63
+ expect($stdout.string).to match(/#{winrm_config.host}/)
64
+ expect($stdout.string).to match(/#{winrm_config.port}/)
65
+ expect($stdout.string).to match(/#{winrm_config.username}/)
66
+ expect($stdout.string).to match(/#{winrm_config.password}/)
67
+ ensure
68
+ $stdout = STDOUT
69
+ end
70
+ end
71
+
72
+ it 'ouputs the WinRMConfig with target' do
73
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new(['vagrant'], env)
74
+ begin
75
+ $stdout = StringIO.new
76
+ expect(c.execute).to be_zero
77
+ expect($stdout.string).to match(/#{machine.name}/)
78
+ expect($stdout.string).to match(/#{winrm_config.host}/)
79
+ expect($stdout.string).to match(/#{winrm_config.port}/)
80
+ expect($stdout.string).to match(/#{winrm_config.username}/)
81
+ expect($stdout.string).to match(/#{winrm_config.password}/)
82
+ ensure
83
+ $stdout = STDOUT
84
+ end
85
+ end
86
+
87
+ it 'ouputs the WinRMConfig with custom host key when --host is provided' do
88
+ c = VagrantPlugins::VagrantWinRM::WinRMConfig.new(['--host', 'custom_host_key', 'vagrant'], env)
89
+ begin
90
+ $stdout = StringIO.new
91
+ expect(c.execute).to be_zero
92
+ expect($stdout.string).to match(/custom_host_key/)
93
+ expect($stdout.string).to match(/#{winrm_config.host}/)
94
+ expect($stdout.string).to match(/#{winrm_config.port}/)
95
+ expect($stdout.string).to match(/#{winrm_config.username}/)
96
+ expect($stdout.string).to match(/#{winrm_config.password}/)
97
+ ensure
98
+ $stdout = STDOUT
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe VagrantPlugins::VagrantWinRM::WinRM, :unit => true do
5
+
6
+ =begin ############
7
+ # Here we mock!
8
+ =end ##############
9
+
10
+ let(:idx) { double('idx') }
11
+ let(:communicator) { double('communicator') }
12
+ let(:config_vm) { double('config_vm', communicator: :winrm) }
13
+ let(:machine_config) { double('machine_config', vm: config_vm) }
14
+ let(:machine) { double('machine', config: machine_config, name: 'vagrant', provider: 'virtualbox', config: machine_config, communicate: communicator, ui: double('ui', opts: {})) }
15
+ let(:env) { double('env', root_path: '', home_path: '', ui_class: '', machine_names: [machine.name], active_machines: [machine], machine_index: idx, default_provider: 'virtualbox') }
16
+
17
+ before do
18
+ # Mock the local env creation
19
+ allow(machine).to receive(:vagrant_env).with('', { :ui_class => '' }).and_return env
20
+
21
+ # Mock the index to include only our machine
22
+ allow(idx).to receive(:release).with machine
23
+ allow(idx).to receive(:include?).with(any_args) do |name|
24
+ 'vagrant' == name
25
+ end
26
+ allow(idx).to receive(:get).with(any_args) do |name|
27
+ env.machine(name.to_sym, :virtualbox)
28
+ end
29
+
30
+ # Add our machine to the environment
31
+ allow(env).to receive(:machine).with(any_args, :virtualbox) do |name, provider|
32
+ machine if :vagrant == name
33
+ end
34
+ end
35
+
36
+ =begin ############
37
+ # Here we test!
38
+ =end ##############
39
+ describe 'execute' do
40
+ it 'does nothing with no option' do
41
+ c = VagrantPlugins::VagrantWinRM::WinRM.new([], env)
42
+ expect {
43
+ expect(c.execute).to be_zero
44
+ }.not_to output.to_stdout
45
+ end
46
+
47
+ it 'gives proper version with option --plugin-version' do
48
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['--plugin-version'], env)
49
+ expect {
50
+ expect(c.execute).to be_zero
51
+ }.to output("Vagrant-winrm plugin 0.0.1\n").to_stdout
52
+ end
53
+
54
+ it 'displays help message with option --help' do
55
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['--help'], env)
56
+ expect {
57
+ expect(c.execute).to be_nil
58
+ }.to output.to_stdout
59
+ end
60
+
61
+ it 'raises error when communicator not winrm' do
62
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'dummyCommand'], env)
63
+ expect(config_vm).to receive(:communicator).and_return :ssh
64
+
65
+ expect { c.execute }.to raise_error(VagrantPlugins::VagrantWinRM::Errors::ConfigurationError, /not configured to communicate through WinRM/)
66
+ end
67
+
68
+ it 'raises error on unknown target' do
69
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'command1', 'unknownTarget'], env)
70
+ expect { c.execute }.to raise_error(Vagrant::Errors::VMNotFoundError)
71
+ end
72
+
73
+ it 'raises error ''invalid options'' on unknown option' do
74
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['--unknown'], env)
75
+ expect { c.execute }.to raise_error(Vagrant::Errors::CLIInvalidOptions)
76
+ end
77
+
78
+ it 'passes commands to communicator with no target' do
79
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'command1', '--command', 'command2', '-c', 'command3', '--command', 'command4'], env)
80
+
81
+ expect(communicator).to receive(:execute).ordered.with('command1').and_return 0
82
+ expect(communicator).to receive(:execute).ordered.with('command2').and_return 0
83
+ expect(communicator).to receive(:execute).ordered.with('command3').and_return 0
84
+ expect(communicator).to receive(:execute).ordered.with('command4').and_return 0
85
+
86
+ expect {
87
+ expect(c.execute).to be_zero
88
+ }.not_to output.to_stdout
89
+ end
90
+
91
+ it 'passes commands to communicator even with a specific target' do
92
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'command5', '--command', 'command6', '-c', 'command7', '--command', 'command8', 'vagrant'], env)
93
+ expect(communicator).to receive(:execute).ordered.with('command5').and_return 0
94
+ expect(communicator).to receive(:execute).ordered.with('command6').and_return 0
95
+ expect(communicator).to receive(:execute).ordered.with('command7').and_return 0
96
+ expect(communicator).to receive(:execute).ordered.with('command8').and_return 0
97
+ expect {
98
+ expect(c.execute).to be_zero
99
+ }.not_to output.to_stdout
100
+ end
101
+
102
+ it 'redirects winrm outputs to stdout' do
103
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'command'], env)
104
+
105
+ expect(communicator).to receive(:execute).with('command').and_yield(:stdout, 'output message').and_return 0
106
+ expect {
107
+ expect(c.execute).to be_zero
108
+ }.to output('output message').to_stdout
109
+ end
110
+
111
+ it 'redirects winrm errors to stderr' do
112
+ c = VagrantPlugins::VagrantWinRM::WinRM.new(['-c', 'command'], env)
113
+
114
+ expect(communicator).to receive(:execute).with('command').and_yield(:stderr, 'error message').and_return 0
115
+ expect {
116
+ expect(c.execute).to be_zero
117
+ }.to output('error message').to_stderr
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe VagrantPlugins::VagrantWinRM::WinRMUpload, :unit => true do
5
+
6
+ =begin ############
7
+ # Here we mock!
8
+ =end ##############
9
+
10
+ let(:idx) { double('idx') }
11
+ let(:communicator) { double('communicator') }
12
+ let(:config_vm) { double('config_vm', communicator: :winrm) }
13
+ let(:machine_config) { double('machine_config', vm: config_vm) }
14
+ let(:machine) { double('machine', config: machine_config, name: 'vagrant', provider: 'virtualbox', config: machine_config, communicate: communicator, ui: double('ui', opts: {})) }
15
+ let(:env) { double('env', root_path: '', home_path: '', ui_class: '', machine_names: [machine.name], active_machines: [machine], machine_index: idx, default_provider: 'virtualbox') }
16
+
17
+ before do
18
+ # Mock the local env creation
19
+ allow(machine).to receive(:vagrant_env).with('', { :ui_class => '' }).and_return env
20
+
21
+ # Mock the index to include only our machine
22
+ allow(idx).to receive(:release).with machine
23
+ allow(idx).to receive(:include?).with(any_args) do |name|
24
+ 'vagrant' == name
25
+ end
26
+ allow(idx).to receive(:get).with(any_args) do |name|
27
+ env.machine(name.to_sym, :virtualbox)
28
+ end
29
+
30
+ # Add our machine to the environment
31
+ allow(env).to receive(:machine).with(any_args, :virtualbox) do |name, provider|
32
+ machine if :vagrant == name
33
+ end
34
+ end
35
+
36
+ =begin ############
37
+ # Here we test!
38
+ =end ##############
39
+ describe 'execute' do
40
+ it 'raises error ''invalid usage'' on bad usage' do
41
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new([], env)
42
+ expect { c.execute }.to raise_error(Vagrant::Errors::CLIInvalidUsage)
43
+ end
44
+
45
+ it 'raises error ''invalid options'' on unknown option' do
46
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['--unknown'], env)
47
+ expect { c.execute }.to raise_error(Vagrant::Errors::CLIInvalidOptions)
48
+ end
49
+
50
+ it 'displays help message with option --help' do
51
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['--help'], env)
52
+ expect {
53
+ expect(c.execute).to be_nil
54
+ }.to output.to_stdout
55
+ end
56
+
57
+ it 'raises error when communicator not winrm' do
58
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['source', 'destination'], env)
59
+ expect(config_vm).to receive(:communicator).and_return :ssh
60
+
61
+ expect { c.execute }.to raise_error(VagrantPlugins::VagrantWinRM::Errors::ConfigurationError, /not configured to communicate through WinRM/)
62
+ end
63
+
64
+ it 'raises error on unknown target' do
65
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['source', 'destination', 'unknownTarget'], env)
66
+ expect { c.execute }.to raise_error Vagrant::Errors::VMNotFoundError
67
+ end
68
+
69
+
70
+ it 'passes source and destination to communicator with no target' do
71
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['source', 'destination'], env)
72
+ expect(communicator).to receive(:upload).with('source', 'destination').and_return 0
73
+
74
+ expect {
75
+ expect(c.execute).to be_zero
76
+ }.not_to output.to_stdout
77
+ end
78
+
79
+ it 'passes source and destination to communicator even with a specific target' do
80
+ c = VagrantPlugins::VagrantWinRM::WinRMUpload.new(['source', 'destination', 'vagrant'], env)
81
+ expect(communicator).to receive(:upload).with('source', 'destination').and_return 0
82
+ expect {
83
+ expect(c.execute).to be_zero
84
+ }.not_to output.to_stdout
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ Host <%= host_key %>
2
+ HostName <%= winrm_host %>
3
+ Port <%= winrm_port %>
4
+ User <%= winrm_user %>
5
+ Password <%= winrm_password %>
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'vagrant-winrm'
6
+ s.version = VagrantPlugins::VagrantWinRM::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Baptiste Courtois']
9
+ s.email = ['b.courtois@criteo.fr']
10
+ s.homepage = 'https://gitlab.criteois.lan/ruby-gems/vagrant-winrm/'
11
+ s.summary = 'A Vagrant 1.6+ plugin extending WinRM communication features.'
12
+ s.description = 'A Vagrant 1.6+ plugin that adds new command to extends WinRM communication features.'
13
+ s.license = 'Apache 2.0'
14
+
15
+ s.required_rubygems_version = '>= 2.0.0'
16
+
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'rspec_junit_formatter'
19
+ s.add_development_dependency 'rspec-core', '~> 3.0.0'
20
+ s.add_development_dependency 'rspec-expectations', '~> 3.0.0'
21
+ s.add_development_dependency 'rspec-mocks', '~> 3.0.0'
22
+
23
+ s.add_development_dependency 'bundler', '>= 1.0.0'
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.executables = `git ls-files`.split("\n").map { |f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
27
+ s.require_path = 'lib'
28
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-winrm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Baptiste Courtois
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec_junit_formatter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-core
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-expectations
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0
97
+ description: A Vagrant 1.6+ plugin that adds new command to extends WinRM communication
98
+ features.
99
+ email:
100
+ - b.courtois@criteo.fr
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - lib/vagrant-winrm.rb
112
+ - lib/vagrant-winrm/commands/winrm.rb
113
+ - lib/vagrant-winrm/commands/winrm_config.rb
114
+ - lib/vagrant-winrm/commands/winrm_upload.rb
115
+ - lib/vagrant-winrm/errors.rb
116
+ - lib/vagrant-winrm/plugin.rb
117
+ - lib/version.rb
118
+ - locales/en.yml
119
+ - spec/spec_helper.rb
120
+ - spec/vagrant-winrm/commands/winrm_config_spec.rb
121
+ - spec/vagrant-winrm/commands/winrm_spec.rb
122
+ - spec/vagrant-winrm/commands/winrm_upload_spec.rb
123
+ - templates/winrm_config/config.erb
124
+ - vagrant-winrm.gemspec
125
+ homepage: https://gitlab.criteois.lan/ruby-gems/vagrant-winrm/
126
+ licenses:
127
+ - Apache 2.0
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 2.0.0
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.0.14
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A Vagrant 1.6+ plugin extending WinRM communication features.
149
+ test_files: []