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

Use match? instead of =~ to reduce memory usage #508

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
## [v3.0.0](https://github.com/test-kitchen/kitchen-ec2/tree/v3.0.0) (2019-05-01)
[Full Changelog](https://github.com/test-kitchen/kitchen-ec2/compare/v2.4.0..v3.0.0)

- Switch from the monolithic aws-sdk-v2 to the just aws-sdk-ec2 aka aws-sdk-v3. This greatly reduces the number of dependencies necessary for this plugin, but is a major change that makes it incompatible with older released of Chef-DK that require aws-sdk-v2.
- Switch from the monolithic aws-sdk-v2 to the just aws-sdk-ec2 aka aws-sdk-v3. This greatly reduces the number of dependencies necessary for this plugin, but is a major change that makes it incompatible with older released of ChefDK that require aws-sdk-v2.
- Require Ruby 2.3 or later as Ruby 2.2 is now EOL
- Loosen the dependency on Test Kitchen to allow this plugin to work with Test Kitchen 2.0
- Fix hostname detection to not fail when the system doesn't have a public IP. Thanks [@niekrasp](https://github.com/niekrasp)
Expand Down Expand Up @@ -297,7 +297,7 @@

**Closed issues:**

- Requesting to include this plug-in in Chefdk [\#218](https://github.com/test-kitchen/kitchen-ec2/issues/218)
- Requesting to include this plug-in in ChefDK [\#218](https://github.com/test-kitchen/kitchen-ec2/issues/218)
- Can't ssh to instance after it's created [\#217](https://github.com/test-kitchen/kitchen-ec2/issues/217)
- No installation instructions [\#216](https://github.com/test-kitchen/kitchen-ec2/issues/216)
- availability\_zone is always b [\#215](https://github.com/test-kitchen/kitchen-ec2/issues/215)
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/driver/aws/instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize

availability_zone = config[:availability_zone]
if availability_zone
if availability_zone =~ /^[a-z]$/i
if /^[a-z]$/i.match?(availability_zone)
availability_zone = "#{config[:region]}#{availability_zone}"
end
i[:placement] = { availability_zone: availability_zone.downcase }
Expand Down Expand Up @@ -175,7 +175,7 @@ def ec2_instance_data # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
end
availability_zone = config[:availability_zone]
if availability_zone
if availability_zone =~ /^[a-z]$/i
if /^[a-z]$/i.match?(availability_zone)
availability_zone = "#{config[:region]}#{availability_zone}"
end
i[:placement] = { availability_zone: availability_zone.downcase }
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/amazon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /amzn-ami/i
if /amzn-ami/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+[\.\d])?)/i
new(driver, "amazon", (Regexp.last_match || [])[1], image.architecture)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/amazon2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /amzn2-ami/i
if /amzn2-ami/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+[\.\d])?)/i
new(driver, "amazon2", (Regexp.last_match || [])[1], image.architecture)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/centos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def sort_by_version(images)
end

def self.from_image(driver, image)
if image.name =~ /centos/i
if /centos/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+)?)\b/i
new(driver, "centos", (Regexp.last_match || [])[1], image.architecture)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /debian/i
if /debian/i.match?(image.name)
image.name =~ /\b(\d+|#{DEBIAN_CODENAMES.values.join("|")})\b/i
version = (Regexp.last_match || [])[1]
if version && version.to_i == 0
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 @@ -39,7 +39,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /fedora/i
if /fedora/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+)?)\b/i
new(driver, "fedora", (Regexp.last_match || [])[1], image.architecture)
end
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 @@ -41,7 +41,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /freebsd/i
if /freebsd/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+)?)\b/i
new(driver, "freebsd", (Regexp.last_match || [])[1], image.architecture)
end
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 @@ -45,7 +45,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /rhel/i
if /rhel/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+)?)/i
new(driver, "rhel", (Regexp.last_match || [])[1], image.architecture)
end
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 @@ -39,7 +39,7 @@ def image_search
end

def self.from_image(driver, image)
if image.name =~ /ubuntu/i
if /ubuntu/i.match?(image.name)
image.name =~ /\b(\d+(\.\d+)?)\b/i
new(driver, "ubuntu", (Regexp.last_match || [])[1], image.architecture)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/aws/standard_platform/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def sort_by_version(images)
end

def self.from_image(driver, image)
if image.name =~ /Windows/i
if /Windows/i.match?(image.name)
# 2008 R2 SP2
if image.name =~ /(\b\d+)\W*(r\d+)?/i
major, revision = (Regexp.last_match || [])[1], (Regexp.last_match || [])[2]
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def create(state)

info("EC2 instance <#{state[:server_id]}> ready (hostname: #{state[:hostname]}).")
instance.transport.connection(state).wait_until_ready
create_ec2_json(state) if instance.provisioner.name =~ /chef/i
create_ec2_json(state) if /chef/i.match?(instance.provisioner.name)
debug("ec2:create '#{state[:hostname]}'")
rescue Exception
# Clean up any auto-created security groups or keys on the way out.
Expand Down