Skip to content

Commit 8100c59

Browse files
authored
feat: allow image_name to function the same for ARM as it does for x86_64 (#72)
* updated ARM image searching
1 parent 34e5302 commit 8100c59

5 files changed

Lines changed: 56 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# kitchen-oci CHANGELOG
22

3+
# 1.25.0
4+
- feat: allow `image_name` to function the same for ARM as it does for Linux
5+
36
# 1.24.0
47
- feat: change pessimistic lock on oci gem to just `~> 2.18`
58

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ OR
7575
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
7676
name of the image rather than the ocid. There are two ways to do this:
7777

78-
- specify the entire image name. For example, `Oracle-Linux-8.9-2024.02.26-0`
79-
- specify the un-dated, un-versioned portion of the display name. For example, `Oracle-Linux-8.9`\
78+
- Specify the entire image name. For example, `Oracle-Linux-8.9-2024.02.26-0`
79+
- Specify the un-dated, un-versioned portion of the display name. For example, `Oracle-Linux-8.9`\
8080
Note: for aesthetics, the dashes can be replaced with spaces `Oracle Linux 8.9`. Both ways work, one way is prettier.
8181
- Regular Expressions are also supported. For example, `Oracle Linux 8.\d+` will give the latest `Oracle Linux 8.x`\
8282
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.
83+
- 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`\
84+
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.\
85+
[ARM Documentation Here](https://docs.oracle.com/en-us/iaas/Content/Compute/References/arm.htm)
86+
- **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.\
87+
[OCI Documentation Here](https://docs.oracle.com/en-us/iaas/tools/ruby/2.21.0/OCI/Core/ComputeClient.html#list_images-instance_method)
8388

8489
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
8590
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.

lib/kitchen/driver/oci/models/compute.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def image_id
6767
end
6868

6969
def image_id_by_name
70-
image_name = config[:image_name].gsub(" ", "-")
70+
image_name = image_name_conversion
7171
image_list = images.select { |i| i.display_name.match(/#{image_name}/) }
7272
raise "unable to find image_id" if image_list.empty?
7373

@@ -77,6 +77,14 @@ def image_id_by_name
7777
latest_image_id(image_list)
7878
end
7979

80+
def image_name_conversion
81+
image_name = config[:image_name].gsub(" ", "-")
82+
if config[:shape] =~ /^VM\.Standard\.A\d+\.Flex$/ && !config[:image_name].include?("aarch64")
83+
image_name = "#{image_name}-aarch64"
84+
end
85+
image_name
86+
end
87+
8088
def filter_image_list(image_list, image_name)
8189
image_list.select { |i| i.display_name.match(/#{image_name}-[0-9]{4}\.[0-9]{2}\.[0-9]{2}/) }
8290
end

lib/kitchen/driver/oci_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
module Kitchen
2121
module Driver
2222
# Version string for Oracle OCI Kitchen driver
23-
OCI_VERSION = "1.24.0"
23+
OCI_VERSION = "1.25.0"
2424
end
2525
end

spec/kitchen/driver/image_id_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,39 @@
6060
it_behaves_like "image_name provided", images
6161
end
6262
end
63+
64+
describe Kitchen::Driver::Oci::Models::Compute do
65+
include_context "compute"
66+
include_context "create"
67+
68+
context "append aarch64 for ARM shapes" do
69+
subject { Kitchen::Driver::Oci::Models::Compute.new(driver_config, state, oci_config, api, :create) }
70+
let(:state) { {} }
71+
let(:api) { Kitchen::Driver::Oci::Api.new(oci, driver_config) }
72+
let(:driver_config) do
73+
base_driver_config.merge!(
74+
{
75+
image_id: nil,
76+
image_name: "Oracle-Linux-9.3", # test with an image name that does not include aarch64
77+
shape: "VM.Standard.A1.Flex", # Arm shape
78+
}
79+
)
80+
end
81+
82+
before do
83+
allow(compute_client).to receive(:list_images).and_return(list_images_response)
84+
allow(list_images_response).to receive(:next_page).and_return(nil)
85+
end
86+
87+
it "adjusts the image name to include -aarch64" do
88+
expected_image_name = "Oracle-Linux-9.3-aarch64"
89+
expect(subject.send(:image_name_conversion)).to eq(expected_image_name)
90+
end
91+
92+
it "selects the right image ocid for Oracle-Linux-9.3" do
93+
expected_image_ocid = "ocid1.image.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz147852"
94+
selected_image_id = subject.send(:image_id)
95+
expect(selected_image_id).to eq(expected_image_ocid)
96+
end
97+
end
98+
end

0 commit comments

Comments
 (0)