(FACT-2648) Escaped path strings for test runs on localhost
Andrei Filipovici
3 years ago
126 | 126 | '/bin/bash' |
127 | 127 | end |
128 | 128 | end |
129 | ||
130 | def escape_paths(host, str) | |
131 | if host['platform'] =~ /windows/ && !host.is_cygwin? | |
132 | str.gsub('\\') { '\\\\' } | |
133 | else | |
134 | str | |
135 | end | |
136 | end | |
129 | 137 | end |
130 | 138 | end |
131 | 139 | end |
66 | 66 | step "should create a cached-custom-facts cache file that containt fact information" do |
67 | 67 | result = agent.file_exist?("#{cache_folder}/cached-custom-facts") |
68 | 68 | assert_equal(true, result) |
69 | cat_output = agent.cat( "#{cache_folder}/cached-custom-facts") | |
69 | cat_output = agent.cat("#{cache_folder}/cached-custom-facts") | |
70 | 70 | assert_match(cached_file_content.chomp, cat_output.strip, 'Expected cached custom fact file to contain fact information') |
71 | 71 | end |
72 | 72 |
15 | 15 | fact1_value = 'fact1_value' |
16 | 16 | fact2_value = 'fact2_value' |
17 | 17 | external_filename = 'text.yaml' |
18 | external_dir1 = agent.tmpdir('external_dir') | |
18 | external_dir1 = agent.tmpdir('external_dir1') | |
19 | 19 | external_fact_file1 = File.join(external_dir1, external_filename) |
20 | external_dir2 = agent.tmpdir('external_dir') | |
20 | external_dir2 = agent.tmpdir('external_dir2') | |
21 | 21 | external_fact_file2 = File.join(external_dir2, external_filename) |
22 | 22 | create_remote_file(agent, external_fact_file1, "#{fact1}: #{fact1_value}") |
23 | 23 | create_remote_file(agent, external_fact_file2, "#{fact2}: #{fact2_value}") |
37 | 37 | custom-dir : "#{custom_config_dir}", |
38 | 38 | } |
39 | 39 | EOM |
40 | ||
41 | config_content = escape_paths(agent, config_content) | |
40 | 42 | create_remote_file(agent, config_file, config_content) |
41 | 43 | |
42 | 44 | teardown do |
25 | 25 | custom-dir : "#{custom_dir}", |
26 | 26 | } |
27 | 27 | EOM |
28 | config_content = escape_paths(agent, config_content) | |
28 | 29 | create_remote_file(agent, config_file, config_content) |
29 | 30 | |
30 | 31 | teardown do |
37 | 37 | custom-dir : [ "#{custom_dir_1}", "#{custom_dir_2}" ], |
38 | 38 | } |
39 | 39 | EOM |
40 | config_content = escape_paths(agent, config_content) | |
40 | 41 | create_remote_file(agent, config_file, config_content) |
41 | 42 | |
42 | 43 | teardown do |
21 | 21 | external-dir : "#{external_config_dir}", |
22 | 22 | } |
23 | 23 | EOM |
24 | config_content = escape_paths(agent, config_content) | |
24 | 25 | create_remote_file(agent, config_file, config_content) |
25 | 26 | |
26 | 27 | teardown do |
20 | 20 | external-dir : "#{external_dir}", |
21 | 21 | } |
22 | 22 | EOM |
23 | config_content = escape_paths(agent, config_content) | |
23 | 24 | create_remote_file(agent, config_file, config_content) |
24 | 25 | |
25 | 26 | teardown do |
26 | 26 | external-dir : [ "#{external_dir_1}", "#{external_dir_2}" ], |
27 | 27 | } |
28 | 28 | EOM |
29 | config_content = escape_paths(agent, config_content) | |
29 | 30 | create_remote_file(agent, config_file, config_content) |
30 | 31 | |
31 | 32 | teardown do |
40 | 40 | end |
41 | 41 | |
42 | 42 | step "Agent #{agent}: create facter.conf, external fact, and custom fact files" do |
43 | ||
44 | create_remote_file(agent, facter_conf_default_path, <<-FILE) | |
43 | config_content = <<-FILE | |
45 | 44 | global : { |
46 | 45 | external-dir : ["#{ext_fact_dir1}", "#{ext_fact_dir2}"], |
47 | 46 | custom-dir : ["#{cust_fact_dir}"] |
48 | 47 | } |
49 | 48 | FILE |
49 | ||
50 | config_content = escape_paths(agent, config_content) | |
51 | create_remote_file(agent, facter_conf_default_path, config_content) | |
50 | 52 | |
51 | 53 | create_remote_file(agent, ext_path1, <<-FILE) |
52 | 54 | externalfact1: 'This is external fact 1 in #{ext_fact_dir1} directory' |
67 | 69 | |
68 | 70 | step "running `puppet facts` should load the config file automatically and search all external-dir and custom-dir paths" do |
69 | 71 | on(agent, puppet('facts')) do |puppet_facts_output| |
70 | assert_match(/This is external fact 1 in #{ext_fact_dir1} directory/, puppet_facts_output.stdout, "Expected external fact") | |
71 | assert_match(/This is external fact 2 in #{ext_fact_dir2} directory/, puppet_facts_output.stdout, "Expected external fact") | |
72 | assert_match(/This is a custom fact in #{cust_fact_dir} directory/, puppet_facts_output.stdout, "Expected custom fact") | |
72 | ||
73 | assert_match(/This is external fact 1 in #{escape_paths(agent, ext_fact_dir1)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected external fact") | |
74 | assert_match(/This is external fact 2 in #{escape_paths(agent, ext_fact_dir2)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected external fact") | |
75 | assert_match(/This is a custom fact in #{escape_paths(agent, cust_fact_dir)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected custom fact") | |
73 | 76 | end |
74 | 77 | end |
75 | 78 | end |