Skip to content

Commit 2a34327

Browse files
author
Himani Anil Deshpande
committed
[Bug] Install cfn dependencies in all regions
1 parent 2a50d8a commit 2a34327

File tree

2 files changed

+73
-33
lines changed

2 files changed

+73
-33
lines changed

cookbooks/aws-parallelcluster-environment/recipes/install/cfn_bootstrap.rb

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,31 @@
3333
not_if { ::File.exist?("#{virtualenv_path}/bin/activate") }
3434
end
3535

36-
if aws_region.start_with?("us-iso")
37-
dependency_package_name = "pypi-cfn-dependencies-#{node['cluster']['python-major-minor-version']}-#{node['kernel']['machine']}"
38-
dependency_folder_name = dependency_package_name
39-
if platform?('amazon') && node['platform_version'] == "2"
40-
dependency_package_name = "cfn-dependencies"
41-
dependency_folder_name = "cfn"
42-
end
43-
remote_file "#{node['cluster']['base_dir']}/cfn-dependencies.tgz" do
44-
source "#{node['cluster']['artifacts_s3_url']}/dependencies/PyPi/#{node['kernel']['machine']}/#{dependency_package_name}.tgz"
45-
mode '0644'
46-
retries 3
47-
retry_delay 5
48-
action :create_if_missing
49-
end
50-
51-
bash 'pip install' do
52-
user 'root'
53-
group 'root'
54-
cwd "#{node['cluster']['base_dir']}"
55-
code <<-REQ
56-
set -e
57-
tar xzf cfn-dependencies.tgz
58-
cd #{dependency_folder_name}
59-
#{virtualenv_path}/bin/pip install * -f ./ --no-index
60-
REQ
61-
end
36+
dependency_package_name = "pypi-cfn-dependencies-#{node['cluster']['python-major-minor-version']}-#{node['kernel']['machine']}"
37+
dependency_folder_name = dependency_package_name
38+
if platform?('amazon') && node['platform_version'] == "2"
39+
dependency_package_name = "cfn-dependencies"
40+
dependency_folder_name = "cfn"
41+
end
42+
43+
remote_file "#{node['cluster']['base_dir']}/cfn-dependencies.tgz" do
44+
source "#{node['cluster']['artifacts_s3_url']}/dependencies/PyPi/#{node['kernel']['machine']}/#{dependency_package_name}.tgz"
45+
mode '0644'
46+
retries 3
47+
retry_delay 5
48+
action :create_if_missing
49+
end
50+
51+
bash 'pip install' do
52+
user 'root'
53+
group 'root'
54+
cwd "#{node['cluster']['base_dir']}"
55+
code <<-REQ
56+
set -e
57+
tar xzf cfn-dependencies.tgz
58+
cd #{dependency_folder_name}
59+
#{virtualenv_path}/bin/pip install * -f ./ --no-index
60+
REQ
6261
end
6362

6463
cfnbootstrap_version = '2.0-33'
@@ -79,11 +78,8 @@
7978
retry_delay 5
8079
end
8180

82-
command = if aws_region.start_with?("us-iso")
83-
"#{virtualenv_path}/bin/pip install #{cfnbootstrap_package} --no-build-isolation"
84-
else
85-
"#{virtualenv_path}/bin/pip install #{cfnbootstrap_package}"
86-
end
81+
command = "#{virtualenv_path}/bin/pip install #{cfnbootstrap_package} --no-build-isolation"
82+
8783
bash "Install CloudFormation helpers from #{cfnbootstrap_package}" do
8884
user 'root'
8985
group 'root'

cookbooks/aws-parallelcluster-environment/spec/unit/recipes/cfn_bootstrap_spec.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,46 @@
44
for_all_oses do |platform, version|
55
context "on #{platform}#{version}" do
66
cached(:cfnbootstrap_version) { '2.0-33' }
7-
cached(:cfnbootstrap_package) { "aws-cfn-bootstrap-py3-#{cfnbootstrap_version}.tar.gz" }
7+
cached(:arch) { 'x86_64' }
8+
cached(:s3_url) { 's3://url' }
9+
cached(:base_dir) { 'base_dir' }
810
cached(:python_version) { "#{node['cluster']['python-version']}" }
11+
cached(:dependecy_package_name_suffix) do
12+
if platform == 'amazon' && version == '2'
13+
"cfn-dependencies"
14+
else
15+
"pypi-cfn-dependencies-#{node['cluster']['python-major-minor-version']}-#{arch}"
16+
end
17+
end
18+
cached(:dependecy_folder_name) do
19+
if platform == 'amazon' && version == '2'
20+
"cfn"
21+
else
22+
dependecy_package_name_suffix
23+
end
24+
end
25+
cached(:cfnbootstrap_package) { "aws-cfn-bootstrap-py3-#{cfnbootstrap_version}.tar.gz" }
926
cached(:system_pyenv_root) { 'system_pyenv_root' }
1027
cached(:virtualenv_path) { "system_pyenv_root/versions/#{python_version}/envs/cfn_bootstrap_virtualenv" }
1128
cached(:timeout) { 1800 }
29+
cached(:dependency_bash_code) do
30+
<<-REQ
31+
set -e
32+
tar xzf cfn-dependencies.tgz
33+
cd #{dependecy_folder_name}
34+
#{virtualenv_path}/bin/pip install * -f ./ --no-index
35+
REQ
36+
end
1237

1338
context "when cfn_bootstrap virtualenv not installed yet" do
1439
cached(:chef_run) do
1540
runner = runner(platform: platform, version: version) do |node|
1641
node.override['cluster']['system_pyenv_root'] = system_pyenv_root
1742
node.override['cluster']['region'] = 'non_china'
43+
node.override['cluster']['base_dir'] = base_dir
1844
node.override['cluster']['compute_node_bootstrap_timeout'] = timeout
45+
node.override['cluster']['artifacts_s3_url'] = s3_url
46+
node.override['kernel']['machine'] = arch
1947
end
2048
runner.converge(described_recipe)
2149
end
@@ -37,6 +65,22 @@
3765
is_expected.to write_node_attributes('dump node attributes')
3866
end
3967

68+
it 'downloads cfn_dependecies package from s3' do
69+
is_expected.to create_if_missing_remote_file("#{base_dir}/cfn-dependencies.tgz")
70+
.with(source: "#{s3_url}/dependencies/PyPi/#{arch}/#{dependecy_package_name_suffix}.tgz")
71+
.with(mode: '0644')
72+
.with(retries: 3)
73+
.with(retry_delay: 5)
74+
end
75+
76+
it 'pip installs dependencies' do
77+
is_expected.to run_bash('pip install')
78+
.with(user: 'root')
79+
.with(group: 'root')
80+
.with(cwd: base_dir)
81+
.with(code: dependency_bash_code)
82+
end
83+
4084
it 'downloads cfn_bootstrap package from s3' do
4185
is_expected.to create_remote_file("/tmp/#{cfnbootstrap_package}").with(
4286
source: "https://s3.amazonaws.com/cloudformation-examples/#{cfnbootstrap_package}"
@@ -48,7 +92,7 @@
4892
user: 'root',
4993
group: 'root',
5094
cwd: '/tmp',
51-
code: "#{virtualenv_path}/bin/pip install #{cfnbootstrap_package}",
95+
code: "#{virtualenv_path}/bin/pip install #{cfnbootstrap_package} --no-build-isolation",
5296
creates: "#{virtualenv_path}/bin/cfn-hup"
5397
)
5498
end

0 commit comments

Comments
 (0)