Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed testing #43

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ Metrics/BlockLength:
AllCops:
Exclude:
- '.kitchen/**/*'

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: single_quotes

Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: '()'
'%i': '[]'
'%I': '[]'
'%r': '{}'
'%w': '()'
'%W': '[]'
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
language: ruby
os: linux
dist: focal

matrix:
include:
- rvm: 3.0.2
- rvm: ruby-head
- rvm: 3.0.2
- rvm: 2.7.1
- rvm: 2.7.1
services: docker
sudo: required
env:
- KITCHEN_YAML=kitchen.travis.yml
before_script:
- sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- sudo locale-gen en_US.UTF-8
- sudo dpkg-reconfigure locales
script:
- bundle exec kitchen verify
- time bundle exec kitchen verify
after_failure:
- cat .kitchen/logs/kitchen.log
env:
- UBUNTU=20.04
- KITCHEN_YAML=.kitchen.travis.yml

branches:
only:
Expand Down
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log

## [0.10.0](https://github.com/mwrock/kitchen-nodes/tree/0.10.0) (2021-08-26)
[Full Changelog](https://github.com/mwrock/kitchen-nodes/compare/v0.9.1...0.10.0)

**Closed issues:**

- test-kitchen dependency version is too old [\#40](https://github.com/mwrock/kitchen-nodes/issues/40)
- can't load 'nodes' provisioner from load path [\#29](https://github.com/mwrock/kitchen-nodes/issues/29)
- Gem conflict on Windows workstation, not sure how to solve [\#20](https://github.com/mwrock/kitchen-nodes/issues/20)

**Merged pull requests:**

- merge scalp42 changes
- added reset_node_files option, default is false, determines if nodes file should be updated or left unchanged between kitchen runs
- add name_run_list and policy_group to template
- removed version constraints to work with latest versions of dependencies [\#42](https://github.com/mwrock/kitchen-nodes/pull/42) ([stromweld](https://github.com/stromweld))
- Updated travis-ci tests and unit tests
- Rubocop fixes [\#43](https://github.com/mwrock/kitchen-nodes/pull/43) ([stromweld](https://github.com/stromweld))


## [0.9.1](https://github.com/mwrock/kitchen-nodes/tree/0.9.1) (2017-03-19)
[Full Changelog](https://github.com/mwrock/kitchen-nodes/compare/v0.9.0...0.9.1)

Expand Down Expand Up @@ -121,4 +140,4 @@
## [v0.2.0](https://github.com/mwrock/kitchen-nodes/tree/v0.2.0) (2015-04-21)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The nodes provisioner extends the `chef-zero` provisioner along with all of its

### Example nodes:

```
```json
{
"id": "server-community-ubuntu-1204",
"automatic": {
Expand All @@ -21,15 +21,19 @@ The nodes provisioner extends the `chef-zero` provisioner along with all of its
},
"normal": {
"attr1": "val1"
}
},
"run_list": [
"recipe[apt]",
"recipe[couchbase-tests::ipaddress]",
"recipe[couchbase::server]",
"recipe[export-node]"
]
],
"named_run_list" : null,
"policy_group": null
}
```

```json
{
"id": "second-node-ubuntu-1204",
"automatic": {
Expand All @@ -47,11 +51,13 @@ The nodes provisioner extends the `chef-zero` provisioner along with all of its
"recipe[couchbase-tests::ipaddress]",
"recipe[couchbase-tests::default]",
"recipe[export-node]"
]
],
"named_run_list" : null,
"policy_group": null
}
```

The node data includes the node id based on the test-kitchen suite name, the run list assigned to the node, the normal attributes included in the `.kitchen.yml` file, the externally reachable ip address and the platform of the test instance os.
The node data includes the node id based on the test-kitchen suite name, the run list assigned to the node, the normal attributes included in the `kitchen.yml` file, the externally reachable ip address and the platform of the test instance os.

## <a name="installation"></a> Installation

Expand Down Expand Up @@ -102,7 +108,7 @@ When using kitchen-nodes with the vagrant driver, make sure you add the followin

```
network:
- ["private_network", { type: "dhcp" }]
- ["private_network", "type: \"dhcp\""]
```

This will add an additional non-NAT NIC to your vagrant box with an IP reachable from the host and other test nodes.
Expand All @@ -121,7 +127,6 @@ suites:

You can add this even if you do not use virtualbox and the recipe will do nothing.


## <a name="development"></a> Development

* Source hosted at [GitHub][repo]
Expand Down Expand Up @@ -151,4 +156,4 @@ Apache 2.0 (see [LICENSE][license])
[license]: https://github.com/mwrock/kitchen-nodes/blob/master/LICENSE
[repo]: https://github.com/mwrock/kitchen-nodes
[driver_usage]: http://docs.kitchen-ci.org/drivers/usage
[chef_omnibus_dl]: http://www.getchef.com/chef/install/
[chef_downloads]: https://downloads.chef.io/
14 changes: 10 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'bundler/gem_tasks'
require 'github_changelog_generator/task'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:test)

RuboCop::RakeTask.new(:style) do |task|
task.options << '--display-cop-names'
begin
require 'rubocop/rake_task'
require 'chefstyle'
desc 'Run Chefstyle tests'
RuboCop::RakeTask.new(:style) do |task|
task.options += ['--display-cop-names', '--extra-details']
end
rescue LoadError
puts 'chefstyle gem is not installed. bundle install first to make sure all dependencies are installed.'
end

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
Expand All @@ -21,4 +27,4 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
]
end

task default: [:test, :style]
task default: %i[test style]
18 changes: 9 additions & 9 deletions kitchen-nodes.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'kitchen/provisioner/nodes_version'

Expand All @@ -11,7 +10,7 @@ Gem::Specification.new do |spec|
spec.description = 'A Test Kitchen Provisioner for Chef Nodes'
spec.summary = spec.description
spec.homepage = ''
spec.license = 'Apache 2.0'
spec.license = 'Apache-2.0'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = []
Expand All @@ -20,12 +19,13 @@ Gem::Specification.new do |spec|

spec.add_dependency 'net-ping'
spec.add_dependency 'win32-security'
spec.add_dependency 'test-kitchen', '> 1.13'
spec.add_dependency 'test-kitchen', '>= 1.13'

spec.add_development_dependency 'bundler', '> 1.3'
spec.add_development_dependency 'fakefs', '> 0.4'
spec.add_development_dependency 'github_changelog_generator', '> 1.11.3'
spec.add_development_dependency 'bundler', '>= 1.3'
spec.add_development_dependency 'fakefs', '>= 0.4'
spec.add_development_dependency 'github_changelog_generator', '>= 1.11.3'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '> 3.2'
spec.add_development_dependency 'rubocop', '> 0.37'
spec.add_development_dependency 'rspec', '>= 3.2'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'chefstyle'
end
13 changes: 9 additions & 4 deletions .kitchen.travis.yml → kitchen.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ driver:
name: docker
username: vagrant
provision_command:
- usermod -p $(echo vagrant | openssl passwd -1 -stdin) vagrant
- locale-gen en_US.UTF-8
- dpkg-reconfigure locales
- sudo usermod -p $(echo vagrant | openssl passwd -1 -stdin) vagrant
- sudo locale-gen en_US.UTF-8
- sudo echo 'LANG=en_US.UTF-8' >> /etc/environment

provisioner:
name: nodes
roles_path: test/fixtures/roles
require_chef_omnibus: latest
product_name: chef
product_version: latest
chef_license: accept-no-persist

platforms:
- name: ubuntu-20.04
driver_config:
image: dokken/ubuntu-20.04
platform: debian

suites:
- name: node1
Expand Down
1 change: 1 addition & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ driver:
provisioner:
name: nodes
roles_path: test/fixtures/roles
reset_node_files: true

platforms:
- name: ubuntu-20.04
Expand Down
6 changes: 5 additions & 1 deletion lib/kitchen/provisioner/finder/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Ssh < Kitchen::Transport::Base
class Connection < Kitchen::Transport::Base::Connection
def node_execute(command, &block)
return if command.nil?

out, exit_code = node_execute_with_exit_code(command, &block)

if exit_code.nonzero?
Expand Down Expand Up @@ -51,7 +52,7 @@ module Provisioner
module Finder
# SSH implementation for returning active non-localhost IPs
class Ssh
IP4REGEX = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
IP4REGEX = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/.freeze

Finder.register_finder(Kitchen::Transport::Ssh, self)

Expand All @@ -68,6 +69,7 @@ def find_ips
ips = run_ip_addr
end
return ips unless ips.empty?

sleep 0.5
end
ips
Expand All @@ -85,6 +87,7 @@ def run_ifconfig
response.split(/^\S+/).each do |device|
next if !device.include?('RUNNING') || device.include?('LOOPBACK')
next if IP4REGEX.match(device).nil?

ips << IP4REGEX.match(device)[1]
end
ips.compact
Expand All @@ -96,6 +99,7 @@ def run_ip_addr
response.split(/^[0-9]+: /).each do |device|
next if device.include?('LOOPBACK') || device.include?('NO-CARRIER')
next if device == ''

found_ips = IP4REGEX.match(device)
ips << IP4REGEX.match(device)[1] unless found_ips.nil?
end
Expand Down
15 changes: 7 additions & 8 deletions lib/kitchen/provisioner/nodes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- encoding: utf-8 -*-
#
# Author:: Matt Wrock (<[email protected]>)
#
# Copyright (C) 2015, Matt Wrock
# Copyright:: (C) 2015, Matt Wrock
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,8 +54,6 @@ def create_node
def updated_node_def
if config[:reset_node_files]
node_template
else
nil
end
end

Expand All @@ -73,13 +70,14 @@ def ipaddress
if %w(127.0.0.1 localhost).include?(state[:hostname])
return get_reachable_guest_address(state)
end

state[:hostname]
end

def fqdn
state = state_file
begin
[:username, :password].each do |prop|
%i[username password].each do |prop|
state[prop] = instance.driver[prop] if instance.driver[prop]
end
Finder.for_transport(instance.transport, state).find_fqdn
Expand Down Expand Up @@ -119,12 +117,12 @@ def node_template
ipaddress: ipaddress,
platform: instance.platform.name.split('-')[0].downcase,
fqdn: fqdn,
recipes: recipes
recipes: recipes,
},
normal: config[:attributes],
run_list: config[:run_list],
named_run_list: config[:named_run_list],
policy_group: config[:policy_group]
policy_group: config[:policy_group],
}
end
# rubocop:enable Metrics/AbcSize
Expand Down Expand Up @@ -153,11 +151,12 @@ def reachable?(address)

def active_ips(transport, state)
# inject creds into state for legacy drivers
[:username, :password].each do |prop|
%i[username password].each do |prop|
state[prop] = instance.driver[prop] if instance.driver[prop]
end
ips = Finder.for_transport(transport, state).find_ips
raise 'Unable to retrieve IPs' if ips.empty?

ips
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/kitchen/provisioner/nodes_version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- encoding: utf-8 -*-
#
# Author:: Matt Wrock (<[email protected]>)
#
# Copyright (C) 2015, Matt Wrock
# Copyright:: (C) 2015, Matt Wrock
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions lib/kitchen/provisioner/run_list_expansion_from_kitchen.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- encoding: utf-8 -*-
#
# Author:: Matt Wrock (<[email protected]>)
#
# Copyright (C) 2015, Matt Wrock
# Copyright:: (C) 2015, Matt Wrock
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
Expand Down
Loading