From 2c32c9070d7d9f4be93c5b11e7af47ca628f83e9 Mon Sep 17 00:00:00 2001 From: Default User Date: Mon, 23 Dec 2024 15:51:14 -0700 Subject: [PATCH 1/4] updated ARM image searching --- CHANGELOG.md | 3 ++ README.md | 9 ++++-- lib/kitchen/driver/oci/models/compute.rb | 10 ++++++- lib/kitchen/driver/oci_version.rb | 2 +- spec/kitchen/driver/image_id_spec.rb | 38 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9176f3a..ac11ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # kitchen-oci CHANGELOG +# 1.24.1 +- fix: allow `image_name` to function the same for ARM as it does for Linux + # 1.24.0 - feat: change pessimistic lock on oci gem to just `~> 2.18` diff --git a/README.md b/README.md index 654181a..69ce7e0 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,16 @@ OR Image ocids and display names can be found on the public [OCI Documentation / Images](https://docs.oracle.com/en-us/iaas/images/) page. The `image_name` property allows you to specify the display name of the image rather than the ocid. There are two ways to do this: -- specify the entire image name. For example, `Oracle-Linux-8.9-2024.02.26-0` -- specify the un-dated, un-versioned portion of the display name. For example, `Oracle-Linux-8.9`\ +- Specify the entire image name. For example, `Oracle-Linux-8.9-2024.02.26-0` +- Specify the un-dated, un-versioned portion of the display name. For example, `Oracle-Linux-8.9`\ Note: for aesthetics, the dashes can be replaced with spaces `Oracle Linux 8.9`. Both ways work, one way is prettier. - Regular Expressions are also supported. For example, `Oracle Linux 8.\d+` will give the latest `Oracle Linux 8.x`\ Note: be careful here. If the regular expression is too broad, the newest image id of the matching set will be returned and might not be of the desired operating system. +- For an ARM specific `shape` you can add in `-aarch64` to the `image_name`. For example, `Oracle-Linux-8.9-aarch64-2024.02.26-0` or `Oracle Linux 8.\d+-aarch64`\ + But you don't have to as if a `shape` matches `VM.Standard.A<##>.Flex` then `-aarch64` gets added automatically and `Oracle Linux 8.\d+` will work the same.\ + [ARM Documentation Here](https://docs.oracle.com/en-us/iaas/Content/Compute/References/arm.htm) +- **Caution:** Platform images are refreshed regularly. When new images are released, older versions are replaced. The image OCIDs remain available, but when the platform image is replaced, the image OCIDs are no longer returned as part of the platform image list.\ + [OCI Documentation Here](https://docs.oracle.com/en-us/iaas/tools/ruby/2.21.0/OCI/Core/ComputeClient.html#list_images-instance_method) If the second option is chosen (providing a portion of the display name), the behavior is to search all display names that match the string provided plus anything that looks like a date, then sort by time created and return the ocid for the newest one. This allows you to always get the latest version of a given image without having to continually update your kitchen.yml files. diff --git a/lib/kitchen/driver/oci/models/compute.rb b/lib/kitchen/driver/oci/models/compute.rb index 7d31f88..9714273 100644 --- a/lib/kitchen/driver/oci/models/compute.rb +++ b/lib/kitchen/driver/oci/models/compute.rb @@ -67,7 +67,7 @@ def image_id end def image_id_by_name - image_name = config[:image_name].gsub(" ", "-") + image_name = image_name_convertion image_list = images.select { |i| i.display_name.match(/#{image_name}/) } raise "unable to find image_id" if image_list.empty? @@ -77,6 +77,14 @@ def image_id_by_name latest_image_id(image_list) end + def image_name_convertion + image_name = config[:image_name].gsub(" ", "-") + if config[:shape] =~ /^VM\.Standard\.A\d+\.Flex$/ && !config[:image_name].include?("aarch64") + image_name = "#{image_name}-aarch64" + end + image_name + end + def filter_image_list(image_list, image_name) image_list.select { |i| i.display_name.match(/#{image_name}-[0-9]{4}\.[0-9]{2}\.[0-9]{2}/) } end diff --git a/lib/kitchen/driver/oci_version.rb b/lib/kitchen/driver/oci_version.rb index 85ba492..3f2896b 100644 --- a/lib/kitchen/driver/oci_version.rb +++ b/lib/kitchen/driver/oci_version.rb @@ -20,6 +20,6 @@ module Kitchen module Driver # Version string for Oracle OCI Kitchen driver - OCI_VERSION = "1.24.0" + OCI_VERSION = "1.24.1" end end diff --git a/spec/kitchen/driver/image_id_spec.rb b/spec/kitchen/driver/image_id_spec.rb index bf8006d..7689b97 100644 --- a/spec/kitchen/driver/image_id_spec.rb +++ b/spec/kitchen/driver/image_id_spec.rb @@ -19,6 +19,7 @@ require "spec_helper" +# First test block: Basic image name selection (without considering the shape) describe Kitchen::Driver::Oci::Models::Compute do include_context "compute" include_context "create" @@ -60,3 +61,40 @@ it_behaves_like "image_name provided", images end end + +# Image name selection with ARM shape set +describe Kitchen::Driver::Oci::Models::Compute do + include_context "compute" + include_context "create" + + context "append aarch64 for ARM shapes" do + subject { Kitchen::Driver::Oci::Models::Compute.new(driver_config, state, oci_config, api, :create) } + let(:state) { {} } + let(:api) { Kitchen::Driver::Oci::Api.new(oci, driver_config) } + let(:driver_config) do + base_driver_config.merge!( + { + image_id: nil, + image_name: "Oracle-Linux-9.3", # Test with an image name that does not include aarch64 + shape: "VM.Standard.A1.Flex", # ARM shape + } + ) + end + + before do + allow(compute_client).to receive(:list_images).and_return(list_images_response) + allow(list_images_response).to receive(:next_page).and_return(nil) + end + + it "adjusts the image name to include -aarch64" do + expected_image_name = "Oracle-Linux-9.3-aarch64" + expect(subject.send(:image_name_convertion)).to eq(expected_image_name) + end + + it "selects the right image ocid for Oracle-Linux-9.3" do + expected_image_ocid = "ocid1.image.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz147852" + selected_image_id = subject.send(:image_id) + expect(selected_image_id).to eq(expected_image_ocid) + end + end +end From 5aad873848f1758f5615f62e585af9a1ed1c0952 Mon Sep 17 00:00:00 2001 From: Default User Date: Mon, 23 Dec 2024 15:58:58 -0700 Subject: [PATCH 2/4] typo --- lib/kitchen/driver/oci/models/compute.rb | 4 ++-- spec/kitchen/driver/image_id_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kitchen/driver/oci/models/compute.rb b/lib/kitchen/driver/oci/models/compute.rb index 9714273..4cc7d31 100644 --- a/lib/kitchen/driver/oci/models/compute.rb +++ b/lib/kitchen/driver/oci/models/compute.rb @@ -67,7 +67,7 @@ def image_id end def image_id_by_name - image_name = image_name_convertion + image_name = image_name_conversion image_list = images.select { |i| i.display_name.match(/#{image_name}/) } raise "unable to find image_id" if image_list.empty? @@ -77,7 +77,7 @@ def image_id_by_name latest_image_id(image_list) end - def image_name_convertion + def image_name_conversion image_name = config[:image_name].gsub(" ", "-") if config[:shape] =~ /^VM\.Standard\.A\d+\.Flex$/ && !config[:image_name].include?("aarch64") image_name = "#{image_name}-aarch64" diff --git a/spec/kitchen/driver/image_id_spec.rb b/spec/kitchen/driver/image_id_spec.rb index 7689b97..80cf166 100644 --- a/spec/kitchen/driver/image_id_spec.rb +++ b/spec/kitchen/driver/image_id_spec.rb @@ -88,7 +88,7 @@ it "adjusts the image name to include -aarch64" do expected_image_name = "Oracle-Linux-9.3-aarch64" - expect(subject.send(:image_name_convertion)).to eq(expected_image_name) + expect(subject.send(:image_name_conversion)).to eq(expected_image_name) end it "selects the right image ocid for Oracle-Linux-9.3" do From c5d805cb1777d45140c1a55b1a09f5e44f3f251c Mon Sep 17 00:00:00 2001 From: Default User Date: Mon, 23 Dec 2024 16:10:34 -0700 Subject: [PATCH 3/4] cleanup of comments --- spec/kitchen/driver/image_id_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/kitchen/driver/image_id_spec.rb b/spec/kitchen/driver/image_id_spec.rb index 80cf166..dc48776 100644 --- a/spec/kitchen/driver/image_id_spec.rb +++ b/spec/kitchen/driver/image_id_spec.rb @@ -19,7 +19,6 @@ require "spec_helper" -# First test block: Basic image name selection (without considering the shape) describe Kitchen::Driver::Oci::Models::Compute do include_context "compute" include_context "create" @@ -62,7 +61,6 @@ end end -# Image name selection with ARM shape set describe Kitchen::Driver::Oci::Models::Compute do include_context "compute" include_context "create" @@ -75,8 +73,8 @@ base_driver_config.merge!( { image_id: nil, - image_name: "Oracle-Linux-9.3", # Test with an image name that does not include aarch64 - shape: "VM.Standard.A1.Flex", # ARM shape + image_name: "Oracle-Linux-9.3", # test with an image name that does not include aarch64 + shape: "VM.Standard.A1.Flex", # Arm shape } ) end From 48c633dedc73737cea1e557d92a85a0a05cceb91 Mon Sep 17 00:00:00 2001 From: Default User Date: Tue, 24 Dec 2024 07:51:00 -0700 Subject: [PATCH 4/4] bump version to 1.25.0 --- CHANGELOG.md | 4 ++-- lib/kitchen/driver/oci_version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac11ddd..d782969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # kitchen-oci CHANGELOG -# 1.24.1 -- fix: allow `image_name` to function the same for ARM as it does for Linux +# 1.25.0 +- feat: allow `image_name` to function the same for ARM as it does for Linux # 1.24.0 - feat: change pessimistic lock on oci gem to just `~> 2.18` diff --git a/lib/kitchen/driver/oci_version.rb b/lib/kitchen/driver/oci_version.rb index 3f2896b..5cca85d 100644 --- a/lib/kitchen/driver/oci_version.rb +++ b/lib/kitchen/driver/oci_version.rb @@ -20,6 +20,6 @@ module Kitchen module Driver # Version string for Oracle OCI Kitchen driver - OCI_VERSION = "1.24.1" + OCI_VERSION = "1.25.0" end end