nodespec 1.0.0 → 1.0.1

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: c521201ce3c84255c9eadcf6f4e120601f2c6782
4
- data.tar.gz: b5128627491fd84aae37789dca3560d77531284d
3
+ metadata.gz: f8247290f8693f24e63078e9d02fade2c040fe5f
4
+ data.tar.gz: c2e28b72b7015f6646632cbe6a0a7edacc4891bc
5
5
  SHA512:
6
- metadata.gz: 6e08d0e4dc3acf0545ec32f0e4ada934e7899df36d6225028995589b8a8ffa992dc2b19760afefa90faa2d55a9bfa973c13f47c41cb055a3af3bb32468f71ce7
7
- data.tar.gz: f5e3b4ae194e6f943ba560e33abb43d4bc823f0309f09d7e0a8bd2a4ce07077ee8a0f1fb106aba5cfc61cf8532a484a72edf2c394633f771dfb7f5becc9fabf4
6
+ metadata.gz: 20acb8ed594cbb3aca4648ddf7f2424c045ca9809e26b11211b08555173e053c15373ecda9c9ff6921416d45c330fea9ded126827e1eda9e53fe5c4342797188
7
+ data.tar.gz: f5a76255ea11a6d108c828f3f7555dfe91821bda499b13cd1c4b4afba26152fea42b933526f2876eded41b9705807b593acbe37fad674a1c656894a142960fe4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nodespec (1.0.0)
4
+ nodespec (1.0.1)
5
5
  net-ssh
6
6
  os
7
7
  serverspec (~> 2.3)
data/lib/nodespec.rb CHANGED
@@ -24,9 +24,9 @@ RSpec.configure do |config|
24
24
  property[:os] = nil # prevent os caching so we can switch os for any node test
25
25
  config.os = Specinfra::Helper::DetectOs.const_get(node.os).detect if node.os
26
26
 
27
- Specinfra.configuration.backend = node.backend
27
+ Specinfra.configuration.backend = node.communicator.backend
28
28
 
29
- node.communicator.bind_to(NodeSpec::ConfigurationBinding.new(config))
29
+ node.communicator.init_session(NodeSpec::ConfigurationBinding.new(config))
30
30
  end
31
31
  end
32
32
  end
@@ -13,9 +13,9 @@ module NodeSpec
13
13
 
14
14
  raise "EC2 Instance #{instance_name} is not reachable" unless ec2_instance.exists? && ec2_instance.status == :running
15
15
  if options.has_key?('winrm')
16
- WinrmCommunicator.new(ec2_instance.public_dns_name, options['winrm'])
16
+ WinrmCommunicator.new(ec2_instance.public_ip_address, options['winrm'])
17
17
  else
18
- SshCommunicator.new(ec2_instance.public_dns_name, options['ssh'] || {})
18
+ SshCommunicator.new(ec2_instance.public_ip_address, options['ssh'] || {})
19
19
  end
20
20
  end
21
21
  end
@@ -7,7 +7,7 @@ module NodeSpec
7
7
  class NativeCommunicator
8
8
  include VerboseOutput
9
9
 
10
- def bind_to(configuration)
10
+ def init_session(configuration)
11
11
  configuration.unbind_ssh_session
12
12
  configuration.unbind_winrm_session
13
13
  verbose_puts "\nRunning on local host..."
@@ -17,10 +17,10 @@ module NodeSpec
17
17
  end
18
18
  end
19
19
 
20
- def bind_to(configuration)
20
+ def init_session(configuration)
21
21
  configuration.unbind_winrm_session
22
22
 
23
- @session = configuration.bind_ssh_session_for(@host, @ssh_options[:port]) do
23
+ @session = configuration.bind_ssh_session_for({host: @host, port: @ssh_options[:port]}) do
24
24
  msg = "\nConnecting to #{@host}"
25
25
  msg << ":#{@ssh_options[:port]}" if @ssh_options[:port]
26
26
  msg << " as #{@user}..."
@@ -29,10 +29,10 @@ module NodeSpec
29
29
  @options = @options.inject({}) {|h,(k,v)| h[k.to_sym] = v; h}
30
30
  end
31
31
 
32
- def bind_to(configuration)
32
+ def init_session(configuration)
33
33
  configuration.unbind_ssh_session
34
34
 
35
- @session = configuration.bind_winrm_session_for(@host, @endpoint) do
35
+ @session = configuration.bind_winrm_session_for({host: @host, endpoint: @endpoint}) do
36
36
  RuntimeGemLoader.require_or_fail('winrm') do
37
37
  verbose_puts "\nConnecting to #{@endpoint}..."
38
38
  WinRM::WinRMWebService.new(@endpoint, @transport, @options)
