Skip to content

Commit

Permalink
feat: add capacity_reservation_id for compute shapes (#69)
Browse files Browse the repository at this point in the history
* feat: add capacity_reservation_id for compute shapes
  • Loading branch information
justintsteele authored Sep 12, 2024
1 parent 6ee1df4 commit b6a10f7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# kitchen-oci CHANGELOG

# 1.23.0
- feat: add `capacity_reservation_id` for compute shapes

# 1.22.0
- feat: add `volume_id` to `volumes` config option to allow for cloning of block volumes
- feat: add `device` to `volumes` config option to allow for mapping block volumes on attachment
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ These settings are optional:
- `display_name`, Overrides the display name and hostname randomaization provided by the `hostname_prefix` setting
- `hostname_prefix`, Prefix for the generated hostnames (note that OCI doesn't like underscores)
- `preemptible_instance`, Boolean flag to indicate if the compute instance should be preemptible (default: `false`) [[more](#preemptible-instance)]
- `capacity_reservation_id`, OCID of the [capacity reservation](https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/reserve-capacity.htm) that should be used for provisioning the instance
- `shape_config`, Hash of shape config parameters required when using Flex shapes. [[more](#flex-shape-instances)]
- `ocpus`, number of CPUs requested
- `memory_in_gbs`, the amount of memory requested
Expand Down
1 change: 1 addition & 0 deletions lib/kitchen/driver/oci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Oci < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength
default_config :post_create_reboot, false

# compute only configs
default_config :capacity_reservation_id
default_config :setup_winrm, false
default_config :winrm_user, "opc"
default_config :winrm_password, nil
Expand Down
4 changes: 4 additions & 0 deletions lib/kitchen/driver/oci/instance/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def shape_config
)
end

def capacity_reservation
launch_details.capacity_reservation_id = config[:capacity_reservation_id]
end

def agent_config
launch_details.agent_config = OCI::Core::Models::LaunchInstanceAgentConfigDetails.new(
are_all_plugins_disabled: config[:all_plugins_disabled],
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/oci_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
module Kitchen
module Driver
# Version string for Oracle OCI Kitchen driver
OCI_VERSION = "1.22.0"
OCI_VERSION = "1.23.0"
end
end
35 changes: 19 additions & 16 deletions spec/kitchen/driver/compute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
include_context "create"

let(:state) { {} }
let(:driver_config) { base_driver_config }
let(:driver_config) { compute_driver_config }

context "standard compute (Linux)" do
it "creates a compute instance with no volumes" do
Expand Down Expand Up @@ -64,14 +64,15 @@
context "standard compute (Windows) with custom metadata" do
# kitchen.yml driver config section
let(:driver_config) do
base_driver_config.merge!({
setup_winrm: true,
winrm_password: "f4k3p@55w0rd",
custom_metadata: {
"hostclass" => "foo",
},
})
compute_driver_config.merge!({
setup_winrm: true,
winrm_password: "f4k3p@55w0rd",
custom_metadata: {
"hostclass" => "foo",
},
})
end

let(:instance_metadata) do
{
"ssh_authorized_keys" => ssh_pub_key,
Expand Down Expand Up @@ -102,13 +103,12 @@
context "standard compute with nsg" do
# kitchen.yml driver config section
let(:driver_config) do
base_driver_config.merge!({

nsg_ids: [
"ocid1.networksecuritygroup.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz12345",
"ocid1.networksecuritygroup.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz67890",
],
})
compute_driver_config.merge!({
nsg_ids: [
"ocid1.networksecuritygroup.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz12345",
"ocid1.networksecuritygroup.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz67890",
],
})
end

it "creates a compute instance with nsg_ids specified" do
Expand Down Expand Up @@ -374,6 +374,7 @@

context "standard compute" do
let(:state) { { server_id: instance_ocid } }
let(:driver_config) { compute_driver_config }

it "destroys a compute instance with no volumes" do
expect(compute_client).to receive(:terminate_instance).with(instance_ocid)
Expand All @@ -383,6 +384,7 @@
end

context "compute with volumes" do
let(:driver_config) { compute_driver_config }
let(:state) do
{
server_id: instance_ocid,
Expand All @@ -400,6 +402,7 @@
],
}
end

it "destroys a compute instance with volumes attached" do
expect(compute_client).to receive(:detach_volume).with(pv_attachment_ocid)
expect(blockstorage_client).to receive(:delete_volume).with(pv_volume_ocid)
Expand All @@ -413,7 +416,7 @@
include_context "create"

let(:state) { {} }
let(:driver_config) { base_driver_config.merge!({ post_create_reboot: true }) }
let(:driver_config) { compute_driver_config.merge!({ post_create_reboot: true }) }

before do
allow(compute_client).to receive(:instance_action).with(instance_ocid, "SOFTRESET")
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,14 @@
include_context "oci"
include_context "net"

let(:driver_config) { base_driver_config }
let(:compute_driver_config) { base_driver_config.merge!({ capacity_reservation_id: capacity_reservation }) }
let(:instance_ocid) { "ocid1.instance.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz12345" }
let(:instance_metadata) do
{
"ssh_authorized_keys" => ssh_pub_key,
}
end
let(:capacity_reservation) { "ocid1.capacityreservation.oc1.fake.aaaaaaaaaabcdefghijklmnopqrstuvwxyz12345" }
let(:launch_instance_request) do
OCI::Core::Models::LaunchInstanceDetails.new.tap do |l|
l.availability_domain = availability_domain
Expand All @@ -310,6 +311,7 @@
bootVolumeSizeInGBs: nil
)
l.shape = shape
l.capacity_reservation_id = capacity_reservation
l.create_vnic_details = OCI::Core::Models::CreateVnicDetails.new(
assign_public_ip: false,
display_name: hostname,
Expand Down

0 comments on commit b6a10f7

Please sign in to comment.