Skip to content

Commit

Permalink
Source code changes and dependency updates for Ruby 3.1 and 3.2 support
Browse files Browse the repository at this point in the history
commit: 6c7988df7868ecfa183fe9778ef5ed5587210698
Author: Andres Jardon <[email protected]>
Date: 2023-03-20T20:06:16.000Z

Source code changes and dependency updates for Ruby 3.1 and 3.2 support

commit: 3aa58788849a414fb0ae6ddd94a96d8dbf696f92
Author: Andres Jardon <[email protected]>
Date: 2023-03-20T18:04:30.000Z

Source code changes and dependency updates for Ruby 3.1 and 3.2 support

commit: 77a4cc18f931284d4908a4f8bfa1854727e205ad
Author: Andres Jardon <[email protected]>
Date: 2023-03-17T19:53:35.000Z

Source code changes and dependency updates for Ruby 3.1 and 3.2 support
  • Loading branch information
aj-aws authored and Michael Choi committed Apr 3, 2023
1 parent 18347be commit 67a2faf
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 186 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source 'http://rubygems.org'
gemspec
gem "process_manager", "0.0.13", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/process_manager-0.0.13"
gem "codedeploy-commands", "1.0.0", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/codedeploy-commands-1.0.0"
gem "simple_pid", "0.2.1", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/simple_pid-0.2.1"

group :test do
gem 'test-unit'
Expand Down
1 change: 0 additions & 1 deletion codedeploy_agent.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
spec.add_dependency('logging', '~> 2.2')
spec.add_dependency('aws-sdk-core', '~> 3')
spec.add_dependency('aws-sdk-s3', '~> 1')
spec.add_dependency('simple_pid', '~> 0.2.1')
spec.add_dependency('docopt', '~> 0.5.0')
spec.add_dependency('concurrent-ruby', '~> 1.1.9')

Expand Down
6 changes: 3 additions & 3 deletions lib/aws/codedeploy/local/cli_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def validate(args)
raise ValidationError.new("location #{location} cannot be http, only encrypted (https) url endpoints supported")
end

if (uri.scheme != 'https' && uri.scheme != 's3' && !File.exists?(location))
if (uri.scheme != 'https' && uri.scheme != 's3' && !File.exist?(location))
raise ValidationError.new("location #{location} is specified as a file or directory which does not exist")
end

Expand All @@ -41,10 +41,10 @@ def validate(args)

if (type == 'directory' && (uri.scheme != 'https' && uri.scheme != 's3' && File.directory?(location)))
appspec_filename = args['--appspec-filename']
if !appspec_filename.nil? && !File.exists?("#{location}/#{appspec_filename}")
if !appspec_filename.nil? && !File.exist?("#{location}/#{appspec_filename}")
raise ValidationError.new("Expecting appspec file at location #{location}/#{appspec_filename} but it is not found there. Please either run the CLI from within a directory containing the #{appspec_filename} file or specify a bundle location containing an #{appspec_filename} file in its root directory")
end
if appspec_filename.nil? && !File.exists?("#{location}/appspec.yml") && !File.exists?("#{location}/appspec.yaml")
if appspec_filename.nil? && !File.exist?("#{location}/appspec.yml") && !File.exist?("#{location}/appspec.yaml")
raise ValidationError.new("Expecting appspec file at location #{location}/appspec.yml or #{location}/appspec.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml or appspec.yaml file or specify a bundle location containing an appspec.yml or appspec.yaml file in its root directory")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/instance_agent/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InstanceAgent::DeploymentLog

