Skip to content

Commit

Permalink
Merge pull request test-kitchen#301 from test-kitchen/cleanup
Browse files Browse the repository at this point in the history
Use Chefstyle and require Ruby 2.2.2
  • Loading branch information
tas50 authored Apr 7, 2017
2 parents 068b4c1 + 1e142c9 commit aac18fd
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 263 deletions.
21 changes: 0 additions & 21 deletions .rubocop.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
language: ruby
cache: bundler
sudo: false
branches:
only:
- master
rvm:
- 2.2.6
- 2.3.1
- 2.3.3
- 2.4.0
- ruby-head
8 changes: 2 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ source "https://rubygems.org"

# Specify your gem"s dependencies in kitchen-ec2.gemspec
gemspec
gem "test-kitchen"

gem "winrm-transport"
gem "winrm-fs"
gem "activesupport", "~> 4.0"
gem "faraday-http-cache", "~> 1.3"

group :test do
gem "rake", "< 12"
gem "rake"
gem "pry"
end

group :development do
gem "github_changelog_generator"
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ task :stats do
sh "countloc -r spec features"
end

require "finstyle"
require "chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options << "--display-cop-names"
Expand Down
11 changes: 4 additions & 7 deletions kitchen-ec2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.required_ruby_version = ">= 2.2.2"

gem.add_dependency "test-kitchen", "~> 1.4", ">= 1.4.1"
gem.add_dependency "excon"
gem.add_dependency "multi_json"
Expand All @@ -30,16 +32,11 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "simplecov", "~> 0.7"
gem.add_development_dependency "yard", "~> 0.8"

# conflicts with finstyle 1.4.0
# gem.add_development_dependency "github_changelog_generator"
gem.add_development_dependency "github_changelog_generator"

# style and complexity libraries are tightly version pinned as newer releases
# may introduce new and undesireable style choices which would be immediately
# enforced in CI
gem.add_development_dependency "finstyle", "1.4.0"
gem.add_development_dependency "chefstyle", "= 0.5.0"
gem.add_development_dependency "climate_control"

# github_changelog_generator -> github-api -> oauth2 -> rack
# rack being unconstrained breaks Ruby 2.1 installs
gem.add_development_dependency "rack", "~> 1.0"
end
32 changes: 16 additions & 16 deletions lib/kitchen/driver/aws/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ def initialize( # rubocop:disable Metrics/ParameterLists
def self.get_credentials(profile_name, access_key_id, secret_access_key, session_token,
region, options = {})
source_creds =
if access_key_id && secret_access_key
::Aws::Credentials.new(access_key_id, secret_access_key, session_token)
elsif ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
::Aws::Credentials.new(
ENV["AWS_ACCESS_KEY_ID"],
ENV["AWS_SECRET_ACCESS_KEY"],
ENV["AWS_SESSION_TOKEN"]
)
elsif profile_name
::Aws::SharedCredentials.new(:profile_name => profile_name)
elsif default_shared_credentials?
::Aws::SharedCredentials.new
else
::Aws::InstanceProfileCredentials.new(:retries => 1)
end
if access_key_id && secret_access_key
::Aws::Credentials.new(access_key_id, secret_access_key, session_token)
elsif ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
::Aws::Credentials.new(
ENV["AWS_ACCESS_KEY_ID"],
ENV["AWS_SECRET_ACCESS_KEY"],
ENV["AWS_SESSION_TOKEN"]
)
elsif profile_name
::Aws::SharedCredentials.new(:profile_name => profile_name)
elsif default_shared_credentials?
::Aws::SharedCredentials.new
else
::Aws::InstanceProfileCredentials.new(:retries => 1)
end

if options[:assume_role_arn] && options[:assume_role_session_name]
sts = ::Aws::STS::Client.new(:credentials => source_creds, :region => region)
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_instance_from_spot_request(request_id)
resource.instances(
:filters => [{
:name => "spot-instance-request-id",
:values => [request_id]
:values => [request_id],
}]
).to_a[0]
end
Expand Down
20 changes: 10 additions & 10 deletions lib/kitchen/driver/aws/instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
:filters => [
{
:name => "tag:#{config[:subnet_filter][:tag]}",
:values => [config[:subnet_filter][:value]]
}
:values => [config[:subnet_filter][:value]],
},
]
)[0][0].subnet_id

