From b5adbf3fe568a4b9d292a30b4e3b9f5667eb01bc Mon Sep 17 00:00:00 2001 From: Seth Boyles Date: Mon, 16 Dec 2024 14:14:03 -0800 Subject: [PATCH] Remove unused code (#4072) --- lib/cloud_controller.rb | 1 - lib/cloud_controller/backends/runners.rb | 4 -- .../background_job_environment.rb | 2 - .../blobstore/fingerprints_collection.rb | 6 --- lib/cloud_controller/drain.rb | 2 + .../egress_network_rules_presenter.rb | 11 ----- lib/cloud_controller/resource_match.rb | 2 +- lib/cloud_controller/runner.rb | 6 +-- lib/cloud_controller/seeds.rb | 8 ---- lib/diego/client.rb | 9 ---- spec/diego/client_spec.rb | 45 +------------------ .../blobstore/fingerprints_collection_spec.rb | 6 --- .../egress_network_rules_presenter_spec.rb | 22 --------- spec/unit/lib/cloud_controller/runner_spec.rb | 4 -- 14 files changed, 5 insertions(+), 123 deletions(-) delete mode 100644 lib/cloud_controller/egress_network_rules_presenter.rb delete mode 100644 spec/unit/lib/cloud_controller/egress_network_rules_presenter_spec.rb diff --git a/lib/cloud_controller.rb b/lib/cloud_controller.rb index 0db3fc67a3f..7c4965dd80a 100644 --- a/lib/cloud_controller.rb +++ b/lib/cloud_controller.rb @@ -74,7 +74,6 @@ module VCAP::CloudController; end require 'cloud_controller/transport_rule_validator' require 'cloud_controller/icmp_rule_validator' require 'cloud_controller/controller_factory' -require 'cloud_controller/egress_network_rules_presenter' require 'cloud_controller/organization_instance_usage_calculator' require 'cloud_controller/organization_quota_usage' require 'cloud_controller/url_secret_obfuscator' diff --git a/lib/cloud_controller/backends/runners.rb b/lib/cloud_controller/backends/runners.rb index ea0d5862875..ad037b79e26 100644 --- a/lib/cloud_controller/backends/runners.rb +++ b/lib/cloud_controller/backends/runners.rb @@ -77,9 +77,5 @@ def diego_runner(process) def dependency_locator CloudController::DependencyLocator.instance end - - def staging_timeout - @config.get(:staging, :timeout_in_seconds) - end end end diff --git a/lib/cloud_controller/background_job_environment.rb b/lib/cloud_controller/background_job_environment.rb index 4f4ba3d8f04..e81521592b1 100644 --- a/lib/cloud_controller/background_job_environment.rb +++ b/lib/cloud_controller/background_job_environment.rb @@ -14,8 +14,6 @@ def initialize(config) @logger = Steno.logger('cc.background') end - READINESS_SOCKET_QUEUE_DEPTH = 100 - def setup_environment(readiness_port=nil) VCAP::CloudController::DB.load_models(@config.get(:db), @logger) @config.configure_components diff --git a/lib/cloud_controller/blobstore/fingerprints_collection.rb b/lib/cloud_controller/blobstore/fingerprints_collection.rb index 72a0eff5e4f..5ff87270d0b 100644 --- a/lib/cloud_controller/blobstore/fingerprints_collection.rb +++ b/lib/cloud_controller/blobstore/fingerprints_collection.rb @@ -27,12 +27,6 @@ def each(&block) end end - def storage_size - @fingerprints.inject(0) do |sum, fingerprint| - sum + fingerprint['size'] - end - end - private def parse_mode(raw_mode, filename) diff --git a/lib/cloud_controller/drain.rb b/lib/cloud_controller/drain.rb index e935952a316..07368cef208 100644 --- a/lib/cloud_controller/drain.rb +++ b/lib/cloud_controller/drain.rb @@ -1,3 +1,5 @@ +# This class is used in capi-release (e.g. https://github.com/cloudfoundry/capi-release/blob/b817791b0f4d8780304cef148f1aeb3f2a944af8/jobs/cloud_controller_ng/templates/shutdown_drain.rb.erb#L8) + require 'logger' require 'fileutils' diff --git a/lib/cloud_controller/egress_network_rules_presenter.rb b/lib/cloud_controller/egress_network_rules_presenter.rb deleted file mode 100644 index dac291c257a..00000000000 --- a/lib/cloud_controller/egress_network_rules_presenter.rb +++ /dev/null @@ -1,11 +0,0 @@ -module VCAP::CloudController - class EgressNetworkRulesPresenter - def initialize(security_groups) - @security_groups = security_groups - end - - def to_array - @security_groups.map(&:rules).flatten - end - end -end diff --git a/lib/cloud_controller/resource_match.rb b/lib/cloud_controller/resource_match.rb index 736e099aed6..9041469acc4 100644 --- a/lib/cloud_controller/resource_match.rb +++ b/lib/cloud_controller/resource_match.rb @@ -1,6 +1,6 @@ module VCAP::CloudController class ResourceMatch - attr_reader :descriptors, :minimum_size, :maximum_size, :resource_batch_id + attr_reader :descriptors FILE_SIZE_GROUPS = { '1KB or less': 0...1.kilobyte, diff --git a/lib/cloud_controller/runner.rb b/lib/cloud_controller/runner.rb index 6ed46583fde..c70b3e6307a 100644 --- a/lib/cloud_controller/runner.rb +++ b/lib/cloud_controller/runner.rb @@ -17,7 +17,7 @@ module VCAP::CloudController class Runner - attr_reader :config, :config_file, :insert_seed_data, :secrets_file + attr_reader :config, :config_file, :secrets_file def initialize(argv) @argv = argv @@ -66,10 +66,6 @@ def options_parser end end - def deprecation_warning(message) - Rails.logger.warn message - end - def parse_options! options_parser.parse!(@argv) raise 'Missing config' if @config_file.blank? diff --git a/lib/cloud_controller/seeds.rb b/lib/cloud_controller/seeds.rb index a6ad5a7bcb0..9b6b3b3f0d3 100644 --- a/lib/cloud_controller/seeds.rb +++ b/lib/cloud_controller/seeds.rb @@ -192,14 +192,6 @@ def seed_encryption_key_sentinels(config) def routing_api_client CloudController::DependencyLocator.instance.routing_api_client end - - def domain_overlap(parsed_domain, system_config) - overlap = false - parsed_domain.each do |d| - overlap = true if d['name'].include?(system_config) - end - overlap - end end end end diff --git a/lib/diego/client.rb b/lib/diego/client.rb index 5f995f2b843..010f9051d13 100644 --- a/lib/diego/client.rb +++ b/lib/diego/client.rb @@ -20,15 +20,6 @@ def initialize(url:, ca_cert_file:, client_cert_file:, client_key_file:, ) end - def ping - response = with_request_error_handling do - client.post(Routes::PING) - end - - validate_status_200!(response) - protobuf_decode!(response.body, Bbs::Models::PingResponse) - end - def upsert_domain(domain:, ttl:) request = protobuf_encode!({ domain: domain, ttl: ttl.to_i }, Bbs::Models::UpsertDomainRequest) diff --git a/spec/diego/client_spec.rb b/spec/diego/client_spec.rb index c18f1840183..602ebde1eab 100644 --- a/spec/diego/client_spec.rb +++ b/spec/diego/client_spec.rb @@ -34,49 +34,6 @@ module Diego end end - describe '#ping' do - let(:response_body) { Bbs::Models::PingResponse.encode(Bbs::Models::PingResponse.new(available: true)).to_s } - let(:response_status) { 200 } - - before do - stub_request(:post, "#{bbs_url}/v1/ping").to_return(status: response_status, body: response_body) - end - - it 'returns a ping response' do - expect(client.ping.available).to be_truthy - expect(a_request(:post, "#{bbs_url}/v1/ping")).to have_been_made.once - end - - context 'when it does not return successfully' do - let(:response_status) { 500 } - let(:response_body) { 'Internal Server Error' } - - it 'raises' do - expect { client.ping }.to raise_error(ResponseError, /status: 500, body: Internal Server Error/) - end - end - - context 'when it fails to make the request' do - before do - stub_request(:post, "#{bbs_url}/v1/ping").to_raise(StandardError.new('error message')) - allow(subject).to receive(:sleep) { |n| Timecop.travel(n) } - end - - it 'raises' do - expect { client.ping }.to raise_error(RequestError, /error message/) - expect(a_request(:post, "#{bbs_url}/v1/ping")).to have_been_made.times(17) - end - end - - context 'when decoding the response fails' do - let(:response_body) { 'potato' } - - it 'raises' do - expect { client.ping }.to raise_error(DecodeError) - end - end - end - describe '#upsert_domain' do let(:response_body) { Bbs::Models::UpsertDomainResponse.encode(Bbs::Models::UpsertDomainResponse.new(error: nil)).to_s } let(:response_status) { 200 } @@ -887,7 +844,7 @@ module Diego end it 'sets TCPSocket:connect_timeout to HTTPClient:connect_timeout / 2' do - expect { client.ping }.to raise_error('done!') + expect { client.task_by_guid('b62be6c2-0f2c-4199-94d3-41a69e00f67d') }.to raise_error('done!') expect(TCPSocket).to have_received(:new).with(bbs_host, bbs_port, { connect_timeout: timeout / 2 }).exactly(17).times end end diff --git a/spec/unit/lib/cloud_controller/blobstore/fingerprints_collection_spec.rb b/spec/unit/lib/cloud_controller/blobstore/fingerprints_collection_spec.rb index 7d8cc5e3a98..8659399a1d7 100644 --- a/spec/unit/lib/cloud_controller/blobstore/fingerprints_collection_spec.rb +++ b/spec/unit/lib/cloud_controller/blobstore/fingerprints_collection_spec.rb @@ -23,12 +23,6 @@ module Blobstore end end - describe '#storage_size' do - it 'sums the sizes' do - expect(collection.storage_size).to eq 123 + 321 + 112 - end - end - describe '#fingerprints' do let(:unpresented_fingerprints) do [ diff --git a/spec/unit/lib/cloud_controller/egress_network_rules_presenter_spec.rb b/spec/unit/lib/cloud_controller/egress_network_rules_presenter_spec.rb deleted file mode 100644 index d9169b57869..00000000000 --- a/spec/unit/lib/cloud_controller/egress_network_rules_presenter_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -module VCAP::CloudController - RSpec.describe EgressNetworkRulesPresenter do - let(:sg1) { SecurityGroup.make(rules: [{ 'protocol' => 'udp', 'ports' => '8080', 'destination' => '198.41.191.47/1' }]) } - let(:sg2) { SecurityGroup.make(rules: [{ 'protocol' => 'tcp', 'ports' => '9090', 'destination' => '198.41.191.48/1', 'log' => true }]) } - let(:sg3) { SecurityGroup.make(rules: [{ 'protocol' => 'udp', 'ports' => '1010', 'destination' => '198.41.191.49/1' }]) } - - subject { EgressNetworkRulesPresenter.new([sg1, sg2, sg3]) } - - describe '#to_array' do - it 'returns an aggregated array of rules' do - expected = [ - { 'protocol' => 'udp', 'ports' => '8080', 'destination' => '198.41.191.47/1' }, - { 'protocol' => 'tcp', 'ports' => '9090', 'destination' => '198.41.191.48/1', 'log' => true }, - { 'protocol' => 'udp', 'ports' => '1010', 'destination' => '198.41.191.49/1' } - ] - expect(subject.to_array).to match_array(expected) - end - end - end -end diff --git a/spec/unit/lib/cloud_controller/runner_spec.rb b/spec/unit/lib/cloud_controller/runner_spec.rb index 5fabb456a1c..93079535066 100644 --- a/spec/unit/lib/cloud_controller/runner_spec.rb +++ b/spec/unit/lib/cloud_controller/runner_spec.rb @@ -43,10 +43,6 @@ module VCAP::CloudController end describe '#initialize' do - before do - allow_any_instance_of(Runner).to receive(:deprecation_warning) - end - describe 'web server selection' do context 'when thin is specifed' do it 'chooses ThinRunner as the web server' do