diff --git a/acceptance/tests/environment/can_enumerate_environments.rb b/acceptance/tests/environment/can_enumerate_environments.rb index e09718f52..ee033d93a 100644 --- a/acceptance/tests/environment/can_enumerate_environments.rb +++ b/acceptance/tests/environment/can_enumerate_environments.rb @@ -1,62 +1,68 @@ test_name "Can enumerate environments via an HTTP endpoint" def master_port(agent) setting_on(agent, "agent", "masterport") 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}:#{master_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 -sg --cert \"#{cert_path}\" --key \"#{key_path}\" -k -H '#{headers}'" on agent, "#{curl_base} '#{url}'", &block end environments_dir = master.tmpdir("environments") apply_manifest_on(master, <<-MANIFEST) File { ensure => directory, - owner => puppet, - mode => 0700, + owner => #{master['user']}, + group => #{master['group']}, + mode => 0750, } file { "#{environments_dir}":; "#{environments_dir}/env1":; "#{environments_dir}/env2":; } MANIFEST -with_puppet_running_on(master, { +master_opts = { :master => { :environmentpath => environments_dir } -}) do +} +if master.is_pe? + master_opts[:master][:basemodulepath] = master['sitemoduledir'] +end + +with_puppet_running_on(master, master_opts) do agents.each do |agent| step "Ensure that an unauthenticated client cannot access the environments list" do on agent, "curl -ksv https://#{master}:#{master_port(agent)}/v2.0/environments", :acceptable_exit_codes => [0,7] do assert_match(/< HTTP\/1\.\d 403/, stderr) end end step "Ensure that an authenticated client can retrieve the list of environments" do curl_master_from(agent, '/v2.0/environments') do data = JSON.parse(stdout) assert_equal(["env1", "env2"], data["environments"].keys.sort) end end end end diff --git a/acceptance/tests/environment/cmdline_overrides_environment.rb b/acceptance/tests/environment/cmdline_overrides_environment.rb index ed926bc86..09319f749 100644 --- a/acceptance/tests/environment/cmdline_overrides_environment.rb +++ b/acceptance/tests/environment/cmdline_overrides_environment.rb @@ -1,266 +1,293 @@ test_name "Commandline modulepath and manifest settings override environment" testdir = master.tmpdir('cmdline_and_environment') environmentpath = "#{testdir}/environments" modulepath = "#{testdir}/modules" manifests = "#{testdir}/manifests" sitepp = "#{manifests}/site.pp" other_manifestdir = "#{testdir}/other_manifests" other_sitepp = "#{other_manifestdir}/site.pp" other_modulepath = "#{testdir}/some_other_modulepath" cmdline_manifest = "#{testdir}/cmdline.pp" step "Prepare manifests and modules" apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) File { ensure => directory, - owner => puppet, - mode => 0700, + owner => #{master['user']}, + group => #{master['group']}, + mode => 0750, } ############################################## # A production directory environment file { "#{testdir}":; "#{environmentpath}":; "#{environmentpath}/production":; "#{environmentpath}/production/manifests":; "#{environmentpath}/production/modules":; "#{environmentpath}/production/modules/amod":; "#{environmentpath}/production/modules/amod/manifests":; } file { "#{environmentpath}/production/modules/amod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class amod { notify { "amod from production environment": } }' } file { "#{environmentpath}/production/manifests/production.pp": ensure => file, + mode => 0640, content => ' notify { "in production.pp": } include amod ' } ############################################################## # To be set as default manifests and modulepath in puppet.conf file { "#{modulepath}":; "#{modulepath}/amod/":; "#{modulepath}/amod/manifests":; } file { "#{modulepath}/amod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class amod { notify { "amod from modulepath": } }' } file { "#{manifests}": } file { "#{sitepp}": ensure => file, + mode => 0640, content => ' notify { "in site.pp": } include amod ' } file { "#{other_manifestdir}": } file { "#{other_sitepp}": ensure => file, + mode => 0640, content => ' notify { "in other manifestdir site.pp": } include amod ' } ################################ # To be specified on commandline file { "#{other_modulepath}":; "#{other_modulepath}/amod/":; "#{other_modulepath}/amod/manifests":; } file { "#{other_modulepath}/amod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class amod { notify { "amod from commandline modulepath": } }' } file { "#{cmdline_manifest}": ensure => file, + mode => 0640, content => ' notify { "in cmdline.pp": } include amod ' } MANIFEST # Note: this is the semantics seen with legacy environments if commandline # manifest/modulepath are set. step "CASE 1: puppet master with --manifest and --modulepath overrides set production directory environment" do - master_opts = { - 'master' => { - 'environmentpath' => environmentpath, - 'manifest' => sitepp, - 'modulepath' => modulepath, + if master.is_pe? + step "Skipping for Passenger (PE) setup; since the equivalent of a commandline override would be adding the setting to config.ru, which seems like a very odd thing to do." + else + master_opts = { + 'master' => { + 'environmentpath' => environmentpath, + 'manifest' => sitepp, + 'modulepath' => modulepath, + } } - } - - master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifest=#{cmdline_manifest} --modulepath=#{other_modulepath}") - with_puppet_running_on master, master_opts_with_cmdline, testdir do - agents.each do |agent| - on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do - assert_match(/in cmdline\.pp/, stdout) - assert_match(/amod from commandline modulepath/, stdout) - assert_no_match(/production/, stdout) - end - - step "CASE 1a: even if environment is specified" - on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2]) do - assert_match(/in cmdline\.pp/, stdout) - assert_match(/amod from commandline modulepath/, stdout) - assert_no_match(/production/, stdout) - end - end - end - step "CASE 2: or if you set --manifestdir" do - master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifestdir=#{other_manifestdir} --modulepath=#{other_modulepath}") - step "CASE 2: it is ignored if manifest is set in puppet.conf to something not using $manifestdir" + master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifest=#{cmdline_manifest} --modulepath=#{other_modulepath}") with_puppet_running_on master, master_opts_with_cmdline, testdir do agents.each do |agent| - on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2]) do - assert_match(/in production\.pp/, stdout) + on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do + assert_match(/in cmdline\.pp/, stdout) assert_match(/amod from commandline modulepath/, stdout) + assert_no_match(/production/, stdout) end - end - end - step "CASE 2a: but does pull in the default manifest via manifestdir if manifest is not set" - master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifestdir=#{other_manifestdir} --modulepath=#{other_modulepath}") - master_opts_with_cmdline['master'].delete('manifest') - with_puppet_running_on master, master_opts_with_cmdline, testdir do - agents.each do |agent| - on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2]) do - assert_match(/in other manifestdir site\.pp/, stdout) + step "CASE 1a: even if environment is specified" + on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2]) do + assert_match(/in cmdline\.pp/, stdout) assert_match(/amod from commandline modulepath/, stdout) assert_no_match(/production/, stdout) end end end + + step "CASE 2: or if you set --manifestdir" do + master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifestdir=#{other_manifestdir} --modulepath=#{other_modulepath}") + step "CASE 2: it is ignored if manifest is set in puppet.conf to something not using $manifestdir" + with_puppet_running_on master, master_opts_with_cmdline, testdir do + agents.each do |agent| + on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2]) do + assert_match(/in production\.pp/, stdout) + assert_match(/amod from commandline modulepath/, stdout) + end + end + end + + step "CASE 2a: but does pull in the default manifest via manifestdir if manifest is not set" + master_opts_with_cmdline = master_opts.merge(:__commandline_args__ => "--manifestdir=#{other_manifestdir} --modulepath=#{other_modulepath}") + master_opts_with_cmdline['master'].delete('manifest') + with_puppet_running_on master, master_opts_with_cmdline, testdir do + agents.each do |agent| + on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2]) do + assert_match(/in other manifestdir site\.pp/, stdout) + assert_match(/amod from commandline modulepath/, stdout) + assert_no_match(/production/, stdout) + end + end + end + end end end step "CASE 3: puppet master with manifest and modulepath set in puppet.conf is overriden by an existing and set production directory environment" do master_opts = { 'master' => { 'environmentpath' => environmentpath, 'manifest' => sitepp, 'modulepath' => modulepath, } } + if master.is_pe? + master_opts['master']['basemodulepath'] = master['sitemoduledir'] + end with_puppet_running_on master, master_opts, testdir do agents.each do |agent| step "CASE 3: this case is unfortunate, but will be irrelevant when we remove legacyenv in 4.0" on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do assert_match(/in production\.pp/, stdout) assert_match(/amod from production environment/, stdout) end - step "CASE 3a:if environment is specified" + step "CASE 3a: if environment is specified" on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2]) do assert_match(/in production\.pp/, stdout) assert_match(/amod from production environment/, stdout) end end end end step "CASE 4: puppet master with default manifest, modulepath, environment, environmentpath and an existing '#{environmentpath}/production' directory environment that has not been set" do - ssldir = on(master, puppet("master --configprint ssldir")).stdout.chomp - master_opts = { - :__commandline_args__ => "--confdir=#{testdir} --ssldir=#{ssldir}" - } - with_puppet_running_on master, master_opts, testdir do - agents.each do |agent| - step "CASE 4: #{environmentpath}/production directory environment does not take precedence because default environmentpath is ''" - on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do - assert_match(/in site\.pp/, stdout) - assert_match(/amod from modulepath/, stdout) - end - on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2]) do - assert_match(/in site\.pp/, stdout) - assert_match(/amod from modulepath/, stdout) + + if master.is_pe? + step "Skipping for PE because PE requires most of the existing puppet.conf and /etc/puppetlabs/puppet configuration, and we cannot simply point to a new conf directory." + else + ssldir = on(master, puppet("master --configprint ssldir")).stdout.chomp + master_opts = { + :__commandline_args__ => "--confdir=#{testdir} --ssldir=#{ssldir}" + } + + with_puppet_running_on master, master_opts, testdir do + agents.each do |agent| + step "CASE 4: #{environmentpath}/production directory environment does not take precedence because default environmentpath is ''" + on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do + assert_match(/in site\.pp/, stdout) + assert_match(/amod from modulepath/, stdout) + end + on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2]) do + assert_match(/in site\.pp/, stdout) + assert_match(/amod from modulepath/, stdout) + end end end end end step "CASE 5: puppet master with explicit dynamic environment settings and empty environmentpath" do step "CASE 5: Prepare an additional modulepath module" apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) File { ensure => directory, - owner => puppet, - mode => 0700, + owner => #{master['user']}, + group => #{master['group']}, + mode => 0750, } - + # A second module in another modules dir file { "#{other_modulepath}":; "#{other_modulepath}/bmod/":; "#{other_modulepath}/bmod/manifests":; } file { "#{other_modulepath}/bmod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class bmod { notify { "bmod from other modulepath": } }' } - + file { "#{environmentpath}/production/manifests/production.pp": ensure => file, + mode => 0640, content => ' notify { "in production.pp": } include amod include bmod ' } MANIFEST master_opts = { - 'master' => { - 'manifest' => "#{environmentpath}/$environment/manifests", - 'modulepath' => "#{environmentpath}/$environment/modules:#{other_modulepath}", - } + 'master' => { + 'manifest' => "#{environmentpath}/$environment/manifests", + 'modulepath' => "#{environmentpath}/$environment/modules:#{other_modulepath}", } - + } + if master.is_pe? + master_opts['master']['modulepath'] << ":#{master['sitemoduledir']}" + end + with_puppet_running_on master, master_opts, testdir do agents.each do |agent| step "CASE 5: pulls in the production environment based on $environment default" on(agent, puppet("agent -t --server #{master}"), :acceptable_exit_codes => [2] ) do assert_match(/in production\.pp/, stdout) assert_match(/amod from production environment/, stdout) step "CASE 5: and sees modules located in later elements of the modulepath (which would not be seen by a directory env (PUP-2158)" assert_match(/bmod from other modulepath/, stdout) end step "CASE 5a: pulls in the production environment when explicitly set" on(agent, puppet("agent -t --server #{master} --environment production"), :acceptable_exit_codes => [2] ) do assert_match(/in production\.pp/, stdout) assert_match(/amod from production environment/, stdout) step "CASE 5a: and sees modules located in later elements of the modulepath (which would not be seen by a directory env (PUP-2158)" assert_match(/bmod from other modulepath/, stdout) end end end end diff --git a/acceptance/tests/environment/directory_environment_with_environment_conf.rb b/acceptance/tests/environment/directory_environment_with_environment_conf.rb index 9e32679ca..f1d75ce2b 100644 --- a/acceptance/tests/environment/directory_environment_with_environment_conf.rb +++ b/acceptance/tests/environment/directory_environment_with_environment_conf.rb @@ -1,99 +1,109 @@ test_name 'Use a directory environment from environmentpath with an environment.conf' testdir = master.tmpdir('use-environment-conf') absolute_manifestdir = "#{testdir}/manifests" absolute_modulesdir = "#{testdir}/absolute-modules" absolute_globalsdir = "#{testdir}/global-modules" apply_manifest_on(master, <<-MANIFEST, :catch_failures => true) File { ensure => directory, - owner => puppet, - mode => 0700, + owner => #{master['user']}, + group => #{master['group']}, + mode => 0750, } file { "#{testdir}":; "#{testdir}/environments":; "#{testdir}/environments/direnv":; "#{testdir}/environments/direnv/environment.conf": ensure => file, + mode => 0640, content => ' manifest=#{absolute_manifestdir} modulepath=relative-modules:#{absolute_modulesdir}:$basemodulepath config_version=version_script.sh ' ; "#{testdir}/environments/direnv/relative-modules":; "#{testdir}/environments/direnv/relative-modules/relmod":; "#{testdir}/environments/direnv/relative-modules/relmod/manifests":; "#{testdir}/environments/direnv/relative-modules/relmod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class relmod { notify { "included relmod": } }' ; "#{testdir}/environments/direnv/version_script.sh": ensure => file, + mode => 0750, content => '#!/usr/bin/env sh echo "ver123" ' ; "#{absolute_manifestdir}":; "#{absolute_manifestdir}/site.pp": ensure => file, + mode => 0640, content => ' notify { "direnv site.pp": } include relmod include absmod include globalmod ' ; "#{absolute_modulesdir}":; "#{absolute_modulesdir}/absmod":; "#{absolute_modulesdir}/absmod/manifests":; "#{absolute_modulesdir}/absmod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class absmod { notify { "included absmod": } }' ; "#{absolute_globalsdir}":; "#{absolute_globalsdir}/globalmod":; "#{absolute_globalsdir}/globalmod/manifests":; "#{absolute_globalsdir}/globalmod/manifests/init.pp": ensure => file, + mode => 0640, content => 'class globalmod { notify { "included globalmod": } }' ; } MANIFEST master_opts = { 'master' => { 'environmentpath' => "#{testdir}/environments", 'basemodulepath' => "#{absolute_globalsdir}", } } +if master.is_pe? + master_opts['master']['basemodulepath'] << ":#{master['sitemoduledir']}" +end with_puppet_running_on master, master_opts, testdir do agents.each do |agent| on(agent, puppet("agent", "-t", "--server", master, "--environment", "direnv"), :acceptable_exit_codes => [2]) do |result| assert_match(/direnv site.pp/, result.stdout) assert_match(/included relmod/, result.stdout) assert_match(/included absmod/, result.stdout) assert_match(/included globalmod/, result.stdout) assert_match(/Applying.*ver123/, result.stdout) end end end diff --git a/acceptance/tests/environment/dynamic_environments.rb b/acceptance/tests/environment/dynamic_environments.rb index d0fcca786..f1994744d 100644 --- a/acceptance/tests/environment/dynamic_environments.rb +++ b/acceptance/tests/environment/dynamic_environments.rb @@ -1,130 +1,138 @@ test_name "Dynamic Environments" testdir = master.tmpdir('dynamic-environment') environmentsdir = "#{testdir}/environments" step "Prepare manifests and modules" def an_environment(envdir, env) content = <<-ENVIRONMENT #################### # #{env} environment file { "#{envdir}/#{env}":; "#{envdir}/#{env}/hiera":; "#{envdir}/#{env}/manifests":; "#{envdir}/#{env}/modules":; "#{envdir}/#{env}/modules/amod":; "#{envdir}/#{env}/modules/amod/manifests":; } file { "#{envdir}/#{env}/hiera/#{env}.yaml": ensure => file, + mode => 0640, content => 'foo: foo-#{env}', } file { "#{envdir}/#{env}/hiera/common.yaml": ensure => file, + mode => 0640, content => 'foo: foo-common', } file { "#{envdir}/#{env}/manifests/site.pp": ensure => file, + mode => 0640, content => ' notify { "#{env}-site.pp": } notify { "hiera": message => hiera(foo), } include amod ' } file { "#{envdir}/#{env}/modules/amod/manifests/init.pp": ensure => file, + mode => 0640, content => ' class amod { notify { "#{env}-amod": } } ' } ENVIRONMENT end manifest = <<-MANIFEST File { ensure => directory, owner => #{master['user']}, group => #{master['group']}, mode => 0750, } file { "#{testdir}":; "#{environmentsdir}":; } file { "#{testdir}/hiera.yaml": ensure => file, + mode => 0640, content => ' --- :backends: yaml :yaml: :datadir: "#{environmentsdir}/%{environment}/hiera" :hierarchy: - "%{environment}" - common ', } #{an_environment(environmentsdir, 'production')} #{an_environment(environmentsdir, 'testing')} MANIFEST apply_manifest_on(master, manifest, :catch_failures => true) def test_on_agents(environment, default_env = false) agents.each do |agent| environment_switch = "--environment #{environment}" if !default_env on(agent, puppet("agent -t --server #{master}", environment_switch), :acceptable_exit_codes => [2] ) do assert_match(/#{environment}-site.pp/, stdout) assert_match(/foo-#{environment}/, stdout) assert_match(/#{environment}-amod/, stdout) end end end ssldir = on(master, puppet("master --configprint ssldir")).stdout.chomp common_opts = { 'modulepath' => "#{testdir}/environments/$environment/modules", 'hiera_config' => "#{testdir}/hiera.yaml", } +if master.is_pe? + common_opts['modulepath'] << ":#{master['sitemoduledir']}" +end master_opts = { 'master' => { 'manifest' => "#{testdir}/environments/$environment/manifests/site.pp", }.merge(common_opts) } with_puppet_running_on master, master_opts, testdir do step "Agent run with default environment" test_on_agents('production', true) end master_opts = { 'master' => { 'manifest' => "#{testdir}/environments/$environment/manifests/site.pp", }.merge(common_opts) } with_puppet_running_on master, master_opts, testdir do step "Agent run with testing environment" test_on_agents('testing') step "And then agent run with another environment but the same master process" test_on_agents('production') end master_opts = { 'master' => { 'manifestdir' => "#{testdir}/environments/$environment/manifests", }.merge(common_opts) } with_puppet_running_on master, master_opts, testdir do step "Agent run with testing environment and manifestdir set instead of manifest" test_on_agents('testing') end diff --git a/acceptance/tests/environment/use_environment_from_environmentpath.rb b/acceptance/tests/environment/use_environment_from_environmentpath.rb index b4edce410..479ed5ce2 100644 --- a/acceptance/tests/environment/use_environment_from_environmentpath.rb +++ b/acceptance/tests/environment/use_environment_from_environmentpath.rb @@ -1,164 +1,177 @@ test_name "Use environments from the environmentpath" testdir = master.tmpdir('use_environmentpath') def generate_environment(path_to_env, environment) env_content = <<-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 module_content = <<-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) manifest_content = <<-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 => puppet, - mode => 0700, + owner => #{master['user']}, + group => #{master['group']}, + mode => 0750, } 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)} } MANIFEST def run_with_environment(agent, environment, options = {}) expected_exit_code = options[:expected_exit_code] || 2 expected_strings = options[:expected_strings] step "running an agent in environment '#{environment}'" atmp = agent.tmpdir("use_environmentpath_#{environment}") agent_config = [ "-t", "--server", master, ] agent_config << '--environment' << environment if environment 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 on agent, "rm -rf #{atmp}" 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, nil, :expected_exit_code => 0) do |tmpdir, result| - assert_no_match(/module-atmp/, result.stdout, "module-atmp was included despite no environment being loaded") - assert_match(/Loading facts.*globalmod/, result.stdout) + if master.is_pe? + step("This test cannot run if the production environment directory does not exist, because the fallback production environment puppet creates has an empty modulepath and PE cannot run without it's basemodulepath in /opt. PUP-2519, which implicitly creates the production environment directory should allow this to run again") + else + run_with_environment(agent, nil, :expected_exit_code => 0) do |tmpdir, result| + assert_no_match(/module-atmp/, result.stdout, "module-atmp was included despite no environment being loaded") + assert_match(/Loading facts.*globalmod/, result.stdout) + end end end end diff --git a/acceptance/tests/modules/install/with_environment.rb b/acceptance/tests/modules/install/with_environment.rb index 4888f153f..73257713a 100644 --- a/acceptance/tests/modules/install/with_environment.rb +++ b/acceptance/tests/modules/install/with_environment.rb @@ -1,70 +1,70 @@ test_name 'puppet module install (with environment)' require 'puppet/acceptance/module_utils' extend Puppet::Acceptance::ModuleUtils module_author = "pmtacceptance" module_name = "nginx" 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) end step 'Setup' stub_forge_on(master) puppet_conf = generate_base_legacy_and_directory_environments(master['puppetpath']) check_module_install_in = lambda do |environment_path, module_install_args| on master, "puppet module install #{module_author}-#{module_name} --config=#{puppet_conf} #{module_install_args}" do assert_module_installed_ui(stdout, module_author, module_name) assert_match(/#{environment_path}/, stdout, "Notice of non default install path was not displayed") end assert_module_installed_on_disk(master, "#{environment_path}", module_name) end step 'Install a module into a non default legacy environment' do check_module_install_in.call("#{master['puppetpath']}/legacyenv/modules", "--environment=legacyenv") end step 'Enable directory environments' do on master, puppet("config", "set", "environmentpath", "#{master['puppetpath']}/environments", "--section", "main", "--config", puppet_conf) end step 'Install a module into a non default directory environment' do check_module_install_in.call("#{master['puppetpath']}/environments/direnv/modules", "--environment=direnv") end step 'Prepare a separate modulepath' modulepath_dir = master.tmpdir("modulepath") apply_manifest_on(master, <<-MANIFEST , :catch_failures => true) file { [ '#{master['puppetpath']}/environments/production', '#{modulepath_dir}', ]: ensure => directory, - owner => puppet, + owner => #{master['user']}, } MANIFEST step "Install a module into --modulepath #{modulepath_dir} despite the implicit production directory env existing" do check_module_install_in.call(modulepath_dir, "--modulepath=#{modulepath_dir}") end step "Uninstall so we can try a different scenario" do on master, "puppet module uninstall #{module_author}-#{module_name} --config=#{puppet_conf} --modulepath=#{modulepath_dir}" end step "Install a module into --modulepath #{modulepath_dir} with a directory env specified" do check_module_install_in.call(modulepath_dir, "--modulepath=#{modulepath_dir} --environment=direnv") end