specinfra 2.13.1 → 2.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b8d53c88f5f7856146564c19b8a07297077b84e
4
- data.tar.gz: ffd058dbb01359c42d382cc70ce4b4f127a51374
3
+ metadata.gz: 7f078db8f071c4f138453bcdb382e170c3c6ea9f
4
+ data.tar.gz: d0775ad341f116f542f01f10a7389b9354f6c952
5
5
  SHA512:
6
- metadata.gz: 069336fcfc1fb59d91de7a870f506ae4119a3f49df4372a2ea8ac959489b62af7de002e7e251aee34098e1db291a9c89056778dacadf9866f590a529d60c7337
7
- data.tar.gz: 3afd026657eb256a84c69049380707e2708b2d73ede8d3e9c1a09f38566e8d47292e5839401d3ef45e8051a6c370fca7424d71b6a63998860b22109468135d03
6
+ metadata.gz: 5d1f097db93f0da16a44dc0644e1fccf9c6147c15c22cfd8964fe9b3bc7969b42b42f6b057d6fa7db72a590c7c1871317ed66765bdf7cb7cb710cc1087e2be76
7
+ data.tar.gz: caca16b97fa5da5efdaad2a6702bf8058773df78d99c555718350ba04970a2d979842e6915be87d024b2d685fa5618e61fc9b2df9c27f407c83a938aa2a5ba2b
@@ -0,0 +1,109 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'specinfra/backend/exec'
3
+ require 'net/telnet'
4
+
5
+ module Specinfra::Backend
6
+ class Telnet < Exec
7
+ def run_command(cmd, opt={})
8
+ cmd = build_command(cmd)
9
+ cmd = add_pre_command(cmd)
10
+ ret = with_env do
11
+ telnet_exec!(cmd)
12
+ end
13
+ if @example
14
+ @example.metadata[:command] = cmd
15
+ @example.metadata[:stdout] = ret[:stdout]
16
+ end
17
+
18
+ CommandResult.new ret
19
+ end
20
+
21
+ def build_command(cmd)
22
+ cmd = super(cmd)
23
+ cmd
24
+ end
25
+
26
+ private
27
+ def prompt
28
+ 'Login: '
29
+ end
30
+
31
+ def with_env
32
+ env = Specinfra.configuration.env || {}
33
+ env[:LANG] ||= 'C'
34
+
35
+ env.each do |key, value|
36
+ key = key.to_s
37
+ ENV["_SPECINFRA_#{key}"] = ENV[key];
38
+ ENV[key] = value
39
+ end
40
+
41
+ yield
42
+ ensure
43
+ env.each do |key, value|
44
+ key = key.to_s
45
+ ENV[key] = ENV.delete("_SPECINFRA_#{key}");
46
+ end
47
+ end
48
+
49
+ def add_pre_command(cmd)
50
+ if Specinfra.configuration.pre_command
51
+ pre_cmd = build_command(Specinfra.configuration.pre_command)
52
+ "#{pre_cmd} && #{cmd}"
53
+ else
54
+ cmd
55
+ end
56
+ end
57
+
58
+ def telnet_exec!( command )
59
+ stdout_data = ''
60
+ stderr_data = ''
61
+ exit_status = nil
62
+ exit_signal = nil
63
+ retry_prompt = /^Login: /
64
+ if Specinfra.configuration.telnet.nil?
65
+ Specinfra.configuration.telnet = create_telnet
66
+ end
67
+ telnet = Specinfra.configuration.telnet
68
+ re = []
69
+ unless telnet.nil?
70
+ re = telnet.cmd( "#{command}; echo $?" ).split("\n")[0..-2]
71
+ exit_status = re.last.to_i
72
+ stdout_data = re[1..-2].join("\n")
73
+ end
74
+ { :stdout => stdout_data, :stderr => stderr_data, :exit_status => exit_status, :exit_signal => exit_signal }
75
+ end
76
+
77
+ def create_telnet
78
+ tel = Net::Telnet.new( "Host" => Specinfra.configuration.host )
79
+ tel.login(
80
+ "Name" => Specinfra.configuration.telnet_options[:user],
81
+ "Password" => Specinfra.configuration.telnet_options[:pass]
82
+ )
83
+ tel
84
+ rescue
85
+ return nil
86
+ end
87
+
88
+ def sudo
89
+ if sudo_path = Specinfra.configuration.sudo_path
90
+ sudo_path += '/sudo'
91
+ else
92
+ sudo_path = 'sudo'
93
+ end
94
+
95
+ sudo_options = Specinfra.configuration.sudo_options
96
+ if sudo_options
97
+ sudo_options = sudo_options.shelljoin if sudo_options.is_a?(Array)
98
+ sudo_options = ' ' + sudo_options
99
+ end
100
+
101
+ "#{sudo_path.shellescape}#{sudo_options}"
102
+ end
103
+
104
+ def sudo?
105
+ false
106
+ end
107
+
108
+ end
109
+ end
@@ -9,3 +9,4 @@ require 'specinfra/backend/lxc'
9
9
  require 'specinfra/backend/winrm'
10
10
  require 'specinfra/backend/shell_script'
11
11
  require 'specinfra/backend/dockerfile'
12
+ require 'specinfra/backend/telnet'
@@ -7,6 +7,13 @@ class Specinfra::Command::Base::Package < Specinfra::Command::Base
7
7
  cmd
8
8
  end
9
9
 
10
+ def check_is_installed_by_rvm(name, version=nil)
11
+ regexp = "^#{name}"
12
+ cmd = "rvm list strings | grep -iw -- #{escape(regexp)}"
13
+ cmd = "#{cmd} | grep -w -- #{escape(version)}" if version
14
+ cmd
15
+ end
16
+
10
17
  def check_is_installed_by_npm(name, version=nil)
11
18
  cmd = "npm ls #{escape(name)} -g"
12
19
  cmd = "#{cmd} | grep -w -- #{escape(version)}" if version
@@ -19,6 +19,7 @@ module Specinfra
19
19
  :request_pty,
20
20
  :ssh_options,
21
21
  :dockerfile_finalizer,
22
+ :telnet_options,
22
23
  ].freeze
23
24
 
24
25
  def defaults
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.13.1"
2
+ VERSION = "2.14.0"
3
3
  end
@@ -5,3 +5,7 @@ set :os, { :family => nil }
5
5
  describe get_command(:check_package_is_installed_by_gem, 'serverspec', '2.0.0') do
6
6
  it { should eq 'gem list --local | grep -iw -- \\^serverspec | grep -w -- "[( ]2.0.0[,)]"' }
7
7
  end
8
+
9
+ describe get_command(:check_package_is_installed_by_rvm, 'rbx', '2.4.1') do
10
+ it { should eq 'rvm list strings | grep -iw -- \\^rbx | grep -w -- 2.4.1' }
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.1
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-13 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -134,6 +134,7 @@ files:
134
134
  - lib/specinfra/backend/powershell/support/list_windows_features.ps1
135
135
  - lib/specinfra/backend/shell_script.rb
136
136
  - lib/specinfra/backend/ssh.rb
137
+ - lib/specinfra/backend/telnet.rb
137
138
  - lib/specinfra/backend/winrm.rb
138
139
  - lib/specinfra/command.rb
139
140
  - lib/specinfra/command/aix.rb