kitchen-nodes 0.4.1 → 0.5.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: c0ac0bec76ff5ea74db4a5108e2496f2da73abce
4
- data.tar.gz: 8a6a61cc1b3cfdb2aedf36fbaebe9e240ed1991a
3
+ metadata.gz: 4b8930d518f65a1dee4809dbb78e4ae736fe4541
4
+ data.tar.gz: aa20c8911a41adc5825ff1652c23bcf8f60181ed
5
5
  SHA512:
6
- metadata.gz: b802b58bcb5b36059cfc9da263a540fb4221627f48ab8bd52fde5f20f49d0c1165c96f158c743a35fcdf3f1dcd48f65c023c49c96b88b3c0075524633d5c78fd
7
- data.tar.gz: c6e999c8e2eb11768ce1300cd2f9448bfe0e537ef9b6fbbc0d72648d44b40a4275cef99beeb720af5d8a672d7fa518ee4e997677cfbac35d82fadf17f0a7b653
6
+ metadata.gz: 49add0cf3e506a17bbcee92212ac72b38629141c25e3d3c23333540736b255f49c8a000304dd27aa07b5195926e1b2ead7926fc847225470fd407109316a78f2
7
+ data.tar.gz: ef5e99b812d19f73495d89f2d8d208a1aab8159a938c19a285fef8e2527723aa74c0cc31140ed68b3c4a881281d49bb1f150bd5714221bcca870a52c904a7455
data/.gitignore CHANGED
@@ -2,7 +2,9 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .kitchen/
5
6
  .yardoc
7
+ Berksfile.lock
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
data/.kitchen.yml ADDED
@@ -0,0 +1,41 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+ network:
5
+ - ["private_network", { type: "dhcp" }]
6
+
7
+ provisioner:
8
+ name: nodes
9
+
10
+ platforms:
11
+ - name: ubuntu-12.04
12
+ run_list:
13
+ - recipe[apt]
14
+ driver_config:
15
+ box: hashicorp/precise64
16
+
17
+ - name: windows-2012R2
18
+ driver_config:
19
+ gui: true
20
+ box: mwrock/Windows2012R2
21
+
22
+ suites:
23
+ - name: node1
24
+ run_list:
25
+ - recipe[hurry-up-and-test::set_non_nat_vbox_ip]
26
+ - recipe[node-tests::node1]
27
+ attributes:
28
+ consul:
29
+ config:
30
+ bootstrap_expect: 2
31
+ server: true
32
+
33
+ - name: node2
34
+ run_list:
35
+ - recipe[hurry-up-and-test::set_non_nat_vbox_ip]
36
+ - recipe[node-tests::node2]
37
+ attributes:
38
+ consul:
39
+ config:
40
+ bootstrap_expect: 2
41
+ server: true
data/.rubocop.yml CHANGED
@@ -1,2 +1,6 @@
1
1
  Metrics/MethodLength:
2
2
  Max: 20
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - '.kitchen/**/*'
data/Berksfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://supermarket.chef.io'
2
+
3
+ group :integration do
4
+ cookbook 'apt'
5
+ cookbook 'hurry-up-and-test'
6
+ cookbook 'node-tests', path: './test/integration/cookbooks/node-tests'
7
+ end
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'kitchen-vagrant'
6
+ gem 'berkshelf'
7
+ gem 'winrm-transport'
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'fakefs', '~> 0.4'
27
27
  spec.add_development_dependency 'rake'
28
28
  spec.add_development_dependency 'rspec', '~> 3.2'
29
- spec.add_development_dependency 'rubocop', '~> 0.29'
29
+ spec.add_development_dependency 'rubocop', '~> 0.34'
30
30
  end
@@ -3,10 +3,10 @@ module Kitchen
3
3
  # Locates active IPs that are not localhost
4
4
  # there are separate implementations for
5
5
  # different kitchen transports
6
- module IpFinder
6
+ module Finder
7
7
  def self.for_transport(transport, state)
8
8
  transport_string = transport.class.name.split('::').last
9
- require("kitchen/provisioner/ip_finder/#{transport_string.downcase}")
9
+ require("kitchen/provisioner/finder/#{transport_string.downcase}")
10
10
 
11
11
  connection = transport.connection(state)
12
12
  klass = const_get(transport_string)
