diff --git a/.gitignore b/.gitignore index b9420be9a41..64cc161fdf9 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,6 @@ pkg/ .dev_builds .final_builds/jobs/**/*.tgz .final_builds/packages/**/*.tgz -.idea .vscode blobs config/dev.yml diff --git a/ci/dockerfiles/warden-cpi/warden-cloud-config.yml b/ci/dockerfiles/warden-cpi/warden-cloud-config.yml index 1b9512058b4..f23c9e4dc7f 100644 --- a/ci/dockerfiles/warden-cpi/warden-cloud-config.yml +++ b/ci/dockerfiles/warden-cpi/warden-cloud-config.yml @@ -17,7 +17,6 @@ networks: - azs: [z1, z2, z3] dns: [8.8.8.8] range: 10.245.0.0/24 - dns: [8.8.8.8] # IPs that will not be used for anything reserved: [10.245.0.2-10.245.0.10] gateway: 10.245.0.1 diff --git a/spec/director.yml.erb_spec.rb b/spec/director.yml.erb_spec.rb index 700e442b30c..307a980e254 100644 --- a/spec/director.yml.erb_spec.rb +++ b/spec/director.yml.erb_spec.rb @@ -293,7 +293,7 @@ 'enabled' => true, 'url' => 'https://config-server-host', 'uaa' => { - 'url' => 'http://something.com', + 'url' => 'https://something.com', 'client_secret' => 'secret', 'ca_cert_path' => '/var/vcap/blah/to/go' } diff --git a/spec/director_templates_spec.rb b/spec/director_templates_spec.rb index b7396d606f4..8fa69dbfffb 100644 --- a/spec/director_templates_spec.rb +++ b/spec/director_templates_spec.rb @@ -329,7 +329,7 @@ ) end - it 'converts the adapter to `mysqql`' do + it 'converts the adapter to `mysql`' do bbr_config = JSON.parse(template.render(properties)) expect(bbr_config['adapter']).to eq('mysql') end @@ -375,16 +375,13 @@ end end - # rubocop:disable Metrics/MethodLength describe 'certificate expiry template' do before do @key, @cert, @expiry = create_key_and_csr_cert end - # rubocop:disable Metrics/BlockLength it_should_behave_like 'a rendered file' do let(:file_name) { '../jobs/director/templates/certificate_expiry.json.erb' } - # rubocop:disable Metrics/BlockLength let(:properties) do { 'properties' => { @@ -445,8 +442,6 @@ JSON end end - # rubocop:enable Metrics/BlockLength - # rubocop:enable Metrics/MethodLength end end end @@ -465,7 +460,7 @@ def new_csr(key, subject) csr.version = 0 csr.subject = subject csr.public_key = key.public_key - csr.sign key, OpenSSL::Digest::SHA1.new + csr.sign key, OpenSSL::Digest.new('SHA1') csr end @@ -475,13 +470,13 @@ def new_csr_certificate(key, csr) csr_cert.serial = 0 csr_cert.version = 2 csr_cert.not_before = Time.now - 60 * 60 * 24 - csr_cert.not_after = Time.now + 94608000 + csr_cert.not_after = Time.now + 94_608_000 csr_cert.subject = csr.subject csr_cert.public_key = csr.public_key csr_cert.issuer = csr.subject - csr_cert.sign key, OpenSSL::Digest::SHA1.new + csr_cert.sign key, OpenSSL::Digest.new('SHA1') csr_cert end diff --git a/src/bosh-dev/lib/bosh/dev/sandbox/mysql.rb b/src/bosh-dev/lib/bosh/dev/sandbox/mysql.rb index f5760b84350..9ca1483b6ed 100644 --- a/src/bosh-dev/lib/bosh/dev/sandbox/mysql.rb +++ b/src/bosh-dev/lib/bosh/dev/sandbox/mysql.rb @@ -58,9 +58,7 @@ def current_tasks def current_locked_jobs jobs_cmd = %Q{mysql -h #{@host} -P #{@port} --user=#{@username} --password=#{@password} -e "select * from delayed_jobs where locked_by is not null;" #{db_name} 2> /dev/null} - job_lines = `#{jobs_cmd}`.lines.to_a[1..-1] || [] - - job_lines + `#{jobs_cmd}`.lines.to_a[1..-1] || [] end def truncate_db diff --git a/src/bosh-dev/lib/bosh/dev/sandbox/services/director_service.rb b/src/bosh-dev/lib/bosh/dev/sandbox/services/director_service.rb index fb1964fafb9..0ff8bf7118f 100644 --- a/src/bosh-dev/lib/bosh/dev/sandbox/services/director_service.rb +++ b/src/bosh-dev/lib/bosh/dev/sandbox/services/director_service.rb @@ -141,8 +141,7 @@ def db_config end connection_config.delete_if { |_, v| v.to_s.empty? } - connection_config = connection_config.merge(custom_connection_options) - connection_config + connection_config.merge(custom_connection_options) end def read_log diff --git a/src/bosh-dev/lib/bosh/dev/tasks/migrations.rake b/src/bosh-dev/lib/bosh/dev/tasks/migrations.rake index 8fdfd44fea7..5be378f97dc 100644 --- a/src/bosh-dev/lib/bosh/dev/tasks/migrations.rake +++ b/src/bosh-dev/lib/bosh/dev/tasks/migrations.rake @@ -56,7 +56,7 @@ EOF migration_digest = Digest::SHA1.hexdigest(File.read(new_migration_path)) digest_migration_json = JSON.parse(File.read(migration_digests)) - if digest_migration_json[name] != nil then + if digest_migration_json[name] != nil puts ' YOU ARE MODIFIFYING A DB MIGRATION DIGEST. IF THIS MIGRATION HAS ALREADY BEEN RELEASED, IT MIGHT RESULT IN UNDESIRABLE BEHAVIOR. diff --git a/src/bosh-dev/lib/bosh/dev/test_runner.rb b/src/bosh-dev/lib/bosh/dev/test_runner.rb index 999090bcb2b..4d862f4f55c 100644 --- a/src/bosh-dev/lib/bosh/dev/test_runner.rb +++ b/src/bosh-dev/lib/bosh/dev/test_runner.rb @@ -41,7 +41,8 @@ def unit_exec(build, log_file: nil, parallel: false) lines.append " #{command}" lines.append(File.read(log_file)) if log_file && File.exist?(log_file) lines.append "----- END #{build}\n\n" - return {:lines => lines, :error => false} + + {:lines => lines, :error => false} else lines.append "----- BEGIN #{build}" lines.append " #{command}" @@ -49,7 +50,8 @@ def unit_exec(build, log_file: nil, parallel: false) error_message += ": #{File.read(log_file)}" if log_file && File.exist?(log_file) lines.append " #{error_message}\n" lines.append "----- END #{build}\n\n" - return {:lines => lines, :error => true} + + {:lines => lines, :error => true} end end diff --git a/src/bosh-director-core/lib/bosh/director/core/templates/template_blob_cache.rb b/src/bosh-director-core/lib/bosh/director/core/templates/template_blob_cache.rb index daf7b3eed76..aac19b66df3 100644 --- a/src/bosh-director-core/lib/bosh/director/core/templates/template_blob_cache.rb +++ b/src/bosh-director-core/lib/bosh/director/core/templates/template_blob_cache.rb @@ -1,7 +1,7 @@ module Bosh::Director::Core::Templates class TemplateBlobCache def self.with_fresh_cache - cache = new() + cache = new yield cache ensure cache.clean_cache! diff --git a/src/bosh-director/lib/bosh/director.rb b/src/bosh-director/lib/bosh/director.rb index 29f6e8068a8..80d172f27b7 100644 --- a/src/bosh-director/lib/bosh/director.rb +++ b/src/bosh-director/lib/bosh/director.rb @@ -13,7 +13,6 @@ module Director require 'optparse' require 'ostruct' require 'pathname' -require 'pp' require 'tmpdir' require 'yaml' require 'time' @@ -27,14 +26,11 @@ module Director require 'bcrypt' require 'netaddr' require 'delayed_job' -#TODO: remove when https://github.com/collectiveidea/delayed_job/pull/1185 is merged -require "active_support/core_ext/array/extract_options" require 'sequel' require 'sinatra/base' require 'securerandom' require 'nats/io/client' require 'openssl' -require 'securerandom' require 'delayed_job_sequel' require 'common/thread_formatter' diff --git a/src/bosh-director/lib/bosh/director/agent_client.rb b/src/bosh-director/lib/bosh/director/agent_client.rb index 8b5cc9303db..c71d1fa72d6 100644 --- a/src/bosh-director/lib/bosh/director/agent_client.rb +++ b/src/bosh-director/lib/bosh/director/agent_client.rb @@ -205,7 +205,7 @@ def wait_for_task(agent_task_id, timeout = nil, &blk) task = get_task_status(agent_task_id) timed_out = false - until task['state'] != 'running' || (timeout && timed_out = timeout.timed_out?) + until task['state'] != 'running' || (timeout && (timed_out = timeout.timed_out?)) blk.call if block_given? sleep(DEFAULT_POLL_INTERVAL) task = get_task_status(agent_task_id) @@ -324,7 +324,7 @@ def format_exception(exception) def inject_compile_log(response) if response['value'] && response['value'].is_a?(Hash) && response['value']['result'].is_a?(Hash) && - blob_id = response['value']['result']['compile_log_id'] + (blob_id = response['value']['result']['compile_log_id']) compile_log = download_and_delete_blob(blob_id) response['value']['result']['compile_log'] = compile_log end diff --git a/src/bosh-director/lib/bosh/director/api/config_manager.rb b/src/bosh-director/lib/bosh/director/api/config_manager.rb index 521e31d1cdd..0ba524ed88a 100644 --- a/src/bosh-director/lib/bosh/director/api/config_manager.rb +++ b/src/bosh-director/lib/bosh/director/api/config_manager.rb @@ -16,7 +16,7 @@ def create(type, name, config_yaml, team_id = nil) def deploy_config_enabled? deploy_config = find(type: 'deploy') - return !deploy_config.empty? + !deploy_config.empty? end def find(type: nil, name: nil, limit: 1) diff --git a/src/bosh-director/lib/bosh/director/api/controllers/tasks_controller.rb b/src/bosh-director/lib/bosh/director/api/controllers/tasks_controller.rb index e290907ba8c..bf7e4aa3b7f 100644 --- a/src/bosh-director/lib/bosh/director/api/controllers/tasks_controller.rb +++ b/src/bosh-director/lib/bosh/director/api/controllers/tasks_controller.rb @@ -52,11 +52,11 @@ def self.authorization(perm) ]) end - if context_id = params['context_id'] + if (context_id = params['context_id']) dataset = dataset.filter(:context_id => context_id) end - if limit = params['limit'] + if (limit = params['limit']) limit = limit.to_i limit = 1 if limit < 1 end diff --git a/src/bosh-director/lib/bosh/director/api/release_manager.rb b/src/bosh-director/lib/bosh/director/api/release_manager.rb index dcd1df60f5c..97565a2227d 100644 --- a/src/bosh-director/lib/bosh/director/api/release_manager.rb +++ b/src/bosh-director/lib/bosh/director/api/release_manager.rb @@ -4,15 +4,13 @@ class ReleaseManager include ApiHelper def get_all_releases - releases = Models::Release.order_by(Sequel.asc(:name)).map do |release| + Models::Release.order_by(Sequel.asc(:name)).map do |release| release_versions = sorted_release_versions(release) { 'name' => release.name, 'release_versions' => release_versions } end - - releases end def sorted_release_versions(release, prefix = nil) diff --git a/src/bosh-director/lib/bosh/director/api/stemcell_manager.rb b/src/bosh-director/lib/bosh/director/api/stemcell_manager.rb index 5a266fa59fc..d8089bf40b8 100644 --- a/src/bosh-director/lib/bosh/director/api/stemcell_manager.rb +++ b/src/bosh-director/lib/bosh/director/api/stemcell_manager.rb @@ -19,7 +19,7 @@ def find_by_name_and_version_and_cpi(name, version, cpi) matched_cpis = found_cpis & cpi_aliases raise StemcellNotFound, "Stemcell '#{name}/#{version}' and cpi #{cpi} doesn't exist" if matched_cpis.empty? - return Models::Stemcell[:name => name, :version => version, :cpi => matched_cpis[0]] + Models::Stemcell[:name => name, :version => version, :cpi => matched_cpis[0]] end def find_all_stemcells @@ -112,12 +112,10 @@ def find_latest(stemcells, prefix = nil) latest_version = Bosh::Common::Version::StemcellVersionList.parse(versions).latest.to_s - latest_stemcell = stemcells.find do |stemcell| + stemcells.find do |stemcell| parsed_version = Bosh::Common::Version::StemcellVersion.parse(stemcell.version).to_s parsed_version == latest_version end - - latest_stemcell end end end diff --git a/src/bosh-director/lib/bosh/director/api/user/config_user_manager.rb b/src/bosh-director/lib/bosh/director/api/user/config_user_manager.rb index fa35508d776..ec84fe0472f 100644 --- a/src/bosh-director/lib/bosh/director/api/user/config_user_manager.rb +++ b/src/bosh-director/lib/bosh/director/api/user/config_user_manager.rb @@ -21,7 +21,8 @@ def authenticate(username, password) def user_scopes(username) user = @users.find { |u| u['name'] == username } raise "User #{username} not found in ConfigUserManager" if user.nil? - return user.fetch('scopes', ['bosh.admin']) + + user.fetch('scopes', ['bosh.admin']) end def delete_user(_) diff --git a/src/bosh-director/lib/bosh/director/cidr_range_combiner.rb b/src/bosh-director/lib/bosh/director/cidr_range_combiner.rb index 34e9e15abe9..2f041ece9ab 100644 --- a/src/bosh-director/lib/bosh/director/cidr_range_combiner.rb +++ b/src/bosh-director/lib/bosh/director/cidr_range_combiner.rb @@ -40,11 +40,11 @@ def combine_adjacent_ranges(range_tuples) can_combine = false break end - if (range_tuple[1].succ == next_range_tuple[0]) + if range_tuple[1].succ == next_range_tuple[0] range_tuple[1] = next_range_tuple[1] i += 1 # does not cover all cases: 10/32, 10/8 - elsif ((range_tuple[0] < next_range_tuple[0]) && (range_tuple[1] > next_range_tuple[1])) + elsif (range_tuple[0] < next_range_tuple[0]) && (range_tuple[1] > next_range_tuple[1]) i += 1 else can_combine = false diff --git a/src/bosh-director/lib/bosh/director/config_server/client.rb b/src/bosh-director/lib/bosh/director/config_server/client.rb index e02988c5b73..1e261215f91 100644 --- a/src/bosh-director/lib/bosh/director/config_server/client.rb +++ b/src/bosh-director/lib/bosh/director/config_server/client.rb @@ -403,7 +403,7 @@ def get_variable_id_and_value_by_name(name) raise Bosh::Director::ConfigServerFetchError, "Failed to fetch variable '#{name_root}' from config server: Expected data[0] to have key 'id'" unless fetched_variable.key?('id') raise Bosh::Director::ConfigServerFetchError, "Failed to fetch variable '#{name_root}' from config server: Expected data[0] to have key 'value'" unless fetched_variable.key?('value') - return fetched_variable['id'], extract_variable_value(name, fetched_variable['value']) + [fetched_variable['id'], extract_variable_value(name, fetched_variable['value'])] elsif response.is_a? Net::HTTPNotFound raise Bosh::Director::ConfigServerMissingName, "Failed to find variable '#{name_root}' from config server: HTTP Code '404', Error: '#{response_body['error']}'" else diff --git a/src/bosh-director/lib/bosh/director/config_server/deep_hash_replacement.rb b/src/bosh-director/lib/bosh/director/config_server/deep_hash_replacement.rb index 6c7a79490c1..68ec1dfd22d 100644 --- a/src/bosh-director/lib/bosh/director/config_server/deep_hash_replacement.rb +++ b/src/bosh-director/lib/bosh/director/config_server/deep_hash_replacement.rb @@ -7,11 +7,9 @@ def variables_path(obj, subtrees_to_ignore = []) map = [] construct_variables_paths(map, obj) - result = map.select do |elem| + map.select do |elem| !path_matches_subtrees_to_ignore?(subtrees_to_ignore, elem['path']) end - - result end def replace_variables(obj_to_be_resolved, variables_paths, variable_values) diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/agent_state_migrator.rb b/src/bosh-director/lib/bosh/director/deployment_plan/agent_state_migrator.rb index 26481db1482..0a1e304037b 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/agent_state_migrator.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/agent_state_migrator.rb @@ -1,3 +1,5 @@ +require 'pp' # for #pretty_inspect + module Bosh::Director module DeploymentPlan class AgentStateMigrator diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/compiled_package_finder.rb b/src/bosh-director/lib/bosh/director/deployment_plan/compiled_package_finder.rb index b12a0ad4da2..c15b135b084 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/compiled_package_finder.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/compiled_package_finder.rb @@ -12,8 +12,8 @@ def find_compiled_package(package:, stemcell:, exported_from: [], dependency_key return compiled_package if compiled_package compiled_package = find_newest_match(package, stemcell, dependency_key) unless package.source? - return compiled_package if compiled_package + compiled_package if compiled_package end private diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb b/src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb index 6d4a705942a..f4a50b87631 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/ip_provider/ip_repo.rb @@ -146,7 +146,7 @@ def validate_instance_and_update_reservation_type(instance_model, ip, ip_address ip_address.update(static: is_static, network_name: network_name) end - return ip_address + ip_address elsif reserved_instance.nil? raise Bosh::Director::NetworkReservationAlreadyInUse, "Failed to reserve IP '#{ip}' for instance '#{instance_model}': " \ diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/job.rb b/src/bosh-director/lib/bosh/director/deployment_plan/job.rb index 5a56330c693..28a2865fc22 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/job.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/job.rb @@ -140,7 +140,8 @@ def links_of_kind_for_instance_group_name(instance_group_name, kind) if link_infos.has_key?(instance_group_name) && link_infos[instance_group_name].has_key?(kind) return link_infos[instance_group_name][kind] end - return [] + + [] end end end diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb b/src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb index 8eee955925f..73439aa490d 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/manual_network.rb @@ -76,7 +76,7 @@ def ip_type(cidr_ip) def find_az_names_for_ip(ip) subnet = find_subnet_containing(ip) if subnet - return subnet.availability_zone_names + subnet.availability_zone_names end end diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/network_parser/name_servers_parser.rb b/src/bosh-director/lib/bosh/director/deployment_plan/network_parser/name_servers_parser.rb index e0658404b72..0949f0f8e43 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/network_parser/name_servers_parser.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/network_parser/name_servers_parser.rb @@ -5,7 +5,7 @@ class NameServersParser include ValidationHelper - def initialize() + def initialize dns_config = Config.dns || {} @include_power_dns_server_addr = !!Config.dns_db @default_server = dns_config['server'] diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/network_settings.rb b/src/bosh-director/lib/bosh/director/deployment_plan/network_settings.rb index 5f2c1cfe152..632c4628782 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/network_settings.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/network_settings.rb @@ -86,7 +86,7 @@ def link_network_addresses(link_def, prefer_dns_entry) def get_address(network_name, network, prefer_dns_entry = true) if should_use_dns?(network, prefer_dns_entry) - return @dns_encoder.encode_query({ + @dns_encoder.encode_query({ group_type: Models::LocalDnsEncodedGroup::Types::INSTANCE_GROUP, group_name: @instance_group_name, root_domain: @root_domain, @@ -95,13 +95,13 @@ def get_address(network_name, network, prefer_dns_entry = true) uuid: @instance_id, }) else - return network['ip'] + network['ip'] end end def get_link_address(link_def, network_name, network, prefer_dns_entry = true) if should_use_dns?(network, prefer_dns_entry) - return @dns_encoder.encode_link( + @dns_encoder.encode_link( link_def, { root_domain: @root_domain, @@ -110,7 +110,7 @@ def get_link_address(link_def, network_name, network, prefer_dns_entry = true) } ) else - return network['ip'] + network['ip'] end end diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/persistent_disk_collection.rb b/src/bosh-director/lib/bosh/director/deployment_plan/persistent_disk_collection.rb index 98d6b75ffa4..9be70f72075 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/persistent_disk_collection.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/persistent_disk_collection.rb @@ -123,7 +123,7 @@ def to_s { name: name, size: size, cloud_properties: cloud_properties }.inspect end - def to_json + def to_json(*_args) { name: name, size: size, cloud_properties: cloud_properties }.to_json end diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/balancer.rb b/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/balancer.rb index d18be158433..eeeacf54feb 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/balancer.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/balancer.rb @@ -12,10 +12,12 @@ def initialize(initial_weight: {}, tie_strategy:, preferred:) def pop return nil if @weight.size == 0 peek_value = peek + if peek_value.length != 1 - return choose(peek_value.find {|k| @preferred.include?(k.name) } || @tie_strategy.call(peek_value)) + choose(peek_value.find {|k| @preferred.include?(k.name) } || @tie_strategy.call(peek_value)) + else + choose(peek_value.first) end - return choose(peek_value.first) end private @@ -27,7 +29,7 @@ def peek def choose(chosen_value) @weight[chosen_value]+=1 - if preferred_chosen_index = @preferred.find_index {|v| v == chosen_value.name} + if (preferred_chosen_index = @preferred.find_index { |v| v == chosen_value.name }) @preferred.delete_at(preferred_chosen_index) end chosen_value diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/bruteforce_ip_allocation.rb b/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/bruteforce_ip_allocation.rb index 146f4a23add..46a51f0dd8f 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/bruteforce_ip_allocation.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/placement_planner/bruteforce_ip_allocation.rb @@ -54,7 +54,7 @@ def try_combination(networks_to_static_ips, allocated_ips) end end - return nil + nil end def even_distribution_of_ips?(networks_to_static_ips) @@ -113,7 +113,7 @@ def has_same_distribution?(static_ips_to_azs) end end - return true + true end end end diff --git a/src/bosh-director/lib/bosh/director/deployment_plan/vip_network.rb b/src/bosh-director/lib/bosh/director/deployment_plan/vip_network.rb index 646c9c5e7a1..1f0b761a4b9 100644 --- a/src/bosh-director/lib/bosh/director/deployment_plan/vip_network.rb +++ b/src/bosh-director/lib/bosh/director/deployment_plan/vip_network.rb @@ -71,7 +71,8 @@ def has_azs?(*) def find_az_names_for_ip(ip) subnet = @subnets.find { |sn| sn.static_ips.include?(ip) } - return subnet.availability_zone_names if subnet + + subnet.availability_zone_names if subnet end end end diff --git a/src/bosh-director/lib/bosh/director/dns/blobstore_dns_publisher.rb b/src/bosh-director/lib/bosh/director/dns/blobstore_dns_publisher.rb index 4e4b3b055b9..d701b994d9d 100644 --- a/src/bosh-director/lib/bosh/director/dns/blobstore_dns_publisher.rb +++ b/src/bosh-director/lib/bosh/director/dns/blobstore_dns_publisher.rb @@ -132,7 +132,7 @@ def export_dns_records add_aliases(aliases, dns_records) - local_dns_records.each do |dns_record| + local_dns_records&.each do |dns_record| dns_records.add_record( instance_id: dns_record.instance.uuid, num_id: dns_record.instance.id, diff --git a/src/bosh-director/lib/bosh/director/dns/dns_records.rb b/src/bosh-director/lib/bosh/director/dns/dns_records.rb index 367152f94d9..042c5fb166e 100644 --- a/src/bosh-director/lib/bosh/director/dns/dns_records.rb +++ b/src/bosh-director/lib/bosh/director/dns/dns_records.rb @@ -51,7 +51,7 @@ def shasum "sha256:#{::Digest::SHA256.hexdigest(to_json)}" end - def to_json + def to_json(*_args) JSON.dump( records: @records, version: @version, diff --git a/src/bosh-director/lib/bosh/director/dns/local_dns_encoder_manager.rb b/src/bosh-director/lib/bosh/director/dns/local_dns_encoder_manager.rb index d9e334465d4..623c90df0bf 100644 --- a/src/bosh-director/lib/bosh/director/dns/local_dns_encoder_manager.rb +++ b/src/bosh-director/lib/bosh/director/dns/local_dns_encoder_manager.rb @@ -45,12 +45,12 @@ def self.new_encoder_with_updated_index(plan) class << self private - # rubocop:disable Lint/HandleExceptions + # rubocop:disable Lint/SuppressedException def with_skip_dupes yield rescue Sequel::UniqueConstraintViolation => _ end - # rubocop:enable Lint/HandleExceptions + # rubocop:enable Lint/SuppressedException def encode_az(name) with_skip_dupes { Models::LocalDnsEncodedAz.find_or_create(name: name) } diff --git a/src/bosh-director/lib/bosh/director/errand/instance_matcher.rb b/src/bosh-director/lib/bosh/director/errand/instance_matcher.rb index f393bdacf9a..6f3b3a0c160 100644 --- a/src/bosh-director/lib/bosh/director/errand/instance_matcher.rb +++ b/src/bosh-director/lib/bosh/director/errand/instance_matcher.rb @@ -27,7 +27,7 @@ def match(instances) end end - return results.to_a, (@filters-applied_filters.to_a).compact.map(&:original) + [results.to_a, (@filters - applied_filters.to_a).compact.map(&:original)] end end diff --git a/src/bosh-director/lib/bosh/director/ip_util.rb b/src/bosh-director/lib/bosh/director/ip_util.rb index 44ffaea75d7..1cb0d0df05f 100644 --- a/src/bosh-director/lib/bosh/director/ip_util.rb +++ b/src/bosh-director/lib/bosh/director/ip_util.rb @@ -39,7 +39,8 @@ def format_ip(ip) def ip_address?(ip) ip_address = IPAddr.new(ip) - return ip_address.ipv4? || ip_address.ipv6? + + ip_address.ipv4? || ip_address.ipv6? rescue return false end diff --git a/src/bosh-director/lib/bosh/director/jobs/delete_stemcell.rb b/src/bosh-director/lib/bosh/director/jobs/delete_stemcell.rb index fe4941ecce8..d150a8e63b1 100644 --- a/src/bosh-director/lib/bosh/director/jobs/delete_stemcell.rb +++ b/src/bosh-director/lib/bosh/director/jobs/delete_stemcell.rb @@ -1,3 +1,5 @@ +require 'pp' # for #pretty_inspect + module Bosh::Director module Jobs class DeleteStemcell < BaseJob diff --git a/src/bosh-director/lib/bosh/director/jobs/orphan_disk.rb b/src/bosh-director/lib/bosh/director/jobs/orphan_disk.rb index d265a3bbdbe..cb20b858567 100644 --- a/src/bosh-director/lib/bosh/director/jobs/orphan_disk.rb +++ b/src/bosh-director/lib/bosh/director/jobs/orphan_disk.rb @@ -28,7 +28,8 @@ def perform @orphan_disk_manager.orphan_disk(persistent_disk) end end - return "disk #{@disk_cid} orphaned" + + "disk #{@disk_cid} orphaned" end end end diff --git a/src/bosh-director/lib/bosh/director/jobs/update_release.rb b/src/bosh-director/lib/bosh/director/jobs/update_release.rb index 1113278fac6..90a3eda9bb0 100644 --- a/src/bosh-director/lib/bosh/director/jobs/update_release.rb +++ b/src/bosh-director/lib/bosh/director/jobs/update_release.rb @@ -1,3 +1,4 @@ +require 'pp' # for #pretty_inspect require 'securerandom' require 'common/version/release_version' @@ -270,9 +271,7 @@ def process_jobs(release_dir) end did_something = create_jobs(new_jobs, release_dir) - did_something |= use_existing_jobs(existing_jobs, release_dir) - - did_something + did_something | use_existing_jobs(existing_jobs, release_dir) end # @return [boolean] true if at least one job was created; false if the call had no effect. diff --git a/src/bosh-director/lib/bosh/director/jobs/update_stemcell.rb b/src/bosh-director/lib/bosh/director/jobs/update_stemcell.rb index 25c3447b1e9..61b4f5ec656 100644 --- a/src/bosh-director/lib/bosh/director/jobs/update_stemcell.rb +++ b/src/bosh-director/lib/bosh/director/jobs/update_stemcell.rb @@ -168,7 +168,7 @@ def is_supported?(cloud, cpi) return (info['stemcell_formats'] & @stemcell_formats).any? if @stemcell_formats && info['stemcell_formats'] logger.info('There is no enough information to check if stemcell format is supported') - return true + true rescue Bosh::Clouds::NotImplemented cpi_suffix = " (cpi: #{cpi})" unless cpi.blank? logger.info("info method is not supported by cpi #{cpi_suffix}") diff --git a/src/bosh-director/lib/bosh/director/jobs/vm_state.rb b/src/bosh-director/lib/bosh/director/jobs/vm_state.rb index e7b8dc1bf2a..b4170ad9b6c 100644 --- a/src/bosh-director/lib/bosh/director/jobs/vm_state.rb +++ b/src/bosh-director/lib/bosh/director/jobs/vm_state.rb @@ -106,7 +106,7 @@ def vm_details(vm) end end - return job_state, job_vitals, processes, ips + [job_state, job_vitals, processes, ips] end def get_index(agent_state) diff --git a/src/bosh-director/lib/bosh/director/links/link_consumers_parser.rb b/src/bosh-director/lib/bosh/director/links/link_consumers_parser.rb index 8afa8af3934..84f04a7d727 100644 --- a/src/bosh-director/lib/bosh/director/links/link_consumers_parser.rb +++ b/src/bosh-director/lib/bosh/director/links/link_consumers_parser.rb @@ -73,10 +73,9 @@ def process_release_template_consumes( type: 'job', ) - errors = create_consumer_intent_from_template_model( + create_consumer_intent_from_template_model( consumer, consumes_links, current_release_template_model, instance_group_name, job_name ) - errors end def create_consumer_intent_from_template_model( diff --git a/src/bosh-director/lib/bosh/director/links/link_providers_parser.rb b/src/bosh-director/lib/bosh/director/links/link_providers_parser.rb index f856776799c..5e2aaf58282 100644 --- a/src/bosh-director/lib/bosh/director/links/link_providers_parser.rb +++ b/src/bosh-director/lib/bosh/director/links/link_providers_parser.rb @@ -121,7 +121,7 @@ def process_providers(release_properties, provider_definitions, manifest_provide type: 'job', ) - errors = process_provider_definitions( + process_provider_definitions( manifest_provides_links, provider, provider_definitions, @@ -131,7 +131,6 @@ def process_providers(release_properties, provider_definitions, manifest_provide job_name: job_name, job_properties: job_properties, ) - errors end def process_provider_definitions( diff --git a/src/bosh-director/lib/bosh/director/lock.rb b/src/bosh-director/lib/bosh/director/lock.rb index 8de80b7845e..d6bcafd0c66 100644 --- a/src/bosh-director/lib/bosh/director/lock.rb +++ b/src/bosh-director/lib/bosh/director/lock.rb @@ -46,7 +46,7 @@ def lock @refresh_signal.wait(@refresh_mutex, renew_interval) break if @unlock - @logger.debug("Renewing lock: #@name") + @logger.debug("Renewing lock: #{@name}") lock_expiration = Time.now.to_f + @expiration + 1 if Models::Lock.where(name: @name, uid: @uid).update(expired_at: Time.at(lock_expiration)) == 0 diff --git a/src/bosh-director/lib/bosh/director/manifest/manifest.rb b/src/bosh-director/lib/bosh/director/manifest/manifest.rb index 45cbaddc702..9898d9fe03d 100644 --- a/src/bosh-director/lib/bosh/director/manifest/manifest.rb +++ b/src/bosh-director/lib/bosh/director/manifest/manifest.rb @@ -16,7 +16,7 @@ def self.load_from_hash(manifest_hash, manifest_text, cloud_configs, runtime_con load_manifest(manifest_hash, manifest_text, consolidated_cloud_config, consolidated_runtime_config, options) end - def self.generate_empty_manifest() + def self.generate_empty_manifest consolidated_runtime_config = Bosh::Director::RuntimeConfig::RuntimeConfigsConsolidator.new([]) load_manifest({}, '{}', nil, consolidated_runtime_config, resolve_interpolation: false) end @@ -190,7 +190,7 @@ def resolve_stemcell_os(stemcell) models = stemcell_manager.all_by_name_and_version(stemcell['name'], stemcell['version']) unless models.empty? - return models.first.operating_system + models.first.operating_system end end diff --git a/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb index f7e6a139416..972303988d6 100644 --- a/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb @@ -312,7 +312,7 @@ def manifest_with_errand(deployment_name='errand') it 'does not skip draining' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_excluding('skip_drain'), anything()) + .with(anything, anything, anything, anything, anything, hash_excluding('skip_drain'), anything) .and_return(OpenStruct.new(:id => 1)) post '/', spec_asset('test_conf.yaml'), { 'CONTENT_TYPE' => 'text/yaml' } expect(last_response).to be_redirect @@ -323,7 +323,7 @@ def manifest_with_errand(deployment_name='errand') it 'skips draining' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_including('skip_drain' => '*'), anything()) + .with(anything, anything, anything, anything, anything, hash_including('skip_drain' => '*'), anything) .and_return(OpenStruct.new(:id => 1)) post '/?skip_drain=*', spec_asset('test_conf.yaml'), { 'CONTENT_TYPE' => 'text/yaml' } expect(last_response).to be_redirect @@ -334,7 +334,7 @@ def manifest_with_errand(deployment_name='errand') it 'skips draining' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_including('skip_drain' => 'job_one,job_two'), anything()) + .with(anything, anything, anything, anything, anything, hash_including('skip_drain' => 'job_one,job_two'), anything) .and_return(OpenStruct.new(:id => 1)) post '/?skip_drain=job_one,job_two', spec_asset('test_conf.yaml'), { 'CONTENT_TYPE' => 'text/yaml' } expect(last_response).to be_redirect @@ -345,7 +345,7 @@ def manifest_with_errand(deployment_name='errand') it 'passes the parameter' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_including('fix' => true), anything()) + .with(anything, anything, anything, anything, anything, hash_including('fix' => true), anything) .and_return(OpenStruct.new(:id => 1)) post '/?fix=true', spec_asset('test_conf.yaml'), {'CONTENT_TYPE' => 'text/yaml'} expect(last_response).to be_redirect @@ -396,7 +396,7 @@ def manifest_with_errand(deployment_name='errand') it 'calls create deployment with deployment name' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), deployment, hash_excluding('skip_drain'), anything()) + .with(anything, anything, anything, anything, deployment, hash_excluding('skip_drain'), anything) .and_return(OpenStruct.new(:id => 1)) post '/', spec_asset('test_manifest.yml'), { 'CONTENT_TYPE' => 'text/yaml' } expect(last_response).to be_redirect @@ -407,7 +407,7 @@ def manifest_with_errand(deployment_name='errand') it 'to false' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), deployment, hash_including('new' => false), anything()) + .with(anything, anything, anything, anything, deployment, hash_including('new' => false), anything) .and_return(OpenStruct.new(:id => 1)) post '/', spec_asset('test_manifest.yml'), { 'CONTENT_TYPE' => 'text/yaml' } end @@ -415,7 +415,7 @@ def manifest_with_errand(deployment_name='errand') it 'to true' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_including('new' => true), anything()) + .with(anything, anything, anything, anything, anything, hash_including('new' => true), anything) .and_return(OpenStruct.new(:id => 1)) Models::Deployment.first.delete post '/', spec_asset('test_manifest.yml'), { 'CONTENT_TYPE' => 'text/yaml' } @@ -426,7 +426,7 @@ def manifest_with_errand(deployment_name='errand') it 'passes the parameter' do expect_any_instance_of(DeploymentManager) .to receive(:create_deployment) - .with(anything(), anything(), anything(), anything(), anything(), hash_including('force_latest_variables' => true), anything()) + .with(anything, anything, anything, anything, anything, hash_including('force_latest_variables' => true), anything) .and_return(OpenStruct.new(:id => 1)) post '/?force_latest_variables=true', spec_asset('test_conf.yaml'), {'CONTENT_TYPE' => 'text/yaml'} expect(last_response).to be_redirect diff --git a/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb index 61591b8e09b..740f127ff0c 100644 --- a/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb @@ -109,35 +109,25 @@ module Api { 'name' => 'release-1', 'release_versions' => [ - Hash[ - 'version', - '1', - 'commit_hash', - 'unknown', - 'uncommitted_changes', - false, - 'currently_deployed', - true, - 'job_names', - [], - ], + { + 'version' => '1', + 'commit_hash' => 'unknown', + 'uncommitted_changes' => false, + 'currently_deployed' => true, + 'job_names' => [], + }, ], }, { 'name' => 'release-2', 'release_versions' => [ - Hash[ - 'version', - '2', - 'commit_hash', - '0b2c3d', - 'uncommitted_changes', - true, - 'currently_deployed', - false, - 'job_names', - [], - ], + { + 'version' => '2', + 'commit_hash' => '0b2c3d', + 'uncommitted_changes' => true, + 'currently_deployed' => false, + 'job_names' => [], + }, ], }, ] diff --git a/src/bosh-director/spec/unit/api/resource_manager_spec.rb b/src/bosh-director/spec/unit/api/resource_manager_spec.rb index d660d52f2c1..9f037573191 100644 --- a/src/bosh-director/spec/unit/api/resource_manager_spec.rb +++ b/src/bosh-director/spec/unit/api/resource_manager_spec.rb @@ -24,7 +24,7 @@ module Bosh::Director it 'saves resource to a local file' do blobstore.define_singleton_method(:get) {|id, f| - if id == 99 then + if id == 99 f.write('some data') end } @@ -49,7 +49,7 @@ module Bosh::Director it 'should return the contents of the blobstore id' do blobstore.define_singleton_method(:get) {|id| - if id == 99 then + if id == 99 'some data' end } diff --git a/src/bosh-director/spec/unit/blobstore_client/azurestoragecli_blobstore_client_spec.rb b/src/bosh-director/spec/unit/blobstore_client/azurestoragecli_blobstore_client_spec.rb index dfff4bbbf27..26c0b18cf28 100644 --- a/src/bosh-director/spec/unit/blobstore_client/azurestoragecli_blobstore_client_spec.rb +++ b/src/bosh-director/spec/unit/blobstore_client/azurestoragecli_blobstore_client_spec.rb @@ -67,7 +67,7 @@ module Bosh::Blobstore context 'when azure_storage_cli_config_path option is provided' do let(:azure_storage_cli_config_path) { Dir.tmpdir } let(:config_file_options) do - options.merge ( + options.merge( { azure_storage_cli_config_path: azure_storage_cli_config_path, }) diff --git a/src/bosh-director/spec/unit/blobstore_client/base_spec.rb b/src/bosh-director/spec/unit/blobstore_client/base_spec.rb index 0c97bcc2909..1845f22c30e 100644 --- a/src/bosh-director/spec/unit/blobstore_client/base_spec.rb +++ b/src/bosh-director/spec/unit/blobstore_client/base_spec.rb @@ -246,7 +246,7 @@ def redacted_credential_properties_list expect(logger).to receive(:debug).with("[blobstore] creating 'id' start: #{start_time}").ordered expect(subject).to receive(:create_file).ordered expect(logger).to receive(:debug).with("[blobstore] creating 'id' (took #{end_time - start_time})").ordered - subject.create(File.new(Tempfile.new().path, 'r'), 'id') + subject.create(File.new(Tempfile.new.path, 'r'), 'id') end end diff --git a/src/bosh-director/spec/unit/blobstore_client/gcscli_blobstore_client_spec.rb b/src/bosh-director/spec/unit/blobstore_client/gcscli_blobstore_client_spec.rb index 43dd15bad89..25f67d4a22c 100644 --- a/src/bosh-director/spec/unit/blobstore_client/gcscli_blobstore_client_spec.rb +++ b/src/bosh-director/spec/unit/blobstore_client/gcscli_blobstore_client_spec.rb @@ -70,7 +70,7 @@ module Bosh::Blobstore context 'when gcscli_config_path option is provided' do let(:gcscli_config_path) { Dir::tmpdir } let(:config_file_options) do - options.merge ( + options.merge( { gcscli_config_path: gcscli_config_path }) diff --git a/src/bosh-director/spec/unit/blobstore_client/s3cli_blobstore_client_spec.rb b/src/bosh-director/spec/unit/blobstore_client/s3cli_blobstore_client_spec.rb index 594d87c9fdf..85a62fef585 100644 --- a/src/bosh-director/spec/unit/blobstore_client/s3cli_blobstore_client_spec.rb +++ b/src/bosh-director/spec/unit/blobstore_client/s3cli_blobstore_client_spec.rb @@ -98,7 +98,7 @@ module Bosh::Blobstore context 'when s3cli_config_path option is provided' do let(:s3cli_config_path) { Dir.tmpdir } let(:config_file_options) do - options.merge ( + options.merge( { s3cli_config_path: s3cli_config_path, }) diff --git a/src/bosh-director/spec/unit/deployment_plan/network_parser/name_servers_parser_spec.rb b/src/bosh-director/spec/unit/deployment_plan/network_parser/name_servers_parser_spec.rb index 544b02261bc..f41a3d145ff 100644 --- a/src/bosh-director/spec/unit/deployment_plan/network_parser/name_servers_parser_spec.rb +++ b/src/bosh-director/spec/unit/deployment_plan/network_parser/name_servers_parser_spec.rb @@ -3,7 +3,7 @@ module Bosh::Director module DeploymentPlan::NetworkParser describe NameServersParser do - subject(:name_servers_parser) { NameServersParser.new() } + subject(:name_servers_parser) { NameServersParser.new } it 'should return nil when there are no DNS servers' do expect(name_servers_parser.parse('network', {})).to be_nil diff --git a/src/bosh-director/spec/unit/deployment_plan/stages/update_stage_functional_spec.rb b/src/bosh-director/spec/unit/deployment_plan/stages/update_stage_functional_spec.rb index 3189b15c6ac..928c1ba4bb1 100644 --- a/src/bosh-director/spec/unit/deployment_plan/stages/update_stage_functional_spec.rb +++ b/src/bosh-director/spec/unit/deployment_plan/stages/update_stage_functional_spec.rb @@ -147,7 +147,7 @@ module Bosh::Director::DeploymentPlan::Stages allow(agent_client).to receive(:prepare) allow(agent_client).to receive(:run_script) allow(agent_client).to receive(:start) - allow(cloud).to receive(:create_vm).and_return(['vm-cid-2']).ordered + allow(cloud).to receive(:create_vm).and_return(['vm-cid-2']) end it "creates an instance with 'lifecycle' in the spec" do diff --git a/src/bosh-director/spec/unit/errand/errand_provider_spec.rb b/src/bosh-director/spec/unit/errand/errand_provider_spec.rb index ed613dae045..945c8314521 100644 --- a/src/bosh-director/spec/unit/errand/errand_provider_spec.rb +++ b/src/bosh-director/spec/unit/errand/errand_provider_spec.rb @@ -579,9 +579,9 @@ module Bosh::Director end it 'will not raise an error' do - expect do + expect { subject.get(deployment_name, ig_name, keep_alive, instance_slugs) - end.not_to raise_error(RunErrandError) + }.not_to raise_error(RunErrandError) end end end @@ -600,9 +600,9 @@ module Bosh::Director end it 'fails' do - expect do + expect { subject.get(deployment_name, ig_name, keep_alive, instance_slugs) - end.to raise_error( + }.to raise_error( RunErrandError, "Instance group 'instance-group-name' is not an errand. " \ "To mark an instance group as an errand set its lifecycle to 'errand' in the deployment manifest.", diff --git a/src/bosh-director/spec/unit/jobs/helpers/package_deleter_spec.rb b/src/bosh-director/spec/unit/jobs/helpers/package_deleter_spec.rb index 7a5e79838c6..b691e2b3f82 100644 --- a/src/bosh-director/spec/unit/jobs/helpers/package_deleter_spec.rb +++ b/src/bosh-director/spec/unit/jobs/helpers/package_deleter_spec.rb @@ -8,8 +8,8 @@ module Jobs::Helpers let(:compiled_package_deleter) { CompiledPackageDeleter.new(blobstore, logger) } let(:blobstore) { instance_double(Bosh::Blobstore::BaseClient) } before { allow(blobstore).to receive(:delete) } - let(:release_version_1) { Models::ReleaseVersion.make() } - let(:release_version_2) { Models::ReleaseVersion.make() } + let(:release_version_1) { Models::ReleaseVersion.make } + let(:release_version_2) { Models::ReleaseVersion.make } let(:package) { Models::Package.make(blobstore_id: 'package_blobstore_id') } before do diff --git a/src/bosh-director/spec/unit/jobs/update_deployment_spec.rb b/src/bosh-director/spec/unit/jobs/update_deployment_spec.rb index 7c37c571dbb..1858b07b7f1 100644 --- a/src/bosh-director/spec/unit/jobs/update_deployment_spec.rb +++ b/src/bosh-director/spec/unit/jobs/update_deployment_spec.rb @@ -351,7 +351,7 @@ module Jobs it 'does not fail if cleaning up old VariableSets raises an error' do another_variable_set = Bosh::Director::Models::VariableSet.make(deployment: deployment_model) allow(deployment_instance_group).to receive(:referenced_variable_sets).and_return([variable_set, another_variable_set]) - allow(deployment_model).to receive(:cleanup_variable_sets).with([variable_set, another_variable_set]).and_raise(Sequel::ForeignKeyConstraintViolation.new('bad stuff happened')) + allow(deployment_model).to receive(:cleanup_variable_sets).with([variable_set, another_variable_set]).and_raise(Sequel::ForeignKeyConstraintViolation.new) expect { job.perform @@ -917,9 +917,9 @@ module Jobs it 'formats the error messages' do expect { job.perform - }.to raise_error { |error| + }.to(raise_error { |error| expect(error.message).to eq(expected_result) - } + }) end context 'when option deploy is set' do @@ -984,9 +984,9 @@ module Jobs it 'formats the error messages for service & errand instance groups' do expect { job.perform - }.to raise_error { |error| + }.to(raise_error { |error| expect(error.message).to eq(expected_result) - } + }) end end end diff --git a/src/bosh-director/spec/unit/sync_dns_scheduler_spec.rb b/src/bosh-director/spec/unit/sync_dns_scheduler_spec.rb index daf7800bd03..a9cc8b3e619 100644 --- a/src/bosh-director/spec/unit/sync_dns_scheduler_spec.rb +++ b/src/bosh-director/spec/unit/sync_dns_scheduler_spec.rb @@ -2,12 +2,12 @@ require 'db_migrator' require_relative '../../lib/bosh/director/sync_dns_scheduler' -Models = Bosh::Director::Models +SyncDnsSchedulerSpecModels = Bosh::Director::Models module Kernel - alias original_require require + alias sync_dns_scheduler_spec_require require def require(path) - Bosh::Director.const_set(:Models, Models) if path == 'bosh/director' && !defined?(Bosh::Director::Models) - original_require(path) + Bosh::Director.const_set(:Models, SyncDnsSchedulerSpecModels) if path == 'bosh/director' && !defined?(Bosh::Director::Models) + sync_dns_scheduler_spec_require(path) end end diff --git a/src/bosh-director/spec/unit/worker_spec.rb b/src/bosh-director/spec/unit/worker_spec.rb index dd362f96d41..8308383e493 100644 --- a/src/bosh-director/spec/unit/worker_spec.rb +++ b/src/bosh-director/spec/unit/worker_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' require 'db_migrator' -Models = Bosh::Director::Models +WorkerSpecModels = Bosh::Director::Models module Kernel - alias old_require require + alias worker_spec_require require def require(path) - Bosh::Director.const_set(:Models, Models) if path == 'bosh/director' && !defined?(Bosh::Director::Models) - old_require(path) + Bosh::Director.const_set(:Models, WorkerSpecModels) if path == 'bosh/director' && !defined?(Bosh::Director::Models) + worker_spec_require(path) end end @@ -103,7 +103,7 @@ module Bosh::Director worker.start - event = Models::Event.first + event = ::Bosh::Director::Models::Event.first expect(event.user).to eq('_director') expect(event.action).to eq('start') expect(event.object_type).to eq('worker') diff --git a/src/bosh-monitor/lib/bosh/monitor/plugins/email.rb b/src/bosh-monitor/lib/bosh/monitor/plugins/email.rb index e0d17d156e1..331333923b1 100644 --- a/src/bosh-monitor/lib/bosh/monitor/plugins/email.rb +++ b/src/bosh-monitor/lib/bosh/monitor/plugins/email.rb @@ -81,7 +81,7 @@ def process_queues email_body = '' @lock.synchronize do - while event = queue.shift + while (event = queue.shift) logger.info('Dequeueing...') email_body << event.to_plain_text << "\n" end diff --git a/src/bosh-monitor/lib/bosh/monitor/plugins/json.rb b/src/bosh-monitor/lib/bosh/monitor/plugins/json.rb index d49239fb863..91536fdcced 100644 --- a/src/bosh-monitor/lib/bosh/monitor/plugins/json.rb +++ b/src/bosh-monitor/lib/bosh/monitor/plugins/json.rb @@ -102,13 +102,13 @@ def run @wait_thr = wait_thr task.async do - while data = @stdout.read(1) + while (data = @stdout.read(1)) receive_data(data) end end task.async do - while data = @stderr.read(1) + while (data = @stderr.read(1)) receive_data(data) end end diff --git a/src/bosh-monitor/lib/bosh/monitor/plugins/riemann.rb b/src/bosh-monitor/lib/bosh/monitor/plugins/riemann.rb index 28e622d535c..5d4fc44cf67 100644 --- a/src/bosh-monitor/lib/bosh/monitor/plugins/riemann.rb +++ b/src/bosh-monitor/lib/bosh/monitor/plugins/riemann.rb @@ -19,7 +19,6 @@ def validate_options def client @client ||= ::Riemann::Client.new host: options['host'], port: options['port'] - @client end def process(event) diff --git a/src/bosh-template/lib/bosh/template/evaluation_context.rb b/src/bosh-template/lib/bosh/template/evaluation_context.rb index dc2927ce360..ade2f51b826 100644 --- a/src/bosh-template/lib/bosh/template/evaluation_context.rb +++ b/src/bosh-template/lib/bosh/template/evaluation_context.rb @@ -133,7 +133,7 @@ def link(name) def if_link(name) link_spec = lookup_property(@links, name) if link_spec.nil? || !link_spec.has_key?('instances') - return ActiveElseBlock.new(self) + ActiveElseBlock.new(self) else yield create_evaluation_link(link_spec) InactiveElseBlock.new diff --git a/src/spec/assets/uaa_config/asymmetric/uaa.yml b/src/spec/assets/uaa_config/asymmetric/uaa.yml index 37c2bb7fb71..755569383a6 100644 --- a/src/spec/assets/uaa_config/asymmetric/uaa.yml +++ b/src/spec/assets/uaa_config/asymmetric/uaa.yml @@ -83,7 +83,7 @@ oauth: hm: id: hm override: true - authorized-grant-types: client_credentials + authorized-grant-types: client_credentials,refresh_token scope: openid authorities: uaa.none,bosh.admin secret: "secret" @@ -108,13 +108,6 @@ oauth: scope: openid authorities: bosh.admin secret: "auditsecret" - hm: - id: hm - override: true - authorized-grant-types: client_credentials,refresh_token - scope: openid - authorities: uaa.none,bosh.admin - secret: "secret" jwt: token: signing-key: | diff --git a/src/spec/integration/cli_cloud_config_spec.rb b/src/spec/integration/cli_cloud_config_spec.rb index 9bb2fbda2d0..c3341cd657d 100644 --- a/src/spec/integration/cli_cloud_config_spec.rb +++ b/src/spec/integration/cli_cloud_config_spec.rb @@ -62,9 +62,9 @@ it 'does not fail if the uploaded cloud config is a large file' do cloud_config = Bosh::Common::DeepCopy.copy(Bosh::Spec::Deployments.simple_cloud_config) - for i in 0..10001 + (0..10001).each { |i| cloud_config["boshbosh#{i}"] = 'smurfsAreBlueGargamelIsBrownPinkpantherIsPinkAndPikachuIsYellow' - end + } cloud_config_file = yaml_file('cloud_config.yml', cloud_config) diff --git a/src/spec/integration/cli_cpi_config_spec.rb b/src/spec/integration/cli_cpi_config_spec.rb index 99cb3ba1a9b..a21c78274de 100644 --- a/src/spec/integration/cli_cpi_config_spec.rb +++ b/src/spec/integration/cli_cpi_config_spec.rb @@ -45,9 +45,9 @@ it 'does not fail when cpi config is very large' do cpi_config = Bosh::Common::DeepCopy.copy(Bosh::Spec::Deployments.multi_cpi_config) - for i in 0..10001 + (0..10001).each { |i| cpi_config["boshbosh#{i}"] = 'smurfsAreBlueGargamelIsBrownPinkpantherIsPinkAndPikachuIsYellow' - end + } cpi_yaml = yaml_file('cpi_config.yml', cpi_config) output, exit_code = bosh_runner.run("update-cpi-config #{cpi_yaml.path}", return_exit_code: true) diff --git a/src/spec/integration/cli_start_isolated_spec.rb b/src/spec/integration/cli_start_isolated_spec.rb index 765a5c4ae46..905d183c9e9 100644 --- a/src/spec/integration/cli_start_isolated_spec.rb +++ b/src/spec/integration/cli_start_isolated_spec.rb @@ -221,7 +221,9 @@ def vm_states expect(config_file).to include('updated_value') isolated_stop(instance_group: 'foobar', index: middle_instance.index) - expect { isolated_start(instance_group: 'foobar', index: middle_instance.index) }.to raise_error + expect { + isolated_start(instance_group: 'foobar', index: middle_instance.index) + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) config_file = middle_instance.read_job_template('job_with_bad_template', 'config/config.yml') expect(config_file).to include('updated_value') diff --git a/src/spec/integration/config_server/config_server_cloud_config_spec.rb b/src/spec/integration/config_server/config_server_cloud_config_spec.rb index 3d9f5f1331c..57247d10de0 100644 --- a/src/spec/integration/config_server/config_server_cloud_config_spec.rb +++ b/src/spec/integration/config_server/config_server_cloud_config_spec.rb @@ -231,9 +231,13 @@ def bosh_run_cck_with_resolution(num_errors, option = 1, env = {}) end it 'can redeploy' do - expect do - deploy_simple_manifest(no_login: true, manifest_hash: manifest_hash, return_exit_code: true, include_credentials: false, env: client_env) - end.to_not raise_error + expect { + deploy_simple_manifest(no_login: true, + manifest_hash: manifest_hash, + return_exit_code: true, + include_credentials: false, + env: client_env) + }.to_not raise_error end end end @@ -247,9 +251,14 @@ def bosh_run_cck_with_resolution(num_errors, option = 1, env = {}) end it 'errors on deploy' do - expect do - deploy_from_scratch(no_login: true, manifest_hash: manifest_hash, cloud_config_hash: cloud_config, return_exit_code: true, include_credentials: false, env: client_env) - end.to raise_error + expect { + deploy_from_scratch(no_login: true, + manifest_hash: manifest_hash, + cloud_config_hash: cloud_config, + return_exit_code: true, + include_credentials: false, + env: client_env) + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) end end @@ -260,15 +269,20 @@ def bosh_run_cck_with_resolution(num_errors, option = 1, env = {}) it 'does NOT error on update of cloud-config' do cloud_config_manifest = yaml_file('cloud_manifest', cloud_config) - expect do + expect { bosh_runner.run("update-cloud-config #{cloud_config_manifest.path}", no_login: true, include_credentials: false, env: client_env) - end.to_not raise_error + }.to_not raise_error end it 'errors on deploy' do - expect do - deploy_from_scratch(no_login: true, manifest_hash: manifest_hash, cloud_config_hash: cloud_config, return_exit_code: true, include_credentials: false, env: client_env) - end.to raise_error(RuntimeError, /Relative paths are not allowed in this context. The following must be be switched to use absolute paths: 'z1_cloud_properties'/) + expect { + deploy_from_scratch(no_login: true, + manifest_hash: manifest_hash, + cloud_config_hash: cloud_config, + return_exit_code: true, + include_credentials: false, + env: client_env) + }.to raise_error(RuntimeError, /Relative paths are not allowed in this context. The following must be be switched to use absolute paths: 'z1_cloud_properties'/) end end end @@ -292,7 +306,12 @@ def bosh_run_cck_with_resolution(num_errors, option = 1, env = {}) context 'after a successful deployment' do before do - deploy_from_scratch(no_login: true, manifest_hash: manifest_hash, cloud_config_hash: cloud_config, return_exit_code: true, include_credentials: false, env: client_env) + deploy_from_scratch(no_login: true, + manifest_hash: manifest_hash, + cloud_config_hash: cloud_config, + return_exit_code: true, + include_credentials: false, + env: client_env) end context 'deployment has unresponsive agents' do @@ -393,9 +412,9 @@ def bosh_run_cck_with_resolution(num_errors, option = 1, env = {}) manifest = yaml_file('manifest', manifest_hash) bosh_runner.run("deploy #{manifest.path}", deployment_name: 'foo-deployment', return_exit_code: true, include_credentials: false, env: client_env) - expect do + expect { bosh_runner.run('recreate', deployment_name: 'foo-deployment', return_exit_code: true, include_credentials: false, env: client_env) - end.to_not raise_error + }.to_not raise_error end end diff --git a/src/spec/integration/config_server/env_spec.rb b/src/spec/integration/config_server/env_spec.rb index 51be81a454d..3c10b864455 100644 --- a/src/spec/integration/config_server/env_spec.rb +++ b/src/spec/integration/config_server/env_spec.rb @@ -120,11 +120,7 @@ def prepend_namespace(key) end context 'when remove_dev_tools key exist' do - with_reset_sandbox_before_each( - remove_dev_tools: true, - config_server_enabled: true, - user_authentication: 'uaa', - ) + with_reset_sandbox_before_each(remove_dev_tools: true, config_server_enabled: true, user_authentication: 'uaa') let(:env_hash) do { diff --git a/src/spec/integration/create_swap_delete_update_spec.rb b/src/spec/integration/create_swap_delete_update_spec.rb index 13c1a119d23..94a580128f8 100644 --- a/src/spec/integration/create_swap_delete_update_spec.rb +++ b/src/spec/integration/create_swap_delete_update_spec.rb @@ -14,14 +14,8 @@ end describe 'deploy with create-swap-delete', type: :integration do - with_reset_sandbox_before_each( - local_dns: { - 'enabled' => true, - 'include_index' => false, - 'use_dns_addresses' => true, - }, - agent_wait_timeout: 3, - ) + with_reset_sandbox_before_each(local_dns: {'enabled' => true, 'include_index' => false, 'use_dns_addresses' => true}, + agent_wait_timeout: 3) let(:manifest) do manifest = Bosh::Spec::Deployments.simple_manifest_with_instance_groups(instances: 1, azs: ['z1']) diff --git a/src/spec/integration/links/consuming_and_providing_spec.rb b/src/spec/integration/links/consuming_and_providing_spec.rb index 000ebb9972b..98bda5fee5e 100644 --- a/src/spec/integration/links/consuming_and_providing_spec.rb +++ b/src/spec/integration/links/consuming_and_providing_spec.rb @@ -384,7 +384,7 @@ def upload_links_release end def get_provider_instance_group(provides_definition) - instance_group_spec = Bosh::Spec::Deployments.simple_instance_group( + Bosh::Spec::Deployments.simple_instance_group( name: 'provider_ig', jobs: [ { @@ -395,7 +395,6 @@ def get_provider_instance_group(provides_definition) ], instances: 2, ) - instance_group_spec end let(:consumer_instance_group) do diff --git a/src/spec/integration/network_configuration_spec.rb b/src/spec/integration/network_configuration_spec.rb index 5e5e3919184..a5a3340ddfc 100644 --- a/src/spec/integration/network_configuration_spec.rb +++ b/src/spec/integration/network_configuration_spec.rb @@ -342,7 +342,7 @@ expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - }.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) end end diff --git a/src/spec/integration/network_lifecycle_spec.rb b/src/spec/integration/network_lifecycle_spec.rb index cbca67bbc53..8dda32717ef 100644 --- a/src/spec/integration/network_lifecycle_spec.rb +++ b/src/spec/integration/network_lifecycle_spec.rb @@ -63,9 +63,9 @@ ], }] upload_cloud_config(cloud_config_hash: cloud_config_hash) - expect do + expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - end.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) end it 'should have unique subnet names' do @@ -102,9 +102,9 @@ }] upload_cloud_config(cloud_config_hash: cloud_config_hash) - expect do + expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - end.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) end it 'should not have both netmask_bits and range' do @@ -125,9 +125,9 @@ }] upload_cloud_config(cloud_config_hash: cloud_config_hash) - expect do + expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - end.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) end it 'should create a subnet in the iaas for first deployment' do @@ -269,9 +269,9 @@ }] upload_cloud_config(cloud_config_hash: cloud_config_hash) - expect do + expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - end.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) create_network_invocations = current_sandbox.cpi.invocations_for_method('create_network') expect(create_network_invocations.count).to eq(0) end @@ -401,9 +401,9 @@ ], }] upload_cloud_config(cloud_config_hash: cloud_config_hash) - expect do + expect { deploy_from_scratch(cloud_config_hash: cloud_config_hash, manifest_hash: manifest_hash) - end.to raise_error + }.to raise_error(Bosh::Spec::BoshGoCliRunner::Error) create_network_invocations = current_sandbox.cpi.invocations_for_method('create_network') expect(create_network_invocations.count).to eq(4) delete_network_invocations = current_sandbox.cpi.invocations_for_method('delete_network') diff --git a/src/spec/integration/release/create_release_spec.rb b/src/spec/integration/release/create_release_spec.rb index 9a135c21a0b..cc54ad89e7e 100644 --- a/src/spec/integration/release/create_release_spec.rb +++ b/src/spec/integration/release/create_release_spec.rb @@ -4,8 +4,8 @@ describe 'create-release', type: :integration do include Bosh::Spec::CreateReleaseOutputParsers with_reset_sandbox_before_each - SHA2_REGEXP = /^[0-9a-f]{64}$/ - SHA2_PREFIXED_REGEXP = /^sha256:[0-9a-f]{64}$/ + let(:sha2_regexp) { /^[0-9a-f]{64}$/ } + let(:sha2_prefixed_regexp) { /^sha256:[0-9a-f]{64}$/ } before do setup_test_release_dir @@ -136,7 +136,7 @@ expect(release_manifest['name']).to eq('bosh-release') expect(release_manifest['version']).to eq('1') - expect(release_manifest['packages']).to match(a_collection_containing_exactly( + expect(release_manifest['packages']).to contain_exactly( package_desc('a', ['b']), package_desc('b', ['c']), package_desc('bar', ['foo']), @@ -155,9 +155,9 @@ package_desc('foo_8', []), package_desc('foo_9', []), package_desc('foo_10', []), - )) + ) - expect(release_manifest['jobs']).to match(a_collection_containing_exactly( + expect(release_manifest['jobs']).to contain_exactly( job_desc('emoji-errand'), job_desc('errand1', ['errand1']), job_desc('errand_without_package'), @@ -197,7 +197,7 @@ job_desc('id_job'), job_desc('job_with_bad_template'), job_desc('local_dns_records_json'), - )) + ) expect(release_manifest['uncommitted_changes']).to eq(false) end @@ -503,28 +503,28 @@ def with_changed_release def package_desc(name, dependencies) match( 'name' => name, - 'version' => SHA2_REGEXP, - 'fingerprint' => SHA2_REGEXP, + 'version' => sha2_regexp, + 'fingerprint' => sha2_regexp, 'dependencies' => dependencies, - 'sha1' => SHA2_PREFIXED_REGEXP, + 'sha1' => sha2_prefixed_regexp, ) end def job_desc(name, packages = []) match( 'name' => name, - 'version' => SHA2_REGEXP, - 'fingerprint' => SHA2_REGEXP, - 'sha1' => SHA2_PREFIXED_REGEXP, + 'version' => sha2_regexp, + 'fingerprint' => sha2_regexp, + 'sha1' => sha2_prefixed_regexp, 'packages' => packages, ) end def license_desc match( - 'version' => SHA2_REGEXP, - 'fingerprint' => SHA2_REGEXP, - 'sha1' => SHA2_PREFIXED_REGEXP, + 'version' => sha2_regexp, + 'fingerprint' => sha2_regexp, + 'sha1' => sha2_prefixed_regexp, ) end @@ -539,7 +539,7 @@ def it_creates_artifact(artifact_path, expected_files = []) 'builds' => { fingerprint => { 'version' => fingerprint, - 'sha1' => SHA2_PREFIXED_REGEXP, + 'sha1' => sha2_prefixed_regexp, 'blobstore_id' => kind_of(String), }, }, diff --git a/src/spec/shared/support/api_helpers.rb b/src/spec/shared/support/api_helpers.rb index 85b671e13bf..2b8dfa1ea8f 100644 --- a/src/spec/shared/support/api_helpers.rb +++ b/src/spec/shared/support/api_helpers.rb @@ -42,7 +42,8 @@ def build_director_api_url(url_path, query) director_url = URI(current_sandbox.director_url) director_url.path = url_path director_url.query = query - return director_url + + director_url end end end diff --git a/src/spec/support/bosh_go_cli_runner.rb b/src/spec/support/bosh_go_cli_runner.rb index 72da057805b..4e6c0bad193 100644 --- a/src/spec/support/bosh_go_cli_runner.rb +++ b/src/spec/support/bosh_go_cli_runner.rb @@ -4,6 +4,26 @@ module Bosh::Spec class BoshGoCliRunner include Support::TableHelpers + class Error < RuntimeError + + end + + class TaskIdParseError < Error + + end + + class CommandExecutionError < Error + + end + + class TaskNotFoundError < Error + + end + + class ThreadSandboxMissingError < Error + + end + def initialize(bosh_work_dir, bosh_config, agent_log_path_resolver, nats_log_path, saved_logs_path, logger, sha2) @bosh_work_dir = bosh_work_dir @bosh_config = bosh_config @@ -37,7 +57,7 @@ def reset def current_sandbox sandbox = Thread.current[:sandbox] - raise "call prepare_sandbox to set up this thread's sandbox" if sandbox.nil? + raise ThreadSandboxMissingError, "call prepare_sandbox to set up this thread's sandbox" if sandbox.nil? sandbox end @@ -54,14 +74,14 @@ def run_in_dir(cmd, working_dir, options = {}) exit_code = 0 time = Benchmark.realtime do - Open3.popen2e(env, command, chdir: working_dir) do |stdin, stdout_and_stderr, wait_thr| + Open3.popen2e(env, command, chdir: working_dir) do |_stdin, stdout_and_stderr, wait_thr| if options.fetch(:no_track, false) line = "negative-ghostrider" start = Time.now loop do line = stdout_and_stderr.gets break if line =~ /Task (\d+)/ - raise 'Failed to parse task id from output within timeout' if (Time.now - start) > 20 + raise TaskIdParseError, 'Failed to parse task id from output within timeout' if (Time.now - start) > 20 end output = line exit_code = 0 @@ -90,7 +110,7 @@ def run_in_dir(cmd, working_dir, options = {}) print_agent_debug_logs($1) end - raise "ERROR: #{command} failed with output:\n#{output}" + raise CommandExecutionError, "ERROR: #{command} failed with output:\n#{output}" end options.fetch(:return_exit_code, false) ? [output, exit_code] : output @@ -124,7 +144,7 @@ def get_most_recent_task_id task_table = table(run('tasks --recent --all --json')) if task_table.empty? - raise 'No tasks found!' + raise TaskNotFoundError, 'No tasks found!' end task_table[0]['id'] diff --git a/src/spec/support/director.rb b/src/spec/support/director.rb index 341b6ea6a7c..c823bb07512 100644 --- a/src/spec/support/director.rb +++ b/src/spec/support/director.rb @@ -138,7 +138,7 @@ def finish_recording_nats def task(id) output = @runner.run("task #{id}", failure_expected: true) # permit failures, gocli task command fails if non-success. ruby cli return success despite task failure. failed = /Task (\d+) error/.match(output) - return output, !failed + [output, !failed] end def tasks diff --git a/src/spec/support/integration_example_group.rb b/src/spec/support/integration_example_group.rb index 0fa537d9c62..599bb5a1660 100644 --- a/src/spec/support/integration_example_group.rb +++ b/src/spec/support/integration_example_group.rb @@ -5,6 +5,14 @@ require 'bosh/dev/gnatsd_manager' module IntegrationExampleGroup + class DeploymentFailedError < RuntimeError + + end + + class UnknownRecordTypeError < RuntimeError + + end + def logger @logger ||= current_sandbox.logger end @@ -209,7 +217,9 @@ def deploy_simple_manifest(options = {}) output, exit_code = deploy(options.merge(return_exit_code: true)) - raise "Deploy failed. Exited #{exit_code}: #{output}" if exit_code != 0 && !options.fetch(:failure_expected, false) + if exit_code != 0 && !options.fetch(:failure_expected, false) + raise DeploymentFailedError, "Deploy failed. Exited #{exit_code}: #{output}" + end return_exit_code ? [output, exit_code] : output end @@ -364,7 +374,7 @@ def sub_in_records(output, regex_pattern, replace_pattern) elsif record.is_a?(String) record.gsub(regex_pattern, replace_pattern) else - raise 'Unknown record type' + raise UnknownRecordTypeError, 'Unknown record type' end end end @@ -375,12 +385,16 @@ def start_sandbox unless sandbox_started? at_exit do begin - status = $! ? ($!.is_a?(::SystemExit) ? $!.status : 1) : 0 + status = if $! + $!.is_a?(::SystemExit) ? $!.status : 1 + else + 0 + end logger.info("\n Stopping sandboxed environment for BOSH tests...") current_sandbox.stop cleanup_client_sandbox_dir rescue StandardError => e - logger.error "Failed to stop sandbox! #{e.message}\n#{e.backtrace.join("\n")}" + logger.error "Failed to stop sandbox! #{e.message}\n#{e.backtrace&.join("\n")}" ensure exit(status) end diff --git a/src/spec/support/license_blobs.rb b/src/spec/support/license_blobs.rb index 64082d71a0e..e12a02eaca4 100644 --- a/src/spec/support/license_blobs.rb +++ b/src/spec/support/license_blobs.rb @@ -1,17 +1,20 @@ def blobstore_license_file_path(version) license_index = YAML.load_file(File.join(ClientSandbox.test_release_dir, '.final_builds', 'license', 'index.yml')) blobstore_id = license_index['builds'][version]['blobstore_id'] - return File.join(ClientSandbox.blobstore_dir, blobstore_id) + + File.join(ClientSandbox.blobstore_dir, blobstore_id) end def manifest_sha1_of_license(version) license_index = YAML.load_file(File.join(ClientSandbox.test_release_dir, '.final_builds', 'license', 'index.yml')) - return license_index['builds'][version]['sha1'] + + license_index['builds'][version]['sha1'] end def blobstore_tarball_listing(version) license_tarball_path = blobstore_license_file_path(version) - return `tar ztf #{license_tarball_path}`.split("\n").sort + + `tar ztf #{license_tarball_path}`.split("\n").sort end def actual_sha1_of_license(version)