Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for tenancy parameter in placement config. #235

Merged
merged 13 commits into from
Feb 7, 2017
8 changes: 8 additions & 0 deletions lib/kitchen/driver/aws/instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
end
i[:placement] = { :availability_zone => availability_zone.downcase }
end
tenancy = config[:tenancy]
if tenancy && %w[default dedicated].include?(tenancy)
if i.key?(:placement)
i[:placement][:tenancy] = tenancy
else
i[:placement] = { :tenancy => tenancy }
end
end
unless config[:block_device_mappings].nil? || config[:block_device_mappings].empty?
i[:block_device_mappings] = config[:block_device_mappings]
end
Expand Down
1 change: 1 addition & 0 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Ec2 < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength
default_config :interface, nil
default_config :http_proxy, ENV["HTTPS_PROXY"] || ENV["HTTP_PROXY"]
default_config :retry_limit, 3
default_config :tenancy, "dedicated"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the real default value when tenancy is not specified. I guess that by default should be "default". Guess not everybody wants to use dedicated instances.


required_config :aws_ssh_key_id

Expand Down
61 changes: 61 additions & 0 deletions spec/kitchen/driver/ec2/instance_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,67 @@
end
end

context "when availability_zone and tenancy are provided" do
let(:config) do
{
:region => "eu-east-1",
:availability_zone => "c",
:tenancy => "dedicated"
}
end
it "adds the region to it in the instance data" do
expect(generator.ec2_instance_data).to eq(
:instance_type => nil,
:ebs_optimized => nil,
:image_id => nil,
:key_name => nil,
:subnet_id => nil,
:private_ip_address => nil,
:placement => { :availability_zone => "eu-east-1c",
:tenancy => "dedicated" }
)
end
end

context "when tenancy is provided but availability_zone isn't" do
let(:config) do
{
:region => "eu-east-1",
:tenancy => "default"
}
end
it "is not added to the instance data" do
expect(generator.ec2_instance_data).to eq(
:instance_type => nil,
:ebs_optimized => nil,
:image_id => nil,
:key_name => nil,
:subnet_id => nil,
:private_ip_address => nil,
:placement => { :tenancy => "default" }
)
end
end

context "when tenancy is not supported" do
let(:config) do
{
:region => "eu-east-1",
:tenancy => "ephemeral"
}
end
it "is not added to the instance data" do
expect(generator.ec2_instance_data).to eq(
:instance_type => nil,
:ebs_optimized => nil,
:image_id => nil,
:key_name => nil,
:subnet_id => nil,
:private_ip_address => nil
)
end
end

context "when subnet_id is provided" do
let(:config) do
{
Expand Down