if config[:subnet_id].nil?
fail "The subnet tagged '#{config[:subnet_filter][:tag]}\
raise "The subnet tagged '#{config[:subnet_filter][:tag]}\
#{config[:subnet_filter][:value]}' does not exist!"
end
end
Expand All @@ -66,13 +66,13 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
:filters => [
{
:name => "tag:#{config[:security_group_filter][:tag]}",
:values => [config[:security_group_filter][:value]]
}
:values => [config[:security_group_filter][:value]],
},
]
)[0][0].group_id]

if config[:security_group_ids].nil?
fail "The group tagged '#{config[:security_group_filter][:tag]}\
raise "The group tagged '#{config[:security_group_filter][:tag]}\
#{config[:security_group_filter][:value]}' does not exist!"
end
end
Expand All @@ -83,7 +83,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
:image_id => config[:image_id],
:key_name => config[:aws_ssh_key_id],
:subnet_id => config[:subnet_id],
:private_ip_address => config[:private_ip_address]
:private_ip_address => config[:private_ip_address],
}

availability_zone = config[:availability_zone]
Expand All @@ -94,7 +94,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
i[:placement] = { :availability_zone => availability_zone.downcase }
end
tenancy = config[:tenancy]
if tenancy && %w[default dedicated].include?(tenancy)
if tenancy && %w{default dedicated}.include?(tenancy)
if i.key?(:placement)
i[:placement][:tenancy] = tenancy
else
Expand All @@ -114,7 +114,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
[{
:device_index => 0,
:associate_public_ip_address => config[:associate_public_ip],
:delete_on_termination => true
:delete_on_termination => true,
}]
# If specifying `:network_interfaces` in the request, you must specify
# network specific configs in the network_interfaces block and not at
Expand All @@ -137,7 +137,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
i[:placement] = { :availability_zone => availability_zone.downcase }
end
tenancy = config[:tenancy]
if tenancy && %w[default dedicated].include?(tenancy)
if tenancy && %w{default dedicated}.include?(tenancy)
if i.key?(:placement)
i[:placement][:tenancy] = tenancy
else
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/driver/aws/standard_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def self.from_image(driver, image)
#
# The list of supported architectures
#
ARCHITECTURE = %w[x86_64 i386 i86pc sun4v powerpc]
ARCHITECTURE = %w{x86_64 i386 i86pc sun4v powerpc}

protected

Expand All @@ -162,7 +162,7 @@ def sort_by_version(images)
images.group_by do |image|
platform = self.class.from_image(driver, image)
platform ? platform.version : nil
end.sort_by { |k, _v| k ? k.to_f : nil }.reverse.map { |_k, v| v }.flatten(1)
end.sort_by { |k, _v| k ? k.to_f : nil }.reverse.flat_map { |_k, v| v }
end

# Not supported yet: aix mac_os_x nexus solaris
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/driver/aws/standard_platform/centos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def username
def image_search
search = {
"owner-alias" => "aws-marketplace",
"name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"]
"name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"],
}
search["architecture"] = architecture if architecture
search
Expand All @@ -30,7 +30,7 @@ def sort_by_version(images)
# ...
images.group_by { |image| self.class.from_image(driver, image).version }.
sort_by { |k, _v| (k && k.include?(".") ? k.to_f : "#{k}.999".to_f) }.
reverse.map { |_k, v| v }.flatten(1)
reverse.flat_map { |_k, v| v }
end

def self.from_image(driver, image)
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/driver/aws/standard_platform/debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Debian < StandardPlatform
DEBIAN_CODENAMES = {
"8" => "jessie",
"7" => "wheezy",
"6" => "squeeze"
"6" => "squeeze",
}

