From a7d270bb84b63d13f5b65df8524f3fb4d45161fa Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Fri, 12 Dec 2025 16:07:00 -0500 Subject: [PATCH] [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. --- .../recipes/docker_mock.rb | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/cookbooks/aws-parallelcluster-tests/recipes/docker_mock.rb b/cookbooks/aws-parallelcluster-tests/recipes/docker_mock.rb index bb2a5e65af..ba5e435039 100644 --- a/cookbooks/aws-parallelcluster-tests/recipes/docker_mock.rb +++ b/cookbooks/aws-parallelcluster-tests/recipes/docker_mock.rb @@ -74,6 +74,60 @@ end end +if alinux2023_on_docker? + # Create pcluster-admin user and group + group 'pcluster-admin' do + gid 400 + end + + user 'pcluster-admin' do + uid 400 + gid 400 + home '/home/pcluster-admin' + shell '/bin/bash' + end + + # Create required directories + directory '/opt/parallelcluster/shared' do + recursive true + end + + # Install Python 3.12 for AL2023 Docker tests + package 'python3.12' + package 'python3.12-pip' + + # Mock python environment for AL2023 Docker tests + # The pyenv/virtualenv setup doesn't work in Docker because it requires S3 access + python_version = node['cluster']['python-version'] + pyenv_root = node['cluster']['system_pyenv_root'] + virtualenv_path = "#{pyenv_root}/versions/#{python_version}/envs/cookbook_virtualenv" + + directory "#{virtualenv_path}/bin" do + recursive true + end + + # Create a wrapper script that reports the expected version but uses system Python + file "#{virtualenv_path}/bin/python" do + content %(#!/bin/bash +if [[ "$1" == "-V" || "$1" == "--version" ]]; then + echo "Python #{python_version}" +else + exec /usr/bin/python3.12 "$@" +fi +) + mode '0755' + end + + link "#{virtualenv_path}/bin/pip" do + to '/usr/bin/pip3.12' + end + + bash 'Install cookbook requirements for AL2023' do + cwd Chef::Config[:file_cache_path] + code "/usr/bin/python3.12 -m pip install -r cookbooks/aws-parallelcluster-platform/files/cookbook_virtualenv/requirements.txt" + end +end + file '/usr/bin/ssh-keyscan' do content %( #!/bin/bash