diff --git a/CHANGELOG.md b/CHANGELOG.md index 9176f3a..d782969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # kitchen-oci CHANGELOG +# 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/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..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 = config[:image_name].gsub(" ", "-") + 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,6 +77,14 @@ def image_id_by_name latest_image_id(image_list) end + 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" + 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..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.0" + OCI_VERSION = "1.25.0" end end diff --git a/spec/kitchen/driver/image_id_spec.rb b/spec/kitchen/driver/image_id_spec.rb index bf8006d..dc48776 100644 --- a/spec/kitchen/driver/image_id_spec.rb +++ b/spec/kitchen/driver/image_id_spec.rb @@ -60,3 +60,39 @@ it_behaves_like "image_name provided", images end end + +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_conversion)).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