@@ -48,7 +48,7 @@ module Kitchen
48
48
  end
49
49
 
50
50
  module Provisioner
51
- module IpFinder
51
+ module Finder
52
52
  # SSH implementation for returning active non-localhost IPs
53
53
  class Ssh
54
54
  IP4REGEX = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
@@ -70,6 +70,12 @@ module Kitchen
70
70
  ips
71
71
  end
72
72
 
73
+ def find_fqdn
74
+ @connection.node_execute('hostname -f').chomp
75
+ end
76
+
77
+ private
78
+
73
79
  def run_ifconfig
74
80
  response = @connection.node_execute('/sbin/ifconfig -a')
75
81
  ips = []
@@ -12,7 +12,7 @@ module Kitchen
12
12
  end
13
13
 
14
14
  module Provisioner
15
- module IpFinder
15
+ module Finder
16
16
  # WinRM implementation for returning active non-localhost IPs
17
17
  class Winrm
18
18
  def initialize(connection)
@@ -29,6 +29,21 @@ module Kitchen
29
29
  end
30
30
  data
31
31
  end
32
+
33
+ def find_fqdn
34
+ out = @connection.node_execute <<-EOS
35
+ [System.Net.Dns]::GetHostByName($env:computername) |
36
+ FL HostName |
37
+ Out-String |
38
+ % { \"{0}\" -f $_.Split(':')[1].Trim() }
39
+ EOS
40
+ data = ''
41
+ out[:data].each do |out_data|
42
+ stdout = out_data[:stdout]
43
+ data << stdout.chomp unless stdout.nil?
44
+ end
45
+ data
46
+ end
32
47
  end
33
48
  end
34
49
  end
@@ -18,7 +18,7 @@
18
18
 
19
19
  require 'kitchen'
20
20
  require 'kitchen/provisioner/chef_zero'
21
- require 'kitchen/provisioner/ip_finder'
21
+ require 'kitchen/provisioner/finder'
22
22
  require 'net/ping'
23
23
 
24
24
  module Kitchen
@@ -41,11 +41,15 @@ module Kitchen
41
41
  end
42
42
  end
43
43
 
44
- def ipaddress
45
- state = Kitchen::StateFile.new(
44
+ def state_file
45
+ @state_file ||= Kitchen::StateFile.new(
46
46
  config[:kitchen_root],
47
47
  instance.name
48
48
  ).read
49
+ end
50
+
51
+ def ipaddress
52
+ state = state_file
49
53
 
50
54
  if %w(127.0.0.1 localhost).include?(state[:hostname])
51
55
  return get_reachable_guest_address(state)
@@ -53,6 +57,18 @@ module Kitchen
53
57
  state[:hostname]
54
58
  end
55
59
 
60
+ def fqdn
61
+ state = state_file
62
+ begin
63
+ [:username, :password].each do |prop|
64
+ state[prop] = instance.driver[prop] if instance.driver[prop]
65
+ end
66
+ Finder.for_transport(instance.transport, state).find_fqdn
67
+ rescue
68
+ nil
69
+ end
70
+ end
71
+
56
72
  def chef_environment
57
73
  env = '_default'
58
74
  if config[:client_rb] && config[:client_rb][:environment]
@@ -67,7 +83,8 @@ module Kitchen
67
83
  chef_environment: chef_environment,
68
84
  automatic: {
69
85
  ipaddress: ipaddress,
70
- platform: instance.platform.name.split('-')[0].downcase
86
+ platform: instance.platform.name.split('-')[0].downcase,
87
+ fqdn: fqdn
71
88
  },
72
89
  normal: config[:attributes],
73
90
  run_list: config[:run_list]
@@ -94,7 +111,7 @@ module Kitchen
94
111
  [:username, :password].each do |prop|
95
112
  state[prop] = instance.driver[prop] if instance.driver[prop]
96
113
  end
97
- ips = IpFinder.for_transport(transport, state).find_ips
114
+ ips = Finder.for_transport(transport, state).find_ips
98
115
  fail 'Unable to retrieve IPs' if ips.empty?
99
116
  ips
100
117
  end
@@ -19,6 +19,6 @@
19
19
  module Kitchen
20
20
  # Version string for Nodes Kitchen driver
21
21
  module Provisioner
22
- NODES_VERSION = '0.4.1'
22
+ NODES_VERSION = '0.5.0'
23
23
  end
24
24
  end
@@ -27,7 +27,7 @@ describe Kitchen::Provisioner::Nodes do
27
27
  driver: Kitchen::Driver::Dummy.new
28
28
  )
29
29
  end
30
- let(:transport) { Kitchen::Transport::Dummy.new }
30
+ let(:transport) { Kitchen::Transport::Ssh.new }
31
31
  let(:platform) { double('platform', os_type: nil, name: 'ubuntu') }
32
32
  let(:suite) { double('suite', name: 'suite') }
33
33
  let(:state) { { hostname: '192.168.1.10' } }
@@ -38,6 +38,11 @@ describe Kitchen::Provisioner::Nodes do
38
38
  FileUtils.mkdir_p(config[:test_base_path])
39
39
  allow_any_instance_of(Kitchen::StateFile)
40
40
  .to receive(:read).and_return(state)
41
+ allow(transport).to receive(:connection)
42
+ .and_return(Kitchen::Transport::Base::Connection.new)
43
+ allow_any_instance_of(Kitchen::Transport::Base::Connection)
44
+ .to receive(:node_execute).with('hostname -f')
45
+ .and_return('fakehostname')
41
46
  end
42
47
  after do
43
48
  FakeFS.deactivate!
@@ -82,6 +87,25 @@ describe Kitchen::Provisioner::Nodes do
82
87
  expect(node[:automatic][:ipaddress]).to eq state[:hostname]
83
88
  end
84
89
 
90
+ it 'sets the fqdn' do
91
+ subject.create_node
92
+
93
+ expect(node[:automatic][:fqdn]).to eq 'fakehostname'
94
+ end
95
+
96
+ context 'cannot obtain fqdn' do
97
+ before do
98
+ allow_any_instance_of(Kitchen::Transport::Base::Connection)
99
+ .to receive(:node_execute).with('hostname -f')
100
+ .and_raise(Kitchen::Transport::TransportFailed.new(''))
101
+ end
102
+
103
+ it 'sets the fqdn to nil' do
104
+ subject.create_node
105
+ expect(node[:automatic][:fqdn]).to be_nil
106
+ end
107
+ end
108
+
85
109
  context 'no environment explicitly set' do
86
110
  before { config.delete(:client_rb) }
87
111
 
@@ -99,8 +123,6 @@ describe Kitchen::Provisioner::Nodes do
99
123
  before do
100
124
  allow_any_instance_of(Net::Ping::External).to receive(:ping)
101
125
  .and_return(true)
102
- allow(transport).to receive(:connection)
103
- .and_return(Kitchen::Transport::Base::Connection.new)
104
126
  end
105
127
 
106
128
  context 'cannot find an ip' do
@@ -0,0 +1,18 @@
1
+ require 'timeout'
2
+
3
+ def search_for_nodes(query, timeout = 120)
4
+ nodes = []
5
+ Timeout.timeout(timeout) do
6
+ nodes = search(:node, query)
7
+ until nodes.count > 0 && nodes[0].key?('ipaddress')
8
+ sleep 5
9
+ nodes = search(:node, query)
10
+ end
11
+ end
12
+
13
+ if nodes.count == 0 || !nodes[0].key?('ipaddress')
14
+ fail "Unable to find any nodes meeting the search criteria '#{query}'!"
15
+ end
16
+
17
+ nodes
18
+ end
@@ -0,0 +1,4 @@
1
+ name 'node-tests'
2
+ version '0.1.0'
3
+ maintainer ''
4
+ maintainer_email ''
@@ -0,0 +1,9 @@
1
+ first_node = search_for_nodes(
2
+ "run_list:*node1* AND platform:#{node['platform']}")
3
+
4
+ ruby_block 'Save first attributes' do
5
+ block do
6
+ parent = File.join(ENV['TEMP'] || '/tmp', 'kitchen')
7
+ IO.write(File.join(parent, 'other_node.json'), first_node[0].to_json)
8
+ end
9
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'winrm' if RUBY_PLATFORM =~ /mingw/
@@ -0,0 +1,64 @@
1
+ require 'serverspec'
2
+ require 'json'
3
+
4
+ if RUBY_PLATFORM =~ /mingw/
5
+ set :backend, :cmd
6
+ set :os, family: 'windows'
7
+ else
8
+ set :backend, :exec
9
+ end
10
+
11
+ describe 'other node' do
12
+ let(:node) do
13
+ JSON.parse(
14
+ IO.read(File.join(ENV['TEMP'] || '/tmp', 'kitchen/other_node.json'))
15
+ )
16
+ end
17
+ let(:ip) { node['automatic']['ipaddress'] }
18
+ let(:fqdn) { node['automatic']['fqdn'] }
19
+ let(:connection) do
20
+ if RUBY_PLATFORM =~ /mingw/
21
+ require 'winrm'
22
+ ::WinRM::WinRMWebService.new(
23
+ "http://#{ip}:5985/wsman",
24
+ :plaintext,
25
+ user: 'vagrant',
26
+ pass: 'vagrant',
27
+ basic_auth_only: true
28
+ )
29
+ else
30
+ Net::SSH.start(
31
+ ip,
32
+ 'vagrant',
33
+ password: 'vagrant',
34
+ paranoid: false
35
+ )
36
+ end
37
+ end
38
+
39
+ it 'has an non localhost ip' do
40
+ expect(ip).not_to eq('127.0.0.1')
41
+ end
42
+
43
+ describe command('hostname') do
44
+ its(:stdout) { should_not match(/#{Regexp.quote(fqdn)}/) }
45
+ end
46
+
47
+ if RUBY_PLATFORM =~ /mingw/
48
+ it 'has a computername matching node fqdn' do
49
+ expect(connection.run_cmd('hostname').stdout.chomp).to eq(fqdn)
50
+ end
51
+ else
52
+ it 'has a computername matching node fqdn' do
53
+ connection.open_channel do |channel|
54
+ channel.request_pty
55
+ channel.exec('hostname') do |_ch, _success|
56
+ channel.on_data do |_ch, data|
57
+ expect(data.chomp).to eq(fqdn)
58
+ end
59
+ end
60
+ end
61
+ connection.loop
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "node1-ubuntu-1204",
3
+ "chef_environment": "_default",
4
+ "automatic": {
5
+ "ipaddress": "192.168.1.147",
6
+ "platform": "ubuntu",
7
+ "fqdn": "node1-ubuntu-1204"
8
+ },
9
+ "normal": {
10
+ "consul": {
11
+ "config": {
12
+ "bootstrap_expect": 2,
13
+ "server": true
14
+ }
15
+ }
16
+ },
17
+ "run_list": [
18
+ "recipe[apt]",
19
+ "recipe[hurry-up-and-test::set_non_nat_vbox_ip]",
20
+ "recipe[node-tests::node1]"
21
+ ]
22
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "node1-windows-2012R2",
3
+ "chef_environment": "_default",
4
+ "automatic": {
5
+ "ipaddress": "192.168.1.149",
6
+ "platform": "windows",
7
+ "fqdn": "WIN-HKCPKCREPB8"
8
+ },
9
+ "normal": {
10
+ "consul": {
11
+ "config": {
12
+ "bootstrap_expect": 2,
13
+ "server": true
14
+ }
15
+ }
16
+ },
17
+ "run_list": [
18
+ "recipe[hurry-up-and-test::set_non_nat_vbox_ip]",
19
+ "recipe[node-tests::node1]"
20
+ ]
21
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "node2-ubuntu-1204",
3
+ "chef_environment": "_default",
4
+ "automatic": {
5
+ "ipaddress": "192.168.1.148",
6
+ "platform": "ubuntu",
7
+ "fqdn": "node2-ubuntu-1204"
8
+ },
9
+ "normal": {
10
+ "consul": {
11
+ "config": {
12
+ "bootstrap_expect": 2,
13
+ "server": true
14
+ }
15
+ }
16
+ },
17
+ "run_list": [
18
+ "recipe[apt]",
19
+ "recipe[hurry-up-and-test::set_non_nat_vbox_ip]",
20
+ "recipe[node-tests::node2]"
21
+ ]
22
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": "node2-windows-2012R2",
3
+ "chef_environment": "_default",
4
+ "automatic": {
5
+ "ipaddress": "192.168.1.150",
6
+ "platform": "windows",
7
+ "fqdn": "WIN-70EEPS83GN7"
8
+ },
9
+ "normal": {
10
+ "consul": {
11
+ "config": {
12
+ "bootstrap_expect": 2,
13
+ "server": true
14
+ }
15
+ }
16
+ },
17
+ "run_list": [
18
+ "recipe[hurry-up-and-test::set_non_nat_vbox_ip]",
19
+ "recipe[node-tests::node2]"
20
+ ]
21
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-nodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wrock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-14 00:00:00.000000000 Z
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ping
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.29'
117
+ version: '0.34'
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: '0.29'
124
+ version: '0.34'
125
125
  description: A Test Kitchen Provisioner for Chef Nodes
126
126
  email:
127
127
  - matt@mattwrock.com
@@ -130,22 +130,34 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
+ - ".kitchen.yml"
133
134
  - ".rubocop.yml"
134
135
  - ".travis.yml"
135
- - CHANGELOG.md
136
+ - Berksfile
136
137
  - Gemfile
137
138
  - LICENSE
138
139
  - README.md
139
140
  - Rakefile
140
141
  - kitchen-nodes.gemspec
141
- - lib/kitchen/provisioner/ip_finder.rb
142
- - lib/kitchen/provisioner/ip_finder/ssh.rb
143
- - lib/kitchen/provisioner/ip_finder/winrm.rb
142
+ - lib/kitchen/provisioner/finder.rb
143
+ - lib/kitchen/provisioner/finder/ssh.rb
144
+ - lib/kitchen/provisioner/finder/winrm.rb
144
145
  - lib/kitchen/provisioner/nodes.rb
145
146
  - lib/kitchen/provisioner/nodes_version.rb
146
147
  - spec/unit/nodes_spec.rb
147
148
  - spec/unit/stubs/ifconfig.txt
148
149
  - spec/unit/stubs/ip.txt
150
+ - test/integration/cookbooks/node-tests/libraries/helper.rb
151
+ - test/integration/cookbooks/node-tests/metadata.rb
152
+ - test/integration/cookbooks/node-tests/recipes/node1.rb
153
+ - test/integration/cookbooks/node-tests/recipes/node2.rb
154
+ - test/integration/node1/serverspec/default_spec.rb
155
+ - test/integration/node2/serverspec/Gemfile
156
+ - test/integration/node2/serverspec/default_spec.rb
157
+ - test/integration/nodes/node1-ubuntu-1204.json
158
+ - test/integration/nodes/node1-windows-2012R2.json
159
+ - test/integration/nodes/node2-ubuntu-1204.json
160
+ - test/integration/nodes/node2-windows-2012R2.json
149
161
  homepage: ''
150
162
  licenses:
151
163
  - Apache 2.0
@@ -166,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
178
  version: '0'
167
179
  requirements: []
168
180
  rubyforge_project:
169
- rubygems_version: 2.4.4
181
+ rubygems_version: 2.4.8
170
182
  signing_key:
171
183
  specification_version: 4
172
184
  summary: A Test Kitchen Provisioner for Chef Nodes
@@ -174,4 +186,15 @@ test_files:
174
186
  - spec/unit/nodes_spec.rb
175
187
  - spec/unit/stubs/ifconfig.txt
176
188
  - spec/unit/stubs/ip.txt
189
+ - test/integration/cookbooks/node-tests/libraries/helper.rb
190
+ - test/integration/cookbooks/node-tests/metadata.rb
191
+ - test/integration/cookbooks/node-tests/recipes/node1.rb
192
+ - test/integration/cookbooks/node-tests/recipes/node2.rb
193
+ - test/integration/node1/serverspec/default_spec.rb
194
+ - test/integration/node2/serverspec/Gemfile
195
+ - test/integration/node2/serverspec/default_spec.rb
196
+ - test/integration/nodes/node1-ubuntu-1204.json
197
+ - test/integration/nodes/node1-windows-2012R2.json
198
+ - test/integration/nodes/node2-ubuntu-1204.json
199
+ - test/integration/nodes/node2-windows-2012R2.json
177
200
  has_rdoc:
data/CHANGELOG.md DELETED
@@ -1,3 +0,0 @@
1
- ## 0.1.0 / Unreleased
2
-
3
- * Initial release