Skip to content

Commit eb7620b

Browse files
committed
[Test] Mock cookbook virtualenv for Docker tests on AL 2023.
This is required to execute system tests on Docker for AL 2023 that depend on the cookbook virtualenv, such as the CloudWatch Agent tests.
1 parent 48044c2 commit eb7620b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cookbooks/aws-parallelcluster-tests/recipes/docker_mock.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@
7474
end
7575
end
7676

77+
if alinux2023_on_docker?
78+
# Install Python 3.12 for AL2023 Docker tests
79+
package 'python3.12'
80+
package 'python3.12-pip'
81+
82+
# Mock python environment for AL2023 Docker tests
83+
# The pyenv/virtualenv setup doesn't work in Docker because it requires S3 access
84+
python_version = node['cluster']['python-version']
85+
pyenv_root = node['cluster']['system_pyenv_root']
86+
virtualenv_path = "#{pyenv_root}/versions/#{python_version}/envs/cookbook_virtualenv"
87+
88+
directory "#{virtualenv_path}/bin" do
89+
recursive true
90+
end
91+
92+
# Create a wrapper script that reports the expected version but uses system Python
93+
file "#{virtualenv_path}/bin/python" do
94+
content %(#!/bin/bash
95+
if [[ "$1" == "-V" || "$1" == "--version" ]]; then
96+
echo "Python #{python_version}"
97+
else
98+
exec /usr/bin/python3.12 "$@"
99+
fi
100+
)
101+
mode '0755'
102+
end
103+
104+
link "#{virtualenv_path}/bin/pip" do
105+
to '/usr/bin/pip3.12'
106+
end
107+
108+
bash 'Install cookbook requirements for AL2023' do
109+
cwd Chef::Config[:file_cache_path]
110+
code "/usr/bin/python3.12 -m pip install -r cookbooks/aws-parallelcluster-platform/files/cookbook_virtualenv/requirements.txt"
111+
end
112+
end
113+
77114
file '/usr/bin/ssh-keyscan' do
78115
content %(
79116
#!/bin/bash

0 commit comments

Comments
 (0)