From 057def0c37be42f2f3b6cd8704547acc8219f959 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 22 Feb 2017 15:44:44 -0800 Subject: [PATCH 1/3] (PUP-7243) Relax temp directory permissions The previous version of this test created a temp directory for the test environment, but the directory is not readable by puppetserver when running as the puppet user. Due to PUP-7102, puppetserver will fail to start if any directory in the environmentpath is unreadable. This version changes the permissions of that directory to 0777. --- acceptance/tests/utf8/utf8-in-function-args.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/acceptance/tests/utf8/utf8-in-function-args.rb b/acceptance/tests/utf8/utf8-in-function-args.rb index bd4ff72cbf6..9739ca51994 100644 --- a/acceptance/tests/utf8/utf8-in-function-args.rb +++ b/acceptance/tests/utf8/utf8-in-function-args.rb @@ -4,13 +4,14 @@ 'eos-4', # PUP-7146 'cumulus', # PUP-7147 'cisco', # PUP-7150 + 'aix', # PUP-7194 + 'huawei', # PUP-7195 ] - confine :except, :platform => /^aix/ # PUP-7190 - confine :except, :platform => /^huawei/ # utf8chars = "€‰ㄘ万竹ÜÖ" utf8chars = "\u20ac\u2030\u3118\u4e07\u7af9\u00dc\u00d6" master_lookup_test_dir = master.tmpdir("lookup_test_dir") + on(master, "chmod -R 777 #{master_lookup_test_dir}") master_opts = { 'main' => { 'hiera_config' => "#{master_lookup_test_dir}/hiera.yaml", @@ -327,7 +328,7 @@ :environment => {:LANG => "en_US.UTF-8"} ) assert_match( - /[[€‰ㄘ万竹ÜÖ], [€‰ㄘ万竹ÜÖ], , ]/, + /[[#{utf8chars}], [#{utf8chars}], , ]/, result.stdout, "match() result unexpected" ) From b5d50dee0549d5c652ebe5b0450be7776ff1c3fe Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 22 Feb 2017 17:34:18 -0800 Subject: [PATCH 2/3] (PUP-7243) Don't start master since it's not needed This commit removes the unnecessary with_puppet_running_on do end block. --- .../tests/utf8/utf8-in-function-args.rb | 410 +++++++++--------- 1 file changed, 204 insertions(+), 206 deletions(-) diff --git a/acceptance/tests/utf8/utf8-in-function-args.rb b/acceptance/tests/utf8/utf8-in-function-args.rb index 9739ca51994..ac2df60a3f8 100644 --- a/acceptance/tests/utf8/utf8-in-function-args.rb +++ b/acceptance/tests/utf8/utf8-in-function-args.rb @@ -18,80 +18,79 @@ 'environmentpath' => "#{master_lookup_test_dir}/environments", }, } - with_puppet_running_on(master, master_opts, master_lookup_test_dir) do - agents.each do |agent| - step 'alert' do - result = on( - agent, - puppet("apply", "-e" "'alert(\"alert #{utf8chars}\")'"), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match( - /#{utf8chars}/, - result.stderr, - "Did not find the utf8 chars." - ) - end - - step 'assert_type' do - on( - agent, - puppet( - "apply", "-e", "'notice(assert_type(String, \"#{utf8chars}\"))'" - ), - { - :environment => {:LANG => "en_US.UTF-8"}, - :acceptable_exit_codes => [0], - } - ) - on( - agent, - puppet("apply", "-e 'notice(assert_type(Float, \"#{utf8chars}\"))'"), - { - :environment => {:LANG => "en_US.UTF-8"}, - :acceptable_exit_codes => [1], - } - ) - end - - step 'filter' do - puppet_cmd = "' - [$a] = [[\"abc\", \"#{utf8chars}\", \"100\"]]; - [$f] = [filter($a) |$p| {$p =~ /#{utf8chars}/}]; - notice(\"f = $f\") - '" - result = on( - agent, - puppet("apply", "-e", puppet_cmd), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match(/#{utf8chars}/, result.stdout, "filter() failed.") - end - - agent_lookup_test_dir = - (agent == master) ? - master_lookup_test_dir : - agent_lookup_test_dir = agent.tmpdir("lookup_test_dir") + agents.each do |agent| + step 'alert' do + result = on( + agent, + puppet("apply", "-e" "'alert(\"alert #{utf8chars}\")'"), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match( + /#{utf8chars}/, + result.stderr, + "Did not find the utf8 chars." + ) + end + + step 'assert_type' do + on( + agent, + puppet( + "apply", "-e", "'notice(assert_type(String, \"#{utf8chars}\"))'" + ), + { + :environment => {:LANG => "en_US.UTF-8"}, + :acceptable_exit_codes => [0], + } + ) + on( + agent, + puppet("apply", "-e 'notice(assert_type(Float, \"#{utf8chars}\"))'"), + { + :environment => {:LANG => "en_US.UTF-8"}, + :acceptable_exit_codes => [1], + } + ) + end + + step 'filter' do + puppet_cmd = "' + [$a] = [[\"abc\", \"#{utf8chars}\", \"100\"]]; + [$f] = [filter($a) |$p| {$p =~ /#{utf8chars}/}]; + notice(\"f = $f\") + '" + result = on( + agent, + puppet("apply", "-e", puppet_cmd), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match(/#{utf8chars}/, result.stdout, "filter() failed.") + end + + agent_lookup_test_dir = + (agent == master) ? + master_lookup_test_dir : + agent_lookup_test_dir = agent.tmpdir("lookup_test_dir") - mod_name = "lookup_module" - mod_key = "#{mod_name}::mod_key_#{utf8chars}" - mod_val = "mod_val_#{utf8chars}" - env_key = "env_key_#{utf8chars}" - env_val = "env_val_#{utf8chars}" - array_key = "array_key_with_utf8_#{utf8chars}" - array_val_2 = "array value 2 with utf8 #{utf8chars}" - scalar_key = "scalar_key_with_utf8_#{utf8chars}" - scalar_val = "scalar value with utf8 #{utf8chars}" - non_key = "non_key_#{utf8chars}" + mod_name = "lookup_module" + mod_key = "#{mod_name}::mod_key_#{utf8chars}" + mod_val = "mod_val_#{utf8chars}" + env_key = "env_key_#{utf8chars}" + env_val = "env_val_#{utf8chars}" + array_key = "array_key_with_utf8_#{utf8chars}" + array_val_2 = "array value 2 with utf8 #{utf8chars}" + scalar_key = "scalar_key_with_utf8_#{utf8chars}" + scalar_val = "scalar value with utf8 #{utf8chars}" + non_key = "non_key_#{utf8chars}" - step 'apply hiera/lookup manifest' do - # I want the banner in the output but - # some results: orig_hiera_config, - # orig_environmentpath from operations - # here are used later, so I don't want - # them local to a step block. - end - lookup_manifest = + step 'apply hiera/lookup manifest' do + # I want the banner in the output but + # some results: orig_hiera_config, + # orig_environmentpath from operations + # here are used later, so I don't want + # them local to a step block. + end + lookup_manifest = < {:LANG => "en_US.UTF-8"} + apply_manifest_on( + agent, lookup_manifest, :environment => {:LANG => "en_US.UTF-8"} + ) + result = on( + agent, + puppet("config", "print hiera_config"), + :environment => {:LANG => "en_US.UTF-8"} + ) + orig_hiera_config = result.stdout.chomp + + result = on( + agent, + puppet("config", "print environmentpath"), + :environment => {:LANG => "en_US.UTF-8"} + ) + orig_environmentpath = result.stdout.chomp + + on( + agent, + puppet( + "config", + "set hiera_config #{agent_lookup_test_dir}/hiera.yaml" + ), + :environment => {:LANG => "en_US.UTF-8"} + ) + on( + agent, + puppet( + "config", "set environmentpath #{agent_lookup_test_dir}/environments" + ), + :environment => {:LANG => "en_US.UTF-8"} + ) + + step 'hiera' do + result = on( + agent, + puppet("apply", "-e", "'notice(hiera(\"#{array_key}\"))'"), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match(/#{array_val_2}/, result.stdout, "hiera array lookup") + + result = on( + agent, + puppet("apply", "-e", "'notice(hiera(\"#{scalar_key}\"))'"), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match(/#{scalar_val}/, result.stdout, "hiera scalar lookup") + + result = on( + agent, + puppet("apply", "-e", "'notice(hiera(\"#{non_key}\"))'"), + { + :acceptable_exit_codes => (0..255), + :environment => {:LANG => "en_US.UTF-8"} + } + ) + assert_match( + /did not find a value for the name '#{non_key}'/, + result.stderr, + "hiera non_key lookup" ) + end + + step 'lookup' do result = on( agent, - puppet("config", "print hiera_config"), + puppet("apply", "-e", "'notice(lookup(\"#{env_key}\"))'"), :environment => {:LANG => "en_US.UTF-8"} ) - orig_hiera_config = result.stdout.chomp + assert_match( + /#{env_val}/, + result.stdout, + "env lookup failed for '#{env_key}'" + ) result = on( agent, - puppet("config", "print environmentpath"), + puppet("apply", "-e", "'notice(lookup(\"#{mod_key}\"))'"), :environment => {:LANG => "en_US.UTF-8"} ) - orig_environmentpath = result.stdout.chomp + assert_match( + /#{mod_val}/, + result.stdout, + "module lookup failed for '#{mod_key}'" + ) on( agent, - puppet( - "config", - "set hiera_config #{agent_lookup_test_dir}/hiera.yaml" - ), + puppet("config", "set hiera_config #{orig_hiera_config}"), :environment => {:LANG => "en_US.UTF-8"} ) on( agent, - puppet( - "config", "set environmentpath #{agent_lookup_test_dir}/environments" - ), + puppet("config", "set environmentpath #{orig_environmentpath}"), :environment => {:LANG => "en_US.UTF-8"} ) - - step 'hiera' do - result = on( - agent, - puppet("apply", "-e", "'notice(hiera(\"#{array_key}\"))'"), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match(/#{array_val_2}/, result.stdout, "hiera array lookup") - - result = on( - agent, - puppet("apply", "-e", "'notice(hiera(\"#{scalar_key}\"))'"), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match(/#{scalar_val}/, result.stdout, "hiera scalar lookup") - - result = on( - agent, - puppet("apply", "-e", "'notice(hiera(\"#{non_key}\"))'"), - { - :acceptable_exit_codes => (0..255), - :environment => {:LANG => "en_US.UTF-8"} - } - ) - assert_match( - /did not find a value for the name '#{non_key}'/, - result.stderr, - "hiera non_key lookup" - ) - end - - step 'lookup' do - result = on( - agent, - puppet("apply", "-e", "'notice(lookup(\"#{env_key}\"))'"), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match( - /#{env_val}/, - result.stdout, - "env lookup failed for '#{env_key}'" - ) - - result = on( - agent, - puppet("apply", "-e", "'notice(lookup(\"#{mod_key}\"))'"), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match( - /#{mod_val}/, - result.stdout, - "module lookup failed for '#{mod_key}'" - ) - - on( - agent, - puppet("config", "set hiera_config #{orig_hiera_config}"), - :environment => {:LANG => "en_US.UTF-8"} - ) - on( - agent, - puppet("config", "set environmentpath #{orig_environmentpath}"), - :environment => {:LANG => "en_US.UTF-8"} - ) - end - - step 'dig' do - hash_string = "{ - a => { - b => [ - { - x => 10, - y => 20, - }, - { - x => 100, - y => \"dig_result = #{utf8chars}\" - }, - ] - } - }" - puppet_cmd = "' - [$v] = [#{hash_string}]; - [$dig_result] = [dig($v, a, b, 1, y)]; - notice($dig_result) - '" - result = on( - agent, - puppet("apply", "-e", puppet_cmd), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match( - /dig_result = #{utf8chars}/, - result.stdout, - "dig() test failed." - ) - end - - step 'match' do - strings = [ - "string1_#{utf8chars}", - "string2_#{utf8chars}", - "string3_no-utf8", - "string4_no-utf8" - ] - puppet_cmd = "' - [$vec] = [#{strings}]; - [$found] = [match($vec, /#{utf8chars}/)]; - notice($found) - '" - result = on( - agent, - puppet("apply", "-e", puppet_cmd), - :environment => {:LANG => "en_US.UTF-8"} - ) - assert_match( - /[[#{utf8chars}], [#{utf8chars}], , ]/, - result.stdout, - "match() result unexpected" - ) - end + end + + step 'dig' do + hash_string = "{ + a => { + b => [ + { + x => 10, + y => 20, + }, + { + x => 100, + y => \"dig_result = #{utf8chars}\" + }, + ] + } + }" + puppet_cmd = "' + [$v] = [#{hash_string}]; + [$dig_result] = [dig($v, a, b, 1, y)]; + notice($dig_result) + '" + result = on( + agent, + puppet("apply", "-e", puppet_cmd), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match( + /dig_result = #{utf8chars}/, + result.stdout, + "dig() test failed." + ) + end + + step 'match' do + strings = [ + "string1_#{utf8chars}", + "string2_#{utf8chars}", + "string3_no-utf8", + "string4_no-utf8" + ] + puppet_cmd = "' + [$vec] = [#{strings}]; + [$found] = [match($vec, /#{utf8chars}/)]; + notice($found) + '" + result = on( + agent, + puppet("apply", "-e", puppet_cmd), + :environment => {:LANG => "en_US.UTF-8"} + ) + assert_match( + /[[#{utf8chars}], [#{utf8chars}], , ]/, + result.stdout, + "match() result unexpected" + ) end end end From 59824dd6715e5186e77ac83793a8508052eacb9b Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 22 Feb 2017 21:50:32 -0800 Subject: [PATCH 3/3] (PUP-7243) Remove unneeded variables and whitespace Remove unneeded variables since we're no longer starting puppetserver during the test. Also remove trailing whitespace. --- .../tests/utf8/utf8-in-function-args.rb | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/acceptance/tests/utf8/utf8-in-function-args.rb b/acceptance/tests/utf8/utf8-in-function-args.rb index ac2df60a3f8..f750fa2a768 100644 --- a/acceptance/tests/utf8/utf8-in-function-args.rb +++ b/acceptance/tests/utf8/utf8-in-function-args.rb @@ -10,14 +10,6 @@ # utf8chars = "€‰ㄘ万竹ÜÖ" utf8chars = "\u20ac\u2030\u3118\u4e07\u7af9\u00dc\u00d6" - master_lookup_test_dir = master.tmpdir("lookup_test_dir") - on(master, "chmod -R 777 #{master_lookup_test_dir}") - master_opts = { - 'main' => { - 'hiera_config' => "#{master_lookup_test_dir}/hiera.yaml", - 'environmentpath' => "#{master_lookup_test_dir}/environments", - }, - } agents.each do |agent| step 'alert' do result = on( @@ -31,7 +23,7 @@ "Did not find the utf8 chars." ) end - + step 'assert_type' do on( agent, @@ -52,7 +44,7 @@ } ) end - + step 'filter' do puppet_cmd = "' [$a] = [[\"abc\", \"#{utf8chars}\", \"100\"]]; @@ -66,11 +58,8 @@ ) assert_match(/#{utf8chars}/, result.stdout, "filter() failed.") end - - agent_lookup_test_dir = - (agent == master) ? - master_lookup_test_dir : - agent_lookup_test_dir = agent.tmpdir("lookup_test_dir") + + agent_lookup_test_dir = agent.tmpdir("lookup_test_dir") mod_name = "lookup_module" mod_key = "#{mod_name}::mod_key_#{utf8chars}" @@ -84,7 +73,7 @@ non_key = "non_key_#{utf8chars}" step 'apply hiera/lookup manifest' do - # I want the banner in the output but + # I want the banner in the output but # some results: orig_hiera_config, # orig_environmentpath from operations # here are used later, so I don't want @@ -121,7 +110,7 @@ } file { "#{agent_lookup_test_dir}/environments/production/modules/#{mod_name}/data/common.yaml" : - ensure => "file", + ensure => "file", mode => "0644", content => '--- #{mod_key}: #{mod_val} @@ -276,7 +265,7 @@ :environment => {:LANG => "en_US.UTF-8"} ) end - + step 'dig' do hash_string = "{ a => { @@ -308,7 +297,7 @@ "dig() test failed." ) end - + step 'match' do strings = [ "string1_#{utf8chars}",