Skip to content

Commit

Permalink
fix rubocop issues in production code
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Oct 4, 2024
1 parent 85baaf2 commit 21bab9d
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 46 deletions.
2 changes: 0 additions & 2 deletions src/bosh_aws_cpi/lib/cloud/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module AwsCloud; end
require 'aws-sdk-elasticloadbalancingv2'

require 'httpclient'
require 'pp'
require 'set'
require 'tmpdir'
require 'securerandom'
require 'json'
Expand Down
10 changes: 5 additions & 5 deletions src/bosh_aws_cpi/lib/cloud/aws/cloud_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class CloudCore
# Initialize BOSH AWS CPI. The contents of sub-hashes are defined in the {file:README.md}
# @param [Bosh::AwsCloud::Config] config CPI Config options
# @param [Bosh::Cpi::Logger] logger AWS specific options
# @param [Bosh::AwsCloud::VolumeManager] volume manager
# @param [Bosh::AwsCloud::AvailabilityZoneSelector] az selector
# @param [Integer] Stemcell api version
# @param [Bosh::AwsCloud::VolumeManager] volume_manager
# @param [Bosh::AwsCloud::AvailabilityZoneSelector] az_selector
# @param [Integer] stemcell_api_version
def initialize(config, logger, volume_manager, az_selector, stemcell_api_version)
@config = config
@supported_api_version = @config.supported_api_version
Expand Down Expand Up @@ -48,7 +48,7 @@ def info

##
# Create an EC2 instance and wait until it's in running state
# @param [String] agent_id agent id associated with new VM
# @param [String] _agent_id agent id associated with new VM
# @param [String] stemcell_id AMI id of the stemcell used to
# create the new instance
# @param [Hash] vm_type resource pool specification
Expand All @@ -62,7 +62,7 @@ def info
# @param [optional, Hash] environment data to be merged into
# agent settings
# @return String, Hash - EC2 instance id of the new virtual machine, Network info
def create_vm(agent_id, stemcell_id, vm_type, network_props, settings, disk_locality = [], environment = nil)
def create_vm(_agent_id, stemcell_id, vm_type, network_props, settings, disk_locality = [], environment = nil)
vm_props = @props_factory.vm_props(vm_type)

target_groups = vm_props.lb_target_groups
Expand Down
6 changes: 1 addition & 5 deletions src/bosh_aws_cpi/lib/cloud/aws/cloud_props.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def region_ami
ami[@global_config.aws.region]
end

private

DEFAULT_DISK_SIZE = 2048
PARAVIRTUAL = 'paravirtual'.freeze
Expand Down Expand Up @@ -212,7 +211,7 @@ class NetworkCloudProps

# @param [Hash] network_spec
# @param [Bosh::AwsCloud::Config] global_config
def initialize(network_spec, global_config)
def initialize(network_spec, _global_config)
@network_spec = (network_spec || {}).dup

@networks = []
Expand Down Expand Up @@ -310,9 +309,6 @@ def initialize(name, settings)
end

class DynamicNetwork < Network
def initialize(name, settings)
super(name, settings)
end
end

class PublicNetwork < Network
Expand Down
12 changes: 6 additions & 6 deletions src/bosh_aws_cpi/lib/cloud/aws/cloud_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def delete_vm(instance_id)
with_thread_name("delete_vm(#{instance_id})") do
logger.info("Deleting instance '#{instance_id}'")

