Skip to content

Commit a7d270b

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 a7d270b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,60 @@
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+
# Create required directories
91+
directory '/opt/parallelcluster/shared' do
92+
recursive true
93+
end
94+
95+
# Install Python 3.12 for AL2023 Docker tests
96+
package 'python3.12'
97+
package 'python3.12-pip'
98+
99+
# Mock python environment for AL2023 Docker tests
100+
# The pyenv/virtualenv setup doesn't work in Docker because it requires S3 access
101+
python_version = node['cluster']['python-version']
102+
pyenv_root = node['cluster']['system_pyenv_root']
103+
virtualenv_path = "#{pyenv_root}/versions/#{python_version}/envs/cookbook_virtualenv"
104+
105+
directory "#{virtualenv_path}/bin" do
106+
recursive true
107+
end
108+
109+
# Create a wrapper script that reports the expected version but uses system Python
110+
file "#{virtualenv_path}/bin/python" do
111+
content %(#!/bin/bash
112+
if [[ "$1" == "-V" || "$1" == "--version" ]]; then
113+
echo "Python #{python_version}"
114+
else
115+
exec /usr/bin/python3.12 "$@"
116+
fi
117+
)
118+
mode '0755'
119+
end
120+
121+
link "#{virtualenv_path}/bin/pip" do
122+
to '/usr/bin/pip3.12'
123+
end
124+
125+
bash 'Install cookbook requirements for AL2023' do
126+
cwd Chef::Config[:file_cache_path]
127+
code "/usr/bin/python3.12 -m pip install -r cookbooks/aws-parallelcluster-platform/files/cookbook_virtualenv/requirements.txt"
128+
end
129+
end
130+
77131
file '/usr/bin/ssh-keyscan' do
78132
content %(
79133
#!/bin/bash

0 commit comments

Comments
 (0)