|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'aws-parallelcluster-computefleet::custom_parallelcluster_node' do |
| 4 | + for_all_oses do |platform, version| |
| 5 | + context "on #{platform}#{version}" do |
| 6 | + cached(:s3_url) { 's3://url' } |
| 7 | + cached(:base_dir) { 'base_dir' } |
| 8 | + cached(:arch) { 'x86_64' } |
| 9 | + cached(:region) { 'any-region' } |
| 10 | + cached(:python_version) { 'python_version' } |
| 11 | + cached(:dependency_pkg_name_suffix) do |
| 12 | + if platform == 'amazon' && version == '2' |
| 13 | + 'node-dependencies' |
| 14 | + else |
| 15 | + "pypi-node-dependencies-#{python_version}-#{arch}" |
| 16 | + end |
| 17 | + end |
| 18 | + cached(:dependency_folder_name_suffix) do |
| 19 | + if platform == 'amazon' && version == '2' |
| 20 | + "node" |
| 21 | + else |
| 22 | + dependency_pkg_name_suffix |
| 23 | + end |
| 24 | + end |
| 25 | + cached(:virtualenv_path) { "#{base_dir}/pyenv/versions/#{python_version}/envs/node_virtualenv" } |
| 26 | + cached(:cookbook_virtualenv_path) { "#{base_dir}/pyenv/versions/#{python_version}/envs/cookbook_virtualenv" } |
| 27 | + cached(:custom_node_s3_url) { "#{s3_url}/pyenv/versions/#{python_version}/envs/node_virtualenv" } |
| 28 | + cached(:pip_install_bash_code) do |
| 29 | + <<-REQ |
| 30 | + set -e |
| 31 | + tar xzf node-dependencies.tgz |
| 32 | + cd #{dependency_folder_name_suffix} |
| 33 | + #{virtualenv_path}/bin/pip install * -f ./ --no-index |
| 34 | + REQ |
| 35 | + end |
| 36 | + cached(:node_bash_code) do |
| 37 | + <<-NODE |
| 38 | + set -e |
| 39 | + [[ ":$PATH:" != *":/usr/local/bin:"* ]] && PATH="/usr/local/bin:${PATH}" |
| 40 | + echo "PATH is $PATH" |
| 41 | + source #{virtualenv_path}/bin/activate |
| 42 | + pip uninstall --yes aws-parallelcluster-node |
| 43 | + if [[ "#{custom_node_s3_url}" =~ ^s3:// ]]; then |
| 44 | + custom_package_url=$(#{cookbook_virtualenv_path}/bin/aws s3 presign #{custom_node_s3_url} --region #{region}) |
| 45 | + else |
| 46 | + custom_package_url=#{custom_node_s3_url} |
| 47 | + fi |
| 48 | + curl --retry 3 -L -o aws-parallelcluster-node.tgz ${custom_package_url} |
| 49 | + rm -fr aws-parallelcluster-custom-node |
| 50 | + mkdir aws-parallelcluster-custom-node |
| 51 | + tar -xzf aws-parallelcluster-node.tgz --directory aws-parallelcluster-custom-node |
| 52 | + cd aws-parallelcluster-custom-node/*aws-parallelcluster-node* |
| 53 | + pip install . --no-build-isolation |
| 54 | + deactivate |
| 55 | + NODE |
| 56 | + end |
| 57 | + cached(:chef_run) do |
| 58 | + runner = runner(platform: platform, version: version) do |node| |
| 59 | + node.override['kernel']['machine'] = arch |
| 60 | + node.override['cluster']['python-major-minor-version'] = python_version |
| 61 | + node.override['cluster']['python-version'] = python_version |
| 62 | + node.override['cluster']['base_dir'] = base_dir |
| 63 | + node.override['cluster']['region'] = region |
| 64 | + node.override['cluster']['artifacts_s3_url'] = s3_url |
| 65 | + node.override['cluster']['custom_node_package'] = custom_node_s3_url |
| 66 | + end |
| 67 | + allow(File).to receive(:exist?).with("#{virtualenv_path}/bin/activate").and_return(true) |
| 68 | + runner.converge(described_recipe) |
| 69 | + end |
| 70 | + |
| 71 | + it 'downloads tarball' do |
| 72 | + is_expected.to create_if_missing_remote_file("base_dir/node-dependencies.tgz") |
| 73 | + .with(source: "#{s3_url}/dependencies/PyPi/#{arch}/#{dependency_pkg_name_suffix}.tgz") |
| 74 | + .with(mode: '0644') |
| 75 | + .with(retries: 3) |
| 76 | + .with(retry_delay: 5) |
| 77 | + end |
| 78 | + |
| 79 | + it 'pip installs' do |
| 80 | + is_expected.to run_bash('pip install') |
| 81 | + .with(cwd: base_dir) |
| 82 | + .with(code: pip_install_bash_code) |
| 83 | + end |
| 84 | + |
| 85 | + it 'install custom aws-parallelcluster-node' do |
| 86 | + is_expected.to run_bash('install custom aws-parallelcluster-node') |
| 87 | + .with(code: node_bash_code) |
| 88 | + end |
| 89 | + end |
| 90 | + end |
| 91 | +end |
0 commit comments