def username
Expand All @@ -25,7 +25,7 @@ def codename
def image_search
search = {
"owner-id" => "379101102735",
"name" => "debian-#{codename}-*"
"name" => "debian-#{codename}-*",
}
search["architecture"] = architecture if architecture
search
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def username
def image_search
search = {
"owner-id" => "125523088429",
"name" => version ? "Fedora-Cloud-Base-#{version}-*" : "Fedora-Cloud-Base-*"
"name" => version ? "Fedora-Cloud-Base-#{version}-*" : "Fedora-Cloud-Base-*",
}
search["architecture"] = architecture if architecture
search
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/freebsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sudo_command
def image_search
search = {
"owner-id" => "118940168514",
"name" => ["FreeBSD #{version}*-RELEASE*", "FreeBSD/EC2 #{version}*-RELEASE*"]
"name" => ["FreeBSD #{version}*-RELEASE*", "FreeBSD/EC2 #{version}*-RELEASE*"],
}
search["architecture"] = architecture if architecture
search
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/rhel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def username
def image_search
search = {
"owner-id" => "309956199498",
"name" => "RHEL-#{version}*"
"name" => "RHEL-#{version}*",
}
search["architecture"] = architecture if architecture
search
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/ubuntu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def username
def image_search
search = {
"owner-id" => "099720109477",
"name" => "ubuntu/images/*/ubuntu-*-#{version}*"
"name" => "ubuntu/images/*/ubuntu-*-#{version}*",
}
search["architecture"] = architecture if architecture
search
Expand Down
6 changes: 3 additions & 3 deletions lib/kitchen/driver/aws/standard_platform/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def username
def image_search
search = {
"owner-alias" => "amazon",
"name" => windows_name_filter
"name" => windows_name_filter,
}
search["architecture"] = architecture if architecture
search
Expand All @@ -47,7 +47,7 @@ def sort_by_version(images)
# ...
images.group_by { |image| self.class.from_image(driver, image).windows_version_parts }.
sort_by { |version, _platform_images| version }.
reverse.map { |_version, platform_images| platform_images }.flatten(1)
reverse.flat_map { |_version, platform_images| platform_images }
end

def self.from_image(driver, image)
Expand Down Expand Up @@ -101,7 +101,7 @@ def windows_version_parts

# Turn service_pack into an integer. rtm = 0, spN = N.
if service_pack
service_pack = (service_pack.downcase == "rtm") ? 0 : service_pack[2..-1].to_i
service_pack = (service_pack.casecmp("rtm") == 0) ? 0 : service_pack[2..-1].to_i
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class Ec2 < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength

plugin_version Kitchen::Driver::EC2_VERSION

default_config :region, ENV["AWS_REGION"] || "us-east-1"
default_config :region, ENV["AWS_REGION"] || "us-east-1"
default_config :shared_credentials_profile, nil
default_config :availability_zone, nil
default_config :availability_zone, nil
default_config :instance_type do |driver|
driver.default_instance_type
end
default_config :ebs_optimized, false
default_config :security_group_ids, nil
default_config :tags, "created-by" => "test-kitchen"
default_config :tags, "created-by" => "test-kitchen"
default_config :user_data do |driver|
if driver.windows_os?
driver.default_windows_user_data
Expand All @@ -83,7 +83,7 @@ class Ec2 < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength
default_config :retry_limit, 3
default_config :tenancy, "default"
default_config :instance_initiated_shutdown_behavior, nil
default_config :ssl_verify_peer, true
default_config :ssl_verify_peer, true

def initialize(*args, &block)
super
Expand Down Expand Up @@ -372,7 +372,7 @@ def create_spot_request
request_data = {
:spot_price => config[:spot_price].to_s,
:launch_specification => instance_generator.ec2_instance_data,
:valid_until => Time.now + request_duration
:valid_until => Time.now + request_duration,
}
if config[:block_duration_minutes]
request_data[:block_duration_minutes] = config[:block_duration_minutes]
Expand Down Expand Up @@ -491,7 +491,7 @@ def fetch_windows_admin_password(server, state)
"dns" => "public_dns_name",
"public" => "public_ip_address",
"private" => "private_ip_address",
"private_dns" => "private_dns_name"
"private_dns" => "private_dns_name",
}

#
Expand Down
6 changes: 3 additions & 3 deletions spec/kitchen/driver/ec2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
end

context "when provided all optional parameters" do
let(:client) {
let(:client) do
Kitchen::Driver::Aws::Client.new(
"us-west-1",
"profile_name",
Expand All @@ -175,7 +175,7 @@
999,
false
)
}
end
let(:creds) { double("creds") }
it "Sets the AWS config" do
expect(Kitchen::Driver::Aws::Client).to receive(:get_credentials).and_return(creds)
Expand All @@ -202,7 +202,7 @@ def env_creds(key_id, secret, &block)
"AWS_ACCESS_KEY_ID" => key_id,
"AWS_SECRET_ACCESS_KEY" => secret
) do
block.call
yield
end
end
end
Loading

0 comments on commit aac18fd

Please sign in to comment.