def initialize
deployment_logs_dir = File.join(InstanceAgent::Config.config[:root_dir], 'deployment-logs')
FileUtils.mkdir_p(deployment_logs_dir) unless File.exists? deployment_logs_dir
FileUtils.mkdir_p(deployment_logs_dir) unless File.exist? deployment_logs_dir
@deployment_log ||= Logger.new(File.join(deployment_logs_dir, "#{InstanceAgent::Config.config[:program_name]}-deployments.log"), 8, 64 * 1024 * 1024)
@deployment_log.formatter = proc do |severity, datetime, progname, msg|
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
Expand Down
6 changes: 3 additions & 3 deletions lib/instance_agent/plugins/codedeploy/hook_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def script_error_prefix(script_location, script_run_as_user)
private
def create_script_log_file_if_needed
script_log_file_location = File.join(@current_deployment_root_dir, ScriptLog::SCRIPT_LOG_FILE_RELATIVE_LOCATION)
if(!File.exists?(script_log_file_location))
if(!File.exist?(script_log_file_location))
unless File.directory?(File.dirname(script_log_file_location))
FileUtils.mkdir_p(File.dirname(script_log_file_location))
end
Expand All @@ -232,7 +232,7 @@ def script_absolute_path(script)
def parse_app_spec
app_spec_location = File.join(@deployment_archive_dir, @app_spec_path)
log(:debug, "Checking for app spec in #{app_spec_location}")
unless File.exists?(app_spec_location)
unless File.exist?(app_spec_location)
raise <<-MESSAGE.gsub(/^[\s\t]*/, '').gsub(/\s*\n/, ' ').strip
The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path "#{@app_spec_path}".
The revision was unpacked to directory "#{@deployment_archive_dir}", and the AppSpec file was expected but not found at path
Expand All @@ -249,7 +249,7 @@ def select_correct_deployment_root_dir(current_deployment_root_dir, last_success
hook_deployment_mapping = mapping_between_hooks_and_deployments
if(select_correct_mapping_for_hooks == LAST_SUCCESSFUL_DEPLOYMENT && !File.exist?(File.join(@deployment_root_dir, 'deployment-archive')))
@deployment_root_dir = last_successful_deployment_root_dir
elsif(select_correct_mapping_for_hooks == MOST_RECENT_DEPLOYMENT && !File.exists?(File.join(@deployment_root_dir, 'deployment-archive')))
elsif(select_correct_mapping_for_hooks == MOST_RECENT_DEPLOYMENT && !File.exist?(File.join(@deployment_root_dir, 'deployment-archive')))
@deployment_root_dir = most_recent_deployment_dir
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/instance_agent/plugins/codedeploy/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(opts = {})
def install(deployment_group_id, application_specification)
cleanup_file = File.join(deployment_instructions_dir, "#{deployment_group_id}-cleanup")

if File.exists?(cleanup_file)
if File.exist?(cleanup_file)
commands = InstanceAgent::Plugins::CodeDeployPlugin::InstallInstruction.parse_remove_commands(File.read(cleanup_file))
commands.each do |cmd|
cmd.execute
Expand Down Expand Up @@ -116,7 +116,7 @@ def generate_directory_copy(i, absolute_source_path, destination, file_exists_be

private
def generate_normal_copy(i, absolute_source_path, destination, file_exists_behavior)
if File.exists?(destination)
if File.exist?(destination)
case file_exists_behavior
when "DISALLOW"
raise "The deployment failed because a specified file already exists at this location: #{destination}"
Expand All @@ -136,7 +136,7 @@ def generate_normal_copy(i, absolute_source_path, destination, file_exists_behav
def fill_in_missing_ancestors(i, destination)
missing_ancestors = []
parent_dir = File.dirname(destination)
while !File.exists?(parent_dir) &&
while !File.exist?(parent_dir) &&
parent_dir != "." && parent_dir != "/"
missing_ancestors.unshift(parent_dir)
parent_dir = File.dirname(parent_dir)
Expand Down
2 changes: 1 addition & 1 deletion lib/instance_agent/plugins/codedeploy/onpremise_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class OnPremisesConfig
def self.configure
file_path = InstanceAgent::Config.config[:on_premises_config_file]
file_config = nil
if File.exists?(file_path) && File.readable?(file_path)
if File.readable?(file_path)
begin
file_config = YAML.load(File.read(file_path)).symbolize_keys
rescue
Expand Down
34 changes: 17 additions & 17 deletions spec/aws/codedeploy/local/cli_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

it 'returns the same arguments' do
allow(File).to receive(:exists?).with(VALID_FILE).and_return(true)
allow(File).to receive(:exist?).with(VALID_FILE).and_return(true)
expect(validator.validate(args)).to equal(args)
end
end
Expand Down Expand Up @@ -93,10 +93,10 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(false)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yaml").and_return(false)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(false)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yaml").and_return(false)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "Expecting appspec file at location #{FAKE_DIRECTORY}/appspec.yml or #{FAKE_DIRECTORY}/appspec.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec.yml or appspec.yaml file or specify a bundle location containing an appspec.yml or appspec.yaml file in its root directory")
end
end
Expand All @@ -109,9 +109,9 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec-override.yaml").and_return(false)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec-override.yaml").and_return(false)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "Expecting appspec file at location #{FAKE_DIRECTORY}/appspec-override.yaml but it is not found there. Please either run the CLI from within a directory containing the appspec-override.yaml file or specify a bundle location containing an appspec-override.yaml file in its root directory")
end
end
Expand All @@ -129,7 +129,7 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_FILE_WHICH_DOES_NOT_EXIST).and_return(false)
allow(File).to receive(:exist?).with(FAKE_FILE_WHICH_DOES_NOT_EXIST).and_return(false)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "location #{FAKE_FILE_WHICH_DOES_NOT_EXIST} is specified as a file or directory which does not exist")
end
end
Expand All @@ -147,7 +147,7 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_FILE).and_return(true)
allow(File).to receive(:exist?).with(FAKE_FILE).and_return(true)
allow(File).to receive(:file?).with(FAKE_FILE).and_return(true)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "location #{FAKE_FILE} is specified with type directory but it is a file")
end
Expand All @@ -173,7 +173,7 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect{validator.validate(argszip)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "location #{FAKE_DIRECTORY} is specified as a compressed local file but it is a directory")
expect{validator.validate(argstgz)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "location #{FAKE_DIRECTORY} is specified as a compressed local file but it is a directory")
Expand All @@ -189,9 +189,9 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "The only events that can be specified before DownloadBundle are BeforeBlockTraffic,AfterBlockTraffic,ApplicationStop. Please fix the order of your specified events: #{args['--events']}")
end
end
Expand All @@ -205,9 +205,9 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "The only events that can be specified before DownloadBundle are BeforeBlockTraffic,AfterBlockTraffic,ApplicationStop. Please fix the order of your specified events: #{args['--events']}")
end
end
Expand All @@ -221,9 +221,9 @@
end

it 'throws a ValidationError' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect{validator.validate(args)}.to raise_error(AWS::CodeDeploy::Local::CLIValidator::ValidationError, "The only events that can be specified before Install are BeforeBlockTraffic,AfterBlockTraffic,ApplicationStop,DownloadBundle,BeforeInstall. Please fix the order of your specified events: #{args['--events']}")
end
end
Expand All @@ -237,9 +237,9 @@
end

it 'returns the same arguments' do
allow(File).to receive(:exists?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:exist?).with(FAKE_DIRECTORY).and_return(true)
allow(File).to receive(:directory?).with(FAKE_DIRECTORY).and_return(true)
expect(File).to receive(:exists?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect(File).to receive(:exist?).with("#{FAKE_DIRECTORY}/appspec.yml").and_return(true)
expect(validator.validate(args)).to equal(args)
end
end
Expand Down
Loading

0 comments on commit 67a2faf

Please sign in to comment.