@cloud_core.delete_vm(instance_id) do |instance_id|
@registry.delete_settings(instance_id)
@cloud_core.delete_vm(instance_id) do |delete_vm_instance_id|
@registry.delete_settings(delete_vm_instance_id)
end
end
end
Expand Down Expand Up @@ -265,11 +265,11 @@ def attach_disk(instance_id, disk_id)
# @param [String] disk_id EBS volume id of the disk to detach
def detach_disk(instance_id, disk_id)
with_thread_name("detach_disk(#{instance_id}, #{disk_id})") do
@cloud_core.detach_disk(instance_id, disk_id) do |disk_id|
@cloud_core.detach_disk(instance_id, disk_id) do |detach_disk_disk_id|
update_agent_settings(instance_id) do |settings|
settings['disks'] ||= {}
settings['disks']['persistent'] ||= {}
settings['disks']['persistent'].delete(disk_id)
settings['disks']['persistent'].delete(detach_disk_disk_id)
end
end
end
Expand Down Expand Up @@ -335,7 +335,7 @@ def delete_snapshot(snapshot_id)
snapshot = @ec2_resource.snapshot(snapshot_id)
begin
snapshot.delete
rescue Aws::EC2::Errors::InvalidSnapshotNotFound => e
rescue Aws::EC2::Errors::InvalidSnapshotNotFound
logger.info("snapshot '#{snapshot_id}' not found")
end
logger.info("snapshot '#{snapshot_id}' deleted")
Expand All @@ -346,7 +346,7 @@ def delete_snapshot(snapshot_id)
# @param [String] instance_id EC2 instance id
# @param [Hash] network_spec network properties
# @raise [Bosh::Clouds:NotSupported] configure_networks is no longer supported
def configure_networks(instance_id, network_spec)
def configure_networks(_instance_id, _network_spec)
raise Bosh::Clouds::NotSupported, 'configure_networks is no longer supported'
end

