diff --git a/acceptance/tests/agent/agent_disable_lockfile.rb b/acceptance/tests/agent/agent_disable_lockfile.rb deleted file mode 100644 index 68d4419668..0000000000 --- a/acceptance/tests/agent/agent_disable_lockfile.rb +++ /dev/null @@ -1,97 +0,0 @@ -test_name "C4553 - agent --disable/--enable functionality should manage the agent lockfile properly" -tag 'audit:integration', # lockfile uses the standard `vardir` location to store/query lockfile. - # The validation of the `vardir` at the OS level - # should be accomplished in another test. - 'audit:high', - 'audit:refactor' # This test should not require a master. Remove the use of `with_puppet_running_on`. - -# -# This test is intended to ensure that puppet agent --enable/--disable -# work properly, both in terms of complying with our public "API" around -# lockfile semantics ( http://links.puppet.com/agent_lockfiles ), and -# in terms of actually restricting or allowing new agent runs to begin. -# - -require 'puppet/acceptance/temp_file_utils' - -extend Puppet::Acceptance::TempFileUtils - -initialize_temp_dirs() -@all_tests_passed = false - - -############################################################################### -# BEGIN TEST LOGIC -############################################################################### - -teardown do - if @all_tests_passed then - remove_temp_dirs() - end - agents.each do |agent| - on(agent, puppet('agent', "--enable")) - end -end - -tuples = [ - ["reason not specified", false], - ["I'm busy; go away.'", true] -] - -with_puppet_running_on(master, {}) do - tuples.each do |expected_message, explicitly_specify_message| - step "disable the agent; specify message? '#{explicitly_specify_message}', message: '#{expected_message}'" do - agents.each do |agent| - if (explicitly_specify_message) - on(agent, puppet('agent', "--disable \"#{expected_message}\"")) - else - on(agent, puppet('agent', "--disable")) - end - - agent_disabled_lockfile = "#{agent.puppet['vardir']}/state/agent_disabled.lock" - unless file_exists?(agent, agent_disabled_lockfile) then - fail_test("Failed to create disabled lock file '#{agent_disabled_lockfile}' on agent '#{agent}'") - end - lock_file_content = file_contents(agent, agent_disabled_lockfile) - - # This is a hack; we should parse the JSON into a hash, but I don't - # think I have a library available from the acceptance test framework - # that I can use to do that. So I'm falling back to regex. - lock_file_content_regex = /"disabled_message"\s*:\s*"#{expected_message}"/ - unless lock_file_content =~ lock_file_content_regex - fail_test("Disabled lock file contents invalid; expected to match '#{lock_file_content_regex}', got '#{lock_file_content}' on agent '#{agent}'") - end - end - end - - step "attempt to run the agent (message: '#{expected_message}')" do - agents.each do |agent| - on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [1]) do |result| - disabled_regex = /administratively disabled.*'#{expected_message}'/ - unless result.stdout =~ disabled_regex - fail_test("Unexpected output from attempt to run agent disabled; expecting to match '#{disabled_regex}', got '#{result.stdout}' on agent '#{agent}'") unless agent['locale'] == 'ja' - end - end - end - end - - step "enable the agent (message: '#{expected_message}')" do - agents.each do |agent| - - agent_disabled_lockfile = "#{agent.puppet['vardir']}/state/agent_disabled.lock" - on(agent, puppet('agent', "--enable")) - if file_exists?(agent, agent_disabled_lockfile) then - fail_test("Failed to remove disabled lock file '#{agent_disabled_lockfile}' on agent '#{agent}'") - end - end - end - - step "verify that we can run the agent (message: '#{expected_message}')" do - agents.each do |agent| - on(agent, puppet('agent', "--test")) - end - end - end # tuples block -end # with_puppet_running_on block - -@all_tests_passed = true diff --git a/acceptance/tests/agent/agent_fails_with_unknown_resource.rb b/acceptance/tests/agent/agent_fails_with_unknown_resource.rb deleted file mode 100644 index b5289167ed..0000000000 --- a/acceptance/tests/agent/agent_fails_with_unknown_resource.rb +++ /dev/null @@ -1,79 +0,0 @@ -test_name "agent run should fail if it finds an unknown resource type" do - tag 'audit:high', - 'audit:integration' - - require 'puppet/acceptance/common_utils' - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - step "agent should fail when it can't find a resource" do - vendor_modules_path = master.tmpdir('vendor_modules') - tmp_environment = mk_tmp_environment_with_teardown(master, 'tmp') - - site_pp_content = <<-SITEPP - define foocreateresource($one) { - $msg = 'hello' - notify { $name: message => $msg } - } - class example($x) { - if $x == undef or $x == [] or $x == '' { - notice 'foo' - return() - } - notice 'bar' - } - node default { - class { example: x => [] } - create_resources('foocreateresource', {'blah'=>{'one'=>'two'}}) - mycustomtype{'foobar':} - } - SITEPP - manifests_path = "/tmp/#{tmp_environment}/manifests" - on(master, "mkdir -p '#{manifests_path}'") - create_remote_file(master, "#{manifests_path}/site.pp", site_pp_content) - - custom_type_content = <<-CUSTOMTYPE - Puppet::Type.newtype(:mycustomtype) do - @doc = "Create a new mycustomtype thing." - - newparam(:name, :namevar => true) do - desc "Name of mycustomtype instance" - end - - def refresh - end - end - CUSTOMTYPE - type_path = "#{vendor_modules_path}/foo/lib/puppet/type" - on(master, "mkdir -p '#{type_path}'") - create_remote_file(master, "#{type_path}/mycustomtype.rb", custom_type_content) - - on(master, "chmod -R 750 '#{vendor_modules_path}' '/tmp/#{tmp_environment}'") - on(master, "chown -R #{master.puppet['user']}:#{master.puppet['group']} '#{vendor_modules_path}' '/tmp/#{tmp_environment}'") - - master_opts = { - 'main' => { - 'environment' => tmp_environment, - 'vendormoduledir' => vendor_modules_path - } - } - - with_puppet_running_on(master, master_opts) do - agents.each do |agent| - teardown do - agent.rm_rf(vendor_modules_path) - end - - # override vendormoduledir in case agent and server are on the same host - agent_dir = get_test_file_path(agent, 'vendormodulepath') - on(agent, puppet('agent', '-t', '--environment', tmp_environment, '--vendormoduledir', agent_dir), acceptable_exit_codes: [1]) do |result| - assert_match(/Error: Failed to apply catalog: Resource type 'Mycustomtype' was not found/, result.stderr) - end - end - end - end -end diff --git a/acceptance/tests/agent/agent_parses_json_catalog.rb b/acceptance/tests/agent/agent_parses_json_catalog.rb deleted file mode 100644 index f5719f7396..0000000000 --- a/acceptance/tests/agent/agent_parses_json_catalog.rb +++ /dev/null @@ -1,28 +0,0 @@ -test_name "C99978: Agent parses a JSON catalog" - -tag 'risk:high', - 'audit:high', # tests defined catalog format - 'audit:integration', # There is no OS specific risk here. - 'server', - 'catalog:json' - -require 'puppet/acceptance/common_utils' -require 'json' - -step "Agent parses a JSON catalog" do - agents.each do |agent| - # Path to a ruby binary - ruby = Puppet::Acceptance::CommandUtils.ruby_command(agent) - - # Refresh the catalog - on(agent, puppet("agent --test")) - - # The catalog file should be parseable JSON - json_catalog = File.join(agent.puppet['client_datadir'], 'catalog', - "#{agent.puppet['certname']}.json") - on(agent, "cat #{json_catalog} | #{ruby} -rjson -e 'JSON.parse(STDIN.read)'") - - # Can the agent parse it as JSON? - on(agent, puppet("catalog find --terminus json > /dev/null")) - end -end diff --git a/acceptance/tests/agent/fallback_to_cached_catalog.rb b/acceptance/tests/agent/fallback_to_cached_catalog.rb deleted file mode 100644 index ccf24ae3a4..0000000000 --- a/acceptance/tests/agent/fallback_to_cached_catalog.rb +++ /dev/null @@ -1,22 +0,0 @@ -test_name "fallback to the cached catalog" - -tag 'audit:high', - 'audit:integration', # This test is not OS sensitive. - 'audit:refactor' # A catalog fixture can be used for this test. Remove the usage of `with_puppet_running_on`. - -step "run agents once to cache the catalog" do - with_puppet_running_on master, {} do - on(agents, puppet("agent -t")) - end -end - -step "run agents again, verify they use cached catalog" do - agents.each do |agent| - # can't use --test, because that will set usecacheonfailure=false - # We use a server that the agent can't possibly talk to in order - # to guarantee that no communication can take place. - on(agent, puppet("agent --onetime --no-daemonize --server puppet.example.com --verbose")) do |result| - assert_match(/Using cached catalog/, result.stdout) unless agent['locale'] == 'ja' - end - end -end diff --git a/acceptance/tests/agent/last_run_summary_report.rb b/acceptance/tests/agent/last_run_summary_report.rb deleted file mode 100644 index 178b877119..0000000000 --- a/acceptance/tests/agent/last_run_summary_report.rb +++ /dev/null @@ -1,116 +0,0 @@ -test_name "The 'last_run_summary.yaml' report has the right location and permissions" do - tag 'audit:high' - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - agents.each do |agent| - skip_test('This test does not work on Windows in japanese') if agent['platform'] =~ /windows/ && agent['locale'] == 'ja' - - custom_publicdir = agent.tmpdir('custom_public_dir') - - statedir = on(agent, puppet('config print statedir')).stdout.chomp - fail_test("The 'statedir' config is not set!") if statedir.empty? - - publicdir = on(agent, puppet('config print publicdir')).stdout.chomp - fail_test("The 'publicdir' config is not set!") if publicdir.empty? - - teardown do - agent.rm_rf(custom_publicdir) - agent.rm_rf("#{publicdir}/*") unless publicdir.empty? - on(agent, puppet("config set publicdir #{publicdir}")) - end - - step "Check if '#{publicdir}' was created during puppet installation" do - on(agent, "ls #{publicdir}", :acceptable_exit_codes => [0]) - end - - step "Check if '#{publicdir}' has '0755' permissions" do - if agent['platform'] =~ /windows/ - on(agent, "icacls #{publicdir}") do |result| - # Linux 'Owner' permissions class equivalent - assert_match(/BUILTIN\\Administrators:.*\(F\)/, result.stdout) - - # Known issue on Windows: 'C:\ProgramData\PuppetLabs\puppet' permissions are inherited - # by its subfolders and it does not have any permissions for 'Everyone' (see 'PuppetAppDir' - # in 'puppet-agent/resources/windows/wix/appdatafiles.wxs') - # Below line should be added when solution is found: - # assert_match(/Everyone:.*\(RX\)/, result.stdout) - end - else - on(agent, "ls -al #{publicdir}") do |result| - assert_match(/rwxr-xr-x.+\.$/, result.stdout) - end - end - end - - step "Create the 'last_run_summary.yaml' report file by applying catalog" do - on(agent, puppet('agent -t')) do |result| - assert_match('Applied catalog', result.stdout) - end - end - - step "Check if the 'last_run_summary.yaml' report file created has '0640' permissions" do - if agent['platform'] =~ /windows/ - on(agent, "icacls #{File.join(publicdir, 'last_run_summary.yaml')}") do |result| - # Linux 'Owner' premissions class equivalent - assert_match('Administrator:(R,W', result.stdout) - # Linux 'Group' permissions class equivalent - assert_match('None:(R)', result.stdout) - # Linux 'Public' permissions class equivalent - assert_match('Everyone:(Rc,S,RA)', result.stdout) - # According to icacls docs: - # Rc = Read control - # S = Synchronize - # RA = Read attributes - # More at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls - end - else - on(agent, "ls -al #{publicdir}") do |result| - assert_match(/rw-r-----.+last_run_summary\.yaml$/, result.stdout) - end - end - end - - step "Check that '#{statedir}' exists and has no 'last_run_summary.yaml' file" do - on(agent, "ls #{statedir}",:acceptable_exit_codes => [0]) do |result| - refute_match(/last_run_summary.yaml/, result.stdout) - end - end - - step "Check that 'publicdir' can be reconfigured" do - on(agent, puppet("config set publicdir #{custom_publicdir}")) - on(agent, puppet('config print publicdir')) do |result| - assert_match(custom_publicdir, result.stdout) - end - end - - step "Create a new 'last_run_summary.yaml' report file by applying catalog" do - on(agent, puppet('agent -t')) do |result| - assert_match('Applied catalog', result.stdout) - end - end - - step "Check if the 'last_run_summary.yaml' report file was created in the new location and still has '0640' permissions" do - if agent['platform'] =~ /windows/ - on(agent, "icacls #{File.join(custom_publicdir, 'last_run_summary.yaml')}") do |result| - # Linux 'Owner' premissions class equivalent - assert_match('Administrator:(R,W', result.stdout) - # Linux 'Group' permissions class equivalent - assert_match('None:(R)', result.stdout) - # Linux 'Public' permissions class equivalent - assert_match('Everyone:(Rc,S,RA)', result.stdout) - # According to icacls docs: - # Rc = Read control - # S = Synchronize - # RA = Read attributes - # More at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls - end - else - on(agent, "ls -al #{custom_publicdir}") do |result| - assert_match(/rw-r-----.+last_run_summary\.yaml$/, result.stdout) - end - end - end - end -end diff --git a/acceptance/tests/aix/aix_package_provider.rb b/acceptance/tests/aix/aix_package_provider.rb deleted file mode 100644 index bd03be55d4..0000000000 --- a/acceptance/tests/aix/aix_package_provider.rb +++ /dev/null @@ -1,97 +0,0 @@ -test_name "aix package provider should work correctly" do - - tag 'audit:high', - 'audit:acceptance' # OS specific by definition. - - confine :to, :platform => /aix/ - - dir = "/tmp/aix-packages-#{$$}" - - def assert_package_version(package, expected_version) - # The output of lslpp is a colon-delimited list like: - # sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/: - # We want the version, so grab the third field - on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result| - actual_version = result.stdout.chomp - assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}") - end - end - - def get_package_manifest(package, version, sourcedir) - <<-MANIFEST - package { '#{package}': - ensure => '#{version}', - provider => aix, - source => '#{sourcedir}', - } - MANIFEST - end - - package = 'sudo.rte' - version1 = '1.7.10.4' - version2 = '1.8.6.4' - - teardown do - on hosts, "rm -rf #{dir}" - on hosts, "installp -u #{package}" - end - - step "download packages to use for test" do - on hosts, "mkdir -p #{dir}" - on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version1}.aix51.lam.bff > #{dir}/sudo.#{version1}.aix51.lam.bff" - on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version2}.aix51.lam.bff > #{dir}/sudo.#{version2}.aix51.lam.bff" - end - - step "install the older version of package" do - apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true) - end - - step "verify package is installed and at the correct version" do - assert_package_version package, version1 - end - - step "install a newer version of the package" do - apply_manifest_on(hosts, get_package_manifest(package, version2, dir), :catch_failures => true) - end - - step "verify package is installed and at the newer version" do - assert_package_version package, version2 - end - - step "test that downgrading fails by trying to install an older version of the package" do - apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :acceptable_exit_codes => [4,6]) do |res| - assert_match(/aix package provider is unable to downgrade packages/, res.stderr, "Didn't get an error about downgrading packages") - end - end - - step "uninstall the package" do - apply_manifest_on(hosts, get_package_manifest(package, 'absent', dir), :catch_failures => true) - end - - step "verify the package is gone" do - on hosts, "lslpp -qLc #{package}", :acceptable_exit_codes => [1] - end - - step "install the older version of package" do - apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true) - end - - step "verify package is installed and at the correct version" do - assert_package_version package, version1 - end - - step "install latest version of the package" do - apply_manifest_on(hosts, get_package_manifest(package, 'latest', dir), :catch_failures => true) - end - - step "verify package is installed and at the correct version" do - assert_package_version package, version2 - end - - step "PUP-7818 remove a package without defining the source metaparameter" do - manifest = get_package_manifest(package, 'latest', dir) - manifest = manifest + "package { 'nonexistant_example_package.rte': ensure => absent, }" - apply_manifest_on(hosts, manifest, :catch_failures => true) - end - -end diff --git a/acceptance/tests/aix/nim_package_provider.rb b/acceptance/tests/aix/nim_package_provider.rb deleted file mode 100644 index 0694ffc6e0..0000000000 --- a/acceptance/tests/aix/nim_package_provider.rb +++ /dev/null @@ -1,120 +0,0 @@ -test_name "NIM package provider should work correctly" - -tag 'audit:high', - 'audit:acceptance' # OS specific by definition - -# nim test is slow, confine to only aix 7.2 and recent puppet versions -confine :to, :platform => "aix" do |aix| - version = on(aix, 'puppet --version').stdout - version && - Gem::Version.new(version) > Gem::Version.new('6.4.0') && - on(aix, 'facter os.release.full').stdout == '7.2' -end - -teardown do - test_apply('cdrecord', 'absent', '') - test_apply('puppet.test.rte', 'absent', '') -end - -def assert_package_version(package, expected_version) - # The output of lslpp is a colon-delimited list like: - # sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/: - # We want the version, so grab the third field - on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result| - actual_version = result.stdout.chomp - assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}") - end -end - -def get_manifest(package, ensure_value) - < '#{ensure_value}', - source => 'lpp_custom', - provider => nim, -} -MANIFEST -end - -def test_apply(package_name, ensure_value, expected_version) - manifest = get_manifest(package_name, ensure_value) - on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]), - {:stdin => manifest, :acceptable_exit_codes => [2]} - - step "validate installed package version" do - assert_package_version package_name, expected_version - end - - step "run again to ensure idempotency" do - on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]), - {:stdin => manifest, :acceptable_exit_codes => [0]} - end - - step "validate installed package version" do - assert_package_version package_name, expected_version - end -end - -# These two packages live in an LPP source on the NIM master. Details -# on our nim masters are available at -# https://confluence.puppetlabs.com/display/OPS/IBM+Power+LPARs -package_types = { - "RPM" => { - :package_name => "cdrecord", - :old_version => '1.9-6', - :new_version => '1.9-9' - }, - "BFF" => { - :package_name => "puppet.test.rte", - :old_version => '1.0.0.0', - :new_version => '2.0.0.0' - } -} - -step "Setup: ensure test packages are not installed" do - pkgs = ['cdrecord', 'puppet.test.rte'] - pkgs.each do |pkg| - on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]), - {:stdin => get_manifest(pkg, 'absent'), :acceptable_exit_codes => [0,2]} - end -end - -package_types.each do |package_type, details| - step "install a #{package_type} package via 'ensure=>present'" do - package_name = details[:package_name] - version = details[:new_version] - test_apply(package_name, 'present', version) - end - - step "uninstall a #{package_type} package via 'ensure=>absent'" do - package_name = details[:package_name] - version = '' - test_apply(package_name, 'absent', version) - end - - step "install a #{package_type} package via 'ensure=>'" do - package_name = details[:package_name] - version = details[:old_version] - test_apply(package_name, version, version) - end - - step "upgrade a #{package_type} package via 'ensure=>'" do - package_name = details[:package_name] - version = details[:new_version] - test_apply(package_name, version, version) - end - - step "attempt to downgrade a #{package_type} package via 'ensure=>'" do - package_name = details[:package_name] - version = details[:old_version] - - manifest = get_manifest(package_name, version) - on(hosts, puppet_apply("--verbose", "--detailed-exitcodes"), - { :stdin => manifest, - :acceptable_exit_codes => [4,6] }) do |result| - - assert_match(/NIM package provider is unable to downgrade packages/, result.stderr, "Didn't get an error about downgrading packages") - end - end - -end diff --git a/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb deleted file mode 100644 index 3be7ee7ed2..0000000000 --- a/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb +++ /dev/null @@ -1,154 +0,0 @@ -test_name "node_name_fact should be used to determine the node name for puppet agent" - -tag 'audit:high', - 'audit:integration', # Tests that the server properly overrides certname with node_name fact. - # Testing of passenger master is no longer needed. - 'server' - -success_message = "node_name_fact setting was correctly used to determine the node name" - -testdir = master.tmpdir("nodenamefact") -node_names = [] - -on agents, facter('kernel') do |result| - node_names << result.stdout.chomp -end - -node_names.uniq! - -step "Prepare for custom tk-auth rules" do - on master, 'cp /etc/puppetlabs/puppetserver/conf.d/auth.conf /etc/puppetlabs/puppetserver/conf.d/auth.bak' - modify_tk_config(master, options['puppetserver-config'], {'jruby-puppet' => {'use-legacy-auth-conf' => false}}) -end - -teardown do - modify_tk_config(master, options['puppetserver-config'], {'jruby-puppet' => {'use-legacy-auth-conf' => true}}) - on master, 'cp /etc/puppetlabs/puppetserver/conf.d/auth.bak /etc/puppetlabs/puppetserver/conf.d/auth.conf' - service(master, :reload, master['puppetservice']) -end - -step "Setup tk-auth rules" do - tka_header = <<-HEADER -authorization: { - version: 1 - rules: [ - { - match-request: { - path: "/puppet/v3/file" - type: path - } - allow: "*" - sort-order: 500 - name: "puppetlabs file" - }, - HEADER - - tka_node_rules = node_names.map do |node_name| - <<-NODE_RULES - { - match-request: { - path: "/puppet/v3/catalog/#{node_name}" - type: path - method: [get, post] - } - allow: "*" - sort-order: 500 - name: "puppetlabs catalog #{node_name}" - }, - { - match-request: { - path: "/puppet/v3/node/#{node_name}" - type: path - method: get - } - allow: "*" - sort-order: 500 - name: "puppetlabs node #{node_name}" - }, - { - match-request: { - path: "/puppet/v3/report/#{node_name}" - type: path - method: put - } - allow: "*" - sort-order: 500 - name: "puppetlabs report #{node_name}" - }, - NODE_RULES - end - - tka_footer = <<-FOOTER - { - match-request: { - path: "/" - type: path - } - deny: "*" - sort-order: 999 - name: "puppetlabs deny all" - } - ] -} - FOOTER - - tk_auth = [tka_header, tka_node_rules, tka_footer].flatten.join("\n") - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - file { '/etc/puppetlabs/puppetserver/conf.d/auth.conf': - ensure => file, - mode => '0644', - content => '#{tk_auth}', - } - MANIFEST -end - -step "Setup site.pp for node name based classification" do - - site_manifest = <<-SITE_MANIFEST -node default { - notify { "false": } -} - -node #{node_names.map { |name| %Q["#{name}"] }.join(", ")} { - notify { "#{success_message}": } -} -SITE_MANIFEST - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - $directories = [ - '#{testdir}', - '#{testdir}/environments', - '#{testdir}/environments/production', - '#{testdir}/environments/production/manifests', - ] - - file { $directories: - ensure => directory, - mode => '0755', - } - - file { '#{testdir}/environments/production/manifests/manifest.pp': - ensure => file, - mode => '0644', - content => '#{site_manifest}', - } - MANIFEST -end - -step "Ensure nodes are classified based on the node name fact" do - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - 'master' => { - 'node_terminus' => 'plain', - }, - } - - with_puppet_running_on(master, master_opts, testdir) do - on(agents, puppet('agent', "--no-daemonize --verbose --onetime --node_name_fact kernel")) do |result| - assert_match(/defined 'message'.*#{success_message}/, result.stdout) - end - end -end diff --git a/acceptance/tests/allow_arbitrary_node_name_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_for_agent.rb deleted file mode 100644 index d8439d664d..0000000000 --- a/acceptance/tests/allow_arbitrary_node_name_for_agent.rb +++ /dev/null @@ -1,134 +0,0 @@ -test_name "node_name_value should be used as the node name for puppet agent" - -tag 'audit:high', - 'audit:integration', # Tests that the server properly overrides certname with node_name fact. - # Testing of passenger master is no longer needed. - 'server' - -success_message = "node_name_value setting was correctly used as the node name" -testdir = master.tmpdir('nodenamevalue') - -step "Prepare for custom tk-auth rules" do - on master, 'cp /etc/puppetlabs/puppetserver/conf.d/auth.conf /etc/puppetlabs/puppetserver/conf.d/auth.bak' - modify_tk_config(master, options['puppetserver-config'], {'jruby-puppet' => {'use-legacy-auth-conf' => false}}) -end - -teardown do - on master, 'cp /etc/puppetlabs/puppetserver/conf.d/auth.bak /etc/puppetlabs/puppetserver/conf.d/auth.conf' - modify_tk_config(master, options['puppetserver-config'], {'jruby-puppet' => {'use-legacy-auth-conf' => true}}) - service(master, :reload, master['puppetservice']) -end - -step "Setup tk-auth rules" do - tk_auth = <<-TK_AUTH -authorization: { - version: 1 - rules: [ - { - match-request: { - path: "/puppet/v3/file" - type: path - } - allow: "*" - sort-order: 500 - name: "puppetlabs file" - }, - { - match-request: { - path: "/puppet/v3/catalog/specified_node_name" - type: path - method: [get, post] - } - allow: "*" - sort-order: 500 - name: "puppetlabs catalog" - }, - { - match-request: { - path: "/puppet/v3/node/specified_node_name" - type: path - method: get - } - allow: "*" - sort-order: 500 - name: "puppetlabs node" - }, - { - match-request: { - path: "/puppet/v3/report/specified_node_name" - type: path - method: put - } - allow: "*" - sort-order: 500 - name: "puppetlabs report" - }, - { - match-request: { - path: "/" - type: path - } - deny: "*" - sort-order: 999 - name: "puppetlabs deny all" - } - ] -} - TK_AUTH - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - file { '/etc/puppetlabs/puppetserver/conf.d/auth.conf': - ensure => file, - mode => '0644', - content => '#{tk_auth}', - } - MANIFEST -end - -step "Setup site.pp for node name based classification" do - - site_manifest = <<-SITE_MANIFEST -node default { - notify { "false": } -} -node specified_node_name { - notify { "#{success_message}": } -} - SITE_MANIFEST - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - $directories = [ - '#{testdir}', - '#{testdir}/environments', - '#{testdir}/environments/production', - '#{testdir}/environments/production/manifests', - ] - - file { $directories: - ensure => directory, - mode => '0755', - } - - file { '#{testdir}/environments/production/manifests/manifest.pp': - ensure => file, - mode => '0644', - content => '#{site_manifest}', - } - MANIFEST -end - -step "Ensure nodes are classified based on the node name fact" do - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - 'master' => { - 'node_terminus' => 'plain', - }, - } - with_puppet_running_on(master, master_opts, testdir) do - on(agents, puppet('agent', "-t --node_name_value specified_node_name"), :acceptable_exit_codes => [0,2]) do |result| - assert_match(/defined 'message'.*#{success_message}/, result.stdout) - end - end -end diff --git a/acceptance/tests/apply/classes/parameterized_classes.rb b/acceptance/tests/apply/classes/parameterized_classes.rb deleted file mode 100755 index 3f089a968c..0000000000 --- a/acceptance/tests/apply/classes/parameterized_classes.rb +++ /dev/null @@ -1,59 +0,0 @@ -test_name "parametrized classes" - -tag 'audit:high', - 'audit:unit' # This should be covered at the unit layer. - -######################################################################## -step "should allow param classes" -manifest = %q{ -class x($y, $z) { - notice("${y}-${z}") -} -class {x: y => '1', z => '2'} -} - -apply_manifest_on(agents, manifest) do |result| - fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2" -end - -######################################################################## -# REVISIT: This was ported from the old set of tests, but I think that -# the desired behaviour has recently changed. --daniel 2010-12-23 -step "should allow param class post inclusion" -manifest = %q{ -class x($y, $z) { - notice("${y}-${z}") -} -class {x: y => '1', z => '2'} -include x -} - -apply_manifest_on(agents, manifest) do |result| - fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2" -end - -######################################################################## -step "should allow param classes defaults" -manifest = %q{ -class x($y, $z='2') { - notice("${y}-${z}") -} -class {x: y => '1'} -} - -apply_manifest_on(agents, manifest) do |result| - fail_test "the default didn't apply as expected" unless result.stdout.include? "1-2" -end - -######################################################################## -step "should allow param class defaults to be overridden" -manifest = %q{ -class x($y, $z='2') { - notice("${y}-${z}") -} -class {x: y => '1', z => '3'} -} - -apply_manifest_on(agents, manifest) do |result| - fail_test "the override didn't happen as we expected" unless result.stdout.include? "1-3" -end diff --git a/acceptance/tests/apply/classes/should_allow_param_override.rb b/acceptance/tests/apply/classes/should_allow_param_override.rb deleted file mode 100755 index c077e27201..0000000000 --- a/acceptance/tests/apply/classes/should_allow_param_override.rb +++ /dev/null @@ -1,23 +0,0 @@ -test_name "should allow param override" - -tag 'audit:high', - 'audit:unit' # This should be covered at the unit layer. - -manifest = %q{ -class parent { - notify { 'msg': - message => parent, - } -} -class child inherits parent { - Notify['msg'] {message => 'child'} -} -include parent -include child -} - -apply_manifest_on(agents, manifest) do |result| - fail_test "parameter override didn't work" unless - result.stdout.include? "defined 'message' as 'child'" -end - diff --git a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb deleted file mode 100755 index 052bdf270e..0000000000 --- a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb +++ /dev/null @@ -1,39 +0,0 @@ -test_name "should allow overriding a parameter to undef in inheritence" - -tag 'audit:high', - 'audit:unit' # This should be covered at the unit layer. - -agents.each do |agent| - dir = agent.tmpdir('class_undef_override') - out = File.join(dir, 'class_undef_override_out') - source = File.join(dir, 'class_undef_override_test') - -manifest = %Q{ - class parent { - file { 'test': - path => '#{out}', - source => '#{source}', - } - } - class child inherits parent { - File['test'] { - source => undef, - content => 'hello new world!', - } - } - include parent - include child -} - - step "prepare the target file on all systems" - on(agent, "echo 'hello world!' > #{out}") - step "apply the manifest" - apply_manifest_on(agent, manifest) - step "verify the file content" - on(agent, "cat #{out}") do |result| - fail_test "the file was not touched" if result.stdout.include? "hello world!" - fail_test "the file was not updated" unless result.stdout.include? "hello new world" - end - - on(agent, "rm -rf #{dir}") -end diff --git a/acceptance/tests/apply/classes/should_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_include_resources_from_class.rb deleted file mode 100755 index 52f78f513f..0000000000 --- a/acceptance/tests/apply/classes/should_include_resources_from_class.rb +++ /dev/null @@ -1,14 +0,0 @@ -test_name "resources declared in a class can be applied with include" - -tag 'audit:high', - 'audit:unit' # This should be covered at the unit layer. - -manifest = %q{ -class x { - notify{'a':} -} -include x -} -apply_manifest_on(agents, manifest) do |result| - fail_test "the resource did not apply" unless result.stdout.include?("defined 'message' as 'a'") -end diff --git a/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb deleted file mode 100755 index 80aeea50fd..0000000000 --- a/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb +++ /dev/null @@ -1,10 +0,0 @@ -test_name "resources declared in classes are not applied without include" - -tag 'audit:high', - 'audit:unit' # This should be covered at the unit layer. - -manifest = %q{ class x { notify { 'test': message => 'never invoked' } } } -apply_manifest_on(agents, manifest) do |result| - fail_test "found the notify despite not including it" if - result.stdout.include? "never invoked" -end diff --git a/acceptance/tests/catalog_with_binary_data.rb b/acceptance/tests/catalog_with_binary_data.rb deleted file mode 100644 index fcb35f69a6..0000000000 --- a/acceptance/tests/catalog_with_binary_data.rb +++ /dev/null @@ -1,83 +0,0 @@ -test_name "C100300: Catalog containing binary data is applied correctly" do - require 'puppet/acceptance/common_utils' - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tag 'risk:high', - 'server' - - test_num = 'c100300' - tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*')) - agent_tmp_dirs = {} - agents.each do |agent| - agent_tmp_dirs[agent_to_fqdn(agent)] = agent.tmpdir(tmp_environment) - end - - teardown do - step 'remove all test files on agents' do - agents.each {|agent| on(agent, "rm -r '#{agent_tmp_dirs[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)} - end - - # Remove all traces of the last used environment - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - - # note - master teardown is registered by #mk_tmp_environment_with_teardown - end - - step "Create module with binary data file on master" do - on(master, "mkdir -p '#{environmentpath}/#{tmp_environment}/modules/#{test_num}'/{manifests,files}") - master_module_manifest = "#{environmentpath}/#{tmp_environment}/modules/#{test_num}/manifests/init.pp" - master_module_binary_file = "#{environmentpath}/#{tmp_environment}/modules/#{test_num}/files/binary_data" - - create_remote_file(master, master_module_binary_file, "\xC0\xFF") - on(master, "chmod 644 '#{master_module_binary_file}'") - - manifest = <<-MANIFEST - class #{test_num}( - ) { - \$test_path = \$facts['networking']['fqdn'] ? #{agent_tmp_dirs} - file { '#{test_num}': - path => "\$test_path/#{test_num}", - content => binary_file('#{test_num}/binary_data'), - ensure => present, - } - } - MANIFEST - create_remote_file(master, master_module_manifest, manifest) - on(master, "chmod 644 '#{master_module_manifest}'") - end - - step "Create site.pp to classify nodes to include module" do - site_pp_file = "#{environmentpath}/#{tmp_environment}/manifests/site.pp" - site_pp = <<-SITE_PP - node default { - include #{test_num} - } - SITE_PP - create_remote_file(master, site_pp_file, site_pp) - on(master, "chmod 644 '#{site_pp_file}'") - end - - step "start the master" do - with_puppet_running_on(master, {}) do - - step "run puppet and ensure that binary data was correctly applied" do - agents.each do |agent| - on(agent, puppet('agent', '--test', "--environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - on(agent, "#{Puppet::Acceptance::CommandUtils::ruby_command(agent)} -e 'puts File.binread(\"#{agent_tmp_dirs[agent_to_fqdn(agent)]}/#{test_num}\").bytes.map {|b| b.to_s(16)}'") do |res| - assert_match(/c0\nff/, res.stdout, 'Binary file did not contain originally specified data') - end - end - end - - end - end - -end diff --git a/acceptance/tests/direct_puppet/cached_catalog_remediate_local_drift.rb b/acceptance/tests/direct_puppet/cached_catalog_remediate_local_drift.rb deleted file mode 100644 index 60c9fb33e9..0000000000 --- a/acceptance/tests/direct_puppet/cached_catalog_remediate_local_drift.rb +++ /dev/null @@ -1,137 +0,0 @@ -require 'puppet/acceptance/static_catalog_utils' -extend Puppet::Acceptance::StaticCatalogUtils - -test_name "PUP-5122: Puppet remediates local drift using code_id and content_uri" do - - tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # use mk_tmp_environment_with_teardown helper for environment construction - 'server' - - - skip_test 'requires puppetserver installation' if @options[:type] != 'aio' - - basedir = master.tmpdir(File.basename(__FILE__, '.*')) - module_dir = "#{basedir}/environments/production/modules" - - master_opts = { - 'main' => { - 'environmentpath' => "#{basedir}/environments" - } - } - - step "Add versioned-code parameters to puppetserver.conf and ensure the server is running" do - setup_puppetserver_code_id_scripts(master, basedir) - end - - teardown do - cleanup_puppetserver_code_id_scripts(master, basedir) - on master, "rm -rf #{basedir}" - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "Create a module and a file with content representing the first code_id version" do - apply_manifest_on(master, < true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{basedir}':; - '#{basedir}/environments':; - '#{basedir}/environments/production':; - '#{basedir}/environments/production/manifests':; - '#{module_dir}':; - '#{module_dir}/foo':; - '#{module_dir}/foo/files':; -} -MANIFEST - end - - with_puppet_running_on master, master_opts, basedir do - agents.each do |agent| - agent_test_file_path = agent.tmpfile('foo_file') - - step "Add test file resource to site.pp on master with agent-specific file path" do - apply_manifest_on(master, < true) -File { - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { "#{basedir}/environments/production/manifests/site.pp" : - ensure => file, - mode => "0640", - content => "node default { - file { '#{agent_test_file_path}' : - ensure => file, - source => 'puppet:///modules/foo/foo.txt' - } -}", -} - -file { "#{module_dir}/foo/files/foo.txt" : - ensure => file, - content => "code_version_1", - mode => "0640", -} -MANIFEST - end - - step "agent: #{agent}: Initial run: create the file with code version 1 and cache the catalog" - on(agent, puppet("agent", "-t"), :acceptable_exit_codes => [0,2]) - - # When there is no drift, there should be no request made to the server - # for file metadata or file content. A puppet run depending on - # a non-server will fail if such a request is made. Verify the agent - # sends a report. - - step "Remove existing reports from server reports directory" - on(master, "rm -rf /opt/puppetlabs/server/data/puppetserver/reports/#{agent.node_name}/*") - r = on(master, "ls /opt/puppetlabs/server/data/puppetserver/reports/#{agent.node_name} | wc -l").stdout.chomp - assert_equal(r, '0', "reports directory should be empty!") - - step "Verify puppet run without drift does not make file request from server" - r = on(agent, puppet("agent", - "--use_cached_catalog", - "--server", "no_such_host", - "--report_server", master.hostname, - "--onetime", - "--no-daemonize", - "--detailed-exitcodes", - "--verbose" - )).stderr - assert_equal(r, "", "Fail: Did agent try to contact server?") - - step "Verify report was delivered to server" - r = on(master, "ls /opt/puppetlabs/server/data/puppetserver/reports/#{agent.node_name} | wc -l").stdout.chomp - assert_equal(r, '1', "Reports directory should have one file") - - step "agent: #{agent}: Remove the test file to simulate drift" - on(agent, "rm -rf #{agent_test_file_path}") - - step "Alter the source file on the master to simulate a code update" - apply_manifest_on(master, < true) -file { "#{module_dir}/foo/files/foo.txt" : - ensure => file, - mode => "0640", - content => "code_version_2", -} -MANIFEST - - step "Run agent again using --use_cached_catalog and ensure content from the first code_id is used" - on(agent, puppet("agent", "-t", "--use_cached_catalog"), :acceptable_exit_codes => [0,2]) - on(agent, "cat #{agent_test_file_path}") do |result| - assert_equal('code_version_1', result.stdout) - end - end - end -end diff --git a/acceptance/tests/direct_puppet/catalog_uuid_correlates_catalogs_with_reports.rb b/acceptance/tests/direct_puppet/catalog_uuid_correlates_catalogs_with_reports.rb deleted file mode 100644 index 45c862f7f5..0000000000 --- a/acceptance/tests/direct_puppet/catalog_uuid_correlates_catalogs_with_reports.rb +++ /dev/null @@ -1,56 +0,0 @@ -test_name "PUP-5872: catalog_uuid correlates catalogs with reports" do - - tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # remove dependence on server by adding a - # catalog and report fixture to validate against. - - master_reportdir = create_tmpdir_for_user(master, 'reportdir') - - def remove_reports_on_master(master_reportdir, agent_node_name) - on(master, "rm -rf #{master_reportdir}/#{agent_node_name}/*") - end - - def get_catalog_uuid_from_cached_catalog(host, agent_vardir, agent_node_name) - cache_catalog_uuid = nil - on(host, "cat #{agent_vardir}/client_data/catalog/#{agent_node_name}.json") do |result| - cache_catalog_uuid = result.stdout.match(/"catalog_uuid":"([a-z0-9\-]*)",/)[1] - end - cache_catalog_uuid - end - - def get_catalog_uuid_from_report(master_reportdir, agent_node_name) - report_catalog_uuid = nil - on(master, "cat #{master_reportdir}/#{agent_node_name}/*") do |result| - report_catalog_uuid = result.stdout.match(/catalog_uuid: '?([a-z0-9\-]*)'?/)[1] - end - report_catalog_uuid - end - - with_puppet_running_on(master, :master => { :reportdir => master_reportdir, :reports => 'store' }) do - agents.each do |agent| - agent_vardir = agent.tmpdir(File.basename(__FILE__, '.*')) - - step "agent: #{agent}: Initial run to retrieve a catalog and generate the first report" do - on(agent, puppet("agent", "-t", "--vardir #{agent_vardir}"), :acceptable_exit_codes => [0,2]) - end - - cache_catalog_uuid = get_catalog_uuid_from_cached_catalog(agent, agent_vardir, agent.node_name) - - step "agent: #{agent}: Ensure the catalog and report share the same catalog_uuid" do - report_catalog_uuid = get_catalog_uuid_from_report(master_reportdir, agent.node_name) - assert_equal(cache_catalog_uuid, report_catalog_uuid, "catalog_uuid found in cached catalog, #{cache_catalog_uuid} did not match report #{report_catalog_uuid}") - end - - step "cleanup reports on master" do - remove_reports_on_master(master_reportdir, agent.node_name) - end - - step "Run with --use_cached_catalog and ensure catalog_uuid in the new report matches the cached catalog" do - on(agent, puppet("agent", "--onetime", "--no-daemonize", "--use_cached_catalog", "--vardir #{agent_vardir}"), :acceptance_exit_codes => [0,2]) - report_catalog_uuid = get_catalog_uuid_from_report(master_reportdir, agent.node_name) - assert_equal(cache_catalog_uuid, report_catalog_uuid, "catalog_uuid found in cached catalog, #{cache_catalog_uuid} did not match report #{report_catalog_uuid}") - end - end - end -end diff --git a/acceptance/tests/direct_puppet/static_catalog_env_control.rb b/acceptance/tests/direct_puppet/static_catalog_env_control.rb deleted file mode 100644 index cb751bb92b..0000000000 --- a/acceptance/tests/direct_puppet/static_catalog_env_control.rb +++ /dev/null @@ -1,344 +0,0 @@ -test_name "Environment control of static catalogs" - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # use mk_tmp_environment_with_teardown helper for environment construction - 'server' - -skip_test 'requires puppetserver to test static catalogs' if @options[:type] != 'aio' - -require 'json' - -@testroot = master.tmpdir(File.basename(__FILE__, '/*')) -@coderoot = "#{@testroot}/code" -@confdir = master['puppetserver-confdir'] -@master_opts = { - 'main' => { - 'environmentpath' => "#{@coderoot}/environments", - }, -} -@production_files = {} -@canary_files = {} -@agent_manifests = {} -@catalog_files = {} -agents.each do |agent| - hn = agent.node_name - resdir = agent.tmpdir('results') - @production_files[hn] = "#{resdir}/prod_hello_from_puppet_uri" - @canary_files[hn] = "#{resdir}/can_hello_from_puppet_uri" - @catalog_files[hn] = "#{on(agent, puppet('config', 'print', 'client_datadir')).stdout.chomp}/catalog/#{hn}.json" - @agent_manifests[hn] = < file, - mode => "0644", - content => "class hello { - notice('hello from production-hello') - file { '#{resdir}' : - ensure => directory, - mode => '0755', - } - file { '#{resdir}/prod_hello_from_puppet_uri' : - ensure => file, - mode => '0644', - source => 'puppet:///modules/hello/hello_msg', - } -}", -} - -file { '#{@coderoot}/environments/canary/modules/can_hello/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class can_hello { - notice("hello from production-hello") - file { "#{resdir}": - ensure => directory, - mode => "0755", - } - file { "#{resdir}/can_hello_from_puppet_uri" : - ensure => file, - mode => "0644", - source => "puppet:///modules/can_hello/hello_msg", - } -}', -} -MANIFESTAGENT -end - -# The code_content script needs to return the correct content whose checksum -# matches the metadata contained in the static catalog. -PRODUCTION_CONTENT = "Hello message from production/hello module, content from source attribute.".freeze -CANARY_CONTENT = "Hello message from canary/can_hello module, content from source attribute.".freeze - -@manifest = < directory, - mode => "0755", -} - -file { - '#{@testroot}':; - '#{@coderoot}':; - '#{@coderoot}/environments':; - '#{@coderoot}/environments/production':; - '#{@coderoot}/environments/production/manifests':; - '#{@coderoot}/environments/production/modules':; - '#{@coderoot}/environments/production/modules/hello':; - '#{@coderoot}/environments/production/modules/hello/manifests':; - '#{@coderoot}/environments/production/modules/hello/files':; - - '#{@coderoot}/environments/canary':; - '#{@coderoot}/environments/canary/manifests':; - '#{@coderoot}/environments/canary/modules':; - '#{@coderoot}/environments/canary/modules/can_hello':; - '#{@coderoot}/environments/canary/modules/can_hello/manifests':; - '#{@coderoot}/environments/canary/modules/can_hello/files':; - -} - -file { '#{@coderoot}/code_id.sh' : - ensure => file, - mode => "0755", - content => '#! /bin/bash -echo "code_version_1" -', -} - -file { '#{@coderoot}/code_content.sh' : - ensure => file, - mode => "0755", - content => '#! /bin/bash -# script arguments: -# $1 environment -# $2 code_id -# $3 path relative to mount -# use echo -n to omit newline -if [ $1 == "production" ] ; then - echo -n "#{PRODUCTION_CONTENT}" -else - echo -n "#{CANARY_CONTENT}" -fi -', -} - -file { '#{@coderoot}/environments/production/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -', -} - -file { '#{@coderoot}/environments/canary/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -static_catalogs = false -', -} - -file { '#{@coderoot}/environments/production/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include hello -} -", -} - -file { '#{@coderoot}/environments/canary/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include can_hello -} -", -} - -file { '#{@coderoot}/environments/production/modules/hello/files/hello_msg': - ensure => file, - mode => "0644", - content => "#{PRODUCTION_CONTENT}", -} - -file { '#{@coderoot}/environments/canary/modules/can_hello/files/hello_msg': - ensure => file, - mode => "0644", - content => "#{CANARY_CONTENT}", -} -MANIFEST - -teardown do - on(master, "mv #{@confdir}/puppetserver.conf.bak #{@confdir}/puppetserver.conf") - on(master, "rm -rf #{@testroot}") - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end -end - -step 'apply main manifest, static_catalogs unspecified in global scope, unspecified in production environment, disabled in canary environment' -on( - master, - "cp #{@confdir}/puppetserver.conf #{@confdir}/puppetserver.conf.bak" -) -apply_manifest_on(master, @manifest, :catch_failures => true) - -step "Add versioned-code parameters to puppetserver.conf and ensure the server is running" -puppetserver_config = "#{master['puppetserver-confdir']}/puppetserver.conf" -on master, "cp #{puppetserver_config} #{@coderoot}/puppetserver.conf.bak" -versioned_code_settings = { - "jruby-puppet" => { - "master-code-dir" => @coderoot - }, - "versioned-code" => { - "code-id-command" => "#{@coderoot}/code_id.sh", - "code-content-command" => "#{@coderoot}/code_content.sh" - } -} -modify_tk_config(master, puppetserver_config, versioned_code_settings) - -step 'start puppet server' -with_puppet_running_on master, @master_opts, @coderoot do - agents.each do |agent| - hn = agent.node_name - - apply_manifest_on(master, @agent_manifests[hn], :catch_failures => true) - - step 'agent gets a production catalog, should be static catalog by default' - on( - agent, - puppet( - 'agent', - '-t', - '--environment', 'production' - ), - :acceptable_exit_codes => [0, 2] - ) - - step 'verify production environment' - r = on(agent, "cat #{@catalog_files[hn]}") - catalog_content = JSON.parse(r.stdout) - assert_equal( - catalog_content['environment'], - 'production', - 'catalog for unexpectected environment' - ) - - step 'verify static catalog by finding metadata section in catalog' - assert( - catalog_content['metadata'] && catalog_content['metadata'][@production_files[hn]], - 'metadata section of catalog not found' - ) - - step 'agent gets a canary catalog, static catalog should be disabled' - on( - agent, - puppet( - 'agent', - '-t', - '--environment', 'canary' - ), - :acceptable_exit_codes => [0, 2] - ) - - step 'verify canary environment' - r = on(agent, "cat #{@catalog_files[hn]}") - catalog_content = JSON.parse(r.stdout) - assert_equal( - catalog_content['environment'], - 'canary', - 'catalog for unexpectected environment' - ) - - step 'verify not static catalog by absence of metadata section in catalog' - assert_nil( - catalog_content['metadata'], - 'unexpected metadata section found in catalog' - ) - - end -end - -step 'enable static catalog for canary environment' -@static_canary_manifest = < file, - mode => "0644", - content => 'environment_timeout = 0 -static_catalogs = true -', -} -MANIFEST2 -apply_manifest_on(master, @static_canary_manifest, :catch_failures => true) - -step 'disable global static catalog setting' -@master_opts = { - 'master' => { - 'static_catalogs' => false - }, - 'main' => { - 'environmentpath' => "#{@coderoot}/environments", - }, -} - -step 'bounce server for static catalog disable setting to take effect.' -with_puppet_running_on master, @master_opts, @coderoot do - agents.each do |agent| - hn = agent.node_name - - apply_manifest_on(master, @agent_manifests[hn], :catch_failures => true) - - step 'agent gets a production catalog, should not be a static catalog' - on( - agent, - puppet( - 'agent', - '-t', - '--environment', 'production' - ), - :acceptable_exit_codes => [0, 2] - ) - - step 'verify production environment' - r = on(agent, "cat #{@catalog_files[hn]}") - catalog_content = JSON.parse(r.stdout) - assert_equal( - catalog_content['environment'], - 'production', - 'catalog for unexpectected environment' - ) - - step 'verify production environment, not static catalog' - assert_nil( - catalog_content['metadata'], - 'unexpected metadata section found in catalog' - ) - - step 'agent gets a canary catalog, static catalog should be enabled' - on( - agent, - puppet( - 'agent', - '-t', - '--environment', 'canary' - ), - :acceptable_exit_codes => [0, 2] - ) - - step 'verify canary catalog' - r = on(agent, "cat #{@catalog_files[hn]}") - catalog_content = JSON.parse(r.stdout) - assert_equal( - catalog_content['environment'], - 'canary', - 'catalog for unexpectected environment' - ) - - step 'verify canary static catalog' - assert( - catalog_content['metadata'] && catalog_content['metadata'][@canary_files[hn]], - 'metadata section of catalog not found' - ) - - end -end diff --git a/acceptance/tests/direct_puppet/supports_utf8.rb b/acceptance/tests/direct_puppet/supports_utf8.rb deleted file mode 100644 index 2e7bffac17..0000000000 --- a/acceptance/tests/direct_puppet/supports_utf8.rb +++ /dev/null @@ -1,83 +0,0 @@ -test_name "C97172: static catalogs support utf8" do - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # Review for agent side UTF validation. - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - - tmp_file = {} - agents.each do |agent| - tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment) - end - - teardown do - # Remove all traces of the last used environment - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - - step 'clean out produced resources' do - agents.each do |agent| - if tmp_file.has_key?(agent_to_fqdn(agent)) && !tmp_file[agent_to_fqdn(agent)].empty? - on(agent, "rm -f '#{tmp_file[agent_to_fqdn(agent)]}'") - end - end - end - end - - file_contents = 'Mønti Pythøn ik den Hølie Gräilen, yër? € ‰ ㄘ 万 竹 Ü Ö' - step 'create site.pp with utf8 chars' do - manifest = < file, - content => ' -\$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file} -file { \$test_path: - content => @(UTF8) - #{file_contents} - | UTF8 -} - ', -} -MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - step 'run agent(s)' do - with_puppet_running_on(master, {}) do - agents.each do |agent| - config_version = '' - config_version_matcher = /configuration version '(\d+)'/ - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), - :acceptable_exit_codes => 2).stdout do |result| - config_version = result.match(config_version_matcher)[1] - end - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |result| - assert_equal(file_contents, result, 'file contents did not match accepted') - end - - on(agent, "rm -f '#{tmp_file[agent_to_fqdn(agent)]}'") - on(agent, puppet("agent -t --environment '#{tmp_environment}' --use_cached_catalog"), - :acceptable_exit_codes => 2).stdout do |result| - assert_match(config_version_matcher, result, 'agent did not use cached catalog') - second_config_version = result.match(config_version_matcher)[1] - asset_equal(config_version, second_config_version, 'config version should have been the same') - end - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |result| - assert_equal(file_contents, result, 'file contents did not match accepted') - end - end - end - end - -end diff --git a/acceptance/tests/environment/broken_unassigned_environment_handled_gracefully.rb b/acceptance/tests/environment/broken_unassigned_environment_handled_gracefully.rb deleted file mode 100644 index 23d32a6246..0000000000 --- a/acceptance/tests/environment/broken_unassigned_environment_handled_gracefully.rb +++ /dev/null @@ -1,66 +0,0 @@ -test_name 'PUP-3755 Test an un-assigned broken environment' - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # Use mk_tmp_environment_with_teardown helper - 'server' - -teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end -end - -step 'setup environments' - -testdir = create_tmpdir_for_user(master, 'confdir') -environment = 'debug' -manifest = <<-MANIFEST - File { - ensure => directory, - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - mode => "0750", - } - - file { "#{testdir}":; - "#{testdir}/environments":; - "#{testdir}/environments/production":; - "#{testdir}/environments/production/manifests":; - "#{testdir}/environments/production/modules":; - "#{testdir}/environments/#{environment}":; - "#{testdir}/environments/#{environment}/manifests":; - "#{testdir}/environments/#{environment}/modules":; - } - # broken envioronment - file { "#{testdir}/environments/production/manifests/site.pp": - ensure => file, - content => 'import "/tmp/bogus/*.pp"' - } - file { "#{testdir}/environments/#{environment}/manifests/site.pp": - ensure => file, - content => 'node default{\nnotify{"you win":}\n}' - } -MANIFEST - -apply_manifest_on(master, manifest, :catch_failures => true) - -step 'run agents, ensure no one complains about the other environment' - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments" - } -} - -with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - on(agent, puppet('agent', - "--test --environment #{environment}"), - :acceptable_exit_codes => (0..255)) do |result| - assert_match(/you win/, result.stdout, 'agent did not pickup newly classified environment.') - end - end -end diff --git a/acceptance/tests/environment/can_enumerate_environments.rb b/acceptance/tests/environment/can_enumerate_environments.rb deleted file mode 100644 index 3fb8a0dad9..0000000000 --- a/acceptance/tests/environment/can_enumerate_environments.rb +++ /dev/null @@ -1,73 +0,0 @@ -test_name "Can enumerate environments via an HTTP endpoint" - -tag 'audit:high', - 'audit:integration', - 'server' - -confine :except, :platform => /osx/ # see PUP-4820 - -def server_port(agent) - setting_on(agent, "agent", "serverport") -end - -def setting_on(host, section, name) - on(host, puppet("config", "print", name, "--section", section)).stdout.chomp -end - -def full_path(host, path) - if host['platform'] =~ /win/ - on(host, "cygpath '#{path}'").stdout.chomp - else - path - end -end - -def curl_master_from(agent, path, headers = '', &block) - url = "https://#{master}:#{server_port(agent)}#{path}" - cert_path = full_path(agent, setting_on(agent, "agent", "hostcert")) - key_path = full_path(agent, setting_on(agent, "agent", "hostprivkey")) - curl_base = "curl --tlsv1 -sg --cert \"#{cert_path}\" --key \"#{key_path}\" -k -H '#{headers}'" - - on agent, "#{curl_base} '#{url}'", &block -end - -master_user = puppet_config(master, 'user', section: 'master') -environments_dir = create_tmpdir_for_user master, "environments" -apply_manifest_on(master, <<-MANIFEST) -File { - ensure => directory, - owner => #{master_user}, - group => #{master.puppet['group']}, - mode => "0770", -} - -file { - "#{environments_dir}":; - "#{environments_dir}/env1":; - "#{environments_dir}/env2":; -} -MANIFEST - -master_opts = { - :master => { - :environmentpath => environments_dir - } -} -if master.is_pe? - master_opts[:master][:basemodulepath] = master['sitemoduledir'] -end - -with_puppet_running_on(master, master_opts) do - step "Ensure that an unauthenticated client cannot access the environments list" do - on(master, "curl --tlsv1 -ksv https://#{master}:#{server_port(master)}/puppet/v3/environments", :acceptable_exit_codes => [0,7]) do |result| - assert_match(/< HTTP\/1\.\d 403/, result.stderr) - end - end - - step "Ensure that an authenticated client can retrieve the list of environments" do - curl_master_from(master, '/puppet/v3/environments') do |result| - data = JSON.parse(result.stdout) - assert_equal(["env1", "env2", "production"], data["environments"].keys.sort) - end - end -end diff --git a/acceptance/tests/environment/custom_type_provider_from_same_environment.rb b/acceptance/tests/environment/custom_type_provider_from_same_environment.rb deleted file mode 100644 index 3a8074aba2..0000000000 --- a/acceptance/tests/environment/custom_type_provider_from_same_environment.rb +++ /dev/null @@ -1,121 +0,0 @@ -test_name 'C59122: ensure provider from same env as custom type' do -require 'puppet/acceptance/environment_utils' -extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:integration', # This behavior is specific to the master to 'do the right thing' - 'server' - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - file_correct = "#{tmp_environment}-correct.txt" - file_wrong = "#{tmp_environment}-wrong.txt" - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - fq_prod_environmentpath = "#{environmentpath}/production" - - teardown do - step 'clean out production env' do - on(master, "rm -rf #{fq_prod_environmentpath}/modules/*", :accept_all_exit_codes => true) - on(master, "rm #{fq_prod_environmentpath}/manifests/site.pp", :accept_all_exit_codes => true) - end - step 'clean out file resources' do - on(hosts, "rm #{file_correct} #{file_wrong}", :accept_all_exit_codes => true) - end - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create a custom type and provider in each of production and #{tmp_environment}" do - type_name = 'test_custom_type' - provider_name = 'universal' - type_content = < directory } -file { - '#{fq_tmp_environmentpath}/modules/simple_type':; - '#{fq_tmp_environmentpath}/modules/simple_type/lib':; - '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet':; - '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/type/':; - '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/':; - '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}':; - '#{fq_prod_environmentpath}/modules':; - '#{fq_prod_environmentpath}/modules/simple_type':; - '#{fq_prod_environmentpath}/modules/simple_type/lib':; - '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet':; - '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/type/':; - '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/':; - '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}':; -} -file { '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/type/#{type_name}.rb': - ensure => file, - content => '#{type_content}', -} -file { '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/type/#{type_name}.rb': - ensure => file, - content => '#{type_content}', -} -file { '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}/#{provider_name}.rb': - ensure => file, - content => '#{provider_content('correct', type_name, provider_name)}', -} -file { '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}/#{provider_name}.rb': - ensure => file, - content => '#{provider_content('wrong', type_name, provider_name)}', -} -file { '#{fq_tmp_environmentpath}/manifests/site.pp': - ensure => file, - content => 'node default { #{type_name}{"#{file_correct}": ensure=>present} }', -} -file { '#{fq_prod_environmentpath}/manifests': } -file { '#{fq_prod_environmentpath}/manifests/site.pp': - ensure => file, - content => 'node default { #{type_name}{"#{file_wrong}": ensure=>present} }', -} -MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - step "run agent in #{tmp_environment}, ensure it finds the correct provider" do - with_puppet_running_on(master,{}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert_equal(2, result.exit_code, 'agent did not exit with the correct code of 2') - assert_match(/#{file_correct}/, result.stdout, 'agent did not ensure the correct file') - assert(agent.file_exist?(file_correct), 'puppet did not create the file') - end - end - end - end - -end diff --git a/acceptance/tests/environment/directory_environment_production_created_master.rb b/acceptance/tests/environment/directory_environment_production_created_master.rb deleted file mode 100644 index 3f4c3ec0b7..0000000000 --- a/acceptance/tests/environment/directory_environment_production_created_master.rb +++ /dev/null @@ -1,42 +0,0 @@ -test_name 'ensure production environment created by master if missing' - -tag 'audit:high', - 'audit:integration', - 'server' - -testdir = create_tmpdir_for_user master, 'prod-env-created' - -step 'make environmentpath' -master_user = puppet_config(master, 'user', section: 'master') -apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) -File { - ensure => directory, - owner => #{master_user}, - group => #{master.puppet['group']}, - mode => '0640', -} - -file { - "#{testdir}":; - "#{testdir}/environments":; -} -MANIFEST - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - } -} - -step 'run master; ensure production environment created' -with_puppet_running_on(master, master_opts, testdir) do - on(master, "test -d '#{testdir}/environments/production'") - - step 'ensure catalog returned from production env with no changes' - agents.each do |agent| - on(agent, puppet("agent -t --environment production --detailed-exitcodes")) do |result| - # detailed-exitcodes produces a 0 when no changes are made. - assert_equal(0, result.exit_code) - end - end -end diff --git a/acceptance/tests/environment/enc_nonexistent_directory_environment.rb b/acceptance/tests/environment/enc_nonexistent_directory_environment.rb deleted file mode 100644 index 2c938aee1d..0000000000 --- a/acceptance/tests/environment/enc_nonexistent_directory_environment.rb +++ /dev/null @@ -1,79 +0,0 @@ -test_name "Master should produce error if enc specifies a nonexistent environment" do - require 'puppet/acceptance/classifier_utils.rb' - extend Puppet::Acceptance::ClassifierUtils - - tag 'audit:high', - 'audit:unit', - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'nonexistent_env') - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) -File { - ensure => directory, - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - mode => '0755', -} - -file { - "#{testdir}":; - "#{testdir}/environments":; - "#{testdir}/environments/production":; - "#{testdir}/environments/production/manifests":; - "#{testdir}/environments/production/manifests/site.pp": - ensure => file, - mode => '0644', - content => 'notify { "In the production environment": }'; -} - MANIFEST - - if master.is_pe? - group = { - 'name' => 'Environment Does Not Exist', - 'description' => 'Classify our test agent nodes in an environment that does not exist.', - 'environment' => 'doesnotexist', - 'environment_trumps' => true, - } - create_group_for_nodes(agents, group) - else - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - file { "#{testdir}/enc.rb": - ensure => file, - mode => '0775', - content => '#!#{master['privatebindir']}/ruby - puts "environment: doesnotexist" - '; - } - MANIFEST - end - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - } - } - master_opts['master'] = { - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb", - } if !master.is_pe? - - with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - on(agent, puppet("agent -t --verbose"), :acceptable_exit_codes => [1]) do |result| - unless agent['locale'] == 'ja' - assert_match(/Could not find a directory environment named 'doesnotexist'/, result.stderr, "Errors when nonexistent environment is specified") - end - refute_match(/In the production environment/, result.stdout, "Executed manifest from production environment") - end - end - end -end diff --git a/acceptance/tests/environment/environment_scenario-bad.rb b/acceptance/tests/environment/environment_scenario-bad.rb deleted file mode 100644 index 344ceb4f08..0000000000 --- a/acceptance/tests/environment/environment_scenario-bad.rb +++ /dev/null @@ -1,66 +0,0 @@ -test_name 'Test behavior of directory environments when environmentpath is set to a non-existent directory' do - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - require 'puppet/acceptance/classifier_utils' - extend Puppet::Acceptance::ClassifierUtils - - tag 'audit:high', - 'audit:unit', # The error responses for the agent should be covered by Ruby unit tests. - # The server 404/400 response should be covered by server integration tests. - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - classify_nodes_as_agent_specified_if_classifer_present - - step 'setup environments' - - testdir = create_tmpdir_for_user(master, 'confdir') - puppet_conf_backup_dir = create_tmpdir_for_user(master, "puppet-conf-backup-dir") - - apply_manifest_on(master, environment_manifest(testdir), :catch_failures => true) - - step 'Test' do - env_path = '/doesnotexist' - master_opts = { - 'main' => { - 'environmentpath' => "#{env_path}", - } - } - env = 'testing' - - results = use_an_environment(env, 'bad environmentpath', master_opts, testdir, puppet_conf_backup_dir, :directory_environments => true) - - expectations = { - :puppet_config => { - :exit_code => 0, - :matches => [%r{basemodulepath = /etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules}, - %r{modulepath =}, - %r{manifest =}, - %r{config_version =}], - }, - :puppet_apply => { - :exit_code => 1, - :matches => [%r{Could not find a directory environment named '#{env}' anywhere in the path.*#{env_path}}], - }, - :puppet_agent => { - :exit_code => 0, - }, - } - - agents.each do |host| - unless host['locale'] == 'ja' - expectations[:puppet_agent][:matches] = [%r{Environment '#{env}' not found on server, skipping initial pluginsync.}, - %r{Local environment: '#{env}' doesn't match server specified environment 'production', restarting agent run with environment 'production'}] - end - end - - assert_review(review_results(results, expectations)) - end -end diff --git a/acceptance/tests/environment/feature_branch_configured_environment.rb b/acceptance/tests/environment/feature_branch_configured_environment.rb deleted file mode 100644 index d95fa0d053..0000000000 --- a/acceptance/tests/environment/feature_branch_configured_environment.rb +++ /dev/null @@ -1,27 +0,0 @@ -test_name "Agent should use set environment after running with specified environment" do - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - tag 'audit:high', - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - tmp_environment = mk_tmp_environment_with_teardown(master, 'special') - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}")) do |result| - assert_match(/Info: Using environment 'special_\w+'/, result.stdout) - end - - on(agent, puppet('agent -t')) do |result| - assert_match(/Info: Using environment 'production'/, result.stdout) - end - end -end diff --git a/acceptance/tests/environment/should_find_existing_production_environment.rb b/acceptance/tests/environment/should_find_existing_production_environment.rb deleted file mode 100644 index ad5b096f6b..0000000000 --- a/acceptance/tests/environment/should_find_existing_production_environment.rb +++ /dev/null @@ -1,149 +0,0 @@ -test_name "should find existing production environment" -tag 'audit:medium' - -require 'puppet/acceptance/i18ndemo_utils' -extend Puppet::Acceptance::I18nDemoUtils - -agents.each do |agent| - path_separator = agent.platform_defaults[:pathseparator] - initial_environment = on(agent, puppet("config print environment")).stdout.chomp - initial_environment_paths = on(agent, puppet("config print environmentpath")).stdout.chomp.split(path_separator) - - default_environment_path = '' - custom_environment_path = agent.tmpdir('custom_environment') - - teardown do - step 'uninstall the module' do - uninstall_i18n_demo_module(master) - uninstall_i18n_demo_module(agent) - end - - step 'Remove custom environment paths' do - environment_paths = on(agent, puppet("config print environmentpath")).stdout.chomp - environment_paths.split(path_separator).each do |path| - agent.rm_rf(path) unless initial_environment_paths.include?(path) - end - - agent.rm_rf(custom_environment_path) - end - - step 'Reset environment settings' do - on(agent, puppet("config set environmentpath #{initial_environment_paths.join(path_separator)}")) - - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - - if initial_environment == 'production' - on(agent, puppet("config delete environment")) - else - on(agent, puppet("config set environment #{initial_environment}")) - end - - on(agent, puppet("agent -t")) - end - end - - step 'Ensure a clean environment with default settings' do - step 'Remove the lastrunfile which contains the last used agent environment' do - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - - step 'Change to the default environment setting' do - on(agent, puppet("config delete environment")) - on(agent, puppet("config print environment")) do |result| - assert_match('production', result.stdout, "Default environment is not 'production' as expected") - end - end - - step 'Change to the default environmentpath setting and remove production folder' do - on(agent, puppet("config delete environmentpath")) - default_environment_path = on(agent, puppet("config print environmentpath")).stdout.chomp - agent.rm_rf("#{default_environment_path}/production") - end - - step 'Apply changes and expect puppet to create the production folder back' do - on(agent, puppet("agent -t")) - on(agent, "ls #{default_environment_path}") do |result| - assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run") - end - end - end - - step 'Install a module' do - install_i18n_demo_module(master) - end - - step 'Expect output from the custom fact of the module' do - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Error:.*i18ndemo/, result.stderr) - end - end - - step 'Add a custom environment path before the current one' do - current_environment_path = on(agent, puppet("config print environmentpath")).stdout.chomp - on(agent, puppet("config set environmentpath '#{custom_environment_path}#{path_separator}#{current_environment_path}'")) - end - - step 'Expect the module to still be found' do - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Error:.*i18ndemo/, result.stderr) - end - end - - step 'Expect no production environment folder changes' do - on(agent, "ls #{custom_environment_path}") do |result| - refute_match(/production/, result.stdout) - end - - on(agent, "ls #{default_environment_path}") do |result| - assert_match('production', result.stdout) - end - end - - step 'Remove production folder' do - agent.rm_rf("#{default_environment_path}/production") - end - - step 'Expect production environment folder to be recreated in the custom path' do - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result| - step 'Expect the module to be gone on the server node' do - refute_match(/Error:.*i18ndemo/, result.stderr) - end if agent == master - - step 'Expect the production environment, along with the module, to be synced back on the agent node' do - assert_match(/Error:.*i18ndemo/, result.stderr) - end if agent != master - end - - on(agent, "ls #{custom_environment_path}") do |result| - assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run") - end - - on(agent, "ls #{default_environment_path}") do |result| - refute_match(/production/, result.stdout) - end - end - - step 'Set back to just default environmentpath setting' do - on(agent, puppet("config delete environmentpath")) - end - - step 'Expect production environment folder to be found in both paths but use the default one' do - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result| - step 'Expect the module to be gone' do - refute_match(/Error:.*i18ndemo/, result.stderr) - end if agent == master - end - - on(agent, "ls #{default_environment_path}") do |result| - assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run") - end - - on(agent, "ls #{custom_environment_path}") do |result| - assert_match('production', result.stdout) - end - end -end diff --git a/acceptance/tests/environment/use_agent_environment_when_enc_doesnt_specify.rb b/acceptance/tests/environment/use_agent_environment_when_enc_doesnt_specify.rb deleted file mode 100644 index 4e9173e3e1..0000000000 --- a/acceptance/tests/environment/use_agent_environment_when_enc_doesnt_specify.rb +++ /dev/null @@ -1,73 +0,0 @@ -test_name "Agent should use agent environment if there is an enc that does not specify the environment" do - require 'puppet/acceptance/classifier_utils' - extend Puppet::Acceptance::ClassifierUtils - - tag 'audit:high', - 'audit:integration', - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - classify_nodes_as_agent_specified_if_classifer_present - - testdir = create_tmpdir_for_user(master, 'use_agent_env') - - create_remote_file(master, "#{testdir}/enc.rb", < true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/more_different/':; - '#{testdir}/environments/more_different/manifests':; - } - file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - mode => "0640", - content => 'notify { "production environment": }', - } - file { '#{testdir}/environments/more_different/manifests/more_different.pp': - ensure => file, - mode => "0640", - content => 'notify { "more_different_string": }', - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb", - }, - } - - with_puppet_running_on(master, master_opts, testdir) do - - agents.each do |agent| - run_agent_on(agent, "--no-daemonize --onetime --verbose --environment more_different") do |result| - assert_match(/more_different_string/, result.stdout, "Did not find more_different_string from \"more_different\" environment") - end - end - - end -end diff --git a/acceptance/tests/environment/use_agent_environment_when_no_enc.rb b/acceptance/tests/environment/use_agent_environment_when_no_enc.rb deleted file mode 100644 index b9d1bbdb21..0000000000 --- a/acceptance/tests/environment/use_agent_environment_when_no_enc.rb +++ /dev/null @@ -1,62 +0,0 @@ -test_name "Agent should use agent environment if there is no enc-specified environment" do - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This can be combined with use_agent_environment_when_enc_doesnt_specify test - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'use_agent_env') - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/more_different/':; - '#{testdir}/environments/more_different/manifests':; - } - file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - mode => "0640", - content => 'notify { "production environment": }', - } - file { '#{testdir}/environments/more_different/manifests/more_different.pp': - ensure => file, - mode => "0640", - content => 'notify { "more_different_string": }', - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - 'master' => { - 'node_terminus' => 'plain' - }, - } - - with_puppet_running_on(master, master_opts, testdir) do - - agents.each do |agent| - run_agent_on(agent, "--no-daemonize --onetime --verbose --environment more_different") do |result| - assert_match(/more_different_string/, result.stdout, "Did not find more_different_string from \"more_different\" environment") - end - end - end -end diff --git a/acceptance/tests/environment/use_enc_environment.rb b/acceptance/tests/environment/use_enc_environment.rb deleted file mode 100644 index 41f6d50d5d..0000000000 --- a/acceptance/tests/environment/use_enc_environment.rb +++ /dev/null @@ -1,87 +0,0 @@ -test_name 'Agent should use environment given by ENC and only compile a catalog once' do - require 'puppet/acceptance/classifier_utils.rb' - extend Puppet::Acceptance::ClassifierUtils - - tag 'audit:high', - 'audit:integration', - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'use_enc_env') - - if master.is_pe? - group = { - 'name' => 'Special Environment', - 'description' => 'Classify our test agent nodes in the special environment.', - 'environment' => 'special', - 'environment_trumps' => true, - } - create_group_for_nodes(agents, group) - else - - create_remote_file(master, "#{testdir}/enc.rb", < true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/special/':; - '#{testdir}/environments/special/manifests':; - } - file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - mode => "0640", - content => 'notify { "production environment": }', - } - file { '#{testdir}/environments/special/manifests/different.pp': - ensure => file, - mode => "0640", - content => 'notify { "expected_string": }', - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - } - master_opts['master'] = { - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb", - } if !master.is_pe? - - with_puppet_running_on(master, master_opts, testdir) do - - agents.each do |agent| - run_agent_on(agent, "--no-daemonize --onetime --verbose") do |result| - assert_match(/expected_string/, result.stdout, "Did not find expected_string from \"special\" environment") - caching_catalog_message_count = result.stdout.split(/Info: Caching catalog for/).length - 1 - assert_equal(caching_catalog_message_count, 1, 'Should only compile and cache the catalog once during the run') - end - end - end -end diff --git a/acceptance/tests/environment/use_enc_environment_for_files.rb b/acceptance/tests/environment/use_enc_environment_for_files.rb deleted file mode 100644 index e03d64f817..0000000000 --- a/acceptance/tests/environment/use_enc_environment_for_files.rb +++ /dev/null @@ -1,87 +0,0 @@ -test_name "Agent should use environment given by ENC for fetching remote files" do - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This test should be rolled into use_enc_environment - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'respect_enc_test') - - create_remote_file(master, "#{testdir}/enc.rb", < true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/special/':; - '#{testdir}/environments/special/manifests':; - '#{testdir}/environments/special/modules':; - '#{testdir}/environments/special/modules/amod':; - '#{testdir}/environments/special/modules/amod/files':; - } - file { '#{testdir}/environments/special/modules/amod/files/testy': - ensure => file, - mode => "0640", - content => 'special_environment', - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'environment_timeout' => 0, - }, - 'master' => { - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb", - }, - } - - with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - atmp = agent.tmpdir('respect_enc_test') - teardown do - on(agent, "rm -rf '#{atmp}'") - end - - logger.debug "agent: #{agent} \tagent.tmpdir => #{atmp}" - - create_remote_file(master, "#{testdir}/environments/special/manifests/different.pp", < "puppet:///modules/amod/testy", -} -END - on(master, "chmod 644 '#{testdir}/environments/special/manifests/different.pp'") - - run_agent_on(agent, "--no-daemonize --onetime --verbose --trace") - - on(agent, "cat '#{atmp}/special_testy'") do |result| - assert_match(/special_environment/, - result.stdout, - "The file from environment 'special' was not found") - end - end - end -end diff --git a/acceptance/tests/environment/use_enc_environment_for_pluginsync.rb b/acceptance/tests/environment/use_enc_environment_for_pluginsync.rb deleted file mode 100644 index 1d4dd113eb..0000000000 --- a/acceptance/tests/environment/use_enc_environment_for_pluginsync.rb +++ /dev/null @@ -1,75 +0,0 @@ -test_name "Agent should use environment given by ENC for pluginsync" do - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This test should be rolled into use_enc_environment - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'respect_enc_test') - - create_remote_file(master, "#{testdir}/enc.rb", < true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/special/':; - '#{testdir}/environments/special/modules':; - '#{testdir}/environments/special/modules/amod':; - '#{testdir}/environments/special/modules/amod/lib':; - '#{testdir}/environments/special/modules/amod/lib/puppet':; - } - file { '#{testdir}/environments/special/modules/amod/lib/puppet/foo.rb': - ensure => file, - mode => "0640", - content => "#special_version", - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - 'master' => { - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb" - }, - } - - with_puppet_running_on(master, master_opts, testdir) do - - agents.each do |agent| - agent_vardir = agent.puppet['vardir'] - teardown do - on(agent, "rm -rf '#{agent_vardir}/lib'") - end - - run_agent_on(agent, "-t --no-daemonize --onetime") - on(agent, "cat '#{agent_vardir}/lib/puppet/foo.rb'") do |result| - assert_match(/#special_version/, result.stdout, "The plugin from environment 'special' was not synced") - end - end - end -end diff --git a/acceptance/tests/environment/use_environment_from_environmentpath.rb b/acceptance/tests/environment/use_environment_from_environmentpath.rb deleted file mode 100644 index 14a9034747..0000000000 --- a/acceptance/tests/environment/use_environment_from_environmentpath.rb +++ /dev/null @@ -1,193 +0,0 @@ -test_name "Use environments from the environmentpath" do - require 'puppet/acceptance/classifier_utils' - extend Puppet::Acceptance::ClassifierUtils - - tag 'audit:high', - 'audit:integration', - 'server' - - classify_nodes_as_agent_specified_if_classifer_present - - testdir = create_tmpdir_for_user(master, 'use_environmentpath') - - def generate_environment(path_to_env, environment) - <<-EOS - "#{path_to_env}/#{environment}":; - "#{path_to_env}/#{environment}/manifests":; - "#{path_to_env}/#{environment}/modules":; - EOS - end - - def generate_module_content(module_name, options = {}) - base_path = options[:base_path] - environment = options[:environment] - env_path = options[:env_path] - - path_to_module = [base_path, env_path, environment, "modules"].compact.join("/") - module_info = "module-#{module_name}" - module_info << "-from-#{environment}" if environment - - <<-EOS - "#{path_to_module}/#{module_name}":; - "#{path_to_module}/#{module_name}/manifests":; - "#{path_to_module}/#{module_name}/files":; - "#{path_to_module}/#{module_name}/templates":; - "#{path_to_module}/#{module_name}/lib":; - "#{path_to_module}/#{module_name}/lib/facter":; - - "#{path_to_module}/#{module_name}/manifests/init.pp": - ensure => file, - mode => "0640", - content => 'class #{module_name} { - notify { "template-#{module_name}": message => template("#{module_name}/our_template.erb") } - file { "$agent_file_location/file-#{module_info}": source => "puppet:///modules/#{module_name}/data" } - }' - ; - "#{path_to_module}/#{module_name}/lib/facter/environment_fact_#{module_name}.rb": - ensure => file, - mode => "0640", - content => "Facter.add(:environment_fact_#{module_name}) { setcode { 'environment fact from #{module_info}' } }" - ; - "#{path_to_module}/#{module_name}/files/data": - ensure => file, - mode => "0640", - content => "data file from #{module_info}" - ; - "#{path_to_module}/#{module_name}/templates/our_template.erb": - ensure => file, - mode => "0640", - content => "<%= @environment_fact_#{module_name} %>" - ; - EOS - end - - def generate_site_manifest(path_to_manifest, *modules_to_include) - <<-EOS - "#{path_to_manifest}/site.pp": - ensure => file, - mode => "0640", - content => "#{modules_to_include.map {|m| "include #{m}"}.join("\n")}" - ; - EOS - end - - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) -File { - ensure => directory, - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - mode => "0770", -} - -file { - "#{testdir}":; - "#{testdir}/base":; - "#{testdir}/additional":; - "#{testdir}/modules":; -#{generate_environment("#{testdir}/base", "shadowed")} - #{generate_environment("#{testdir}/base", "onlybase")} - #{generate_environment("#{testdir}/additional", "shadowed")} - - #{generate_module_content("atmp", - :base_path => testdir, - :env_path => 'base', - :environment => 'shadowed')} - #{generate_site_manifest("#{testdir}/base/shadowed/manifests", "atmp", "globalmod")} - - #{generate_module_content("atmp", - :base_path => testdir, - :env_path => 'base', - :environment => 'onlybase')} - #{generate_site_manifest("#{testdir}/base/onlybase/manifests", "atmp", "globalmod")} - - #{generate_module_content("atmp", - :base_path => testdir, - :env_path => 'additional', - :environment => 'shadowed')} - #{generate_site_manifest("#{testdir}/additional/shadowed/manifests", "atmp", "globalmod")} - -# And one global module (--modulepath setting) -#{generate_module_content("globalmod", :base_path => testdir)} - "#{testdir}/additional/production":; - "#{testdir}/additional/production/manifests":; -#{generate_site_manifest("#{testdir}/additional/production/manifests", "globalmod")} -} - MANIFEST - - def run_with_environment(agent, environment, options = {}) - expected_exit_code = options[:expected_exit_code] || 2 - - step "running an agent in environment '#{environment}'" - atmp = agent.tmpdir("use_environmentpath_#{environment}") - - teardown do - on(agent, "rm -rf '#{atmp}'") - end - - agent_config = [ - "-t" - ] - agent_config << '--environment' << environment if environment - # This to test how the agent behaves when using the directory environment - # loaders (which will not load an environment if it does not exist) - agent_config << "--environmentpath='$confdir/environments'" if agent != master - agent_config << { - 'ENV' => { "FACTER_agent_file_location" => atmp }, - } - - on(agent, - puppet("agent", *agent_config), - :acceptable_exit_codes => [expected_exit_code]) do |result| - - yield atmp, result - end - end - - master_opts = { - 'master' => { - 'environmentpath' => "#{testdir}/additional:#{testdir}/base", - 'basemodulepath' => "#{testdir}/modules", - } - } - if master.is_pe? - master_opts['master']['basemodulepath'] << ":#{master['sitemoduledir']}" - end - - with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - run_with_environment(agent, "shadowed") do |tmpdir, catalog_result| - ["module-atmp-from-shadowed", "module-globalmod"].each do |expected| - assert_match(/environment fact from #{expected}/, catalog_result.stdout) - end - - ["module-atmp-from-shadowed", "module-globalmod"].each do |expected| - on(agent, "cat '#{tmpdir}/file-#{expected}'") do |file_result| - assert_match(/data file from #{expected}/, file_result.stdout) - end - end - end - - run_with_environment(agent, "onlybase") do |tmpdir, catalog_result| - ["module-atmp-from-onlybase", "module-globalmod"].each do |expected| - assert_match(/environment fact from #{expected}/, catalog_result.stdout) - end - - ["module-atmp-from-onlybase", "module-globalmod"].each do |expected| - on(agent, "cat '#{tmpdir}/file-#{expected}'") do |file_result| - assert_match(/data file from #{expected}/, file_result.stdout) - end - end - end - - run_with_environment(agent, "production", :expected_exit_code => 2) do |tmpdir, catalog_result| - refute_match(/module-atmp/, catalog_result.stdout, "module-atmp was included despite the default environment being loaded") - - assert_match(/environment fact from module-globalmod/, catalog_result.stdout) - - on(agent, "cat '#{tmpdir}/file-module-globalmod'") do |file_result| - assert_match(/data file from module-globalmod/, file_result.stdout) - end - end - end - end -end diff --git a/acceptance/tests/environment/use_last_server_specified_environment.rb b/acceptance/tests/environment/use_last_server_specified_environment.rb deleted file mode 100644 index 4d75ac65d0..0000000000 --- a/acceptance/tests/environment/use_last_server_specified_environment.rb +++ /dev/null @@ -1,88 +0,0 @@ -test_name "Agent should use the last server-specified environment if server is authoritative" do - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - tag 'audit:high', - 'server' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - testdir = create_tmpdir_for_user(master, 'use_enc_env') - - create_remote_file(master, "#{testdir}/enc.rb", < true) - File { - ensure => directory, - mode => "0770", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/special/':; - '#{testdir}/environments/special/manifests':; - } - file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - mode => "0640", - content => 'notify { "production environment": }', - } - file { '#{testdir}/environments/special/manifests/different.pp': - ensure => file, - mode => "0640", - content => 'notify { "special environment": }', - } - MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - }, - } - master_opts['master'] = { - 'node_terminus' => 'exec', - 'external_nodes' => "#{testdir}/enc.rb", - } if !master.is_pe? - - with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - step 'ensure the lastrunfile is absent for the first run' do - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - - step 'first run: agent makes a node request to get the environment' do - run_agent_on(agent, '--no-daemonize --onetime --debug') do |result| - assert_match(/Local environment: 'production' doesn't match server specified node environment 'special', switching agent to 'special'/, result.stdout) - assert_match(/Debug: HTTP GET .*\/puppet\/v3\/node/, result.stdout) - assert_match(/Notice: special environment/, result.stdout) - end - end - - step 'second run: agent uses the environment from lastrunfile' do - run_agent_on(agent, '--no-daemonize --onetime --debug') do |result| - assert_match(/Debug: Successfully loaded last environment from the lastrunfile/, result.stdout) - assert_match(/Notice: special environment/, result.stdout) - end - end - end - end -end diff --git a/acceptance/tests/environment/variables_refreshed_each_compilation.rb b/acceptance/tests/environment/variables_refreshed_each_compilation.rb deleted file mode 100644 index 7b1fa57247..0000000000 --- a/acceptance/tests/environment/variables_refreshed_each_compilation.rb +++ /dev/null @@ -1,112 +0,0 @@ -test_name 'C98115 compilation should get new values in variables on each compilation' do - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - confine :except, :platform => /^(aix|osx|solaris)/ - - tag 'audit:high', - 'audit:integration', - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - create_remote_file(master, "#{fq_tmp_environmentpath}/environment.conf", <<-CONF) - environment_timeout = unlimited - CONF - # the module function loading logic is different from inside a single manifest - # we exercise both here - on(master, "mkdir -p '#{fq_tmp_environmentpath}'/modules/custom_time/{manifests,functions,facts.d}") - create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/manifests/init.pp", <<-FILE) - class custom_time { - $t = custom_time::my_system_time() - - notify { 'custom time': - message => "module_${t}_module", - } - } - FILE - create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/functions/my_system_time.pp", <<-FILE) - function custom_time::my_system_time() { - $facts['custom_time'] - } - FILE - create_sitepp(master, tmp_environment, <<-SITE) - function bar() { - $facts['custom_time'] - } - class foo::bar { - notify { "local_${bar()}_local": } - } - include foo::bar - include custom_time - SITE - create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/facts.d/custom_time.sh", <<-FILE) -#!/bin/bash - - -if [[ `uname` == 'Darwin' ]]; then - echo -n "custom_time=$(date +%s)" -else - echo -n "custom_time=$(date +%s%N)" -fi - FILE - - on(master, "chmod -R 0777 '#{fq_tmp_environmentpath}/'") - - windows_fact_location = "#{fq_tmp_environmentpath}/modules/custom_time/facts.d/custom_time.ps1" - create_remote_file(master, windows_fact_location, <<-FILE) -echo "custom_time=$(get-date -format HHmmssffffff)" - FILE - - on(master, "chmod -R 0666 '#{windows_fact_location}'") - - - step "run agent in #{tmp_environment}, ensure it increments the customtime with each run" do - with_puppet_running_on(master, {}) do - local_custom_time_pattern = 'local_(\d+)_local' - module_custom_time_pattern = 'module_(\d+)_module' - agents.each do |agent| - # ensure our custom facts have been synced - on(agent, - puppet("agent -t --environment '#{tmp_environment}'"), - :accept_all_exit_codes => true) - - local_custom_time1 = module_custom_time1 = nil - local_custom_time2 = module_custom_time2 = nil - - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), - :accept_all_exit_codes => [2]) do |result| - assert_match(/Notice: #{local_custom_time_pattern}/, result.stdout, 'first custom time was not as expected') - assert_match(/Notice: #{module_custom_time_pattern}/, result.stdout, 'first module uptime was not as expected') - - local_custom_time1 = result.stdout.match(/Notice: #{local_custom_time_pattern}/)[1].to_i - module_custom_time1 = result.stdout.match(/Notice: #{module_custom_time_pattern}/)[1].to_i - end - - sleep 1 - - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), - :accept_all_exit_codes => [2]) do |result| - assert_match(/Notice: #{local_custom_time_pattern}/, result.stdout, 'second custom time was not as expected') - assert_match(/Notice: #{module_custom_time_pattern}/, result.stdout, 'second module uptime was not as expected') - - local_custom_time2 = result.stdout.match(/Notice: #{local_custom_time_pattern}/)[1].to_i - module_custom_time2 = result.stdout.match(/Notice: #{module_custom_time_pattern}/)[1].to_i - end - - assert(local_custom_time2 > local_custom_time1, 'local custom time did not change as expected if at all') - assert(module_custom_time2 > module_custom_time1, 'module custom time did not change as expected if at all') - end - end - end -end diff --git a/acceptance/tests/face/4654_facts_face.rb b/acceptance/tests/face/4654_facts_face.rb deleted file mode 100644 index d8dc895483..0000000000 --- a/acceptance/tests/face/4654_facts_face.rb +++ /dev/null @@ -1,67 +0,0 @@ -test_name "Puppet facts face should resolve custom and external facts" - -tag 'audit:high', - 'audit:integration' # The facter acceptance tests should be acceptance. - # However, the puppet face merely needs to interact with libfacter. - # So, this should be an integration test. -# -# This test is intended to ensure that custom and external facts present -# on the agent are resolved and displayed by the puppet facts face. -# -custom_fact = < < directory, - } - - file { "#{agent.puppet['plugindest']}/facter/custom.rb": - ensure => file, - content => "#{custom_fact}", - } - - file { "#{agent.puppet['pluginfactdest']}/external#{ext}": - ensure => file, - mode => "0755", - content => "#{external_fact}", - } -MANIFEST - - step "Agent #{agent}: custom_fact and external_fact should be present in the output of `puppet facts`" - on agent, puppet('facts') do |result| - assert_match(/"custom_fact": "foo"/, result.stdout, "custom_fact did not match expected output") - assert_match(/"external_fact": "bar"/, result.stdout, "external_fact did not match expected output") - end -end diff --git a/acceptance/tests/face/loadable_from_modules.rb b/acceptance/tests/face/loadable_from_modules.rb deleted file mode 100644 index 15d80450cc..0000000000 --- a/acceptance/tests/face/loadable_from_modules.rb +++ /dev/null @@ -1,113 +0,0 @@ -test_name "Exercise loading a face from a module" - -# Because the module tool does not work on windows, we can't run this test there -confine :except, :platform => 'windows' - -tag 'audit:high', - 'audit:acceptance', # This has been OS sensitive. - 'audit:refactor' # Remove the confine against windows and refactor to - # accommodate the Windows platform. - -require 'puppet/acceptance/temp_file_utils' -extend Puppet::Acceptance::TempFileUtils -initialize_temp_dirs - -metadata_json_file = <<-FILE -{ - "name": "puppetlabs-helloworld", - "version": "0.0.1", - "author": "Puppet Labs", - "summary": "Nginx Module", - "license": "Apache Version 2.0", - "source": "https://github.com/puppetlabs/puppetlabs-nginx", - "project_page": "https://github.com/puppetlabs/puppetlabs-nginx", - "issues_url": "https://github.com/puppetlabs/puppetlabs-nginx", - "dependencies": [ - {"name":"puppetlabs-stdlub","version_requirement":">= 1.0.0"} - ] -} -FILE - -agents.each do |agent| - - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing not supported on fips enabled platforms" - next - end - - environmentpath = get_test_file_path(agent, 'environments') - dev_modulepath = "#{environmentpath}/dev/modules" - module_base_dir = "#{dev_modulepath}/helloworld" - - teardown do - on agent, "rm -rf #{module_base_dir}" - end - - # make sure that we use the modulepath from the dev environment - puppetconf = get_test_file_path(agent, 'puppet.conf') - on agent, puppet("config", "set", "environmentpath", environmentpath, "--section", "main", "--config", puppetconf) - on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf) - - mkdirs agent, module_base_dir - create_remote_file(agent, "#{module_base_dir}/metadata.json", metadata_json_file) - mkdirs agent, "#{module_base_dir}/lib/puppet/application" - mkdirs agent, "#{module_base_dir}/lib/puppet/face" - - # copy application, face, and utility module - create_remote_file(agent, "#{module_base_dir}/lib/puppet/application/helloworld.rb", <<'EOM') -require 'puppet/face' -require 'puppet/application/face_base' - -class Puppet::Application::Helloworld < Puppet::Application::FaceBase -end -EOM - - create_remote_file(agent, "#{module_base_dir}/lib/puppet/face/helloworld.rb", <<'EOM') -Puppet::Face.define(:helloworld, '0.1.0') do - summary "Hello world face" - description "This is the hello world face" - - action 'actionprint' do - summary "Prints hello world from an action" - when_invoked do |options| - puts "Hello world from an action" - end - end - - action 'moduleprint' do - summary "Prints hello world from a required module" - when_invoked do |options| - require 'puppet/helloworld.rb' - Puppet::Helloworld.print - end - end -end -EOM - - create_remote_file(agent, "#{module_base_dir}/lib/puppet/helloworld.rb", <<'EOM') -module Puppet::Helloworld - def print - puts "Hello world from a required module" - end - module_function :print -end -EOM - - on(agent, puppet('help', '--config', puppetconf)) do |result| - assert_match(/helloworld\s*Hello world face/, result.stdout, "Face missing from list of available subcommands") - end - - on(agent, puppet('help', 'helloworld', '--config', puppetconf)) do |result| - assert_match(/This is the hello world face/, result.stdout, "Descripion help missing") - assert_match(/moduleprint\s*Prints hello world from a required module/, result.stdout, "help for moduleprint action missing") - assert_match(/actionprint\s*Prints hello world from an action/, result.stdout, "help for actionprint action missing") - end - - on(agent, puppet('helloworld', 'actionprint', '--config', puppetconf)) do |result| - assert_match(/^Hello world from an action$/, result.stdout, "face did not print hello world") - end - - on(agent, puppet('helloworld', 'moduleprint', '--config', puppetconf)) do |result| - assert_match(/^Hello world from a required module$/, result.stdout, "face did not load module to print hello world") - end -end diff --git a/acceptance/tests/face/parser_validate.rb b/acceptance/tests/face/parser_validate.rb deleted file mode 100644 index f913eb67b6..0000000000 --- a/acceptance/tests/face/parser_validate.rb +++ /dev/null @@ -1,70 +0,0 @@ -test_name 'parser validate' do - -tag 'audit:high', - 'audit:unit' # Parser validation should be core to ruby - # and platform agnostic. - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - app_type = File.basename(__FILE__, '.*') - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - agents.each do |agent| - skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr' - - step 'manifest with parser function call' do - if agent.platform !~ /windows/ - tmp_environment = mk_tmp_environment_with_teardown(agent, app_type) - - create_sitepp(agent, tmp_environment, <<-SITE) -function validate_this() { - notice('hello, puppet') -} -validate_this() - SITE - on(agent, puppet("parser validate --environment #{tmp_environment}"), :pty => true) # default manifest - end - - # manifest with Type aliases - create_test_file(agent, "#{app_type}.pp", <<-PP) -function validate_this() { - notice('hello, puppet') -} -validate_this() -type MyInteger = Integer -notice 42 =~ MyInteger - PP - tmp_manifest = get_test_file_path(agent, "#{app_type}.pp") - on(agent, puppet("parser validate #{tmp_manifest}")) - end - - step 'manifest with bad syntax' do - create_test_file(agent, "#{app_type}_broken.pp", "notify 'hello there'") - tmp_manifest = get_test_file_path(agent, "#{app_type}_broken.pp") - on(agent, puppet("parser validate #{tmp_manifest}"), :accept_all_exit_codes => true) do |result| - assert_equal(result.exit_code, 1, 'parser validate did not exit with 1 upon parse failure') - expected = /Error: Could not parse for environment production: This Name has no effect\. A value was produced and then forgotten \(one or more preceding expressions may have the wrong form\) \(file: .*_broken\.pp, line: 1, column: 1\)/ - assert_match(expected, result.output, "parser validate did not output correctly: '#{result.output}'. expected: '#{expected.to_s}'") unless agent['locale'] == 'ja' - end - end - - step '(large) manifest with exported resources' do - fixture_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures/manifest_large_exported_classes_node.pp') - create_test_file(agent, "#{app_type}_exported.pp", File.read(fixture_path)) - tmp_manifest = get_test_file_path(agent, "#{app_type}_exported.pp") - on(agent, puppet("parser validate #{tmp_manifest}")) - end - - end - -end diff --git a/acceptance/tests/i18n/enable_option_disable_i18n.rb b/acceptance/tests/i18n/enable_option_disable_i18n.rb deleted file mode 100644 index d55e22c184..0000000000 --- a/acceptance/tests/i18n/enable_option_disable_i18n.rb +++ /dev/null @@ -1,88 +0,0 @@ -test_name 'Verify that disable_i18n can be set to true and have translations disabled' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - step "configure server locale to #{language}" do - configure_master_system_locale(language) - end - - tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*')) - - step 'install a i18ndemo module' do - install_i18n_demo_module(master, tmp_environment) - end - - disable_i18n_default_master = master.puppet['disable_i18n'] - teardown do - step 'resetting the server locale' do - on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }")) - reset_master_system_locale - end - step 'uninstall the module' do - agents.each do |agent| - uninstall_i18n_demo_module(agent) - end - uninstall_i18n_demo_module(master) - end - end - - agents.each do |agent| - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - on(master, puppet("config set disable_i18n false")) - reset_master_system_locale - end - - step 'expect #{language} translation for a custom type' do - site_pp_content = <<-PP - node default { - i18ndemo_type { '12345': } - } - PP - create_sitepp(master, tmp_environment, site_pp_content) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result| - assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param') - end - end - - step 'disable i18n' do - on(agent, puppet("config set disable_i18n true")) - on(master, puppet("config set disable_i18n true")) - reset_master_system_locale - end - - step 'expect no #{language} translation for a custom type' do - site_pp_content = <<-PP - node default { - i18ndemo_type { '12345': } - } - PP - create_sitepp(master, tmp_environment, site_pp_content) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result| - assert_match(/Error: .* Value 12345 is not a valid value for i18ndemo_type\:\:name/, result.stderr) - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_agent.rb b/acceptance/tests/i18n/modules/puppet_agent.rb deleted file mode 100644 index 50c7131762..0000000000 --- a/acceptance/tests/i18n/modules/puppet_agent.rb +++ /dev/null @@ -1,142 +0,0 @@ -test_name 'C100565: puppet agent with module should translate messages' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - skip_test('i18n test module uses deprecated function; update module to resume testing.') - # function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15 - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - disable_i18n_default_master = master.puppet['disable_i18n'] - - step 'enable i18n on master' do - on(master, puppet("config set disable_i18n false")) - end - - step "configure server locale to #{language}" do - configure_master_system_locale(language) - end - - tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*')) - - step 'install a i18ndemo module' do - install_i18n_demo_module(master, tmp_environment) - end - - teardown do - step 'resetting the server locale' do - on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }")) - reset_master_system_locale - end - step 'uninstall the module' do - agents.each do |agent| - uninstall_i18n_demo_module(agent) - end - uninstall_i18n_demo_module(master) - end - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - type_path = agent.tmpdir('provider') - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - agent.rm_rf(type_path) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step "Run puppet agent of a module with language #{agent_language} and verify the translations" do - - step 'verify custom fact translations' do - site_pp_content_1 = <<-PP - node default { - class { 'i18ndemo': - filename => '#{type_path}' - } - } - PP - - create_sitepp(master, tmp_environment, site_pp_content_1) - on(agent, puppet("agent -t --no-disable_i18n --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact') - end - end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved - - step 'verify custom type translations' do - site_pp_content_2 = <<-PP - node default { - i18ndemo_type { 'hello': } - } - PP - - create_sitepp(master, tmp_environment, site_pp_content_2) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result| - assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, result.stderr, 'missing warning from custom type') - end - - site_pp_content_3 = <<-PP - node default { - i18ndemo_type { '12345': } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_3) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result| - assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param') - end - end - - step 'verify custom provider translation' do - site_pp_content_4 = <<-PP - node default { - i18ndemo_type { 'hello': - ensure => present, - dir => '#{type_path}', - } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_4) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language)) do |result| - assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message') - end - end - - step 'verify function string translation' do - site_pp_content_5 = <<-PP - node default { - notify { 'happy': - message => happyfuntime('happy') - } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_5) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result| - assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb b/acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb deleted file mode 100644 index 7bf115da41..0000000000 --- a/acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb +++ /dev/null @@ -1,128 +0,0 @@ -test_name 'C100566: puppet agent with module should translate messages when using a cached catalog' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - skip_test('i18n test module uses deprecated function; update module to resume testing.') - # function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15 - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - disable_i18n_default_master = master.puppet['disable_i18n'] - - step 'enable i18n on master' do - on(master, puppet("config set disable_i18n false")) - end - - step "configure server locale to #{language}" do - configure_master_system_locale(language) - end - - tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*')) - - step 'install a i18ndemo module' do - install_i18n_demo_module(master, tmp_environment) - end - - teardown do - step 'resetting the server locale' do - on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }")) - reset_master_system_locale - end - step 'uninstall the module' do - agents.each do |agent| - uninstall_i18n_demo_module(agent) - end - uninstall_i18n_demo_module(master) - end - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - type_path = agent.tmpdir('provider') - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - agent.rm_rf(type_path) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - unresolved_server = 'puppet.unresolved.host.example.com' - - step "Run puppet apply of a module with language #{agent_language} and verify the translations using the cached catalog" do - step 'verify custom fact translations' do - site_pp_content_1 = <<-PP - node default { - class { 'i18ndemo': - filename => '#{type_path}' - } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_1) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact') - end - on(agent, puppet("agent -t --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact when using cached catalog') - end - end - - step 'verify custom provider translation' do - site_pp_content_2 = <<-PP - node default { - i18ndemo_type { 'hello': - ensure => present, - dir => '#{type_path}', - } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_2) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message') - end - on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message when using cached catalog') - end - end - - step 'verify function string translation' do - site_pp_content_3 = <<-PP - node default { - notify { 'happy': - message => happyfuntime('happy') - } - } - PP - create_sitepp(master, tmp_environment, site_pp_content_3) - on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message') - end - on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result| - assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message when using cached catalog') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb b/acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb deleted file mode 100644 index 94856e6a92..0000000000 --- a/acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb +++ /dev/null @@ -1,100 +0,0 @@ -test_name 'C100575: puppet agent with different modules in different environments should translate based on their module' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - app_type_1 = File.basename(__FILE__, '.*') + "_env_1" - app_type_2 = File.basename(__FILE__, '.*') + "_env_2" - tmp_environment_1 = mk_tmp_environment_with_teardown(master, app_type_1) - tmp_environment_2 = mk_tmp_environment_with_teardown(master, app_type_2) - full_path_env_1 = File.join('/tmp', tmp_environment_1) - full_path_env_2 = File.join('/tmp', tmp_environment_2) - tmp_po_file = master.tmpfile('tmp_po_file') - - disable_i18n_default_master = master.puppet['disable_i18n'] - step 'enable i18n on master' do - on(master, puppet("config set disable_i18n false")) - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(master, tmp_environment_1) - install_i18n_demo_module(master, tmp_environment_2) - end - - step "configure server locale to #{language}" do - configure_master_system_locale(language) - end - - teardown do - on(master, "rm -f '#{tmp_po_file}'") - step 'uninstall the module' do - agents.each do |agent| - uninstall_i18n_demo_module(agent) - end - uninstall_i18n_demo_module(master) - end - step 'resetting the server locale' do - on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }")) - reset_master_system_locale - end - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - env_1_po_file = File.join(full_path_env_1, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po") - on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_1\"':\\2/' #{env_1_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_1_po_file}") - env_2_po_file = File.join(full_path_env_2, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po") - on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_2\"':\\2/' #{env_2_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_2_po_file}") - on(master, "chmod a+r '#{env_1_po_file}' '#{env_2_po_file}'") - - step 'verify function string translation' do - site_pp_content = <<-PP - node default { - notify { 'happy': - message => happyfuntime('happy') - } - } - PP - create_sitepp(master, tmp_environment_1, site_pp_content) - on(agent, puppet("agent -t --environment #{tmp_environment_1}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result| - assert_match(/Notice: --\*(ENV_1:)?ENV_1:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 1') - end - - create_sitepp(master, tmp_environment_2, site_pp_content) - on(agent, puppet("agent -t --environment #{tmp_environment_2}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result| - assert_match(/Notice: --\*(ENV_2:)?ENV_2:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 2') - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_apply.rb b/acceptance/tests/i18n/modules/puppet_apply.rb deleted file mode 100644 index f6d7a2c282..0000000000 --- a/acceptance/tests/i18n/modules/puppet_apply.rb +++ /dev/null @@ -1,82 +0,0 @@ -test_name 'C100567: puppet apply of module should translate messages' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - skip_test('i18n test module uses deprecated function; update module to resume testing.') - # function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15 - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - type_path = agent.tmpdir('provider') - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - on(agent, "rm -rf '#{type_path}'") - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step "Run puppet apply of a module with language #{agent_language} and verify the translations" do - step 'verify custom fact translations' do - on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, apply_result.stderr, 'missing translation for raise from ruby fact') - end - end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved - - step 'verify custom translations' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, apply_result.stderr, 'missing warning from custom type') - end - - on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, apply_result.stderr, 'missing error from invalid value for custom type param') - end - end - - step 'verify custom provider translation' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, apply_result.stderr, 'missing translated provider message') - end - end - - step 'verify function string translation' do - on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, apply_result.stdout, 'missing translated notice message') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_apply_module_lang.rb b/acceptance/tests/i18n/modules/puppet_apply_module_lang.rb deleted file mode 100644 index 8cb49b19f8..0000000000 --- a/acceptance/tests/i18n/modules/puppet_apply_module_lang.rb +++ /dev/null @@ -1,93 +0,0 @@ -test_name 'C100574: puppet apply using a module should translate messages in a language not supported by puppet' do - - confine :except, :platform => /^windows/ # Can't print Finish on an English or Japanese code page - - tag 'audit:medium', - 'audit:acceptance' - - skip_test('i18n test module uses deprecated function; update module to resume testing.') - # function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15 - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language='fi_FI' - - agents.each do |agent| - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - type_path = agent.tmpdir('provider') - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - on(agent, "rm -rf '#{type_path}'") - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step "Run puppet apply of a module with language #{agent_language} and verify default english returned" do - step 'verify custom fact message translated and applied catalog message not translatated' do - on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/i18ndemo_fact: tämä on korotus mukautetusta tosiasiasta \w+-i18ndemo/, - apply_result.stderr, 'missing translated message for raise from ruby fact') - assert_match(/Notice: Applied catalog in [0-9.]+ seconds/, apply_result.stdout, 'missing untranslated message for catalog applied') - end - end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved - - step 'verify warning translated from init.pp' do - on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Warning: .*I18ndemo-tiedoston luominen/, apply_result.stderr, 'missing translated warning from init.pp') - end - - on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Error: .* tiedostoa ei voitu luoda./, apply_result.stderr, 'missing translated message for fail from init.pp') - end - end - - step 'verify custom type messages translated' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Warning: .* Hyvä arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated warning from custom type') - end - - on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Error: .* Arvo 12345 ei ole kelvollinen arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated error from invalid value for custom type param') - end - end - - step 'verify custom provider translation' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Warning: .* Onko i18ndemo_type olemassa\?/, apply_result.stderr, 'missing translated provider message') - end - end - - step 'verify function string translation' do - on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Notice: --\*SE ON HAUSKAA AIKAA\*--/, apply_result.stdout, 'missing translated notice message') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb b/acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb deleted file mode 100644 index 41ab356725..0000000000 --- a/acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb +++ /dev/null @@ -1,83 +0,0 @@ -test_name 'C100568: puppet apply of module for an unsupported language should fall back to english' do - - tag 'audit:medium', - 'audit:acceptance' - - skip_test('i18n test module uses deprecated function; update module to resume testing.') - # function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15 - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - unsupported_language='hu_HU' - shell_env_language = { 'LANGUAGE' => unsupported_language, 'LANG' => unsupported_language } - - agents.each do |agent| - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - type_path = agent.tmpdir('provider') - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - on(agent, "rm -rf '#{type_path}'") - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - step "Run puppet apply of a module with language #{unsupported_language} and verify default english returned" do - step 'verify custom fact messages not translatated' do - on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/.*i18ndemo_fact: this is a raise from a custom fact from \w+-i18ndemo/, apply_result.stderr, 'missing untranslated message for raise from ruby fact') - end - end - - step 'verify warning not translated from init.pp' do - on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Warning:.*Creating an i18ndemo file/, apply_result.stderr, 'missing untranslated warning from init.pp') - end - - on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Error:.*Failed to create/, apply_result.stderr, 'missing untranslated message for fail from init.pp') - end - end - - step 'verify custom type messages not translated' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Warning:.*Good value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated warning from custom type') - end - - on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result| - assert_match(/Error:.*Value 12345 is not a valid value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated error from invalid value for custom type param') - end - end - - step 'verify custom provider translation' do - on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Warning:.* Does i18ndemo_type exist\?/, apply_result.stderr, 'missing untranslated provider message') - end - end - - step 'verify function string translation' do - on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result| - assert_match(/Notice: --\*IT'S HAPPY FUN TIME\*--/, apply_result.stdout, 'missing untranslated notice message') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_describe.rb b/acceptance/tests/i18n/modules/puppet_describe.rb deleted file mode 100644 index 5e5916b427..0000000000 --- a/acceptance/tests/i18n/modules/puppet_describe.rb +++ /dev/null @@ -1,51 +0,0 @@ -test_name 'C100576: puppet describe with module type translates message' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - step "Run puppet describe from a module with language #{agent_language} and verify the translations" do - on(agent, puppet('describe i18ndemo_type', 'ENV' => shell_env_language)) do |result| - assert_match(/\w+-i18ndemo type: dirパラメータは、検査するディレクトリパスをとります/, result.stdout, 'missing translation of dir parameter from i18ndemo_type') - assert_match(/\w+-i18ndemo type: nameパラメータには、大文字と小文字の変数A-Za-zが使用されます/, result.stdout, 'missing translation of name parameter from i18ndemo_type') - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_face.rb b/acceptance/tests/i18n/modules/puppet_face.rb deleted file mode 100644 index 50c83b8632..0000000000 --- a/acceptance/tests/i18n/modules/puppet_face.rb +++ /dev/null @@ -1,64 +0,0 @@ -test_name 'C100573: puppet application/face with module translates messages' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - step "Run puppet i18ndemo (face/application from a module with language #{agent_language} and verify the translations" do - step 'puppet --help contains i18ndemo summary translation' do - on(agent, puppet('--help', 'ENV' => shell_env_language)) do |result| - assert_match(/\s*i18ndemo\s+\w+-i18ndemo face: I18ndemoモジュールの人形の顔の例/, result.stdout, 'missing translation of i18ndemo help summary') - end - end - - step 'puppet i18ndemo --help contains test_face summary' do - on(agent, puppet('i18ndemo --help', 'ENV' => shell_env_language)) do |result| - assert_match(/\s*test_face\s+\w+-i18ndemo face: test_faceアクションのヘルプの要約/, result.stdout, 'missing translation of i18ndemo face help summary') - end - end - - step 'puppet i18ndemo test_face contains translated warning' do - on(agent, puppet('i18ndemo', 'ENV' => shell_env_language)) do |result| - assert_match(/Warning: \w+-i18ndemo face: i18ndemo test_faceが呼び出されました/, result.stderr, 'missing translation of Warning message from i18ndemo face') - end - end - end - end -end diff --git a/acceptance/tests/i18n/modules/puppet_resource.rb b/acceptance/tests/i18n/modules/puppet_resource.rb deleted file mode 100644 index 56dd97d1fa..0000000000 --- a/acceptance/tests/i18n/modules/puppet_resource.rb +++ /dev/null @@ -1,52 +0,0 @@ -test_name 'C100572: puppet resource with module translates messages' do - confine :except, :platform => /^solaris/ # translation not supported - - tag 'audit:medium', - 'audit:acceptance' - - require 'puppet/acceptance/i18n_utils' - extend Puppet::Acceptance::I18nUtils - - require 'puppet/acceptance/i18ndemo_utils' - extend Puppet::Acceptance::I18nDemoUtils - - language = 'ja_JP' - - agents.each do |agent| - skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja' - - # REMIND - It was noted that skipping tests on certain platforms sometimes causes - # beaker to mark the test as a failed even if the test succeeds on other targets. - # Hence we just print a message and skip w/o telling beaker about it. - if on(agent, facter("fips_enabled")).stdout =~ /true/ - puts "Module build, loading and installing is not supported on fips enabled platforms" - next - end - - agent_language = enable_locale_language(agent, language) - skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil? - shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language } - - disable_i18n_default_agent = agent.puppet['disable_i18n'] - teardown do - on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }")) - uninstall_i18n_demo_module(agent) - end - - step 'enable i18n' do - on(agent, puppet("config set disable_i18n false")) - end - - step 'install a i18ndemo module' do - install_i18n_demo_module(agent) - end - - step "Run puppet resource for a module with language #{agent_language} and verify the translations" do - step 'puppet resource i18ndemo_type information contains translation' do - on(agent, puppet('resource i18ndemo_type', 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result| - assert_match(/Warning: Puppet::Type::I18ndemo_type::ProviderRuby: \w+-i18ndemo type: i18ndemo_typeからの警告メッセージ/, result.stderr, 'missing translation of resource i18ndemo_type information') - end - end - end - end -end diff --git a/acceptance/tests/i18n/translation_fallback.rb b/acceptance/tests/i18n/translation_fallback.rb deleted file mode 100644 index d5b191b92e..0000000000 --- a/acceptance/tests/i18n/translation_fallback.rb +++ /dev/null @@ -1,19 +0,0 @@ -test_name 'C100560: puppet agent run output falls back to english when language not available' do - # No confines because even on non-translation supported OS' we should still fall back to english - - tag 'audit:medium', - 'audit:acceptance' - - agents.each do |agent| - step 'Run Puppet apply with language Hungarian and check the output' do - unsupported_language='hu_HU' - on(agent, puppet("agent -t", - 'ENV' => {'LANG' => unsupported_language, 'LANGUAGE' => ''})) do |apply_result| - assert_match(/Applying configuration version '[^']*'/, apply_result.stdout, - 'agent run should default to english translation') - assert_match(/Applied catalog in [0-9.]* seconds/, apply_result.stdout, - 'agent run should default to english translation') - end - end - end -end diff --git a/acceptance/tests/language/binary_data_type.rb b/acceptance/tests/language/binary_data_type.rb deleted file mode 100644 index 00a4a2fd56..0000000000 --- a/acceptance/tests/language/binary_data_type.rb +++ /dev/null @@ -1,83 +0,0 @@ -test_name 'C98346: Binary data type' do - require 'puppet/acceptance/puppet_type_test_tools.rb' - extend Puppet::Acceptance::PuppetTypeTestTools - - tag 'audit:high', - 'audit:integration', # Tests that binary data is retains integrity - # between server and agent transport/application. - # The weak link here is final ruby translation and - # should not be OS sensitive. - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - - tmp_filename_win = tmp_filename_else = '' - agents.each do |agent| - # ugh... this won't work with more than two agents of two types - if agent.platform =~ /32$/ - tmp_filename_win = "C:\\cygwin\\tmp\\#{tmp_environment}.txt" - else - tmp_filename_win = "C:\\cygwin64\\tmp\\#{tmp_environment}.txt" - end - tmp_filename_else = "/tmp/#{tmp_environment}.txt" - on(agent, "echo 'old content' > '/tmp/#{tmp_environment}.txt'") - end - # create a fake module files... file for binary_file() - on(master, puppet_apply("-e 'file{[\"#{environmentpath}/#{tmp_environment}/modules\",\"#{environmentpath}/#{tmp_environment}/modules/empty\",\"#{environmentpath}/#{tmp_environment}/modules/empty/files\"]: ensure => \"directory\"} file{\"#{environmentpath}/#{tmp_environment}/modules/empty/files/blah.txt\": content => \"binary, yo\"}'")) - - base64_relaxed = Base64.encode64("invasionfromspace#{random_string}").strip - base64_strict = Base64.strict_encode64("invasion from space #{random_string}\n") - base64_urlsafe = Base64.urlsafe_encode64("invasion from-space/#{random_string}\n") - - test_resources = [ - { :type => 'notify', :parameters => { :namevar => "1:$hell" }, :pre_code => "$hell = Binary('hello','%b')", - :assertions => { :assert_match => 'Notice: 1:hell' } }, - { :type => 'notify', :parameters => { :namevar => "2:$relaxed" }, :pre_code => "$relaxed = Binary('#{base64_relaxed}')", - :assertions => { :assert_match => "Notice: 2:#{base64_relaxed}" } }, - { :type => 'notify', :parameters => { :namevar => "3:$cHVwcGV0" }, :pre_code => "$cHVwcGV0 = Binary('cHVwcGV0')", - :assertions => { :assert_match => 'Notice: 3:cHVwcGV0' } }, - { :type => 'notify', :parameters => { :namevar => "4:$strict" }, :pre_code => "$strict = Binary('#{base64_strict}')", - :assertions => { :assert_match => "Notice: 4:#{base64_strict}" } }, - { :type => 'notify', :parameters => { :namevar => "5:$urlsafe" }, :pre_code => "$urlsafe = Binary('#{base64_urlsafe}')", - :assertions => { :assert_match => "Notice: 5:#{base64_urlsafe}" } }, - { :type => 'notify', :parameters => { :namevar => "6:$byte_array" }, :pre_code => "$byte_array = Binary([67,68])", - :assertions => { :assert_match => "Notice: 6:Q0Q=" } }, - { :type => 'notify', :parameters => { :namevar => "7:${empty_array}empty" }, :pre_code => "$empty_array = Binary([])", - :assertions => { :assert_match => "Notice: 7:empty" } }, - { :type => 'notify', :parameters => { :namevar => "8:${relaxed[1]}" }, - :assertions => { :assert_match => "Notice: 8:bg==" } }, - { :type => 'notify', :parameters => { :namevar => "9:${relaxed[1,3]}" }, - :assertions => { :assert_match => "Notice: 9:bnZh" } }, - { :type => 'notify', :parameters => { :namevar => "A:${utf8}" }, :pre_code => '$utf8=String(Binary([0xF0, 0x9F, 0x91, 0x92]),"%s")', - :assertions => { :assert_match => 'Notice: A:\\xF0\\x9F\\x91\\x92' } }, - { :type => 'notify', :parameters => { :namevar => "B:${type($bin_file)}" }, :pre_code => '$bin_file=binary_file("empty/blah.txt")', - :assertions => { :assert_match => 'Notice: B:Binary' } }, - { :type => 'file', :parameters => { :namevar => "$pup_tmp_filename", :content => "$relaxed" }, :pre_code => "$pup_tmp_filename = if $facts['os']['family'] == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }", - :assertions => { :assert_match => /#{base64_relaxed}/ } }, - ] - - sitepp_content = generate_manifest(test_resources) - assertion_code = generate_assertions(test_resources) - - create_sitepp(master, tmp_environment, sitepp_content) - - step "run agent in #{tmp_environment}, run all assertions" do - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => [2]) do |result| - run_assertions(assertion_code, result) - end - end - end - end - -end diff --git a/acceptance/tests/language/exported_resources.rb b/acceptance/tests/language/exported_resources.rb deleted file mode 100644 index 62ab011f31..0000000000 --- a/acceptance/tests/language/exported_resources.rb +++ /dev/null @@ -1,180 +0,0 @@ -test_name "C94788: exported resources using a yaml terminus for storeconfigs" do -require 'puppet/acceptance/environment_utils' -extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This could be a component of a larger workflow scenario. - 'server' - - skip_test 'requires puppetserver to service restart' if @options[:type] != 'aio' - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - exported_username = 'er0ck' - - teardown do - step 'stop puppet server' do - service(master, :stop, master['puppetservice']) - end - step 'remove cached agent json catalogs from the master' do - on(master, "rm -f #{File.join(master.puppet['yamldir'],'catalog','*')}", - :accept_all_exit_codes => true) - end - on(master, "mv #{File.join('','tmp','puppet.conf')} #{master.puppet['confdir']}", - :accept_all_exit_codes => true) - step 'clean out collected resources' do - on(hosts, puppet_resource("user #{exported_username} ensure=absent"), :accept_all_exit_codes => true) - end - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - storeconfigs_backend_name = 'json_storeconfigs' - step 'create a yaml storeconfigs terminus in the modulepath' do - moduledir = File.join(environmentpath,tmp_environment,'modules') - terminus_class_name = 'JsonStoreconfigs' - manifest = < directory, -} -file { - '#{moduledir}':; - '#{moduledir}/yaml_terminus':; - '#{moduledir}/yaml_terminus/lib':; - '#{moduledir}/yaml_terminus/lib/puppet':; - '#{moduledir}/yaml_terminus/lib/puppet/indirector':; - '#{moduledir}/yaml_terminus/lib/puppet/indirector/catalog':; - '#{moduledir}/yaml_terminus/lib/puppet/indirector/facts':; - '#{moduledir}/yaml_terminus/lib/puppet/indirector/node':; - '#{moduledir}/yaml_terminus/lib/puppet/indirector/resource':; -} -file { '#{moduledir}/yaml_terminus/lib/puppet/indirector/catalog/#{storeconfigs_backend_name}.rb': - ensure => file, - content => ' - require "puppet/indirector/catalog/yaml" - class Puppet::Resource::Catalog::#{terminus_class_name} < Puppet::Resource::Catalog::Yaml - def save(request) - raise ArgumentError.new("You can only save objects that respond to :name") unless request.instance.respond_to?(:name) - file = path(request.key) - basedir = File.dirname(file) - # This is quite likely a bad idea, since we are not managing ownership or modes. - Dir.mkdir(basedir) unless Puppet::FileSystem.exist?(basedir) - begin - # We cannot dump anonymous modules in yaml, so dump to json - File.open(file, "w") { |f| f.write request.instance.to_json } - rescue TypeError => detail - Puppet.err "Could not save \#{self.name} \#{request.key}: \#{detail}" - end - end - def find(request) - nil - end - end - ', -} -file { '#{moduledir}/yaml_terminus/lib/puppet/indirector/facts/#{storeconfigs_backend_name}.rb': - ensure => file, - content => ' - require "puppet/indirector/facts/yaml" - class Puppet::Node::Facts::#{terminus_class_name} < Puppet::Node::Facts::Yaml - def find(request) - nil - end - end - ', -} -file { '#{moduledir}/yaml_terminus/lib/puppet/indirector/node/#{storeconfigs_backend_name}.rb': - ensure => file, - content => ' - require "puppet/indirector/node/yaml" - class Puppet::Node::#{terminus_class_name} < Puppet::Node::Yaml - def find(request) - nil - end - end - ', -} -file { '#{moduledir}/yaml_terminus/lib/puppet/indirector/resource/#{storeconfigs_backend_name}.rb': - ensure => file, - content => ' - require "puppet/indirector/yaml" - require "puppet/resource/catalog" - class Puppet::Resource::#{terminus_class_name} < Puppet::Indirector::Yaml - desc "Read resource instances from cached catalogs" - def search(request) - catalog_dir = File.join(Puppet.run_mode.server? ? Puppet[:yamldir] : Puppet[:clientyamldir], "catalog", "*") - results = Dir.glob(catalog_dir).collect { |file| - catalog = Puppet::Resource::Catalog.convert_from(:json, File.read(file)) - if catalog.name == request.options[:host] - next - end - catalog.resources.select { |resource| - resource.type == request.key && resource.exported - }.map! { |res| - data_hash = res.to_data_hash - parameters = data_hash["parameters"].map do |name, value| - Puppet::Parser::Resource::Param.new(:name => name, :value => value) - end - attrs = {:parameters => parameters, :scope => request.options[:scope]} - result = Puppet::Parser::Resource.new(res.type, res.title, attrs) - result.collector_id = "\#{catalog.name}|\#{res.type}|\#{res.title}" - result - } - }.flatten.compact - results - end - end - ', -} -# all the filtering is taken care of in the terminii -# so any tests on filtering belong with puppetdb or pe -file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp': - ensure => file, - content => ' - node "#{master.hostname}" { - @@user{"#{exported_username}": ensure => present,} - } - node "default" { - # collect resources on all nodes (puppet prevents collection on same node) - User<<| |>> - } - ', -} -MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - # must specify environment in puppet.conf for it to pickup the terminus code in an environment module - # but we have to bounce the server to pickup the storeconfigs... config anyway - # we can't use with_puppet_running_on here because it uses puppet resource to bounce the server - # puppet resource tries to use yaml_storeconfig's path() which doesn't exist - # and fails back to yaml which indicates an attempted directory traversal and fails. - # we could implemnt path() properly, but i'm just going to start the server the old fashioned way - # and... config set is broken and doesn't add a main section - step 'turn on storeconfigs, start puppetserver the old fashioned way' do - on(master, "cp #{File.join(master.puppet['confdir'],'puppet.conf')} #{File.join('','tmp')}") - on(master, "echo [main] >> #{File.join(master.puppet['confdir'],'puppet.conf')}") - on(master, "echo environment=#{tmp_environment} >> #{File.join(master.puppet['confdir'],'puppet.conf')}") - on(master, puppet('config set storeconfigs true --section main')) - on(master, puppet("config set storeconfigs_backend #{storeconfigs_backend_name} --section main")) - service(master, :restart, master['puppetservice']) - step 'run the master agent to export the resources' do - on(master, puppet("agent -t --environment #{tmp_environment}")) - end - agents.each do |agent| - next if agent == master - step 'run the agents to collect exported resources' do - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :acceptable_exit_codes => 2) - on(agent, puppet_resource("user #{exported_username}"), :accept_all_exit_codes => true) do |result| - assert_match(/present/, result.stdout, 'collected resource not found') - end - end - end - end - -end diff --git a/acceptance/tests/language/functions_in_puppet_language.rb b/acceptance/tests/language/functions_in_puppet_language.rb deleted file mode 100644 index 8ce841502f..0000000000 --- a/acceptance/tests/language/functions_in_puppet_language.rb +++ /dev/null @@ -1,139 +0,0 @@ -test_name 'Puppet executes functions written in the Puppet language' - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # use mk_tmp_environment_with_teardown helper for environment construction - 'server' - -teardown do - on master, 'rm -rf /etc/puppetlabs/code/modules/jenny' - on master, 'rm -rf /etc/puppetlabs/code/environments/tommy' - on master, 'rm -rf /etc/puppetlabs/code/environments/production/modules/one' - on master, 'rm -rf /etc/puppetlabs/code/environments/production/modules/three' - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end -end - -step 'Create some functions' do - - manifest = <<-EOF - File { - ensure => 'present', - owner => 'root', - group => 'root', - mode => '0644', - } - - file {['/etc/puppetlabs/', - '/etc/puppetlabs/code/', - '/etc/puppetlabs/code/modules/', - '/etc/puppetlabs/code/modules/jenny', - '/etc/puppetlabs/code/modules/jenny/functions', - '/etc/puppetlabs/code/modules/jenny/functions/nested', - '/etc/puppetlabs/code/environments', - '/etc/puppetlabs/code/environments/production', - '/etc/puppetlabs/code/environments/production/modules', - '/etc/puppetlabs/code/environments/production/modules/one', - '/etc/puppetlabs/code/environments/production/modules/one/functions', - '/etc/puppetlabs/code/environments/production/modules/one/manifests', - '/etc/puppetlabs/code/environments/production/modules/three', - '/etc/puppetlabs/code/environments/production/modules/three/functions', - '/etc/puppetlabs/code/environments/production/modules/three/manifests', - '/etc/puppetlabs/code/environments/tommy', - '/etc/puppetlabs/code/environments/tommy/modules', - '/etc/puppetlabs/code/environments/tommy/modules/two', - '/etc/puppetlabs/code/environments/tommy/modules/two/functions', - ]: - ensure => directory, - mode => '0755', - } - - # "Global" functions, no env - file { '/etc/puppetlabs/code/modules/jenny/functions/mini.pp': - content => 'function jenny::mini($a, $b) {if $a <= $b {$a} else {$b}}', - require => File['/etc/puppetlabs/code/modules/jenny/functions'], - } - file { '/etc/puppetlabs/code/modules/jenny/functions/nested/maxi.pp': - content => 'function jenny::nested::maxi($a, $b) {if $a >= $b {$a} else {$b}}', - require => File['/etc/puppetlabs/code/modules/jenny/functions/nested'], - } - - # Module "one", "production" env - file { '/etc/puppetlabs/code/environments/production/modules/one/functions/foo.pp': - content => 'function one::foo() {"This is the one::foo() function in the production environment"}', - require => File['/etc/puppetlabs/code/environments/production/modules/one/functions'], - } - file { '/etc/puppetlabs/code/environments/production/modules/one/manifests/init.pp': - content => 'class one { }', - require => File['/etc/puppetlabs/code/environments/production/modules/one/manifests'], - } - - # Module "three", "production" env - file { '/etc/puppetlabs/code/environments/production/modules/three/functions/baz.pp': - content => 'function three::baz() {"This is the three::baz() function in the production environment"}', - require => File['/etc/puppetlabs/code/environments/production/modules/three/functions'], - } - file { '/etc/puppetlabs/code/environments/production/modules/three/manifests/init.pp': - content => 'class three { }', - require => File['/etc/puppetlabs/code/environments/production/modules/three/functions'], - } - - # Module "two", "tommy" env - file { '/etc/puppetlabs/code/environments/tommy/modules/two/functions/bar.pp': - content => 'function two::bar() {"This is the two::bar() function in the tommy environment"}', - require => File['/etc/puppetlabs/code/environments/tommy/modules/two/functions'], - } - EOF - apply_manifest_on(master, manifest, {:catch_failures => true, :acceptable_exit_codes => [0,1]}) -end - -manifest = <<-MANIFEST - notice 'jenny::mini(1, 2) =', jenny::mini(1,2) - notice 'jenny::nested::maxi(1, 2) =', jenny::nested::maxi(1,2) - notice 'one::foo() =', one::foo() - require 'one'; notice 'three::baz() =', three::baz() -MANIFEST - -rc = apply_manifest_on(master, manifest, {:accept_all_exit_codes => true,}) - -step 'Call a global function' do - fail_test 'Failed to call a "global" function' \ - unless rc.stdout.include?('jenny::mini(1, 2) = 1') - end - -step 'Call a global nested function' do - fail_test 'Failed to call a "global" nested function' \ - unless rc.stdout.include?('jenny::nested::maxi(1, 2) = 2') - end - -step 'Call an env-specific function' do - fail_test 'Failed to call a function defined in the current environment' \ - unless rc.stdout.include?('This is the one::foo() function in the production environment') - end - -step 'Call a function defined in an un-included module' do - fail_test 'Failed to call a function defined in an un-required module' \ - unless rc.stdout.include?('This is the three::baz() function in the production environment') -end - -manifest = <<-MANIFEST.strip - notice "two::bar() =", two::bar() -MANIFEST - -# This should fail -step 'Call a function not defined in the current environment' do - rc = on master, puppet("apply -e '#{manifest}' --environment production"), {:accept_all_exit_codes => true,} - fail_test 'Should not be able to call a function not defined in the current environment' \ - unless rc.stderr.include?("Error: Evaluation Error: Unknown function: 'two::bar'") -end - -step 'Call an env-specific function in a non-default environment' do - rc = on master, puppet("apply -e '#{manifest}' --environment tommy") - fail_test 'Failed to call env-specific function from that environment' \ - unless rc.stdout.include?('This is the two::bar() function in the tommy environment') -end - diff --git a/acceptance/tests/language/objects_in_catalog.rb b/acceptance/tests/language/objects_in_catalog.rb deleted file mode 100644 index 7861b15b98..0000000000 --- a/acceptance/tests/language/objects_in_catalog.rb +++ /dev/null @@ -1,41 +0,0 @@ -test_name 'C99627: can use Object types in the catalog and apply/agent' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:integration', - 'audit:refactor' # The use of apply on a reference system should - # be adequate to test puppet. Running this in - # context of server/agent should not be necessary. - - manifest = <<-PP -type Mod::Foo = Object[{ - attributes => { - 'name' => String, - 'size' => Integer[0, default] - } -}] -define mod::foo_notifier(Mod::Foo $foo) { - notify { $foo.name: } -} -class mod { - mod::foo_notifier { xyz: - foo => Mod::Foo('A foo', 42) - } -} -include mod - PP - - agents.each do |agent| - # This is currently only expected to work with apply as the custom data type - # definition will not be present on the agent to deserialize properly - - step "apply manifest on agent #{agent.hostname} and assert notify output" do - apply_manifest_on(agent, manifest) do |result| - assert(result.exit_code == 0, "agent didn't exit properly: (#{result.exit_code})") - assert_match(/A foo/, result.stdout, 'agent didn\'t notify correctly') - end - end - end - -end diff --git a/acceptance/tests/language/pcore_generate_env_isolation.rb b/acceptance/tests/language/pcore_generate_env_isolation.rb deleted file mode 100644 index 3468711bc7..0000000000 --- a/acceptance/tests/language/pcore_generate_env_isolation.rb +++ /dev/null @@ -1,86 +0,0 @@ -test_name 'C98345: ensure puppet generate assures env. isolation' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:integration', - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - tmp_environment2 = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - fq_tmp_environmentpath2 = "#{environmentpath}/#{tmp_environment2}" - - type_name = 'conflicting' - relative_type_dir = 'modules/conflict/lib/puppet/type' - relative_type_path = "#{relative_type_dir}/#{type_name}.rb" - step 'create custom type in two environments' do - on(master, "mkdir -p #{fq_tmp_environmentpath}/#{relative_type_dir}") - on(master, "mkdir -p #{fq_tmp_environmentpath2}/#{relative_type_dir}") - - custom_type1 = <<-END - Puppet::Type.newtype(:#{type_name}) do - newparam :name, :namevar => true - END - custom_type2 = "#{custom_type1}" - custom_type2 << " newparam :other\n" - custom_type1 << " end\n" - custom_type2 << " end\n" - create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_type_path}", custom_type1) - create_remote_file(master, "#{fq_tmp_environmentpath2}/#{relative_type_path}", custom_type2) - - site_pp1 = <<-PP - notify{$environment:} - #{type_name}{"somename":} - PP - site_pp2 = <<-PP - notify{$environment:} - #{type_name}{"somename": other => "uhoh"} - PP - create_sitepp(master, tmp_environment, site_pp1) - create_sitepp(master, tmp_environment2, site_pp2) - end - - on master, "chmod -R 755 /tmp/#{tmp_environment}" - on master, "chmod -R 755 /tmp/#{tmp_environment2}" - - with_puppet_running_on(master,{}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :acceptable_exit_codes => 2) - step 'run agent in environment with type with an extra parameter. try to use this parameter' do - on(agent, puppet("agent -t --environment #{tmp_environment2}"), - :accept_all_exit_codes => true) do |result| - unless agent['locale'] == 'ja' - assert_match("Error: no parameter named 'other'", result.output, - 'did not produce environment isolation issue as expected') - end - end - end - end - - step 'generate pcore files' do - on(master, puppet("generate types --environment #{tmp_environment}")) - on(master, puppet("generate types --environment #{tmp_environment2}")) - end - - agents.each do |agent| - step 'rerun agents after generate, ensure proper runs' do - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :acceptable_exit_codes => 2) - on(agent, puppet("agent -t --environment #{tmp_environment2}"), - :acceptable_exit_codes => 2) - end - end - end - -end diff --git a/acceptance/tests/language/pcore_resource_types_should_have_precedence_over_ruby.rb b/acceptance/tests/language/pcore_resource_types_should_have_precedence_over_ruby.rb deleted file mode 100644 index d0eb3f5461..0000000000 --- a/acceptance/tests/language/pcore_resource_types_should_have_precedence_over_ruby.rb +++ /dev/null @@ -1,114 +0,0 @@ -test_name 'C98097 - generated pcore resource types should be loaded instead of ruby for custom types' do - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # use `mk_tmp_environment_with_teardown` helper to build environment - 'server' - - environment = 'production' - step 'setup - install module with custom ruby resource type' do - #{{{ - testdir = master.tmpdir('c98097') - codedir = "#{testdir}/codedir" - - site_manifest_content =< true) do - desc "Name of mycustomtype instance" - $stderr.puts "this indicates that we are running ruby code and should not be seen when running generated pcore resource" - end - - def refresh - end - -end -EOM - - apply_manifest_on(master, < true) -File { - ensure => directory, - mode => "0755", -} - -file {[ - '#{codedir}', - '#{codedir}/environments', - '#{codedir}/environments/#{environment}', - '#{codedir}/environments/#{environment}/manifests', - '#{codedir}/environments/#{environment}/modules', - '#{codedir}/environments/#{environment}/modules/mymodule', - '#{codedir}/environments/#{environment}/modules/mymodule/manifests', - '#{codedir}/environments/#{environment}/modules/mymodule/lib', - '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet', - '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet/type' - ]: -} - -file { '#{codedir}/environments/#{environment}/manifests/site.pp': - ensure => file, - content => '#{site_manifest_content}', -} - -file { '#{codedir}/environments/#{environment}/modules/mymodule/lib/puppet/type/mycustomtype.rb': - ensure => file, - content => '#{custom_type_content}', -} -MANIFEST - - conf_opts = { - 'main' => { - 'environmentpath' => "#{codedir}/environments" - } - } - - backup_file = backup_the_file(master, puppet_config(master, 'confdir', section: 'master'), testdir, 'puppet.conf') - lay_down_new_puppet_conf master, conf_opts, testdir - - teardown do - restore_puppet_conf_from_backup( master, backup_file ) - # See PUP-6995 - on(master, "rm -f #{puppet_config(master, 'yamldir', section: 'master')}/node/*.yaml") - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - #}}} - - catalog_results = {} - catalog_results[master.hostname] = { 'ruby_cat' => '', 'pcore_cat' => '' } - - step 'compile catalog using ruby resource' do - on master, puppet('catalog', 'find', master.hostname) do |result| - assert_match(/running ruby code/, result.stderr) - catalog_results[master.hostname]['ruby_cat'] = JSON.parse(result.stdout.sub(/^[^{]+/,'')) - end - end - - step 'generate pcore type from ruby type' do - on master, puppet('generate', 'types', '--environment', environment) - end - - step 'compile catalog and make sure that ruby code is NOT executed' do - on master, puppet('catalog', 'find', master.hostname) do |result| - refute_match(/running ruby code/, result.stderr) - catalog_results[master.hostname]['pcore_cat'] = JSON.parse(result.stdout.sub(/^[^{]+/,'')) - end - end - - step 'ensure that the resources created in the catalog using ruby and pcore are the same' do - assert_equal(catalog_results[master.hostname]['ruby_cat']['resources'], catalog_results[master.hostname]['pcore_cat']['resources']) - end - - end -end diff --git a/acceptance/tests/language/resource_refs_with_nested_arrays.rb b/acceptance/tests/language/resource_refs_with_nested_arrays.rb deleted file mode 100644 index b8c345ff3b..0000000000 --- a/acceptance/tests/language/resource_refs_with_nested_arrays.rb +++ /dev/null @@ -1,30 +0,0 @@ -test_name "#7681: Allow using array variables in resource references" - -tag 'audit:high', - 'audit:unit' - -agents.each do |agent| - test_manifest = < "#{agent.echo('the first command')}", - path => "#{agent.path}", - logoutput => true, -} -exec { "second": - command => "#{agent.echo('the second command')}", - path => "#{agent.path}", - logoutput => true, -} -exec { "third": - command => "#{agent.echo('the final command')}", - path => "#{agent.path}", - logoutput => true, - require => Exec[$exec_names], -} -MANIFEST - - apply_manifest_on(agent, test_manifest) do |result| - assert_match(/Exec\[third\].*the final command/, result.stdout) - end -end diff --git a/acceptance/tests/language/sensitive_data_type.rb b/acceptance/tests/language/sensitive_data_type.rb deleted file mode 100644 index e92f0326a3..0000000000 --- a/acceptance/tests/language/sensitive_data_type.rb +++ /dev/null @@ -1,138 +0,0 @@ -test_name 'C98120, C98077: Sensitive Data is redacted on CLI, logs, reports' do - require 'puppet/acceptance/puppet_type_test_tools.rb' - extend Puppet::Acceptance::PuppetTypeTestTools - -tag 'audit:high', - 'audit:acceptance', # Tests that sensitive data is retains integrity - # between server and agent transport/application. - # Leaving at acceptance layer due to validate - # written logs. - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - - tmp_filename_win = tmp_filename_else = '' - agents.each do |agent| - # ugh... this won't work with more than two agents of two types - if agent.platform =~ /32$/ - tmp_filename_win = "C:\\cygwin\\tmp\\#{tmp_environment}.txt" - else - tmp_filename_win = "C:\\cygwin64\\tmp\\#{tmp_environment}.txt" - end - tmp_filename_else = "/tmp/#{tmp_environment}.txt" - on agent, "echo 'old content' > /tmp/#{tmp_environment}.txt" - end - - # first attempts at a reasonable table driven test. needs API work - # FIXME: - # expand this to other resource types, make parameters arbitrary, make assertions arbitrary - # FIXME: add context messaging to each instance - notify_redacted = 'Sensitive \[value redacted\]' - file_redacted = 'changed \[redacted\] to \[redacted\]' - test_resources = [ - {:type => 'notify', :parameters => {:namevar => "1:${Sensitive.new('sekrit1')}"}, - :assertions => [{:refute_match => 'sekrit1'}, {:assert_match => "1:#{notify_redacted}"}]}, - {:type => 'notify', :parameters => {:namevar => "2:${Sensitive.new($meh2)}"}, :pre_code => '$meh2="sekrit2"', - :assertions => [{:refute_match => 'sekrit2'}, {:assert_match => "2:#{notify_redacted}"}]}, - {:type => 'notify', :parameters => {:namevar => "3:meh", :message => '"3:${Sensitive.new(\'sekrit3\')}"'}, - :assertions => [{:refute_match => 'sekrit3'}, {:assert_match => "3:#{notify_redacted}"}]}, - {:type => 'notify', :parameters => {:namevar => "4:meh", :message => "Sensitive.new($meh4)"}, :pre_code => '$meh4="sekrit4"', - :assertions => [{:refute_match => 'sekrit4'}, {:assert_match => file_redacted}]}, - {:type => 'notify', :parameters => {:namevar => "5:meh", :message => "$meh5"}, :pre_code => '$meh5=Sensitive.new("sekrit5")', - :assertions => [{:refute_match => 'sekrit5'}, {:assert_match => file_redacted}]}, - {:type => 'notify', :parameters => {:namevar => "6:meh", :message => '"6:${meh6}"'}, :pre_code => '$meh6=Sensitive.new("sekrit6")', - :assertions => [{:refute_match => 'sekrit6'}, {:assert_match => "6:#{notify_redacted}"}]}, - {:type => 'notify', :parameters => {:namevar => "7:${Sensitive('sekrit7')}"}, - :assertions => [{:refute_match => 'sekrit7'}, {:assert_match => "7:#{notify_redacted}"}]}, - # unwrap(), these should be en-clair - {:type => 'notify', :parameters => {:namevar => "8:${unwrap(Sensitive.new('sekrit8'))}"}, - :assertions => {:assert_match => "8:sekrit8"}}, - {:type => 'notify', :parameters => {:namevar => "9:meh", :message => '"9:${unwrap(Sensitive.new(\'sekrit9\'))}"'}, - :assertions => {:assert_match => "9:sekrit9"}}, - {:type => 'notify', :parameters => {:namevar => "A:meh", :message => '"A:${unwrap($mehA)}"'}, :pre_code => '$mehA=Sensitive.new("sekritA")', - :assertions => {:assert_match => "A:sekritA"}}, - {:type => 'notify', :parameters => {:namevar => "B:meh", :message => '"B:${$mehB.unwrap}"'}, :pre_code => '$mehB=Sensitive.new("sekritB")', - :assertions => {:assert_match => "B:sekritB"}}, - {:type => 'notify', :parameters => {:namevar => "C:meh", :message => '"C:${$mehC.unwrap |$unwrapped| { "blk_${unwrapped}_blk" } } nonblk_${mehC}_nonblk"'}, :pre_code => '$mehC=Sensitive.new("sekritC")', - :assertions => {:assert_match => ["C:blk_sekritC_blk", "nonblk_#{notify_redacted}_nonblk"]}}, - # for --show_diff - {:type => 'file', :parameters => {:namevar => "$pup_tmp_filename", :content => "Sensitive.new('sekritD')"}, :pre_code => "$pup_tmp_filename = if $facts['os']['family'] == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }", - :assertions => [{:refute_match => 'sekritD'}, {:assert_match => /#{tmp_environment}\.txt..content. #{file_redacted}/}]}, - - ] - - sitepp_content = generate_manifest(test_resources) - assertion_code = generate_assertions(test_resources) - - # Make a copy of the full set of 'test_resources' but filtered down to include - # only the assertions of type ':refute_match'. So for example, where the - # 'test_resources' array might have an entry like this... - # - # {:type => 'notify', ... - # :assertions => [{:refute_match => 'sekrit1'}, - # {:assert_match => "1:#{notify_redacted}"}]} - # - # ... the ':assert_match' entry would be filtered out in the new - # 'refutation_resources' array, producing: - # - # {:type => 'notify', ... - # :assertions => [{:refute_match => 'sekrit1'}]} - # - # This is done so that when validating the log output, we can refute the - # existence of any of the sensitive info in the log without having to - # assert that redacted info is in the log. The redacted info appears in - # the console output from the Puppet agent run - by virtue of including a - # '--debug' flag on the agent command line - whereas the redacted info is not - # expected to be piped into the log. - - refutation_resources = test_resources.collect do |assertion_group| - refutation_group = assertion_group.clone - refutation_group[:assertions] = assertion_group[:assertions].select do |assertion| - assertion.has_key?(:refute_match) - end - refutation_group - end - refutation_code = generate_assertions(refutation_resources) - - create_sitepp(master, tmp_environment, sitepp_content) - - step "run agent in #{tmp_environment}, run all assertions" do - with_puppet_running_on(master,{}) do - agents.each do |agent| - # redirect logging to a temp location to avoid platform specific syslogs - on(agent, puppet("agent -t --debug --trace --show_diff --environment #{tmp_environment}"), :accept_all_exit_codes => true) do |result| - assert_equal(result.exit_code, 2,'puppet agent run failed') - - run_assertions(assertion_code, result) unless agent['locale'] == 'ja' - - step "assert no redacted data in log" do - run_assertions(refutation_code, result) - end - end - - # don't do this before the agent log scanning, above. it will skew the results - step "assert no redacted data in vardir" do - # no recursive grep in solaris :facepalm: - on(agent, "find #{agent.puppet['vardir']} -type f | xargs grep sekrit", :accept_all_exit_codes => true) do |result| - refute_match(/sekrit(1|2|3|6|7)/, result.stdout, 'found redacted data we should not have') - #TODO: if/when this is fixed, we should just be able to eval(assertion_code_ in this result block also! - expect_failure 'file resource contents will end up in the cached catalog en-clair' do - refute_match(/sekritD/, result.stdout, 'found redacted file data we should not have') - end - end - end - - end - end - end - -end diff --git a/acceptance/tests/language/server_set_facts.rb b/acceptance/tests/language/server_set_facts.rb deleted file mode 100644 index a143a32e62..0000000000 --- a/acceptance/tests/language/server_set_facts.rb +++ /dev/null @@ -1,51 +0,0 @@ -test_name 'C64667: ensure server_facts is set and error if any value is overwritten by an agent' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:acceptance', # Validating server/client interaction - 'server' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - - step 'ensure $server_facts exist' do - create_sitepp(master, tmp_environment, <<~SITE) - $server_facts_hash_exists_and_is_not_empty = ($server_facts =~ Hash) and ($server_facts.length != 0) - notify { "server_facts hash exists and is not empty: ${server_facts_hash_exists_and_is_not_empty}": } - SITE - - master_opts = {} - with_puppet_running_on(master, master_opts) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :acceptable_exit_codes => 2) do |result| - assert_match(/Notify\[server_facts hash exists and is not empty: true\]/, result.stdout, - "#{agent}: $server_facts should have some stuff" ) - end - end - end - end - - step 'ensure puppet issues a warning if an agent overwrites a server fact' do - agents.each do |agent| - on(agent, puppet("agent -t", - 'ENV' => { 'FACTER_server_facts' => 'overwrite' }), - :acceptable_exit_codes => 1) do |result| - # Do not perform this check on non-English hosts - unless agent['locale'] == 'ja' - assert_match(/Error.*Attempt to assign to a reserved variable name: 'server_facts'/, - result.stderr, "#{agent}: $server_facts should error if overwritten" ) - end - end - end - end -end diff --git a/acceptance/tests/loader/autoload_from_resource_type_decl.rb b/acceptance/tests/loader/autoload_from_resource_type_decl.rb deleted file mode 100644 index e50f801e49..0000000000 --- a/acceptance/tests/loader/autoload_from_resource_type_decl.rb +++ /dev/null @@ -1,152 +0,0 @@ -test_name 'C100303: Resource type statement triggered auto-loading works both with and without generated types' do - tag 'risk:high' - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - # create the file and make sure its empty and accessible by everyone - def empty_execution_log_file(host, path) - create_remote_file(host, path, '') - on(host, "chmod 777 '#{path}'") - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - relative_type_dir = 'modules/one/lib/puppet/type' - relative_type_path = "#{relative_type_dir}/type_tst.rb" - - execution_log = {} - execution_log[agent_to_fqdn(master)] = master.tmpfile('master_autoload_resource') - agents.each do |agent| - execution_log[agent_to_fqdn(agent)] = agent.tmpfile('agent_autoload_resource') - end - - teardown do - on(master, "rm -f '#{execution_log[agent_to_fqdn(master)]}'") - agents.each do |agent| - on(agent, "rm -f '#{execution_log[agent_to_fqdn(agent)]}'") - - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step 'create custom type' do - on(master, "mkdir -p '#{fq_tmp_environmentpath}/#{relative_type_dir}'") - - # create a custom type that will write out to a different file on each agent - # this way we can verify whether the newtype code was executed on each system - custom_type = <<-END - Puppet::Type.newtype(:type_tst) do - newparam(:name, :namevar => true) do - fqdn = Facter.value('networking.fqdn') - if fqdn == '#{agent_to_fqdn(master)}' - File.open("#{execution_log[agent_to_fqdn(master)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) } - end - END - agents.each do |agent| - custom_type << <<-END - if fqdn == '#{agent_to_fqdn(agent)}' - File.open("#{execution_log[agent_to_fqdn(agent)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) } - end - END - end - custom_type << <<-END - Puppet.notice("found_type_tst") - end - end - END - create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_type_path}", custom_type) - - site_pp = <<-PP - Resource['type_tst'] { 'found_type': } - PP - create_sitepp(master, tmp_environment, site_pp) - end - on(master, "chmod -R 755 '/tmp/#{tmp_environment}'") - - # when the agent does its run, the newtype is executed on both the agent and master nodes - # so we should see a message in the execution log file on the agent and the master - agents.each do |agent| - with_puppet_running_on(master, {}) do - - empty_execution_log_file(master, execution_log[agent_to_fqdn(master)]) - empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)]) - - on(agent, puppet("agent -t --environment '#{tmp_environment}'")) do |puppet_result| - assert_match(/\/File\[.*\/type_tst.rb\]\/ensure: defined content as/, puppet_result.stdout, - 'Expected to see defined content message for type: type_tst') - assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see the notice from the new type: type_tst') - end - - on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result| - assert_match(/found_type_tst:/, cat_result.stdout, - "Expected to see execution log entry on master #{agent_to_fqdn(master)}") - end - on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result| - assert_match(/found_type_tst:/, cat_result.stdout, - "Expected to see execution log entry on agent #{agent_to_fqdn(agent)}") - end - end - end - - # when generating the pcore the newtype should only be run on the master node - step 'generate pcore files' do - # start with an empty execution log - empty_execution_log_file(master, execution_log[agent_to_fqdn(master)]) - agents.each do |agent| - empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)]) - end - - on(master, puppet("generate types --environment '#{tmp_environment}'")) do |puppet_result| - assert_match(/Notice: Generating '\/.*\/type_tst\.pp' using 'pcore' format/, puppet_result.stdout, - 'Expected to see Generating message for type: type_tst') - assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see log entry on master ') - end - - # we should see a log entry on the master node - on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result| - assert_match(/found_type_tst:/, cat_result.stdout, - "Expected to see execution log entry on master #{agent_to_fqdn(master)}") - end - - # we should not see any log entries on any of the agent nodes - agents.each do |agent| - next if agent == master - on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result| - assert_empty(cat_result.stdout.chomp, "Expected execution log file to be empty on agent node #{agent_to_fqdn(agent)}") - end - end - end - - empty_execution_log_file(master, execution_log[agent_to_fqdn(master)]) - agents.each do |agent| - next if agent == master - empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)]) - - # this test is relying on the beaker helper with_puppet_running_on() to restart the server - # Compilation should now work using the generated types, - # so we should only see a log entry on the agent node and nothing on the master node - with_puppet_running_on(master, {}) do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), - :acceptable_exit_codes => 0) do |puppet_result| - assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see output from new type: type_tst') - end - end - - on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result| - assert_match(/found_type_tst:/, cat_result.stdout, - "Expected to see an execution log entry on agent #{agent_to_fqdn(agent)}") - end - end - - on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result| - assert_empty(cat_result.stdout.chomp, "Expected master execution log to be empty #{agent_to_fqdn(master)}") - end -end diff --git a/acceptance/tests/loader/func4x_loadable_from_modules.rb b/acceptance/tests/loader/func4x_loadable_from_modules.rb deleted file mode 100644 index 8e8a4d8c9b..0000000000 --- a/acceptance/tests/loader/func4x_loadable_from_modules.rb +++ /dev/null @@ -1,80 +0,0 @@ -test_name "Exercise a module with 4x function and 4x system function" - -# Purpose: -# Test that a packed puppet can call a 4x system function, and that a 4x function in -# a module can be called. -# -# Method: -# * Manually construct a very simple module with a manifest that creates a file. -# * The file has content that depends on logic that calls both a system function (reduce), and -# a function supplied in the module (helloworld::mul10). -# * The module is manually constructed to allow the test to also run on Windows where the module tool -# is not supported. -# * The module is included by calling 'include' from 'puppet apply'. -# * Puppet apply is executed to generate the file with the content. -# * The generated contents is asserted. - -# TODO: The test can be improved by adding yet another module that calls the function in helloworld. -# TODO: The test can be improved to also test loading of a non namespaced function - -require 'puppet/acceptance/temp_file_utils' -extend Puppet::Acceptance::TempFileUtils - -tag 'audit:high', - 'audit:unit' # This should be covered adequately by unit tests - -initialize_temp_dirs - -agents.each do |agent| - # The modulepath to use in environment 'dev' - envs_path = get_test_file_path(agent, 'environments') - dev_modulepath = get_test_file_path(agent, 'environments/dev/modules') - target_path = get_test_file_path(agent, 'output') - mkdirs agent, target_path - - # make sure that we use the modulepath from the dev environment - puppetconf = get_test_file_path(agent, 'puppet.conf') - on agent, puppet("config", "set", "environmentpath", envs_path, "--section", "main", "--config", puppetconf) - on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf) - - # Where the functions in the written modules should go - helloworld_functions = 'helloworld/lib/puppet/functions/helloworld' - # Clean out the module that will be written to ensure no interference from a previous run - on agent, "rm -rf #{File.join(dev_modulepath, 'helloworld')}" - mkdirs agent, File.join(dev_modulepath, helloworld_functions) - - # Write a module - # Write the function helloworld::mul10, that multiplies its argument by 10 - create_remote_file(agent, File.join(dev_modulepath, helloworld_functions, "mul10.rb"), <<'SOURCE') -Puppet::Functions.create_function(:'helloworld::mul10') do - def mul10(x) - x * 10 - end -end -SOURCE - - # Write a manifest that calls a 4x function (reduce), and calls a function defined in the module - # (helloworld::mul10). - # - mkdirs agent, File.join(dev_modulepath, "helloworld", "manifests") - create_remote_file(agent, File.join(dev_modulepath, "helloworld", "manifests", "init.pp"), < 'file', - mode => '0666', - content => [1,2,3].reduce("Generated") |$memo, $n| { - "${memo}, ${n} => ${helloworld::mul10($n)}" - } - } -} -SOURCE - - # Run apply to generate the file with the output - on(agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf)) - - # Assert that the file was written with the generated content - on(agent, "cat #{File.join(target_path, 'result.txt')}") do |result| - assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, result.stdout, "Generated the wrong content") - end - -end diff --git a/acceptance/tests/loader/resource_triggers_autoload.rb b/acceptance/tests/loader/resource_triggers_autoload.rb deleted file mode 100644 index cfa193cb6d..0000000000 --- a/acceptance/tests/loader/resource_triggers_autoload.rb +++ /dev/null @@ -1,57 +0,0 @@ -test_name 'C100296: can auto-load defined types using a Resource statement' do - tag 'risk:high' - - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - relative_define_type_dir = 'modules/one/manifests' - relative_define_type_1_path = "#{relative_define_type_dir}/tst1.pp" - relative_define_type_2_path = "#{relative_define_type_dir}/tst2.pp" - step 'create custom type in two environments' do - on(master, "mkdir -p #{fq_tmp_environmentpath}/#{relative_define_type_dir}") - - define_type_1 = <<-END - define one::tst1($var) { - notify { "tst1: ${var}": } - } - END - define_type_2 = <<-END - define one::tst2($var) { - notify { "tst2: ${var}": } - } - END - create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_1_path}", define_type_1) - create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_2_path}", define_type_2) - - site_pp = <<-PP - each(['tst1', 'tst2']) |$nr| { - Resource["one::${nr}"] { "some_title_${nr}": var => "Define found one::${nr}" } - } - PP - create_sitepp(master, tmp_environment, site_pp) - end - - on(master, "chmod -R 755 /tmp/#{tmp_environment}") - - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}"), - :acceptable_exit_codes => 2) do |puppet_result| - assert_match(/Notice: tst1: Define found one::tst1/, puppet_result.stdout, 'Expected to see output from define notify') - assert_match(/Notice: tst2: Define found one::tst2/, puppet_result.stdout, 'Expected to see output from define notify') - end - end - end -end diff --git a/acceptance/tests/lookup/config3_interpolation.rb b/acceptance/tests/lookup/config3_interpolation.rb deleted file mode 100644 index 002fc23162..0000000000 --- a/acceptance/tests/lookup/config3_interpolation.rb +++ /dev/null @@ -1,80 +0,0 @@ -test_name 'C99578: lookup should allow interpolation in hiera3 configs' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This test specifically tests interpolation on the master. - # Recommend adding an additonal test that validates - # lookup in a masterless setup. - 'server' - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - master_confdir = puppet_config(master, 'confdir', section: 'master') - - hiera_conf_backup = master.tmpfile('C99578-hiera-yaml') - - step "backup global hiera.yaml" do - on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1]) - end - - teardown do - on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1]) - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create hiera configs in #{tmp_environment} and global" do - step "create global hiera.yaml and module data" do - create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA) ---- -:backends: - - "yaml" -:hierarchy: - - "%{calling_class_path}" - - "%{calling_class}" - - "%{calling_module}" - - "common" - HIERA - - on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/") - on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/manifests") - create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/manifests/init.pp", <<-PP) -class some_mod { - notify { "${lookup('environment_key')}": } -} - PP - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/some_mod.yaml", <<-YAML) ---- -environment_key: "env value" - YAML - - create_sitepp(master, tmp_environment, <<-SITE) -include some_mod - SITE - - on(master, "chmod -R 775 #{fq_tmp_environmentpath}") - on(master, "chmod -R 775 #{master_confdir}") - end - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent lookup" do - on(agent, puppet('agent', "-t --environment #{tmp_environment} --debug"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/env value/, result.stdout, - "agent lookup didn't find correct key") - end - end - end - end - -end diff --git a/acceptance/tests/lookup/config5_interpolation.rb b/acceptance/tests/lookup/config5_interpolation.rb deleted file mode 100644 index fffaf6d851..0000000000 --- a/acceptance/tests/lookup/config5_interpolation.rb +++ /dev/null @@ -1,135 +0,0 @@ -test_name 'C99578: hiera5 lookup config with interpolated scoped nested variables' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - - -tag 'audit:high', - 'audit:integration', - 'audit:refactor', # This test specifically tests interpolation on the master. - # Recommend adding an additonal test that validates - # lookup in a masterless setup. - 'server' - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1') - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create environment hiera5.yaml and environment data" do - - create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA) ---- -version: 5 -defaults: - datadir: 'hieradata' - data_hash: yaml_data -hierarchy: - - name: "Global settings" - path: "global.yaml" - - name: "Role specific settings" - paths: - - "roles/%{::roles.0}.yaml" - - name: "Other Role specific settings" - paths: - - "roles/%{roles2.0}.yaml" - - name: "scoped variable" - paths: - - "roles/%{::myclass::myvar.0}.yaml" - - name: "nested hash variable" - paths: - - "roles/%{::hash_array.key1.0}.yaml" - HIERA - - on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/roles") - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/global.yaml", <<-YAML) -roles: - - test1 -roles2: - - test2 -data: - - "from global" - YAML - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test1.yaml", <<-YAML) -data: - - 'from test1' - YAML - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test2.yaml", <<-YAML) -data: - - 'from test2' - YAML - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test3.yaml", <<-YAML) -data: - - 'from test3' - YAML - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test4.yaml", <<-YAML) -data: - - 'from test4' - YAML - - create_sitepp(master, tmp_environment, <<-SITE) -class myclass { - $myvar = ['test3'] -} -include myclass - -$hash_array = {key1 => ['test4']} - -$roles = lookup('roles') -$data = lookup('data', Array[String], 'unique') -notify{"data: ${data}":} -$hiera_array_data = hiera_array('data') -notify{"hiera_array_data: ${hiera_array_data}":} - -$roles2 = lookup('roles2') -$data2 = lookup('data', Array[String], 'unique') -notify{"data2: ${data2}":} -$hiera_array_data2 = hiera_array('data') -notify{"hiera_array_data2: ${hiera_array_data2}":} - SITE - - on(master, "chmod -R 775 #{fq_tmp_environmentpath}") - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent lookups: #{agent.hostname}, hiera5" do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/data: \[from global, from test1/, result.stdout, - "agent lookup didn't interpolate with hiera value") - assert_match(/hiera_array_data: \[from global, from test1/, result.stdout, - "agent hiera_array didn't interpolate with hiera value") - - assert_match(/data2: \[from global, from test1, from test2/, result.stdout, - "agent lookup didn't interpolate non-global scope with hiera value") - assert_match(/hiera_array_data2: \[from global, from test1, from test2/, result.stdout, - "agent hiera_array didn't interpolate non-global scope with hiera value") - - assert_match(/data2: \[from global, from test1, from test2, from test3/, result.stdout, - "agent lookup didn't interpolate class scope with hiera value") - assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3/, result.stdout, - "agent hiera_array didn't interpolate class scope with hiera value") - - assert_match(/data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout, - "agent lookup didn't interpolate nested hashes with hiera value") - assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout, - "agent hiera_array didn't interpolate nested hashes with hiera value") - end - end - end - - end - -end diff --git a/acceptance/tests/lookup/hiera3_custom_backend.rb b/acceptance/tests/lookup/hiera3_custom_backend.rb deleted file mode 100644 index f11e4d4705..0000000000 --- a/acceptance/tests/lookup/hiera3_custom_backend.rb +++ /dev/null @@ -1,102 +0,0 @@ -test_name 'C99630: hiera v3 custom backend' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - require 'puppet/acceptance/temp_file_utils.rb' - extend Puppet::Acceptance::TempFileUtils - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local module tree. - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - puppetserver_config = "#{master['puppetserver-confdir']}/puppetserver.conf" - existing_loadpath = read_tk_config_string(on(master, "cat #{puppetserver_config}").stdout.strip)['jruby-puppet']['ruby-load-path'].first - confdir = puppet_config(master, 'confdir', section: 'master') - - hiera_conf_backup = master.tmpfile('C99629-hiera-yaml') - - step "backup global hiera.yaml" do - on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1]) - end - - teardown do - step 'delete custom backend, restore default hiera config' do - on(master, "rm #{existing_loadpath}/hiera/backend/custom_backend.rb", :acceptable_exit_codes => [0,1]) - on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1]) - on(master, "/opt/puppetlabs/server/bin/puppetserver gem uninstall --executables --force hiera") - on(master, "/opt/puppetlabs/puppet/bin/gem uninstall --executables --force hiera") - end - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "install hiera v3 gem" do - # for puppet agent <-> server, hiera must be installed using puppetserver's gem command - on(master, "/opt/puppetlabs/server/bin/puppetserver gem install --no-document hiera") - # for puppet lookup, hiera must be installed using puppet's gem command - on(master, "/opt/puppetlabs/puppet/bin/gem install --no-document hiera") - end - - step "create hiera v5 config and v3 custom backend" do - on(master, "cp #{confdir}/hiera.yaml /tmp") - create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA) ---- -version: 5 -hierarchy: - - name: Test - hiera3_backend: custom - HIERA - on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{confdir}") - - on(master, "mkdir -p #{existing_loadpath}/hiera/backend/") - custom_backend_rb = <<-RB -class Hiera - module Backend - class Custom_backend - def lookup(key, scope, order_override, resolution_type, context) - return 'custom value' unless (key == 'lookup_options') - end - end - end -end - RB - create_remote_file(master, "#{existing_loadpath}/hiera/backend/custom_backend.rb", custom_backend_rb) - on(master, "chmod #{PUPPET_CODEDIR_PERMISSIONS} #{existing_loadpath}/hiera/backend/custom_backend.rb") - end - - step "create site.pp which calls lookup on our keys" do - create_sitepp(master, tmp_environment, <<-SITE) - notify { "${lookup('anykey')}": } - SITE - on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{fq_tmp_environmentpath}") - end - - step 'assert lookups using lookup subcommand on the master' do - on(master, puppet('lookup', "--environment #{tmp_environment}", '--explain', 'anykey'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/custom value/, result.stdout, - "lookup subcommand didn't find correct key") - end - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent manifest lookup on #{agent.hostname}" do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/custom value/, result.stdout, - "agent lookup didn't find correct key") - end - end - end - end - -end diff --git a/acceptance/tests/lookup/lookup.rb b/acceptance/tests/lookup/lookup.rb deleted file mode 100644 index a65d5a347a..0000000000 --- a/acceptance/tests/lookup/lookup.rb +++ /dev/null @@ -1,334 +0,0 @@ -test_name "Lookup data using the agnostic lookup function" do - # pre-docs: - # https://puppet-on-the-edge.blogspot.com/2015/01/puppet-40-data-in-modules-and.html - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local module tree. - # Use mk_tmp_environment_with_teardown to create environment. - 'server' - - testdir = master.tmpdir('lookup') - - module_name = "data_module" - module_name2 = "other_module" - hash_name = "hash_name" - array_key = "array_key" - - env_data_implied_key = "env_data_implied" - env_data_implied_value = "env_implied_a" - env_data_key = "env_data" - env_data_value = "env_a" - env_hash_key = "env_hash_key" - env_hash_value = "env_class_a" - env_array_value0 = "env_array_a" - env_array_value1 = "env_array_b" - - module_data_implied_key = "module_data_implied" - module_data_implied_value = "module_implied_b" - module_data_key = "module_data" - module_data_value = "module_b" - module_data_value_other = "other_module_b" - module_hash_key = "module_hash_key" - module_hash_value = "module_class_b" - module_array_value0 = "module_array_a" - module_array_value1 = "module_array_b" - - env_data_override_implied_key = "env_data_override_implied" - env_data_override_implied_value = "env_override_implied_c" - env_data_override_key = "env_data_override" - env_data_override_value = "env_override_c" - - hiera_data_implied_key = "apache_server_port_implied" - hiera_data_implied_value = "8080" - hiera_data_key = "apache_server_port" - hiera_data_value = "9090" - hiera_hash_key = "hiera_hash_key" - hiera_hash_value = "hiera_class_c" - hiera_array_value0 = "hiera_array_a" - hiera_array_value1 = "hiera_array_b" - - automatic_data_key = "automatic_data_key" - automatic_data_value = "automatic_data_value" - automatic_default_value = "automatic_default_value" - - def mod_manifest_entry(module_name = nil, testdir, module_data_implied_key, - module_data_implied_value, module_data_key, - module_data_value, hash_name, module_hash_key, - module_hash_value, array_key, module_array_value0, - module_array_value1) - if module_name - module_files_manifest = < file, - content => " - Puppet::Functions.create_function(:'#{module_name}::data') do - def data() - { '#{module_name}::#{module_data_implied_key}' => '#{module_data_implied_value}', - '#{module_name}::#{module_data_key}' => '#{module_data_value}', - '#{module_name}::#{hash_name}' => {'#{module_hash_key}' => '#{module_hash_value}'}, - '#{module_name}::#{array_key}' => ['#{module_array_value0}', '#{module_array_value1}'] - } - end - end - ", - mode => "0640", - } -PP - module_files_manifest - end - end - - def mod_manifest_metadata_json(module_name = nil, testdir) - if module_name - < file, - content => ' -{ - "name": "tester-#{module_name}", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [ - ], - "data_provider": "function" -} - ', - mode => "0644", - } - file { '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings': - ensure => absent, - force => true, - } -PPmetadata - end - end - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - module_manifest1 = mod_manifest_entry(module_name, testdir, module_data_implied_key, - module_data_implied_value, module_data_key, module_data_value, - hash_name, module_hash_key, module_hash_value, array_key, - module_array_value0, module_array_value1) - module_manifest2 = mod_manifest_entry(module_name2, testdir, module_data_implied_key, - module_data_implied_value, module_data_key, module_data_value_other, - hash_name, module_hash_key, module_hash_value, array_key, - module_array_value0, module_array_value1) - metadata_manifest1 = mod_manifest_metadata_json(module_name, testdir) - metadata_manifest2 = mod_manifest_metadata_json(module_name2, testdir) - - apply_manifest_on(master, <<-PP, :catch_failures => true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{testdir}':; - '#{testdir}/hieradata':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/production/modules':; - '#{testdir}/environments/production/lib':; - '#{testdir}/environments/production/lib/puppet':; - '#{testdir}/environments/production/lib/puppet/functions':; - '#{testdir}/environments/production/lib/puppet/functions/environment':; - '#{testdir}/environments/production/modules/#{module_name}':; - '#{testdir}/environments/production/modules/#{module_name}/manifests':; - '#{testdir}/environments/production/modules/#{module_name}/lib':; - '#{testdir}/environments/production/modules/#{module_name}/lib/puppet':; - '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings':; - '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings/#{module_name}':; - '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions':; - '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions/#{module_name}':; - '#{testdir}/environments/production/modules/#{module_name2}':; - '#{testdir}/environments/production/modules/#{module_name2}/manifests':; - '#{testdir}/environments/production/modules/#{module_name2}/lib':; - '#{testdir}/environments/production/modules/#{module_name2}/lib/puppet':; - '#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings':; - '#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings/#{module_name2}':; - '#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions':; - '#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions/#{module_name2}':; -} - -file { '#{testdir}/hiera.yaml': - ensure => file, - content => '--- - :backends: - - "yaml" - :logger: "console" - :hierarchy: - - "global" - - :yaml: - :datadir: "#{testdir}/hieradata" - ', - mode => "0640", -} - -file { '#{testdir}/hieradata/global.yaml': - ensure => file, - content => "--- - #{hiera_data_key}: #{hiera_data_value} - #{module_name}::#{hiera_data_implied_key}: #{hiera_data_implied_value} - #{module_name}::#{hash_name}: - #{hiera_hash_key}: #{hiera_hash_value} - #{module_name}::#{array_key}: - - #{hiera_array_value0} - - #{hiera_array_value1} - #{module_name}::#{automatic_data_key}: #{automatic_data_value} - ", - mode => "0640", -} - -file { '#{testdir}/environments/production/environment.conf': - ensure => file, - content => ' - environment_timeout = 0 - # for this environment, provide our own function to supply data to lookup - # implies a ruby function in /lib/puppet/functions/environment/data.rb - # named environment::data() - environment_data_provider = "function" - ', - mode => "0640", -} - -# the function to provide data for this environment -file { '#{testdir}/environments/production/lib/puppet/functions/environment/data.rb': - ensure => file, - content => " - Puppet::Functions.create_function(:'environment::data') do - def data() - { '#{module_name}::#{env_data_implied_key}' => '#{env_data_implied_value}', - '#{module_name}::#{env_data_override_implied_key}' => '#{env_data_override_implied_value}', - '#{env_data_key}' => '#{env_data_value}', - '#{module_name}::#{hash_name}' => {'#{env_hash_key}' => '#{env_hash_value}'}, - '#{env_data_override_key}' => '#{env_data_override_value}', - '#{module_name}::#{array_key}' => ['#{env_array_value0}', '#{env_array_value1}'] - } - end - end - ", - mode => "0640", -} - -# place module file segments here -#{module_manifest1} -# same key, different module and values -#{module_manifest2} - -file { '#{testdir}/environments/production/modules/#{module_name}/manifests/init.pp': - ensure => file, - content => ' - class #{module_name}($#{env_data_implied_key}, - $#{module_data_implied_key}, - $#{env_data_override_implied_key}, - $#{hiera_data_implied_key}, - $#{automatic_data_key}=$#{automatic_default_value}) { - # lookup data from the environment function databinding - notify { "#{env_data_implied_key} $#{env_data_implied_key}": } - $lookup_env = lookup("#{env_data_key}") - notify { "#{env_data_key} $lookup_env": } - - # lookup data from the module databinding - notify { "#{module_data_implied_key} $#{module_data_implied_key}": } - $lookup_module = lookup("#{module_name}::#{module_data_key}") - notify { "#{module_data_key} $lookup_module": } - - # lookup data from another modules databinding - $lookup_module2 = lookup("#{module_name2}::#{module_data_key}") - notify { "#{module_data_key} $lookup_module2": } - - # ensure env can override module - notify { "#{env_data_override_implied_key} $#{env_data_override_implied_key}": } - $lookup_override = lookup("#{env_data_override_key}") - notify { "#{env_data_override_key} $lookup_override": } - - # should fall-back to hiera global.yaml data - notify { "#{hiera_data_implied_key} $#{hiera_data_implied_key}": } - $lookup_port = lookup("#{hiera_data_key}") - notify { "#{hiera_data_key} $lookup_port": } - - # should be able to merge hashes across sources - # this mimicks/covers behavior for including classes - $lookup_hash = lookup("#{module_name}::#{hash_name}",Hash[String,String],\\'hash\\') - notify { "#{hash_name} $lookup_hash": } - - # should be able to make an array across sources - # this mimicks/covers behavior for including classes - $lookup_array = lookup("#{module_name}::#{array_key}",Array[String],\\'unique\\') - notify { "yep": message => "#{array_key} $lookup_array" } - - # automatic data lookup of parametrized class - notify { "#{automatic_data_key} $#{automatic_data_key}": } - }', - mode => "0640", -} - -file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - content => " - node default { - include #{module_name} - }", - mode => "0640", -} -PP - - apply_manifest_on(master, <<-PP, :catch_failures => true) -#{metadata_manifest1} -#{metadata_manifest2} - PP - - - master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'hiera_config' => "#{testdir}/hiera.yaml", - }, - } - with_puppet_running_on master, master_opts, testdir do - step "Lookup string data, binding specified in metadata.json" do - agents.each do |agent| - on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [0, 2]) do |result| - assert_match("#{env_data_implied_key} #{env_data_implied_value}", result.stdout) - assert_match("#{env_data_key} #{env_data_value}", result.stdout) - - assert_match("#{module_data_implied_key} #{module_data_implied_value}", result.stdout) - assert_match("#{module_data_key} #{module_data_value}", result.stdout) - - assert_match("#{module_data_key} #{module_data_value_other}", result.stdout) - - assert_match("#{env_data_override_implied_key} #{env_data_override_implied_value}", result.stdout) - assert_match("#{env_data_override_key} #{env_data_override_value}", result.stdout) - - assert_match("#{hiera_data_implied_key} #{hiera_data_implied_value}", result.stdout) - assert_match("#{hiera_data_key} #{hiera_data_value}", result.stdout) - - assert_match("#{hash_name} {#{module_hash_key} => #{module_hash_value}, #{env_hash_key} => #{env_hash_value}, #{hiera_hash_key} => #{hiera_hash_value}}", result.stdout) - - assert_match("#{array_key} [#{hiera_array_value0}, #{hiera_array_value1}, #{env_array_value0}, #{env_array_value1}, #{module_array_value0}, #{module_array_value1}]", result.stdout) - - assert_match("#{automatic_data_key} #{automatic_data_value}", result.stdout) - end - end - end - end - -end diff --git a/acceptance/tests/lookup/lookup_rich_values.rb b/acceptance/tests/lookup/lookup_rich_values.rb deleted file mode 100644 index 2b3af46060..0000000000 --- a/acceptance/tests/lookup/lookup_rich_values.rb +++ /dev/null @@ -1,124 +0,0 @@ -test_name 'C99044: lookup should allow rich data as values' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local environment. - 'server' - - # The following two lines are required for the puppetserver service to - # start correctly. These should be removed when PUP-7102 is resolved. - confdir = puppet_config(master, 'confdir', section: 'master') - on(master, "chown puppet:puppet #{confdir}/hiera.yaml") - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - sensitive_value_rb = 'foot, no mouth' - sensitive_value_pp = 'toe, no step' - sensitive_value_pp2 = 'toe, no module' - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create ruby lookup function in #{tmp_environment}" do - on(master, "mkdir -p #{fq_tmp_environmentpath}/lib/puppet/functions/environment") - create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA) ---- -version: 5 -hierarchy: - - name: Test - data_hash: rich_data_test - - name: Test2 - data_hash: some_mod::rich_data_test2 - - name: Test3 - data_hash: rich_data_test3 - HIERA - create_remote_file(master, "#{fq_tmp_environmentpath}/lib/puppet/functions/rich_data_test.rb", <<-FUNC) -Puppet::Functions.create_function(:rich_data_test) do - def rich_data_test(options, context) - rich_type_instance = Puppet::Pops::Types::PSensitiveType::Sensitive.new("#{sensitive_value_rb}") - { - 'environment_key' => rich_type_instance, - } - end -end - FUNC - end - - step "create puppet language lookup function in #{tmp_environment} module" do - on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/functions") - create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/functions/rich_data_test2.pp", <<-FUNC) -function some_mod::rich_data_test2($options, $context) { - { - "environment_key2" => Sensitive('#{sensitive_value_pp}'), - } -} - FUNC - on(master, "chmod -R a+rw #{fq_tmp_environmentpath}") - end - - step "C99571: create puppet language lookup function in #{tmp_environment}" do - on(master, "mkdir -p #{fq_tmp_environmentpath}/functions") - create_remote_file(master, "#{fq_tmp_environmentpath}/functions/rich_data_test3.pp", <<-FUNC) -function rich_data_test3($options, $context) { - { - "environment_key3" => Sensitive('#{sensitive_value_pp2}'), - } -} - FUNC - on(master, "chmod -R a+rw #{fq_tmp_environmentpath}") - end - - step "create site.pp which calls lookup on our keys" do - create_sitepp(master, tmp_environment, <<-SITE) - notify { "${unwrap(lookup('environment_key'))}": } - notify { "${unwrap(lookup('environment_key2'))}": } - notify { "${unwrap(lookup('environment_key3'))}": } - SITE - end - - step 'assert lookups using lookup subcommand' do - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "lookup subcommand using ruby function didn't exit properly: (#{result.exit_code})") - assert_match(sensitive_value_rb, result.stdout, - "lookup subcommand using ruby function didn't find correct key") - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "lookup subcommand using puppet function in module didn't exit properly: (#{result.exit_code})") - assert_match(sensitive_value_pp, result.stdout, - "lookup subcommand using puppet function in module didn't find correct key") - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "lookup subcommand using puppet function didn't exit properly: (#{result.exit_code})") - assert_match(sensitive_value_pp2, result.stdout, - "lookup subcommand using puppet function didn't find correct key") - end - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent lookup in ruby function" do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup using ruby function didn't exit properly: (#{result.exit_code})") - assert_match(sensitive_value_rb, result.stdout, - "agent lookup using ruby function didn't find correct key") - assert_match(sensitive_value_pp, result.stdout, - "agent lookup using puppet function in module didn't find correct key") - assert_match(sensitive_value_pp2, result.stdout, - "agent lookup using puppet function didn't find correct key") - end - end - end - end - -end diff --git a/acceptance/tests/lookup/merge_strategies.rb b/acceptance/tests/lookup/merge_strategies.rb deleted file mode 100644 index 79cfd36ed6..0000000000 --- a/acceptance/tests/lookup/merge_strategies.rb +++ /dev/null @@ -1,226 +0,0 @@ -test_name 'C99903: merge strategies' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local module tree. - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1') - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - tmp_environment2 = mk_tmp_environment_with_teardown(master, app_type + '2') - fq_tmp_environmentpath2 = "#{environmentpath}/#{tmp_environment2}" - - master_confdir = puppet_config(master, 'confdir', section: 'master') - hiera_conf_backup = master.tmpfile(app_type) - - teardown do - step "restore default global hiera.yaml" do - on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1]) - end - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create global hiera.yaml and environment data" do - step "backup global hiera.yaml" do - on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}") - end - - create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA) ---- -:backends: - - yaml -:yaml: - :datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata" -:hierarchy: - - "host" - - "roles" - - "profiles" - - "%{facts.os.name}" - - "%{facts.os.family}" - - "%{facts.kernel}" - - "common" -:merge_behavior: deeper -:deep_merge_options: - :merge_hash_arrays: true -HIERA - on(master, "chown puppet:puppet #{master_confdir}/hiera.yaml") - - on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/") - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/host.yaml", <<-YAML) ---- -profiles: - webserver: - apache: - httpd: - modules: - - mpm_prefork - - php - - ssl -arrayed_hash: - the_hash: - - array1: - key1: val1 - key2: val2 -array: - - foo -YAML - - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/profiles.yaml", <<-YAML) -profiles: - webserver: - apache: - httpd: - modules: - - auth_kerb - - authnz_ldap - - cgid - - php - - status -array: - - bar -YAML - - create_sitepp(master, tmp_environment, <<-SITE) -notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": } -notify { "lookup1: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": } -notify { "lookup1b: ${lookup ({'name' => 'profiles', 'merge' => 'deep'})['webserver']['apache']['httpd']['modules']}": } -notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": } -notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": } -notify { "hiera-array: ${hiera ('array')}": } -notify { "hiera_array: ${hiera_array ('array')}": } -notify { "lookup-array: ${lookup ('array')}": } - SITE - - on(master, "chmod -R 775 #{fq_tmp_environmentpath}") - end - - step "create another environment, hiera5 config and environment data: #{tmp_environment2}" do - create_remote_file(master, "#{fq_tmp_environmentpath2}/hiera.yaml", <<-HIERA) ---- -version: 5 -hierarchy: - - name: "%{environment}/host" - data_hash: yaml_data - path: "hieradata/host.yaml" - - name: "%{environment}/profiles" - data_hash: yaml_data - path: "hieradata/profiles.yaml" -HIERA - - on(master, "mkdir -p #{fq_tmp_environmentpath2}/hieradata/") - create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/host.yaml", <<-YAML) ---- -profiles: - webserver: - apache: - httpd: - modules: - - mpm_prefork - - php - - ssl -arrayed_hash: - the_hash: - - array1: - key1: val1 - key2: val2 -array: - - foo -lookup_options: - 'profiles': - merge: - strategy: deep -YAML - - create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/profiles.yaml", <<-YAML) -profiles: - webserver: - apache: - httpd: - modules: - - auth_kerb - - authnz_ldap - - cgid - - php - - status -array: - - bar -lookup_options: - 'profiles': - merge: - strategy: deep -YAML - - create_sitepp(master, tmp_environment2, <<-SITE) -notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": } -notify { "lookup2: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": } -notify { "lookup2b: ${lookup ({'name' => 'profiles', 'merge' => 'first'})['webserver']['apache']['httpd']['modules']}": } -notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": } -notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": } -notify { "hiera-array: ${hiera ('array')}": } -notify { "hiera_array: ${hiera_array ('array')}": } -notify { "lookup-array: ${lookup ('array')}": } - SITE - - on(master, "chmod -R 775 #{fq_tmp_environmentpath2}") - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent lookups #{agent.hostname}, hiera3" do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - # hiera_hash will honor old global merge strategies, which were a bad idea - assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout, - "1: agent hiera_hash didn't find correct key") - # so, lookup doesn't honor them except on a by-key or by-lookup basis - assert_match(/lookup1: \[mpm_prefork, php, ssl\]/, result.stdout, - "1: agent lookup didn't find correct key") - assert_match(/lookup1b: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout, - "1b: agent lookup didn't find correct key") - assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout, - "agent hiera_hash 1 merge_hash_arrays didn't work properly") - assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout, - "agent lookup 1 deep merge with merge_hash_arrays didn't work properly") - assert_match(/hiera-array: \[foo\]/, result.stdout, - "hiera() lookup of an array with deeper should be merged") - assert_match(/hiera_array: \[foo, bar\]/, result.stdout, - "hiera_array() lookup of an array should be merged") - assert_match(/lookup-array: \[foo\]/, result.stdout, - "lookup() lookup of an array should default to first") - end - end - step "agent lookups #{agent.hostname}, hiera5" do - on(agent, puppet('agent', "-t --environment #{tmp_environment2}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout, - "2: agent hiera_hash didn't find correct key") - assert_match(/lookup2: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout, - "2: agent lookup didn't find correct key") - assert_match(/lookup2b: \[mpm_prefork, php, ssl\]/, result.stdout, - "2b: agent lookup didn't find correct key") - assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout, - "agent hiera_hash 2 merge_hash_arrays didn't work properly") - assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout, - "agent lookup 2 deep merge with merge_hash_arrays didn't work properly") - assert_match(/hiera-array: \[foo\]/, result.stdout, - "hiera() 2 lookup in hiera5 of an array should default to first") - assert_match(/hiera_array: \[foo, bar\]/, result.stdout, - "hiera_array() 2 lookup of an array should be merged") - assert_match(/lookup-array: \[foo\]/, result.stdout, - "lookup() 2 lookup in hiera5 of an array should default to first") - end - end - end - end - -end diff --git a/acceptance/tests/lookup/v3_config_and_data.rb b/acceptance/tests/lookup/v3_config_and_data.rb deleted file mode 100644 index dd713b02d0..0000000000 --- a/acceptance/tests/lookup/v3_config_and_data.rb +++ /dev/null @@ -1,126 +0,0 @@ -test_name 'C99629: hiera v5 can use v3 config and data' do - require 'puppet/acceptance/environment_utils.rb' - extend Puppet::Acceptance::EnvironmentUtils - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local module tree. - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - hiera_conf_backup = master.tmpfile('C99629-hiera-yaml') - - step "create hiera v3 global config and data" do - confdir = puppet_config(master, 'confdir', section: 'master') - - step "backup global hiera.yaml" do - on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1]) - end - - teardown do - step "restore global hiera.yaml" do - on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1]) - end - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create global hiera.yaml and module data" do - create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA) ---- -:backends: - - "yaml" - - "json" - - "hocon" -:hierarchy: - - "somesuch" - - "common" - HIERA - - on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/") - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.yaml", <<-YAML) ---- -environment_key1: "env value1" -environment_key3: "env value3" - YAML - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.json", <<-JSON) -{ - "environment_key1" : "wrong value", - "environment_key2" : "env value2" -} - JSON - step "C99628: add hocon backend and data" do - create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.conf", <<-HOCON) -environment_key4 = "hocon value", - HOCON - end - - create_sitepp(master, tmp_environment, <<-SITE) -notify { "${lookup('environment_key1')}": } -notify { "${lookup('environment_key2')}": } -notify { "${lookup('environment_key3')}": } -notify { "${lookup('environment_key4')}": } - SITE - - on(master, "chmod -R 775 #{fq_tmp_environmentpath}") - on(master, "chmod -R 775 #{confdir}") - end - end - - step 'assert lookups using lookup subcommand' do - step 'assert lookup --explain using lookup subcommand' do - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key1 --explain'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/env value1/, result.stdout, - "1: lookup subcommand didn't find correct key") - assert_match(/hiera configuration version 3/, result.stdout, - "hiera config version not reported properly") - assert_match(/#{fq_tmp_environmentpath}\/hieradata\/somesuch\.yaml/, result.stdout, - "hiera hierarchy abs path not reported properly") - assert_match(/path: "somesuch"/, result.stdout, - "hiera hierarchy path not reported properly") - end - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/env value2/, result.stdout, - "2: lookup subcommand didn't find correct key") - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/env value3/, result.stdout, - "3: lookup subcommand didn't find correct key") - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key4'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "4: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/hocon value/, result.stdout, - "4: lookup subcommand didn't find correct key") - end - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step "agent lookup" do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/env value1/, result.stdout, - "1: agent lookup didn't find correct key") - assert_match(/env value2/, result.stdout, - "2: agent lookup didn't find correct key") - assert_match(/env value3/, result.stdout, - "3: agent lookup didn't find correct key") - assert_match(/hocon value/, result.stdout, - "4: agent lookup didn't find correct key") - end - end - end - end -end diff --git a/acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb b/acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb deleted file mode 100644 index c2082c3f0f..0000000000 --- a/acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb +++ /dev/null @@ -1,132 +0,0 @@ -test_name 'C99572: v4 hieradata with v5 configs' do - require 'puppet/acceptance/puppet_type_test_tools.rb' - extend Puppet::Acceptance::PuppetTypeTestTools - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor', # Master is not needed for this test. Refactor - # to use puppet apply with a local module tree. - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}" - - confdir = puppet_config(master, 'confdir', section: 'master') - hiera_conf_backup = master.tmpfile('C99572-hiera-yaml') - - step "backup global hiera.yaml" do - on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1]) - end - - teardown do - step "restore global hiera.yaml" do - on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1]) - end - - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - step "create global hiera.yaml and data" do - create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA) ---- -version: 5 -hierarchy: - - name: "%{environment}" - data_hash: yaml_data - path: "%{environment}.yaml" - - name: common - data_hash: yaml_data - path: "common.yaml" - HIERA - on(master, "chmod 755 #{confdir}/hiera.yaml") - create_remote_file(master, "#{confdir}/#{tmp_environment}.yaml", <<-YAML) ---- -environment_key: environment_key-global_env_file -global_key: global_key-global_env_file - YAML - create_remote_file(master, "#{confdir}/common.yaml", <<-YAML) ---- -environment_key: environment_key-global_common_file -global_key: global_key-global_common_file - YAML - end - - step "create environment hiera.yaml and data" do - on(master, "mkdir -p #{fq_tmp_environmentpath}/data") - create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA) ---- -version: 5 -hierarchy: - - name: "%{environment}" - data_hash: yaml_data - path: "%{environment}.yaml" - - name: common - data_hash: yaml_data - path: "common.yaml" - - name: hocon - data_hash: hocon_data - path: "common.conf" - HIERA - create_remote_file(master, "#{fq_tmp_environmentpath}/data/#{tmp_environment}.yaml", <<-YAML) ---- -environment_key: "environment_key-env_file" - YAML - create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.yaml", <<-YAML) ---- -environment_key: "environment_key-common_file" -global_key: "global_key-common_file" - YAML - step "C99628: add hocon backend and data" do - create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.conf", <<-HOCON) -environment_key2 = "hocon value", - HOCON - end - - create_sitepp(master, tmp_environment, <<-SITE) - notify { "${lookup('environment_key')}": } - notify { "${lookup('global_key')}": } - notify { "${lookup('environment_key2')}": } - SITE - on(master, "chmod -R 755 #{fq_tmp_environmentpath}") - end - - step 'assert lookups using lookup subcommand' do - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/environment_key-env_file/, result.stdout, - 'lookup environment_key subcommand didn\'t find correct key') - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'global_key'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/global_key-common_file/, result.stdout, - 'lookup global_key subcommand didn\'t find correct key') - end - on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})") - assert_match(/hocon value/, result.stdout, - 'lookup environment_key2 subcommand didn\'t find correct key') - end - end - - with_puppet_running_on(master,{}) do - agents.each do |agent| - step 'agent lookup' do - on(agent, puppet('agent', "-t --environment #{tmp_environment}"), - :accept_all_exit_codes => true) do |result| - assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})") - assert_match(/global_key-common_file/m, result.stdout, - 'agent lookup didn\'t find global key') - assert_match(/environment_key-env_file/m, result.stdout, - 'agent lookup didn\'t find environment_key') - assert_match(/hocon value/m, result.stdout, - 'agent lookup didn\'t find environment_key2') - end - end - end - end - -end diff --git a/acceptance/tests/modulepath.rb b/acceptance/tests/modulepath.rb deleted file mode 100644 index a119f547fa..0000000000 --- a/acceptance/tests/modulepath.rb +++ /dev/null @@ -1,130 +0,0 @@ -test_name 'Supports vendored modules' do - tag 'risk:high' - - # beacon custom type emits a message so we can tell where the - # type was loaded from, e.g. vendored, global, and whether the - # type was loaded locally or pluginsynced from the master. - def beacon_type(message) - return < true) - newproperty(:message) do - def sync; true; end - def retrieve; :absent; end - def insync?(is); false; end - defaultto { "#{message}" } - end - end -END - end - - def global_modules(host) - if host.platform =~ /windows/ - '/cygdrive/c/ProgramData/PuppetLabs/code/modules' - else - '/etc/puppetlabs/code/modules' - end - end - - def vendor_modules(host) - if host.platform =~ /windows/ - # escape spaces - "/cygdrive/c/Program\\ Files/Puppet\\ Labs/Puppet/puppet/vendor_modules" - else - '/opt/puppetlabs/puppet/vendor_modules' - end - end - - teardown do - hosts.each do |host| - on(host, "rm -rf #{vendor_modules(host)}/beacon") - on(host, "rm -rf #{global_modules(host)}/beacon") - - libdir = host.puppet['vardir'] - on(host, "rm -rf #{libdir}") - end - - on(master, "rm -rf /etc/puppetlabs/code/environments/production/modules/beacon") - on(master, "rm -f /etc/puppetlabs/code/environments/production/manifests/site.pp") - end - - step 'delete libdir' do - hosts.each do |host| - on(host, "rm -rf #{host.puppet['libdir']}") - end - end - - step 'create vendored module with a custom type' do - hosts.each do |host| - vendor_dir = vendor_modules(host) - on(host, "mkdir -p #{vendor_dir}/beacon/lib/puppet/type") - - # unescape, because net-scp escapes - vendor_dir.gsub!(/\\/, '') - create_remote_file(host, "#{vendor_dir}/beacon/lib/puppet/type/beacon.rb", beacon_type("vendored module from #{host}")) - end - end - - step 'vendored modules work locally' do - hosts.each do |host| - on(host, puppet("apply -e \"beacon { 'ping': }\"")) do |result| - assert_match(/defined 'message' as 'vendored module from #{host}'/, result.stdout) - end - end - end - - step 'vendored modules can be excluded' do - hosts.each do |host| - on(host, puppet("describe --vendormoduledir '' beacon"), accept_all_exit_codes: true) do |result| - assert_match(/Unknown type beacon/, result.stdout) - end - end - end - - step 'global modules override vendored modules' do - agents.each do |agent| - # skip the agent on the master, as we don't want to install the - # global module on the master until later - next if agent == master - - global_dir = global_modules(agent) - on(agent, "mkdir -p #{global_dir}/beacon/lib/puppet/type") - - # global_dir doesn't have spaces, so don't need to escape - create_remote_file(agent, "#{global_dir}/beacon/lib/puppet/type/beacon.rb", beacon_type("global module from #{agent}")) - - on(agent, puppet("apply -e \"beacon { 'ping': }\"")) do |result| - assert_match(/defined 'message' as 'global module from #{agent}'/, result.stdout) - end - end - end - - step "prepare server" do - create_remote_file(master, "/etc/puppetlabs/code/environments/production/manifests/site.pp", "beacon { 'ping': }") - on(master, "chown -R puppet:puppet /etc/puppetlabs/code/environments/production/manifests/site.pp") - on(master, "chown -R puppet:puppet #{vendor_modules(master)}") - end - - with_puppet_running_on(master, {}) do - step "agent doesn't pluginsync the vendored module, instead using its local vendored module" do - agents.each do |agent| - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0,2]) do |result| - assert_match(/defined 'message' as 'vendored module from #{agent}'/, result.stdout) - end - end - end - - step "agent downloads and uses newly installed global module from the server" do - global_dir = global_modules(master) - on(master, "mkdir -p #{global_dir}/beacon/lib/puppet/type") - create_remote_file(master, "#{global_dir}/beacon/lib/puppet/type/beacon.rb", beacon_type("server module from #{master}")) - on(master, "chown -R puppet:puppet #{global_dir}") - - agents.each do |agent| - on(agent, puppet("agent -t"), :acceptable_exit_codes => [0,2]) do |result| - assert_match(/defined 'message' as 'server module from #{master}'/, result.stdout) - end - end - end - end -end diff --git a/acceptance/tests/ordering/master_agent_application.rb b/acceptance/tests/ordering/master_agent_application.rb deleted file mode 100644 index 5ebc2ea0d8..0000000000 --- a/acceptance/tests/ordering/master_agent_application.rb +++ /dev/null @@ -1,51 +0,0 @@ -test_name "Puppet applies resources without dependencies in file order over the network" - -tag 'audit:high', - 'audit:integration', - 'server' - -testdir = master.tmpdir('application_order') - -apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - } - file { - '#{testdir}':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - mode => "0640", - content => ' -notify { "first": } -notify { "second": } -notify { "third": } -notify { "fourth": } -notify { "fifth": } -notify { "sixth": } -notify { "seventh": } -notify { "eighth": } - '; - } -MANIFEST - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - } -} - -with_puppet_running_on(master, master_opts) do - agents.each do |agent| - on(agent, puppet('agent', "--no-daemonize --onetime --verbose")) do |result| - if result.stdout !~ /Notice: first.*Notice: second.*Notice: third.*Notice: fourth.*Notice: fifth.*Notice: sixth.*Notice: seventh.*Notice: eighth/m - fail_test "Output did not include the notify resources in the correct order" - end - end - end -end diff --git a/acceptance/tests/parser_functions/calling_all_functions.rb b/acceptance/tests/parser_functions/calling_all_functions.rb deleted file mode 100644 index f03ac4101a..0000000000 --- a/acceptance/tests/parser_functions/calling_all_functions.rb +++ /dev/null @@ -1,235 +0,0 @@ -test_name 'Calling all functions.. test in progress!' - -tag 'audit:high', - 'audit:acceptance' - -# create single manifest calling all functions -step 'Apply manifest containing all function calls' -def manifest_call_each_function_from_array(functions) - manifest = '' - # use index to work around puppet's immutable variables - # use variables so we can concatenate strings - functions.each_with_index do |function,index| - if function[:rvalue] - manifest << "$pre#{index} = \"sayeth #{function[:name].capitalize}: Scope(Class[main]): \" " - manifest << "$output#{index} = #{function[:name]}(#{function[:args]}) " - manifest << "#{function[:lambda]} notice \"${pre#{index}}${output#{index}}\"\n" - else - manifest << "$pre#{index} = \"sayeth #{function[:name].capitalize}: \" " - manifest << "notice \"${pre#{index}}\"\n" - manifest << "#{function[:name]}(#{function[:args]}) " - manifest << "#{function[:lambda]}\n" - end - end - manifest -end - - -agents.each do |agent| - testdir = agent.tmpdir('calling_all_functions') - # if agent["platform"] =~ /win/ - # generator = {:args => '"c:/windows/system32/tasklist.exe"', :expected => /\nImage Name/} - # else - # generator = {:args => '"/bin/date"', :expected => /\w\w\w.*?\d\d:\d\d\:\d\d/} - # end - - # create list of 3x functions and args - # notes: hiera functions are well tested elsewhere, included for completeness - # special cases: contain (call this from call_em_all) - # do fail last because it errors out - - functions_3x = [ - {:name => :alert, :args => '"consider yourself on alert"', :lambda => nil, :expected => 'consider yourself on alert', :rvalue => false}, - {:name => :binary_file, :args => '"call_em_all/rickon.txt"', :lambda => nil, :expected => '', :rvalue => true}, - #{:name => :break, :args => '', :lambda => nil, :expected => '', :rvalue => false}, - # this is explicitly called from call_em_all module which is included below - #{:name => :contain, :args => 'call_em_all', :lambda => nil, :expected => '', :rvalue => true}, - # below doens't instance the resource. no output - {:name => :create_resources, :args => 'notify, {"w"=>{message=>"winter is coming"}}', :lambda => nil, :expected => '', :rvalue => false}, - {:name => :crit, :args => '"consider yourself critical"', :lambda => nil, :expected => 'consider yourself critical', :rvalue => false}, - {:name => :debug, :args => '"consider yourself bugged"', :lambda => nil, :expected => '', :rvalue => false}, # no output expected unless run with debug - {:name => :defined, :args => 'File["/tmp"]', :lambda => nil, :expected => 'false', :rvalue => true}, - {:name => :dig, :args => '[100]', :lambda => nil, :expected => '[100]', :rvalue => true}, - # Expect sha256 hash value for the digest - {:name => :digest, :args => '"Sansa"', :lambda => nil, :expected => '4ebf3a5527313f06c7965749d7764c15cba6fe86da11691ca9bd0ce448563979', :rvalue => true}, - {:name => :emerg, :args => '"consider yourself emergent"', :lambda => nil, :expected => 'consider yourself emergent', :rvalue => false}, - {:name => :err, :args => '"consider yourself in err"', :lambda => nil, :expected => 'consider yourself in err', :rvalue => false}, - {:name => :file, :args => '"call_em_all/rickon.txt"', :lambda => nil, :expected => 'who?', :rvalue => true}, - {:name => :fqdn_rand, :args => '100000', :lambda => nil, :expected => /Fqdn_rand: Scope\(Class\[main\]\): \d{1,5}/, :rvalue => true}, - # generate requires a fully qualified exe; which requires specifics for windows vs posix - #{:name => :generate, :args => generator[:args], :lambda => nil, :expected => generator[:expected], :rvalue => true}, - {:name => :hiera_array, :args => 'date,default_array', :lambda => nil, :expected => 'default_array', :rvalue => true}, - {:name => :hiera_hash, :args => 'date,default_hash', :lambda => nil, :expected => 'default_hash', :rvalue => true}, - {:name => :hiera_include, :args => 'date,call_em_all', :lambda => nil, :expected => '', :rvalue => false}, - {:name => :hiera, :args => 'date,default_date', :lambda => nil, :expected => 'default_date', :rvalue => true}, - {:name => :include, :args => 'call_em_all', :lambda => nil, :expected => '', :rvalue => false}, - {:name => :info, :args => '"consider yourself informed"', :lambda => nil, :expected => '', :rvalue => false}, # no ouput unless in debug mode - {:name => :inline_template, :args => '\'empty<%= @x %>space\'', :lambda => nil, :expected => 'emptyspace', :rvalue => true}, - # test the living life out of this thing in lookup.rb, and it doesn't allow for a default value - #{:name => :lookup, :args => 'date,lookup_date', :lambda => nil, :expected => '', :rvalue => true}, # well tested elsewhere - {:name => :sha256, :args => '"Bran"', :lambda => nil, :expected => '824264f7f73d6026550b52a671c50ad0c4452af66c24f3784e30f515353f2ce0', :rvalue => true}, - # Integer.new - {:name => :Integer, :args => '"100"', :lambda => nil, :expected => '100', :rvalue => true}, - {:name => :notice, :args => '"consider yourself under notice"', :lambda => nil, :expected => 'consider yourself under notice', :rvalue => false}, - {:name => :realize, :args => 'User[arya]', :lambda => nil, :expected => '', :rvalue => false}, # TODO: create a virtual first - {:name => :regsubst, :args => '"Cersei","Cer(\\\\w)ei","Daenery\\\\1"',:lambda => nil, :expected => 'Daenerys', :rvalue => true}, - # explicitly called in call_em_all; implicitly called by the include above - #{:name => :require, :args => '[4,5,6]', :lambda => nil, :expected => '', :rvalue => true}, - # 4x output contains brackets around scanf output - {:name => :scanf, :args => '"Eddard Stark","%6s"', :lambda => nil, :expected => '[Eddard]', :rvalue => true}, - {:name => :sha1, :args => '"Sansa"', :lambda => nil, :expected => '4337ce5e4095e565d51e0ef4c80df1fecf238b29', :rvalue => true}, - {:name => :shellquote, :args => '["-1", "--two"]', :lambda => nil, :expected => '-1 --two', :rvalue => true}, - # 4x output contains brackets around split output and commas btwn values - {:name => :split, :args => '"9,8,7",","', :lambda => nil, :expected => '[9, 8, 7]', :rvalue => true}, - {:name => :sprintf, :args => '"%b","123"', :lambda => nil, :expected => '1111011', :rvalue => true}, - {:name => :step, :args => '[100,99],1', :lambda => nil, :expected => 'Iterator[Integer]-Value', :rvalue => true}, - # explicitly called in call_em_all - #{:name => :tag, :args => '[4,5,6]', :lambda => nil, :expected => '', :rvalue => true}, - {:name => :tagged, :args => '"yer_it"', :lambda => nil, :expected => 'false', :rvalue => true}, - {:name => :template, :args => '"call_em_all/template.erb"', :lambda => nil, :expected => 'no defaultsno space', :rvalue => true}, - {:name => :type, :args => '42', :lambda => nil, :expected => 'Integer[42, 42]', :rvalue => true}, - {:name => :versioncmp, :args => '"1","2"', :lambda => nil, :expected => '-1', :rvalue => true}, - {:name => :warning, :args => '"consider yourself warned"', :lambda => nil, :expected => 'consider yourself warned', :rvalue => false}, - # do this one last or it will not allow the others to run. - {:name => :fail, :args => '"Jon Snow"', :lambda => nil, :expected => /Error:.*Jon Snow/, :rvalue => false}, - ] - - puppet_version = on(agent, puppet('--version')).stdout.chomp - - functions_4x = [ - {:name => :assert_type, :args => '"String[1]", "Valar morghulis"', :lambda => nil, :expected => 'Valar morghulis', :rvalue => true}, - {:name => :each, :args => '[1,2,3]', :lambda => '|$x| {$x}', :expected => '[1, 2, 3]', :rvalue => true}, - {:name => :epp, :args => '"call_em_all/template.epp",{x=>droid}', :lambda => nil, :expected => 'This is the droid you are looking for!', :rvalue => true}, - {:name => :filter, :args => '[4,5,6]', :lambda => '|$x| {true}', :expected => '[4, 5, 6]', :rvalue => true}, - # find_file() called by binary_file - #{:name => :find_file, :args => '[4,5,6]', :lambda => '|$x| {true}', :expected => '[4, 5, 6]', :rvalue => true}, - {:name => :inline_epp, :args => '\'<%= $x %>\',{x=>10}', :lambda => nil, :expected => '10', :rvalue => true}, - #{:name => :lest, :args => '100', :lambda => '"100"', :expected => '100', :rvalue => true}, - {:name => :map, :args => '[7,8,9]', :lambda => '|$x| {$x * $x}', :expected => '[49, 64, 81]', :rvalue => true}, - {:name => :match, :args => '"abc", /b/', :lambda => nil, :expected => '[b]', :rvalue => true}, - #{:name => :next, :args => '100', :lambda => nil, :expected => '100', :rvalue => true}, - {:name => :reduce, :args => '[4,5,6]', :lambda => '|$sum, $n| { $sum+$n }', :expected => '15', :rvalue => true}, - #{:name => :return, :args => '100', :lambda => nil, :expected => '100', :rvalue => true}, - {:name => :reverse_each, :args => '[100,99]', :lambda => nil, :expected => 'Iterator[Integer]-Value', :rvalue => true}, - # :reuse,:recycle - {:name => :slice, :args => '[1,2,3,4,5,6], 2', :lambda => nil, :expected => '[[1, 2], [3, 4], [5, 6]]', :rvalue => true}, - {:name => :strftime, :args => 'Timestamp("4216-09-23T13:14:15.123 UTC"), "%C"', :lambda => nil, :expected => '42', :rvalue => true}, - {:name => :then, :args => '100', :lambda => '|$x| {$x}', :expected => '100', :rvalue => true}, - {:name => :with, :args => '1, "Catelyn"', :lambda => '|$x, $y| {"$x, $y"}', :expected => '1, Catelyn', :rvalue => true}, - ] - - module_manifest = < directory, -} -file { - '#{testdir}':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/modules':; - '#{testdir}/environments/production/modules/tagged':; - '#{testdir}/environments/production/modules/tagged/manifests':; - '#{testdir}/environments/production/modules/contained':; - '#{testdir}/environments/production/modules/contained/manifests':; - '#{testdir}/environments/production/modules/required':; - '#{testdir}/environments/production/modules/required/manifests':; - '#{testdir}/environments/production/modules/call_em_all':; - '#{testdir}/environments/production/modules/call_em_all/manifests':; - '#{testdir}/environments/production/modules/call_em_all/templates':; - '#{testdir}/environments/production/modules/call_em_all/files':; -} -file { '#{testdir}/environments/production/modules/tagged/manifests/init.pp': - ensure => file, - content => 'class tagged { - notice tagged - tag yer_it - }', -} -file { '#{testdir}/environments/production/modules/required/manifests/init.pp': - ensure => file, - content => 'class required { - notice required - }', -} -file { '#{testdir}/environments/production/modules/contained/manifests/init.pp': - ensure => file, - content => 'class contained { - notice contained - }', -} -file { '#{testdir}/environments/production/modules/call_em_all/manifests/init.pp': - ensure => file, - content => 'class call_em_all { - notice call_em_all - contain contained - require required - tag yer_it - }', -} -file { '#{testdir}/environments/production/modules/call_em_all/files/rickon.txt': - ensure => file, - content => 'who?', -} -file { '#{testdir}/environments/production/modules/call_em_all/templates/template.epp': - ensure => file, - content => 'This is the <%= $x %> you are looking for!', -} -file { '#{testdir}/environments/production/modules/call_em_all/templates/template.erb': - ensure => file, - content => 'no defaults<%= @x %>no space', -} -PP - - apply_manifest_on(agent, module_manifest, :catch_failures => true) - - scope = 'Scope(Class[main]):' - # apply the 4x function manifest with future parser - puppet_apply_options = {:modulepath => "#{testdir}/environments/production/modules/", - :acceptable_exit_codes => 1} - puppet_apply_options[:future_parser] = true if puppet_version =~ /\A3\./ - apply_manifest_on(agent, manifest_call_each_function_from_array(functions_4x), puppet_apply_options) do |result| - functions_4x.each do |function| - expected = "#{function[:name].capitalize}: #{scope} #{function[:expected]}" - unless agent['locale'] == 'ja' - assert_match(expected, result.output, - "#{function[:name]} output didn't match expected value") - end - end - end - - file_path = agent.tmpfile('apply_manifest.pp') - - create_remote_file(agent, file_path, manifest_call_each_function_from_array(functions_3x)) - - trusted_3x = puppet_version =~ /\A3\./ ? '--trusted_node_data ' : '' - on(agent, puppet("apply #{trusted_3x} --color=false --modulepath #{testdir}/environments/production/modules/ #{file_path}"), - :acceptable_exit_codes => 1 ) do |result| - functions_3x.each do |function| - # append the function name to the matcher so it's more expressive - if function[:expected].is_a?(String) - if function[:name] == :fail - expected = function[:expected] - elsif function[:name] == :crit - expected = "#{function[:name].capitalize}ical: #{scope} #{function[:expected]}" - elsif function[:name] == :emerg - expected = "#{function[:name].capitalize}ency: #{scope} #{function[:expected]}" - elsif function[:name] == :err - expected = "#{function[:name].capitalize}or: #{scope} #{function[:expected]}" - elsif function[:expected] == '' - expected = "#{function[:name].capitalize}: #{function[:expected]}" - else - expected = "#{function[:name].capitalize}: #{scope} #{function[:expected]}" - end - elsif function[:expected].is_a?(Regexp) - expected = function[:expected] - else - raise 'unhandled function expectation type (we allow String or Regexp)' - end - - unless agent['locale'] == 'ja' - assert_match(expected, result.output, "#{function[:name]} output didn't match expected value") - end - end - end - -end diff --git a/acceptance/tests/parser_functions/hiera/lookup_data.rb b/acceptance/tests/parser_functions/hiera/lookup_data.rb deleted file mode 100644 index 3e0b67f1d9..0000000000 --- a/acceptance/tests/parser_functions/hiera/lookup_data.rb +++ /dev/null @@ -1,95 +0,0 @@ -test_name "Lookup data using the hiera parser function" - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # Master is not required for this test. Replace with agents.each - -testdir = master.tmpdir('hiera') - -step 'Setup' - -apply_manifest_on(master, <<-PP, :catch_failures => true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{testdir}':; - '#{testdir}/hieradata':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/production/modules':; -} - -file { '#{testdir}/hiera.yaml': - ensure => file, - content => '--- - :backends: - - "yaml" - :logger: "console" - :hierarchy: - - "%{environment}" - - "global" - - :yaml: - :datadir: "#{testdir}/hieradata" - ', - mode => "0640", -} - -file { '#{testdir}/hieradata/global.yaml': - ensure => file, - content => "--- - port: 8080 - ", - mode => "0640", -} - -file { - '#{testdir}/environments/production/modules/apache':; - '#{testdir}/environments/production/modules/apache/manifests':; -} - -file { '#{testdir}/environments/production/modules/apache/manifests/init.pp': - ensure => file, - content => ' - class apache { - $port = hiera("port") - - notify { "port from hiera": - message => "apache server port: ${port}" - } - }', - mode => "0640", -} - -file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - content => " - node default { - include apache - }", - mode => "0640", -} -PP - -step "Try to lookup string data" - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'hiera_config' => "#{testdir}/hiera.yaml", - }, -} - -with_puppet_running_on master, master_opts, testdir do - agents.each do |agent| - on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result| - assert_match('apache server port: 8080', result.stdout) - end - end -end diff --git a/acceptance/tests/parser_functions/hiera_array/lookup_data.rb b/acceptance/tests/parser_functions/hiera_array/lookup_data.rb deleted file mode 100644 index 3bfbcfa635..0000000000 --- a/acceptance/tests/parser_functions/hiera_array/lookup_data.rb +++ /dev/null @@ -1,108 +0,0 @@ -test_name "Lookup data using the hiera_array parser function" - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # Master is not required for this test. Replace with agents.each - -testdir = master.tmpdir('hiera') - -step 'Setup' - -apply_manifest_on(master, <<-PP, :catch_failures => true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{testdir}':; - '#{testdir}/hieradata':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/production/modules':; -} - -file { '#{testdir}/hiera.yaml': - ensure => file, - content => '--- - :backends: - - "yaml" - :logger: "console" - :hierarchy: - - "%{environment}" - - "global" - - :yaml: - :datadir: "#{testdir}/hieradata" - ', - mode => "0640"; -} - -file { '#{testdir}/hieradata/global.yaml': - ensure => file, - content => "--- - port: '8080' - ntpservers: ['global.ntp.puppetlabs.com'] - ", - mode => "0640"; -} - -file { '#{testdir}/hieradata/production.yaml': - ensure => file, - content => "--- - ntpservers: ['production.ntp.puppetlabs.com'] - ", - mode => "0640"; -} - -file { - '#{testdir}/environments/production/modules/ntp':; - '#{testdir}/environments/production/modules/ntp/manifests':; -} - -file { '#{testdir}/environments/production/modules/ntp/manifests/init.pp': - ensure => file, - content => ' - class ntp { - $ntpservers = hiera_array("ntpservers") - - define print { - $server = $name - notify { "ntpserver ${server}": } - } - - ntp::print { $ntpservers: } - }', - mode => "0640"; -} - -file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - content => " - node default { - include ntp - }", - mode => "0640"; -} -PP - -step "Try to lookup array data" - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'hiera_config' => "#{testdir}/hiera.yaml", - }, -} - -with_puppet_running_on master, master_opts, testdir do - agents.each do |agent| - on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result| - assert_match('ntpserver global.ntp.puppetlabs.com', result.stdout) - assert_match('ntpserver production.ntp.puppetlabs.com', result.stdout) - end - end -end diff --git a/acceptance/tests/parser_functions/hiera_hash/lookup_data.rb b/acceptance/tests/parser_functions/hiera_hash/lookup_data.rb deleted file mode 100644 index 3532fdb454..0000000000 --- a/acceptance/tests/parser_functions/hiera_hash/lookup_data.rb +++ /dev/null @@ -1,105 +0,0 @@ -test_name "Lookup data using the hiera_hash parser function" - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # Master is not required for this test. Replace with agents.each - -testdir = master.tmpdir('hiera') - -step 'Setup' - -apply_manifest_on(master, <<-PP, :catch_failures => true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} -file { - '#{testdir}':; - '#{testdir}/hieradata':; - '#{testdir}/environments':; - '#{testdir}/environments/production':; - '#{testdir}/environments/production/manifests':; - '#{testdir}/environments/production/modules':; -} - -file { '#{testdir}/hiera.yaml': - ensure => file, - content => '--- - :backends: - - "yaml" - :logger: "console" - :hierarchy: - - "%{environment}" - - "global" - - :yaml: - :datadir: "#{testdir}/hieradata" - ', - mode => "0640"; -} - -file { '#{testdir}/hieradata/global.yaml': - ensure => file, - content => "--- - database_user: - name: postgres - uid: 500 - gid: 500 - ", - mode => "0640"; -} - -file { '#{testdir}/hieradata/production.yaml': - ensure => file, - content => "--- - database_user: - shell: '/bin/bash' - ", - mode => "0640"; -} - -file { - '#{testdir}/environments/production/modules/ntp/':; - '#{testdir}/environments/production/modules/ntp/manifests':; -} - -file { '#{testdir}/environments/production/modules/ntp/manifests/init.pp': - ensure => file, - content => 'class ntp { - $database_user = hiera_hash("database_user") - - notify { "the database user": - message => "name: ${database_user["name"]} shell: ${database_user["shell"]}" - } - }', - mode => "0640"; -} - -file { '#{testdir}/environments/production/manifests/site.pp': - ensure => file, - content => " - node default { - include ntp - }", - mode => "0640"; -} -PP - -step "Try to lookup hash data" - -master_opts = { - 'main' => { - 'environmentpath' => "#{testdir}/environments", - 'hiera_config' => "#{testdir}/hiera.yaml", - }, -} - -with_puppet_running_on master, master_opts, testdir do - agents.each do |agent| - on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result| - assert_match("name: postgres shell: /bin/bash", result.stdout) - end - end -end diff --git a/acceptance/tests/parser_functions/hiera_in_templates.rb b/acceptance/tests/parser_functions/hiera_in_templates.rb deleted file mode 100644 index 49924b5e43..0000000000 --- a/acceptance/tests/parser_functions/hiera_in_templates.rb +++ /dev/null @@ -1,475 +0,0 @@ -test_name "Calling Hiera function from inside templates" - -tag 'audit:high', - 'audit:integration', - 'audit:refactor' # Master is not required for this test. Replace with agents.each - -@module_name = "hieratest" -@coderoot = master.tmpdir("#{@module_name}") - -@msg_default = 'message from default.yaml' -@msg_production = 'message from production.yaml' -@msg1os = 'message1 from {osfamily}.yaml' -@msg2os = 'message2 from {osfamily}.yaml' -@msg_fqdn = 'messsage from {fqdn}.yaml' - -@k1 = 'key1' -@k2 = 'key2' -@k3 = 'key3' - -@hval2p = 'hash_value2 from production.yaml' -@hval3p = 'hash_value3 from production.yaml' -@hval1os = 'hash_value1 from {osfamily}.yaml' -@hval2os = 'hash_value2 from {osfamily}.yaml' - -@h_m_call = "hiera\\('message'\\)" -@h_h_call = "hiera\\('hash_value'\\)" -@h_i_call = "hiera\\('includes'\\)" -@ha_m_call = "hiera_array\\('message'\\)" -@ha_i_call = "hiera_array\\('includes'\\)" -@hh_h_call = "hiera_hash\\('hash_value'\\)" - -@mod_default_msg = 'This file created by mod_default.' -@mod_osfamily_msg = 'This file created by mod_osfamily.' -@mod_production_msg = 'This file created by mod_production.' -@mod_fqdn_msg = 'This file created by mod_fqdn.' - -@master_opts = { - 'main' => { - 'environmentpath' => "#{@coderoot}/environments", - 'hiera_config' => "#{@coderoot}/hiera.yaml", - }, -} - - -def create_environment(osfamilies, tmp_dirs) - envroot = "#{@coderoot}/environments" - production = "#{envroot}/production" - modroot = "#{production}/modules" - moduledir = "#{modroot}/#{@module_name}" - hieradir = "#{@coderoot}/hieradata" - - osfamily_yamls = "" - osfamilies.each do |osf| - new_yaml = < " ---- -message: [ - '#{@msg1os}', - '#{@msg2os}', -] -includes: '#{@module_name}::mod_osfamily' -hash_value: - #{@k1}: '#{@hval1os}' - #{@k2}: '#{@hval2os}' -" -} -NEW_YAML - osfamily_yamls += new_yaml - end - environ = < file, - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, - mode => "0644", -} - -file { - [ - "#{@coderoot}", - "#{envroot}", - "#{production}", - "#{production}/modules", - "#{production}/manifests", - "#{hieradir}", - "#{moduledir}", - "#{moduledir}/examples", - "#{moduledir}/manifests", - "#{moduledir}/templates", - ] : - ensure => directory, -} - -file { '#{production}/manifests/site.pp': - ensure => file, - content => " -node default { - \\$msgs = hiera_array('message') - notify {\\$msgs:} - class {'#{@module_name}': - result_dir => hiera('result_dir')[\\$facts['networking']['hostname']], - } -} -", -} - - -file {"#{@coderoot}/hiera.yaml": - content => " ---- -:backends: - - yaml - -:yaml: - :datadir: #{@coderoot}/hieradata - -:hierarchy: - - \\"%{clientcert}\\" - - \\"%{environment}\\" - - \\"%{os.family}\\" - - \\"default\\" -" -} - -file {"#{hieradir}/default.yaml": - content => " ---- -message: '#{@msg_default}' -includes: '#{@module_name}::mod_default' -result_dir: -#{tmp_dirs} -" -} - -#{osfamily_yamls} - - -file {"#{hieradir}/production.yaml": - content => " ---- -message: '#{@msg_production}' -includes: '#{@module_name}::mod_production' -hash_value: - #{@k2}: '#{@hval2p}' - #{@k3}: '#{@hval3p}' -" -} - -file {"#{hieradir}/#{$fqdn}.yaml": - content => " ---- -message: '#{@msg_fqdn}' -includes: '#{@module_name}::mod_fqdn' -" -} - -file {"#{moduledir}/examples/init.pp": - content => " -include #{@module_name} -" -} - -file { "#{moduledir}/manifests/init.pp": - content => " -class #{@module_name} ( - \\$result_dir, -) { - file { \\$result_dir: - ensure => directory, - mode => '0755', - } - file {\\\"\\\${result_dir}/#{@module_name}_results_epp\\\": - ensure => file, - mode => '0644', - content => epp('#{@module_name}/hieratest_results_epp.epp'), - } - file {\\\"\\\${result_dir}/#{@module_name}_results_erb\\\": - ensure => file, - mode => '0644', - content => template('#{@module_name}/hieratest_results_erb.erb'), - } -} -" -} - -file { "#{moduledir}/manifests/mod_default.pp": - content => " -class #{@module_name}::mod_default { - \\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']] - notify{\\"module mod_default invoked.\\\\n\\":} - file {\\\"\\\${result_dir}/mod_default\\\": - ensure => 'file', - mode => '0644', - content => \\\"#{@mod_default_msg}\\\\n\\\", - } -} -" -} - -file { "#{moduledir}/manifests/mod_osfamily.pp": - content => " -class #{@module_name}::mod_osfamily { - \\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']] - notify{\\"module mod_osfamily invoked.\\\\n\\":} - file {\\\"\\\${result_dir}/mod_osfamily\\\": - ensure => 'file', - mode => '0644', - content => \\\"#{@mod_osfamily_msg}\\\\n\\\", - } -} -" -} - -file { "#{moduledir}/manifests/mod_production.pp": - content => " -class #{@module_name}::mod_production { - \\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']] - notify{\\"module mod_production invoked.\\\\n\\":} - file {\\\"\\\${result_dir}/mod_production\\\": - ensure => 'file', - mode => '0644', - content => '#{@mod_production_msg}', - } -} -" -} - -file { "#{moduledir}/manifests/mod_fqdn.pp": - content => " -class #{@module_name}::mod_fqdn { - \\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']] - notify{\\"module mod_fqdn invoked.\\\\n\\":} - file {\\\"\\\${result_dir}/mod_fqdn\\\": - ensure => 'file', - mode => '0644', - content => \\\"#{@mod_fqdn_msg}\\\\n\\\", - } -} -" -} - -file { "#{moduledir}/templates/hieratest_results_epp.epp": - content => " -hiera('message'): <%= hiera('message') %> -hiera('hash_value'): <%= hiera('hash_value') %> -hiera('includes'): <%= hiera('includes') %> -hiera_array('message'): <%= hiera_array('message') %> -hiera_array('includes'): <%= hiera_array('includes') %> -hiera_hash('hash_value'): <%= hiera_hash('hash_value') %> -hiera_include('includes'): <%= hiera_include('includes') %> -" -} - -file { "#{moduledir}/templates/hieratest_results_erb.erb": - content => " -hiera('message'): <%= scope().call_function('hiera', ['message']) %> -hiera('hash_value'): <%= scope().call_function('hiera', ['hash_value']) %> -hiera('includes'): <%= scope().call_function('hiera', ['includes']) %> -hiera_array('message'): <%= scope().call_function('hiera_array', ['message']) %> -hiera_array('includes'): <%= scope().call_function('hiera_array', ['includes']) %> -hiera_hash('hash_value'): <%= scope().call_function('hiera_hash', ['hash_value']) %> -" -} - -ENV - environ -end - -def find_osfamilies - family_hash = {} - agents.each do |agent| - res = on(agent, facter("os.family")) - osf = res.stdout.chomp - family_hash[osf] = 1 - end - family_hash.keys -end - -def find_tmp_dirs - tmp_dirs = "" - host_to_result_dir = {} - agents.each do |agent| - h = on(agent, facter("networking.hostname")).stdout.chomp - t = agent.tmpdir("#{@module_name}_results") - tmp_dirs += " #{h}: '#{t}'\n" - host_to_result_dir[h] = t - end - result = { - 'tmp_dirs' => tmp_dirs, - 'host_to_result_dir' => host_to_result_dir - } - result -end - - -step 'Setup' - -with_puppet_running_on master, @master_opts, @coderoot do - res = find_tmp_dirs - tmp_dirs = res['tmp_dirs'] - host_to_result_dir = res['host_to_result_dir'] - env_manifest = create_environment(find_osfamilies, tmp_dirs) - apply_manifest_on(master, env_manifest, :catch_failures => true) - agents.each do |agent| - resultdir = host_to_result_dir[on(agent, facter("networking.hostname")).stdout.chomp] - step "Applying catalog to agent: #{agent}. result files in #{resultdir}" - on( - agent, - puppet('agent', "-t"), - :acceptable_exit_codes => [2] - ) - - step "####### Verifying hiera calls from erb template #######" - r1 = on(agent, "cat #{resultdir}/hieratest_results_erb") - result = r1.stdout - - step "Verifying hiera() call #1." - assert_match( - /#{@h_m_call}: #{@msg_production}/, - result, - "#{@h_m_call} failed. Expected: '#{@msg_production}'" - ) - - step "Verifying hiera() call #2." - assert_match( - /#{@h_h_call}.*\"#{@k3}\"=>\"#{@hval3p}\"/, - result, - "#{@h_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'" - ) - - step "Verifying hiera() call #3." - assert_match( - /#{@h_h_call}.*\"#{@k2}\"=>\"#{@hval2p}\"/, - result, - "#{@h_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'" - ) - - step "Verifying hiera() call #4." - assert_match( - /#{@h_i_call}: #{@module_name}::mod_production/, - result, - "#{@h_i_call} failed. Expected:'#{@module_name}::mod_production'" - ) - - step "Verifying hiera_array() call. #1" - assert_match( -/#{@ha_m_call}: \[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"\]/, - result, - "#{@ha_m_call} failed. Expected: '[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"]'" - ) - - step "Verifying hiera_array() call. #2" - assert_match( -/#{@ha_i_call}: \[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"\]/, - result, - "#{@ha_i_call} failed. Expected: '[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"]'" - ) - - step "Verifying hiera_hash() call. #1" - assert_match( - /#{@hh_h_call}:.*\"#{@k3}\"=>\"#{@hval3p}\"/, - result, - "#{@hh_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'" - ) - - step "Verifying hiera_hash() call. #2" - assert_match( - /#{@hh_h_call}:.*\"#{@k2}\"=>\"#{@hval2p}\"/, - result, - "#{@hh_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'" - ) - - step "Verifying hiera_hash() call. #3" - assert_match( - /#{@hh_h_call}:.*\"#{@k1}\"=>\"#{@hval1os}\"/, - result, - "#{@hh_h_call} failed. Expected: '\"#{@k1}\"=>\"#{@hval1os}\"'" - ) - - r2 = on(agent, "cat #{resultdir}/mod_default") - result = r2.stdout - step "Verifying hiera_include() call. #1" - assert_match( - "#{@mod_default_msg}", - result, - "#{@hi_i_call} failed. Expected: '#{@mod_default_msg}'" - ) - - r3 = on(agent, "cat #{resultdir}/mod_osfamily") - result = r3.stdout - step "Verifying hiera_include() call. #2" - assert_match( - "#{@mod_osfamily_msg}", - result, - "#{@hi_i_call} failed. Expected: '#{@mod_osfamily_msg}'" - ) - - r4 = on(agent, "cat #{resultdir}/mod_production") - result = r4.stdout - step "Verifying hiera_include() call. #3" - assert_match( - "#{@mod_production_msg}", - result, - "#{@hi_i_call} failed. Expected: '#{@mod_production_msg}'" - ) - - step "####### Verifying hiera calls from epp template #######" - r5 = on(agent, "cat #{resultdir}/hieratest_results_epp") - result = r5.stdout - - step "Verifying hiery() call #1." - assert_match( - /#{@h_m_call}: #{@msg_production}/, - result, - "#{@hi_m_call} failed. Expected '#{@msg_production}'" - ) - - step "Verifying hiera() call #2." - assert_match( - /#{@h_h_call}.*#{@k3} => #{@hval3p}/, - result, - "#{@h_h_call} failed. Expected '#{@k3} => #{@hval3p}'" - ) - - step "Verifying hiera() call #3." - assert_match(/#{@h_h_call}.*#{@k2} => #{@hval2p}/, - result, - "#{@h_h_call} failed. Expected '#{@k2} => #{@hval2p}'" - ) - - step "Verifying hiera() call #4." - assert_match( - /#{@h_i_call}: #{@module_name}::mod_production/, - result, - "#{@h_i_call} failed. Expected: '#{@module_name}::mod_production'" - ) - - step "Verifying hiera_array() call. #1" - assert_match( -/#{@ha_m_call}: \[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}\]/, - result, - "#{@ha_m_call} failed. Expected: '[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}]'" - ) - - step "Verifying hiera_array() call. #2" - assert_match( -/#{@ha_i_call}: \[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default\]/, - result, - "#{@ha_i_call} failed. Expected: '[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default'" - ) - - step "Verifying hiera_hash() call. #1" - assert_match( - /#{@hh_h_call}:.*#{@k3} => #{@hval3p}/, - result, - "#{@hh_h_call} failed. Expected: '{@k3} => #{@hval3p}'" - ) - - step "Verifying hiera_hash() call. #2" - assert_match( - /#{@hh_h_call}:.*#{@k2} => #{@hval2p}/, - result, - "#{@hh_h_call} failed. Expected '#{@k2} => #{@hval2p}'", - ) - - step "Verifying hiera_hash() call. #3" - assert_match( - /#{@hh_h_call}:.*#{@k1} => #{@hval1os}/, - result, - "#{@hh_h_call}: failed. Expected: '#{@k1} => #{@hval1os}'" - ) - end -end diff --git a/acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb b/acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb deleted file mode 100644 index c3120a5145..0000000000 --- a/acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb +++ /dev/null @@ -1,71 +0,0 @@ -test_name 'C97760: Integer in reduce() should not cause exception' do - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - tag 'audit:high', - 'audit:unit' - - # Remove all traces of the last used environment - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_type = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, app_type) - - step 'On master, create site.pp with integer' do - create_sitepp(master, tmp_environment, <<-SITEPP) -$data = [ -{ -"certname"=>"xxxxxxxxx.some.domain", -"parameters"=>{ - "admin_auth_keys"=>{ - "keyname1"=>{ - "key"=>"ABCDEF", - "options"=>["from=\\"10.0.0.0/8\\""] - }, - "keyname2"=>{ - "key"=>"ABCDEF", - }, - "keyname3"=>{ - "key"=>"ABCDEF", - "options"=>["from=\\"10.0.0.0/8\\""], - "type"=>"ssh-xxx" - }, - "keyname4"=>{ - "key"=>"ABCDEF", - "options"=>["from=\\"10.0.0.0/8\\""] - } - }, - "admin_user"=>"ertxa", - "admin_hosts"=>["1.2.3.4", - "1.2.3.4", - "1.2.3.4"], - "admin_password"=>"ABCDEF", - "sshd_ports"=>[22, - 22, 24], - "sudo_no_password_all"=>false, - "sudo_no_password_commands"=>[], - "sshd_config_template"=>"cfauth/sshd_config.epp", - "sudo_env_keep"=>[] -}, -"exported"=>false}, -] -$data_reduced = $data.reduce({}) |$m, $r|{ - $cn = $r['certname'] - notice({ $cn => $r['parameters'] }) -} -SITEPP - end - - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}")) - end - end - -end diff --git a/acceptance/tests/parser_functions/puppet_lookup_cmd.rb b/acceptance/tests/parser_functions/puppet_lookup_cmd.rb deleted file mode 100644 index 4d3a2e2d82..0000000000 --- a/acceptance/tests/parser_functions/puppet_lookup_cmd.rb +++ /dev/null @@ -1,2625 +0,0 @@ -test_name "Puppet Lookup Command" - -tag 'audit:high', - 'audit:acceptance', - 'audit:refactor' # Master is not required for this test. Replace with agents.each - # Wrap steps in blocks in accordance with Beaker style guide - -# doc: -# https://puppet.com/docs/puppet/latest/hiera_automatic.html - -@module_name = "puppet_lookup_command_test" - -### @testroot = "/etc/puppetlabs" -@testroot = master.tmpdir("#{@module_name}") - -@coderoot = "#{@testroot}/code" -@confdir = "#{@testroot}/puppet" - -@node1 = 'node1.example.org' -@node2 = 'node2.example.org' - -@master_opts = { - 'main' => { - 'environmentpath' => "#{@coderoot}/environments", - 'hiera_config' => "#{@coderoot}/hiera.yaml", - }, -} - -@manifest = < directory, - mode => "0755", -} - -file { - '#{@confdir}':; - '#{@coderoot}':; - '#{@coderoot}/hieradata':; - '#{@coderoot}/environments':; - -##### default environment, production - '#{@coderoot}/environments/production':; - '#{@coderoot}/environments/production/data':; - '#{@coderoot}/environments/production/functions':; - '#{@coderoot}/environments/production/functions/environment':; - '#{@coderoot}/environments/production/lib':; - '#{@coderoot}/environments/production/lib/puppet':; - '#{@coderoot}/environments/production/lib/puppet/functions':; - '#{@coderoot}/environments/production/lib/puppet/functions/environment':; - '#{@coderoot}/environments/production/manifests':; - '#{@coderoot}/environments/production/modules':; - -# module mod1 hiera - '#{@coderoot}/environments/production/modules/mod1':; - '#{@coderoot}/environments/production/modules/mod1/manifests':; - '#{@coderoot}/environments/production/modules/mod1/data':; - '#{@coderoot}/environments/production/modules/mod1/functions':; - '#{@coderoot}/environments/production/modules/mod1/lib':; - '#{@coderoot}/environments/production/modules/mod1/lib/puppet':; - '#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions':; - '#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions/mod1':; - -# module mod2 ruby function - '#{@coderoot}/environments/production/modules/mod2':; - '#{@coderoot}/environments/production/modules/mod2/manifests':; - '#{@coderoot}/environments/production/modules/mod2/data':; - '#{@coderoot}/environments/production/modules/mod2/functions':; - '#{@coderoot}/environments/production/modules/mod2/lib':; - '#{@coderoot}/environments/production/modules/mod2/lib/puppet':; - '#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions':; - '#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions/mod2':; - -# module mod3 puppet function - '#{@coderoot}/environments/production/modules/mod3':; - '#{@coderoot}/environments/production/modules/mod3/manifests':; - '#{@coderoot}/environments/production/modules/mod3/data':; - '#{@coderoot}/environments/production/modules/mod3/functions':; - '#{@coderoot}/environments/production/modules/mod3/not-lib':; - '#{@coderoot}/environments/production/modules/mod3/not-lib/puppet':; - '#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions':; - '#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions/mod3':; - -# module mod4 none - '#{@coderoot}/environments/production/modules/mod4':; - '#{@coderoot}/environments/production/modules/mod4/manifests':; - '#{@coderoot}/environments/production/modules/mod4/data':; - '#{@coderoot}/environments/production/modules/mod4/functions':; - '#{@coderoot}/environments/production/modules/mod4/lib':; - '#{@coderoot}/environments/production/modules/mod4/lib/puppet':; - '#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions':; - '#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions/mod4':; - -##### env1 hiera - '#{@coderoot}/environments/env1':; - '#{@coderoot}/environments/env1/data':; - '#{@coderoot}/environments/env1/functions':; - '#{@coderoot}/environments/env1/functions/environment':; - '#{@coderoot}/environments/env1/lib':; - '#{@coderoot}/environments/env1/lib/puppet':; - '#{@coderoot}/environments/env1/lib/puppet/functions':; - '#{@coderoot}/environments/env1/lib/puppet/functions/environment':; - '#{@coderoot}/environments/env1/manifests':; - '#{@coderoot}/environments/env1/modules':; - -# module mod1 hiera - '#{@coderoot}/environments/env1/modules/mod1':; - '#{@coderoot}/environments/env1/modules/mod1/manifests':; - '#{@coderoot}/environments/env1/modules/mod1/data':; - '#{@coderoot}/environments/env1/modules/mod1/functions':; - '#{@coderoot}/environments/env1/modules/mod1/lib':; - '#{@coderoot}/environments/env1/modules/mod1/lib/puppet':; - '#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions':; - '#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions/mod1':; - -# module mod2 ruby function - '#{@coderoot}/environments/env1/modules/mod2':; - '#{@coderoot}/environments/env1/modules/mod2/manifests':; - '#{@coderoot}/environments/env1/modules/mod2/data':; - '#{@coderoot}/environments/env1/modules/mod2/functions':; - '#{@coderoot}/environments/env1/modules/mod2/lib':; - '#{@coderoot}/environments/env1/modules/mod2/lib/puppet':; - '#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions':; - '#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions/mod2':; - -# module mod3 puppet function - '#{@coderoot}/environments/env1/modules/mod3':; - '#{@coderoot}/environments/env1/modules/mod3/manifests':; - '#{@coderoot}/environments/env1/modules/mod3/data':; - '#{@coderoot}/environments/env1/modules/mod3/functions':; - '#{@coderoot}/environments/env1/modules/mod3/not-lib':; - '#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet':; - '#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet/functions':; - '#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet/functions/mod3':; - -# module mod4 none - '#{@coderoot}/environments/env1/modules/mod4':; - '#{@coderoot}/environments/env1/modules/mod4/manifests':; - '#{@coderoot}/environments/env1/modules/mod4/data':; - '#{@coderoot}/environments/env1/modules/mod4/functions':; - '#{@coderoot}/environments/env1/modules/mod4/lib':; - '#{@coderoot}/environments/env1/modules/mod4/lib/puppet':; - '#{@coderoot}/environments/env1/modules/mod4/lib/puppet/functions':; - '#{@coderoot}/environments/env1/modules/mod4/lib/puppet/functions/mod4':; - - -##### env2 ruby function - '#{@coderoot}/environments/env2':; - '#{@coderoot}/environments/env2/data':; - '#{@coderoot}/environments/env2/functions':; - '#{@coderoot}/environments/env2/functions/environment':; - '#{@coderoot}/environments/env2/lib':; - '#{@coderoot}/environments/env2/lib/puppet':; - '#{@coderoot}/environments/env2/lib/puppet/functions':; - '#{@coderoot}/environments/env2/lib/puppet/functions/environment':; - '#{@coderoot}/environments/env2/manifests':; - '#{@coderoot}/environments/env2/modules':; - -# module mod1 hiera - '#{@coderoot}/environments/env2/modules/mod1':; - '#{@coderoot}/environments/env2/modules/mod1/manifests':; - '#{@coderoot}/environments/env2/modules/mod1/data':; - '#{@coderoot}/environments/env2/modules/mod1/functions':; - '#{@coderoot}/environments/env2/modules/mod1/lib':; - '#{@coderoot}/environments/env2/modules/mod1/lib/puppet':; - '#{@coderoot}/environments/env2/modules/mod1/lib/puppet/functions':; - '#{@coderoot}/environments/env2/modules/mod1/lib/puppet/functions/mod1':; - -# module mod2 ruby function - '#{@coderoot}/environments/env2/modules/mod2':; - '#{@coderoot}/environments/env2/modules/mod2/manifests':; - '#{@coderoot}/environments/env2/modules/mod2/data':; - '#{@coderoot}/environments/env2/modules/mod2/functions':; - '#{@coderoot}/environments/env2/modules/mod2/lib':; - '#{@coderoot}/environments/env2/modules/mod2/lib/puppet':; - '#{@coderoot}/environments/env2/modules/mod2/lib/puppet/functions':; - '#{@coderoot}/environments/env2/modules/mod2/lib/puppet/functions/mod2':; - -# module mod3 puppet function - '#{@coderoot}/environments/env2/modules/mod3':; - '#{@coderoot}/environments/env2/modules/mod3/manifests':; - '#{@coderoot}/environments/env2/modules/mod3/data':; - '#{@coderoot}/environments/env2/modules/mod3/functions':; - '#{@coderoot}/environments/env2/modules/mod3/not-lib':; - '#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet':; - '#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet/functions':; - '#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet/functions/mod3':; - -# module mod4 none - '#{@coderoot}/environments/env2/modules/mod4':; - '#{@coderoot}/environments/env2/modules/mod4/manifests':; - '#{@coderoot}/environments/env2/modules/mod4/data':; - '#{@coderoot}/environments/env2/modules/mod4/functions':; - '#{@coderoot}/environments/env2/modules/mod4/lib':; - '#{@coderoot}/environments/env2/modules/mod4/lib/puppet':; - '#{@coderoot}/environments/env2/modules/mod4/lib/puppet/functions':; - '#{@coderoot}/environments/env2/modules/mod4/lib/puppet/functions/mod4':; - - -##### env3 puppet function - '#{@coderoot}/environments/env3':; - '#{@coderoot}/environments/env3/data':; - '#{@coderoot}/environments/env3/functions':; - '#{@coderoot}/environments/env3/functions/environment':; - '#{@coderoot}/environments/env3/not-lib':; - '#{@coderoot}/environments/env3/not-lib/puppet':; - '#{@coderoot}/environments/env3/not-lib/puppet/functions':; - '#{@coderoot}/environments/env3/not-lib/puppet/functions/environment':; - '#{@coderoot}/environments/env3/manifests':; - '#{@coderoot}/environments/env3/modules':; - -# module mod1 hiera - '#{@coderoot}/environments/env3/modules/mod1':; - '#{@coderoot}/environments/env3/modules/mod1/manifests':; - '#{@coderoot}/environments/env3/modules/mod1/data':; - '#{@coderoot}/environments/env3/modules/mod1/functions':; - '#{@coderoot}/environments/env3/modules/mod1/lib':; - '#{@coderoot}/environments/env3/modules/mod1/lib/puppet':; - '#{@coderoot}/environments/env3/modules/mod1/lib/puppet/functions':; - '#{@coderoot}/environments/env3/modules/mod1/lib/puppet/functions/mod1':; - -# module mod2 ruby function - '#{@coderoot}/environments/env3/modules/mod2':; - '#{@coderoot}/environments/env3/modules/mod2/manifests':; - '#{@coderoot}/environments/env3/modules/mod2/data':; - '#{@coderoot}/environments/env3/modules/mod2/functions':; - '#{@coderoot}/environments/env3/modules/mod2/lib':; - '#{@coderoot}/environments/env3/modules/mod2/lib/puppet':; - '#{@coderoot}/environments/env3/modules/mod2/lib/puppet/functions':; - '#{@coderoot}/environments/env3/modules/mod2/lib/puppet/functions/mod2':; - -# module mod3 puppet function - '#{@coderoot}/environments/env3/modules/mod3':; - '#{@coderoot}/environments/env3/modules/mod3/manifests':; - '#{@coderoot}/environments/env3/modules/mod3/data':; - '#{@coderoot}/environments/env3/modules/mod3/functions':; - '#{@coderoot}/environments/env3/modules/mod3/not-lib':; - '#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet':; - '#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet/functions':; - '#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet/functions/mod3':; - -# module mod4 none - '#{@coderoot}/environments/env3/modules/mod4':; - '#{@coderoot}/environments/env3/modules/mod4/manifests':; - '#{@coderoot}/environments/env3/modules/mod4/data':; - '#{@coderoot}/environments/env3/modules/mod4/functions':; - '#{@coderoot}/environments/env3/modules/mod4/lib':; - '#{@coderoot}/environments/env3/modules/mod4/lib/puppet':; - '#{@coderoot}/environments/env3/modules/mod4/lib/puppet/functions':; - '#{@coderoot}/environments/env3/modules/mod4/lib/puppet/functions/mod4':; - - -##### env4 none - '#{@coderoot}/environments/env4':; - '#{@coderoot}/environments/env4/data':; - '#{@coderoot}/environments/env4/functions':; - '#{@coderoot}/environments/env4/functions/environment':; - '#{@coderoot}/environments/env4/lib':; - '#{@coderoot}/environments/env4/lib/puppet':; - '#{@coderoot}/environments/env4/lib/puppet/functions':; - '#{@coderoot}/environments/env4/lib/puppet/functions/environment':; - '#{@coderoot}/environments/env4/manifests':; - '#{@coderoot}/environments/env4/modules':; - -# module mod1 hiera - '#{@coderoot}/environments/env4/modules/mod1':; - '#{@coderoot}/environments/env4/modules/mod1/manifests':; - '#{@coderoot}/environments/env4/modules/mod1/data':; - '#{@coderoot}/environments/env4/modules/mod1/functions':; - '#{@coderoot}/environments/env4/modules/mod1/lib':; - '#{@coderoot}/environments/env4/modules/mod1/lib/puppet':; - '#{@coderoot}/environments/env4/modules/mod1/lib/puppet/functions':; - '#{@coderoot}/environments/env4/modules/mod1/lib/puppet/functions/mod1':; - -# module mod2 ruby function - '#{@coderoot}/environments/env4/modules/mod2':; - '#{@coderoot}/environments/env4/modules/mod2/manifests':; - '#{@coderoot}/environments/env4/modules/mod2/data':; - '#{@coderoot}/environments/env4/modules/mod2/functions':; - '#{@coderoot}/environments/env4/modules/mod2/lib':; - '#{@coderoot}/environments/env4/modules/mod2/lib/puppet':; - '#{@coderoot}/environments/env4/modules/mod2/lib/puppet/functions':; - '#{@coderoot}/environments/env4/modules/mod2/lib/puppet/functions/mod2':; - -# module mod3 puppet function - '#{@coderoot}/environments/env4/modules/mod3':; - '#{@coderoot}/environments/env4/modules/mod3/manifests':; - '#{@coderoot}/environments/env4/modules/mod3/data':; - '#{@coderoot}/environments/env4/modules/mod3/functions':; - '#{@coderoot}/environments/env4/modules/mod3/not-lib':; - '#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet':; - '#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet/functions':; - '#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet/functions/mod3':; - -# module mod4 none - '#{@coderoot}/environments/env4/modules/mod4':; - '#{@coderoot}/environments/env4/modules/mod4/manifests':; - '#{@coderoot}/environments/env4/modules/mod4/data':; - '#{@coderoot}/environments/env4/modules/mod4/functions':; - '#{@coderoot}/environments/env4/modules/mod4/lib':; - '#{@coderoot}/environments/env4/modules/mod4/lib/puppet':; - '#{@coderoot}/environments/env4/modules/mod4/lib/puppet/functions':; - '#{@coderoot}/environments/env4/modules/mod4/lib/puppet/functions/mod4':; -} - -## Global data provider config (hiera) -file { '#{@coderoot}/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - :backends: - - "yaml" - :logger: "console" - :hierarchy: - - "global" - - :yaml: - :datadir: "#{@coderoot}/hieradata" -', -} - -## facts file -file { '#{@coderoot}/facts.yaml': - ensure => file, - mode => "0644", - content => '--- - my_data_key: "my_data_value" -', -} - -file { '#{@coderoot}/hieradata/global.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "global-hiera provided value for key" - another_global_key: "global-hiera provided value for key" - mod1::global_key: "global-hiera provided value for key" - mod2::global_key: "global-hiera provided value for key" - mod3::global_key: "global-hiera provided value for key" - mod4::global_key: "global-hiera provided value for key" -', -} - - -## Evironment data provider configuration -file { '#{@coderoot}/environments/production/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -', -} - -file { '#{@coderoot}/environments/env1/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -environment_data_provider = "hiera" -', -} - -file { '#{@coderoot}/environments/env2/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -environment_data_provider = "function" -', -} - -file { '#{@coderoot}/environments/env3/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -environment_data_provider = "function" -', -} - -file { '#{@coderoot}/environments/env4/environment.conf': - ensure => file, - mode => "0644", - content => 'environment_timeout = 0 -environment_data_provider = "none" -', -} - -# Environment hiera data provider -file { '#{@coderoot}/environments/production/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/production/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "env-production hiera provided value" - environment_key: "env-production hiera provided value" -', -} - -file { '#{@coderoot}/environments/env1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "env-env1 hiera provided value" - environment_key: "env-env1 hiera provided value" -', -} - - -file { '#{@coderoot}/environments/env2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "env-env1 hiera provided value" - environment_key: "env-env1 hiera provided value" -', -} - - -file { '#{@coderoot}/environments/env3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "env-env1 hiera provided value" - environment_key: "env-env1 hiera provided value" -', -} - - -file { '#{@coderoot}/environments/env4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - global_key: "env-env1 hiera provided value" - environment_key: "env-env1 hiera provided value" -', -} - -# Environment ruby function data provider -file { '#{@coderoot}/environments/production/lib/puppet/functions/environment/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'environment::data') do - def data() - { - 'environment_key': 'env-production-ruby-function data() provided value', - 'global_key': 'env-production-ruby-function data () provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env1/lib/puppet/functions/environment/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'environment::data') do - def data() - { - 'environment_key' => 'env-env1-ruby-function data() provided value', - 'global_key' => 'env-env1-ruby-function data () provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env2/lib/puppet/functions/environment/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'environment::data') do - def data() - { - 'environment_key' => 'env-env2-ruby-function data() provided value', - 'global_key' => 'env-env2-ruby-function data () provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env3/not-lib/puppet/functions/environment/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'environment::data') do - def data() - { - 'environment_key' => 'env-env3-ruby-function data() provided value', - 'global_key' => 'env-env3-ruby-function data () provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env4/lib/puppet/functions/environment/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'environment::data') do - def data() - { - 'environment_key' => 'env-env4-ruby-function data() provided value', - 'global_key' => 'env-env4-ruby-function data () provided value', - } - end -end -", -} - -# Environment puppet function data provider -file { '#{@coderoot}/environments/production/functions/environment/data.pp': - ensure => file, - mode => "0755", - content => 'function environment::data() { - { - "environment_key" => "env-production-puppet-function data() provided value", - "global_key" => "env-production-puppet-function data() provided value", - } -} -', -} - -file { '#{@coderoot}/environments/env1/functions/environment/data.pp': - ensure => file, - mode => "0755", - content => 'function environment::data() { - { - "environment_key" => "env-env1-puppet-function data() provided value", - "global_key" => "env-env1-puppet-function data() provided value", - } -} -', -} - -file { '#{@coderoot}/environments/env2/functions/environment/data.pp': - ensure => file, - mode => "0755", - content => 'function environment::data() { - { - "environment_key" => "env-env2-puppet-function data() provided value", - "global_key" => "env-env2-puppet-function data() provided value", - } -} -', -} - -file { '#{@coderoot}/environments/env3/functions/environment/data.pp': - ensure => file, - mode => "0755", - content => 'function environment::data() { - { - "environment_key" => "env-env3-puppet-function data() provided value", - "global_key" => "env-env3-puppet-function data() provided value", - } -} -', -} - -file { '#{@coderoot}/environments/env4/functions/environment/data.pp': - ensure => file, - mode => "0755", - content => 'function environment::data() { - { - "environment_key" => "env-env4-puppet-function data() provided value", - "global_key" => "env-env4-puppet-function data() provided value", - } -} -', -} - - -## Module data provider configuration -# Module hiera data provider -file { '#{@coderoot}/environments/production/modules/mod1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/production/modules/mod1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod1::module_key": "module-production-mod1-hiera provided value" - "mod1::global_key": "module-production-mod1-hiera provided value" - "environment_key": "module-production-mod1-hiera provided value" - "global_key": "module-production-mod1-hiera provided value" -', -} - -file { '#{@coderoot}/environments/production/modules/mod2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/production/modules/mod2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod2::module_key": "module-production-mod2-hiera provided value" - "mod2::global_key": "module-production-mod2-hiera provided value" - "environment_key": "module-production-mod2-hiera provided value" - "global_key": "module-production-mod2-hiera provided value" -', -} - -file { '#{@coderoot}/environments/production/modules/mod3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/production/modules/mod3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod3::module_key": "module-production-mod3-hiera provided value" - "mod3::global_key": "module-production-mod3-hiera provided value" - "environment_key": "module-production-mod3-hiera provided value" - "global_key" => "module-production-mod3-hiera provided value" -', -} - -file { '#{@coderoot}/environments/production/modules/mod4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/production/modules/mod4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod4::module_key": "module-production-mod4-hiera provided value" - "mod4::global_key": "module-production-mod4-hiera provided value" - "environment_key": "module-production-mod4-hiera provided value" - "global_key": "module-production-mod4-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env1/modules/mod1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env1/modules/mod1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod1::module_key": "module-env1-mod1-hiera provided value" - "global_key": "module-env1-mod1-hiera provided value" - "environment_key": "module-env1-mod1-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env1/modules/mod2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env1/modules/mod2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod2::module_key": "module-env1-mod2-hiera provided value" - "global_key": "module-env1-mod2-hiera provided value" - "environment_key": "module-env1-mod2-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env1/modules/mod3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env1/modules/mod3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod3::module_key": "module-env1-mod3-hiera provided value" - "global_key": "module-env1-mod3-hiera provided value" - "environment_key": "module-env1-mod3-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env1/modules/mod4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env1/modules/mod4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod4::module_key": "module-env1-mod4-hiera provided value" - "global_key": "module-env1-mod4-hiera provided value" - "environment_key": "module-env1-mod4-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env2/modules/mod1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env2/modules/mod1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod1::module_key": "module-env2-mod1-hiera provided value" - "global_key": "module-env2-mod1-hiera provided value" - "environment_key": "module-env2-mod1-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env2/modules/mod2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env2/modules/mod2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod2::module_key": "module-env2-mod2-hiera provided value" - "global_key": "module-env2-mod2-hiera provided value" - "environment_key": "module-env2-mod2-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env2/modules/mod3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env2/modules/mod3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod3::module_key": "module-env2-mod3-hiera provided value" - "global_key": "module-env2-mod3-hiera provided value" - "environment_key": "module-env2-mod3-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env2/modules/mod4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env2/modules/mod4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod4::module_key": "module-env2-mod4-hiera provided value" - "global_key": "module-env2-mod4-hiera provided value" - "environment_key": "module-env2-mod4-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env3/modules/mod1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env3/modules/mod1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod1::module_key": "module-env3-mod1-hiera provided value" - "global_key": "module-env3-mod1-hiera provided value" - "environment_key": "module-env3-mod1-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env3/modules/mod2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env3/modules/mod2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod2::module_key": "module-env3-mod2-hiera provided value" - "global_key": "module-env3-mod2-hiera provided value" - "environment_key": "module-env3-mod2-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env3/modules/mod3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env3/modules/mod3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod3::module_key": "module-env3-mod3-hiera provided value" - "global_key": "module-env3-mod3-hiera provided value" - "environment_key": "module-env3-mod3-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env3/modules/mod4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env3/modules/mod4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod4::module_key": "module-env3-mod4-hiera provided value" - "global_key": "module-env3-mod4-hiera provided value" - "environment_key": "module-env3-mod4-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env4/modules/mod1/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env4/modules/mod1/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod1::module_key": "module-env4-mod1-hiera provided value" - "global_key": "module-env4-mod1-hiera provided value" - "environment_key": "module-env4-mod1-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env4/modules/mod2/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env4/modules/mod2/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod2::module_key": "module-env4-mod2-hiera provided value" - "global_key": "module-env4-mod2-hiera provided value" - "environment_key": "module-env4-mod2-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env4/modules/mod3/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env4/modules/mod3/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod3::module_key": "module-env4-mod3-hiera provided value" - "global_key": "module-env4-mod3-hiera provided value" - "environment_key": "module-env4-mod3-hiera provided value" -', -} - -file { '#{@coderoot}/environments/env4/modules/mod4/hiera.yaml': - ensure => file, - mode => "0644", - content => '--- - version: 4 -', -} - -file { '#{@coderoot}/environments/env4/modules/mod4/data/common.yaml': - ensure => file, - mode => "0644", - content => '--- - "mod4::module_key": "module-env4-mod4-hiera provided value" - "global_key": "module-env4-mod4-hiera provided value" - "environment_key": "module-env4-mod4-hiera provided value" -', -} - -# Module ruby function data provider -file { '#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions/mod1/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod1::data') do - def data() - { - 'mod1::module_key' => 'module-production-mod1-ruby-function provided value', - 'mod1::global_key' => 'module-production-mod1-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions/mod2/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod2::data') do - def data() - { - 'mod2::module_key' => 'module-production-mod2-ruby-function provided value', - 'mod2::global_key' => 'module-production-mod2-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions/mod3/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod3::data') do - def data() - { - 'mod3::module_key' => 'module-production-mod3-ruby-function provided value', - 'mod3::global_key' => 'module-production-mod3-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions/mod4/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod4::data') do - def data() - { - 'mod4::module_key' => 'module-production-mod4-ruby-function provided value', - 'mod4::global_key' => 'module-production-mod4-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions/mod1/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod1::data') do - def data() - { - 'mod1::module_key' => 'module-env1-mod1-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions/mod2/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod2::data') do - def data() - { - 'mod2::module_key' => 'module-env1-mod2-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet/functions/mod3/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod3::data') do - def data() - { - 'mod3::module_key' => 'module-env1-mod3-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env1/modules/mod4/lib/puppet/functions/mod4/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod4::data') do - def data() - { - 'mod4::module_key' => 'module-env1-mod4-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env2/modules/mod1/lib/puppet/functions/mod1/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod1::data') do - def data() - { - 'mod1::module_key' => 'module-env2-mod1-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env2/modules/mod2/lib/puppet/functions/mod2/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod2::data') do - def data() - { - 'mod2::module_key' => 'module-env2-mod2-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet/functions/mod3/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod3::data') do - def data() - { - 'mod3::module_key' => 'module-env2-mod3-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env2/modules/mod4/lib/puppet/functions/mod4/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod4::data') do - def data() - { - 'mod4::module_key' => 'module-env2-mod4-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env3/modules/mod1/lib/puppet/functions/mod1/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod1::data') do - def data() - { - 'mod1::module_key' => 'module-env3-mod1-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env3/modules/mod2/lib/puppet/functions/mod2/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod2::data') do - def data() - { - 'mod2::module_key' => 'module-env3-mod2-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet/functions/mod3/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod3::data') do - def data() - { - 'mod3::module_key' => 'module-env3-mod3-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env3/modules/mod4/lib/puppet/functions/mod4/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod4::data') do - def data() - { - 'mod4::module_key' => 'module-env3-mod4-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env4/modules/mod1/lib/puppet/functions/mod1/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod1::data') do - def data() - { - 'mod1::module_key' => 'module-env4-mod1-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env4/modules/mod2/lib/puppet/functions/mod2/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod2::data') do - def data() - { - 'mod2::module_key' => 'module-env4-mod2-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet/functions/mod3/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod3::data') do - def data() - { - 'mod3::module_key' => 'module-env4-mod3-ruby-function provided value', - } - end -end -", -} - -file { '#{@coderoot}/environments/env4/modules/mod4/lib/puppet/functions/mod4/data.rb': - ensure => file, - mode => "0644", - content => "Puppet::Functions.create_function(:'mod4::data') do - def data() - { - 'mod4::module_key' => 'module-env4-mod4-ruby-function provided value', - } - end -end -", -} - -# Module puppet function data provider -file { '#{@coderoot}/environments/production/modules/mod1/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod1::data() { - { - 'mod1::module_key' => 'module-production-mod1-puppet-function provided value', - 'mod1::global_key' => 'module-production-mod1-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/production/modules/mod2/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod2::data() { - { - 'mod2::module_key' => 'module-production-mod2-puppet-function provided value', - 'mod2::global_key' => 'module-production-mod2-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/production/modules/mod3/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod3::data() { - { - 'mod3::module_key' => 'module-production-mod3-puppet-function provided value', - 'mod3::global_key' => 'module-production-mod3-puppet-funtion provided value', - } -} -", -} - -file { '#{@coderoot}/environments/production/modules/mod4/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod4::data() { - { - 'mod4::module_key' => 'module-production-mod4-puppet-function provided value', - 'mod4::global_key' => 'module-production-mod4-puppet-funtion provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env1/modules/mod1/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod1::data() { - { - 'mod1::module_key' => 'module-env1-mod1-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env1/modules/mod2/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod2::data() { - { - 'mod2::module_key' => 'module-env1-mod2-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env1/modules/mod3/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod3::data() { - { - 'mod3::module_key' => 'module-env1-mod3-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env1/modules/mod4/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod4::data() { - { - 'mod4::module_key' => 'module-env1-mod4-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env2/modules/mod1/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod1::data() { - { - 'mod1::module_key' => 'module-env2-mod1-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env2/modules/mod2/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod2::data() { - { - 'mod2::module_key' => 'module-env2-mod2-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env2/modules/mod3/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod3::data() { - { - 'mod3::module_key' => 'module-env2-mod3-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env2/modules/mod4/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod4::data() { - { - 'mod4::module_key' => 'module-env2-mod4-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env3/modules/mod1/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod1::data() { - { - 'mod1::module_key' => 'module-env3-mod1-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env3/modules/mod2/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod2::data() { - { - 'mod2::module_key' => 'module-env3-mod2-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env3/modules/mod3/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod3::data() { - { - 'mod3::module_key' => 'module-env3-mod3-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env3/modules/mod4/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod4::data() { - { - 'mod4::module_key' => 'module-env3-mod4-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env4/modules/mod1/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod1::data() { - { - 'mod1::module_key' => 'module-env4-mod1-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env4/modules/mod2/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod2::data() { - { - 'mod2::module_key' => 'module-env4-mod2-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env4/modules/mod3/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod3::data() { - { - 'mod3::module_key' => 'module-env4-mod3-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/env4/modules/mod4/functions/data.pp': - ensure => file, - mode => "0644", - content => "function mod4::data() { - { - 'mod4::module_key' => 'module-env4-mod4-puppet-function provided value', - } -} -", -} - -file { '#{@coderoot}/environments/production/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include mod1 - include mod2 - include mod3 - include mod4 -} -", -} - -file { '#{@coderoot}/environments/env1/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include mod1 - include mod2 - include mod3 - include mod4 -} -", -} - -file { '#{@coderoot}/environments/env2/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include mod1 - include mod2 - include mod3 - include mod4 -} -", -} - -file { '#{@coderoot}/environments/env3/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include mod1 - include mod2 - include mod3 - include mod4 -} -", -} - -file { '#{@coderoot}/environments/env4/manifests/site.pp': - ensure => file, - mode => "0644", - content => "node default { - include mod1 - include mod2 - include mod2 - include mod2 -} -", -} - -file { '#{@coderoot}/environments/production/modules/mod1/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod1 { - notice("hello from production-mod1") -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod2/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod2 { - notice("hello from production-mod2") -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod3/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod3 { - notice("hello from production-mod3") -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod4/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod4 { - notice("hello from production-mod4") -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod1/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod1 { - notice("hello from env1-mod1") -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod2/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod2 { - notice("hello from env1-mod2") -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod3/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod3 { - notice("hello from env1-mod3") -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod4/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod4 { - notice("hello from env1-mod4") -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod1/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod1 { - notice("hello from env2-mod1") -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod2/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod2 { - notice("hello from env2-mod2") -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod3/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod3 { - notice("hello from env2-mod3") -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod4/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod4 { - notice("hello from env2-mod4") -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod1/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod1 { - notice("hello from env3-mod1") -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod2/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod2 { - notice("hello from env3-mod2") -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod3/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod3 { - notice("hello from env3-mod3") -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod4/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod4 { - notice("hello from env3-mod4") -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod1/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod1 { - notice("hello from env4-mod1") -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod2/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod2 { - notice("hello from env4-mod2") -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod3/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod3 { - notice("hello from env4-mod3") -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod4/manifests/init.pp': - ensure => file, - mode => "0644", - content => 'class mod4 { - notice("hello from env4-mod4") -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod1/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "hiera" -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod2/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod2", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod3/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod3", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/production/modules/mod4/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "none" -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod1/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "hiera" -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod2/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod2", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod3/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod3", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env1/modules/mod4/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod4", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "none" -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod1/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "hiera" -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod2/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod2", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod3/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod3", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env2/modules/mod4/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod4", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "none" -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod1/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "hiera" -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod2/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod2", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod3/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod3", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env3/modules/mod4/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod4", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "none" -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod1/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod1", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "hiera" -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod2/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod2", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod3/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod3", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "function" -} -', -} - -file { '#{@coderoot}/environments/env4/modules/mod4/metadata.json': - ensure => file, - mode => "0644", - content => '{ - "name": "tester-mod4", - "version": "0.1.0", - "author": "tester", - "summary": null, - "license": "Apache-2.0", - "source": "", - "project_page": null, - "issues_url": null, - "dependencies": [], - "data_provider": "none" -} -', -} -MANIFEST - - @env1puppetconfmanifest = < file, - mode => "0664", - content => "[server] -vardir = /opt/puppetlabs/server/data/puppetserver -logdir = /var/log/puppetlabs/puppetserver -rundir = /var/run/puppetlabs/puppetserver -pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid -codedir = #{@coderoot} - -[main] -environmentpath = #{@coderoot}/environments -hiera_config = #{@coderoot}/hiera.yaml -environment = env1 -server = #{master.connection.hostname} -", -} -MANI1 - - @env2puppetconfmanifest = < file, - mode => "0664", - content => "[server] -vardir = /opt/puppetlabs/server/data/puppetserver -logdir = /var/log/puppetlabs/puppetserver -rundir = /var/run/puppetlabs/puppetserver -pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid -codedir = #{@coderoot} - -[main] -environmentpath = #{@coderoot}/environments -hiera_config = #{@coderoot}/hiera.yaml -environment = env2 -server = #{master.connection.hostname} -", -} -MANI2 - - @env3puppetconfmanifest = < file, - mode => "0664", - content => "[server] -vardir = /opt/puppetlabs/server/data/puppetserver -logdir = /var/log/puppetlabs/puppetserver -rundir = /var/run/puppetlabs/puppetserver -pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid -codedir = #{@coderoot} - -[main] -environmentpath = #{@coderoot}/environments -hiera_config = #{@coderoot}/hiera.yaml -environment = env3 -server = #{master.connection.hostname} -", -} -MANI3 - - @env4puppetconfmanifest = < file, - mode => "0664", - content => "[server] -vardir = /opt/puppetlabs/server/data/puppetserver -logdir = /var/log/puppetlabs/puppetserver -rundir = /var/run/puppetlabs/puppetserver -pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid -codedir = #{@coderoot} - -[main] -environmentpath = #{@coderoot}/environments -hiera_config = #{@coderoot}/hiera.yaml -environment = env4 -server = #{master.connection.hostname} -", -} -MANI4 - - @encmanifest = < file, - mode => "0755", - content => "#!#{master['privatebindir']}/ruby -nodename = ARGV.shift -node2env = { - '#{@node1}' => \\\"---\\\\n environment: env2\\\\n\\\", - '#{@node2}' => \\\"---\\\\n environment: env3\\\\n\\\", -} -puts (\\\"\#{node2env[nodename]}\\\" ||'') -", -} -file { '#{@confdir}/puppet.conf' : - ensure => file, - mode => "0664", - content => "[server] -vardir = /opt/puppetlabs/server/data/puppetserver -logdir = /var/log/puppetlabs/puppetserver -rundir = /var/run/puppetlabs/puppetserver -pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid -codedir = #{@coderoot} - -[server] -node_terminus = exec -external_nodes = #{@coderoot}/enc.rb - -[main] -environmentpath = #{@coderoot}/environments -hiera_config = #{@coderoot}/hiera.yaml -server = #{master.connection.hostname} -", -} -MANIENC - -teardown do - on(master, "rm -f /etc/puppetlabs/puppet/ssl/certs/#{@node1}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/certs/#{@node2}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/ca/signed/#{@node1}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/ca/signed/#{@node2}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/private_keys/#{@node1}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/private_keys/#{@node2}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/public_keys/#{@node1}.pem") - on(master, "rm -f /etc/puppetlabs/puppet/ssl/public_keys/#{@node2}.pem") -end - -step 'apply main manifest' -apply_manifest_on(master, @manifest, :catch_failures => true) - -step 'start puppet server' -with_puppet_running_on master, @master_opts, @coderoot do - - step "global_key" - rg = on(master, puppet('lookup', 'global_key')) - result = rg.stdout - assert_match( - /global-hiera/, - result, - "global_key lookup failed, expected 'global-hiera'" - ) - - step "production environment_key not provided" - on(master, puppet('lookup', 'enviroment_key'), :acceptable_exit_codes => [1]) - - step "environment_key from environment env1" - re1 = on(master, puppet('lookup', '--environment env1', 'environment_key')) - result = re1.stdout - assert_match( - /env-env1 hiera/, - result, - "env1 environment_key lookup failed, expected 'env-env1 hiera'" - ) - - step "environment_key from environment env2" - re2 = on(master, puppet('lookup', '--environment env2', 'environment_key')) - result = re2.stdout - assert_match( - /env-env2-ruby-function/, - result, - "env2 environment_key lookup failed, expected 'env-env2-puppet-function'" - ) - - step "environment_key from environment env3" - re3 = on(master, puppet('lookup', '--environment env3', 'environment_key')) - result = re3.stdout - assert_match( - /env-env3-puppet-function/, - result, - "env3 environment_key lookup failed, expected 'env-env2-ruby-function data() provided value'" - ) - - step "environment_key from environment env4" - on(master, puppet('lookup', '--environment env4', 'environment_key'), :acceptable_exit_codes => [1]) - - step "production mod1 module_key" - repm1 = on(master, puppet('lookup', 'mod1::module_key')) - result = repm1.stdout - assert_match( - /module-production-mod1-hiera/, - result, - "production mod1 module_key lookup failed, expected 'module-production-mod1-hiera'" - ) - - step "production mod2 module_key" - repm2 = on(master, puppet('lookup', 'mod2::module_key')) - result = repm2.stdout - assert_match( - /module-production-mod2-ruby-function/, - result, - "production mod2 module_key lookup failed, expected 'module-production-mod2-ruby-function'" - ) - - step "production mod3 module_key" - repm3 = on(master, puppet('lookup', 'mod3::module_key')) - result = repm3.stdout - assert_match( - /module-production-mod3-puppet-function/, - result, - "production mod3 module_key lookup failed, expected 'module-production-mod3-puppet-function'" - ) - - step "production mod4 module_key" - on(master, puppet('lookup', 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step "env1 mod1 module_key" - re1m1 = on(master, puppet('lookup', '--environment env1', 'mod1::module_key')) - result = re1m1.stdout - assert_match( - /module-env1-mod1-hiera/, - result, - "env1 mod1 module_key lookup failed, expected 'module-env1-mod1-hiera'" - ) - - step "env1 mod2 module_key" - re1m2 = on(master, puppet('lookup', '--environment env1', 'mod2::module_key')) - result = re1m2.stdout - assert_match( - /module-env1-mod2-ruby-function/, - result, - "env1 mod2 module_key lookup failed, expected 'module-env1-mod2-ruby-function'" - ) - - step "env1 mod3 module_key" - re1m3 = on(master, puppet('lookup', '--environment env1', 'mod3::module_key')) - result = re1m3.stdout - assert_match( - /module-env1-mod3-puppet-function/, - result, - "env1 mod3 module_key lookup failed, expected 'module-env1-mod3-puppet-function'" - ) - - step "env1 mod4 module_key" - on(master, puppet('lookup', '--environment env1', 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step "env2 mod1 module_key" - re2m1 = on(master, puppet('lookup', '--environment env2', 'mod1::module_key')) - result = re2m1.stdout - assert_match( - /module-env2-mod1-hiera/, - result, - "env2 mod1 module_key lookup failed, expected 'module-env2-mod1-hiera'" - ) - - step "env2 mod2 module_key" - re2m2 = on(master, puppet('lookup', '--environment env2', 'mod2::module_key')) - result = re2m2.stdout - assert_match( - /module-env2-mod2-ruby-function/, - result, - "env2 mod2 module_key lookup failed, expected 'module-env2-mod2-ruby-function'" - ) - - step "env2 mod3 module_key" - re2m3 = on(master, puppet('lookup', '--environment env2', 'mod3::module_key')) - result = re2m3.stdout - assert_match( - /module-env2-mod3-puppet-function/, - result, - "env2 mod3 module_key lookup failed, expected 'module-env2-mod3-puppet-function'" - ) - - step "env2 mod4 module_key" - on(master, puppet('lookup', '--environment env2', 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step "env3 mod1 module_key" - re3m1 = on(master, puppet('lookup', '--environment env3', 'mod1::module_key')) - result = re3m1.stdout - assert_match( - /module-env3-mod1-hiera/, - result, - "env3 mod1 module_key lookup failed, expected 'module-env3-mod1-hiera'" - ) - - step "env3 mod2 module_key" - re3m2 = on(master, puppet('lookup', '--environment env3', 'mod2::module_key')) - result = re3m2.stdout - assert_match( - /module-env3-mod2-ruby-function/, - result, - "env3 mod2 module_key lookup failed, expected 'module-env3-mod2-ruby-function'" - ) - - step "env3 mod3 module_key" - re3m3 = on(master, puppet('lookup', '--environment env3', 'mod3::module_key')) - result = re3m3.stdout - assert_match( - /module-env3-mod3-puppet-function/, - result, - "env3 mod3 module_key lookup failed, expected 'module-env3-mod3-puppet-function'" - ) - - step "env3 mod4 module_key" -# re3m4 = on(master, puppet('lookup', '--environment env3', 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step "env4 mod1 module_key" - re4m1 = on(master, puppet('lookup', '--environment env4', 'mod1::module_key')) - result = re4m1.stdout - assert_match( - /module-env4-mod1-hiera/, - result, - "env4 mod2 environent_key lookup failed, expected 'module-env4-hiera'" - ) - - - step "env4 mod2 module_key" - re4m2 = on(master, puppet('lookup', '--environment env4', 'mod2::module_key')) - result = re4m2.stdout - assert_match( - /module-env4-mod2-ruby-function/, - result, - "env4 mod2 environent_key lookup failed, expected 'module-env4-mod2-ruby-function'" - ) - - step "env4 mod3 module_key" - re4m3 = on(master, puppet('lookup', '--environment env4', 'mod3::module_key')) - result = re4m3.stdout - assert_match( - /module-env4-mod3-puppet-function/, - result, - "env4 mod3 module_key lookup failed, expected 'module-env4-mod3-puppet-function'" - ) - - step "env4 mod4 module_key" - on(master, puppet('lookup', '--environment env4', 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step "global key explained" - rxg = on(master, puppet('lookup', '--explain', 'global_key')) - result = rxg.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*Found key.*global-hiera/, - result, - "global_key explained failed, expected /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*Found key.*global-hiera/" - ) - - step "environment env1 environment_key explained" - rxe1 = on(master, puppet('lookup', '--explain', '--environment env1', 'environment_key')) - result = rxe1.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/, - result, - "environment env1 enviroment_key lookup failed, expected /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/" - ) - assert_match( - /common.*\s*.*env-env1 hiera/, - result, - "environment env1 enviroment_key lookup failed, expected /common.*\s*.*env-env1 hiera/" - ) - - step "environment env2 environment_key explained" - rxe2 = on(master, puppet('lookup', '--explain', '--environment env2', 'environment_key')) - result = rxe2.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/, - result, - "environment env2 enviroment_key lookup failed, expected /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/" - ) - assert_match( - /eprecated API function.*\s*.*env-env2-ruby-function/, - result, - "environment env2 enviroment_key lookup failed, expected /eprecated API function.*\s*.*env-env2-ruby-function/" - ) - - step "environment env3 environment_key explained" - rxe3 = on(master, puppet('lookup', '--explain', '--environment env3', 'environment_key')) - result = rxe3.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/, - result, - "environment env3 enviroment_key lookup failed, expected /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key/" - ) - assert_match( - /eprecated API function.*\s*.*env-env3-puppet-function/, - result, - "environment env3 enviroment_key lookup failed, expected /eprecated API function.*\s*.*env-env3-puppet-function/" - ) - - step "environment env4 environment_key explained" - rxe4 = on(master, puppet('lookup', '--explain', '--environment env4', 'environment_key')) - result = rxe4.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key.*environment_key/, - result, - "environment env4 environment_key lookup failed expected /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key.*environment_key.*\s.*did not find a value.*/" - ) - - step "environment env1 mod4::module_key explained" - rxe1m4 = on(master, puppet('lookup', '--explain', '--environment env1', 'mod4::module_key')) - result = rxe1m4.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key.*\s*Env.*\s*.*env1\/hiera.yaml\"\s*Hier.*common\"\s*Path.*\s*Orig.*\s*No such key.*\s*Module data provider.*not found\s*.*did not find a value.*/, - result, - "environment env1 mod4::module_key lookup explained failed." - ) - - step "environment env2 mod3::module_key explained" - rxe2m3 = on(master, puppet('lookup', '--explain', '--environment env2', 'mod3::module_key')) - result = rxe2m3.stdout - assert_match( - /Global Data Provider.*Using configuration.*Hierarchy entry.*Path.*No such key/m, - result, - "global env2 mod3::module_key lookup --explain had correct output" - ) - assert_match( - /Environment Data Provider.*Deprecated.*No such key/m, - result, - "environment env2 mod3::module_key lookup --explain had correct output" - ) - assert_match( - /Module.*Data Provider.*Deprecated API function "mod3::data".*Found key.*module-env2-mod3-puppet-function provided value/m, - result, - "module env2 mod3::module_key lookup --explain had correct output" - ) - - step "environment env3 mod2::module_key explained" - rxe3m2 = on(master, puppet('lookup', '--explain', '--environment env3', 'mod2::module_key')) - result = rxe3m2.stdout - assert_match( - /Global Data Provider.*Using configuration.*Hierarchy entry.*Path.*No such key/m, - result, - "global env2 mod3::module_key lookup --explain had correct output" - ) - assert_match( - /Environment Data Provider.*Deprecated.*No such key/m, - result, - "environment env2 mod3::module_key lookup --explain had correct output" - ) - assert_match( - /Module.*Data Provider.*Deprecated API function "mod2::data".*Found key.*module-env3-mod2-ruby-function provided value/m, - result, - "module env2 mod3::module_key lookup --explain had correct output" - ) - - step "environment env4 mod1::module_key explained" - rxe4m1 = on(master, puppet('lookup', '--explain', '--environment env4', 'mod1::module_key')) - result = rxe4m1.stdout - assert_match( - /Global Data Provider.*\s*Using.*\s*Hier.*\s*Path.*\s*Orig.*\s*No such key.*\s*Module.*Data Provider.*\s*Using.*\s*Hier.*common\"\s*Path.*\s*Orig.*\s*Found key.*module-env4-mod1-hiera/, - result, - "environment env4 mod1::module_key lookup failed." - ) - - step 'apply env1 puppet.conf manifest' - apply_manifest_on(master, @env1puppetconfmanifest, :catch_failures => true) - - step "puppet.conf specified environment env1 environment_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'environment_key')) - result = r.stdout - assert_match( - /env-env1 hiera/, - result, - "puppet.conf specified environment env1, environment_key lookup failed, expected /env-env1 hiera/" - ) - - step "puppet.conf specified environment env1 mod4::module_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'mod4::module_key'), :acceptable_exit_codes => [1]) - - step 'apply env2 puppet.conf manifest' - apply_manifest_on(master, @env2puppetconfmanifest, :catch_failures => true) - - step "puppet.conf specified environment env2 environment_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'environment_key')) - result = r.stdout - assert_match( - /env-env2-ruby-function/, - result, - "puppet.conf specified environment env2, environment_key lookup failed, expected /env-env2-ruby-function/" - ) - - step "puppet.conf specified environment env2 mod3::module_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'mod3::module_key')) - result = r.stdout - assert_match( - /module-env2-mod3-puppet-function/, - result, - "puppet.conf specified environment env2 mod3::module_key lookup failed, expeccted /module-env2-mod3-puppet-function/" - ) - - step 'apply env3 puppet.conf manifest' - apply_manifest_on(master, @env3puppetconfmanifest, :catch_failures => true) - - step "puppet.conf specified environment env3 environment_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'environment_key')) - result = r.stdout - assert_match( - /env-env3-puppet-function/, - result, - "puppet.conf specified environment env1, environment_key lookup failed, expected /env-env3-puppet-function/" - ) - - step "puppet.conf specified environment env3 mod2::module_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'mod2::module_key')) - result = r.stdout - assert_match( - /module-env3-mod2-ruby-function/, - result, - "puppet.conf specified environment env2 mod3::module_key lookup failed, expeccted /module-env3-mod2-ruby-function/" - ) - - step 'apply env4 puppet.conf manifest' - apply_manifest_on(master, @env4puppetconfmanifest, :catch_failures => true) - - step "puppet.conf specified environment env4 environment_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'environment_key'), :acceptable_exit_codes => [1]) - - step "puppet.conf specified environment env4 mod1::module_key" - r = on(master, puppet('lookup', "--confdir #{@confdir}", 'mod1::module_key')) - result = r.stdout - assert_match( - /module-env4-mod1-hiera/, - result, - "puppet.conf specified environment env4 mod1::module_key lookup failed, expeccted /module-env4-mod1-hiera/" - ) - - step 'apply enc manifest' - apply_manifest_on(master, @encmanifest, :catch_failures => true) - - step "--compile uses environment specified in ENC" - r = on(master, puppet('lookup', '--compile', "--node #{@node1}", "--confdir #{@confdir}", "--facts #{@coderoot}/facts.yaml", 'environment_key')) - result = r.stderr - assert_match( - /CA is not available/, - result, - "lookup in ENC specified environment failed" - ) - - step "handle certificate" - on(master, "puppetserver ca generate --certname #{@node1}") - on(master, "puppetserver ca generate --certname #{@node2}") - on(master, "mkdir -p #{@testroot}/puppet/ssl/certs") - on(master, "mkdir -p #{@testroot}/puppet/ssl/private_keys") - on(master, "cp -a /etc/puppetlabs/puppet/ssl/certs/ca.pem #{@testroot}/puppet/ssl/certs") - on(master, "cp -a /etc/puppetlabs/puppet/ssl/crl.pem #{@testroot}/puppet/ssl") - on(master, "cp -a /etc/puppetlabs/puppet/ssl/private_keys/#{master.connection.hostname}.pem #{@testroot}/puppet/ssl/private_keys") - on(master, "cp -a /etc/puppetlabs/puppet/ssl/certs/#{master.connection.hostname}.pem #{@testroot}/puppet/ssl/certs") - - step "--compile uses environment specified in ENC" - r = on(master, puppet('lookup', '--compile', "--node #{@node1}", "--confdir #{@confdir}", "--facts #{@coderoot}/facts.yaml", 'environment_key')) - result = r.stdout - assert_match( - /env-env2-ruby-function/, - result, - "lookup in ENC specified environment failed" - ) - - step "without --compile does not use environment specified in ENC" - r = on(master, puppet('lookup', "--node #{@node1}", "--confdir #{@confdir}", "--facts #{@coderoot}/facts.yaml", 'environment_key')) - result = r.stdout - assert_match( - /env-production hiera provided value/, - result, - "lookup in production environment failed" - ) - - step "lookup fails when there are no facts available" - r = on(master, puppet('lookup', '--compile', "--node #{@node1}", "--confdir #{@confdir}", 'environment_key'), :acceptable_exit_codes => [1]) - result = r.stderr - assert_match( - /No facts available/, - result, - "Expected to raise when there were no facts available." - ) -end diff --git a/acceptance/tests/pluginsync/3935_pluginsync_should_follow_symlinks.rb b/acceptance/tests/pluginsync/3935_pluginsync_should_follow_symlinks.rb deleted file mode 100644 index 40b6e2e83c..0000000000 --- a/acceptance/tests/pluginsync/3935_pluginsync_should_follow_symlinks.rb +++ /dev/null @@ -1,49 +0,0 @@ -test_name "pluginsync should not error when modulepath is a symlink and no modules have plugin directories" - -tag 'audit:high', - 'audit:integration', - 'server' - -step "Create a modulepath directory which is a symlink and includes a module without facts.d or lib directories" -basedir = master.tmpdir("symlink_modulepath") - -target = "#{basedir}/target_dir" -test_module_dir = "#{target}/module1" -link_dest = "#{basedir}/link_dest" -modulepath = "#{link_dest}" -modulepath << "#{master['sitemoduledir']}" if master.is_pe? - -apply_manifest_on(master, < true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{basedir}':; - '#{target}':; - '#{test_module_dir}':; -} - -file { '#{link_dest}': - ensure => link, - target => '#{target}', -} -MANIFEST - -master_opts = { - 'main' => { - 'basemodulepath' => "#{modulepath}" - } -} - -with_puppet_running_on master, master_opts, basedir do - agents.each do |agent| - on(agent, puppet('agent', "-t")) do |result| - refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/pluginfacts/, result.stderr) - refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/plugins/, result.stderr) - end - end -end diff --git a/acceptance/tests/pluginsync/4420_pluginfacts_should_be_resolvable_on_agent.rb b/acceptance/tests/pluginsync/4420_pluginfacts_should_be_resolvable_on_agent.rb deleted file mode 100644 index 1305417b9b..0000000000 --- a/acceptance/tests/pluginsync/4420_pluginfacts_should_be_resolvable_on_agent.rb +++ /dev/null @@ -1,130 +0,0 @@ -test_name "Pluginsync'ed external facts should be resolvable on the agent" do - tag 'audit:high', - 'audit:integration' - -# -# This test is intended to ensure that external facts downloaded onto an agent via -# pluginsync are resolvable. In Linux, the external fact should have the same -# permissions as its source on the master. -# - - step "Create a codedir with a manifest and test module with external fact" - codedir = master.tmpdir('4420-codedir') - - site_manifest_content = < true) -File { - ensure => directory, - mode => "0755", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{codedir}':; - '#{codedir}/environments':; - '#{codedir}/environments/production':; - '#{codedir}/environments/production/manifests':; - '#{codedir}/environments/production/modules':; - '#{codedir}/environments/production/modules/mymodule':; - '#{codedir}/environments/production/modules/mymodule/manifests':; - '#{codedir}/environments/production/modules/mymodule/facts.d':; -} - -file { '#{codedir}/environments/production/manifests/site.pp': - ensure => file, - content => '#{site_manifest_content}', -} - -file { '#{codedir}/environments/production/modules/mymodule/manifests/init.pp': - ensure => file, - content => 'class mymodule {}', -} - -file { '#{codedir}/environments/production/modules/mymodule/facts.d/unix_external_fact.sh': - ensure => file, - mode => '755', - content => '#{unix_fact}', -} -file { '#{codedir}/environments/production/modules/mymodule/facts.d/win_external_fact.bat': - ensure => file, - mode => '644', - content => '#{win_fact}', -} -MANIFEST - - master_opts = { - 'main' => { - 'environmentpath' => "#{codedir}/environments" - } - } - - with_puppet_running_on(master, master_opts, codedir) do - agents.each do |agent| - factsd = agent.tmpdir('facts.d') - pluginfactdest = agent.tmpdir('facts.d') - - teardown do - on(master, "rm -rf '#{codedir}'") - on(agent, "rm -rf '#{factsd}' '#{pluginfactdest}'") - end - - step "Pluginsync the external fact to the agent and ensure it resolves correctly" do - on(agent, puppet('agent', '-t', '--pluginfactdest', factsd), :acceptable_exit_codes => [2]) do |result| - assert_match(/foo is bar/, result.stdout) - end - end - step "Use plugin face to download to the agent" do - on(agent, puppet('plugin', 'download', '--pluginfactdest', pluginfactdest)) do |result| - assert_match(/Downloaded these plugins: .*external_fact/, result.stdout) unless agent['locale'] == 'ja' - end - end - - step "Ensure it resolves correctly" do - on(agent, puppet('apply', '--pluginfactdest', pluginfactdest, '-e', "'notify { \"foo is ${foo}\": }'")) do |result| - assert_match(/foo is bar/, result.stdout) - end - end - # Linux specific tests - next if agent['platform'] =~ /windows/ - - step "In Linux, ensure the pluginsync'ed external fact has the same permissions as its source" do - on(agent, puppet('resource', "file '#{factsd}/unix_external_fact.sh'")) do |result| - assert_match(/0755/, result.stdout) - end - end - step "In Linux, ensure puppet apply uses the correct permissions" do - test_source = File.join('/', 'tmp', 'test') - on(agent, puppet('apply', "-e \"file { '#{test_source}': ensure => file, mode => '0456' }\"")) - - { 'source_permissions => use,' => /0456/, - 'source_permissions => ignore,' => /0644/, - '' => /0644/ - }.each do |source_permissions, mode| - on(agent, puppet('apply', "-e \"file { '/tmp/test_target': ensure => file, #{source_permissions} source => '#{test_source}' }\"")) - on(agent, puppet('resource', "file /tmp/test_target")) do |result| - assert_match(mode, result.stdout) - end - - on(agent, "rm -f /tmp/test_target") - end - end - end - end -end diff --git a/acceptance/tests/pluginsync/4847_pluginfacts_should_be_resolvable_from_applications.rb b/acceptance/tests/pluginsync/4847_pluginfacts_should_be_resolvable_from_applications.rb deleted file mode 100644 index 762ef2516e..0000000000 --- a/acceptance/tests/pluginsync/4847_pluginfacts_should_be_resolvable_from_applications.rb +++ /dev/null @@ -1,70 +0,0 @@ -test_name "Pluginsync'ed custom facts should be resolvable during application runs" do - - tag 'audit:high', - 'audit:integration' - - # - # This test is intended to ensure that custom facts downloaded onto an agent via - # pluginsync are resolvable by puppet applications besides agent/apply. - # - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - tmp_environment = mk_tmp_environment_with_teardown(master, 'resolve') - master_module_dir = "#{environmentpath}/#{tmp_environment}/modules/module_name" - master_type_dir = "#{master_module_dir}/lib/puppet/type" - master_module_type_file = "#{master_type_dir}/test4847.rb" - master_provider_dir = "#{master_module_dir}/lib/puppet/provider/test4847" - master_provider_file = "#{master_provider_dir}/only.rb" - master_facter_dir = "#{master_module_dir}/lib/facter" - master_facter_file = "#{master_facter_dir}/foo.rb" - on(master, "mkdir -p '#{master_type_dir}' '#{master_provider_dir}' '#{master_facter_dir}'") - - teardown do - on(master, "rm -rf '#{master_module_dir}'") - - # Remove all traces of the last used environment - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - test_type = <<-TYPE - Puppet::Type.newtype(:test4847) do - newparam(:name, :namevar => true) - end - TYPE - create_remote_file(master, master_module_type_file, test_type) - - test_provider = <<-PROVIDER - Puppet::Type.type(:test4847).provide(:only) do - def self.instances - warn "fact foo=\#{Facter.value('foo')}" - [] - end - end - PROVIDER - create_remote_file(master, master_provider_file, test_provider) - - foo_fact_content = <<-FACT_FOO - Facter.add('foo') do - setcode do - 'bar' - end - end - FACT_FOO - create_remote_file(master, master_facter_file, foo_fact_content) - on(master, "chmod 755 '#{master_module_type_file}' '#{master_provider_file}' '#{master_facter_file}'") - - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment #{tmp_environment}")) - on(agent, puppet('resource test4847')) do |result| - assert_match(/fact foo=bar/, result.stderr) - end - end - end -end diff --git a/acceptance/tests/pluginsync/7316_apps_should_be_available_via_pluginsync.rb b/acceptance/tests/pluginsync/7316_apps_should_be_available_via_pluginsync.rb deleted file mode 100644 index 13f6836d39..0000000000 --- a/acceptance/tests/pluginsync/7316_apps_should_be_available_via_pluginsync.rb +++ /dev/null @@ -1,109 +0,0 @@ -test_name 'the pluginsync functionality should sync app definitions, and they should be runnable afterwards' do - - tag 'audit:high', - 'audit:integration' - - # - # This test is intended to ensure that pluginsync syncs app definitions to the agents. - # Further, the apps should be runnable on the agent after the sync has occurred. - # - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - tmp_environment = mk_tmp_environment_with_teardown(master, 'app') - master_module_dir = "#{environmentpath}/#{tmp_environment}/modules" - on(master, "mkdir -p '#{master_module_dir}'") - - teardown do - on(master, "rm -rf '#{master_module_dir}'") - - # Remove all traces of the last used environment - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - app_name = "superbogus" - app_desc = "a simple application for testing application delivery via plugin sync" - app_output = "Hello from the #{app_name} application" - - master_module_file_content = <<-HERE -require 'puppet/application' - -class Puppet::Application::#{app_name.capitalize} < Puppet::Application - - def help - <<-HELP - -puppet-#{app_name}(8) -- #{app_desc} -======== - HELP - end - - def main() - puts("#{app_output}") - end -end - HERE - - # here we create a custom app, which basically doesn't do anything except - # for print a hello-world message - # - master_module_app_path = "#{master_module_dir}/#{app_name}/lib/puppet/application" - master_module_app_file = "#{master_module_app_path}/#{app_name}.rb" - on(master, "mkdir -p '#{master_module_app_path}'") - create_remote_file(master, master_module_app_file, master_module_file_content) - on(master, "chmod 755 '#{master_module_app_file}'") - - step "start the master" do - with_puppet_running_on(master, {}) do - agents.each do |agent| - - agent_lib_dir = agent.tmpdir('agent_lib_sync') - agent_module_app_file = "#{agent_lib_dir}/puppet/application/#{app_name}.rb" - teardown do - on(agent, "rm -rf '#{agent_lib_dir}'") - end - - # the module files shouldn't exist on the agent yet because they haven't been synced - step "verify that the module files don't exist on the agent path" do - if file_exists?(agent, agent_module_app_file) - fail_test("app file already exists on agent: '#{agent_module_app_file}'") - end - end - - step "run the agent" do - on(agent, puppet("agent --libdir='#{agent_lib_dir}' --test --environment '#{tmp_environment}'")) do |result| - refute_match( - /The \`source_permissions\` parameter is deprecated/, - result.stderr, - "pluginsync should not get a deprecation warning for source_permissions") - end - end - - step "verify that the module files were synced down to the agent" do - unless file_exists?(agent, agent_module_app_file) - fail_test("The app file we expect was not not synced to agent: '#{agent_module_app_file}'") - end - end - - step "verify that the application shows up in help" do - on(agent, PuppetCommand.new(:help, "--libdir='#{agent_lib_dir}'")) do |result| - assert_match(/^\s+#{app_name}\s+#{app_desc}/, result.stdout) - end - end - - step "verify that we can run the application" do - on(agent, PuppetCommand.new(:"#{app_name}", "--libdir='#{agent_lib_dir}'")) do |result| - assert_match(/^#{app_output}/, result.stdout) - end - end - end - end - end -end diff --git a/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb b/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb deleted file mode 100644 index ee632dc69e..0000000000 --- a/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb +++ /dev/null @@ -1,167 +0,0 @@ -test_name "the pluginsync functionality should sync app definitions, and they should be runnable afterwards" - -tag 'audit:high', - 'audit:integration', - 'server' - -# -# This test is intended to ensure that pluginsync syncs face definitions to the agents. -# Further, the face should be runnable on the agent after the sync has occurred. -# -# (NOTE: When this test is passing, it should resolve both #7316 re: verifying that apps/faces can -# be run on the agent node after a plugin sync, and #6753 re: being able to run a face without -# having a placeholder stub file in the "applications" directory.) -# - -require 'puppet/acceptance/temp_file_utils' - -extend Puppet::Acceptance::TempFileUtils - -initialize_temp_dirs() -all_tests_passed = false - -############################################################################### -# BEGIN TEST LOGIC -############################################################################### - -# create some vars to point to the directories that we're going to point the master/agents at -environments_dir = "environments" -master_module_dir = "#{environments_dir}/production/modules" -agent_lib_dir = "agent_lib" - -app_name = "superbogus" -app_desc = "a simple %1$s for testing %1$s delivery via plugin sync" -app_output = "Hello from the #{app_name} %s" - -master_module_face_content = <<-HERE -Puppet::Face.define(:#{app_name}, '0.0.1') do - copyright "Puppet Labs", 2011 - license "Apache 2 license; see COPYING" - - summary "#{app_desc % "face"}" - - action(:foo) do - summary "a test action defined in the test face in the main puppet lib dir" - - default - when_invoked do |*args| - puts "#{app_output % "face"}" - end - end - -end -HERE - -master_module_app_content = <<-HERE -require 'puppet/application/face_base' - -class Puppet::Application::#{app_name.capitalize} < Puppet::Application::FaceBase -end - -HERE - -# this begin block is here for handling temp file cleanup via an "ensure" block -# at the very end of the test. -begin - - # here we create a custom app, which basically doesn't do anything except for - # print a hello-world message - agent_module_face_file = "#{agent_lib_dir}/puppet/face/#{app_name}.rb" - master_module_face_file = "#{master_module_dir}/#{app_name}/lib/puppet/face/#{app_name}.rb" - - agent_module_app_file = "#{agent_lib_dir}/puppet/application/#{app_name}.rb" - master_module_app_file = "#{master_module_dir}/#{app_name}/lib/puppet/application/#{app_name}.rb" - - # copy all the files to the master - step "write our simple module out to the master" do - create_test_file(master, master_module_app_file, master_module_app_content, :mkdirs => true) - create_test_file(master, master_module_face_file, master_module_face_content, :mkdirs => true) - end - - step "verify that the app file exists on the master" do - unless test_file_exists?(master, master_module_app_file) then - fail_test("Failed to create app file '#{get_test_file_path(master, master_module_app_file)}' on master") - end - unless test_file_exists?(master, master_module_face_file) then - fail_test("Failed to create face file '#{get_test_file_path(master, master_module_face_file)}' on master") - end - end - - master_opts = { - 'main' => { - 'environmentpath' => "#{get_test_file_path(master, environments_dir)}", - } - } - - step "start the master" do - with_puppet_running_on master, master_opts do - - # the module files shouldn't exist on the agent yet because they haven't been synced - step "verify that the module files don't exist on the agent path" do - agents.each do |agent| - if test_file_exists?(agent, agent_module_app_file) then - fail_test("app file already exists on agent: '#{get_test_file_path(agent, agent_module_app_file)}'") - end - if test_file_exists?(agent, agent_module_app_file) then - fail_test("face file already exists on agent: '#{get_test_file_path(agent, agent_module_face_file)}'") - end - end - end - - step "run the agent" do - agents.each do |agent| - on(agent, puppet('agent', - "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\" ", - "--trace --test") - ) - end - end - - end - end - - step "verify that the module files were synced down to the agent" do - agents.each do |agent| - unless test_file_exists?(agent, agent_module_app_file) then - fail_test("The app file we expected was not synced to the agent: '#{get_test_file_path(agent, agent_module_app_file)}'") - end - unless test_file_exists?(agent, agent_module_face_file) then - fail_test("The face file we expected was not not synced to the agent: '#{get_test_file_path(agent, agent_module_face_file)}'") - end - end - end - - step "verify that the application shows up in help" do - agents.each do |agent| - on(agent, PuppetCommand.new(:help, "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do |result| - assert_match(/^\s+#{app_name}\s+#{app_desc % "face"}/, result.stdout) - end - end - end - - step "verify that we can run the application" do - agents.each do |agent| - on(agent, PuppetCommand.new(:"#{app_name}", "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do |result| - assert_match(/^#{app_output % "face"}/, result.stdout) - end - end - end - - step "clear out the libdir on the agents in preparation for the next test" do - agents.each do |agent| - on(agent, "rm -rf #{get_test_file_path(agent, agent_lib_dir)}/*") - end - end - - all_tests_passed = true - -ensure - ########################################################################################## - # Clean up all of the temp files created by this test. It would be nice if this logic - # could be handled outside of the test itself; I envision a stanza like this one appearing - # in a very large number of the tests going forward unless it is handled by the framework. - ########################################################################################## - if all_tests_passed then - remove_temp_dirs() - end -end diff --git a/acceptance/tests/pluginsync/feature/pluginsync_should_sync_features.rb b/acceptance/tests/pluginsync/feature/pluginsync_should_sync_features.rb deleted file mode 100644 index 0e73c46de8..0000000000 --- a/acceptance/tests/pluginsync/feature/pluginsync_should_sync_features.rb +++ /dev/null @@ -1,174 +0,0 @@ -test_name "the pluginsync functionality should sync feature and function definitions" do - - tag 'audit:high', - 'audit:integration' - - # - # This test is intended to ensure that pluginsync syncs feature definitions to - # the agents. It checks the feature twice; once to make sure that it gets - # loaded successfully during the run in which it was synced, and once to ensure - # that it still gets loaded successfully during the subsequent run (in which it - # should not be synced because the files haven't changed.) - # - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - teardown do - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - - module_name = 'superbogus' - tmp_environment = mk_tmp_environment_with_teardown(master, 'sync') - master_module_dir = "#{environmentpath}/#{tmp_environment}/modules" - master_module_type_path = "#{master_module_dir}/#{module_name}/lib/puppet/type/" - master_module_feature_path = "#{master_module_dir}/#{module_name}/lib/puppet/feature" - master_module_function_path = "#{master_module_dir}/#{module_name}/lib/puppet/functions" - master_module_function_path_namespaced = "#{master_module_dir}/#{module_name}/lib/puppet/functions/superbogus" - on(master, "mkdir -p '#{master_module_dir}'") - on(master, "mkdir -p '#{master_module_type_path}' '#{master_module_feature_path}' '#{master_module_function_path}' #{master_module_function_path_namespaced}") - - master_module_type_file = "#{master_module_type_path}/#{module_name}.rb" - master_module_type_content = <<-HERE - module Puppet - Type.newtype(:#{module_name}) do - newparam(:name) do - isnamevar - end - - newproperty(:testfeature) do - def sync - Puppet.info("The value of the #{module_name} feature is: \#{Puppet.features.#{module_name}?}") - end - def retrieve - :absent - end - def insync?(is) - false - end - end - end - end - HERE - create_remote_file(master, master_module_type_file, master_module_type_content) - - master_module_feature_file = "#{master_module_feature_path}/#{module_name}.rb" - master_module_feature_content = <<-HERE - Puppet.features.add(:#{module_name}) do - Puppet.info("#{module_name} feature being queried") - true - end - HERE - create_remote_file(master, master_module_feature_file, master_module_feature_content) - on(master, "chmod 755 '#{master_module_type_file}' '#{master_module_feature_file}'") - - master_module_function_file = "#{master_module_function_path}/bogus_function.rb" - master_module_function_content = <<-HERE - Puppet::Functions.create_function(:bogus_function) do - dispatch :bogus_function do - end - def bogus_function() - three = call_function('round', 3.14) - hostname = `facter hostname` - "Three is \#{three}. bogus_function reporting hostname is \#{hostname}" - end - end - HERE - create_remote_file(master, master_module_function_file, master_module_function_content) - on(master, "chmod 755 '#{master_module_function_file}' '#{master_module_function_file}'") - - master_module_namespaced_function_file = "#{master_module_function_path_namespaced}/bogus_function2.rb" - master_module_namespaced_function_content = <<-HERE - Puppet::Functions.create_function(:'superbogus::bogus_function2') do - dispatch :bogus_function2 do - end - def bogus_function2() - four = call_function('round', 4.14) - hostname = `facter hostname` - "Four is \#{four}. bogus_function reporting hostname is \#{hostname}" - end - end - HERE - create_remote_file(master, master_module_namespaced_function_file, master_module_namespaced_function_content) - on(master, "chmod 755 '#{master_module_namespaced_function_file}'") - - site_pp = <<-HERE - #{module_name} { "This is the title of the #{module_name} type instance in site.pp": - testfeature => "Hi. I'm setting the testfeature property of #{module_name} here in site.pp", - } - notify { module_function: - message => Deferred('bogus_function', []) - } - notify { module_function2: - message => Deferred('superbogus::bogus_function2', []) - } - HERE - create_sitepp(master, tmp_environment, site_pp) - - # These master opts should not be necessary whence content negotation for - # Puppet 6.0.0 is completed, and this should just be removed. - master_opts = { - 'master' => { - 'rich_data' => 'true' - } - } - - step 'start the master' do - with_puppet_running_on(master, master_opts) do - agents.each do |agent| - agent_lib_dir = agent.tmpdir('libdir') - agent_module_type_file = "#{agent_lib_dir}/puppet/type/#{module_name}.rb" - agent_module_feature_file = "#{agent_lib_dir}/puppet/feature/#{module_name}.rb" - agent_module_function_file = "#{agent_lib_dir}/puppet/functions/bogus_function.rb" - agent_module_namespaced_function_file = "#{agent_lib_dir}/puppet/functions/superbogus/bogus_function2.rb" - - facter_hostname = fact_on(agent, 'hostname') - step "verify that the module files don't exist on the agent path" do - [agent_module_type_file, agent_module_feature_file, agent_module_function_file].each do |file_path| - if file_exists?(agent, file_path) - fail_test("file should not exist on the agent yet: '#{file_path}'") - end - end - end - - step 'run the agent and verify that it loaded the feature' do - on(agent, puppet("agent -t --libdir='#{agent_lib_dir}' --rich_data --environment '#{tmp_environment}'"), - :acceptable_exit_codes => [2]) do |result| - assert_match(/The value of the #{module_name} feature is: true/, result.stdout, - "Expected agent stdout to include confirmation that the feature was 'true'") - assert_match(/Three is 3. bogus_function reporting hostname is #{facter_hostname}/, result.stdout, - "Expect the agent stdout to run bogus_function and report hostname") - assert_match(/Four is 4. bogus_function reporting hostname is #{facter_hostname}/, result.stdout, - "Expect the agent stdout to run bogus_function and report hostname") - end - end - - step 'verify that the module files were synced down to the agent' do - [agent_module_type_file, agent_module_feature_file, agent_module_function_file, agent_module_namespaced_function_file].each do |file_path| - unless file_exists?(agent, file_path) - fail_test("Expected file to exist on the agent now: '#{file_path}'") - end - end - end - - step 'run the agent again with a cached catalog' do - on(agent, puppet("agent -t --libdir='#{agent_lib_dir}' --use_cached_catalog --rich_data --environment '#{tmp_environment}'"), :acceptable_exit_codes => [2]) do |result| - assert_match(/The value of the #{module_name} feature is: true/, result.stdout, - "Expected agent stdout to include confirmation that the feature was 'true'") - assert_match(/Three is 3. bogus_function reporting hostname is #{facter_hostname}/, result.stdout, - "Expect the agent stdout to run bogus_function and report hostname") - assert_match(/Four is 4. bogus_function reporting hostname is #{facter_hostname}/, result.stdout, - "Expect the agent stdout to run bogus_function and report hostname") - end - end - end - end - end -end diff --git a/acceptance/tests/pluginsync/files_earlier_in_modulepath_take_precendence.rb b/acceptance/tests/pluginsync/files_earlier_in_modulepath_take_precendence.rb deleted file mode 100644 index 2dacd0ffb3..0000000000 --- a/acceptance/tests/pluginsync/files_earlier_in_modulepath_take_precendence.rb +++ /dev/null @@ -1,69 +0,0 @@ -test_name "earlier modules take precendence over later modules in the modulepath" - -tag 'audit:high', - 'audit:integration', - 'server' - -step "Create some modules in the modulepath" -basedir = master.tmpdir("module_precedence") - -module_dir1 = "#{basedir}/environments/production/modules1" -module_dir2 = "#{basedir}/modules2" -modulepath = "#{module_dir1}:#{module_dir2}" -modulepath << ":#{master['sitemoduledir']}" if master.is_pe? - -apply_manifest_on(master, < true) -File { - ensure => directory, - mode => "0750", - owner => #{master.puppet['user']}, - group => #{master.puppet['group']}, -} - -file { - '#{basedir}':; - '#{module_dir2}':; - '#{module_dir2}/a':; - '#{module_dir2}/a/lib':; - '#{basedir}/environments':; - '#{basedir}/environments/production':; - '#{module_dir1}':; - '#{module_dir1}/a':; - '#{module_dir1}/a/lib':; -} - -file { '#{basedir}/environments/production/environment.conf': - ensure => file, - content => "modulepath='#{modulepath}'", - mode => "0640", -} - -file { "mod1": - ensure => file, - path => "#{module_dir1}/a/lib/foo.rb", - content => "'from the first module'", - mode => "0640", -} - -file { "mod2": - ensure => file, - path => "#{module_dir2}/a/lib/foo.rb", - content => "'from the second module'", - mode => "0640", -} -MANIFEST - -master_opts = { - 'main' => { - 'environmentpath' => "#{basedir}/environments", - } -} - -with_puppet_running_on master, master_opts, basedir do - agents.each do |agent| - on(agent, puppet('agent', "-t")) - on(agent, "cat \"#{agent.puppet['vardir']}/lib/foo.rb\"") do |result| - assert_match(/from the first module/, result.stdout, "The synced plugin was not found or the wrong version was synced") - end - end -end diff --git a/acceptance/tests/provider/package/apt_install_package_with_range.rb b/acceptance/tests/provider/package/apt_install_package_with_range.rb deleted file mode 100644 index daa1f39a0d..0000000000 --- a/acceptance/tests/provider/package/apt_install_package_with_range.rb +++ /dev/null @@ -1,43 +0,0 @@ -test_name "apt can install range if package is not installed" do - confine :to, :platform => /debian|ubuntu/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = "helloworld" - available_package_versions = ['1.0-1', '1.19-1', '2.0-1'] - repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'debian-repo') - - agents.each do |agent| - scp_to(agent, repo_fixture_path, '/tmp') - - file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'present', content: 'deb [trusted=yes] file:/tmp/debian-repo ./') - apply_manifest_on(agent, file_manifest) - - on(agent, 'apt-get update') - - teardown do - package_absent(agent, package, '--force-yes') - file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'absent') - apply_manifest_on(agent, file_manifest) - on(agent, 'rm -rf /tmp/debian-repo') - on(agent, 'apt-get update') - end - - step "Ensure that package is installed first if not present" do - package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}") - apply_manifest_on(agent, package_manifest) - installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout - assert_match(available_package_versions[1], installed_package_version) - end - - step "Ensure that package is updated" do - package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}") - apply_manifest_on(agent, package_manifest) - installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout - assert_match(available_package_versions[2], installed_package_version) - end - end -end diff --git a/acceptance/tests/provider/package/dnfmodule_enable_only.rb b/acceptance/tests/provider/package/dnfmodule_enable_only.rb deleted file mode 100644 index ddf3fd571d..0000000000 --- a/acceptance/tests/provider/package/dnfmodule_enable_only.rb +++ /dev/null @@ -1,42 +0,0 @@ -test_name "dnfmodule can change flavors" do - confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - without_profile = '389-ds' - with_profile = 'swig' - - agents.each do |agent| - skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream') - teardown do - apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'absent', provider: 'dnfmodule')) - apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'absent', provider: 'dnfmodule')) - end - end - - step "Enable module with no default profile: #{without_profile}" do - apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), expect_changes: true) - on(agent, "dnf module list --enabled | grep #{without_profile}") - end - - step "Ensure idempotency for: #{without_profile}" do - apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), catch_changes: true) - end - - step "Enable module with a profile: #{with_profile}" do - apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), expect_changes: true) - on(agent, "dnf module list --enabled | grep #{with_profile}") - end - - step "Ensure idempotency for: #{with_profile}" do - apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), catch_changes: true) - end - - step "Install a flavor for: #{with_profile}" do - apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', flavor: 'common', provider: 'dnfmodule'), expect_changes: true) - on(agent, "dnf module list --installed | grep #{with_profile}") - end -end diff --git a/acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb b/acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb deleted file mode 100644 index 6737f563bd..0000000000 --- a/acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb +++ /dev/null @@ -1,41 +0,0 @@ -test_name "dnfmodule is versionable" do - confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - - package = "postgresql" - - agents.each do |agent| - skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream') - teardown do - apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule')) - end - end - - step "Ensure we get the newer version by default" do - apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', provider: 'dnfmodule')) - on(agent, 'postgres --version') do |version| - assert_match('postgres (PostgreSQL) 10', version.stdout, 'package version not correct') - end - end - - step "Ensure we get a specific version if we want it" do - apply_manifest_on(agent, resource_manifest('package', package, ensure: '9.6', provider: 'dnfmodule')) - on(agent, 'postgres --version') do |version| - assert_match('postgres (PostgreSQL) 9.6', version.stdout, 'package version not correct') - end - end - - step "Ensure we can disable a package" do - apply_manifest_on(agent, resource_manifest('package', package, ensure: :disabled, provider: 'dnfmodule')) - on(agent, "dnf module list | grep #{package}") do |output| - output.stdout.each_line do |line| - assert_match("\[x\]", line, 'package not disabled') - end - end - end -end diff --git a/acceptance/tests/provider/package/dnfmodule_manages_flavors.rb b/acceptance/tests/provider/package/dnfmodule_manages_flavors.rb deleted file mode 100644 index 2658beaab7..0000000000 --- a/acceptance/tests/provider/package/dnfmodule_manages_flavors.rb +++ /dev/null @@ -1,31 +0,0 @@ -test_name "dnfmodule can change flavors" do - confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = "postgresql" - - agents.each do |agent| - skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream') - teardown do - apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule')) - end - end - - step "Install the client #{package} flavor" do - apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'client', provider: 'dnfmodule')) - on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output| - assert_match('client [i]', output.stdout, 'installed flavor not correct') - end - end - - step "Install the server #{package} flavor" do - apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'server', provider: 'dnfmodule')) - on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output| - assert_match('server [i]', output.stdout, 'installed flavor not correct') - end - end -end diff --git a/acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb b/acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb deleted file mode 100644 index ffd3f7d806..0000000000 --- a/acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb +++ /dev/null @@ -1,47 +0,0 @@ -test_name "dpkg ensure latest with allow_virtual set to true, the virtual package should detect and install a real package" do - confine :to, :platform => /debian/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - pkg = "rubygems" - - agents.each do |agent| - ruby_present = on(agent, 'dpkg -s ruby', accept_all_exit_codes: true).exit_code == 0 - - teardown do - if ruby_present - apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'present')) - else - apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent')) - end - end - - step "Uninstall system ruby if already present" do - apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent')) if ruby_present - end - - step "Ensure latest should install ruby instead of rubygems when allow_virtual is set to true" do - package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true) - apply_manifest_on(agent, package_manifest_with_allow_virtual, expect_changes: true) - - output = on(agent, "dpkg-query -W --showformat='${Status} ${Package} ${Version} [${Provides}]\n' ").output - lines = output.split("\n") - matched_line = lines.find { |package| package.match(/[\[ ](#{Regexp.escape(pkg)})[\],]/)} - - package_line_info = matched_line.split - real_package_name = package_line_info[3] - real_package_installed_version = package_line_info[4] - - installed_version = on(agent, "apt-cache policy #{real_package_name} | sed -n -e 's/Installed: //p'").stdout.strip - assert_match(real_package_installed_version, installed_version) - end - - step "Ensure latest should not install ruby package if it's already installed and exit code should be 0" do - package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true) - apply_manifest_on(agent, package_manifest_with_allow_virtual, :catch_changes => true) - end - end -end diff --git a/acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb b/acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb deleted file mode 100644 index 052b7932a4..0000000000 --- a/acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb +++ /dev/null @@ -1,27 +0,0 @@ -test_name "dpkg ensure hold package is latest installed" do - confine :to, :platform => /debian-9-amd64/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - - package = "nginx" - - agents.each do |agent| - teardown do - package_absent(agent, package, '--force-yes') - end - end - - step"Ensure that package is installed first if not present" do - expected_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Candidate: //p'").stdout - package_manifest = resource_manifest('package', package, mark: "hold") - - apply_manifest_on(agent, package_manifest) do |result| - installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout - assert_match(expected_package_version, installed_package_version) - end - end -end diff --git a/acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb b/acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb deleted file mode 100644 index 4d7dd8d73f..0000000000 --- a/acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb +++ /dev/null @@ -1,22 +0,0 @@ -test_name "dpkg ensure hold package should preserve version if package is already installed" do - confine :to, :platform => /debian-9-amd64/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = "openssl" - - step "Ensure hold should lock to specific installed version" do - existing_installed_version = on(agent.name, "dpkg -s #{package} | sed -n -e 's/Version: //p'").stdout - existing_installed_version.delete!(' ') - - package_manifest_hold = resource_manifest('package', package, mark: "hold") - apply_manifest_on(agent, package_manifest_hold) do - installed_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout - installed_version.delete!(' ') - assert_match(existing_installed_version, installed_version) - end - end -end diff --git a/acceptance/tests/provider/package/gem.rb b/acceptance/tests/provider/package/gem.rb deleted file mode 100644 index 0386582163..0000000000 --- a/acceptance/tests/provider/package/gem.rb +++ /dev/null @@ -1,114 +0,0 @@ -test_name "gem provider should install and uninstall" do - confine :to, :template => /centos-7-x86_64|redhat-7-x86_64/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = 'colorize' - - agents.each do |agent| - # On a Linux host with only the 'agent' role, the puppet command fails when another Ruby is installed earlier in the PATH: - # - # [root@agent ~]# env PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin" puppet apply -e ' notify { "Hello": }' - # Activating bundler (2.0.2) failed: - # Could not find 'bundler' (= 2.0.2) among 5 total gem(s) - # To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'` - # - # Magically, the puppet command succeeds on a Linux host with both the 'master' and 'agent' roles. - # - # Puppet's Ruby makes a fine target. Unfortunately, it's first in the PATH on Windows: PUP-6134. - # Also, privatebindir isn't a directory on Windows, it's a PATH: - # https://github.com/puppetlabs/beaker-puppet/blob/master/lib/beaker-puppet/install_utils/aio_defaults.rb - # - # These tests depend upon testing being confined to /centos-7-x86_64|redhat-7-x86_64/. - if agent['roles'].include?('master') - original_path = agent.get_env_var('PATH').split('=').last - - # https://github.com/puppetlabs/puppet-agent/blob/master/resources/files/puppet-agent.sh - puppet_agent_sh_path = '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin' - - system_gem_command = '/usr/bin/gem' - - teardown do - step "Teardown: Uninstall System Ruby, and reset PATH" do - package_absent(agent, 'ruby') - agent.clear_env_var('PATH') - agent.add_env_var('PATH', original_path) - end - end - - step "Setup: Install System Ruby, and set PATH to place System Ruby ahead of Puppet Ruby" do - package_present(agent, 'ruby') - agent.add_env_var('PATH', puppet_agent_sh_path) - end - - step "Install a gem package in System Ruby" do - package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem' } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{system_gem_command} list").stdout - assert_match(/#{package} \(/, list) - end - on(agent, "#{system_gem_command} uninstall #{package}") - end - - step "Uninstall a gem package in System Ruby" do - on(agent, "/usr/bin/gem install #{package}") - package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem' } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{system_gem_command} list").stdout - refute_match(/#{package} \(/, list) - end - on(agent, "#{system_gem_command} uninstall #{package}") - end - - step "Uninstall System Ruby, and reset PATH" do - package_absent(agent, 'ruby') - agent.add_env_var('PATH', original_path) - end - end - - puppet_gem_command = "#{agent['privatebindir']}/gem" - - step "Install a gem package with a target command" do - package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem', command: puppet_gem_command } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{puppet_gem_command} list").stdout - assert_match(/#{package} \(/, list) - end - on(agent, "#{puppet_gem_command} uninstall #{package}") - end - - step "Install a gem package in a certain min max range" do - package_manifest1 = resource_manifest('package', package, { ensure: '>0.5 <0.7', provider: 'gem' } ) - package_manifest2 = resource_manifest('package', package, { ensure: '>0.7 <0.8.1', provider: 'gem' } ) - - # Install package (with version between 0.5 and 0.7) - apply_manifest_on(agent, package_manifest1, :expect_changes => true) do - list = on(agent, "#{puppet_gem_command} list").stdout - assert_match(/#{package} \((0.6.0)\)/, list) - end - - # Reapply same manifest and expect no changes - apply_manifest_on(agent, package_manifest1, :catch_changes => true) - - # Install besides existing package (with version between 0.7 and 0.8.1) and expect changes - apply_manifest_on(agent, package_manifest2, :expect_changes => true) do - list = on(agent, "#{puppet_gem_command} list").stdout - assert_match(/#{package} \((0.8.0, 0.6.0)\)/, list) - end - on(agent, "#{puppet_gem_command} uninstall #{package} --all") - end - - step "Uninstall a gem package with a target command" do - on(agent, "#{puppet_gem_command} install #{package}") - package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem', command: puppet_gem_command } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{puppet_gem_command} list").stdout - refute_match(/#{package} \(/, list) - end - on(agent, "#{puppet_gem_command} uninstall #{package}") - end - end -end diff --git a/acceptance/tests/provider/package/pip.rb b/acceptance/tests/provider/package/pip.rb deleted file mode 100644 index d1113198b0..0000000000 --- a/acceptance/tests/provider/package/pip.rb +++ /dev/null @@ -1,81 +0,0 @@ -test_name "pip provider should install, use install_options with latest, and uninstall" do - confine :to, :template => /centos/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = 'colorize' - pip_command = 'pip' - - teardown do - on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes", :accept_all_exit_codes => true) - end - - agents.each do |agent| - step "Setup: Install EPEL Repository, Python and Pip" do - package_present(agent, 'epel-release') - if agent.platform =~ /el-8/ - package_present(agent, 'python2') - package_present(agent, 'python2-pip') - pip_command = 'pip2' - else - package_present(agent, 'python') - package_present(agent, 'python-pip') - end - end - - step "Ensure presence of a pip package" do - package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'pip' } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout - assert_match(/#{package} \(/, list) - end - on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes") - end - - step "Install a pip package using version range" do - package_manifest1 = resource_manifest('package', package, { ensure: '<=1.1.0', provider: 'pip' } ) - package_manifest2 = resource_manifest('package', package, { ensure: '<1.0.4', provider: 'pip' } ) - - # Make a fresh package install (with version lower than or equal to 1.1.0) - apply_manifest_on(agent, package_manifest1, :expect_changes => true) do - list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout - match = list.match(/#{package} \((.+)\)/) - installed_version = match[1] if match - assert_match(installed_version, '1.1.0') - end - - # Reapply same manifest and expect no changes - apply_manifest_on(agent, package_manifest1, :catch_changes => true) - - # Reinstall over existing package (with version lower than 1.0.4) and expect changes (to be 1.0.3) - apply_manifest_on(agent, package_manifest2, :expect_changes => true) do - list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout - match = list.match(/#{package} \((.+)\)/) - installed_version = match[1] if match - assert_match(installed_version, '1.0.3') - end - - on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes") - end - - step "Ensure latest with pip uses install_options" do - on(agent, "#{pip_command} install #{package} --disable-pip-version-check") - package_manifest = resource_manifest('package', package, { ensure: 'latest', provider: 'pip', install_options: { '--index' => 'https://pypi.python.org/simple' } } ) - result = apply_manifest_on(agent, package_manifest, { :catch_failures => true, :debug => true } ) - assert_match(/--index=https:\/\/pypi.python.org\/simple/, result.stdout) - on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes") - end - - step "Uninstall a pip package" do - on(agent, "#{pip_command} install #{package} --disable-pip-version-check") - package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'pip' } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout - refute_match(/#{package} \(/, list) - end - end - end -end diff --git a/acceptance/tests/provider/package/puppetserver_gem.rb b/acceptance/tests/provider/package/puppetserver_gem.rb index d1aaa1f887..c8501f91bb 100644 --- a/acceptance/tests/provider/package/puppetserver_gem.rb +++ b/acceptance/tests/provider/package/puppetserver_gem.rb @@ -14,11 +14,14 @@ # Ensure the gem is uninstalled if anything goes wrong # TODO maybe execute this only if something fails, as it takes time on(master, "puppetserver gem uninstall #{package}") + on(master, "puppetserver gem env") + on(master, "puppetserver gem list --local") + on(master, "/opt/puppetlabs/puppet/bin/gem list --local") end step "Installing a gem executes without error" do package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'puppetserver_gem' } ) - apply_manifest_on(master, package_manifest, catch_failures: true) do + apply_manifest_on(master, package_manifest, catch_failures: true, trace: true, debug: true) do list = on(master, "puppetserver gem list").stdout assert_match(/#{package} \(/, list) end diff --git a/acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb b/acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb deleted file mode 100644 index b35550b018..0000000000 --- a/acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb +++ /dev/null @@ -1,82 +0,0 @@ -test_name "rpm should install packages with multiple versions" do - confine :to, :platform => /redhat|centos|el|fedora/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = "kernel-devel-puppet" - repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'el-repo') - - repo_content = <<-REPO -[local] -name=EL-releasever - test packages -baseurl=file:///tmp/el-repo -enabled=1 -gpgcheck=0 -protect=1 -REPO - - agents.each do |agent| - initially_installed_versions = [] - scp_to(agent, repo_fixture_path, '/tmp') - - file_manifest = resource_manifest('file', '/etc/yum.repos.d/local.repo', ensure: 'present', content: repo_content) - apply_manifest_on(agent, file_manifest) - - teardown do - on(agent, 'rm -rf /tmp/el-repo') - on(agent, 'rm -f /etc/yum.repos.d/local.repo') - - available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout - initially_installed_versions.each do |version| - if available_versions.include? version - package_manifest = resource_manifest('package', package, ensure: version, install_only: true) - apply_manifest_on(agent, package_manifest, :catch_failures => true) - end - end - end - - step "Uninstall package versions for clean setup" do - initially_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout.split("\n") - - package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout - assert(remaining_installed_versions.empty?) - end - - available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout.split("\n") - if available_versions.size < 2 - skip_test "we need at least two package versions to perform the multiversion rpm test" - end - end - - step "Ensure oldest version of multiversion package is installed" do - oldest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | head -1 | awk '{print $2}'").stdout.strip - package_manifest = resource_manifest('package', package, ensure: oldest_version, install_only: true) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - installed_version = on(agent, "rpm -q #{package}").stdout - assert_match(oldest_version, installed_version) - end - end - - step "Ensure newest package multiversion package in installed" do - newest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | tail -1 | awk '{print $2}'").stdout.strip - package_manifest = resource_manifest('package', package, ensure: newest_version, install_only: true) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - installed_version = on(agent, "rpm -q #{package}").stdout - assert_match(newest_version, installed_version) - end - end - - step "Ensure rpm will uninstall multiversion package" do - package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout - assert(remaining_installed_versions.empty?) - end - end - end -end diff --git a/acceptance/tests/provider/package/yum_semantic_versioning.rb b/acceptance/tests/provider/package/yum_semantic_versioning.rb deleted file mode 100644 index d6fee439fc..0000000000 --- a/acceptance/tests/provider/package/yum_semantic_versioning.rb +++ /dev/null @@ -1,66 +0,0 @@ -test_name "yum provider should use semantic versioning for ensuring desired version" do - confine :to, :platform => /el-7/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = 'yum-utils' - - lower_package_version = '1.1.31-34.el7' - middle_package_version = '1.1.31-42.el7' - higher_package_version = '1.1.31-45.el7' - - agents.each do |agent| - yum_command = 'yum' - - step "Setup: Skip test if box already has the package installed" do - on(agent, "rpm -q #{package}", :acceptable_exit_codes => [1,0]) do |result| - skip_test "package #{package} already installed on this box" unless result.output =~ /package #{package} is not installed/ - end - end - - step "Setup: Skip test if package versions are not available" do - on(agent, "yum list #{package} --showduplicates", :acceptable_exit_codes => [1,0]) do |result| - versions_available = [lower_package_version, middle_package_version, higher_package_version].all? { - |needed_versions| result.output.include? needed_versions } - skip_test "package #{package} versions not available on the box" unless versions_available - end - end - - step "Using semantic versioning to downgrade to a desired version <= X" do - on(agent, "#{yum_command} install #{package} -y") - package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } ) - apply_manifest_on(agent, package_manifest, :catch_failures => true) do - installed_version = on(agent, "rpm -q #{package}").stdout - assert_match(/#{lower_package_version}/, installed_version) - end - # idempotency test - package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } ) - apply_manifest_on(agent, package_manifest, :catch_changes => true) - on(agent, "#{yum_command} remove #{package} -y") - end - - step "Using semantic versioning to ensure a version >X <=Y" do - on(agent, "#{yum_command} install #{package} -y") - package_manifest = resource_manifest('package', package, { ensure: ">#{lower_package_version} <=#{higher_package_version}", provider: 'yum' } ) - apply_manifest_on(agent, package_manifest) do - installed_version = on(agent, "rpm -q #{package}").stdout - assert_match(/#{higher_package_version}/, installed_version) - end - on(agent, "#{yum_command} remove #{package} -y") - end - - step "Using semantic versioning to install a version >X #{lower_package_version} <#{higher_package_version}", provider: 'yum' } ) - # installing a version >X /sles/ - tag 'audit:high' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::PackageUtils - extend Puppet::Acceptance::ManifestUtils - - package = "helloworld" - available_package_versions = ['1.0-2', '1.19-2', '2.0-2'] - repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'sles-repo') - repo_content = <<-REPO -[local] -name=local - test packages -baseurl=file:///tmp/sles-repo -enabled=1 -gpgcheck=0 -REPO - - agents.each do |agent| - scp_to(agent, repo_fixture_path, '/tmp') - - file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'present', content: repo_content) - apply_manifest_on(agent, file_manifest) - - teardown do - package_absent(agent, package, '--force-yes') - file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'absent') - apply_manifest_on(agent, file_manifest) - on(agent, 'rm -rf /tmp/sles-repo') - end - - step "Ensure that package is installed first if not present" do - package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}") - apply_manifest_on(agent, package_manifest) - installed_package_version = on(agent, "rpm -q #{package}").stdout - assert_match(available_package_versions[1], installed_package_version) - end - - step "Ensure that package is updated" do - package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}") - apply_manifest_on(agent, package_manifest) - installed_package_version = on(agent, "rpm -q #{package}").stdout - assert_match(available_package_versions[2], installed_package_version) - end - end -end diff --git a/acceptance/tests/r10k.rb b/acceptance/tests/r10k.rb deleted file mode 100644 index 9619649dc9..0000000000 --- a/acceptance/tests/r10k.rb +++ /dev/null @@ -1,23 +0,0 @@ -# This test ONLY checks if r10k is executable without gem version conflicts, -# due to running into problems here with gem version bumps in puppet-runtime. -# It does not test r10k functionality itself. -test_name 'Can install and execute r10k with no gem conflicts' - -# On pre-8.23.0, we already had fast_gettext installed to the -# /opt/puppetlabs/puppet/lib/ruby/vendor_gems/gems directory, so -# when r10k was installed, it would not install fast_gettext to -# /opt/puppetlabs/puppet/lib/ruby/gems/3.2.0/gems. Then, upon agent -# upgrade, that version in vendor_gems was replaced with 4.1.0 and -# since r10k has a dependency on gettext-setup which pins -# fast_gettext to ~> 2.1, it would fail. Below simulates -# this condition by removing any fast_gettext installed automatically -# via 'gem install r10k'. -# -# To test this more robustly, we'll want to implement this test in an upgrade -# test suite instead. -on(master, '/opt/puppetlabs/puppet/bin/gem install r10k') -on(master, 'rm -rf "/opt/puppetlabs/puppet/lib/ruby/gems/3.2.0/gems/fast_gettext*"') -on(master, 'rm -f /opt/puppetlabs/puppet/lib/ruby/gems/3.2.0/specifications/fast_gettext*.gemspec') -on(master, '/opt/puppetlabs/puppet/bin/r10k') - -teardown { on(master, '/opt/puppetlabs/puppet/bin/gem uninstall -ax r10k') } diff --git a/acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb b/acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb deleted file mode 100644 index b85a54ef17..0000000000 --- a/acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb +++ /dev/null @@ -1,32 +0,0 @@ -test_name "C100533: Agent sends json report for cached catalog" do - - tag 'risk:high', - 'audit:high', - 'audit:integration', - 'server' - - with_puppet_running_on(master, :main => {}) do - expected_format = 'json' - - step "Perform agent run to ensure that catalog is cached" do - agents.each do |agent| - on(agent, puppet('agent', '-t'), :acceptable_exit_codes => [0,2]) - end - end - - step "Ensure agent sends #{expected_format} report for cached catalog" do - agents.each do |agent| - on(agent, puppet('agent', '-t', - '--http_debug'), :acceptable_exit_codes => [0,2]) do |res| - # Expected content-type should be in the headers of the - # HTTP report payload being PUT to the server by the agent. - unless res.stderr =~ /<- "PUT \/puppet\/v[3-9]\/report.*Content-Type: .*\/#{expected_format}/ - fail_test("Report was not submitted in #{expected_format} format") - end - end - end - end - - end - -end diff --git a/acceptance/tests/reports/cached_catalog_status_in_report.rb b/acceptance/tests/reports/cached_catalog_status_in_report.rb deleted file mode 100644 index 6561d353e8..0000000000 --- a/acceptance/tests/reports/cached_catalog_status_in_report.rb +++ /dev/null @@ -1,48 +0,0 @@ -test_name "PUP-5867: The report specifies whether a cached catalog was used, and if so, why" do - tag 'audit:high', - 'audit:integration', - 'server' - - master_reportdir = create_tmpdir_for_user(master, 'report_dir') - - teardown do - on(master, "rm -rf #{master_reportdir}") - end - - def remove_reports_on_master(master_reportdir, agent_node_name) - on(master, "rm -rf #{master_reportdir}/#{agent_node_name}/*") - end - - with_puppet_running_on(master, :master => { :reportdir => master_reportdir, :reports => 'store' }) do - agents.each do |agent| - step "cached_catalog_status should be 'not used' when a new catalog is retrieved" do - step "Initial run: cache a newly retrieved catalog" do - on(agent, puppet("agent", "-t"), :acceptable_exit_codes => [0,2]) - end - - step "Run again and ensure report indicates that the cached catalog was not used" do - on(agent, puppet("agent", "--onetime", "--no-daemonize"), :acceptable_exit_codes => [0, 2]) - on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result| - assert_match(/cached_catalog_status: not_used/, result.stdout, "expected to find 'cached_catalog_status: not_used' in the report") - end - remove_reports_on_master(master_reportdir, agent.node_name) - end - end - - step "Run with --use_cached_catalog and ensure report indicates cached catalog was explicitly requested" do - on(agent, puppet("agent", "--onetime", "--no-daemonize", "--use_cached_catalog"), :acceptable_exit_codes => [0, 2]) - on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result| - assert_match(/cached_catalog_status: explicitly_requested/, result.stdout, "expected to find 'cached_catalog_status: explicitly_requested' in the report") - end - remove_reports_on_master(master_reportdir, agent.node_name) - end - - step "On a run which fails to retrieve a new catalog, ensure report indicates cached catalog was used on failure" do - on(agent, puppet("agent", "--onetime", "--no-daemonize", "--report_server #{master}", "--server nonexist"), :acceptable_exit_codes => [0, 2]) - on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result| - assert_match(/cached_catalog_status: on_failure/, result.stdout, "expected to find 'cached_catalog_status: on_failure' in the report") - end - end - end - end -end diff --git a/acceptance/tests/reports/corrective_change_new_resource.rb b/acceptance/tests/reports/corrective_change_new_resource.rb deleted file mode 100644 index de085a8406..0000000000 --- a/acceptance/tests/reports/corrective_change_new_resource.rb +++ /dev/null @@ -1,99 +0,0 @@ -test_name "C98092 - a new resource should not be reported as a corrective change" do - - require 'yaml' - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # Uses a server currently but is testing agent report - 'broken:images' - - test_file_name = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name) - tmp_file = {} - - agents.each do |agent| - tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment) - end - - teardown do - step 'clean out produced resources' do - agents.each do |agent| - if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != '' - on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true) - end - - - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - end - - step 'create file resource - site.pp to verify corrective change flag' do - file_contents = 'this is a test' - manifest = <<-MANIFEST - file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp': - ensure => file, - content => ' - \$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file} - file { \$test_path: - content => @(UTF8) - #{file_contents} - | UTF8 - } - ', - } - MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - step 'run agent(s)' do - with_puppet_running_on(master, {}) do - agents.each do |agent| - #Run agent once to create new File resource - step 'Run agent once to create new File resource' do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - end - - #Verify the file resource is created - step 'Verify the file resource is created' do - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result| - assert_equal(file_contents, file_result, 'file contents did not match accepted') - end - end - end - end - end - - # Open last_run_report.yaml - step 'Check report' do - agents.each do |agent| - on(agent, puppet('config print statedir')) do |command_result| - report_path = command_result.stdout.chomp + '/last_run_report.yaml' - on(agent, "cat '#{report_path}'").stdout do |report_contents| - - yaml_data = YAML::parse(report_contents) - # Remove any Ruby class tags from the yaml - yaml_data.root.each do |o| - if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby") - o.tag = nil - end - end - report_yaml = yaml_data.to_ruby - - file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"] - assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing') - corrective_change_value = file_resource_details["corrective_change"] - assert_equal(false, corrective_change_value, 'corrective_change flag should be false') - end - end - end - end - -end diff --git a/acceptance/tests/reports/corrective_change_outside_puppet.rb b/acceptance/tests/reports/corrective_change_outside_puppet.rb deleted file mode 100644 index 2e23651fa8..0000000000 --- a/acceptance/tests/reports/corrective_change_outside_puppet.rb +++ /dev/null @@ -1,116 +0,0 @@ -test_name "C98093 - a resource changed outside of Puppet will be reported as a corrective change" do - - require 'yaml' - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # Uses a server currently, but is testing agent report - 'broken:images' - - test_file_name = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name) - tmp_file = {} - - - agents.each do |agent| - tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment) - end - - teardown do - step 'clean out produced resources' do - agents.each do |agent| - if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != '' - on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true) - end - - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - end - - step 'create file resource - site.pp to verify corrective change flag' do - file_contents = 'this is a test' - manifest = <<-MANIFEST - file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp': - ensure => file, - content => ' - \$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file} - file { \$test_path: - content => @(UTF8) - #{file_contents} - | UTF8 - } - ', - } - MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - step 'run agent(s)' do - with_puppet_running_on(master, {}) do - agents.each do |agent| - #Run agent once to create new File resource - step 'Run agent once to create new File resource' do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - end - - #Verify the file resource is created - step 'Verify the file resource is created' do - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result| - assert_equal(file_contents, file_result, 'file contents did not match accepted') - end - end - - #Delete the file - step 'Delete the file' do - on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true) - end - - #Run agent to correct the file's absence - step 'Run agent to correct the files absence' do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - end - - #Verify the file resource is created - step 'Verify the file resource is created' do - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result| - assert_equal(file_contents, file_result, 'file contents did not match accepted') - end - end - end - end - end - - # Open last_run_report.yaml - step 'Check report' do - agents.each do |agent| - on(agent, puppet('config print statedir')) do |command_result| - report_path = command_result.stdout.chomp + '/last_run_report.yaml' - on(agent, "cat '#{report_path}'").stdout do |report_contents| - - yaml_data = YAML::parse(report_contents) - # Remove any Ruby class tags from the yaml - yaml_data.root.each do |o| - if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby") - o.tag = nil - end - end - report_yaml = yaml_data.to_ruby - - file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"] - assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing') - corrective_change_value = file_resource_details["corrective_change"] - assert_equal(true, corrective_change_value, 'corrective_change flag should be true') - end - end - end - end - -end diff --git a/acceptance/tests/reports/corrective_change_via_puppet.rb b/acceptance/tests/reports/corrective_change_via_puppet.rb deleted file mode 100644 index d7cf7d564c..0000000000 --- a/acceptance/tests/reports/corrective_change_via_puppet.rb +++ /dev/null @@ -1,120 +0,0 @@ -test_name "C98094 - a resource changed via Puppet manifest will not be reported as a corrective change" do - - require 'yaml' - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tag 'audit:high', - 'audit:integration', - 'audit:refactor', # Uses a server currently, but is testing agent report - 'broken:images', - 'server' - - test_file_name = File.basename(__FILE__, '.*') - tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name) - tmp_file = {} - - original_test_data = 'this is my original important data' - modified_test_data = 'this is my modified important data' - - agents.each do |agent| - tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment) - end - - teardown do - # Remove all traces of the last used environment - agents.each do |agent| - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - - step 'clean out produced resources' do - agents.each do |agent| - if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != '' - on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true) - end - end - end - end - - def create_manifest_for_file_resource(file_resource, file_contents, environment_name) - manifest = <<-MANIFEST - file { '#{environmentpath}/#{environment_name}/manifests/site.pp': - ensure => file, - content => ' - \$test_path = \$facts["networking"]["fqdn"] ? #{file_resource} - file { \$test_path: - content => @(UTF8) - #{file_contents} - | UTF8 - } - ', - } - MANIFEST - apply_manifest_on(master, manifest, :catch_failures => true) - end - - step 'create file resource in site.pp' do - create_manifest_for_file_resource(tmp_file, original_test_data, tmp_environment) - end - - step 'run agent(s) to create the new resource' do - with_puppet_running_on(master, {}) do - agents.each do |agent| - step 'Run agent once to create new File resource' do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - end - - step 'Verify the file resource is created' do - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents| - assert_equal(original_test_data, file_contents, 'file contents did not match expected contents') - end - end - end - - step 'Change the manifest for the resource' do - create_manifest_for_file_resource(tmp_file, modified_test_data, tmp_environment) - end - - agents.each do |agent| - step 'Run agent a 2nd time to change the File resource' do - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - end - - step 'Verify the file resource is created' do - on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents| - assert_equal(modified_test_data, file_contents, 'file contents did not match expected contents') - end - end - end - end - end - - # Open last_run_report.yaml - step 'Check report' do - agents.each do |agent| - on(agent, puppet('config print statedir')) do |command_result| - report_path = command_result.stdout.chomp + '/last_run_report.yaml' - on(agent, "cat '#{report_path}'").stdout do |report_contents| - - yaml_data = YAML::parse(report_contents) - # Remove any Ruby class tags from the yaml - yaml_data.root.each do |o| - if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby") - o.tag = nil - end - end - report_yaml = yaml_data.to_ruby - file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"] - assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing') - corrective_change_value = file_resource_details["corrective_change"] - assert_equal(false, corrective_change_value, 'corrective_change flag for the changed resource should be false') - end - end - end - end -end diff --git a/acceptance/tests/reports/submission.rb b/acceptance/tests/reports/submission.rb deleted file mode 100644 index b08cb863d7..0000000000 --- a/acceptance/tests/reports/submission.rb +++ /dev/null @@ -1,81 +0,0 @@ -test_name "Report submission" - -tag 'audit:high', - 'audit:integration' - -if master.is_pe? - require "time" - - def puppetdb - hosts.detect { |h| h['roles'].include?('database') } - end - - def sleep_until_queue_empty(timeout=60) - metric = "org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=com.puppetlabs.puppetdb.commands" - queue_size = nil - - begin - Timeout.timeout(timeout) do - until queue_size == 0 - result = on(puppetdb, %Q{curl http://localhost:8080/v3/metrics/mbean/#{CGI.escape(metric)}}) - if md = /"?QueueSize"?\s*:\s*(\d+)/.match(result.stdout.chomp) - queue_size = Integer(md[1]) - end - sleep 1 - end - end - rescue Timeout::Error - raise "Queue took longer than allowed #{timeout} seconds to empty" - end - end - - def query_last_report_time_on(agent) - time_query_script = <<-EOS - require "net/http" - require "json" - - puppetdb_url = URI("http://localhost:8080/v3/reports") - puppetdb_url.query = CGI.escape(%Q{query=["=","certname","#{agent}"]}) - result = Net::HTTP.get(puppetdb_url) - json = JSON.load(result) - puts json.first["receive-time"] - EOS - on(puppetdb, "#{master[:privatebindir]}/ruby -e '#{time_query_script}'").output.chomp - end - - last_times = {} - - agents.each do |agent| - last_times[agent] = query_last_report_time_on(agent) - end - - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet('agent', "-t")) - - sleep_until_queue_empty - - current_time = Time.parse(query_last_report_time_on(agent)) - last_time = Time.parse(last_times[agent]) - - assert(current_time > last_time, "Most recent report time #{current_time} is not newer than last report time #{last_time}") - end - end - -else - - testdir = create_tmpdir_for_user master, 'report_submission' - - teardown do - on master, "rm -rf #{testdir}" - end - - with_puppet_running_on(master, :main => { :reportdir => testdir, :reports => 'store' }) do - agents.each do |agent| - on(agent, puppet('agent', "-t")) - - on master, "grep -q #{agent.node_name} #{testdir}/*/*" - end - end - -end diff --git a/acceptance/tests/resource/exec/accept_array_commands.rb b/acceptance/tests/resource/exec/accept_array_commands.rb deleted file mode 100644 index 2086618db0..0000000000 --- a/acceptance/tests/resource/exec/accept_array_commands.rb +++ /dev/null @@ -1,23 +0,0 @@ -test_name "Be able to execute array commands" do - tag 'audit:high', - 'audit:acceptance' - - agents.each do |agent| - if agent.platform =~ /windows/ - cmd = ['C:\Windows\System32\cmd.exe', '/c', 'echo', '*'] - else - cmd = ['/bin/echo', '*'] - end - - exec_manifest = <<~MANIFEST - exec { "test exec": - command => #{cmd}, - logoutput => true, - } - MANIFEST - - apply_manifest_on(agent, exec_manifest) do |output| - assert_match('Notice: /Stage[main]/Main/Exec[test exec]/returns: *', output.stdout) - end - end -end diff --git a/acceptance/tests/resource/exec/accept_multi-line_commands.rb b/acceptance/tests/resource/exec/accept_multi-line_commands.rb deleted file mode 100644 index d1a77b33ed..0000000000 --- a/acceptance/tests/resource/exec/accept_multi-line_commands.rb +++ /dev/null @@ -1,31 +0,0 @@ -test_name "Be able to execute multi-line commands (#9996)" -confine :except, :platform => 'windows' -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - temp_file_name = agent.tmpfile('9996-multi-line-commands') - - test_manifest = < "/bin/echo '#Test' > #{temp_file_name}; - /bin/echo 'bob' >> #{temp_file_name};" -} -HERE - - expected_results = <64KB file to exceed pipe buffer. - lorem_ipsum = < ['/bin', '/usr/bin', 'C:/cygwin32/bin', 'C:/cygwin64/bin', 'C:/cygwin/bin'], logoutput => true}") do |result| - fail_test "didn't seem to run the command" unless - result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja' - fail_test "didn't print output correctly" unless - result.stdout.lines.select {|line| line =~ /\/returns:/}.count == 4097 - end - - apply_manifest_on(agent, "exec {'echo': path => ['/bin', '/usr/bin', 'C:/cygwin32/bin', 'C:/cygwin64/bin', 'C:/cygwin/bin'], logoutput => true}") do |result| - fail_test "didn't seem to run the command" unless - result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja' - end -end diff --git a/acceptance/tests/resource/exec/should_not_run_command_creates.rb b/acceptance/tests/resource/exec/should_not_run_command_creates.rb deleted file mode 100644 index de827a097e..0000000000 --- a/acceptance/tests/resource/exec/should_not_run_command_creates.rb +++ /dev/null @@ -1,39 +0,0 @@ -test_name "should not run command creates" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - touch = agent.tmpfile('touched') - donottouch = agent.tmpfile('not-touched') - -manifest = %Q{ - exec { "test#{Time.new.to_i}": command => '#{agent.touch(donottouch)}', creates => "#{touch}"} -} - - step "prepare the agents for the test" - on agent, "touch #{touch} && rm -f #{donottouch}" - - step "test using puppet apply" - apply_manifest_on(agent, manifest) do |result| - fail_test "looks like the thing executed, which it shouldn't" if - result.stdout.include? 'executed successfully' - end - - step "verify the file didn't get created" - on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1] - - step "prepare the agents for the second part of the test" - on agent, "touch #{touch} ; rm -f #{donottouch}" - - step "test using puppet resource" - on(agent, puppet_resource('exec', "test#{Time.new.to_i}", - "command='#{agent.touch(donottouch)}'", - "creates='#{touch}'")) do |result| - fail_test "looks like the thing executed, which it shouldn't" if - result.stdout.include? 'executed successfully' - end - - step "verify the file didn't get created the second time" - on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1] -end diff --git a/acceptance/tests/resource/exec/should_run_bad_command.rb b/acceptance/tests/resource/exec/should_run_bad_command.rb deleted file mode 100644 index bd591117a9..0000000000 --- a/acceptance/tests/resource/exec/should_run_bad_command.rb +++ /dev/null @@ -1,70 +0,0 @@ -test_name "tests that puppet can run badly written scripts that fork and inherit descriptors" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -def sleepy_daemon_script(agent) - if agent['platform'] =~ /win/ - # Windows uses a shorter sleep, because it's expected to wait until the end. - return < true}") do |result| - fail_test "didn't seem to run the command" unless - result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja' - end -end - diff --git a/acceptance/tests/resource/exec/should_run_command.rb b/acceptance/tests/resource/exec/should_run_command.rb deleted file mode 100644 index cdce50ac04..0000000000 --- a/acceptance/tests/resource/exec/should_run_command.rb +++ /dev/null @@ -1,35 +0,0 @@ -test_name "tests that puppet correctly runs an exec." -# original author: Dan Bode --daniel 2010-12-23 - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -def before(agent) - step "file to be touched should not exist." - agent.tmpfile('test-exec') -end - -def after(agent, touched) - step "checking the output worked" - on agent, "test -f #{touched}" - - step "clean up the system" - on agent, "rm -f #{touched}" -end - -agents.each do |agent| - touched = before(agent) - apply_manifest_on(agent, "exec {'test': command=>'#{agent.touch(touched)}'}") do |result| - fail_test "didn't seem to run the command" unless - result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja' - end - after(agent, touched) - - touched = before(agent) - on(agent, puppet_resource('-d', 'exec', 'test', "command='#{agent.touch(touched)}'}")) do |result| - fail_test "didn't seem to run the command" unless - result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja' - end - after(agent, touched) -end diff --git a/acceptance/tests/resource/exec/should_run_command_as_user.rb b/acceptance/tests/resource/exec/should_run_command_as_user.rb deleted file mode 100644 index 6a3d2a3350..0000000000 --- a/acceptance/tests/resource/exec/should_run_command_as_user.rb +++ /dev/null @@ -1,58 +0,0 @@ -test_name "The exec resource should be able to run commands as a different user" do - confine :except, :platform => 'windows' - - tag 'audit:high', - 'audit:acceptance' - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::BeakerUtils - - def random_username - "pl#{rand(999999).to_i}" - end - - def exec_resource_manifest(params = {}) - default_params = { - :logoutput => true, - :path => '/usr/bin:/usr/sbin:/bin:/sbin', - :command => 'echo Hello' - } - params = default_params.merge(params) - - params_str = params.map do |param, value| - value_str = value.to_s - value_str = "'#{value_str}'" if value.is_a?(String) - " #{param} => #{value_str}" - end.join(",\n") - - <<-MANIFEST -exec { 'run_test_command': - #{params_str} -} -MANIFEST - end - - agents.each do |agent| - username = random_username - - # Create our user. Ensure that we start with a clean slate. - agent.user_absent(username) - agent.user_present(username) - teardown { agent.user_absent(username) } - - tmpdir = agent.tmpdir("forbidden") - on(agent, "chmod 700 #{tmpdir}") - - step "Runs the command even when the user doesn't have permissions to access the pwd" do - # Can't use apply_manifest_on here because that does not take the :cwd - # as an option. - tmpfile = agent.tmpfile("exec_user_perms_manifest") - create_remote_file(agent, tmpfile, exec_resource_manifest(user: username)) - on(agent, "cd #{tmpdir} && puppet apply #{tmpfile} --detailed-exitcodes", acceptable_exit_codes: [0, 2]) - end - - step "Runs the command even when the user doesn't have permission to access the specified cwd" do - apply_manifest_on(agent, exec_resource_manifest(user: username, cwd: tmpdir), catch_failures: true) - end - end -end diff --git a/acceptance/tests/resource/exec/should_run_command_in_cwd.rb b/acceptance/tests/resource/exec/should_run_command_in_cwd.rb deleted file mode 100644 index a59c8763dc..0000000000 --- a/acceptance/tests/resource/exec/should_run_command_in_cwd.rb +++ /dev/null @@ -1,179 +0,0 @@ -test_name "The Exec resource should run commands in the specified cwd" do - tag 'audit:high', - 'audit:acceptance' - confine :except, :platform => /debian-12-amd64/ # PUP-12020 - - require 'puppet/acceptance/windows_utils' - extend Puppet::Acceptance::WindowsUtils - - # Useful utility that converts a string literal - # to a regex. We do a lot of assertions on file - # paths here that we need to escape, so this is - # a nice way of making the code more readable. - def to_regex(str) - Regexp.new(Regexp.escape(str)) - end - - def exec_resource_manifest(command, params = {}) - default_params = { - :command => command - } - params = default_params.merge(params) - - params_str = params.map do |param, value| - value_str = value.to_s - # Single quote the strings in case our value is a Windows - # path - value_str = "'#{value_str}'" if value.is_a?(String) - - " #{param} => #{value_str}" - end.join(",\n") - - <<-MANIFEST - exec { 'run_test_command': - #{params_str} - } - MANIFEST - end - - def assert_file_on(host, filepath, failure_comment) - if host.platform =~ /windows/ - cmd = "cmd.exe /c \"type #{filepath.gsub('/', '\\')}\"" - else - cmd = "test -f #{filepath}" - end - on(host, cmd, :acceptable_exit_codes => [0, 1]) do |result| - assert_equal(0, result.exit_code, failure_comment) - end - end - - agents.each do |agent| - testdir = agent.tmpdir("mock_testdir") - if agent.platform =~ /windows/ - path = 'C:\Windows\System32' - echo_to = 'cmd.exe /c echo testing >' - cat = 'cmd.exe /c type' - non_existant_dir = 'C:\does_not_exist' - origin_working_dir = on(agent, 'cmd.exe /c echo %CD%').stdout.chomp - else - path = '/usr/bin:/usr/sbin:/bin:/sbin' - echo_to = 'echo testing >' - cat = 'cat' - non_existant_dir = '/does_not_exist' - origin_working_dir = on(agent, 'pwd').stdout.chomp - end - - step "clean current working directory" do - on(agent, "rm -f cwd_test*") - end - - step "Defaults to the current directory if the CWD option is not provided" do - apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test1", {:path => path}), :catch_failures => true) - assert_file_on(agent, File.join(origin_working_dir, 'cwd_test1'), 'Exec did not create file in origin pwd, exec resource not defaulting to pwd when no :cwd option is given') - end - - step "Runs the command in the user specified CWD" do - apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test2", {:cwd => testdir, :path => path}), :catch_failures => true) - assert_file_on(agent, File.join(testdir, 'cwd_test2'), 'Exec did not create file in test directory, exec resource not using :cwd given') - end - - step "Errors if the user specified CWD does not exist" do - apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test3", {cwd: non_existant_dir, :path => path}), :expect_failures => true) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed with non-existant :cwd") - end - end - - # "onlyif" testing will require some form of runnable test in the testdir for the - # onlyif clause to actually execute. The runnable test we will use is attempting to - # 'cat' an unqualified file that will only exist in the testdir - create_remote_file(agent, File.join(testdir, 'testdir_onlyif.txt'), 'testing') - - step 'Runs a "check" command (:onlyif or :unless) in the user specified CWD' do - apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test4", {cwd: testdir, :path => path, :onlyif => "#{cat} testdir_onlyif.txt"}), :expect_changes => true) - assert_file_on(agent, File.join(testdir, 'cwd_test4'), 'Exec did not create file in test directory, exec resource not using :cwd given') - end - - step 'Does not run the exec if the "check" command (:onlyif or :unless) fails' do - apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test5", {cwd: testdir, :path => path, :onlyif => "foobar"}), :expect_failures => true) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed with failed :onlyif clause") - end - end - - tmpdir_noaccess = agent.tmpdir("mock_dir") - create_remote_file(agent, File.join(tmpdir_noaccess, 'noaccess.txt'), 'foobar') - username = "pl#{rand(999999).to_i}" - - # The next two steps set up to test running with a CWD that the user does not have access to. - # The setup for the test creates 1. a new user and 2. a new directory that the new user does - # not have access to. - step "Setup user for 'no access' test" do - agent.user_present(username) - if agent.platform =~ /solaris/ - # for some reason applications of 'user_present' on solaris 10 don't manage the homedir correctly, so just - # force a puppet apply to manage the user - on agent, puppet_resource('user', username, "ensure=present managehome=true home=/export/home/#{username}") - # we need to create the user directory ourselves in order for solaris users to successfully login - on(agent, "mkdir /export/home/#{username} && chown -R #{username} /export/home/#{username}") - elsif agent.platform =~ /osx/ - # we need to create the user directory ourselves in order for macos users to successfully login - on(agent, "mkdir /Users/#{username} && chown -R #{username}:80 /Users/#{username}") - elsif agent.platform =~ /debian|ubuntu|sles/ - # we need to create the user directory ourselves in order for deb users to successfully login - on(agent, "mkdir /home/#{username} && chown -R #{username} /home/#{username}") - end - teardown { agent.user_absent(username) } - end - - tmpdir_noaccess = agent.tmpdir("mock_noaccess") - create_remote_file(agent, File.join(tmpdir_noaccess, 'noaccess.txt'), 'foobar') - - step "Setup restricted access directory for 'no access' test" do - if agent.platform =~ /windows/ - deny_administrator_access_to(agent, tmpdir_noaccess) - deny_administrator_access_to(agent, File.join(tmpdir_noaccess, 'noaccess.txt')) - else - if agent.platform =~ /osx/ - # This is a little nuts, but on MacOS the tmpdir returned from agent.tmpdir is located in - # a directory that users other than root can't even access, i.e. other users won't have access - # to either the noaccess dir itself (which we want) _or the tmpdir root it's located in_. This is - # a problem since it will look to puppet like the noacceess dir doesn't exist at all, and so we - # can't count on any reliaable failure since we want a return indicating no access, not a missing directory. - # - # To get around this for MacOS platforms we simply use the new user's homedir as the 'tmpdir' and - # put the noaccess dir there. - on(agent, "mkdir /Users/#{username}/noaccess_test && cp #{tmpdir_noaccess}/noaccess.txt /Users/#{username}/noaccess_test && chmod -R 600 /Users/#{username}/noaccess_test") - tmpdir_noaccess = "/Users/#{username}/noaccess_test" - end - # remove permissions for all other users other than root, which should force puppet to fail when running as another user - on(agent, "chmod -R 600 #{tmpdir_noaccess}") - end - end - - step "Errors if the user does not have access to the specified CWD" do - manifest_path = agent.tmpfile('apply_manifest.pp') - create_remote_file(agent, manifest_path, exec_resource_manifest("#{cat} noaccess.txt", {:cwd => tmpdir_noaccess, :path => path})) - if agent.platform =~ /windows/ - on(agent, "cmd.exe /c \"puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory", ) - end - elsif agent.platform =~ /osx/ - # on MacOS we need to copy the manifest to run to the user's home dir and give the user ownership. otherwise puppet won't run on it. - on(agent, "cp #{manifest_path} /Users/#{username}/noaccess_manifest.pp && chown #{username}:80 /Users/#{username}/noaccess_manifest.pp") - on(agent, "su - #{username} -c \"/opt/puppetlabs/bin/puppet apply /Users/#{username}/noaccess_manifest.pp --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory") - end - else - on(agent, "chown #{username} #{manifest_path}") - if agent.platform =~ /solaris|aix/ - on(agent, "su - #{username} -c \"/opt/puppetlabs/bin/puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory") - end - else - on(agent, "su #{username} -c \"/opt/puppetlabs/bin/puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result| - assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory") - end - end - end - end - end -end diff --git a/acceptance/tests/resource/exec/should_set_environment_variables.rb b/acceptance/tests/resource/exec/should_set_environment_variables.rb deleted file mode 100644 index 8da766fe06..0000000000 --- a/acceptance/tests/resource/exec/should_set_environment_variables.rb +++ /dev/null @@ -1,103 +0,0 @@ -test_name "The Exec resource should set user-specified environment variables" do - tag 'audit:high', - 'audit:acceptance' - - # Would be nice to parse the actual values from puppet_output, - # but that would require some complicated matching since - # puppet_output contains other stuff. - def assert_env_var_values(puppet_output, expected_values) - expected_values.each do |env_var, value| - assert_match(/#{env_var}=#{value}/, puppet_output, "Expected '#{env_var}=#{value}' to be printed as part of the output!") - end - end - - agents.each do |agent| - # Calculate some top-level variables/functions we - # will need for our tests. - unless agent.platform =~ /windows/ - path = '/usr/bin:/usr/sbin:/bin:/sbin' - print_env_vars = lambda do |*env_vars| - env_vars_str = env_vars.map do |env_var| - "#{env_var}=$#{env_var}" - end.join(" ") - - "echo #{env_vars_str}" - end - else - # Powershell's directory is dependent on what version of Powershell is - # installed on the system (e.g. v1.0, v2.0), so we need to programmatically - # calculate the executable's directory to add to our PATH variable. - powershell_path = on(agent, "cmd.exe /c where powershell.exe").stdout.chomp - *powershell_dir, _ = powershell_path.split('\\') - powershell_dir = powershell_dir.join('\\') - - path = "C:\Windows\System32;#{powershell_dir}" - print_env_vars = lambda do |*env_vars| - env_vars_str = env_vars.map do |env_var| - "#{env_var}=$env:#{env_var}" - end - - "powershell.exe \"Write-Host -NoNewLine #{env_vars_str}\"" - end - end - - # Easier to read than a def. The def. would require us - # to specify the host as a param. in order to get the path - # and print_cwd command, which is unnecessary clutter. - exec_resource_manifest = lambda do |params = {}| - default_params = { - :logoutput => true, - :path => path - } - params = default_params.merge(params) - - params_str = params.map do |param, value| - value_str = value.to_s - # Single quote the strings in case our value is a Windows - # path - value_str = "'#{value_str}'" if value.is_a?(String) - - " #{param} => #{value_str}" - end.join(",\n") - - <<-MANIFEST - exec { 'run_test_command': - #{params_str} - } -MANIFEST - end - - step 'Passes the user-specified environment variables into the command' do - manifest = exec_resource_manifest.call( - command: print_env_vars.call('ENV_VAR_ONE', 'ENV_VAR_TWO'), - environment: ['ENV_VAR_ONE=VALUE_ONE', 'ENV_VAR_TWO=VALUE_TWO'] - ) - - apply_manifest_on(agent, manifest) do |result| - assert_env_var_values(result.stdout, ENV_VAR_ONE: 'VALUE_ONE', ENV_VAR_TWO: 'VALUE_TWO') - end - end - - step "Temporarily overrides previously set environment variables" do - manifest = exec_resource_manifest.call( - command: print_env_vars.call('ENV_VAR_ONE'), - environment: ['ENV_VAR_ONE=VALUE_OVERRIDE'] - ) - - apply_manifest_on(agent, manifest, environment: { 'ENV_VAR_ONE' => 'VALUE' }) do |result| - assert_env_var_values(result.stdout, ENV_VAR_ONE: 'VALUE_OVERRIDE') - end - end - - step "Temporarily overrides previously set environment variables even if the passed-in value is empty" do - manifest = exec_resource_manifest.call( - command: print_env_vars.call('ENV_VAR_ONE'), - environment: ['ENV_VAR_ONE='] - ) - - apply_manifest_on(agent, manifest, environment: { 'ENV_VAR_ONE' => 'VALUE' }) do |result| - assert_env_var_values(result.stdout, ENV_VAR_ONE: '') - end - end - end -end diff --git a/acceptance/tests/resource/exec/should_set_path.rb b/acceptance/tests/resource/exec/should_set_path.rb deleted file mode 100644 index 22691b38a0..0000000000 --- a/acceptance/tests/resource/exec/should_set_path.rb +++ /dev/null @@ -1,21 +0,0 @@ -test_name "the path statement should work to locate commands" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - file = agent.tmpfile('touched-should-set-path') - - step "clean up the system for the test" - on agent, "rm -f #{file}" - - step "invoke the exec resource with a path set" - on(agent, puppet_resource('exec', 'test', - "command='#{agent.touch(file, false)}'", "path='#{agent.path}'")) - - step "verify that the files were created" - on agent, "test -f #{file}" - - step "clean up the system after testing" - on agent, "rm -f #{file}" -end diff --git a/acceptance/tests/resource/file/ascii_diff_output_content_attribute.rb b/acceptance/tests/resource/file/ascii_diff_output_content_attribute.rb deleted file mode 100644 index f955ac5588..0000000000 --- a/acceptance/tests/resource/file/ascii_diff_output_content_attribute.rb +++ /dev/null @@ -1,42 +0,0 @@ -test_name "ASCII Diff Output of Content Attribute" do - tag 'audit:high', - 'audit:acceptance' - - sha256 = Digest::SHA256.new - agents.each do |agent| - step 'When handling ASCII files' do - target = agent.tmpfile('content_ASCII_file_test') - initial_text = 'Initial Text' - initial_text_sha_checksum = sha256.hexdigest(initial_text) - updated_text = 'Updated Text' - updated_text_sha_checksum = sha256.hexdigest(updated_text) - on agent, puppet('config', 'set', 'diff', 'diff') - - step 'Ensure the test environment is clean' do - on agent, "rm -f #{target}" - end - - teardown do - on agent, "rm -f #{target}" - end - - step 'Create ASCII file using content' do - manifest = "file { '#{target}': content => '#{initial_text}', ensure => present , checksum => 'sha256'}" - - on(agent, puppet('apply'), :stdin => manifest) do |result| - assert_match(/ensure: defined content as '{sha256}#{initial_text_sha_checksum}'/, result.stdout, "#{agent}: checksum of ASCII file not matched") - end - end - - step 'Update existing ASCII file content' do - manifest = "file { '#{target}': content => '#{updated_text}', ensure => present , checksum => 'sha256'}" - - on(agent, puppet('apply','--show_diff'), :stdin => manifest) do |result| - assert_match(/content: content changed '{sha256}#{initial_text_sha_checksum}' to '{sha256}#{updated_text_sha_checksum}'/, result.stdout, "#{agent}: checksum of ASCII file not matched after update") - assert_match(/^- ?#{initial_text}$/, result.stdout, "#{agent}: initial text not found in diff") - assert_match(/^\+ ?#{updated_text}$/, result.stdout, "#{agent}: updated text not found in diff") - end - end - end - end -end diff --git a/acceptance/tests/resource/file/bin_diff_output_content_attribute.rb b/acceptance/tests/resource/file/bin_diff_output_content_attribute.rb deleted file mode 100644 index d15d270f5a..0000000000 --- a/acceptance/tests/resource/file/bin_diff_output_content_attribute.rb +++ /dev/null @@ -1,68 +0,0 @@ -test_name "Binary Diff Output of Content Attribute" do - tag 'audit:high', - 'audit:acceptance' - - # cannot test binary diff on windows2012r2_ja-64-1 - # Error: Could not write report for afire-lien.delivery.puppetlabs.net at C:/ProgramData/PuppetLabs/puppet/cache/reports/afire-lien.delivery.puppetlabs.net/201912041455.yaml: anchor value must contain alphanumerical characters only - # Error: Could not send report: anchor value must contain alphanumerical characters only - confine :except, {}, hosts.select { |host| host[:platform]=~ /windows/ && host[:locale] == 'ja' } - - sha256 = Digest::SHA256.new - agents.each do |agent| - step 'When handling binary files' do - target = agent.tmpfile('content_binary_file_test') - initial_bin_data = "\xc7\xd1\xfc\x84" - initial_base64_data = Base64.encode64(initial_bin_data).chomp - initial_sha_checksum = sha256.hexdigest(initial_bin_data) - updated_bin_data = "\xc7\xd1\xfc\x85" - updated_base64_data = Base64.encode64(updated_bin_data).chomp - updated_sha_checksum = sha256.hexdigest(updated_bin_data) - on(agent, puppet('config', 'set', 'diff', 'diff')) - - agent_default_external_encoding=nil - on(agent, "#{ruby_command(agent)} -e \"puts Encoding.default_external\"") do |result| - agent_default_external_encoding = result.stdout.chomp - end - - if agent_default_external_encoding && agent_default_external_encoding != Encoding.default_external - begin - initial_bin_data=initial_bin_data.force_encoding(agent_default_external_encoding).encode(Encoding.default_external) - updated_bin_data=updated_bin_data.force_encoding(agent_default_external_encoding).encode(Encoding.default_external) - rescue Encoding::InvalidByteSequenceError - #depending on agent_default_external_encoding, the conversion may fail, but this should not be a problem - end - end - - teardown do - on agent, "rm -f #{target}" - end - - step 'Ensure the test environment is clean' do - on agent, "rm -f #{target}" - end - - step 'Create binary file using content' do - manifest = "file { '#{target}': content => Binary('#{initial_base64_data}'), ensure => present , checksum => 'sha256'}" - - on(agent, puppet('apply'), :stdin => manifest) do |result| - assert_match(/ensure: defined content as '{sha256}#{initial_sha_checksum}'/, result.stdout, "#{agent}: checksum of binary file not matched") - end - end - - step 'Update existing binary file content' do - manifest = "file { '#{target}': content => Binary('#{updated_base64_data}'), ensure => present , checksum => 'sha256'}" - - on(agent, puppet('apply','--show_diff'), :stdin => manifest) do |result| - assert_match(/content: content changed '{sha256}#{initial_sha_checksum}' to '{sha256}#{updated_sha_checksum}'/, result.stdout, "#{agent}: checksum of binary file not matched after update") - refute_match(/content: Received a Log attribute with invalid encoding:/, result.stdout, "#{agent}: Received a Log attribute with invalid encoding") - if initial_bin_data.valid_encoding? && updated_bin_data.valid_encoding? - assert_match(/^- ?#{initial_bin_data}$/, result.stdout, "#{agent}: initial utf-8 data not found in binary diff") - assert_match(/^\+ ?#{updated_bin_data}$/, result.stdout, "#{agent}: updated utf-8 data not found in binary diff") - else - assert_match(/Binary files #{target} and .* differ/, result.stdout, "#{agent}: Binary file diff notice not matched") - end - end - end - end - end -end diff --git a/acceptance/tests/resource/file/content_attribute.rb b/acceptance/tests/resource/file/content_attribute.rb deleted file mode 100644 index 6b3c820a40..0000000000 --- a/acceptance/tests/resource/file/content_attribute.rb +++ /dev/null @@ -1,78 +0,0 @@ -test_name "Content Attribute" -tag 'audit:high', - 'audit:refactor', # Use block stype test_name - 'audit:acceptance' - -agents.each do |agent| - target = agent.tmpfile('content_file_test') - - step "Ensure the test environment is clean" - on agent, "rm -f #{target}" - - step "Content Attribute: using raw content" - - checksums_fips = ['sha256', 'sha256lite'] - checksums_no_fips = ['sha256', 'sha256lite', 'md5', 'md5lite'] - - if on(agent, facter("fips_enabled")).stdout =~ /true/ - checksums = checksums_fips - else - checksums = checksums_no_fips - end - - manifest = "file { '#{target}': content => 'This is the test file content', ensure => present }" - manifest += checksums.collect {|checksum_type| - "file { '#{target+checksum_type}': content => 'This is the test file content', ensure => present, checksum => #{checksum_type} }" - }.join("\n") - apply_manifest_on(agent, manifest) do |result| - checksums.each do |checksum_type| - refute_match(/content changed/, result.stdout, "#{agent}: shouldn't have overwrote #{target+checksum_type}") - end - end - - on(agent, "cat #{target}") do |result| - assert_match(/This is the test file content/, result.stdout, "File content not matched on #{agent}") unless agent['locale'] == 'ja' - end - - step "Content Attribute: illegal timesteps" - ['mtime', 'ctime'].each do |checksum_type| - manifest = "file { '#{target+checksum_type}': content => 'This is the test file content', ensure => present, checksum => #{checksum_type} }" - apply_manifest_on(agent, manifest, :acceptable_exit_codes => [1]) do |result| - assert_match(/Error: Validation of File\[#{target+checksum_type}\] failed: You cannot specify content when using checksum '#{checksum_type}'/, result.stderr, "#{agent}: expected failure") unless agent['locale'] == 'ja' - end - end - - step "Ensure the test environment is clean" - on(agent, "rm -f #{target}") - - step "Content Attribute: using a checksum from filebucket" - on(agent, "echo 'This is the checksum file contents' > #{target}") - - step "Backup file into the filebucket" - on(agent, puppet_filebucket("backup --local #{target}")) - - step "Modify file to force apply to retrieve file from local clientbucket" - on(agent, "echo 'This is the modified file contents' > #{target}") - - dir = on(agent, puppet_filebucket("--configprint clientbucketdir")).stdout.chomp - - sha256_manifest = %Q| - filebucket { 'local': - path => '#{dir}', - } - - file { '#{target}': - ensure => present, - content => '{sha256}3b9238769b033b48073267b8baea00fa51c598dc14081da51f2e510c37c46a28', - backup => local, - } - | - - step "Applying Manifest on Agent" - apply_manifest_on agent, sha256_manifest - - step "Validate filebucket checksum file contents" - on(agent, "cat #{target}") do |result| - assert_match(/This is the checksum file content/, result.stdout, "File content not matched on #{agent}") unless agent['locale'] == 'ja' - end -end diff --git a/acceptance/tests/resource/file/handle_fifo_files.rb b/acceptance/tests/resource/file/handle_fifo_files.rb deleted file mode 100644 index 4a19f913a0..0000000000 --- a/acceptance/tests/resource/file/handle_fifo_files.rb +++ /dev/null @@ -1,63 +0,0 @@ -test_name "should be able to handle fifo files" -tag 'audit:high', - 'audit:acceptance' -confine :except, :platform => /windows/ - -def ensure_content_to_file_manifest(file_path, ensure_value) - return <<-MANIFEST - file { "#{file_path}": - ensure => #{ensure_value}, - content => "Hello World" - } - MANIFEST -end - -agents.each do |agent| - tmp_path = agent.tmpdir("tmpdir") - fifo_path = "#{tmp_path}/myfifo" - - teardown do - agent.rm_rf(tmp_path) - end - - step "create fifo" do - on(agent, "mkfifo #{fifo_path}") - end - - step "check that fifo got created" do - on(agent, "ls -l #{fifo_path}") do |result| - assert(result.stdout.start_with?('p')) - end - end - - step "puppet ensures given fifo is present" do - apply_manifest_on(agent, ensure_content_to_file_manifest(fifo_path, 'present'), :acceptable_exit_codes => [2]) do |result| - assert_match(/Warning: .+ Ensure set to :present but file type is fifo so no content will be synced/, result.stderr) - end - end - - step "check that given file is still a fifo" do - on(agent, "ls -l #{fifo_path}") do |result| - assert(result.stdout.start_with?('p')) - end - end - - step "puppet ensures given fifo is a regular file" do - apply_manifest_on(agent, ensure_content_to_file_manifest(fifo_path, 'file'), :acceptable_exit_codes => [0]) do |result| - assert_match(/Notice: .+\/myfifo\]\/ensure: defined content as '{/, result.stdout) - refute_match(/Warning: .+ Ensure set to :present but file type is fifo so no content will be synced/, result.stderr) - end - end - - step "check that given fifo is now a regular file" do - on(agent, "ls -l #{fifo_path}") do |result| - assert(result.stdout.start_with?('-')) - end - end - - step "check that given file now has desired content" do - on(agent, "cat #{fifo_path}") do |result| - assert_equal('Hello World', result.stdout) - end - end -end diff --git a/acceptance/tests/resource/file/handle_fifo_files_when_recursing.rb b/acceptance/tests/resource/file/handle_fifo_files_when_recursing.rb deleted file mode 100644 index ee071886ee..0000000000 --- a/acceptance/tests/resource/file/handle_fifo_files_when_recursing.rb +++ /dev/null @@ -1,69 +0,0 @@ -test_name "should be able to handle fifo files when recursing" -tag 'audit:high', - 'audit:acceptance' -confine :except, :platform => /windows/ - -def ensure_owner_recursively_manifest(path, owner_value) - return <<-MANIFEST - file { "#{path}": - ensure => present, - recurse => true, - owner => #{owner_value} - } - MANIFEST -end - -agents.each do |agent| - initial_owner = '' - random_user = "pl#{rand(999).to_i}" - - tmp_path = agent.tmpdir("tmpdir") - fifo_path = "#{tmp_path}/myfifo" - - teardown do - agent.rm_rf(tmp_path) - end - - step "create fifo file" do - on(agent, "mkfifo #{fifo_path}") - on(agent, puppet("resource user #{random_user} ensure=absent")) - end - - step "check that fifo file got created" do - on(agent, "ls -l #{fifo_path}") do |result| - assert(result.stdout.start_with?('p')) - initial_owner = result.stdout.split[2] - end - end - - step "create a new user" do - on(agent, puppet("resource user #{random_user} ensure=present")) - end - - step "puppet ensures '#{random_user}' as owner of path" do - apply_manifest_on(agent, ensure_owner_recursively_manifest(tmp_path, random_user), :acceptable_exit_codes => [0]) do |result| - assert_match(/#{tmp_path}\]\/owner: owner changed '#{initial_owner}' to '#{random_user}'/, result.stdout) - refute_match(/Error: .+ Failed to generate additional resources using ‘eval_generate’: Cannot manage files of type fifo/, result.stderr) - end - end - - step "check that given file is still a fifo" do - on(agent, "ls -l #{fifo_path}") do |result| - assert(result.stdout.start_with?('p')) - end - end - - step "check ownership of fifo file" do - on(agent, "ls -l #{fifo_path}") do |result| - user = result.stdout.split[2] - assert_equal(random_user, user) - end - end - - step "check ownership of tmp folder" do - on(agent, "ls -ld #{tmp_path}") do |result| - user = result.stdout.split[2] - assert_equal(random_user, user) - end - end -end diff --git a/acceptance/tests/resource/file/should_create_directory.rb b/acceptance/tests/resource/file/should_create_directory.rb deleted file mode 100644 index a8eb76170c..0000000000 --- a/acceptance/tests/resource/file/should_create_directory.rb +++ /dev/null @@ -1,43 +0,0 @@ -test_name "should create directory" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - target = agent.tmpfile("create-dir") - teardown do - step "clean up after the test run" do - on(agent, "rm -rf #{target}") - end - end - - step "verify we can create a directory" do - on(agent, puppet_resource("file", target, 'ensure=directory')) - end - - step "verify the directory was created" do - on(agent, "test -d #{target}") - end - - dir_manifest = agent.tmpfile("dir-resource") - create_remote_file(agent, dir_manifest, <<-PP) - $dir='#{target}' - $same_dir='#{target}/' - file {$dir: - ensure => directory, - } - file { $same_dir: - ensure => directory, - } - PP - - step "verify we can't create same dir resource with a trailing slash" do - options = {:acceptable_exit_codes => [1]} - on(agent, puppet_apply("--noop #{dir_manifest}"), options) do |result| - unless agent['locale'] == 'ja' - assert_match('Cannot alias File', result.output, - 'duplicate directory resources did not fail properly') - end - end - end -end diff --git a/acceptance/tests/resource/file/should_create_empty.rb b/acceptance/tests/resource/file/should_create_empty.rb deleted file mode 100644 index 1181136055..0000000000 --- a/acceptance/tests/resource/file/should_create_empty.rb +++ /dev/null @@ -1,20 +0,0 @@ -test_name "should create empty file for 'present'" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - target = agent.tmpfile("empty") - - step "clean up the system before we begin" - on(agent, "rm -rf #{target}") - - step "verify we can create an empty file" - on(agent, puppet_resource("file", target, 'ensure=present')) - - step "verify the target was created" - on(agent, "test -f #{target} && test ! -s #{target}") - - step "clean up after the test run" - on(agent, "rm -rf #{target}") -end diff --git a/acceptance/tests/resource/file/should_create_symlink.rb b/acceptance/tests/resource/file/should_create_symlink.rb deleted file mode 100644 index 364a322c27..0000000000 --- a/acceptance/tests/resource/file/should_create_symlink.rb +++ /dev/null @@ -1,65 +0,0 @@ -test_name "should create symlink" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -def message - 'hello world' -end - -def reset_link_and_target(agent, link, target) - step "clean up the system before we begin" - on agent, "rm -rf #{target} #{link}" - on agent, "echo '#{message}' > #{target}" -end - -def verify_symlink(agent, link, target) - step "verify the symlink was created" - on(agent, "test -L #{link} && test -f #{link}") - step "verify the symlink points to a file" - on(agent, "test -f #{target}") - - step "verify the content is identical on both sides" - on(agent, "cat #{link}") do |result| - fail_test "link missing content" unless result.stdout.include?(message) - end - on(agent, "cat #{target}") do |result| - fail_test "target missing content" unless result.stdout.include?(message) - end -end - -agents.each do |agent| - if agent.platform.variant == 'windows' - # symlinks are supported only on Vista+ (version 6.0 and higher) - on(agent, facter('kernelmajversion')) do |result| - skip_test "Test not supported on this platform" if result.stdout.chomp.to_f < 6.0 - end - end - - link_file = agent.tmpfile("symlink-link") - target_file = agent.tmpfile("symlink-target") - link_dir = agent.tmpdir("dir_symlink-link") - target_dir = agent.tmpdir("dir-symlink-target") - - reset_link_and_target(agent, link_file, target_file) - reset_link_and_target(agent, link_dir, target_dir) - - step "verify we can create a symlink with puppet resource" - on(agent, puppet_resource("file", "#{link_file}", "ensure=#{target_file}")) - verify_symlink(agent, link_file, target_file) - reset_link_and_target(agent, link_file, target_file) - - step "verify that 'links => manage' preserves a symlink" - apply_manifest_on(agent, "file { '#{link_file}': ensure => link, target => '#{target_file}', links => manage }") - verify_symlink(agent, link_file, target_file) - reset_link_and_target(agent, link_file, target_file) - - step "verify that 'links => manage' and 'recurse => true' preserves links in a directory" - on(agent, puppet_resource("file", target_dir, "ensure=directory")) - reset_link_and_target(agent, link_dir, "#{target_dir}/symlink-target") - apply_manifest_on(agent, "file { '#{link_dir}': ensure => directory, target => '#{target_dir}', links => manage, recurse => true }") - verify_symlink(agent, "#{link_dir}/symlink-target", "#{target_dir}/symlink-target") - - step "clean up after the test run" - on agent, "rm -rf #{target_file} #{link_file} #{target_dir} #{link_dir}" -end diff --git a/acceptance/tests/resource/file/should_default_mode.rb b/acceptance/tests/resource/file/should_default_mode.rb deleted file mode 100644 index 56cccd52dc..0000000000 --- a/acceptance/tests/resource/file/should_default_mode.rb +++ /dev/null @@ -1,45 +0,0 @@ -test_name "file resource: set default modes" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -def regexp_mode(mode) - Regexp.new("mode\s*=>\s*'0?#{mode}'") -end - -agents.each do |agent| - step "setup" - parent = agent.tmpdir('default-mode-parent') - on(agent, "rm -rf #{parent}") - - step "puppet should set execute bit on readable directories" - on(agent, puppet_resource("file", parent, "ensure=directory", "mode=0644")) do |result| - assert_match(regexp_mode(755), result.stdout) - end - - step "include execute bit on newly created directories" - dir = "#{parent}/dir" - on(agent, "mkdir #{dir} && cd #{dir} && cd ..") - - step "exclude execute bit from newly created files" - file = "#{parent}/file.txt" - on(agent, "echo foobar > #{file}") - on(agent, "#{file}", :acceptable_exit_codes => (1..255)) do |result| - refute_match(/foobar/, result.stdout) - end - - step "set execute bit on file if explicitly specified" - file_750 = "#{parent}/file_750.txt" - on(agent, puppet_resource("file", file_750, "ensure=file", "mode=0750")) do |result| - assert_match(regexp_mode(750), result.stdout) - end - - step "don't set execute bit if directory not readable" - dir_600 = "#{parent}/dir_600" - on(agent, puppet_resource("file", dir_600, "ensure=directory", "mode=0600")) do |result| - assert_match(regexp_mode(700), result.stdout) # readable by owner, but not group - end - - on(agent, "rm -rf #{parent}") -end - diff --git a/acceptance/tests/resource/file/should_remove_dir.rb b/acceptance/tests/resource/file/should_remove_dir.rb deleted file mode 100644 index ae04d6cce4..0000000000 --- a/acceptance/tests/resource/file/should_remove_dir.rb +++ /dev/null @@ -1,26 +0,0 @@ -test_name "should remove directory, but force required" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - target = agent.tmpdir("delete-dir") - - step "clean up the system before we begin" - on(agent, "rm -rf #{target} ; mkdir -p #{target}") - - step "verify we can't remove a directory without 'force'" - on(agent, puppet_resource("file", target, 'ensure=absent')) do |result| - fail_test "didn't tell us that force was required" unless - result.stdout.include? "Not removing directory; use 'force' to override" unless agent['locale'] == 'ja' - end - - step "verify the directory still exists" - on(agent, "test -d #{target}") - - step "verify we can remove a directory with 'force'" - on(agent, puppet_resource("file", target, 'ensure=absent', 'force=true')) - - step "verify that the directory is gone" - on(agent, "test -d #{target}", :acceptable_exit_codes => [1]) -end diff --git a/acceptance/tests/resource/file/should_remove_file.rb b/acceptance/tests/resource/file/should_remove_file.rb deleted file mode 100644 index 34caee0411..0000000000 --- a/acceptance/tests/resource/file/should_remove_file.rb +++ /dev/null @@ -1,17 +0,0 @@ -test_name "should remove file" -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - target = agent.tmpfile('delete-file') - - step "clean up the system before we begin" - on agent, "rm -rf #{target} && touch #{target}" - - step "verify we can remove a file" - on(agent, puppet_resource("file", target, 'ensure=absent')) - - step "verify that the file is gone" - on agent, "test -e #{target}", :acceptable_exit_codes => [1] -end diff --git a/acceptance/tests/resource/file/source_attribute.rb b/acceptance/tests/resource/file/source_attribute.rb deleted file mode 100644 index 45a51bf3bd..0000000000 --- a/acceptance/tests/resource/file/source_attribute.rb +++ /dev/null @@ -1,301 +0,0 @@ -test_name "The source attribute" do - require 'puppet/acceptance/module_utils' - extend Puppet::Acceptance::ModuleUtils - - tag 'audit:high', - 'audit:acceptance', - 'server' - - @target_file_on_windows = 'C:/windows/temp/source_attr_test' - @target_file_on_nix = '/tmp/source_attr_test' - @target_dir_on_windows = 'C:/windows/temp/source_attr_test_dir' - @target_dir_on_nix = '/tmp/source_attr_test_dir' - - # In case any of the hosts happens to be fips enabled we limit to the lowest - # common denominator. - checksums_fips = [nil, 'sha256', 'sha256lite', 'ctime', 'mtime'] - checksums_no_fips = [nil, 'sha256', 'sha256lite', 'md5', 'md5lite', 'ctime', 'mtime'] - - fips_host_present = hosts.any? { |host| on(host, facter("fips_enabled")).stdout =~ /true/ } - - if fips_host_present - checksums = checksums_fips - else - checksums = checksums_no_fips - end - - orig_installed_modules = get_installed_modules_for_hosts hosts - teardown do - rm_installed_modules_from_hosts orig_installed_modules, (get_installed_modules_for_hosts hosts) - hosts.each do |host| - file_to_rm = host['platform'] =~ /windows/ ? @target_file_on_windows : @target_file_on_nix - dir_to_rm = host['platform'] =~ /windows/ ? @target_dir_on_windows : @target_dir_on_nix - - checksums.each do |checksum_type| - on(host, "rm #{file_to_rm}#{checksum_type}", :acceptable_exit_codes => [0,1]) - on(host, "rm -r #{dir_to_rm}#{checksum_type}", :acceptable_exit_codes => [0,1]) - end - end - end - - step "Setup - create environment and test module" - # set directories - testdir = master.tmpdir('file_source_attr') - env_dir = "#{testdir}/environments" - prod_dir = "#{env_dir}/production" - manifest_dir = "#{prod_dir}/manifests" - manifest_file = "#{prod_dir}/manifests/site.pp" - module_dir = "#{prod_dir}/modules" - test_module_dir = "#{module_dir}/source_test_module" - test_module_manifests_dir = "#{test_module_dir}/manifests" - test_module_files_dir = "#{test_module_dir}/files" - mod_manifest_file = "#{test_module_manifests_dir}/init.pp" - mod_source_file = "#{test_module_files_dir}/source_file" - mod_source_dir = "#{test_module_files_dir}/source_dir" - mod_source_dir_file = "#{mod_source_dir}/source_dir_file" - - mod_source = ' the content is present' - - def mod_manifest_entry(checksum_type = nil) - checksum = if checksum_type then "checksum => #{checksum_type}," else "" end - manifest = <<-EOF - $target_file#{checksum_type} = $::kernel ? { - \\'windows\\' => \\'#{@target_file_on_windows}#{checksum_type}\\', - default => \\'#{@target_file_on_nix}#{checksum_type}\\' - } - - file { $target_file#{checksum_type}: - source => \\'puppet:///modules/source_test_module/source_file\\', - #{checksum} - ensure => present - } - - $target_dir#{checksum_type} = $::kernel ? { - \\'windows\\' => \\'#{@target_dir_on_windows}#{checksum_type}\\', - default => \\'#{@target_dir_on_nix}#{checksum_type}\\' - } - - file { $target_dir#{checksum_type}: - source => \\'puppet:///modules/source_test_module/source_dir\\', - #{checksum} - ensure => directory, - recurse => true - } - EOF - manifest - end - - mod_manifest = <<-EOF - class source_test_module { - #{checksums.collect { |checksum_type| mod_manifest_entry(checksum_type) }.join("\n")} - } - EOF - - env_manifest = <<-EOF - filebucket { \\'main\\': - server => \\'#{master}\\', - path => false, - } - - File { backup => \\'main\\' } - - node default { - include source_test_module - } - EOF - - # apply manifests to setup environment and modules - apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) - File { - ensure => directory, - mode => '0755', - } - - file { - '#{testdir}':; - '#{env_dir}':; - '#{prod_dir}':; - '#{manifest_dir}':; - '#{module_dir}':; - '#{test_module_dir}':; - '#{test_module_manifests_dir}':; - '#{test_module_files_dir}':; - } - - file { '#{mod_manifest_file}': - ensure => file, - mode => '0644', - content => '#{mod_manifest}', - } - - file { '#{mod_source_file}': - ensure => file, - mode => '0644', - content => '#{mod_source}', - } - - file { '#{mod_source_dir}': - ensure => directory, - mode => '0755' - } - - file { '#{mod_source_dir_file}': - ensure => file, - mode => '0644', - content => '#{mod_source}', - } - - file { '#{manifest_file}': - ensure => file, - mode => '0644', - content => '#{env_manifest}', - } - MANIFEST - - step "When using a puppet:/// URI with a master/agent setup" - master_opts = { - 'main' => { - 'environmentpath' => "#{env_dir}", - }, - } - with_puppet_running_on(master, master_opts, testdir) do - agents.each do |agent| - # accept an exit code of 2 which is returned if there are changes - step "create file the first run" - on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [0,2]) do - file_to_check = agent['platform'] =~ /windows/ ? @target_file_on_windows : @target_file_on_nix - dir_to_check = agent['platform'] =~ /windows/ ? @target_dir_on_windows : @target_dir_on_nix - - checksums.each do |checksum_type| - on agent, "cat #{file_to_check}#{checksum_type}" do |result| - assert_match(/the content is present/, result.stdout, "Result file not created #{checksum_type}") - end - - on agent, "cat #{dir_to_check}#{checksum_type}/source_dir_file" do |result| - assert_match(/the content is present/, result.stdout, "Result file not created #{checksum_type}") - end - end - end - - step "second run should not update file" - on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [0,2]) do |result| - refute_match(/content changed.*(md5|sha256)/, result.stdout, "Shouldn't have overwritten any files") - - # When using ctime/mtime, the agent compares the values from its - # local file with the values on the master to determine if the - # file is insync or not. If during the first run, the agent - # creates the files, and the resulting ctime/mtime are still - # behind the times on the master, then the 2nd agent run will - # consider the file to not be insync, and will update it - # again. This process will repeat until the agent updates the - # file, and the resulting ctime/mtime are after the values on - # the master, at which point it will have converged. - if result.stdout =~ /content changed.*ctime/ - Log.warn "Agent did not converge using ctime" - end - - if result.stdout =~ /content changed.*mtime/ - Log.warn "Agent did not converge using mtime" - end - end - end - -=begin - # Disable flaky test until PUP-4115 is addressed. - step "touch files and verify they're updated with ctime/mtime" - # wait until we're not at the mtime of files on the agents - # this could be done cross-platform using Puppet, but a single puppet query is unlikely to be less than a second, - # and iterating over all agents would be much slower - sleep(1) - - on master, "touch #{mod_source_file} #{mod_source_dir_file}" - agents.each do |agent| - on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [0,2]) do - file_to_check = agent['platform'] =~ /windows/ ? @target_file_on_windows : @target_file_on_nix - dir_to_check = agent['platform'] =~ /windows/ ? @target_dir_on_windows : @target_dir_on_nix - ['ctime', 'mtime'].each do |time_type| - assert_match(/File\[#{file_to_check}#{time_type}\]\/content: content changed/, stdout, "Should have updated files") - assert_match(/File\[#{dir_to_check}#{time_type}\/source_dir_file\]\/content: content changed/, stdout, "Should have updated files") - end - end - end -=end - end - - # TODO: Add tests for puppet:// URIs with multi-master/agent setups. - step "When using puppet apply" - agents.each do |agent| - step "Setup testing local file sources" - - # create one larger manifest with all the files so we don't have to run - # puppet apply per each checksum_type - localsource_testdir = agent.tmpdir('local_source_file_test') - source = "#{localsource_testdir}/source_mod/files/source" - on agent, "mkdir -p #{File.dirname(source)}" - # don't put a 'z' in this content - source_content = 'Yay, this is the local file. I have to be bigger than 512 bytes so that my masters. yadda yadda yadda not a nice thing. lorem ipsem. alice bob went to fetch a pail of water. Lorem ipsum dolor sit amet, pede ipsum nam wisi lectus eget, sociis sed, commodo vitae velit eleifend. Vestibulum orci feugiat erat etiam pellentesque sed, imperdiet a integer nulla, mi tincidunt suscipit. Nec sed, mi tortor, in a consequat mattis proin scelerisque eleifend. In lectus magna quam. Magna quam vitae sociosqu. Adipiscing laoreet.' - create_remote_file agent, source, source_content - - local_apply_manifest = "" - target = {} - checksums.each do |checksum_type| - target[checksum_type] = "#{localsource_testdir}/target#{checksum_type}" - checksum = if checksum_type then "checksum => #{checksum_type}," else "" end - local_apply_manifest.concat("file { '#{target[checksum_type]}': source => '#{source}', ensure => present, #{checksum} }\n") - end - - apply_manifest_on agent, local_apply_manifest - - checksums.each do |checksum_type| - step "Using a local file path. #{checksum_type}" - on(agent, "cat #{target[checksum_type]}") do |result| - assert_match(/Yay, this is the local file./, result.stdout, "FIRST: File contents not matched on #{agent}") - end - end - - step "second run should not update any files" - apply_manifest_on(agent, local_apply_manifest) do |result| - refute_match(/content changed/, result.stdout, "Shouldn't have overwrote any files") - end - - # changes in source file producing updates is tested elsewhere - step "subsequent run should not update file using lite if only after byte 512 is changed" - byte_after_md5lite = 513 - source_content[byte_after_md5lite] = 'z' - create_remote_file agent, source, source_content - - if fips_host_present - apply_manifest_on(agent, "file { '#{localsource_testdir}/targetsha256lite': source => '#{source}', ensure => present, checksum => sha256lite }") do |result| - refute_match(/(content changed|defined content)/, result.stdout, "Shouldn't have overwrote any files") - end - else - apply_manifest_on(agent, "file { '#{localsource_testdir}/targetmd5lite': source => '#{source}', ensure => present, checksum => md5lite } file { '#{localsource_testdir}/targetsha256lite': source => '#{source}', ensure => present, checksum => sha256lite }") do |result| - refute_match(/(content changed|defined content)/, result.stdout, "Shouldn't have overwrote any files") - end - end - - local_module_manifest = "" - checksums.each do |checksum_type| - on agent, "rm -rf #{target[checksum_type]}" - checksum = if checksum_type then "checksum => #{checksum_type}," else "" end - local_module_manifest.concat("file { '#{target[checksum_type]}': source => 'puppet:///modules/source_mod/source', ensure => present, #{checksum} }\n") - end - - localsource_test_manifest = agent.tmpfile('local_source_test_manifest') - create_remote_file agent, localsource_test_manifest, local_module_manifest - on agent, puppet( %{apply --modulepath=#{localsource_testdir} #{localsource_test_manifest}} ) - - checksums.each do |checksum_type| - step "Using a puppet:/// URI with checksum type: #{checksum_type}" - on(agent, "cat #{target[checksum_type]}") do |result| - assert_match(/Yay, this is the local file./, result.stdout, "FIRST: File contents not matched on #{agent}") - end - end - - step "second run should not update any files using apply with puppet:/// URI source" - on(agent, puppet( %{apply --modulepath=#{localsource_testdir} #{localsource_test_manifest}} )) do |result| - refute_match(/content changed/, result.stdout, "Shouldn't have overwrote any files") - end - end - -end diff --git a/acceptance/tests/resource/file/symbolic_modes.rb b/acceptance/tests/resource/file/symbolic_modes.rb deleted file mode 100644 index 8c558a76a8..0000000000 --- a/acceptance/tests/resource/file/symbolic_modes.rb +++ /dev/null @@ -1,328 +0,0 @@ -test_name 'file resource: symbolic modes' do - confine :except, :platform => /^windows/ - confine :to, {}, hosts.select {|host| !host[:roles].include?('master')} - - tag 'audit:high', - 'audit:acceptance' - - require 'puppet/acceptance/temp_file_utils' - extend Puppet::Acceptance::TempFileUtils - - class FileSymlink - attr_reader :mode, :path, :start_mode, :symbolic_mode - - def initialize(base_dir, file_type, symbolic_mode, mode, start_mode=nil) - @base_dir = base_dir - @file_type = file_type - @symbolic_mode = symbolic_mode - @mode = mode - @start_mode = start_mode - - if @start_mode.nil? - @path= "#{@base_dir}/#{@file_type}_#{@symbolic_mode}_#{@mode.to_s(8)}" - else - @path= "#{@base_dir}/#{@file_type}_#{@symbolic_mode}_#{@start_mode.to_s(8)}_#{@mode.to_s(8)}" - end - end - - # does the mode of the file/directory change from start_mode to puppet apply - def mode_changes? - ! @start_mode.nil? && @start_mode != @mode - end - - def get_manifest - "file { #{@path.inspect}: ensure => '#{@file_type}', mode => '#{@symbolic_mode}' }" - end - end - - class BaseTest - include Beaker::DSL::Assertions - - def initialize(testcase, agent, base_dir) - @testcase = testcase - @agent = agent - @base_dir = base_dir - @file_list = [] - @directory_list = [] - end - - def assert_mode(agent, path, expected_mode) - permissions = @testcase.stat(agent, path) - assert_equal(expected_mode, permissions[2], "'#{path}' current mode #{permissions[2].to_s(8)} doesn't match expected mode #{expected_mode.to_s(8)}") - end - - def manifest - manifest_array = (@file_list + @directory_list).map {|x| x.get_manifest} - @testcase.step(manifest_array) - manifest_array.join("\n") - end - - def puppet_reapply - @testcase.apply_manifest_on(@agent, manifest) do |apply_result| - refute_match(/mode changed/, apply_result.stdout, "reapplied the symbolic mode change") - (@file_list + @directory_list).each do |file| - refute_match(/#{Regexp.escape(file.path)}/, apply_result.stdout, "Expected to not see '#{file.path}' in 'puppet apply' output") - end - end - end - end - - class CreateTest < BaseTest - - def symlink_file(symbolic_mode, mode) - @file_list << FileSymlink.new(@base_dir, 'file', symbolic_mode, mode) - end - - def symlink_directory(symbolic_mode, mode) - @directory_list << FileSymlink.new(@base_dir, 'directory', symbolic_mode, mode) - end - - def puppet_apply - apply_result = @testcase.apply_manifest_on(@agent, manifest).stdout - (@file_list + @directory_list).each do |file| - assert_match(/File\[#{Regexp.escape(file.path)}\]\/ensure: created/, apply_result, "Failed to create #{file.path}") - assert_mode(@agent, file.path, file.mode) - end - end - end - - class ModifyTest < BaseTest - - def symlink_file(symbolic_mode, start_mode, mode) - @file_list << FileSymlink.new(@base_dir, 'file', symbolic_mode, mode, start_mode) - end - - def symlink_directory(symbolic_mode, start_mode, mode) - @directory_list << FileSymlink.new(@base_dir, 'directory', symbolic_mode, mode, start_mode) - end - - def create_starting_state - files = @file_list.collect {|x| "'#{x.path}'" } - directories = @directory_list.collect {|x| "'#{x.path}'" } - - @testcase.on(@agent, "touch #{files.join(' ')}") - @testcase.on(@agent, "mkdir -p #{directories.join(' ')}") - @testcase.on(@agent, "chown symuser:symgroup #{files.join(' ')} #{directories.join(' ')}") - cmd_list = [] - (@file_list + @directory_list).each do |file| - cmd_list << "chmod #{file.start_mode.to_s(8)} '#{file.path}'" - end - @testcase.on(@agent, cmd_list.join(' && ')) - end - - def puppet_apply - @testcase.step(manifest) - apply_result = @testcase.apply_manifest_on(@agent, manifest).stdout - @testcase.step(apply_result) - (@file_list + @directory_list).each do |file| - if file.mode_changes? - assert_match(/File\[#{Regexp.escape(file.path)}.* mode changed '#{'%04o' % file.start_mode}'.* to '#{'%04o' % file.mode}'/, - apply_result, "couldn't set mode to #{file.symbolic_mode}") - else - refute_match(/#{Regexp.escape(file.path)}.*mode changed/, apply_result, "reapplied the symbolic mode change for file #{file.path}") - end - assert_mode(@agent, file.path, file.mode) - end - end - end - -# For your reference: -# 4000 the set-user-ID-on-execution bit -# 2000 the set-group-ID-on-execution bit -# 1000 the sticky bit -# 0400 Allow read by owner. -# 0200 Allow write by owner. -# 0100 For files, allow execution by owner. For directories, allow the -# owner to search in the directory. -# 0040 Allow read by group members. -# 0020 Allow write by group members. -# 0010 For files, allow execution by group members. For directories, allow -# group members to search in the directory. -# 0004 Allow read by others. -# 0002 Allow write by others. -# 0001 For files, allow execution by others. For directories allow others -# to search in the directory. -# -# On Solaris 11 (from man chmod): -# -# 20#0 Set group ID on execution if # is 7, 5, 3, or 1. -# Enable mandatory locking if # is 6, 4, 2, or 0. -# ... -# For directories, the set-gid bit can -# only be set or cleared by using symbolic mode. - -# From https://www.gnu.org/software/coreutils/manual/html_node/Symbolic-Modes.html#Symbolic-Modes -# Users -# u the user who owns the file; -# g other users who are in the file's group; -# o all other users; -# a all users; the same as 'ugo'. -# -# Operations -# + to add the permissions to whatever permissions the users already have for the file; -# - to remove the permissions from whatever permissions the users already have for the file; -# = to make the permissions the only permissions that the users have for the file. -# -# Permissions -# r the permission the users have to read the file; -# w the permission the users have to write to the file; -# x the permission the users have to execute the file, or search it if it is a directory. -# s the meaning depends on which user (uga) the permission is associated with: -# to set set-user-id-on-execution, use 'u' in the users part of the symbolic mode and 's' in the permissions part. -# to set set-group-id-on-execution, use 'g' in the users part of the symbolic mode and 's' in the permissions part. -# to set both user and group-id-on-execution, omit the users part of the symbolic mode (or use 'a') and use 's' in the permissions part. -# t the restricted deletion flag (sticky bit), omit the users part of the symbolic mode (or use 'a') and use 't' in the permissions part. -# X execute/search permission is affected only if the file is a directory or already had execute permission. -# -# Note we do not currently support the Solaris (l) permission: -# l mandatory file and record locking refers to a file's ability to have its reading or writing -# permissions locked while a program is accessing that file. -# - agents.each do |agent| - is_solaris = agent['platform'].include?('solaris') - - on(agent, puppet('resource user symuser ensure=present')) - on(agent, puppet('resource group symgroup ensure=present')) - base_dir_create = agent.tmpdir('symbolic-modes-create_test') - base_dir_modify = agent.tmpdir('symbolic-modes-modify_test') - - teardown do - on(agent, puppet('resource user symuser ensure=absent')) - on(agent, puppet('resource group symgroup ensure=absent')) - on(agent, "rm -rf '#{base_dir_create}' '#{base_dir_modify}'") - end - - create_test = CreateTest.new(self, agent, base_dir_create) - create_test.symlink_file('u=r', 00444) - create_test.symlink_file('u=w', 00244) - create_test.symlink_file('u=x', 00144) - create_test.symlink_file('u=rw', 00644) - create_test.symlink_file('u=rwx', 00744) - create_test.symlink_file('u=rwxt', 01744) - create_test.symlink_file('u=rwxs', 04744) - create_test.symlink_file('u=rwxts', 05744) - - create_test.symlink_file('ug=r', 00444) - create_test.symlink_file('ug=rw', 00664) - create_test.symlink_file('ug=rwx', 00774) - create_test.symlink_file('ug=rwxt', 01774) - create_test.symlink_file('ug=rwxs', 06774) - create_test.symlink_file('ug=rwxts', 07774) - - create_test.symlink_file('ugo=r', 00444) - create_test.symlink_file('ugo=rw', 00666) - create_test.symlink_file('ugo=rwx', 00777) - create_test.symlink_file('ugo=rwxt', 01777) - #create_test.symlink_file('ugo=rwxs', 06777) ## BUG, puppet creates 07777 - create_test.symlink_file('ugo=rwxts', 07777) - - create_test.symlink_file('u=rwx,go=rx', 00755) - create_test.symlink_file('u=rwx,g=rx,o=r', 00754) - create_test.symlink_file('u=rwx,g=rx,o=', 00750) - create_test.symlink_file('a=rwx', 00777) - - create_test.symlink_file('u+r', 00644) - create_test.symlink_file('u+w', 00644) - create_test.symlink_file('u+x', 00744) - create_test.symlink_directory('u=r', 00455) - create_test.symlink_directory('u=w', 00255) - create_test.symlink_directory('u=x', 00155) - create_test.symlink_directory('u=rw', 00655) - create_test.symlink_directory('u=rwx', 00755) - create_test.symlink_directory('u=rwxt', 01755) - create_test.symlink_directory('u=rwxs', 04755) - create_test.symlink_directory('u=rwxts', 05755) - - create_test.symlink_directory('ug=r', 00445) - create_test.symlink_directory('ug=rw', 00665) - create_test.symlink_directory('ug=rwx', 00775) - create_test.symlink_directory('ug=rwxt', 01775) - create_test.symlink_directory('ug=rwxs', 06775) - create_test.symlink_directory('ug=rwxts', 07775) - - create_test.symlink_directory('ugo=r', 00444) - create_test.symlink_directory('ugo=rw', 00666) - create_test.symlink_directory('ugo=rwx', 00777) - create_test.symlink_directory('ugo=rwxt', 01777) - #create_test.symlink_directory('ugo=rwxs', 06777) ## BUG, puppet creates 07777 - create_test.symlink_directory('ugo=rwxts', 07777) - - create_test.symlink_directory('u=rwx,go=rx', 00755) - create_test.symlink_directory('u=rwx,g=rx,o=r', 00754) - create_test.symlink_directory('u=rwx,g=rx,o=', 00750) - create_test.symlink_directory('a=rwx', 00777) - - create_test.symlink_directory('u+r', 00755) - create_test.symlink_directory('u+w', 00755) - create_test.symlink_directory('u+x', 00755) - create_test.puppet_apply() - create_test.puppet_reapply() - - modify_test = ModifyTest.new(self, agent, base_dir_modify) - modify_test.symlink_file('u+r', 00200, 00600) - modify_test.symlink_file('u+r', 00600, 00600) - modify_test.symlink_file('u+w', 00500, 00700) - modify_test.symlink_file('u+w', 00400, 00600) - modify_test.symlink_file('u+x', 00700, 00700) - modify_test.symlink_file('u+x', 00600, 00700) - modify_test.symlink_file('u+X', 00100, 00100) - modify_test.symlink_file('u+X', 00200, 00200) - modify_test.symlink_file('u+X', 00410, 00510) - modify_test.symlink_file('a+X', 00600, 00600) - modify_test.symlink_file('a+X', 00700, 00711) - - modify_test.symlink_file('u+s', 00744, 04744) - modify_test.symlink_file('g+s', 00744, 02744) - modify_test.symlink_file('u+t', 00744, 01744) - - modify_test.symlink_file('u-r', 00200, 00200) - modify_test.symlink_file('u-r', 00600, 00200) - modify_test.symlink_file('u-w', 00500, 00500) - modify_test.symlink_file('u-w', 00600, 00400) - modify_test.symlink_file('u-x', 00700, 00600) - modify_test.symlink_file('u-x', 00600, 00600) - - modify_test.symlink_file('u-s', 04744, 00744) - modify_test.symlink_file('g-s', 02744, 00744) - modify_test.symlink_file('u-t', 01744, 00744) - - modify_test.symlink_directory('u+r', 00200, 00600) - modify_test.symlink_directory('u+r', 00600, 00600) - modify_test.symlink_directory('u+w', 00500, 00700) - modify_test.symlink_directory('u+w', 00400, 00600) - modify_test.symlink_directory('u+x', 00700, 00700) - modify_test.symlink_directory('u+x', 00600, 00700) - modify_test.symlink_directory('u+X', 00100, 00100) - modify_test.symlink_directory('u+X', 00200, 00300) - modify_test.symlink_directory('u+X', 00410, 00510) - modify_test.symlink_directory('a+X', 00600, 00711) - modify_test.symlink_directory('a+X', 00700, 00711) - - modify_test.symlink_directory('u+s', 00744, 04744) - modify_test.symlink_directory('g+s', 00744, 02744) - modify_test.symlink_directory('u+t', 00744, 01744) - - modify_test.symlink_directory('u-r', 00200, 00200) - modify_test.symlink_directory('u-r', 00600, 00200) - modify_test.symlink_directory('u-w', 00500, 00500) - modify_test.symlink_directory('u-w', 00600, 00400) - modify_test.symlink_directory('u-x', 00700, 00600) - modify_test.symlink_directory('u-x', 00600, 00600) - - modify_test.symlink_directory('u-s', 04744, 00744) - # using chmod 2744 on a directory to set the start_mode fails on Solaris - modify_test.symlink_directory('g-s', 02744, 00744) unless is_solaris - modify_test.symlink_directory('u-t', 01744, 00744) - modify_test.create_starting_state - modify_test.puppet_apply - modify_test.puppet_reapply - - # these raise - # test.assert_raises('') - # test.assert_raises(' ') - # test.assert_raises('u=X') - # test.assert_raises('u-X') - # test.assert_raises('+l') - # test.assert_raises('-l') - end -end diff --git a/acceptance/tests/resource/file/ticket_6448_file_with_utf8_source.rb b/acceptance/tests/resource/file/ticket_6448_file_with_utf8_source.rb deleted file mode 100644 index a664310d1b..0000000000 --- a/acceptance/tests/resource/file/ticket_6448_file_with_utf8_source.rb +++ /dev/null @@ -1,91 +0,0 @@ -test_name 'Ensure a file resource can have a UTF-8 source attribute, content, and path when served via a module' do - tag 'audit:high', - 'broken:images', - 'audit:acceptance', - 'server' - - require 'puppet/acceptance/environment_utils' - extend Puppet::Acceptance::EnvironmentUtils - - require 'puppet/acceptance/agent_fqdn_utils' - extend Puppet::Acceptance::AgentFqdnUtils - - tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*')) - agent_tmp_dirs = {} - - agents.each do |agent| - agent_tmp_dirs[agent_to_fqdn(agent)] = agent.tmpdir(tmp_environment) - end - - teardown do - # note - master teardown is registered by #mk_tmp_environment_with_teardown - step 'remove all test files on agents' do - agents.each do |agent| - on(agent, "rm -r '#{agent_tmp_dirs[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true) - on(agent, puppet('config print lastrunfile')) do |command_result| - agent.rm_rf(command_result.stdout) - end - end - end - end - - step 'create unicode source file served via module on master' do - # 静 \u9759 0xE9 0x9D 0x99 http://www.fileformat.info/info/unicode/char/9759/index.htm - # 的 \u7684 0xE7 0x9A 0x84 http://www.fileformat.info/info/unicode/char/7684/index.htm - # ☃ \2603 0xE2 0x98 0x83 http://www.fileformat.info/info/unicode/char/2603/index.htm - setup_module_on_master = <<-MASTER_MANIFEST - File { - ensure => directory, - mode => "0755", - } - - file { - '#{environmentpath}/#{tmp_environment}/modules/utf8_file_module':; - '#{environmentpath}/#{tmp_environment}/modules/utf8_file_module/files':; - } - - file { '#{environmentpath}/#{tmp_environment}/modules/utf8_file_module/files/\u9759\u7684': - ensure => file, - content => "\u2603" - } - MASTER_MANIFEST - apply_manifest_on(master, setup_module_on_master, :expect_changes => true) - end - - step 'create a site.pp on master containing a unicode file resource' do - site_pp_contents = <<-SITE_PP - \$test_path = \$facts['networking']['fqdn'] ? #{agent_tmp_dirs} - file { "\$test_path/\uff72\uff67\u30d5\u30eb": - ensure => present, - source => "puppet:///modules/utf8_file_module/\u9759\u7684", - } - SITE_PP - - create_site_pp = <<-CREATE_SITE_PP - file { "#{environmentpath}/#{tmp_environment}/manifests/site.pp": - ensure => file, - content => @(UTF8) - #{site_pp_contents} - | UTF8 - } - CREATE_SITE_PP - apply_manifest_on(master, create_site_pp, :expect_changes => true) - end - - step 'ensure agent can manage unicode file resource' do - # イ \uff72 0xEF 0xBD 0xB2 http://www.fileformat.info/info/unicode/char/ff72/index.htm - # ァ \uff67 0xEF 0xBD 0xA7 http://www.fileformat.info/info/unicode/char/ff67/index.htm - # フ \u30d5 0xE3 0x83 0x95 http://www.fileformat.info/info/unicode/char/30d5/index.htm - # ル \u30eb 0xE3 0x83 0xAB http://www.fileformat.info/info/unicode/char/30eb/index.htm - - with_puppet_running_on(master, {}) do - agents.each do |agent| - on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2) - - on(agent, "cat '#{agent_tmp_dirs[agent_to_fqdn(agent)]}/\uff72\uff67\u30d5\u30eb'") do |result| - assert_match("\u2603", result.stdout, "managed UTF-8 file contents '#{result.stdout}' did not match expected value '\u2603'") - end - end - end - end -end diff --git a/acceptance/tests/resource/file/ticket_7680-follow-symlinks.rb b/acceptance/tests/resource/file/ticket_7680-follow-symlinks.rb deleted file mode 100644 index 86d4fb94ee..0000000000 --- a/acceptance/tests/resource/file/ticket_7680-follow-symlinks.rb +++ /dev/null @@ -1,44 +0,0 @@ -test_name "#7680: 'links => follow' should use the file source content" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -agents.each do |agent| - - step "Create file content" - real_source = agent.tmpfile('follow_links_source') - dest = agent.tmpfile('follow_links_dest') - symlink = agent.tmpfile('follow_links_symlink') - - on agent, "echo 'This is the real content' > #{real_source}" - if agent['platform'].include?('windows') - # cygwin ln doesn't behave properly, fallback to mklink, - # but that requires backslashes, that need to be escaped, - # and the link cannot exist prior. - on agent, "rm -f #{symlink}" - on agent, "cmd /c mklink #{symlink.gsub('/', '\\\\\\\\')} #{real_source.gsub('/', '\\\\\\\\')}" - else - on agent, "ln -sf #{real_source} #{symlink}" - end - - manifest = <<-MANIFEST - file { '#{dest}': - ensure => file, - source => '#{symlink}', - links => follow, - } - MANIFEST - apply_manifest_on(agent, manifest, :trace => true) - - on(agent, "cat #{dest}") do |result| - assert_match(/This is the real content/, result.stdout) - end - - step "Cleanup" - [real_source, dest, symlink].each do |file| - on agent, "rm -f '#{file}'" - end -end - - diff --git a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb deleted file mode 100644 index 36f61c07eb..0000000000 --- a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb +++ /dev/null @@ -1,44 +0,0 @@ -test_name "#8740: should not enumerate root directory" - -confine :except, :platform => 'windows' -confine :except, :platform => 'osx' - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' - -target = "/test-socket-#{$$}" - -require 'puppet/acceptance/common_utils' -extend Puppet::Acceptance::CommandUtils - -agents.each do |agent| - step "clean up the system before we begin" - on(agent, "rm -f #{target}") - - step "create UNIX domain socket" - on(agent, "#{ruby_command(agent)} -e \"require 'socket'; UNIXServer::new('#{target}').close\"") - - step "query for all files, which should return nothing" - on(agent, puppet_resource('file'), :acceptable_exit_codes => [1]) do |result| - assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, result.stderr) - end - - ["/", "/etc"].each do |file| - step "query '#{file}' directory, which should return single entry" - on(agent, puppet_resource('file', file)) do |result| - files = result.stdout.scan(/^file \{ '([^']+)'/).flatten - - assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}") - assert_match(file, files[0], "puppet did not return file") - end - end - - step "query file that does not exist, which should report the file is absent" - on(agent, puppet_resource('file', '/this/does/notexist')) do |result| - assert_match(/ensure\s+=>\s+'absent'/, result.stdout) - end - - step "remove UNIX domain socket" - on(agent, "rm -f #{target}") -end diff --git a/acceptance/tests/resource/group/should_create.rb b/acceptance/tests/resource/group/should_create.rb deleted file mode 100644 index aed9ebea16..0000000000 --- a/acceptance/tests/resource/group/should_create.rb +++ /dev/null @@ -1,23 +0,0 @@ -test_name "should create a group" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "pl#{rand(999999).to_i}" - -agents.each do |agent| - step "ensure the group does not exist" - agent.group_absent(name) - - step "create the group" - on agent, puppet_resource('group', name, 'ensure=present') - - step "verify the group exists" - agent.group_get(name) - - step "delete the group" - agent.group_absent(name) -end diff --git a/acceptance/tests/resource/group/should_destroy.rb b/acceptance/tests/resource/group/should_destroy.rb deleted file mode 100644 index c0dfcb2613..0000000000 --- a/acceptance/tests/resource/group/should_destroy.rb +++ /dev/null @@ -1,20 +0,0 @@ -test_name "should destroy a group" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "pl#{rand(999999).to_i}" - -agents.each do |agent| - step "ensure the group is present" - agent.group_present(name) - - step "delete the group" - on agent, puppet_resource('group', name, 'ensure=absent') - - step "verify the group was deleted" - agent.group_absent(name) -end diff --git a/acceptance/tests/resource/group/should_manage_attributes_aix.rb b/acceptance/tests/resource/group/should_manage_attributes_aix.rb deleted file mode 100644 index ddde18492e..0000000000 --- a/acceptance/tests/resource/group/should_manage_attributes_aix.rb +++ /dev/null @@ -1,22 +0,0 @@ -test_name "should correctly manage the attributes property for the Group (AIX only)" do - confine :to, :platform => /aix/ - - tag 'audit:high', - 'audit:acceptance' # Could be done as integration tests, but would - # require changing the system running the test - # in ways that might require special permissions - # or be harmful to the system running the test - - require 'puppet/acceptance/aix_util' - extend Puppet::Acceptance::AixUtil - - initial_attributes = { - 'admin' => true - } - changed_attributes = { - 'admin' => false - } - - run_attribute_management_tests('group', :gid, initial_attributes, changed_attributes) - -end diff --git a/acceptance/tests/resource/group/should_manage_members.rb b/acceptance/tests/resource/group/should_manage_members.rb deleted file mode 100644 index 61cf21071e..0000000000 --- a/acceptance/tests/resource/group/should_manage_members.rb +++ /dev/null @@ -1,205 +0,0 @@ -test_name "should correctly manage the members property for the Group resource" do - # These are the only platforms whose group providers manage the members - # property - confine :to, :platform => /windows|osx|aix|^el-|fedora/ - - tag 'audit:high', - 'audit:acceptance' # Could be done as integration tests, but would - # require changing the system running the test - # in ways that might require special permissions - # or be harmful to the system running the test - - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::BeakerUtils - - def random_name - "pl#{rand(999999).to_i}" - end - - def group_manifest(user, params) - params_str = params.map do |param, value| - value_str = value.to_s - value_str = "\"#{value_str}\"" if value.is_a?(String) - - " #{param} => #{value_str}" - end.join(",\n") - - <<-MANIFEST -group { '#{user}': - #{params_str} -} -MANIFEST - end - - def members_of(host, group) - case host['platform'] - when /windows/ - # More verbose than 'net localgroup ', but more programmatic - # because it does not require us to parse stdout - get_group_members = <<-PS1 -# Adapted from https://github.com/RamblingCookieMonster/PowerShell/blob/master/Get-ADGroupMembers.ps1 -function Get-Members([string] $group) { - $ErrorActionPreference = 'Stop' - - Add-Type -AssemblyName 'System.DirectoryServices.AccountManagement' -ErrorAction Stop - $contextType = [System.DirectoryServices.AccountManagement.ContextType]::Machine - $groupObject = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity( - $contextType, - $group - ) - - if (-Not $groupObject) { - throw "Could not find the group '$group'!" - } - - $members = $groupObject.GetMembers($false) | ForEach-Object { "'$($_.Name)'" } - write-output "[$([string]::join(',', $members))]" -} - -Get-Members #{group} -PS1 - Kernel.eval( - execute_powershell_script_on(host, get_group_members).stdout.chomp - ) - else - # This reads the group members from the /etc/group file - get_group_members = <<-RUBY -require 'etc' - -group_struct = nil -Etc.group do |g| - if g.name == '#{group}' - group_struct = g - break - end -end - -unless group_struct - raise "Could not find the group '#{group}'!" -end - -puts(group_struct.mem.to_s) -RUBY - - script_path = "#{host.tmpfile("get_group_members")}.rb" - create_remote_file(host, script_path, get_group_members) - - # The setup step should have already set :privatebindir on the - # host. We only include the default here to make this routine - # work for local testing, which sometimes skips the setup step. - privatebindir = host.has_key?(:privatebindir) ? host[:privatebindir] : '/opt/puppetlabs/puppet/bin' - - result = on(host, "#{privatebindir}/ruby #{script_path}") - Kernel.eval(result.stdout.chomp) - end - end - - agents.each do |agent| - users = 6.times.collect { random_name } - users.each { |user| agent.user_absent(user) } - - group = random_name - agent.group_absent(group) - teardown { agent.group_absent(group) } - - step 'Creating the Users' do - users.each do |user| - agent.user_present(user) - teardown { agent.user_absent(user) } - end - end - - group_members = [users[0], users[1]] - - step 'Ensure that the group is created with the specified members' do - manifest = group_manifest(group, members: group_members) - apply_manifest_on(agent, manifest) - assert_matching_arrays(group_members, members_of(agent, group), "The group was not successfully created with the specified members!") - end - - step "Verify that Puppet errors when one of the members does not exist" do - manifest = group_manifest(group, members: ['nonexistent_member']) - apply_manifest_on(agent, manifest, :acceptable_exit_codes => [0, 1]) do |result| - assert_match(/Error:.*#{group}/, result.stderr, "Puppet fails to report an error when one of the members in the members property does not exist") - end - end - - step "Verify that Puppet noops when the group's members are already set after creating the group" do - manifest = group_manifest(group, members: group_members) - apply_manifest_on(agent, manifest, catch_changes: true) - assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop") - end - - step "Verify that Puppet enforces minimum user membership when auth_membership == false" do - new_members = [users[2], users[4]] - - manifest = group_manifest(group, members: new_members, auth_membership: false) - apply_manifest_on(agent, manifest) - - group_members += new_members - assert_matching_arrays(group_members, members_of(agent, group), "Puppet fails to enforce minimum user membership when auth_membership == false") - end - - step "Verify that Puppet noops when the group's members are already set after enforcing minimum user membership" do - manifest = group_manifest(group, members: group_members) - apply_manifest_on(agent, manifest, catch_changes: true) - assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop") - end - - # Run some special, platform-specific tests. If these get too large, then - # we should consider placing them in a separate file. - case agent['platform'] - when /windows/ - domain = on(agent, 'hostname').stdout.chomp.upcase - - step "(Windows) Verify that Puppet prints each group member as DOMAIN\\" do - new_members = [users[3]] - - manifest = group_manifest(group, members: new_members, auth_membership: false) - apply_manifest_on(agent, manifest) do |result| - group_members += new_members - - stdout = result.stdout.chomp - - group_members.each do |user| - assert_match(/#{domain}\\#{user}/, stdout, "Puppet fails to print the group member #{user} as #{domain}\\#{user}") - end - end - end - - step "(Windows) Verify that `puppet resource` prints each group member as DOMAIN\\" do - on(agent, puppet('resource', 'group', group)) do |result| - stdout = result.stdout.chomp - - group_members.each do |user| - assert_match(/#{domain}\\#{user}/, stdout, "`puppet resource` fails to print the group member #{user} as #{domain}\\#{user}") - end - end - end - when /aix/ - step "(AIX) Verify that Puppet accepts a comma-separated list of members for backwards compatibility" do - new_members = [users[3], users[5]] - - manifest = group_manifest(group, members: new_members.join(','), auth_membership: false) - apply_manifest_on(agent, manifest) - - group_members += new_members - assert_matching_arrays(group_members, members_of(agent, group), "Puppet cannot manage the members property when the members are provided as a comma-separated list") - end - end - - step "Verify that Puppet enforces inclusive user membership when auth_membership == true" do - group_members = [users[0]] - - manifest = group_manifest(group, members: group_members, auth_membership: true) - apply_manifest_on(agent, manifest) - assert_matching_arrays(group_members, members_of(agent, group), "Puppet fails to enforce inclusive group membership when auth_membership == true") - end - - step "Verify that Puppet noops when the group's members are already set after enforcing inclusive user membership" do - manifest = group_manifest(group, members: group_members) - apply_manifest_on(agent, manifest, catch_changes: true) - assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop") - end - end -end diff --git a/acceptance/tests/resource/group/should_modify_gid.rb b/acceptance/tests/resource/group/should_modify_gid.rb deleted file mode 100644 index a394449ec5..0000000000 --- a/acceptance/tests/resource/group/should_modify_gid.rb +++ /dev/null @@ -1,32 +0,0 @@ -test_name "should modify gid of existing group" -confine :except, :platform => 'windows' - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "pl#{rand(999999).to_i}" -gid1 = (rand(989999).to_i + 10000) -gid2 = (rand(989999).to_i + 10000) - -agents.each do |agent| - # AIX group provider returns quoted gids - step "ensure that the group exists with gid #{gid1}" - on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do |result| - fail_test "missing gid notice" unless result.stdout =~ /gid +=> +'?#{gid1}'?/ - end - - step "ensure that we can modify the GID of the group to #{gid2}" - on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do |result| - fail_test "missing gid notice" unless result.stdout =~ /gid +=> +'?#{gid2}'?/ - end - - step "verify that the GID changed" - gid_output = agent.group_gid(name).to_i - fail_test "gid #{gid_output} does not match expected value of: #{gid2}" unless gid_output == gid2 - - step "clean up the system after the test run" - on(agent, puppet_resource('group', name, 'ensure=absent')) -end diff --git a/acceptance/tests/resource/group/should_not_create_existing.rb b/acceptance/tests/resource/group/should_not_create_existing.rb deleted file mode 100644 index 8105f21861..0000000000 --- a/acceptance/tests/resource/group/should_not_create_existing.rb +++ /dev/null @@ -1,23 +0,0 @@ -test_name "group should not create existing group" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "gr#{rand(999999).to_i}" - -agents.each do |agent| - step "ensure the group exists on the target node" - agent.group_present(name) - - step "verify that we don't try and create the existing group" - on(agent, puppet_resource('group', name, 'ensure=present')) do |result| - fail_test "looks like we created the group" if - result.stdout.include? "/Group[#{name}]/ensure: created" - end - - step "clean up the system after the test run" - agent.group_absent(name) -end diff --git a/acceptance/tests/resource/group/should_not_destroy_unexisting.rb b/acceptance/tests/resource/group/should_not_destroy_unexisting.rb deleted file mode 100644 index c734bdbfb2..0000000000 --- a/acceptance/tests/resource/group/should_not_destroy_unexisting.rb +++ /dev/null @@ -1,21 +0,0 @@ -test_name "should not destroy a group that doesn't exist" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "test-group-#{Time.new.to_i}" - -step "verify the group does not already exist" -agents.each do |agent| - agent.group_absent(name) -end - -step "verify that we don't remove the group when it doesn't exist" -on(agents, puppet_resource('group', name, 'ensure=absent')) do |result| - fail_test "it looks like we tried to remove the group" if - result.stdout.include? "/Group[#{name}]/ensure: removed" -end - diff --git a/acceptance/tests/resource/group/should_query.rb b/acceptance/tests/resource/group/should_query.rb deleted file mode 100644 index 484122f825..0000000000 --- a/acceptance/tests/resource/group/should_query.rb +++ /dev/null @@ -1,24 +0,0 @@ -test_name "test that we can query and find a group that exists." - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -name = "pl#{rand(999999).to_i}" - -agents.each do |agent| - skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr' - - step "ensure that our test group exists" - agent.group_present(name) - - step "query for the resource and verify it was found" - on(agent, puppet_resource('group', name)) do |result| - fail_test "didn't find the group #{name}" unless result.stdout.include? 'present' - end - - step "clean up the group we added" - agent.group_absent(name) -end diff --git a/acceptance/tests/resource/group/should_query_all.rb b/acceptance/tests/resource/group/should_query_all.rb deleted file mode 100644 index ae1b36f9ae..0000000000 --- a/acceptance/tests/resource/group/should_query_all.rb +++ /dev/null @@ -1,29 +0,0 @@ -test_name "should query all groups" - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:integration' # Does not modify system running test - -agents.each do |agent| - skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr' - step "query natively" - - groups = agent.group_list - - fail_test("No groups found") unless groups - - step "query with puppet" - on(agent, puppet_resource('group')) do |result| - result.stdout.each_line do |line| - name = ( line.match(/^group \{ '([^']+)'/) or next )[1] - - unless groups.delete(name) - fail_test "group #{name} found by puppet, not natively" - end - end - end - - if groups.length > 0 then - fail_test "#{groups.length} groups found natively, not puppet: #{groups.join(', ')}" - end -end diff --git a/acceptance/tests/resource/package/common_package_name_in_different_providers.rb b/acceptance/tests/resource/package/common_package_name_in_different_providers.rb deleted file mode 100644 index 26270085a8..0000000000 --- a/acceptance/tests/resource/package/common_package_name_in_different_providers.rb +++ /dev/null @@ -1,147 +0,0 @@ -test_name "ticket 1073: common package name in two different providers should be allowed" do - - confine :to, {:platform => /(?:centos|el-|fedora)/}, agents - # Skipping tests if facter finds this is an ec2 host, PUP-7774 - agents.each do |agent| - skip_test('Skipping EC2 Hosts') if fact_on(agent, 'ec2_metadata') - end - - # Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096) - agents.each do |agent| - on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux' - end - - tag 'audit:high', - 'audit:acceptance' # Uses a provider that depends on AIO packaging - - require 'puppet/acceptance/rpm_util' - extend Puppet::Acceptance::RpmUtils - require 'puppet/acceptance/common_utils' - extend Puppet::Acceptance::CommandUtils - - rpm_options = {:pkg => 'guid', :version => '1.0'} - - teardown do - step "cleanup" - agents.each do |agent| - clean_rpm agent, rpm_options - end - end - - step "Verify gem and ruby-devel on fedora-22 and above if not aio" do - if @options[:type] != 'aio' then - agents.each do |agent| - if agent[:platform] =~ /fedora-2[2-9]/ then - unless check_for_package agent, 'rubygems' - install_package agent, 'rubygems' - end - unless check_for_package agent, 'ruby-devel' - install_package agent, 'ruby-devel' - end - end - end - end - end - - def gem_provider - if @options[:type] == 'aio' - 'puppet_gem' - else - 'gem' - end - end - - def verify_state(hosts, pkg, state, match) - hosts.each do |agent| - cmd = rpm_provider(agent) - # Note yum lists packages as . - on(agent, "#{cmd} list installed") do |result| - method(match).call(/^#{pkg}\./, result.stdout) - end - - on(agent, "#{gem_command(agent, @options[:type])} list --local") do |result| - method(match).call(/^#{pkg} /, result.stdout) - end - end - end - - def verify_present(hosts, pkg) - verify_state(hosts, pkg, '(?!purged|absent)[^\']+', :assert_match) - end - - def verify_absent(hosts, pkg) - verify_state(hosts, pkg, '(?:purged|absent)', :refute_match) - end - - # Setup repo and package - agents.each do |agent| - clean_rpm agent, rpm_options - setup_rpm agent, rpm_options - send_rpm agent, rpm_options - end - - verify_absent agents, 'guid' - - # Test error trying to install duplicate packages - collide1_manifest = <<-MANIFEST - package {'guid': ensure => installed} - package {'other-guid': name => 'guid', ensure => present} - MANIFEST - - apply_manifest_on(agents, collide1_manifest, :acceptable_exit_codes => [1]) do |result| - assert_match(/Error while evaluating a Resource Statement, Cannot alias Package\[other-guid\] to \[nil, "guid", nil\]/, "#{result.host}: #{result.stderr}") - end - - verify_absent agents, 'guid' - - gem_source = if ENV['GEM_SOURCE'] then "source => '#{ENV['GEM_SOURCE']}'," else '' end - collide2_manifest = <<-MANIFEST - package {'guid': ensure => '0.1.0', provider => #{gem_provider}, #{gem_source}} - package {'other-guid': name => 'guid', ensure => installed, provider => #{gem_provider}, #{gem_source}} - MANIFEST - - apply_manifest_on(agents, collide2_manifest, :acceptable_exit_codes => [1]) do |result| - assert_match(/Error while evaluating a Resource Statement, Cannot alias Package\[other-guid\] to \[nil, "guid", "#{gem_provider}"\]/, "#{result.host}: #{result.stderr}") - end - - verify_absent agents, 'guid' - - # Test successful parallel installation - install_manifest = <<-MANIFEST - package {'guid': ensure => installed} - - package {'gem-guid': - provider => #{gem_provider}, - name => 'guid', - ensure => installed, - #{gem_source} - } - MANIFEST - - apply_manifest_on(agents, install_manifest) do |result| - assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}") - assert_match('Package[gem-guid]/ensure: created', "#{result.host}: #{result.stdout}") - end - - verify_present agents, 'guid' - - # Test removal - remove_manifest = <<-MANIFEST - package {'gem-guid': - provider => #{gem_provider}, - name => 'guid', - ensure => absent, - #{gem_source} - } - - package {'guid': ensure => absent} - MANIFEST - - apply_manifest_on(agents, remove_manifest) do |result| - assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}") - assert_match('Package[gem-guid]/ensure: removed', "#{result.host}: #{result.stdout}") - end - - verify_absent agents, 'guid' - -end diff --git a/acceptance/tests/resource/package/does_not_exist.rb b/acceptance/tests/resource/package/does_not_exist.rb deleted file mode 100644 index 96fd9eee44..0000000000 --- a/acceptance/tests/resource/package/does_not_exist.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Redmine (#22529) -test_name "Puppet returns only resource package declaration when querying an uninstalled package" do - - tag 'audit:high', - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - - agents.each do |agent| - - step "test puppet resource package" do - on(agent, puppet('resource', 'package', 'not-installed-on-this-host')) do |result| - assert_match(/package.*not-installed-on-this-host.*\n.*ensure.*(?:absent|purged).*\n.*provider/, result.stdout) - end - end - - end - - # Until #3707 is fixed and purged rpm/yum packages no longer give spurious creation notices - # Also skipping solaris, windows whose providers do not have purgeable implemented. - confine_block(:to, :platform => /debian|ubuntu/) do - agents.each do |agent| - step "test puppet apply" do - on(agent, puppet('apply', '-e', %Q|"package {'not-installed-on-this-host': ensure => purged }"|)) do |result| - refute_match(/warning/i, result.stdout) - end - end - end - end -end diff --git a/acceptance/tests/resource/package/ips/basic_tests.rb b/acceptance/tests/resource/package/ips/basic_tests.rb deleted file mode 100644 index e1126d3538..0000000000 --- a/acceptance/tests/resource/package/ips/basic_tests.rb +++ /dev/null @@ -1,79 +0,0 @@ -test_name "Package:IPS basic tests" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: clean slate" - clean agent - - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - - step "IPS: basic ensure we are clean" - apply_manifest_on(agent, 'package {mypkg : ensure=>absent}') - on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do - refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end - - step "IPS: basic - it should create" - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - - step "IPS: check it was created" - on(agent, puppet("resource package mypkg")) do - assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}") - end - - step "IPS: do not upgrade until latest is mentioned" - send_pkg agent,:pkg => 'mypkg@0.0.2' - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - refute_match( /ensure: created/, result.stdout, "err: #{agent}") - end - - step "IPS: verify it was not upgraded" - on(agent, puppet("resource package mypkg")) do - assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}") - end - - step "IPS: ask to be latest" - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') - - step "IPS: ensure it was upgraded" - on(agent, puppet("resource package mypkg")) do - assert_match( /ensure\s+=> '0\.0\.2[,:]?.*'/, result.stdout, "err: #{agent}") - end - - step "IPS: when there are more than one option, choose latest." - send_pkg agent,:pkg => 'mypkg@0.0.3' - send_pkg agent,:pkg => 'mypkg@0.0.4' - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') - on(agent, puppet("resource package mypkg")) do - assert_match( /ensure\s+=> '0\.0\.4[,:]?.*'/, result.stdout, "err: #{agent}") - end - - step "IPS: ensure removed." - apply_manifest_on(agent, 'package {mypkg : ensure=>absent}') - on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do - refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_be_holdable.rb b/acceptance/tests/resource/package/ips/should_be_holdable.rb deleted file mode 100644 index b23d2fd06b..0000000000 --- a/acceptance/tests/resource/package/ips/should_be_holdable.rb +++ /dev/null @@ -1,87 +0,0 @@ -test_name "Package:IPS versionable" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent, :pkg => 'mypkg2' - clean agent, :pkg => 'mypkg' - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - setup_fakeroot2 agent - send_pkg2 agent, :pkg => 'mypkg2@0.0.1' - set_publisher agent - step "IPS: basic - it should create a specific version and install dependent package" - apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.1"}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg2" do - assert_match( /mypkg2@0.0.1/, result.stdout, "err: #{agent}") - end - - step "IPS: it should upgrade current and dependent package" - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.2' - setup_fakeroot2 agent - send_pkg2 agent, :pkg => 'mypkg2@0.0.2', :pkgdep => 'mypkg@0.0.2' - apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do - assert_match( /changed/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg2" do - assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}") - end - - step "IPS: it should not upgrade current and dependent package if dependent package is hold" - apply_manifest_on(agent, 'package {mypkg : ensure=>"present", mark=>"hold", provider=>"pkg"}') do - assert_match( //, result.stdout, "err: #{agent}") - end - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.3' - setup_fakeroot2 agent - send_pkg2 agent, :pkg => 'mypkg2@0.0.3', :pkgdep => 'mypkg@0.0.3' - apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do - refute_match( /changed/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg2" do - assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}") - end - - step "IPS: it should upgrade if hold was released." - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3", provider=>"pkg"}') do - assert_match( //, result.stdout, "err: #{agent}") - end - apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.3"}') do - assert_match( /changed/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.3/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg2" do - assert_match( /mypkg2@0.0.3/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_be_idempotent.rb b/acceptance/tests/resource/package/ips/should_be_idempotent.rb deleted file mode 100644 index 7f7c72cd9c..0000000000 --- a/acceptance/tests/resource/package/ips/should_be_idempotent.rb +++ /dev/null @@ -1,66 +0,0 @@ -test_name "Package:IPS idempotency" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - - step "IPS: it should create" - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - - step "IPS: should be idempotent (present)" - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - refute_match( /created/, result.stdout, "err: #{agent}") - refute_match( /changed/, result.stdout, "err: #{agent}") - end - send_pkg agent, :pkg => 'mypkg@0.0.2' - - step "IPS: ask for latest version" - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') - - step "IPS: ask for latest version again: should be idempotent (latest)" - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') do - refute_match( /created/, result.stdout, "err: #{agent}") - end - - step "IPS: ask for specific version" - send_pkg agent,:pkg => 'mypkg@0.0.3' - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do - assert_match( /changed/, result.stdout, "err: #{agent}") - end - - step "IPS: ask for specific version again: should be idempotent (version)" - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do - refute_match( /created/, result.stdout, "err: #{agent}") - refute_match( /changed/, result.stdout, "err: #{agent}") - end - - step "IPS: ensure removed." - apply_manifest_on(agent, 'package {mypkg : ensure=>absent}') - on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do - refute_match( /mypkg/, result.stdout, "err: #{agent}") - end - -end diff --git a/acceptance/tests/resource/package/ips/should_be_updatable.rb b/acceptance/tests/resource/package/ips/should_be_updatable.rb deleted file mode 100644 index 3c56cb0fbd..0000000000 --- a/acceptance/tests/resource/package/ips/should_be_updatable.rb +++ /dev/null @@ -1,49 +0,0 @@ -test_name "Package:IPS test for updatable (update, latest)" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - - step "IPS: basic - it should create" - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - - step "IPS: ask to be latest" - send_pkg agent, :pkg => 'mypkg@0.0.2' - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') - - step "IPS: ensure it was upgraded" - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}") - end - - step "IPS: when there are more than one option, choose latest." - send_pkg agent,:pkg => 'mypkg@0.0.3' - send_pkg agent,:pkg => 'mypkg@0.0.4' - apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.4/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb b/acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb deleted file mode 100644 index 247fc3b24b..0000000000 --- a/acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb +++ /dev/null @@ -1,38 +0,0 @@ -test_name "Package:IPS test for updatable holded package" do - confine :to, :platform => 'solaris-11' - - tag 'audit:high' - - require 'puppet/acceptance/solaris_util' - extend Puppet::Acceptance::IPSUtils - - agents.each do |agent| - teardown do - clean agent - end - - step "IPS: setup" do - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - end - - step "IPS: it should create and hold in same manifest" do - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1", mark=>hold}') do |result| - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - end - - step "IPS: it should update and unhold in same manifest" do - send_pkg agent, :pkg => 'mypkg@0.0.2' - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2", mark=>"none"}') - end - - step "IPS: ensure it was upgraded" do - on agent, "pkg list -v mypkg" do |result| - assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}") - end - end - end -end diff --git a/acceptance/tests/resource/package/ips/should_be_versionable.rb b/acceptance/tests/resource/package/ips/should_be_versionable.rb deleted file mode 100644 index ce74efd11e..0000000000 --- a/acceptance/tests/resource/package/ips/should_be_versionable.rb +++ /dev/null @@ -1,52 +0,0 @@ -test_name "Package:IPS versionable" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - send_pkg agent, :pkg => 'mypkg@0.0.2' - set_publisher agent - step "IPS: basic - it should create a specific version" - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - on agent, "pkg list mypkg" do - assert_match( /0.0.1/, result.stdout, "err: #{agent}") - end - - step "IPS: it should upgrade if asked for next version" - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2"}') do - assert_match( /ensure changed/, result.stdout, "err: #{agent}") - end - on agent, "pkg list mypkg" do - refute_match( /0.0.1/, result.stdout, "err: #{agent}") - assert_match( /0.0.2/, result.stdout, "err: #{agent}") - end - step "IPS: it should downpgrade if asked for previous version" - apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do - assert_match( /ensure changed/, result.stdout, "err: #{agent}") - end - on agent, "pkg list mypkg" do - refute_match( /0.0.2/, result.stdout, "err: #{agent}") - assert_match( /0.0.1/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_create.rb b/acceptance/tests/resource/package/ips/should_create.rb deleted file mode 100644 index 70cfabc84a..0000000000 --- a/acceptance/tests/resource/package/ips/should_create.rb +++ /dev/null @@ -1,40 +0,0 @@ -test_name "Package:IPS basic tests" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: clean slate" - clean agent - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - step "IPS: basic - it should create" - apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - step "IPS: check it was created" - on(agent, puppet("resource package mypkg")) do - assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}") - end - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_query.rb b/acceptance/tests/resource/package/ips/should_query.rb deleted file mode 100644 index 0fd33218e6..0000000000 --- a/acceptance/tests/resource/package/ips/should_query.rb +++ /dev/null @@ -1,39 +0,0 @@ -test_name "Package:IPS query" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - step "IPS: basic - it should create" - apply_manifest_on(agent, 'package {mypkg : ensure=>"present"}') do - assert_match( /ensure: created/, result.stdout, "err: #{agent}") - end - - on(agent, puppet("resource package mypkg")) do - assert_match( /0.0.1/, result.stdout, "err: #{agent}") - end - - on(agent, puppet("resource package")) do - assert_match( /0.0.1/, result.stdout, "err: #{agent}") - end -end diff --git a/acceptance/tests/resource/package/ips/should_remove.rb b/acceptance/tests/resource/package/ips/should_remove.rb deleted file mode 100644 index bbedcdba62..0000000000 --- a/acceptance/tests/resource/package/ips/should_remove.rb +++ /dev/null @@ -1,39 +0,0 @@ -test_name "Package:IPS basic tests" -confine :to, :platform => 'solaris-11' - -tag 'audit:medium', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -require 'puppet/acceptance/solaris_util' -extend Puppet::Acceptance::IPSUtils - -teardown do - step "cleanup" - agents.each do |agent| - clean agent - end -end - - -agents.each do |agent| - step "IPS: setup" - setup agent - setup_fakeroot agent - send_pkg agent, :pkg => 'mypkg@0.0.1' - set_publisher agent - on agent, "pkg install mypkg" - on agent, "pkg list -v mypkg" do - assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end - - step "IPS: ensure removed." - apply_manifest_on(agent, 'package {mypkg : ensure=>absent}') - - on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do - refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}") - end - -end diff --git a/acceptance/tests/resource/package/windows.rb b/acceptance/tests/resource/package/windows.rb deleted file mode 100644 index 0ffbae0230..0000000000 --- a/acceptance/tests/resource/package/windows.rb +++ /dev/null @@ -1,68 +0,0 @@ -test_name "Windows Package Provider" do - confine :to, :platform => 'windows' - - tag 'audit:high', - 'audit:acceptance' - - require 'puppet/acceptance/windows_utils' - extend Puppet::Acceptance::WindowsUtils - - def package_manifest(name, params, installer_source) - params_str = params.map do |param, value| - value_str = value.to_s - value_str = "\"#{value_str}\"" if value.is_a?(String) - - " #{param} => #{value_str}" - end.join(",\n") - - <<-MANIFEST -package { '#{name}': - source => '#{installer_source}', - #{params_str} -} -MANIFEST - end - - mock_package = { - :name => "MockPackage" - } - - agents.each do |agent| - tmpdir = agent.tmpdir("mock_installer") - installer_location = create_mock_package(agent, tmpdir, mock_package) - - step 'Verify that ensure = present installs the package' do - apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location)) - assert(package_installed?(agent, mock_package[:name]), 'Package succesfully installed') - end - - step 'Verify that ensure = absent removes the package' do - apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :absent}, installer_location)) - assert_equal(false, package_installed?(agent, mock_package[:name]), 'Package successfully Uninstalled') - end - - tmpdir = agent.tmpdir("mock_installer") - mock_package[:name] = "MockPackageWithFile" - mock_package[:install_commands] = 'System.IO.File.ReadAllLines("install.txt");' - installer_location = create_mock_package(agent, tmpdir, mock_package) - - # Since we didn't add the install.txt package the installation should fail with code 1004 - step 'Verify that ensure = present fails when an installer fails with a non-zero exit code' do - apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location)) do |result| - assert_match(/#{mock_package[:name]}/, result.stderr, 'Windows package provider did not fail when the package install failed') - end - end - - step 'Verify that ensure = present installs a package that requires additional resources' do - create_remote_file(agent, "#{tmpdir}/install.txt", 'foobar') - apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location)) - assert(package_installed?(agent, mock_package[:name]), 'Package succesfully installed') - end - - step 'Verify that ensure = absent removes the package that required additional resources' do - apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :absent}, installer_location)) - assert_equal(false, package_installed?(agent, mock_package[:name]), 'Package successfully Uninstalled') - end - end - -end diff --git a/acceptance/tests/resource/package/yum.rb b/acceptance/tests/resource/package/yum.rb deleted file mode 100644 index 3597ad5476..0000000000 --- a/acceptance/tests/resource/package/yum.rb +++ /dev/null @@ -1,203 +0,0 @@ -test_name "test the yum package provider" do - - confine :to, {:platform => /(?:centos|el-|fedora)/}, agents - # Skipping tests if facter finds this is an ec2 host, PUP-7774 - agents.each do |agent| - skip_test('Skipping EC2 Hosts') if fact_on(agent, 'ec2_metadata') - end - - # Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096) - agents.each do |agent| - on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux' - end - - tag 'audit:high', - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - - require 'puppet/acceptance/rpm_util' - extend Puppet::Acceptance::RpmUtils - - epoch_rpm_options = {:pkg => 'epoch', :version => '1.1', :epoch => '1'} - no_epoch_rpm_options = {:pkg => 'guid', :version => '1.0'} - - teardown do - step "cleanup" - agents.each do |agent| - clean_rpm agent, epoch_rpm_options - clean_rpm agent, no_epoch_rpm_options - end - end - - def verify_state(hosts, pkg, state, match) - hosts.each do |agent| - cmd = rpm_provider(agent) - # Note yum and dnf list packages as . - on(agent, "#{cmd} list installed") do |result| - method(match).call(/^#{pkg}\./, result.stdout) - end - end - end - - def verify_present(hosts, pkg) - verify_state(hosts, pkg, '(?!purged|absent)[^\']+', :assert_match) - end - - def verify_absent(hosts, pkg) - verify_state(hosts, pkg, '(?:purged|absent)', :refute_match) - end - - step "Managing a package which does not include an epoch in its version" do - step 'Setup repo and package' - agents.each do |agent| - clean_rpm agent, no_epoch_rpm_options - setup_rpm agent, no_epoch_rpm_options - send_rpm agent, no_epoch_rpm_options - end - - step 'Installing a known package succeeds' do - verify_absent agents, 'guid' - apply_manifest_on(agents, 'package {"guid": ensure => installed}') do |result| - assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}") - end - end - - step 'Removing a known package succeeds' do - verify_present agents, 'guid' - apply_manifest_on(agents, 'package {"guid": ensure => absent}') do |result| - assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}") - end - end - - step 'Installing a specific version of a known package succeeds' do - verify_absent agents, 'guid' - apply_manifest_on(agents, 'package {"guid": ensure => "1.0"}') do |result| - assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}") - end - end - - step 'Removing a specific version of a known package succeeds' do - verify_present agents, 'guid' - apply_manifest_on(agents, 'package {"guid": ensure => absent}') do |result| - assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}") - end - end - - step 'Installing a non-existent version of a known package fails' do - verify_absent agents, 'guid' - apply_manifest_on(agents, 'package {"guid": ensure => "1.1"}') do |result| - refute_match(/Package\[guid\]\/ensure: created/, "#{result.host}: #{result.stdout}") - assert_match("Package[guid]/ensure: change from 'purged' to '1.1' failed", "#{result.host}: #{result.stderr}") - end - verify_absent agents, 'guid' - end - - step 'Installing a non-existent package fails' do - verify_absent agents, 'not_a_package' - apply_manifest_on(agents, 'package {"not_a_package": ensure => present}') do |result| - refute_match(/Package\[not_a_package\]\/ensure: created/, "#{result.host}: #{result.stdout}") - assert_match("Package[not_a_package]/ensure: change from 'purged' to 'present' failed", "#{result.host}: #{result.stderr}") - end - verify_absent agents, 'not_a_package' - end - - step 'Removing a non-existent package succeeds' do - verify_absent agents, 'not_a_package' - apply_manifest_on(agents, 'package {"not_a_package": ensure => absent}') do |result| - refute_match(/Package\[not_a_package\]\/ensure/, "#{result.host}: #{result.stdout}") - assert_match('Applied catalog', "#{result.host}: #{result.stdout}") - end - verify_absent agents, 'not_a_package' - end - - step 'Installing a known package using source succeeds' do - verify_absent agents, 'guid' - apply_manifest_on(agents, "package { 'guid': ensure => installed, install_options => '--nogpgcheck', source=>'/tmp/rpmrepo/RPMS/noarch/guid-1.0-1.noarch.rpm' }") do |result| - assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}") - end - end - end - - ### Epoch tests ### - agents.each do |agent| - step "Managing a package which includes an epoch in its version" do - step "Setup repo and package" do - clean_rpm agent, no_epoch_rpm_options - setup_rpm agent, epoch_rpm_options - send_rpm agent, epoch_rpm_options - end - - step 'Installing a known package with an epoch succeeds' do - verify_absent [agent], 'epoch' - apply_manifest_on(agent, 'package {"epoch": ensure => installed}') do |result| - assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}") - end - end - - step 'Removing a known package with an epoch succeeds' do - verify_present [agent], 'epoch' - apply_manifest_on(agent, 'package {"epoch": ensure => absent}') do |result| - assert_match('Package[epoch]/ensure: removed', "#{result.host}: #{result.stdout}") - end - end - - step "Installing a specific version of a known package with an epoch succeeds when epoch and arch are specified" do - verify_absent [agent], 'epoch' - apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result| - assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}") - end - - apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result| - refute_match(/epoch/, result.stdout) - end - end - - if rpm_provider(agent) == 'dnf' - # Yum requires the arch to be specified whenever epoch is specified. This step is only - # expected to work in DNF. - step "Installing a specific version of a known package with an epoch succeeds when epoch is specified and arch is not" do - step "Remove the package" do - apply_manifest_on(agent, 'package {"epoch": ensure => absent}') - verify_absent [agent], 'epoch' - end - - apply_manifest_on(agent, 'package {"epoch": ensure => "1:1.1-1"}') do |result| - assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}") - end - - apply_manifest_on(agent, 'package {"epoch": ensure => "1:1.1-1"}') do |result| - refute_match(/epoch/, result.stdout) - end - - apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result| - refute_match(/epoch/, result.stdout) - end - end - end - - if rpm_provider(agent) == 'yum' - step "Installing a specified version of a known package with an epoch succeeds without epoch or arch provided" do - # Due to a bug in DNF, epoch is required. This step is only expected to work in Yum. - # See https://bugzilla.redhat.com/show_bug.cgi?id=1286877 - step "Remove the package" do - apply_manifest_on(agent, 'package {"epoch": ensure => absent}') - verify_absent [agent], 'epoch' - end - - apply_manifest_on(agent, 'package {"epoch": ensure => "1.1-1"}') do |result| - assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}") - end - - apply_manifest_on(agent, 'package {"epoch": ensure => "1.1-1"}') do |result| - refute_match(/epoch/, result.stdout) - end - - apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result| - refute_match(/epoch/, result.stdout) - end - end - end - end - end -end diff --git a/acceptance/tests/resource/service/AIX_service_provider.rb b/acceptance/tests/resource/service/AIX_service_provider.rb deleted file mode 100644 index 42ead3e4fe..0000000000 --- a/acceptance/tests/resource/service/AIX_service_provider.rb +++ /dev/null @@ -1,103 +0,0 @@ -test_name 'AIX Service Provider Testing' - -tag 'audit:high', - 'audit:refactor', # Use block style `test_name` - 'audit:acceptance' # Could be done at the integration (or unit) layer though - # actual changing of resources could irreparably damage a - # host running this, or require special permissions. - -confine :to, :platform => 'aix' - -require 'puppet/acceptance/service_utils' -extend Puppet::Acceptance::ServiceUtils - -sloth_daemon_script = <