Skip to content

Commit 3ad7d3f

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 3ad7d3f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

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

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

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

0 commit comments

Comments
 (0)