From 88fb3df5d4446ed5bb484e83ac744c36a8eac966 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 13:37:47 +0100 Subject: [PATCH 1/7] (feat) - Add ability to override default provisioner --- exe/matrix_from_metadata_v2 | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/exe/matrix_from_metadata_v2 b/exe/matrix_from_metadata_v2 index cfb3b945..a7861d12 100755 --- a/exe/matrix_from_metadata_v2 +++ b/exe/matrix_from_metadata_v2 @@ -94,6 +94,29 @@ else exclude_list = [] end +# Force the use of the provision_service provisioner, if the --provision-service argument is present +if ARGV.include?('--provision-service') + provision_service_occurrences = ARGV.count { |arg| arg == '--provision-service' } + raise 'the --provision-service argument should be present just one time in the command' unless provision_service_occurrences <= 1 + + # NOTE: that the below are the only available images for the provision service + updated_platforms = { + 'CentOS-7' => 'centos-7', + 'CentOS-8' => 'centos-stream-8', + 'Rocky-8' => 'rocky-linux-8', + 'Debian-10' => 'debian-10', + 'Debian-11' => 'debian-11', + 'Ubuntu-20.04' => 'ubuntu-2004-lts', + 'Ubuntu-22.04' => 'ubuntu-2204-lts' + } + + updated_list = IMAGE_TABLE.dup.clone + updated_list.merge!(updated_platforms) + + IMAGE_TABLE = updated_list.freeze + DOCKER_PLATFORMS = {}.freeze +end + metadata_path = ENV['TEST_MATRIX_FROM_METADATA'] || 'metadata.json' metadata = JSON.parse(File.read(metadata_path)) # Set platforms based on declared operating system support @@ -105,13 +128,13 @@ metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase) matrix[:platforms] << { label: image_key, - provider: 'provision::provision_service', + provider: 'provision_service', image: IMAGE_TABLE[image_key] } elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase) matrix[:platforms] << { label: image_key, - provider: 'provision::docker', + provider: 'docker', image: DOCKER_PLATFORMS[image_key] } else From 2e57ea60b4c898602069c1b710b3ff91fd9fc793 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 13:38:01 +0100 Subject: [PATCH 2/7] (feat) - Add ability to provide a custom matrix --- exe/matrix_from_metadata_v2 | 65 +++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/exe/matrix_from_metadata_v2 b/exe/matrix_from_metadata_v2 index a7861d12..d42ce697 100755 --- a/exe/matrix_from_metadata_v2 +++ b/exe/matrix_from_metadata_v2 @@ -119,27 +119,52 @@ end metadata_path = ENV['TEST_MATRIX_FROM_METADATA'] || 'metadata.json' metadata = JSON.parse(File.read(metadata_path)) -# Set platforms based on declared operating system support -metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup| - os = sup['operatingsystem'] - sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver| - image_key = "#{os}-#{ver}" - - if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase) - matrix[:platforms] << { - label: image_key, - provider: 'provision_service', - image: IMAGE_TABLE[image_key] - } - elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase) - matrix[:platforms] << { - label: image_key, - provider: 'docker', - image: DOCKER_PLATFORMS[image_key] - } + +if ARGV.include?('--custom-matrix') + custom_matrix_occurrences = ARGV.count { |arg| arg == '--custom-matrix' } + raise '--custom-matrix argument should be present just one time in the command' unless custom_matrix_occurrences <= 1 + + file_path = ARGV[ARGV.find_index('--custom-matrix') + 1] + raise 'you need to specify a file path' if file_path.nil? + + begin + custom_matrix = JSON.parse(File.read(file_path)) + rescue StandardError => e + case e + when JSON::ParserError + raise 'the matrix must be an array of valid JSON objects' + when Errno::ENOENT + raise "File not found: #{e.message}" else - puts "::warning::#{image_key} was excluded from testing" if exclude_list.include?(image_key.downcase) - puts "::warning::Cannot find image for #{image_key}" unless exclude_list.include?(image_key.downcase) + raise "An unknown exception occurred: #{e.message}" + end + end + custom_matrix.each do |platform| + matrix[:platforms] << platform + end +else + # Set platforms based on declared operating system support + metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup| + os = sup['operatingsystem'] + sup['operatingsystemrelease'].sort_by(&:to_i).each do |ver| + image_key = "#{os}-#{ver}" + + if IMAGE_TABLE.key?(image_key) && !exclude_list.include?(image_key.downcase) + matrix[:platforms] << { + label: image_key, + provider: 'provision_service', + image: IMAGE_TABLE[image_key] + } + elsif DOCKER_PLATFORMS.key?(image_key) && !exclude_list.include?(image_key.downcase) + matrix[:platforms] << { + label: image_key, + provider: 'docker', + image: DOCKER_PLATFORMS[image_key] + } + else + puts "::warning::#{image_key} was excluded from testing" if exclude_list.include?(image_key.downcase) + puts "::warning::Cannot find image for #{image_key}" unless exclude_list.include?(image_key.downcase) + end end end end From 1d0af2eab7eb857d73df7af93519556ebd765eeb Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 13:44:51 +0100 Subject: [PATCH 3/7] (maint) - remove unnecessary provision:: prefix --- spec/exe/matrix_from_metadata_v2_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/exe/matrix_from_metadata_v2_spec.rb b/spec/exe/matrix_from_metadata_v2_spec.rb index c7f65d34..4fa15fd1 100644 --- a/spec/exe/matrix_from_metadata_v2_spec.rb +++ b/spec/exe/matrix_from_metadata_v2_spec.rb @@ -22,9 +22,9 @@ [ 'matrix={', '"platforms":[', - '{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"},', - '{"label":"RedHat-8","provider":"provision::provision_service","image":"rhel-8"},', - '{"label":"Ubuntu-18.04","provider":"provision::docker","image":"litmusimage/ubuntu:18.04"}', + '{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},', + '{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"},', + '{"label":"Ubuntu-18.04","provider":"docker","image":"litmusimage/ubuntu:18.04"}', '],', '"collection":[', '"puppet7-nightly","puppet8-nightly"', @@ -59,8 +59,8 @@ [ 'matrix={', '"platforms":[', - '{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"},', - '{"label":"RedHat-8","provider":"provision::provision_service","image":"rhel-8"}', + '{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"},', + '{"label":"RedHat-8","provider":"provision_service","image":"rhel-8"}', '],', '"collection":[', '"puppet7-nightly","puppet8-nightly"', @@ -96,7 +96,7 @@ [ 'matrix={', '"platforms":[', - '{"label":"CentOS-6","provider":"provision::docker","image":"litmusimage/centos:6"}', + '{"label":"CentOS-6","provider":"docker","image":"litmusimage/centos:6"}', '],', '"collection":[', '"puppet7-nightly","puppet8-nightly"', From c17fd46732e5c245cbba7ad36f012b163e031788 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 13:46:34 +0100 Subject: [PATCH 4/7] (maint) - correct typo in warning --- lib/puppet_litmus/rake_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet_litmus/rake_helper.rb b/lib/puppet_litmus/rake_helper.rb index 7ac155d4..3eea2541 100644 --- a/lib/puppet_litmus/rake_helper.rb +++ b/lib/puppet_litmus/rake_helper.rb @@ -287,7 +287,7 @@ def provisioner_task(provisioner) if SUPPORTED_PROVISIONERS.include?(provisioner) "provision::#{provisioner}" else - warn "WARNING: Unsuported provisioner '#{provisioner}', try #{SUPPORTED_PROVISIONERS.join('/')}" + warn "WARNING: Unsupported provisioner '#{provisioner}', try #{SUPPORTED_PROVISIONERS.join('/')}" provisioner.to_s end end From 7d9c9addf7b8651e97505a2b0e310c4d61ffa72b Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 14:04:32 +0100 Subject: [PATCH 5/7] (maint) - add rocky/alma 8 gcp images --- exe/matrix_from_metadata_v2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exe/matrix_from_metadata_v2 b/exe/matrix_from_metadata_v2 index d42ce697..387b7ac1 100755 --- a/exe/matrix_from_metadata_v2 +++ b/exe/matrix_from_metadata_v2 @@ -101,9 +101,10 @@ if ARGV.include?('--provision-service') # NOTE: that the below are the only available images for the provision service updated_platforms = { + 'AlmaLinux-8' => 'almalinux-cloud/almalinux-8', 'CentOS-7' => 'centos-7', 'CentOS-8' => 'centos-stream-8', - 'Rocky-8' => 'rocky-linux-8', + 'Rocky-8' => 'rocky-linux-cloud/rocky-linux-8', 'Debian-10' => 'debian-10', 'Debian-11' => 'debian-11', 'Ubuntu-20.04' => 'ubuntu-2004-lts', @@ -120,6 +121,7 @@ end metadata_path = ENV['TEST_MATRIX_FROM_METADATA'] || 'metadata.json' metadata = JSON.parse(File.read(metadata_path)) +# Allow the user to pass a file containing a custom matrix if ARGV.include?('--custom-matrix') custom_matrix_occurrences = ARGV.count { |arg| arg == '--custom-matrix' } raise '--custom-matrix argument should be present just one time in the command' unless custom_matrix_occurrences <= 1 From a1ec97022e2447aa0ad6dabc7fc8b207829b1049 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Thu, 6 Jul 2023 15:04:22 +0100 Subject: [PATCH 6/7] (bug) - correct bug with ordering custom matrix --- exe/matrix_from_metadata_v2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exe/matrix_from_metadata_v2 b/exe/matrix_from_metadata_v2 index 387b7ac1..075b76fd 100755 --- a/exe/matrix_from_metadata_v2 +++ b/exe/matrix_from_metadata_v2 @@ -205,9 +205,8 @@ end # Set to defaults (all collections) if no matches are found matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" } if matrix[:collection].empty? - # Just to make sure there aren't any duplicates -matrix[:platforms] = matrix[:platforms].uniq.sort_by { |a| a[:label] } +matrix[:platforms] = matrix[:platforms].uniq.sort_by { |a| a[:label] } unless ARGV.include?('--custom-matrix') matrix[:collection] = matrix[:collection].uniq.sort set_output('matrix', JSON.generate(matrix)) From 4aec93a682e55a7d24231ca14a8a9c3cc950a680 Mon Sep 17 00:00:00 2001 From: jordanbreen28 <112936862+jordanbreen28@users.noreply.github.com> Date: Thu, 6 Jul 2023 15:11:07 +0100 Subject: [PATCH 7/7] (maint) - Update warning Co-authored-by: Gavin Patton <66372268+GSPatton@users.noreply.github.com> --- exe/matrix_from_metadata_v2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exe/matrix_from_metadata_v2 b/exe/matrix_from_metadata_v2 index 075b76fd..be33f1a0 100755 --- a/exe/matrix_from_metadata_v2 +++ b/exe/matrix_from_metadata_v2 @@ -127,7 +127,7 @@ if ARGV.include?('--custom-matrix') raise '--custom-matrix argument should be present just one time in the command' unless custom_matrix_occurrences <= 1 file_path = ARGV[ARGV.find_index('--custom-matrix') + 1] - raise 'you need to specify a file path' if file_path.nil? + raise 'no file path specified' if file_path.nil? begin custom_matrix = JSON.parse(File.read(file_path))