Expand Down
10 changes: 5 additions & 5 deletions src/bosh_aws_cpi/lib/cloud/aws/cloud_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_vm(agent_id, stemcell_id, vm_type, network_spec, disk_locality = [],
agent_settings.agent_id = agent_id

#TODO : should use networks from core create_vm in future
instance_id, networks = @cloud_core.create_vm(agent_id, stemcell_id, vm_type, network_props, agent_settings, disk_locality, environment) do
instance_id, _ = @cloud_core.create_vm(agent_id, stemcell_id, vm_type, network_props, agent_settings, disk_locality, environment) do
|instance_id, settings|
@registry.update_settings(instance_id, settings.agent_settings) if @stemcell_api_version < 2
end
Expand Down Expand Up @@ -96,12 +96,12 @@ def attach_disk(vm_id, disk_id)
# @param [String] disk_id EBS volume id of the disk to detach
def detach_disk(instance_id, disk_id)
with_thread_name("detach_disk(#{instance_id}, #{disk_id}):v2") do
@cloud_core.detach_disk(instance_id, disk_id) do |disk_id|
@cloud_core.detach_disk(instance_id, disk_id) do |detach_disk_disk_id|
if @stemcell_api_version < 2
update_agent_settings(instance_id) do |settings|
settings['disks'] ||= {}
settings['disks']['persistent'] ||= {}
settings['disks']['persistent'].delete(disk_id)
settings['disks']['persistent'].delete(detach_disk_disk_id)
end
end
end
Expand All @@ -115,8 +115,8 @@ def detach_disk(instance_id, disk_id)
def delete_vm(instance_id)
with_thread_name("delete_vm(#{instance_id}):v2") do
logger.info("Deleting instance '#{instance_id}'")
@cloud_core.delete_vm(instance_id) do |instance_id|
@registry.delete_settings(instance_id) if @stemcell_api_version < 2
@cloud_core.delete_vm(instance_id) do |delete_vm_instance_id|
@registry.delete_settings(delete_vm_instance_id) if @stemcell_api_version < 2
end
end
end
Expand Down
31 changes: 16 additions & 15 deletions src/bosh_aws_cpi/lib/cloud/aws/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,6 @@ def registry_configured?
!registry.endpoint.nil?
end

private

def initialize(config_hash)
@config = config_hash
@aws = AwsConfig.new(config_hash['aws'] || {})
@registry = RegistryConfig.new(config_hash['registry'] || {})
@agent = AgentConfig.new(config_hash['agent'] || {})
@debug_api_version = config_hash.fetch('debug',{}).fetch('cpi', {}).fetch('api_version', MAX_SUPPORTED_API_VERSION)
@stemcell_api_version = parse_stemcell_api_version(config_hash['aws'])
end

def parse_stemcell_api_version(aws_config_hash)
aws_config_hash.fetch('vm', {}).fetch('stemcell', {}).fetch('api_version', 1)
end

##
# Checks if options passed to CPI are valid and can actually
# be used to create all required data structures etc.
Expand Down Expand Up @@ -188,5 +173,21 @@ def self.required_keys
required_keys = {'aws' => ['max_retries']}
required_keys
end
private_class_method :required_keys

private

def initialize(config_hash)
@config = config_hash
@aws = AwsConfig.new(config_hash['aws'] || {})
@registry = RegistryConfig.new(config_hash['registry'] || {})
@agent = AgentConfig.new(config_hash['agent'] || {})
@debug_api_version = config_hash.fetch('debug',{}).fetch('cpi', {}).fetch('api_version', MAX_SUPPORTED_API_VERSION)
@stemcell_api_version = parse_stemcell_api_version(config_hash['aws'])
end

def parse_stemcell_api_version(aws_config_hash)
aws_config_hash.fetch('vm', {}).fetch('stemcell', {}).fetch('api_version', 1)
end
end
end
2 changes: 1 addition & 1 deletion src/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def create_aws_instance(instance_params, vm_cloud_props)
# is too slow to update its state when we have released the IP address and want to
# reallocate it again.
errors = [Aws::EC2::Errors::InvalidIPAddressInUse]
Bosh::Common.retryable(sleep: instance_create_wait_time, tries: 20, on: errors) do |tries, error|
Bosh::Common.retryable(sleep: instance_create_wait_time, tries: 20, on: errors) do |_tries, error|
@logger.info('Launching on demand instance...')
if error.class == Aws::EC2::Errors::InvalidIPAddressInUse
@logger.warn("IP address was in use: #{error}")
Expand Down
2 changes: 1 addition & 1 deletion src/bosh_aws_cpi/lib/cloud/aws/instance_param_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def instance_params
nic[:device_index] = 0 unless nic.empty?
params[:network_interfaces] = [nic] unless nic.empty?

params.delete_if { |k, v| v.nil? }
params.delete_if { |_k, v| v.nil? }
end

private
Expand Down
2 changes: 1 addition & 1 deletion src/bosh_aws_cpi/lib/cloud/aws/resource_wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.sleep_callback(description, options)
if options[:exponential]
time = [options[:interval] ** num_tries, max_sleep_time].min
else
time = [1 + options[:interval] * num_tries, max_sleep_time].min
time = [1 + (options[:interval] * num_tries), max_sleep_time].min
end
end
Bosh::AwsCloud::ResourceWait.logger.debug("#{error.class}: `#{error.message}'") if error
Expand Down
1 change: 0 additions & 1 deletion src/bosh_aws_cpi/lib/cloud/aws/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def self.logger
Bosh::Clouds::Config.logger
end

private

def self.format_tags(tags)
formatted_tags = tags.map do |k, v|
Expand Down
4 changes: 2 additions & 2 deletions src/bosh_aws_cpi/spec/unit/create_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
let(:volume_resp) { instance_double(Aws::EC2::Types::Volume, volume_id: 'v-foobar') }

before do
@cloud = mock_cloud do |_ec2|
@ec2 = _ec2
@cloud = mock_cloud do |mock_ec2|
@ec2 = mock_ec2
allow(@ec2).to receive(:instance).with('i-test').and_return(instance)
allow(@ec2).to receive(:config).and_return('fake-config')
end
Expand Down
4 changes: 2 additions & 2 deletions src/bosh_aws_cpi/spec/unit/resize_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
let(:volume_resp) { instance_double(Aws::EC2::Types::ModifyVolumeResult, :volume_modification => {modification_state: 'completed'}) }

before do
@cloud = mock_cloud do |_ec2|
@ec2 = _ec2
@cloud = mock_cloud do |mock_ec2|
@ec2 = mock_ec2
allow(@ec2).to receive(:config).and_return('fake-config')
allow(@ec2).to receive(:volume).with("disk-id").and_return(volume)
end
Expand Down

0 comments on commit 21bab9d

Please sign in to comment.