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

Fixes undefined method facts_from_node error from 0.18.0 #281

Merged
merged 3 commits into from
Apr 2, 2020
Merged
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
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ jobs:
before_script:
- |
set -e
git clone https://github.com/puppetlabs/puppetlabs-motd puppetlabs-motd
git clone --depth 1 https://github.com/puppetlabs/puppetlabs-motd puppetlabs-motd
cd puppetlabs-motd
git reset --hard 88a0015287b943d448271f11b9d6ddc859ba5eca
echo "gem 'puppet_litmus', require: false, git: 'https://github.com/${TRAVIS_PULL_REQUEST_SLUG:-$TRAVIS_REPO_SLUG}', branch: '${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}'" >> Gemfile
# override travis' defaults
unset BUNDLE_GEMFILE
bundle config set gemfile ./Gemfile
bundle config set path '../vendor/bundle'
bundle config set with development
bundle install
bundle config gemfile ./Gemfile
bundle config path '../vendor/bundle'
bundle config with development
bundle install --jobs 4 --retry 2
bundle exec rake 'litmus:provision_list[default]'
bundle exec rake 'litmus:install_agent'
bundle exec rake 'litmus:install_module'
Expand Down
18 changes: 13 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ for:
- ACCEPTANCE: yes
install:
- pwsh: |
$ErrorActionPreference = 'Stop'
$ENV:PATH = "C:\Ruby${ENV:RUBY_VERSION}\bin;${ENV:PATH}"
git clone https://github.com/puppetlabs/puppetlabs-motd motd
git clone --depth 1 https://github.com/puppetlabs/puppetlabs-motd motd
if(-not $?) { Write-Error -Message "failed to clone motd" }
Push-Location motd
git reset --hard 88a0015287b943d448271f11b9d6ddc859ba5eca
if([string]::IsNullOrEmpty($ENV:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME)) {
$URL = "'https://github.com/${ENV:APPVEYOR_REPO_NAME}'"
$Branch = "'${ENV:APPVEYOR_REPO_BRANCH}'"
Expand All @@ -50,14 +51,21 @@ for:
Write-Host $URL
Write-Host $Branch
"gem 'puppet_litmus', require: false, git: $URL, branch: $Branch" >> Gemfile
bundle install --with development --jobs 4 --retry 2 --path vendor/bundle --gemfile=./Gemfile
$ENV:BUNDLE_GEMFILE = './Gemfile'

bundle config gemfile ./Gemfile
if(-not $?) { Write-Error -Message "failed to set gemfile" }
bundle config path '../vendor/bundle'
if(-not $?) { Write-Error -Message "failed to set path" }
bundle config with development
if(-not $?) { Write-Error -Message "failed to set with development" }

bundle install --jobs 4 --retry 2
if(-not $?) { Write-Error -Message "failed to install gems" }
Get-Content Gemfile.lock
test_script:
- pwsh: |
$ErrorActionPreference = 'Stop'
$ENV:PATH = "C:\Ruby${ENV:RUBY_VERSION}\bin;${ENV:PATH}"
$ENV:BUNDLE_GEMFILE = './Gemfile'
Push-Location motd
Get-Location
bundle exec puppet -V
Expand Down
1 change: 0 additions & 1 deletion lib/puppet_litmus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module PuppetLitmus; end

require 'bolt_spec/run'
require 'puppet_litmus/honeycomb_utils'
require 'puppet_litmus/inventory_manipulation'
require 'puppet_litmus/puppet_helpers'
require 'puppet_litmus/rake_helper'
Expand Down
13 changes: 0 additions & 13 deletions lib/puppet_litmus/honeycomb_utils.rb

This file was deleted.

11 changes: 10 additions & 1 deletion lib/puppet_litmus/inventory_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def add_feature_to_node(inventory_hash, feature_name, node_name)
#
# @param inventory_hash [Hash] hash of the inventory.yaml file
# @param feature_name [String] feature to locate in the node
# node_name [String] node of nodes to limit the search for the node_name in
# @param node_name [String] node of nodes to limit the search for the node_name in
# @return inventory.yaml file with feature removed from the node.
# @return [Hash] inventory_hash with feature added to node if node_name exists in inventory hash.
def remove_feature_from_node(inventory_hash, feature_name, node_name)
Expand All @@ -257,4 +257,13 @@ def remove_feature_from_node(inventory_hash, feature_name, node_name)
def write_to_inventory_file(inventory_hash, inventory_full_path)
File.open(inventory_full_path, 'wb+') { |f| f.write(inventory_hash.to_yaml) }
end

# Add the `litmus.platform` with platform information for the target
#
# @param inventory_hash [Hash] hash of the inventory.yaml file
# @param node_name [String] node of nodes to limit the search for the node_name in
def add_platform_field(inventory_hash, node_name)
facts = facts_from_node(inventory_hash, node_name)
Honeycomb.current_span.add_field('litmus.platform', facts&.dig('platform'))
end
end
12 changes: 6 additions & 6 deletions lib/puppet_litmus/puppet_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def apply_manifest(manifest, opts = {})
raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)