@@ -4,31 +4,24 @@ module NodeSpec
4
4
  class ConfigurationBinding
5
5
  include VerboseOutput
6
6
 
7
+ BACKEND_ACTIONS = {
8
+ ssh: {
9
+ diff_session: lambda { |ssh, params| ssh.host != params[:host] || ssh.options[:port] != params[:port] },
10
+ bind_attributes: lambda { |ssh, config| config.ssh_options = ssh.options }
11
+ },
12
+ winrm: {
13
+ diff_session: lambda { |winrm, params| winrm.endpoint != params[:endpoint] }
14
+ }
15
+ }
16
+
7
17
  def initialize(configuration)
8
18
  @configuration = configuration
9
19
  end
10
20
 
11
- def bind_ssh_session_for(host, port)
12
- current_session = @configuration.ssh
13
- if current_session.nil? || current_session.host != host || current_session.options[:port] != port
14
- unbind_ssh_session
15
- current_session = yield
16
- @configuration.ssh = current_session
17
- @configuration.ssh_options = current_session.options
18
- @configuration.host = current_session.host
19
- end
20
- current_session
21
- end
22
-
23
- def bind_winrm_session_for(host, endpoint)
24
- current_session = @configuration.winrm
25
- if current_session.nil? || current_session.endpoint != endpoint
26
- unbind_winrm_session
27
- current_session = yield
28
- @configuration.winrm = current_session
29
- @configuration.host = host
21
+ BACKEND_ACTIONS.keys.each do |backend|
22
+ define_method("bind_#{backend}_session_for") do |params, &block|
23
+ bind_session_for(backend, params, &block)
30
24
  end
31
- current_session
32
25
  end
33
26
 
34
27
  def unbind_ssh_session
@@ -42,7 +35,22 @@ module NodeSpec
42
35
  end
43
36
 
44
37
  def unbind_winrm_session
38
+ verbose_puts "\nClosing connection to #{@configuration.winrm.endpoint}" if @configuration.winrm
45
39
  @configuration.winrm = @configuration.host = nil
46
40
  end
41
+
42
+ private
43
+
44
+ def bind_session_for(backend, params)
45
+ current_session = @configuration.send(backend)
46
+ if current_session.nil? || BACKEND_ACTIONS[backend][:diff_session].call(current_session, params)
47
+ send("unbind_#{backend}_session")
48
+ current_session = yield
49
+ @configuration.send("#{backend}=", current_session)
50
+ @configuration.host = params[:host]
51
+ BACKEND_ACTIONS[backend][:bind_attributes].call(current_session, @configuration) if BACKEND_ACTIONS[backend][:bind_attributes]
52
+ end
53
+ current_session
54
+ end
47
55
  end
48
56
  end
data/lib/nodespec/node.rb CHANGED
@@ -15,10 +15,6 @@ module NodeSpec
15
15
  @communicator = CommunicationAdapters.get_communicator(@name, adapter_name, opts)
16
16
  end
17
17
 
18
- def backend
19
- @communicator.backend
20
- end
21
-
22
18
  [:create_directory, :create_file].each do |met|
23
19
  define_method(met) do |*args|
24
20
  path_argument = args.shift
@@ -1,3 +1,3 @@
1
1
  module NodeSpec
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -17,12 +17,12 @@ module NodeSpec
17
17
  before do
18
18
  allow(ec2_instance).to receive(:exists?).ordered.and_return(true)
19
19
  allow(ec2_instance).to receive(:status).ordered.and_return(:running)
20
- allow(ec2_instance).to receive(:public_dns_name).ordered.and_return('test.host.name')
20
+ allow(ec2_instance).to receive(:public_ip_address).ordered.and_return('ip_address')
21
21
  end
22
22
 
23
23
  %w[ssh winrm].each do |connection|
24
24
  describe "#{connection} communicator" do
25
- include_context "new_#{connection}_communicator", 'test.host.name', 'foo' => 'bar'
25
+ include_context "new_#{connection}_communicator", 'ip_address', 'foo' => 'bar'
26
26
 
27
27
  it 'returns communicator with the instance name from the node name' do
28
28
  expect(AwsEc2.communicator_for('test-instance', connection => {'foo' => 'bar'})).to eq("#{connection} communicator")
@@ -35,7 +35,7 @@ module NodeSpec
35
35
  end
36
36
 
37
37
  describe 'openssh default connection' do
38
- include_context "new_ssh_communicator", 'test.host.name', {}
38
+ include_context "new_ssh_communicator", 'ip_address', {}
39
39
 
40
40
  it 'returns an ssh communicator' do
41
41
  expect(AwsEc2.communicator_for('test-instance')).to eq("ssh communicator")
