remote-exec 0.5.0 → 0.6.0
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.
- checksums.yaml +4 -4
- data/lib/remote-exec.rb +10 -4
- data/lib/remote-exec/base.rb +70 -0
- data/lib/{remote_exec → remote-exec}/fake.rb +11 -5
- data/lib/{remote_exec → remote-exec}/local.rb +9 -3
- data/lib/{remote_exec → remote-exec}/ssh.rb +11 -12
- data/lib/remote-exec/version.rb +11 -0
- data/test/{remote_exec → remote-exec}/fake_test.rb +1 -1
- data/test/{remote_exec → remote-exec}/local_test.rb +1 -1
- data/test/{remote_exec → remote-exec}/ssh_test.rb +3 -4
- metadata +43 -43
- data/lib/remote_exec/base.rb +0 -70
- data/lib/remote_exec/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 800fd883b998fcc94053517f9bf51024abb432dc
|
4
|
+
data.tar.gz: f45137d8cd9ba56550ab77f572c502821cc818e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6860b263ee359578a023e7068e6d44b3b6767b39af3b1f9479739f32b4c2d84ba5586e46f1f8841c615f3490666a97294168b795ce224c9aa68c41540c217435
|
7
|
+
data.tar.gz: 9637678910d64aa18f0299bcc32938520ea23b9c77f2f4a35c6915885912f9a426c01d6b137a107f95726956adb16aa0140262f29213a181397aaf7246469692
|
data/lib/remote-exec.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
7
|
+
require "remote-exec/version"
|
8
|
+
require "remote-exec/fake"
|
9
|
+
require "remote-exec/local"
|
10
|
+
require "remote-exec/ssh"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
7
|
+
require 'ruby-hooks'
|
8
|
+
require "remote-exec/version"
|
9
|
+
|
10
|
+
# Define minimal interface for execution handlers
|
11
|
+
class RemoteExec::Base
|
12
|
+
extend RubyHooks::InstanceHooks
|
13
|
+
|
14
|
+
# called before connection attempt will be made, used when connection may fail
|
15
|
+
# @notify_param object [Object] the target that invoked the method
|
16
|
+
define_hook :before_connect
|
17
|
+
|
18
|
+
# called when connection attempt failed and we are about to sleep and retry
|
19
|
+
# @notify_param object [Object] the target that invoked the method
|
20
|
+
# @notify_param exception [Exception] exception that made the connection attempt fail
|
21
|
+
# @notify_param retries [Integer] number of retries left
|
22
|
+
define_hook :on_connect_retry
|
23
|
+
|
24
|
+
# called when connection attempt failed and no more retries left
|
25
|
+
# @notify_param object [Object] the target that invoked the method
|
26
|
+
# @notify_param exception [Exception] exception that made the connection attempt fail
|
27
|
+
define_hook :on_connect_fail
|
28
|
+
|
29
|
+
# called after connection / session is esatablished
|
30
|
+
# @notify_param object [Object] the target that invoked the method
|
31
|
+
define_hook :after_connect
|
32
|
+
|
33
|
+
# called before terminating connection - only when needed
|
34
|
+
# @notify_param object [Object] the target that invoked the method
|
35
|
+
define_hook :before_shutdown
|
36
|
+
|
37
|
+
# called before executing command
|
38
|
+
# @notify_param object [Object] the target that invoked the method
|
39
|
+
# @notify_param command [String] the command to execute
|
40
|
+
define_hook :before_execute
|
41
|
+
|
42
|
+
# called before executing command
|
43
|
+
# @notify_param object [Object] the target that invoked the method
|
44
|
+
# @notify_param stdout [String] standard output of the command, can be nil
|
45
|
+
# @notify_param stderr [String] standard error output of the command, can be nil
|
46
|
+
define_hook :on_execute_data
|
47
|
+
|
48
|
+
# called after executing command
|
49
|
+
# @notify_param object [Object] the target that invoked the method
|
50
|
+
# @notify_param command [String] the executed command
|
51
|
+
# @notify_param result [Integer] the executed command status code (0 - ok, >0 - fail)
|
52
|
+
define_hook :after_execute
|
53
|
+
|
54
|
+
# standard in place handler that ensures shutdown is called
|
55
|
+
def initialize
|
56
|
+
if block_given?
|
57
|
+
begin
|
58
|
+
yield self
|
59
|
+
ensure
|
60
|
+
shutdown
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# minimal handler for shutdown
|
66
|
+
def shutdown
|
67
|
+
before_shutdown.changed_and_notify(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
7
|
+
require "remote-exec/base"
|
2
8
|
|
3
9
|
# Class to fake running commands and transfering files.
|
4
10
|
class RemoteExec::Fake < RemoteExec::Base
|
@@ -10,15 +16,15 @@ class RemoteExec::Fake < RemoteExec::Base
|
|
10
16
|
#
|
11
17
|
# [1, [[nil,"error\n"]]
|
12
18
|
#
|
13
|
-
#
|
19
|
+
# @return [Array] story to run in execute, format: [ return_status, [[ stdout, stderr],...] ]
|
14
20
|
|
15
21
|
attr_accessor :story
|
16
22
|
|
17
23
|
# Constructs a new Fake object.
|
18
24
|
#
|
19
|
-
# @yield
|
20
|
-
#
|
21
|
-
# remote connection
|
25
|
+
# @yield [self] if a block is given then the constructed object
|
26
|
+
# yields itself and calls `#shutdown` at the end,
|
27
|
+
# closing the remote connection
|
22
28
|
|
23
29
|
def initialize
|
24
30
|
after_connect.changed_and_notify(self)
|
@@ -1,5 +1,11 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
+
|
4
|
+
See the file LICENSE for copying permission.
|
5
|
+
=end
|
6
|
+
|
1
7
|
require 'session'
|
2
|
-
require "
|
8
|
+
require "remote-exec/base"
|
3
9
|
|
4
10
|
# Class to run local commands and transfer files localy.
|
5
11
|
class RemoteExec::Local < RemoteExec::Base
|
@@ -10,8 +16,8 @@ class RemoteExec::Local < RemoteExec::Base
|
|
10
16
|
#
|
11
17
|
# @param shell [String] name of the shell to run
|
12
18
|
# @yield [self] if a block is given then the constructed
|
13
|
-
#
|
14
|
-
# remote connection
|
19
|
+
# object yields itself and calls `#shutdown`
|
20
|
+
# at the end, closing the remote connection
|
15
21
|
|
16
22
|
def initialize(shell = "sh")
|
17
23
|
@shell = shell
|
@@ -8,8 +8,7 @@ License: https://github.com/test-kitchen/test-kitchen/blob/459238b88c/LICENSE
|
|
8
8
|
=end
|
9
9
|
|
10
10
|
require 'net/ssh'
|
11
|
-
require
|
12
|
-
require "remote_exec/base"
|
11
|
+
require "remote-exec/base"
|
13
12
|
|
14
13
|
# Class to help establish SSH connections, issue remote commands, and
|
15
14
|
# transfer files between a local system and remote node.
|
@@ -27,8 +26,8 @@ class RemoteExec::Ssh < RemoteExec::Base
|
|
27
26
|
# @param username [String] the username for the remote host
|
28
27
|
# @param options [Hash] configuration options for ssh
|
29
28
|
# @yield [self] if a block is given then the constructed
|
30
|
-
#
|
31
|
-
# remote connection
|
29
|
+
# object yields itself and calls `#shutdown`
|
30
|
+
# at the end, closing the remote connection
|
32
31
|
def initialize(hostname, username, options = {})
|
33
32
|
@hostname = hostname
|
34
33
|
@username = username
|
@@ -39,10 +38,10 @@ class RemoteExec::Ssh < RemoteExec::Base
|
|
39
38
|
# Shuts down the session connection, if it is still active.
|
40
39
|
def shutdown
|
41
40
|
super
|
42
|
-
return if @
|
43
|
-
|
41
|
+
return if @session.nil?
|
42
|
+
session.shutdown!
|
44
43
|
ensure
|
45
|
-
@
|
44
|
+
@session = nil
|
46
45
|
end
|
47
46
|
|
48
47
|
##
|
@@ -55,8 +54,8 @@ class RemoteExec::Ssh < RemoteExec::Base
|
|
55
54
|
# TODO: make it run in one session
|
56
55
|
@last_status = nil
|
57
56
|
@command = command
|
58
|
-
|
59
|
-
|
57
|
+
session.open_channel(&method(:execute_open_channel))
|
58
|
+
session.loop
|
60
59
|
@last_status
|
61
60
|
end
|
62
61
|
|
@@ -64,7 +63,7 @@ private
|
|
64
63
|
|
65
64
|
def execute_open_channel(channel)
|
66
65
|
before_execute.changed_and_notify(self, @command)
|
67
|
-
channel.request_pty
|
66
|
+
channel.request_pty unless options[:ssh_request_pty] == false
|
68
67
|
channel.exec(@command, &method(:execute_channel_exec))
|
69
68
|
channel.wait
|
70
69
|
after_execute.changed_and_notify(self, @command, @last_status)
|
@@ -93,8 +92,8 @@ private
|
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
|
-
def
|
97
|
-
@
|
95
|
+
def session
|
96
|
+
@session ||= establish_connection
|
98
97
|
end
|
99
98
|
|
100
99
|
RESCUE_EXCEPTIONS = [
|
@@ -8,7 +8,7 @@ License: https://github.com/test-kitchen/test-kitchen/blob/459238b88c/LICENSE
|
|
8
8
|
=end
|
9
9
|
|
10
10
|
require 'test_helper'
|
11
|
-
require '
|
11
|
+
require 'remote-exec/ssh'
|
12
12
|
require 'net/ssh/test'
|
13
13
|
|
14
14
|
module Net
|
@@ -70,7 +70,7 @@ describe RemoteExec::Ssh do
|
|
70
70
|
|
71
71
|
subject do
|
72
72
|
RemoteExec::Ssh.allocate.tap do |ssh|
|
73
|
-
ssh.instance_variable_set(:@
|
73
|
+
ssh.instance_variable_set(:@session, connection)
|
74
74
|
ssh.instance_variable_set(:@options, {})
|
75
75
|
end
|
76
76
|
end
|
@@ -98,7 +98,6 @@ describe RemoteExec::Ssh do
|
|
98
98
|
it "executes true" do
|
99
99
|
story do |session|
|
100
100
|
channel = session.opens_channel
|
101
|
-
channel.sends_request_pty
|
102
101
|
channel.sends_exec "true"
|
103
102
|
channel.gets_exit_status(0)
|
104
103
|
channel.gets_close
|
@@ -106,6 +105,7 @@ describe RemoteExec::Ssh do
|
|
106
105
|
end
|
107
106
|
|
108
107
|
assert_scripted do
|
108
|
+
subject.options[:ssh_request_pty] = false
|
109
109
|
subject.execute("true").must_equal 0
|
110
110
|
end
|
111
111
|
end
|
@@ -221,7 +221,6 @@ describe RemoteExec::Ssh do
|
|
221
221
|
@error_counter = ErrorCounter.new
|
222
222
|
Net::SSH.unstub(:start)
|
223
223
|
Net::SSH.stubs(:start).raises(klass)
|
224
|
-
subject.instance_variable_set(:@ssh, nil)
|
225
224
|
subject.options[:ssh_retries] = 2
|
226
225
|
end
|
227
226
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote-exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
@@ -16,113 +16,113 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: session
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: net-ssh
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.9'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.9'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '10.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '10.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: minitest
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '5.4'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '5.4'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: mocha
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '1.1'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
125
|
-
description:
|
124
|
+
version: '1.1'
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- mpapis@gmail.com
|
128
128
|
executables: []
|
@@ -130,14 +130,14 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- lib/remote-exec.rb
|
133
|
-
- lib/
|
134
|
-
- lib/
|
135
|
-
- lib/
|
136
|
-
- lib/
|
137
|
-
- lib/
|
138
|
-
- test/
|
139
|
-
- test/
|
140
|
-
- test/
|
133
|
+
- lib/remote-exec/base.rb
|
134
|
+
- lib/remote-exec/fake.rb
|
135
|
+
- lib/remote-exec/local.rb
|
136
|
+
- lib/remote-exec/ssh.rb
|
137
|
+
- lib/remote-exec/version.rb
|
138
|
+
- test/remote-exec/fake_test.rb
|
139
|
+
- test/remote-exec/local_test.rb
|
140
|
+
- test/remote-exec/ssh_test.rb
|
141
141
|
- test/test_helper.rb
|
142
142
|
homepage: https://github.com/remote-exec/remote-exec
|
143
143
|
licenses:
|
@@ -165,7 +165,7 @@ specification_version: 4
|
|
165
165
|
summary: Invoke commands on remote hosts
|
166
166
|
test_files:
|
167
167
|
- test/test_helper.rb
|
168
|
-
- test/
|
169
|
-
- test/
|
170
|
-
- test/
|
168
|
+
- test/remote-exec/local_test.rb
|
169
|
+
- test/remote-exec/fake_test.rb
|
170
|
+
- test/remote-exec/ssh_test.rb
|
171
171
|
has_rdoc:
|
data/lib/remote_exec/base.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright 2014 Michal Papis <mpapis@gmail.com>
|
3
|
-
|
4
|
-
See the file LICENSE for copying permission.
|
5
|
-
=end
|
6
|
-
|
7
|
-
require 'ruby/hooks'
|
8
|
-
require "remote_exec/version"
|
9
|
-
|
10
|
-
# Define minimal interface for execution handlers
|
11
|
-
class RemoteExec::Base
|
12
|
-
extend Ruby::Hooks::InstanceHooks
|
13
|
-
|
14
|
-
# called before connection attempt will be made, used when connection may fail
|
15
|
-
# @param object [Object] the target that invoked the method
|
16
|
-
define_hook :before_connect
|
17
|
-
|
18
|
-
# called when connection attempt failed and we are about to sleep and retry
|
19
|
-
# @param object [Object] the target that invoked the method
|
20
|
-
# @param exception [Exception] exception that made the connection attempt fail
|
21
|
-
# @param retries [Integer] number of retries left
|
22
|
-
define_hook :on_connect_retry
|
23
|
-
|
24
|
-
# called when connection attempt failed and we no more retries left
|
25
|
-
# @param object [Object] the target that invoked the method
|
26
|
-
# @param exception [Exception] exception that made the connection attempt fail
|
27
|
-
define_hook :on_connect_fail
|
28
|
-
|
29
|
-
# called after connection / session is esatablished
|
30
|
-
# @param object [Object] the target that invoked the method
|
31
|
-
define_hook :after_connect
|
32
|
-
|
33
|
-
# called before terminating connection - only when needed
|
34
|
-
# @param object [Object] the target that invoked the method
|
35
|
-
define_hook :before_shutdown
|
36
|
-
|
37
|
-
# called before executing command
|
38
|
-
# @param object [Object] the target that invoked the method
|
39
|
-
# @param command [String] the command to execute
|
40
|
-
define_hook :before_execute
|
41
|
-
|
42
|
-
# called before executing command
|
43
|
-
# @param object [Object] the target that invoked the method
|
44
|
-
# @param stdout [String] standard output of the command, can be nil
|
45
|
-
# @param stderr [String] standard error output of the command, can be nil
|
46
|
-
define_hook :on_execute_data
|
47
|
-
|
48
|
-
# called after executing command
|
49
|
-
# @param object [Object] the target that invoked the method
|
50
|
-
# @param command [String] the executed command
|
51
|
-
# @param result [Integer] the executed command status code (0 - ok, >0 - fail)
|
52
|
-
define_hook :after_execute
|
53
|
-
|
54
|
-
# standard in place handler that ensures shutdown is called
|
55
|
-
def initialize
|
56
|
-
if block_given?
|
57
|
-
begin
|
58
|
-
yield self
|
59
|
-
ensure
|
60
|
-
shutdown
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# minimal handler for shutdown
|
66
|
-
def shutdown
|
67
|
-
before_shutdown.changed_and_notify(self)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|