span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

command_to_run = "#{opts[:prefix_command]} puppet apply #{manifest_file_location}"
command_to_run += ' --trace' if !opts[:trace].nil? && (opts[:trace] == true)
Expand Down Expand Up @@ -133,7 +133,7 @@ def create_manifest_file(manifest)
# transfer to TARGET_HOST
inventory_hash = inventory_hash_from_inventory_file
span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

manifest_file_location = "/tmp/#{File.basename(manifest_file)}"
bolt_result = upload_file(manifest_file.path, manifest_file_location, target_node_name, options: {}, config: nil, inventory: inventory_hash)
Expand Down Expand Up @@ -164,7 +164,7 @@ def run_shell(command_to_run, opts = {})
raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)

span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

bolt_result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
span.add_field('litmus.bolt_result', bolt_result)
Expand Down Expand Up @@ -203,7 +203,7 @@ def bolt_upload_file(source, destination, opts = {}, options = {})
raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)

span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

bolt_result = upload_file(source, destination, target_node_name, options: options, config: nil, inventory: inventory_hash)
span.add_field('litmus.bolt_result', bolt_result)
Expand Down Expand Up @@ -261,7 +261,7 @@ def run_bolt_task(task_name, params = {}, opts = {})
raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)

span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

bolt_result = run_task(task_name, target_node_name, params, config: config_data, inventory: inventory_hash)
result_obj = {
Expand Down Expand Up @@ -322,7 +322,7 @@ def bolt_run_script(script, opts = {}, arguments: [])
raise "Target '#{target_node_name}' not found in inventory.yaml" unless target_in_inventory?(inventory_hash, target_node_name)

span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)

bolt_result = run_script(script, target_node_name, arguments, options: opts, config: nil, inventory: inventory_hash)

Expand Down
5 changes: 2 additions & 3 deletions lib/puppet_litmus/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'bolt_spec/run'
require 'honeycomb-beeline'
require 'puppet_litmus/honeycomb_utils'
Honeycomb.configure do |config|
# override client if no configuration is provided, so that the pesky libhoney warning about lack of configuration is not shown
unless ENV['HONEYCOMB_WRITEKEY'] && ENV['HONEYCOMB_DATASET']
Expand Down Expand Up @@ -167,7 +166,7 @@ def tear_down(node_name, inventory_hash)
# how do we know what provisioner to use

span.add_field('litmus.node_name', node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, node_name)
add_platform_field(inventory_hash, node_name)

params = { 'action' => 'tear_down', 'node_name' => node_name, 'inventory' => Dir.pwd }
node_facts = facts_from_node(inventory_hash, node_name)
Expand Down Expand Up @@ -301,7 +300,7 @@ def check_connectivity?(inventory_hash, target_node_name)
# if we're only checking connectivity for a single node
if target_node_name
span.add_field('litmus.node_name', target_node_name)
PuppetLitmus::HoneycombUtils.add_platform_field(inventory_hash, target_node_name)
add_platform_field(inventory_hash, target_node_name)
end