@@ -21,13 +21,13 @@ module NodeSpec
21
21
  end
22
22
  end
23
23
 
24
- describe '#bind_to' do
24
+ describe '#init_session' do
25
25
  let(:configuration) {double('configuration')}
26
26
 
27
27
  it 'unbinds other sessions' do
28
28
  expect(configuration).to receive(:unbind_ssh_session)
29
29
  expect(configuration).to receive(:unbind_winrm_session)
30
- subject.bind_to(configuration)
30
+ subject.init_session(configuration)
31
31
  end
32
32
  end
33
33
  end
@@ -10,30 +10,22 @@ module NodeSpec
10
10
  before do
11
11
  expect(configuration).to receive(:unbind_winrm_session)
12
12
  allow(Net::SSH).to receive(:start).with(hostname, 'testuser', options).and_return('session')
13
- allow(configuration).to receive(:bind_ssh_session_for) do |host, port, &block|
14
- expect(host).to eq hostname
15
- expect(port).to eq port
13
+ allow(configuration).to receive(:bind_ssh_session_for) do |params, &block|
14
+ expect(params[:host]).to eq hostname
15
+ expect(params[:port]).to eq options[:port]
16
16
  block.call
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- shared_examples 'binding session' do
22
- it 'returns a session' do
23
- subject.bind_to(configuration)
24
-
25
- expect(subject.session).to eq('session')
26
- end
27
- end
28
-
29
- describe 'binding the session' do
21
+ describe 'init the session' do
30
22
  context 'default options' do
31
23
  subject {SshCommunicator.new('test.host.name')}
32
24
  before do
33
25
  allow(Net::SSH).to receive(:configuration_for).and_return({someoption: 'somevalue', user: 'testuser'})
34
26
  end
35
27
  include_context 'creating new session', 'test.host.name', someoption: 'somevalue', user: 'testuser'
36
- include_examples 'binding session'
28
+ include_examples 'initializing communicator session'
37
29
  end
38
30
 
39
31
  context 'custom options' do
@@ -42,17 +34,17 @@ module NodeSpec
42
34
  allow(Net::SSH).to receive(:configuration_for).and_return({someoption: 'somevalue', port: 22, user: 'testuser'})
43
35
  end
44
36
  include_context 'creating new session', 'test.host.name', someoption: 'somevalue', port: 1234, user: 'testuser', password: 'testpassword', keys: 'testkeys'
45
- include_examples 'binding session'
37
+ include_examples 'initializing communicator session'
46
38
  end
47
39
 
48
40
  context 'same session' do
49
41
  subject {SshCommunicator.new('test.host.name', 'port' => 1234, 'user' => 'testuser')}
50
42
  before do
51
43
  expect(configuration).to receive(:unbind_winrm_session)
52
- allow(configuration).to receive(:bind_ssh_session_for).with('test.host.name', 1234).and_return('session')
44
+ allow(configuration).to receive(:bind_ssh_session_for).with({host: 'test.host.name', port: 1234}).and_return('session')
53
45
  end
54
46
 
55
- include_examples 'binding session'
47
+ include_examples 'initializing communicator session'
56
48
  end
57
49
  end
58
50
 
@@ -10,43 +10,35 @@ module NodeSpec
10
10
  before do
11
11
  expect(configuration).to receive(:unbind_ssh_session)
12
12
  allow(WinRM::WinRMWebService).to receive(:new).with("http://#{hostname}:#{port}/wsman", transport, options).and_return('session')
13
- allow(configuration).to receive(:bind_winrm_session_for) do |host, endpoint, &block|
14
- expect(host).to eq hostname
15
- expect(endpoint).to eq "http://#{hostname}:#{port}/wsman"
13
+ allow(configuration).to receive(:bind_winrm_session_for) do |params, &block|
14
+ expect(params[:host]).to eq hostname
15
+ expect(params[:endpoint]).to eq "http://#{hostname}:#{port}/wsman"
16
16
  block.call
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- shared_examples 'binding session' do
22
- it 'returns a session' do
23
- subject.bind_to(configuration)
24
-
25
- expect(subject.session).to eq('session')
26
- end
27
- end
28
-
29
- describe 'binding the session' do
21
+ describe 'init the session' do
30
22
  context 'default port and transport' do
31
23
  subject {WinrmCommunicator.new('test.host.name', 'foo' => 'bar')}
32
24
  include_context 'creating new session', 'test.host.name', 5985, :plaintext, {foo: 'bar', disable_sspi: true}
33
- include_examples 'binding session'
25
+ include_examples 'initializing communicator session'
34
26
  end
35
27
 
36
28
  context 'custom port and transport' do
37
29
  subject {WinrmCommunicator.new('test.host.name', 'port' => 1234, 'transport' => 'test_transport', 'foo' => 'bar')}
