diff --git a/cookbooks/aws-parallelcluster-slurm/kitchen.slurm-install.yml b/cookbooks/aws-parallelcluster-slurm/kitchen.slurm-install.yml index 1368a9514..04666c35a 100644 --- a/cookbooks/aws-parallelcluster-slurm/kitchen.slurm-install.yml +++ b/cookbooks/aws-parallelcluster-slurm/kitchen.slurm-install.yml @@ -34,6 +34,15 @@ suites: - /mysql_client/ attributes: resource: mysql_client + - name: mysql_repo_add + run_list: + - recipe[aws-parallelcluster-tests::setup] + - recipe[aws-parallelcluster-tests::test_resource] + verifier: + controls: + - tag:install_mysql_repo_added + attributes: + resource: mysql_repo:add - name: munge run_list: - recipe[aws-parallelcluster-tests::setup] diff --git a/cookbooks/aws-parallelcluster-slurm/libraries/helpers.rb b/cookbooks/aws-parallelcluster-slurm/libraries/helpers.rb index 7aa393e35..d6134ac11 100644 --- a/cookbooks/aws-parallelcluster-slurm/libraries/helpers.rb +++ b/cookbooks/aws-parallelcluster-slurm/libraries/helpers.rb @@ -148,3 +148,18 @@ def get_target_group_name(cluster_name, pool_name) hash_value = Digest::SHA256.hexdigest(combined_name)[0..15] "#{partial_cluster_name}-#{partial_pool_name}-#{hash_value}" end + +def validate_file_hash(file_path, expected_hash) + hash_function = yield + checksum = hash_function.file(file_path).hexdigest + if checksum != expected_hash + raise "Downloaded file #{file_path} checksum #{checksum} does not match expected checksum #{expected_hash}" + end +end + +def validate_file_md5_hash(file_path, expected_hash) + validate_file_hash(file_path, expected_hash) do + require 'digest' + Digest::MD5 + end +end diff --git a/cookbooks/aws-parallelcluster-slurm/recipes/install.rb b/cookbooks/aws-parallelcluster-slurm/recipes/install.rb index 095c7ce95..7139a27e2 100644 --- a/cookbooks/aws-parallelcluster-slurm/recipes/install.rb +++ b/cookbooks/aws-parallelcluster-slurm/recipes/install.rb @@ -17,6 +17,7 @@ dns_domain "Install dns related packages" mysql_client 'Install mysql client' +mysql_repo 'Configure mysql repository' include_recipe 'aws-parallelcluster-slurm::install_jwt' include_recipe 'aws-parallelcluster-slurm::install_pmix' munge 'Install munge' do diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_amazon2.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_amazon2.rb new file mode 100644 index 000000000..1edbf8a73 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_amazon2.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +provides :mysql_repo, platform: 'amazon', platform_version: '2' + +use 'partial/_mysql_repo_rpm.rb' + +def md5_signature + '42048ccae58835e40e37b68a3f8b91fb' +end + +def file_name + 'mysql80-community-release-el7-11.noarch.rpm' +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_centos7.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_centos7.rb new file mode 100644 index 000000000..1c4eb8ce4 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_centos7.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +provides :mysql_repo, platform: 'centos' do |node| + node['platform_version'].to_i == 7 +end + +use 'partial/_mysql_repo_rpm.rb' + +def md5_signature + '42048ccae58835e40e37b68a3f8b91fb' +end + +def file_name + 'mysql80-community-release-el7-11.noarch.rpm' +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_redhat8.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_redhat8.rb new file mode 100644 index 000000000..d11eed55b --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_redhat8.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +provides :mysql_repo, platform: 'redhat' do |node| + node['platform_version'].to_i == 8 +end + +use 'partial/_mysql_repo_rpm.rb' + +def md5_signature + '42048ccae58835e40e37b68a3f8b91fb' +end + +def file_name + 'mysql80-community-release-el8-9.noarch.rpm' +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_rocky8.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_rocky8.rb new file mode 100644 index 000000000..d02a2b5d4 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_rocky8.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +provides :mysql_repo, platform: 'rocky' do |node| + node['platform_version'].to_i == 8 +end + +use 'partial/_mysql_repo_rpm.rb' + +def md5_signature + '42048ccae58835e40e37b68a3f8b91fb' +end + +def file_name + 'mysql80-community-release-el8-9.noarch.rpm' +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_ubuntu20+.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_ubuntu20+.rb new file mode 100644 index 000000000..68f6f3d82 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/mysql_repo_ubuntu20+.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +provides :mysql_repo, platform: 'ubuntu' do |node| + node['platform_version'].to_i >= 20 +end + +use 'partial/_mysql_repo_deb.rb' + +def md5_signature + '42048ccae58835e40e37b68a3f8b91fb' +end + +def file_name + 'mysql-apt-config_0.8.26-1_all.deb' +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_deb.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_deb.rb new file mode 100644 index 000000000..9916ecf51 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_deb.rb @@ -0,0 +1,41 @@ +unified_mode true +default_action :add + +action :add do + remote_file local_path do + source repository_package + mode '0644' + retries 3 + retry_delay 5 + action :create_if_missing + end + + ruby_block "Validate Repository Definition Checksum" do + block do + validate_file_md5_hash(local_path, md5_signature) + end + not_if { ::File.exist?(local_path) } + end + + dpkg_package repository_name do + source local_path + end + + apt_update 'update' do + action :update + retries 3 + retry_delay 5 + end +end + +def repository_name + 'MySQL Repository' +end + +def repository_package + "https://dev.mysql.com/get/#{file_name}" +end + +def local_path + "/tmp/#{file_name}" +end diff --git a/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_rpm.rb b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_rpm.rb new file mode 100644 index 000000000..3c59e193e --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/resources/mysql_repo/partial/_mysql_repo_rpm.rb @@ -0,0 +1,35 @@ +unified_mode true +default_action :add + +action :add do + remote_file local_path do + source repository_package + mode '0644' + retries 3 + retry_delay 5 + action :create_if_missing + end + + ruby_block "Validate Repository Definition Checksum" do + block do + validate_file_md5_hash(local_path, md5_signature) + end + not_if { ::File.exist?(local_path) } + end + + package repository_name do + source local_path + end +end + +def repository_name + 'MySQL Repository' +end + +def repository_package + "https://dev.mysql.com/get/#{file_name}" +end + +def local_path + "/tmp/#{file_name}" +end diff --git a/cookbooks/aws-parallelcluster-slurm/test/controls/mysql_repo_spec.rb b/cookbooks/aws-parallelcluster-slurm/test/controls/mysql_repo_spec.rb new file mode 100644 index 000000000..3b1839e59 --- /dev/null +++ b/cookbooks/aws-parallelcluster-slurm/test/controls/mysql_repo_spec.rb @@ -0,0 +1,29 @@ +# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "LICENSE.txt" file accompanying this file. +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. +# See the License for the specific language governing permissions and limitations under the License. + +control 'tag:install_mysql_repo_added' do + if os_properties.ubuntu? + describe file('/etc/apt/sources.list.d/mysql.list') do + it { should exist } + its('content') { should match /mysql-apt-config/ } + its('content') { should match /mysql-8.0/ } + its('content') { should match /mysql-tools/ } + its('content') { should match /mysql-tools-preview/ } + end + else + %w(mysql-connectors-community mysql-tools-community mysql80-community).each do |repo_name| + describe yum.repo(repo_name) do + it { should exist } + it { should be_enabled } + end + end + end +end