Skip to content

Commit 4d8694c

Browse files
committed
Use raw sql for stack check
1 parent f3834d2 commit 4d8694c

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

lib/cloud_controller/check_stacks.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ module VCAP::CloudController
22
class CheckStacks
33
attr_reader :config
44

5-
def initialize(config)
5+
def initialize(config, db)
66
@config = config
77
@stack_config = VCAP::CloudController::Stack::ConfigFile.new(config.get(:stacks_file))
8+
@db = db
89
end
910

1011
def validate_stacks
@@ -22,8 +23,10 @@ def validate_stack(deprecated_stack)
2223

2324
return if deprecated_stack_in_config
2425

25-
deprecated_stack_in_db = VCAP::CloudController::Stack.first(name: deprecated_stack).present?
26-
26+
deprecated_stack_in_db = false
27+
@db.fetch('SELECT * FROM stacks WHERE name LIKE ? ', deprecated_stack) do |_row|
28+
deprecated_stack_in_db = true
29+
end
2730
raise "rake task 'stack_check' failed, stack '#{deprecated_stack}' not supported" if deprecated_stack_in_db
2831
end
2932
end

lib/tasks/stack_check.rake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace :stacks do
77
next unless db.table_exists?(:buildpack_lifecycle_data)
88

99
RakeConfig.config.load_db_encryption_key
10-
require 'models/runtime/buildpack_lifecycle_data_model'
11-
require 'models/runtime/stack'
1210
require 'cloud_controller/check_stacks'
13-
VCAP::CloudController::CheckStacks.new(RakeConfig.config).validate_stacks
11+
VCAP::CloudController::CheckStacks.new(RakeConfig.config, db).validate_stacks
1412
end
1513
end

spec/tasks/stack_check_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
before do
5353
allow(db_double).to receive(:table_exists?).with(:stacks).and_return true
5454
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double)
55+
allow(db_double).to receive(:fetch).with('SELECT * FROM stacks WHERE name LIKE ? ', 'cflinuxfs3').and_return('1')
5556
end
5657

5758
it 'validates stacks' do
@@ -78,6 +79,7 @@
7879
before do
7980
allow(double).to receive(:table_exists?).with(:buildpack_lifecycle_data).and_return true
8081
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double)
82+
allow(db_double).to receive(:fetch).with('SELECT * FROM stacks WHERE name LIKE ? ', 'cflinuxfs3').and_return('1')
8183
end
8284

8385
it 'validates stacks' do

spec/unit/lib/cloud_controller/check_stacks_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module VCAP::CloudController
2828
TestConfig.override(stacks_file: file.path)
2929
end
3030

31-
let(:stack_checker) { CheckStacks.new(TestConfig.config_instance) }
31+
let(:stack_checker) { CheckStacks.new(TestConfig.config_instance, DbConfig.new.connection) }
3232

3333
describe 'the deprecated stacks is nil' do
3434
let(:stack_file_contents) do

0 commit comments

Comments
 (0)