38
30
  include_context 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar'}
39
- include_examples 'binding session'
31
+ include_examples 'initializing communicator session'
40
32
  end
41
33
 
42
34
  context 'same session' do
43
35
  subject {WinrmCommunicator.new('test.host.name', 'foo' => 'bar')}
44
36
  before do
45
37
  expect(configuration).to receive(:unbind_ssh_session)
46
- allow(configuration).to receive(:bind_winrm_session_for).with('test.host.name', "http://test.host.name:5985/wsman").and_return('session')
38
+ allow(configuration).to receive(:bind_winrm_session_for).with({host: 'test.host.name', endpoint: "http://test.host.name:5985/wsman"}).and_return('session')
47
39
  end
48
40
 
49
- include_examples 'binding session'
41
+ include_examples 'initializing communicator session'
50
42
  end
51
43
  end
52
44
 
@@ -17,7 +17,7 @@ module NodeSpec
17
17
  expect(configuration).to receive(:ssh_options=).with({port: 1234})
18
18
  expect(configuration).to receive(:host=).with('test.host.name')
19
19
 
20
- session = subject.bind_ssh_session_for('test.host.name', 1234) {new_session}
20
+ session = subject.bind_ssh_session_for({host: 'test.host.name', port: 1234}) {new_session}
21
21
  expect(session).to be(new_session)
22
22
  end
23
23
  end
@@ -75,7 +75,7 @@ module NodeSpec
75
75
  end
76
76
 
77
77
  it 'does not change the exisintg session' do
78
- session = subject.bind_ssh_session_for('test.host.name', 1234) {new_session}
78
+ session = subject.bind_ssh_session_for({host: 'test.host.name', port: 1234}) {new_session}
79
79
  expect(session).to be(existing_session)
80
80
  end
81
81
  end
@@ -104,7 +104,7 @@ module NodeSpec
104
104
  expect(configuration).to receive(:winrm=).with(new_session)
105
105
  expect(configuration).to receive(:host=).with('test.host.name')
106
106
 
107
- session = subject.bind_winrm_session_for('test.host.name', 'test.endpoint') {new_session}
107
+ session = subject.bind_winrm_session_for({host: 'test.host.name', endpoint: 'test.endpoint'}) {new_session}
108
108
  expect(session).to be(new_session)
109
109
  end
110
110
  end
@@ -147,7 +147,7 @@ module NodeSpec
147
147
  end
148
148
 
149
149
  it 'does not change the exisintg session' do
150
- session = subject.bind_winrm_session_for('test.host.name', 'test.endpoint') {new_session}
150
+ session = subject.bind_winrm_session_for({host: 'test.host.name', endpoint: 'test.endpoint'}) {new_session}
151
151
  expect(session).to be(existing_session)
152
152
  end
153
153
  end
@@ -155,6 +155,7 @@ module NodeSpec
155
155
 
156
156
  describe '#unbind_winrm_session' do
157
157
  before do
158
+ expect(configuration).to receive(:winrm)
158
159
  expect(configuration).to receive(:winrm=).with(nil)
159
160
  expect(configuration).to receive(:host=).with(nil)
160
161
  end
@@ -20,4 +20,12 @@ shared_examples 'new_communicator' do |adapter_clazz, connection|
20
20
  it 'returns communicator with the host name from the options' do
21
21
  expect(adapter_clazz.communicator_for('test_node', 'host' => 'test.host.name', 'foo' => 'bar')).to eq("#{connection} communicator")
22
22
  end
23
- end
23
+ end
24
+
25
+ shared_examples 'initializing communicator session' do
26
+ it 'returns a session' do
27
+ subject.init_session(configuration)
28
+
29
+ expect(subject.session).to eq('session')
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nodespec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvio Montanari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -207,7 +207,7 @@ files:
207
207
  - spec/runtime_gem_loader_spec.rb
208
208
  - spec/spec_helper.rb
209
209
  - spec/support/backend.rb
210
- - spec/support/communicator_adapters.rb
210
+ - spec/support/communication_adapters.rb
211
211
  - spec/support/init_with_current_node.rb
212
212
  - spec/support/local_command.rb
213
213
  - spec/support/node_command.rb
@@ -263,7 +263,7 @@ test_files:
263
263
  - spec/runtime_gem_loader_spec.rb
264
264
  - spec/spec_helper.rb
265
265
  - spec/support/backend.rb
266
- - spec/support/communicator_adapters.rb
266
+ - spec/support/communication_adapters.rb
267
267
  - spec/support/init_with_current_node.rb
268
268
  - spec/support/local_command.rb
269
269
  - spec/support/node_command.rb