include ::BoltSpec::Run
Expand Down
32 changes: 16 additions & 16 deletions spec/lib/puppet_litmus/inventory_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,70 +92,70 @@
end

it 'no matching node, raises' do
expect { described_class.config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
expect { config_from_node(config_hash, 'not.here') }.to raise_error('No config was found for not.here')
end

it 'no config section, returns nil' do
expect(described_class.config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
expect(config_from_node(no_config_hash, 'test.delivery.puppetlabs.net')).to eq(nil)
end

it 'config exists, and returns' do
expect(described_class.config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
expect(config_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('transport' => 'ssh', 'ssh' =>
{ 'user' => 'root', 'password' => 'Qu@lity!', 'host-key-check' => false })
end

it 'facts exists, and returns' do
expect(described_class.facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
expect(facts_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('provisioner' => 'vmpooler', 'platform' => 'centos-5-x86_64')
end

it 'vars exists, and returns' do
expect(described_class.vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
expect(vars_from_node(config_hash, 'test.delivery.puppetlabs.net')).to eq('role' => 'agent')
end

it 'no feature exists for the group, and returns hash with feature added' do
expect(described_class.add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(add_feature_to_group(no_feature_hash, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'feature exists for the group, and returns hash with feature removed' do
expect(described_class.remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(remove_feature_from_group(feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => [], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'write from inventory_hash to inventory_yaml file feature_hash_group' do
expect { described_class.write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
expect { write_to_inventory_file(feature_hash_group, inventory_full_path) }.not_to raise_error
end

it 'empty feature exists for the group, and returns hash with feature added' do
expect(described_class.add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(add_feature_to_group(empty_feature_hash_group, 'puppet-agent', 'ssh_nodes')).to eq('groups' => [{ 'features' => ['puppet-agent'], 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net' }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'no feature exists for the node, and returns hash with feature added' do
expect(described_class.add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(add_feature_to_node(no_feature_hash, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'feature exists for the node, and returns hash with feature removed' do
expect(described_class.remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(remove_feature_from_node(feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => [] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'write from inventory_hash to inventory_yaml file feature_hash_node' do
expect { described_class.write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
expect { write_to_inventory_file(feature_hash_node, inventory_full_path) }.not_to raise_error
end

it 'empty feature exists for the node, and returns hash with feature added' do
expect(described_class.add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
expect(add_feature_to_node(empty_feature_hash_node, 'puppet-agent', 'test.delivery.puppetlabs.net')).to eq('groups' => [{ 'name' => 'ssh_nodes', 'targets' => [{ 'config' => { 'ssh' => { 'host-key-check' => false, 'password' => 'Qu@lity!', 'user' => 'root' }, 'transport' => 'ssh' }, 'facts' => { 'platform' => 'centos-5-x86_64', 'provisioner' => 'vmpooler' }, 'uri' => 'test.delivery.puppetlabs.net', 'features' => ['puppet-agent'] }] }, { 'name' => 'winrm_nodes', 'targets' => [] }]) # rubocop:disable Layout/LineLength: Line is too long
end

it 'write from inventory_hash to inventory_yaml file no feature_hash' do
expect(File).to exist(inventory_full_path)
expect { described_class.write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
expect { write_to_inventory_file(no_feature_hash, inventory_full_path) }.not_to raise_error
end

it 'group does not exist in inventory, and returns hash with group added' do
expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
expect(add_node_to_group(no_docker_hash, foo_node, 'docker_nodes')).to eq('groups' =>
[{ 'name' => 'ssh_nodes', 'targets' => [] }, { 'name' => 'winrm_nodes', 'targets' => [] }, { 'name' => 'docker_nodes', 'targets' => [foo_node] }])
end

it 'group exists in inventory, and returns hash with node added' do
expect(described_class.add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
expect(add_node_to_group(no_docker_hash, foo_node, 'ssh_nodes')).to eq('groups' =>
[{ 'name' => 'ssh_nodes', 'targets' => [foo_node] }, { 'name' => 'winrm_nodes', 'targets' => [] }])
end
end
Expand Down
Loading