specinfra 1.18.3 → 1.18.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bf80a1d196b4626e0c11c472722e9b4031b1b82
4
- data.tar.gz: f00d376640817bc57efc20e02f260ce3ba0490a4
3
+ metadata.gz: a8317b4e00efd9907dddad5e4d1340efac89d245
4
+ data.tar.gz: 0b54192a51afecf9c70db4dafb49a82a43cf924f
5
5
  SHA512:
6
- metadata.gz: 8debd47886f2ad58a2745b5b5ba918f2ffa59641bb8a4ff832a6217e26394c195732cfec39d1caec87a9296a7d4698c143cc2eb2e09f24c01156e18b766b954a
7
- data.tar.gz: 83b73b2092f2ffe5969837dc7ac8cdcd7cb2017434452a4cb563ccaef1118d2264d3575642bf07beeb928f9919031103348cbef0ff9bca7545232a1c96669fba
6
+ metadata.gz: cdf9c71716d2d99b75c8c4933cac891e7a44a1dea10df3eb65f243d153ba4d9b4b75482d1a4e710dff06b687c72b3dc39cc4ecd58e72773ed730734fd0d7bab8
7
+ data.tar.gz: ab98c78e4600c2c099c9cc2dc0fdf910d44f7a54d83a0589cb6636f58c1ec2562972838058424080aa6a9649324170fd8f200a85052a00db99b739f7d54d5024
@@ -2,8 +2,8 @@ module SpecInfra
2
2
  module Command
3
3
  class Fedora < RedHat
4
4
  def check_enabled(service, target="multi-user.target")
5
- host = SpecInfra.configuration.ssh ? SpecInfra.configuration.ssh.host : 'localhost'
6
- if property.has_key?(:os_by_host) && property[:os_by_host][host][:release].to_i < 15
5
+ host_port = SpecInfra.configuration.ssh ? [SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]] : ['localhost', nil]
6
+ if property.has_key?(:os_by_host) && property[:os_by_host][host_port][:release].to_i < 15
7
7
  super
8
8
  else
9
9
  # Fedora 15+ uses systemd which no longer has runlevels but targets
@@ -17,8 +17,8 @@ module SpecInfra
17
17
  end
18
18
 
19
19
  def check_running(service)
20
- host = SpecInfra.configuration.ssh ? SpecInfra.configuration.ssh.host : 'localhost'
21
- if property.has_key?(:os_by_host) && property[:os_by_host][host][:release].to_i < 15
20
+ host_port = SpecInfra.configuration.ssh ? [SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]] : ['localhost', nil]
21
+ if property.has_key?(:os_by_host) && property[:os_by_host][host_port][:release].to_i < 15
22
22
  super
23
23
  else
24
24
  "systemctl is-active #{escape(service)}.service"
@@ -7,18 +7,29 @@ module SpecInfra
7
7
 
8
8
  def os
9
9
  property[:os_by_host] = {} if ! property[:os_by_host]
10
- host = SpecInfra.configuration.ssh ? SpecInfra.configuration.ssh.host : 'localhost'
10
+ host_port = current_host_and_port
11
11
 
12
- if property[:os_by_host][host]
13
- os_by_host = property[:os_by_host][host]
12
+ if property[:os_by_host][host_port]
13
+ os_by_host = property[:os_by_host][host_port]
14
14
  else
15
15
  # Set command object explicitly to avoid `stack too deep`
16
16
  os_by_host = backend(SpecInfra::Command::Base.new).check_os
17
- property[:os_by_host][host] = os_by_host
17
+ property[:os_by_host][host_port] = os_by_host
18
18
  end
19
19
 
20
20
  os_by_host
21
21
  end
22
+
23
+ private
24
+
25
+ # put this in a module for better reuse
26
+ def current_host_and_port
27
+ if SpecInfra.configuration.ssh
28
+ [SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]]
29
+ else
30
+ ['localhost', nil]
31
+ end
32
+ end
22
33
  end
23
34
  end
24
- end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module SpecInfra
2
- VERSION = "1.18.3"
2
+ VERSION = "1.18.4"
3
3
  end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpecInfra::Helper::DetectOS do
