diff --git a/.fixtures.yml b/.fixtures.yml index 24d89c41..9ab2c0f3 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -11,4 +11,9 @@ fixtures: debug: 'https://github.com/nwops/puppet-debug' format: 'https://github.com/voxpupuli/puppet-format' symlinks: - "peadm": "#{source_dir}" \ No newline at end of file + "peadm": "#{source_dir}" + out: "#{source_dir}/.bundle/gems/bolt-1.49.0/bolt-modules/out" + ctrl: "#{source_dir}/.bundle/gems/bolt-1.49.0/bolt-modules/ctrl" + file: "#{source_dir}/.bundle/gems/bolt-1.49.0/bolt-modules/file" + system: "#{source_dir}/.bundle/gems/bolt-1.49.0/bolt-modules/system" + boltlib: "#{source_dir}/.bundle/gems/bolt-1.49.0/bolt-modules/boltlib" diff --git a/.rubocop.yml b/.rubocop.yml index 3cd2b0e5..fa466014 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ require: - rubocop-i18n AllCops: DisplayCopNames: true - TargetRubyVersion: '2.1' + TargetRubyVersion: '2.4' Include: - "./**/*.rb" Exclude: @@ -67,7 +67,7 @@ Style/TrailingCommaInArguments: Description: Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: Description: Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma @@ -90,7 +90,7 @@ Style/StringMethods: Enabled: true Layout/EndOfLine: Enabled: false -Layout/IndentHeredoc: +Layout/HeredocIndentation: Enabled: false Metrics/AbcSize: Enabled: false diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 57cf282e..00000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.6.5 diff --git a/documentation/provision.md b/documentation/provision.md index def97a68..62422615 100644 --- a/documentation/provision.md +++ b/documentation/provision.md @@ -6,7 +6,7 @@ The peadm provisioning plan creates base reference implementation. Once a base s ## Reference Architectures -When provisioning a new PE stack using peadm, there are several different host parameters which can be specified. At a minimum, you must always specify the Puppet master. Depending on which architecture you are deploying, other host parameters may be needed as well. The following is a list of the architectures peadm can provision. +When provisioning a new PE stack using peadm, there are several different host parameters which can be specified. At a minimum, you must always specify the master parameter. Depending on which architecture you are deploying, other host parameters may be needed as well. The following is a list of the architectures peadm can provision and the required parameters. * Standard - master diff --git a/examples/ruby_task.rb b/examples/ruby_task.rb index 92b92fbf..22250ddd 100755 --- a/examples/ruby_task.rb +++ b/examples/ruby_task.rb @@ -1,4 +1,6 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true + # # rubocop:disable Style/GlobalVars require 'json' diff --git a/lib/puppet/functions/peadm/file_content_upload.rb b/lib/puppet/functions/peadm/file_content_upload.rb index 3852e399..f8556d2f 100644 --- a/lib/puppet/functions/peadm/file_content_upload.rb +++ b/lib/puppet/functions/peadm/file_content_upload.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'tempfile' Puppet::Functions.create_function(:'peadm::file_content_upload') do diff --git a/lib/puppet/functions/peadm/node_manager_yaml_location.rb b/lib/puppet/functions/peadm/node_manager_yaml_location.rb index 82688922..26b39c87 100644 --- a/lib/puppet/functions/peadm/node_manager_yaml_location.rb +++ b/lib/puppet/functions/peadm/node_manager_yaml_location.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Functions.create_function(:'peadm::node_manager_yaml_location') do dispatch :nm_yaml_location do end diff --git a/spec/acceptance/peadm_spec.rb b/spec/acceptance/peadm_spec.rb index 49bb5d5c..9a1f8f4c 100644 --- a/spec/acceptance/peadm_spec.rb +++ b/spec/acceptance/peadm_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' # @summary: default test does nothing def test_peadm diff --git a/spec/functions/convert_hash_spec.rb b/spec/functions/convert_hash_spec.rb index a823717b..a81bacc8 100644 --- a/spec/functions/convert_hash_spec.rb +++ b/spec/functions/convert_hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'peadm::convert_hash' do diff --git a/spec/functions/convert_status_spec.rb b/spec/functions/convert_status_spec.rb index bdcbb581..5b4eadb9 100644 --- a/spec/functions/convert_status_spec.rb +++ b/spec/functions/convert_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'peadm::convert_status' do diff --git a/spec/functions/determine_status_spec.rb b/spec/functions/determine_status_spec.rb index 03001aec..0ca95ade 100644 --- a/spec/functions/determine_status_spec.rb +++ b/spec/functions/determine_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'peadm::determine_status' do diff --git a/spec/functions/fail_on_transport_spec.rb b/spec/functions/fail_on_transport_spec.rb new file mode 100644 index 00000000..04565abd --- /dev/null +++ b/spec/functions/fail_on_transport_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'peadm::fail_on_transport' do + let(:nodes) do + 'some_value_goes_here' + end + let(:transport) do + 'some_value_goes_here' + end + + xit { is_expected.to run.with_params(nodes, transport).and_return('some_value') } +end diff --git a/spec/functions/file_or_content_spec.rb b/spec/functions/file_or_content_spec.rb new file mode 100644 index 00000000..cbc82ec8 --- /dev/null +++ b/spec/functions/file_or_content_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'peadm::file_or_content' do + let(:param_name) do + 'some_value_goes_here' + end + let(:file) do + 'some_value_goes_here' + end + let(:content) do + 'some_value_goes_here' + end + + xit { is_expected.to run.with_params(param_name, file, content).and_return('some_value') } +end diff --git a/spec/functions/flatten_compact_spec.rb b/spec/functions/flatten_compact_spec.rb new file mode 100644 index 00000000..bd4653bc --- /dev/null +++ b/spec/functions/flatten_compact_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'peadm::flatten_compact' do + let(:input) do + [1, 2, 3, nil, 4, 5, 6, nil, 'ds', ''] + end + + it { is_expected.to run.with_params(input).and_return([1, 2, 3, 4, 5, 6, 'ds', '']) } +end diff --git a/spec/functions/generate_pe_conf_spec.rb b/spec/functions/generate_pe_conf_spec.rb new file mode 100644 index 00000000..a7bf33a3 --- /dev/null +++ b/spec/functions/generate_pe_conf_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'peadm::generate_pe_conf' do + let(:settings) do + { 'console_admin_password' => 'puppetlabs' } + end + let(:output) do + JSON.pretty_generate('console_admin_password' => 'puppetlabs', + 'puppet_enterprise::profile::console::java_args' => { + 'Xms' => '256m', + 'Xmx' => '768m' + }, + 'puppet_enterprise::profile::master::java_args' => { + 'Xms' => '512m', + 'Xmx' => '2048m' + }, + 'puppet_enterprise::profile::orchestrator::java_args' => { + 'Xms' => '256m', + 'Xmx' => '768m' + }, + 'puppet_enterprise::profile::puppetdb::java_args' => { + 'Xms' => '256m', + 'Xmx' => '768m' + }) + end + + it do + is_expected.to run.with_params(settings).and_return(%r{puppetlabs}) + end +end diff --git a/spec/functions/get_targets_spec.rb b/spec/functions/get_targets_spec.rb new file mode 100644 index 00000000..262d9b6a --- /dev/null +++ b/spec/functions/get_targets_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' +# TODO: test the error case, however due to an issue with boltspec +# and functions we cannot do this right now. +# https://github.com/puppetlabs/bolt/issues/1688 +describe 'peadm::get_targets' do + let(:spec) do + 'some_value_goes_here' + end + let(:count) do + 'some_value_goes_here' + end + + xit { is_expected.to run.with_params(spec, count).and_return('some_value') } +end diff --git a/spec/functions/oid_spec.rb b/spec/functions/oid_spec.rb new file mode 100644 index 00000000..618ca9cd --- /dev/null +++ b/spec/functions/oid_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' +# TODO: test the error case, however due to an issue with boltspec +# and functions we cannot do this right now. +# https://github.com/puppetlabs/bolt/issues/1688 +describe 'peadm::oid' do + it { is_expected.to run.with_params('peadm_role').and_return('1.3.6.1.4.1.34380.1.1.9812') } + it { is_expected.to run.with_params('peadm_availability_group').and_return('1.3.6.1.4.1.34380.1.1.9813') } + it { is_expected.to run.with_params('pp_application').and_return('1.3.6.1.4.1.34380.1.1.8') } + it { is_expected.to run.with_params('pp_cluster').and_return('1.3.6.1.4.1.34380.1.1.16') } + it do + is_expected.to run.with_params('bogus') + .and_raise_error(Puppet::PreformattedError, %r{No peadm OID for bogus}) + end +end diff --git a/spec/functions/target_name_spec.rb b/spec/functions/target_name_spec.rb new file mode 100644 index 00000000..c9092986 --- /dev/null +++ b/spec/functions/target_name_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# TODO: test the error case, however due to an issue with boltspec +# and functions we cannot do this right now. +# https://github.com/puppetlabs/bolt/issues/1688 +describe 'peadm::target_name' do + let(:target) do + ['test-vm.puppet.vm'] + end + + xit { is_expected.to run.with_params(target).and_return('some_value') } +end diff --git a/spec/functions/validate_architecture_spec.rb b/spec/functions/validate_architecture_spec.rb new file mode 100644 index 00000000..c6c67cbd --- /dev/null +++ b/spec/functions/validate_architecture_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' +# TODO: test the error case, however due to an issue with boltspec +# and functions we cannot do this right now. +# https://github.com/puppetlabs/bolt/issues/1688 + +describe 'peadm::validate_architecture' do + let(:pre_condition) do + 'type TargetSpec = Variant[String[1], Target, Array[TargetSpec]]' + end + let(:master_host) do + 'puppet-std.puppet.vm' + end + let(:master_replica_host) do + 'pup-replica.puppet.vm' + end + let(:puppetdb_database_host) do + 'pup-db.puppet.vm' + end + let(:puppetdb_database_replica_host) do + 'pup-db-replica.puppet.vm' + end + let(:compiler_hosts) do + 'pup-c1.puppet.vm' + end + + it { + is_expected.to run.with_params(master_host) + .and_return('high-availability' => false, 'architecture' => 'standard') + } + it { + is_expected.to run.with_params(master_host, master_replica_host) + .and_return('high-availability' => true, 'architecture' => 'standard') + } + + it do + is_expected.to run.with_params( + master_host, + master_replica_host, + nil, + nil, + compiler_hosts, + ) + .and_return('high-availability' => true, 'architecture' => 'large') + end + + it do + is_expected.to run.with_params( + master_host, + nil, + nil, + nil, + compiler_hosts, + ) + .and_return('high-availability' => false, 'architecture' => 'large') + end + + it do + is_expected.to run.with_params( + master_host, + master_replica_host, + puppetdb_database_host, + puppetdb_database_replica_host, + compiler_hosts, + ) + .and_return('high-availability' => true, 'architecture' => 'extra-large') + end + + it do + is_expected.to run.with_params( + master_host, + nil, + puppetdb_database_host, + nil, + compiler_hosts, + ) + .and_return('high-availability' => false, 'architecture' => 'extra-large') + end +end diff --git a/spec/plans/status_disable.rb b/spec/plans/status_disable.rb index 2a3993c0..f1d55e43 100644 --- a/spec/plans/status_disable.rb +++ b/spec/plans/status_disable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' # https://github.com/puppetlabs/bolt/blob/master/lib/bolt_spec/plans.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index feb57204..9da5a5d2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -7,12 +9,12 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), - File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), + File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')) ] default_fact_files.each do |f| diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index cfb588ab..b6f0b972 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet_litmus' require 'singleton' diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index c71458f0..3622c6b4 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet' if Gem::Version.new(Puppet.version) >= Gem::Version.new('6.0.0') @@ -12,3 +14,21 @@ warn '=== bolt tests will not run; ensure bolt gem is installed (requires Puppet 6+)' end end + +# Bolt has some hidden puppet modules inside the bolt codebase that need to be added here +# for proper testing and availablity with other tooling. The code below will +# locate the bolt gem dir and create fixtures for each of the bolt modules. + +spec = Gem::Specification.latest_specs.find { |s| s.name.eql?('bolt') } +if spec + bolt_modules = File.join(spec.full_gem_path, 'bolt-modules') + Dir.glob(File.join(bolt_modules, '*')).each do |dir| + mod_name = File.basename(dir) + mod_path = File.expand_path(File.join(__dir__, 'fixtures', 'modules', mod_name)) + FileUtils.ln_sf(dir, mod_path) unless File.exist?(mod_path) + end + + RSpec.configure do |c| + c.basemodulepath = bolt_modules + end +end diff --git a/tasks/rbac_token.rb b/tasks/rbac_token.rb index 0e63a3f7..1f2086fe 100755 --- a/tasks/rbac_token.rb +++ b/tasks/rbac_token.rb @@ -1,4 +1,6 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true + # # rubocop:disable Style/GlobalVars require 'net/https' @@ -16,7 +18,7 @@ 'login' => 'admin', 'password' => $params['password'], 'lifetime' => '1y', - 'label' => 'provision-time token', + 'label' => 'provision-time token' }.to_json http = Net::HTTP.new(uri.host, uri.port) diff --git a/tasks/read_file.rb b/tasks/read_file.rb index 9a79ea95..c3fb1466 100755 --- a/tasks/read_file.rb +++ b/tasks/read_file.rb @@ -1,4 +1,5 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true require 'json' @@ -8,11 +9,11 @@ rescue StandardError => err result = { 'content' => nil, - 'error' => err.message, + 'error' => err.message } else result = { - 'content' => content, + 'content' => content } ensure puts result.to_json diff --git a/tasks/sign_csr.rb b/tasks/sign_csr.rb index 0aed172a..64c50b6c 100755 --- a/tasks/sign_csr.rb +++ b/tasks/sign_csr.rb @@ -1,4 +1,6 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true + # require 'json' require 'open3' diff --git a/tasks/submit_csr.rb b/tasks/submit_csr.rb index 04ffdb26..1a67911a 100755 --- a/tasks/submit_csr.rb +++ b/tasks/submit_csr.rb @@ -1,4 +1,6 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true + # require 'json' require 'open3' diff --git a/tasks/trusted_facts.rb b/tasks/trusted_facts.rb index 6bf914ae..2680f894 100755 --- a/tasks/trusted_facts.rb +++ b/tasks/trusted_facts.rb @@ -1,4 +1,5 @@ #!/opt/puppetlabs/puppet/bin/ruby +# frozen_string_literal: true require 'openssl' require 'puppet' @@ -35,7 +36,7 @@ result = { 'certname' => certname, 'dns-alt-names' => alt_names, - 'extensions' => extensions, + 'extensions' => extensions } puts result.to_json