From 368e639ca4234b9a1dd5b77aaca6118823858934 Mon Sep 17 00:00:00 2001 From: Hanwen Date: Tue, 25 Feb 2025 10:09:45 -0800 Subject: [PATCH] Move files out of /tmp Signed-off-by: Hanwen --- .../recipes/config/network_interfaces.rb | 6 +++--- .../recipes/install/cfn_bootstrap.rb | 4 ++-- .../spec/unit/recipes/cfn_bootstrap_spec.rb | 6 +++--- .../test/controls/network_interfaces_spec.rb | 2 +- .../files/ami_cleanup.sh | 1 + .../recipes/install/cuda.rb | 14 +++++++------- .../recipes/install/directories.rb | 1 + .../partial/_nvidia_driver_common.rb | 6 +++--- .../spec/unit/recipes/cuda_spec.rb | 16 ++++++++-------- .../spec/unit/resources/nvidia_driver_spec.rb | 12 ++++++------ .../attributes/cluster.rb | 1 + .../recipes/install/install_pyxis.rb | 4 ++-- .../resources/munge_key_manager.rb | 2 +- .../mysql_client/partial/_setup_rhel_based.rb | 4 ++-- .../spec/unit/recipes/install_pyxis_spec.rb | 4 ++-- .../spec/unit/resources/mysql_client_spec.rb | 4 ++-- .../retrieve_remote_custom_settings_file_spec.rb | 2 +- 17 files changed, 46 insertions(+), 43 deletions(-) diff --git a/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb b/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb index bee82724ee..bd79dbbdb5 100644 --- a/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb +++ b/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb @@ -66,7 +66,7 @@ def cidr_to_netmask(cidr) cookbook_file 'configure_nw_interface.sh' do source 'network_interfaces/configure_nw_interface.sh' - path '/tmp/configure_nw_interface.sh' + path "#{node['cluster']['tmp_dir']}/configure_nw_interface.sh" user 'root' group 'root' mode '0644' @@ -87,7 +87,7 @@ def cidr_to_netmask(cidr) execute 'configure_nw_interface' do user 'root' group 'root' - cwd "/tmp" + cwd node['cluster']['tmp_dir'] environment( # TODO: The variables are a superset of what's required by individual scripts. Consider simplification. 'DEVICE_NAME' => device_name, @@ -101,7 +101,7 @@ def cidr_to_netmask(cidr) 'MAC' => mac ) - command 'sh /tmp/configure_nw_interface.sh' + command "sh #{node['cluster']['tmp_dir']}/configure_nw_interface.sh" end end diff --git a/cookbooks/aws-parallelcluster-environment/recipes/install/cfn_bootstrap.rb b/cookbooks/aws-parallelcluster-environment/recipes/install/cfn_bootstrap.rb index 41fb845c4f..c2f8b40d83 100644 --- a/cookbooks/aws-parallelcluster-environment/recipes/install/cfn_bootstrap.rb +++ b/cookbooks/aws-parallelcluster-environment/recipes/install/cfn_bootstrap.rb @@ -65,7 +65,7 @@ bucket = "s3.#{aws_region}.#{aws_domain}" end -remote_file "/tmp/#{cfnbootstrap_package}" do +remote_file "#{node['cluster']['tmp_dir']}/#{cfnbootstrap_package}" do source "https://#{bucket}/cloudformation-examples/#{cfnbootstrap_package}" retries 3 retry_delay 5 @@ -74,7 +74,7 @@ bash "Install CloudFormation helpers from #{cfnbootstrap_package}" do user 'root' group 'root' - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code "#{virtualenv_path}/bin/pip install #{cfnbootstrap_package}" creates "#{virtualenv_path}/bin/cfn-hup" end diff --git a/cookbooks/aws-parallelcluster-environment/spec/unit/recipes/cfn_bootstrap_spec.rb b/cookbooks/aws-parallelcluster-environment/spec/unit/recipes/cfn_bootstrap_spec.rb index 73bd8cd4e5..2e7b909ee2 100644 --- a/cookbooks/aws-parallelcluster-environment/spec/unit/recipes/cfn_bootstrap_spec.rb +++ b/cookbooks/aws-parallelcluster-environment/spec/unit/recipes/cfn_bootstrap_spec.rb @@ -46,7 +46,7 @@ end it 'downloads cfn_bootstrap package from s3' do - is_expected.to create_remote_file("/tmp/#{cfnbootstrap_package}").with( + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/#{cfnbootstrap_package}").with( source: "https://s3.amazonaws.com/cloudformation-examples/#{cfnbootstrap_package}" ) end @@ -55,7 +55,7 @@ is_expected.to run_bash("Install CloudFormation helpers from #{cfnbootstrap_package}").with( user: 'root', group: 'root', - cwd: '/tmp', + cwd: node['cluster']['tmp_dir'], code: "#{virtualenv_path}/bin/pip install #{cfnbootstrap_package}", creates: "#{virtualenv_path}/bin/cfn-hup" ) @@ -111,7 +111,7 @@ runner.converge(described_recipe) end it 'downloads cfn_bootstrap package from a different s3 bucket' do - is_expected.to create_remote_file("/tmp/#{cfnbootstrap_package}").with( + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/#{cfnbootstrap_package}").with( source: "https://s3.cn-north-1.amazonaws.com.cn/cn-north-1-aws-parallelcluster/cloudformation-examples/#{cfnbootstrap_package}" ) end diff --git a/cookbooks/aws-parallelcluster-environment/test/controls/network_interfaces_spec.rb b/cookbooks/aws-parallelcluster-environment/test/controls/network_interfaces_spec.rb index 6189f2143d..90bf045996 100644 --- a/cookbooks/aws-parallelcluster-environment/test/controls/network_interfaces_spec.rb +++ b/cookbooks/aws-parallelcluster-environment/test/controls/network_interfaces_spec.rb @@ -12,7 +12,7 @@ control 'network_interfaces_configuration_script_created' do title 'Check script to configure network interface is created' - describe file('/tmp/configure_nw_interface.sh') do + describe file("#{node['cluster']['tmp_dir']}/configure_nw_interface.sh") do it { should exist } its('mode') { should cmp '0644' } its('owner') { should eq 'root' } diff --git a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh index 2943b51f38..dbaa4cef0f 100644 --- a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh +++ b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh @@ -4,6 +4,7 @@ cloud-init clean -s rm -rf /var/tmp/* /tmp/* +rm -rf node['cluster']['tmp_dir'] rm -rf /etc/ssh/ssh_host_* rm -f /etc/udev/rules.d/70-persistent-net.rules grep -l "Created by cloud-init on instance boot automatically" /etc/sysconfig/network-scripts/ifcfg-* | xargs rm -f diff --git a/cookbooks/aws-parallelcluster-platform/recipes/install/cuda.rb b/cookbooks/aws-parallelcluster-platform/recipes/install/cuda.rb index 152968a057..298c384652 100644 --- a/cookbooks/aws-parallelcluster-platform/recipes/install/cuda.rb +++ b/cookbooks/aws-parallelcluster-platform/recipes/install/cuda.rb @@ -27,8 +27,8 @@ cuda_url = "#{node['cluster']['artifacts_s3_url']}/dependencies/cuda/cuda_#{cuda_complete_version}_#{cuda_version_suffix}_#{cuda_arch}.run" cuda_samples_version = '12.4' cuda_samples_url = "#{node['cluster']['artifacts_s3_url']}/dependencies/cuda/samples/v#{cuda_samples_version}.tar.gz" -tmp_cuda_run = '/tmp/cuda.run' -tmp_cuda_sample_archive = '/tmp/cuda-sample.tar.gz' +tmp_cuda_run = "#{node['cluster']['tmp_dir']}/cuda.run" +tmp_cuda_sample_archive = "#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz" node.default['cluster']['nvidia']['cuda']['version'] = cuda_version node.default['cluster']['nvidia']['cuda_samples_version'] = cuda_samples_version @@ -47,13 +47,13 @@ bash 'cuda.run advanced' do user 'root' group 'root' - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code <<-CUDA set -e mkdir /cuda-install ./cuda.run --silent --toolkit --samples --tmpdir=/cuda-install rm -rf /cuda-install - rm -f /tmp/cuda.run + rm -f #{node['cluster']['tmp_dir']}/cuda.run CUDA creates "/usr/local/cuda-#{cuda_version}" end @@ -71,11 +71,11 @@ bash 'cuda.sample install' do user 'root' group 'root' - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code <<-CUDA set -e - tar xf "/tmp/cuda-sample.tar.gz" --directory "/usr/local/" - rm -f "/tmp/cuda-sample.tar.gz" + tar xf "#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz" --directory "/usr/local/" + rm -f "#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz" CUDA creates "/usr/local/cuda-#{cuda_version}/samples" end diff --git a/cookbooks/aws-parallelcluster-platform/recipes/install/directories.rb b/cookbooks/aws-parallelcluster-platform/recipes/install/directories.rb index 53096a8b48..7e86082555 100644 --- a/cookbooks/aws-parallelcluster-platform/recipes/install/directories.rb +++ b/cookbooks/aws-parallelcluster-platform/recipes/install/directories.rb @@ -18,6 +18,7 @@ directory node['cluster']['base_dir'] directory node['cluster']['sources_dir'] directory node['cluster']['scripts_dir'] +directory node['cluster']['tmp_dir'] directory node['cluster']['license_dir'] directory node['cluster']['configs_dir'] directory node['cluster']['shared_dir'] diff --git a/cookbooks/aws-parallelcluster-platform/resources/nvidia_driver/partial/_nvidia_driver_common.rb b/cookbooks/aws-parallelcluster-platform/resources/nvidia_driver/partial/_nvidia_driver_common.rb index 5cfa7ea906..a39ed44988 100644 --- a/cookbooks/aws-parallelcluster-platform/resources/nvidia_driver/partial/_nvidia_driver_common.rb +++ b/cookbooks/aws-parallelcluster-platform/resources/nvidia_driver/partial/_nvidia_driver_common.rb @@ -17,7 +17,7 @@ property :nvidia_driver_version, String -tmp_nvidia_run = '/tmp/nvidia.run' +tmp_nvidia_run = "#{node['cluster']['tmp_dir']}/nvidia.run" action :setup do return unless nvidia_driver_enabled? @@ -76,11 +76,11 @@ bash 'nvidia.run advanced' do user 'root' group 'root' - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code <<-NVIDIA set -e #{compiler_path} ./nvidia.run --silent --dkms --disable-nouveau -m=#{nvidia_kernel_module} - rm -f /tmp/nvidia.run + rm -f #{node['cluster']['tmp_dir']}/nvidia.run NVIDIA creates '/usr/bin/nvidia-smi' end diff --git a/cookbooks/aws-parallelcluster-platform/spec/unit/recipes/cuda_spec.rb b/cookbooks/aws-parallelcluster-platform/spec/unit/recipes/cuda_spec.rb index 5e241d8955..63bf0cc790 100644 --- a/cookbooks/aws-parallelcluster-platform/spec/unit/recipes/cuda_spec.rb +++ b/cookbooks/aws-parallelcluster-platform/spec/unit/recipes/cuda_spec.rb @@ -39,7 +39,7 @@ end it 'downloads CUDA run file' do - is_expected.to create_remote_file('/tmp/cuda.run').with( + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/cuda.run").with( source: cuda_url, mode: '0755', retries: 3, @@ -53,16 +53,16 @@ .with( user: 'root', group: 'root', - cwd: '/tmp', + cwd: node['cluster']['tmp_dir'], creates: "/usr/local/cuda-#{cuda_version}") .with_code(%r{mkdir /cuda-install}) .with_code(%r{./cuda.run --silent --toolkit --samples --tmpdir=/cuda-install}) .with_code(%r{rm -rf /cuda-install}) - .with_code(%r{rm -f /tmp/cuda.run}) + .with_code(%r{rm -f #{node['cluster']['tmp_dir']}/cuda.run}) end it 'downloads CUDA sample files' do - is_expected.to create_remote_file('/tmp/cuda-sample.tar.gz').with( + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz").with( source: cuda_samples_url, mode: '0644', retries: 3, @@ -75,9 +75,9 @@ .with( user: 'root', group: 'root', - cwd: '/tmp') - .with_code(%r{tar xf "/tmp/cuda-sample.tar.gz" --directory "/usr/local/"}) - .with_code(%r{rm -f "/tmp/cuda-sample.tar.gz"}) + cwd: node['cluster']['tmp_dir']) + .with_code(%r{tar xf "#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz" --directory "/usr/local/"}) + .with_code(%r{rm -f "#{node['cluster']['tmp_dir']}/cuda-sample.tar.gz"}) end end @@ -95,7 +95,7 @@ cached(:node) { chef_run.node } it 'downloads CUDA run file' do - is_expected.to create_remote_file('/tmp/cuda.run').with_source(cuda_url) + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/cuda.run").with_source(cuda_url) end end end diff --git a/cookbooks/aws-parallelcluster-platform/spec/unit/resources/nvidia_driver_spec.rb b/cookbooks/aws-parallelcluster-platform/spec/unit/resources/nvidia_driver_spec.rb index a1d81426d7..3fd5b71f59 100644 --- a/cookbooks/aws-parallelcluster-platform/spec/unit/resources/nvidia_driver_spec.rb +++ b/cookbooks/aws-parallelcluster-platform/spec/unit/resources/nvidia_driver_spec.rb @@ -198,7 +198,7 @@ def self.setup(chef_run, nvidia_driver_version: nil) end it 'downloads nvidia driver' do - is_expected.to create_remote_file('/tmp/nvidia.run').with( + is_expected.to create_remote_file("#{node['cluster']['tmp_dir']}/nvidia.run").with( source: nvidia_driver_url, mode: '0755', retries: 3, @@ -241,11 +241,11 @@ def self.setup(chef_run, nvidia_driver_version: nil) .with( user: 'root', group: 'root', - cwd: '/tmp', + cwd: node['cluster']['tmp_dir'], creates: '/usr/bin/nvidia-smi' ) .with_code(%r{CC=/usr/bin/gcc10-gcc ./nvidia.run --silent --dkms --disable-nouveau -m=#{kernel_module}}) - .with_code(%r{rm -f /tmp/nvidia.run}) + .with_code(%r{rm -f #{node['cluster']['tmp_dir']}/nvidia.run}) end elsif platform == 'ubuntu' && version == '22.04' it 'installs gcc' do @@ -269,7 +269,7 @@ def self.setup(chef_run, nvidia_driver_version: nil) .with( user: 'root', group: 'root', - cwd: '/tmp', + cwd: node['cluster']['tmp_dir'], creates: '/usr/bin/nvidia-smi' ) .with_code(%r{#{compiler_path} ./nvidia.run --silent --dkms --disable-nouveau -m=#{kernel_module}}) @@ -283,11 +283,11 @@ def self.setup(chef_run, nvidia_driver_version: nil) .with( user: 'root', group: 'root', - cwd: '/tmp', + cwd: node['cluster']['tmp_dir'], creates: '/usr/bin/nvidia-smi' ) .with_code(%r{./nvidia.run --silent --dkms --disable-nouveau -m=#{kernel_module}}) - .with_code(%r{rm -f /tmp/nvidia.run}) + .with_code(%r{rm -f #{node['cluster']['tmp_dir']}/nvidia.run}) end end diff --git a/cookbooks/aws-parallelcluster-shared/attributes/cluster.rb b/cookbooks/aws-parallelcluster-shared/attributes/cluster.rb index def13a134a..7a35294801 100644 --- a/cookbooks/aws-parallelcluster-shared/attributes/cluster.rb +++ b/cookbooks/aws-parallelcluster-shared/attributes/cluster.rb @@ -1,6 +1,7 @@ default['cluster']['base_dir'] = '/opt/parallelcluster' default['cluster']['sources_dir'] = "#{node['cluster']['base_dir']}/sources" default['cluster']['scripts_dir'] = "#{node['cluster']['base_dir']}/scripts" +default['cluster']['tmp_dir'] = "#{node['cluster']['base_dir']}/tmp" default['cluster']['license_dir'] = "#{node['cluster']['base_dir']}/licenses" default['cluster']['configs_dir'] = "#{node['cluster']['base_dir']}/configs" default['cluster']['shared_dir'] = "#{node['cluster']['base_dir']}/shared" diff --git a/cookbooks/aws-parallelcluster-slurm/recipes/install/install_pyxis.rb b/cookbooks/aws-parallelcluster-slurm/recipes/install/install_pyxis.rb index bfc7db8a41..dfb1cb7d22 100644 --- a/cookbooks/aws-parallelcluster-slurm/recipes/install/install_pyxis.rb +++ b/cookbooks/aws-parallelcluster-slurm/recipes/install/install_pyxis.rb @@ -37,8 +37,8 @@ user 'root' code <<-PYXIS_INSTALL set -e - tar xf #{pyxis_tarball} -C /tmp - cd /tmp/pyxis-#{pyxis_version} + tar xf #{pyxis_tarball} -C #{node['cluster']['tmp_dir']} + cd #{node['cluster']['tmp_dir']}/pyxis-#{pyxis_version} CPPFLAGS='-I #{node['cluster']['slurm']['install_dir']}/include/' make CPPFLAGS='-I #{node['cluster']['slurm']['install_dir']}/include/' make install PYXIS_INSTALL diff --git a/cookbooks/aws-parallelcluster-slurm/resources/munge_key_manager.rb b/cookbooks/aws-parallelcluster-slurm/resources/munge_key_manager.rb index b77cbaef15..8b9356c71e 100644 --- a/cookbooks/aws-parallelcluster-slurm/resources/munge_key_manager.rb +++ b/cookbooks/aws-parallelcluster-slurm/resources/munge_key_manager.rb @@ -74,7 +74,7 @@ def generate_munge_key declare_resource(:bash, 'generate_munge_key') do user node['cluster']['munge']['user'] group node['cluster']['munge']['group'] - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code <<-GENERATE_KEY set -e /usr/sbin/mungekey --verbose --force diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_client/partial/_setup_rhel_based.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_client/partial/_setup_rhel_based.rb index 38310a9a59..7c4fe73bd9 100644 --- a/cookbooks/aws-parallelcluster-slurm/resources/mysql_client/partial/_setup_rhel_based.rb +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_client/partial/_setup_rhel_based.rb @@ -15,7 +15,7 @@ action :setup do mysql_archive_url = package_archive(node['cluster']['artifacts_s3_url']) - mysql_tar_file = "/tmp/#{package_filename}" + mysql_tar_file = "#{node['cluster']['tmp_dir']}/#{package_filename}" log "Downloading MySQL packages archive from #{mysql_archive_url}" @@ -33,7 +33,7 @@ bash 'Install MySQL packages' do user 'root' group 'root' - cwd '/tmp' + cwd node['cluster']['tmp_dir'] code <<-MYSQL set -e diff --git a/cookbooks/aws-parallelcluster-slurm/spec/unit/recipes/install_pyxis_spec.rb b/cookbooks/aws-parallelcluster-slurm/spec/unit/recipes/install_pyxis_spec.rb index e9305968fb..7da4b33c1b 100644 --- a/cookbooks/aws-parallelcluster-slurm/spec/unit/recipes/install_pyxis_spec.rb +++ b/cookbooks/aws-parallelcluster-slurm/spec/unit/recipes/install_pyxis_spec.rb @@ -54,8 +54,8 @@ retry_delay: 5, code: <<-CODE set -e - tar xf #{cluster_sources_dir}/pyxis-#{pyxis_version}.tar.gz -C /tmp - cd /tmp/pyxis-#{pyxis_version} + tar xf #{cluster_sources_dir}/pyxis-#{pyxis_version}.tar.gz -C #{node['cluster']['tmp_dir']} + cd #{node['cluster']['tmp_dir']}/pyxis-#{pyxis_version} CPPFLAGS='-I #{slurm_install_dir}/include/' make CPPFLAGS='-I #{slurm_install_dir}/include/' make install CODE diff --git a/cookbooks/aws-parallelcluster-slurm/spec/unit/resources/mysql_client_spec.rb b/cookbooks/aws-parallelcluster-slurm/spec/unit/resources/mysql_client_spec.rb index 048ddc2972..7881ee6f00 100644 --- a/cookbooks/aws-parallelcluster-slurm/spec/unit/resources/mysql_client_spec.rb +++ b/cookbooks/aws-parallelcluster-slurm/spec/unit/resources/mysql_client_spec.rb @@ -46,7 +46,7 @@ def self.validate(chef_run) end end cached(:package_archive) { "#{s3_url}/mysql/#{package_platform}/#{package_filename}" } - cached(:tarfile) { "/tmp/mysql-community-client-#{package_version}.tar.gz" } + cached(:tarfile) { "#{node['cluster']['tmp_dir']}/mysql-community-client-#{package_version}.tar.gz" } cached(:repository_packages) do if platform == 'ubuntu' if version.to_i == 18 @@ -87,7 +87,7 @@ def self.validate(chef_run) is_expected.to run_bash('Install MySQL packages') .with(user: 'root') .with(group: 'root') - .with(cwd: '/tmp') + .with(cwd: node['cluster']['tmp_dir']) .with(code: %{ set -e EXTRACT_DIR=$(mktemp -d --tmpdir mysql.XXXXXXX) diff --git a/cookbooks/aws-parallelcluster-slurm/test/controls/retrieve_remote_custom_settings_file_spec.rb b/cookbooks/aws-parallelcluster-slurm/test/controls/retrieve_remote_custom_settings_file_spec.rb index 3c4ea0950a..9579ba7585 100644 --- a/cookbooks/aws-parallelcluster-slurm/test/controls/retrieve_remote_custom_settings_file_spec.rb +++ b/cookbooks/aws-parallelcluster-slurm/test/controls/retrieve_remote_custom_settings_file_spec.rb @@ -18,7 +18,7 @@ control 'custom_settings_file_retrieved' do title 'Checks that customs settings file has been retrieved if specified in the config' - describe file("/tmp/custom_slurm_settings_include_file_slurm.conf") do + describe file("#{node['cluster']['tmp_dir']}/custom_slurm_settings_include_file_slurm.conf") do it { should exist } end end