4
+ shared_context 'no ssh connection' do
5
+ before do
6
+ SpecInfra.stub_chain(:configuration, :ssh).and_return(nil)
7
+ end
8
+ end
9
+ shared_context 'existing ssh connection' do |hostname, port|
10
+ before do
11
+ ssh_session.stub(:host).and_return(hostname)
12
+ ssh_session.stub(:options).and_return({:port => port})
13
+ SpecInfra.stub_chain(:configuration, :ssh).and_return(ssh_session)
14
+ end
15
+ end
16
+ shared_examples 'derive os from backend' do |os|
17
+ before do
18
+ backend.stub(:check_os).and_return(os)
19
+ end
20
+
21
+ it 'returns the os derived by the backend ' do
22
+ expect(subject.os).to eq os
23
+ end
24
+ end
25
+ shared_examples 'derive os from cached property' do |os|
26
+ it 'returns the os derived by the property ' do
27
+ expect(subject.os).to eq os
28
+ end
29
+ end
30
+
31
+ let(:subject) { Object.new.extend SpecInfra::Helper::DetectOS }
32
+ let(:backend) { double('backend') }
33
+ let(:ssh_session) { double('ssh') }
34
+
35
+ before do
36
+ subject.stub(:backend).and_return(backend)
37
+ end
38
+
39
+ describe '#os' do
40
+ context 'using the backend to retrieve the os' do
41
+ context 'no cached values' do
42
+ before do
43
+ subject.property[:os_by_host] = nil
44
+ end
45
+
46
+ context 'with localhost' do
47
+ include_context 'no ssh connection'
48
+ after do
49
+ expect(subject.property[:os_by_host]).to eq({['localhost', nil] => 'test os'})
50
+ end
51
+
52
+ include_examples 'derive os from backend', 'test os'
53
+ end
54
+
55
+ context 'with ssh' do
56
+ include_context 'existing ssh connection', 'test.host', 123
57
+ after do
58
+ expect(subject.property[:os_by_host]).to eq({['test.host', 123] => 'test os'})
59
+ end
60
+
61
+ include_examples 'derive os from backend', 'test os'
62
+ end
63
+ end
64
+
65
+ context 'existing cached values' do
66
+ before do
67
+ subject.property[:os_by_host] = {['test.host', 123] => 'cached os'}
68
+ end
69
+
70
+ context 'with localhost' do
71
+ include_context 'no ssh connection'
72
+ after do
73
+ expect(property[:os_by_host]).to eq({['test.host', 123] => 'cached os', ['localhost', nil] => 'test os'})
74
+ end
75
+
76
+ include_examples 'derive os from backend', 'test os'
77
+ end
78
+
79
+ context 'with ssh' do
80
+ include_context 'existing ssh connection', 'test.another.host', 456
81
+ after do
82
+ expect(property[:os_by_host]).to eq({['test.host', 123] => 'cached os', ['test.another.host', 456] => 'test os'})
83
+ end
84
+
85
+ include_examples 'derive os from backend', 'test os'
86
+ end
87
+
88
+ context 'same host with different ports' do
89
+ include_context 'existing ssh connection', 'test.host', 456
90
+
91
+ after do
92
+ subject.property[:os_by_host] = {['test.host', 123] => 'cached os', ['test.host', 456] => 'test os'}
93
+ end
94
+
95
+ include_examples 'derive os from backend', 'test os'
96
+ end
97
+ end
98
+ end
99
+
100
+ context 'using cached values to retrieve the os' do
101
+ before do
102
+ subject.property[:os_by_host] = {['test.host', 123] => 'test os', ['localhost', nil] => 'local os'}
103
+ end
104
+ context 'with localhost' do
105
+ include_context 'no ssh connection'
106
+
107
+ include_examples 'derive os from cached property', 'local os'
108
+ end
109
+
110
+ context 'with ssh' do
111
+ include_context 'existing ssh connection', 'test.host', 123
112
+
113
+ include_examples 'derive os from cached property', 'test os'
114
+ end
115
+ end
116
+ end
117
+ 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: 1.18.3
4
+ version: 1.18.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - spec/backend/ssh/build_command_spec.rb
133
133
  - spec/configuration_spec.rb
134
134
  - spec/helper/backend_spec.rb
135
+ - spec/helper/detect_os_spec.rb
135
136
  - spec/helper/properties_spec.rb
136
137
  - spec/spec_helper.rb
137
138
  - specinfra.gemspec
@@ -165,5 +166,6 @@ test_files:
165
166
  - spec/backend/ssh/build_command_spec.rb
166
167
  - spec/configuration_spec.rb
167
168
  - spec/helper/backend_spec.rb
169
+ - spec/helper/detect_os_spec.rb
168
170
  - spec/helper/properties_spec.rb
169
171
  - spec/spec_helper.rb