Module: PuppetLitmus
- Extended by:
- InventoryManipulation
- Includes:
- BoltSpec::Run, InventoryManipulation, PuppetHelpers, RakeHelper
- Defined in:
- lib/puppet_litmus.rb,
lib/puppet_litmus.rb,
lib/puppet_litmus/version.rb,
lib/puppet_litmus/inventory_manipulation.rb,
lib/puppet_litmus/spec_helper_acceptance.rb
Overview
Helper methods for testing puppet content
Defined Under Namespace
Modules: InventoryManipulation, PuppetHelpers, RakeHelper, Util
Constant Summary collapse
- VERSION =
'1.6.0'
Constants included from RakeHelper
RakeHelper::DEFAULT_CONFIG_DATA, RakeHelper::SUPPORTED_PROVISIONERS
Class Method Summary collapse
Methods included from InventoryManipulation
add_feature_to_group, add_feature_to_node, add_node_to_group, add_platform_field, config_from_node, facts_from_node, find_targets, groups_in_inventory, inventory_hash_from_inventory_file, localhost_inventory_hash, nodes_with_role, remove_feature_from_group, remove_feature_from_node, remove_node, search_for_target, target_in_group, target_in_inventory?, targets_in_inventory, vars_from_node, write_to_inventory_file
Methods included from RakeHelper
#build_module, #build_modules_in_dir, #build_modules_in_folder, #check_bolt_errors, #check_connectivity?, #configure_path, #get_metadata_operating_systems, #install_agent, #install_module, #metadata_module_name, #provision, #provision_list, #provisioner_task, #raise_bolt_errors, #run_local_command, #start_spinner, #stop_spinner, #tear_down, #tear_down_nodes, #uninstall_module, #with_retries
Methods included from PuppetHelpers
#apply_manifest, #bolt_run_script, #bolt_upload_file, #create_manifest_file, #idempotent_apply, #run_bolt_task, #run_shell, #targeting_localhost?, #write_file
Class Method Details
.configure! ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/puppet_litmus/spec_helper_acceptance.rb', line 7 def self.configure! require 'serverspec' RSpec.configure do |config| config.include PuppetLitmus config.extend PuppetLitmus end if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' puts 'Running tests against this machine !' if Gem.win_platform? set :backend, :cmd else set :backend, :exec end else # load inventory inventory_hash = inventory_hash_from_inventory_file node_config = config_from_node(inventory_hash, ENV.fetch('TARGET_HOST', nil)) if target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'docker_nodes') host = ENV.fetch('TARGET_HOST', nil) set :backend, :dockercli set :docker_container, host elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'lxd_nodes') host = ENV.fetch('TARGET_HOST', nil) set :backend, :lxd set :login_shell, true set :lxd_remote, node_config.dig('lxd', 'remote') unless node_config.dig('lxd', 'remote').nil? set :lxd_instance, host elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'ssh_nodes') set :backend, :ssh = Net::SSH::Config.for(host) [:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil? [:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil? [:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? [:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? run_as = node_config.dig('ssh', 'run-as') unless node_config.dig('ssh', 'run-as').nil? # Support both net-ssh 4 and 5. # rubocop:disable Metrics/BlockNesting [:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil? # Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+. if @strict_host_key_checking.nil? || @strict_host_key_checking Net::SSH::Verifiers::Always.new else # SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts. # If known_hosts points to /dev/null, then equivalent to :never where it # accepts any key beacuse they're all new. Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new end elsif node_config.dig('ssh', 'host-key-check') if defined?(Net::SSH::Verifiers::Always) Net::SSH::Verifiers::Always.new else Net::SSH::Verifiers::Secure.new end elsif defined?(Net::SSH::Verifiers::Never) Net::SSH::Verifiers::Never.new else Net::SSH::Verifiers::Null.new end # rubocop:enable Metrics/BlockNesting host = if ENV['TARGET_HOST'].include?(':') ENV['TARGET_HOST'].split(':').first else ENV['TARGET_HOST'] end set :host, [:host_name] || host set :ssh_options, set :request_pty, false set :sudo_password, [:password] if run_as puts "Running tests as #{run_as}" if run_as elsif target_in_group(inventory_hash, ENV.fetch('TARGET_HOST', nil), 'winrm_nodes') require 'winrm' set :backend, :winrm set :os, family: 'windows' user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? endpoint = URI("http://#{ENV.fetch('TARGET_HOST', nil)}") endpoint.port = 5985 if endpoint.port == 80 endpoint.path = '/wsman' opts = { user: user, password: pass, endpoint: endpoint, operation_timeout: 300 } winrm = WinRM::Connection.new opts Specinfra.configuration.winrm = winrm end end end |