Skip to content

Commit 200b862

Browse files
committed
(BKR-914) Add workaround for beaker bug BKR-914
The Windows 2012 R2 VMPooler templates were recently updated due to the older version not populating environment variables correctly. However this exposed an issue in Beaker (BKR-914) whereby it's `get_env_var` function was far too loose in its pattern matching causing multiple lines to be returned for a single env var. This then caused newline characters to be injected into the `~/.ssh/environment` file, which then poluted calls to STDOUT and subsequently any tests that depended on parsing STDOUT could potentially fail. This commit adds workarounds to this issue until BKR-914 is fixed and published. - The output from a `get_env_var` is sanitised and if required, additional regex is injected to get the required effect from the `env | grep #{key}` call in Beaker - An existance check is added so that the CommonProgramFiles env var is only added if it does not exist. This avoids modifying the environment unncessarily. This commit can be partially revertted once BKR-914 is resolved and published.
1 parent 102185b commit 200b862

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

spec/spec_helper_acceptance.rb

+24-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,30 @@
2727
unless ENV['MODULE_provision'] == 'no'
2828
agents.each do |agent|
2929
# Emit CommonProgramFiles environment variable
30-
program_files = agent.get_env_var('ProgramFiles').split('=')[1]
31-
agent.add_env_var('CommonProgramFiles', "#{program_files}\\Common Files")
30+
common_program_files = agent.get_env_var('CommonProgramFiles')
31+
32+
# Workarounds due to BKR-914
33+
# - newline chars indicate matching more than one env var
34+
# - env var key matching is very loose. e.g. CommonProgramFiles(x86) can be returned
35+
common_program_files = "" if common_program_files.include?("\n")
36+
common_program_files = "" unless common_program_files.start_with?("CommonProgramFiles=")
37+
# If the env var is not found use a workaround to inject regex into the grep call
38+
common_program_files = agent.get_env_var('^CommonProgramFiles=') if common_program_files == ""
39+
40+
if common_program_files == ""
41+
program_files = agent.get_env_var('PROGRAMFILES')
42+
43+
# Workarounds due to BKR-914
44+
# - newline chars indicate matching more than one env var
45+
# - env var key matching is very loose. e.g. ProgramFiles(x86) can be returned
46+
program_files = "" if program_files.include?("\n")
47+
program_files = "" unless program_files.start_with?("PROGRAMFILES=")
48+
# If the env var is not found use a workaround to inject regex into the grep call
49+
program_files = agent.get_env_var('^PROGRAMFILES=') if program_files == ""
50+
51+
program_files = program_files.split('=')[1]
52+
agent.add_env_var('CommonProgramFiles', "#{program_files}\\Common Files")
53+
end
3254

3355
# Install Forge certs to allow for PMT installation.
3456
install_ca_certs(agent)

0 commit comments

Comments
 (0)