From 90afd20c25b828c65fc06408dbe0c094312942e8 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 19 Oct 2017 14:56:31 -0400 Subject: [PATCH 1/4] extract manageiq-postgres_ha_admin --- .../pending/postgres_ha_admin/database_yml.rb | 59 ------ .../postgres_ha_admin/failover_databases.rb | 76 ------- .../postgres_ha_admin/failover_monitor.rb | 149 -------------- manageiq-gems-pending.gemspec | 2 - spec/postgres_ha_admin/database_yml_spec.rb | 59 ------ .../failover_databases_spec.rb | 130 ------------ .../failover_monitor_spec.rb | 191 ------------------ 7 files changed, 666 deletions(-) delete mode 100644 lib/gems/pending/postgres_ha_admin/database_yml.rb delete mode 100644 lib/gems/pending/postgres_ha_admin/failover_databases.rb delete mode 100644 lib/gems/pending/postgres_ha_admin/failover_monitor.rb delete mode 100644 spec/postgres_ha_admin/database_yml_spec.rb delete mode 100644 spec/postgres_ha_admin/failover_databases_spec.rb delete mode 100644 spec/postgres_ha_admin/failover_monitor_spec.rb diff --git a/lib/gems/pending/postgres_ha_admin/database_yml.rb b/lib/gems/pending/postgres_ha_admin/database_yml.rb deleted file mode 100644 index 2cb2bceb9..000000000 --- a/lib/gems/pending/postgres_ha_admin/database_yml.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'active_support/all' -require 'util/miq-password' -require 'fileutils' - -module PostgresHaAdmin - class DatabaseYml - attr_reader :db_yml_file, :environment - - def initialize(db_yml_file, environment) - @db_yml_file = db_yml_file - @environment = environment - end - - def pg_params_from_database_yml - rails_params_to_pg(YAML.load_file(db_yml_file)[environment]) - end - - def update_database_yml(params) - db_yml = YAML.load_file(db_yml_file) - db_yml[environment].merge!(pg_parameters_to_rails(params)) - remove_empty(db_yml[environment]) - - new_name = "#{db_yml_file}_#{Time.current.strftime("%d-%B-%Y_%H.%M.%S")}" - FileUtils.copy(db_yml_file, new_name) - begin - File.write(db_yml_file, db_yml.to_yaml) - rescue - FileUtils.mv(new_name, db_yml_file) - raise - end - new_name - end - - private - - def rails_params_to_pg(params) - pg_params = {} - pg_params[:dbname] = params['database'] - pg_params[:user] = params['username'] - pg_params[:port] = params['port'] - pg_params[:host] = params['host'] - pg_params[:password] = MiqPassword.try_decrypt(params['password']) - remove_empty(pg_params) - end - - def pg_parameters_to_rails(pg_params) - params = {} - params['username'] = pg_params[:user] - params['database'] = pg_params[:dbname] - params['port'] = pg_params[:port] - params['host'] = pg_params[:host] - remove_empty(params) - end - - def remove_empty(hash) - hash.delete_if { |_k, v| v.nil? || v.to_s.strip.empty? } - end - end -end diff --git a/lib/gems/pending/postgres_ha_admin/failover_databases.rb b/lib/gems/pending/postgres_ha_admin/failover_databases.rb deleted file mode 100644 index 5f6b0de6d..000000000 --- a/lib/gems/pending/postgres_ha_admin/failover_databases.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'active_support/all' -require 'pg' -require 'pg/dsn_parser' - -module PostgresHaAdmin - class FailoverDatabases - TABLE_NAME = "repl_nodes".freeze - - attr_reader :yml_file - - def initialize(yml_file, logger) - @yml_file = yml_file - @logger = logger - end - - def active_databases_conninfo_hash - valid_keys = PG::Connection.conndefaults_hash.keys + [:requiressl] - active_databases.map! do |db_info| - db_info.keep_if { |k, _v| valid_keys.include?(k) } - end - end - - def active_databases - all_databases.select { |record| record[:active] } - end - - def update_failover_yml(connection) - arr_yml = query_repmgr(connection) - File.write(yml_file, arr_yml.to_yaml) unless arr_yml.empty? - rescue IOError => err - @logger.error("#{err.class}: #{err}") - @logger.error(err.backtrace.join("\n")) - end - - def host_is_repmgr_primary?(host, connection) - query_repmgr(connection).each do |record| - if record[:host] == host && entry_is_active_master?(record) - return true - end - end - false - end - - private - - def query_repmgr(connection) - return [] unless table_exists?(connection, TABLE_NAME) - result = [] - db_result = connection.exec("SELECT type, conninfo, active FROM #{TABLE_NAME}") - db_result.map_types!(PG::BasicTypeMapForResults.new(connection)).each do |record| - dsn = PG::DSNParser.parse(record.delete("conninfo")) - result << record.symbolize_keys.merge(dsn) - end - db_result.clear - result - rescue PG::Error => err - @logger.error("#{err.class}: #{err}") - @logger.error(err.backtrace.join("\n")) - result - end - - def entry_is_active_master?(record) - record[:type] == 'master' && record[:active] - end - - def all_databases - return [] unless File.exist?(yml_file) - YAML.load_file(yml_file) - end - - def table_exists?(connection, table_name) - result = connection.exec("SELECT to_regclass('#{table_name}')").first - !result['to_regclass'].nil? - end - end -end diff --git a/lib/gems/pending/postgres_ha_admin/failover_monitor.rb b/lib/gems/pending/postgres_ha_admin/failover_monitor.rb deleted file mode 100644 index b8925613b..000000000 --- a/lib/gems/pending/postgres_ha_admin/failover_monitor.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'active_support/all' -require 'postgres_ha_admin/failover_databases' -require 'postgres_ha_admin/database_yml' -require 'pg' -require 'linux_admin' - -module PostgresHaAdmin - class FailoverMonitor - RAILS_ROOT = [ - Pathname.new("/var/www/miq/vmdb"), - Pathname.new(File.expand_path(File.join(__dir__, "../.."))) - ].detect { |f| File.exist?(f) } - FAILOVER_ATTEMPTS = 10 - DB_CHECK_FREQUENCY = 300 - FAILOVER_CHECK_FREQUENCY = 60 - LOG_FILE = '/var/www/miq/vmdb/log/ha_admin.log'.freeze - attr_accessor :failover_attempts, :db_check_frequency, :failover_check_frequency - - def initialize(db_yml_file: '/var/www/miq/vmdb/config/database.yml', - failover_yml_file: '/var/www/miq/vmdb/config/failover_databases.yml', - ha_admin_yml_file: '/var/www/miq/vmdb/config/ha_admin.yml', - logger: nil, - environment: 'production') - if logger.respond_to?(:error, :info) - @logger = logger - else - @logger = Logger.new(LOG_FILE) - @logger.level = Logger::INFO - end - @database_yml = DatabaseYml.new(db_yml_file, environment) - @failover_db = FailoverDatabases.new(failover_yml_file, @logger) - initialize_settings(ha_admin_yml_file) - end - - def monitor - connection = pg_connection(@database_yml.pg_params_from_database_yml) - if connection - @failover_db.update_failover_yml(connection) - connection.finish - return - end - - @logger.error("Primary Database is not available. EVM server stop initiated. Starting to execute failover...") - stop_evmserverd - - if execute_failover - start_evmserverd - raise_failover_event - else - @logger.error("Failover failed") - end - end - - def monitor_loop - loop do - begin - monitor - rescue => err - @logger.error("#{err.class}: #{err}") - @logger.error(err.backtrace.join("\n")) - end - sleep(db_check_frequency) - end - end - - def active_servers_conninfo - servers = @failover_db.active_databases_conninfo_hash - db_yml_params = @database_yml.pg_params_from_database_yml - servers.map! { |info| db_yml_params.merge(info) } - end - - def raise_failover_event - require "awesome_spawn" - AwesomeSpawn.run("rake evm:raise_server_event", - :chdir => RAILS_ROOT, - :params => ["--", {:event => "db_failover_executed"}]) - end - - private - - def initialize_settings(ha_admin_yml_file) - begin - ha_admin_yml = YAML.load_file(ha_admin_yml_file) - rescue SystemCallError, IOError => err - ha_admin_yml = {} - @logger.error("#{err.class}: #{err}") - @logger.info("File not loaded: #{ha_admin_yml_file}. Default settings for failover will be used.") - end - @failover_attempts = ha_admin_yml['failover_attempts'] || FAILOVER_ATTEMPTS - @db_check_frequency = ha_admin_yml['db_check_frequency'] || DB_CHECK_FREQUENCY - @failover_check_frequency = ha_admin_yml['failover_check_frequency'] || FAILOVER_CHECK_FREQUENCY - @logger.info("FAILOVER_ATTEMPTS=#{@failover_attempts} DB_CHECK_FREQUENCY=#{@db_check_frequency} FAILOVER_CHECK_FREQUENCY=#{@failover_check_frequency}") - end - - def execute_failover - failover_attempts.times do - with_each_standby_connection do |connection, params| - next if database_in_recovery?(connection) - next unless @failover_db.host_is_repmgr_primary?(params[:host], connection) - @logger.info("Failing over to server using conninfo: #{params.reject { |k, _v| k == :password }}") - @failover_db.update_failover_yml(connection) - @database_yml.update_database_yml(params) - return true - end - sleep(failover_check_frequency) - end - false - end - - def with_each_standby_connection - active_servers_conninfo.each do |params| - connection = pg_connection(params) - next if connection.nil? - begin - yield connection, params - ensure - connection.finish - end - end - end - - def pg_connection(params) - PG::Connection.open(params) - rescue PG::Error => e - @logger.error("Failed to establish PG connection: #{e.message}") - nil - end - - def start_evmserverd - LinuxAdmin::Service.new("evmserverd").restart - @logger.info("Starting EVM server from failover monitor") - end - - def stop_evmserverd - LinuxAdmin::Service.new("evmserverd").stop - end - - # Checks if postgres database is in recovery mode - # - # @param pg_connection [PG::Connection] established pg connection - # @return [Boolean] true if database in recovery mode - def database_in_recovery?(pg_connection) - pg_connection.exec("SELECT pg_catalog.pg_is_in_recovery()") do |db_result| - result = db_result.map_types!(PG::BasicTypeMapForResults.new(pg_connection)).first - result['pg_is_in_recovery'] - end - end - end -end diff --git a/manageiq-gems-pending.gemspec b/manageiq-gems-pending.gemspec index 32dccb1af..01ab58a73 100644 --- a/manageiq-gems-pending.gemspec +++ b/manageiq-gems-pending.gemspec @@ -31,8 +31,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency "net-scp", "~> 1.2.1" s.add_runtime_dependency "net-sftp", "~> 2.1.2" s.add_runtime_dependency "nokogiri", "~> 1.8.1" - s.add_runtime_dependency "pg", "~> 0.18.2" - s.add_runtime_dependency "pg-dsn_parser", "~> 0.1.0" s.add_runtime_dependency "rake", ">= 11.0" s.add_runtime_dependency "sys-proctable", "~> 1.1.5" s.add_runtime_dependency "sys-uname", "~> 1.0.1" diff --git a/spec/postgres_ha_admin/database_yml_spec.rb b/spec/postgres_ha_admin/database_yml_spec.rb deleted file mode 100644 index 99e81d04e..000000000 --- a/spec/postgres_ha_admin/database_yml_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -require 'postgres_ha_admin/database_yml' - -describe PostgresHaAdmin::DatabaseYml do - let(:yml_utils) { described_class.new(@yml_file.path, 'test') } - - before do - @yml_file = Tempfile.new('database.yml') - yml_data = YAML.load(<<-DOC) ---- -base: &base - username: user - wait_timeout: 5 - port: -test: &test - <<: *base - pool: 3 - database: vmdb_test -DOC - File.write(@yml_file.path, yml_data.to_yaml) - end - - after do - @yml_file.close(true) - end - - describe "#pg_params_from_database_yml" do - it "returns pg connection parameters based on 'database.yml'" do - params = yml_utils.pg_params_from_database_yml - expect(params).to eq(:dbname => 'vmdb_test', :user => 'user') - end - end - - describe "#update_database_yml" do - it "back-up existing 'database.yml'" do - original_yml = YAML.load_file(@yml_file) - - new_name = yml_utils.update_database_yml(:any => 'any') - - expect(new_name.size).to be > @yml_file.path.size - expect(YAML.load_file(new_name)).to eq original_yml - end - - it "expect raise error and keep original 'database.yml' if updating database.yml failed" do - original_yml = YAML.load_file(@yml_file) - allow(File).to receive(:write).and_raise(StandardError) - - expect { yml_utils.update_database_yml(:any => 'any') }.to raise_error(StandardError) - expect(YAML.load_file(@yml_file)).to eq original_yml - end - - it "takes hash with 'pg style' parameters and override database.yml" do - yml_utils.update_database_yml(:dbname => 'some_db', :host => "localhost", :port => '') - yml = YAML.load_file(@yml_file) - - expect(yml['test']).to eq('database' => 'some_db', 'host' => 'localhost', - 'username' => 'user', 'pool' => 3, 'wait_timeout' => 5) - end - end -end diff --git a/spec/postgres_ha_admin/failover_databases_spec.rb b/spec/postgres_ha_admin/failover_databases_spec.rb deleted file mode 100644 index 064b96e3d..000000000 --- a/spec/postgres_ha_admin/failover_databases_spec.rb +++ /dev/null @@ -1,130 +0,0 @@ -require 'postgres_ha_admin/failover_databases' -require 'pg' - -describe PostgresHaAdmin::FailoverDatabases do - let(:logger) { Logger.new(@logger_file) } - let(:failover_databases) { described_class.new(@yml_file.path, logger) } - - before do - @yml_file = Tempfile.new('failover_databases.yml') - @logger_file = Tempfile.new('ha_admin.log') - end - - after do - @yml_file.close(true) - @logger_file.close(true) - end - - describe "#active_databases_conninfo_hash" do - it "returns a list of active databases connection info" do - expected = [ - {:host => '203.0.113.1', :user => 'root', :dbname => 'vmdb_test'}, - {:host => '203.0.113.2', :user => 'root', :dbname => 'vmdb_test'} - ] - File.write(@yml_file, initial_db_list.to_yaml) - expect(failover_databases.active_databases_conninfo_hash).to contain_exactly(*expected) - end - end - - describe "#active_databases" do - it "return list of active databases saved in 'config/failover_databases.yml'" do - File.write(@yml_file, initial_db_list.to_yaml) - expect(failover_databases.active_databases).to contain_exactly( - {:type => 'master', :active => true, :host => '203.0.113.1', :user => 'root', :dbname => 'vmdb_test'}, - {:type => 'standby', :active => true, :host => '203.0.113.2', :user => 'root', :dbname => 'vmdb_test'}) - end - end - - context "accessing database" do - after do - if @connection - @connection.exec("ROLLBACK") - @connection.finish - end - end - - before do - # @connection = PG::Connection.open(:dbname => 'vmdb_test') - begin - @connection = PG::Connection.open(:dbname => 'travis', :user => 'travis') - rescue PG::ConnectionBad - skip "travis database does not exist" - end - - @connection.exec("START TRANSACTION") - @connection.exec(<<-SQL) - CREATE TABLE #{described_class::TABLE_NAME} ( - type text NOT NULL, - conninfo text NOT NULL, - active boolean DEFAULT true NOT NULL - ) - SQL - - @connection.exec(<<-SQL) - INSERT INTO - #{described_class::TABLE_NAME}(type, conninfo, active) - VALUES - ('master', 'host=203.0.113.1 user=root dbname=vmdb_test', 'true'), - ('standby', 'host=203.0.113.2 user=root dbname=vmdb_test', 'true'), - ('standby', 'host=203.0.113.3 user=root dbname=vmdb_test', 'false'), - ('master', 'host=203.0.113.5 user=root dbname=vmdb_test', 'false') - SQL - end - - describe "#update_failover_yml" do - it "updates 'failover_databases.yml'" do - failover_databases.update_failover_yml(@connection) - - yml_hash = YAML.load_file(@yml_file) - expect(yml_hash).to eq initial_db_list - - add_new_record - - failover_databases.update_failover_yml(@connection) - yml_hash = YAML.load_file(@yml_file) - expect(yml_hash).to eq new_db_list - end - end - - describe "#host_is_repmgr_primary?" do - it "return true if supplied connection established with primary database" do - expect(failover_databases.host_is_repmgr_primary?('203.0.113.1', @connection)).to be true - end - - it "return false if supplied connection established with not active standby database" do - expect(failover_databases.host_is_repmgr_primary?('203.0.113.3', @connection)).to be false - end - - it "return false if supplied connection established with active standby database" do - expect(failover_databases.host_is_repmgr_primary?('203.0.113.2', @connection)).to be false - end - - it "return false if supplied connection established with not active master database" do - expect(failover_databases.host_is_repmgr_primary?('203.0.113.5', @connection)).to be false - end - end - end - - def initial_db_list - arr = [] - arr << {:type => 'master', :active => true, :host => '203.0.113.1', :user => 'root', :dbname => 'vmdb_test'} - arr << {:type => 'standby', :active => true, :host => '203.0.113.2', :user => 'root', :dbname => 'vmdb_test'} - arr << {:type => 'standby', :active => false, :host => '203.0.113.3', :user => 'root', :dbname => 'vmdb_test'} - arr << {:type => 'master', :active => false, :host => '203.0.113.5', :user => 'root', :dbname => 'vmdb_test'} - arr - end - - def new_db_list - initial_db_list << {:type => 'standby', :active => true, :host => '203.0.113.4', - :user => 'root', :dbname => 'some_db'} - end - - def add_new_record - @connection.exec(<<-SQL) - INSERT INTO - #{described_class::TABLE_NAME}(type, conninfo, active) - VALUES - ('standby', 'host=203.0.113.4 user=root dbname=some_db', 'true') - SQL - end -end diff --git a/spec/postgres_ha_admin/failover_monitor_spec.rb b/spec/postgres_ha_admin/failover_monitor_spec.rb deleted file mode 100644 index b057bbb35..000000000 --- a/spec/postgres_ha_admin/failover_monitor_spec.rb +++ /dev/null @@ -1,191 +0,0 @@ -require 'postgres_ha_admin/failover_monitor' -require 'util/postgres_admin' - -describe PostgresHaAdmin::FailoverMonitor do - let(:db_yml) { double('DatabaseYml') } - let(:failover_db) { double('FailoverDatabases') } - - let(:connection) do - conn = double("PGConnection") - allow(conn).to receive(:finish) - conn - end - let(:logger) do - logger = double('Logger') - allow(logger).to receive_messages(:error => 'any', :info => 'any') - logger - end - let(:failover_monitor) do - expect(PostgresHaAdmin::DatabaseYml).to receive(:new).and_return(db_yml) - expect(PostgresHaAdmin::FailoverDatabases).to receive(:new).and_return(failover_db) - failover_instance = described_class.new(:logger => logger) - failover_instance - end - let(:linux_admin) do - linux_adm = double('LinuxAdmin') - allow(LinuxAdmin::Service).to receive(:new).and_return(linux_adm) - linux_adm - end - - describe "#initialize" do - it "override default failover settings with settings loaded from 'ha_admin.yml'" do - ha_admin_yml_file = Tempfile.new('ha_admin.yml') - yml_data = YAML.load(<<-DOC) ---- -failover_attempts: 20 - DOC - - File.write(ha_admin_yml_file.path, yml_data.to_yaml) - monitor_with_settings = described_class.new(:ha_admin_yml_file => ha_admin_yml_file.path, - :logger => logger) - ha_admin_yml_file.close(true) - - expect(described_class::FAILOVER_ATTEMPTS).not_to eq 20 - expect(monitor_with_settings.failover_attempts).to eq 20 - expect(monitor_with_settings.db_check_frequency).to eq described_class::DB_CHECK_FREQUENCY - end - - it "uses default failover settings if 'ha_admin.yml' not found" do - expect(failover_monitor.failover_attempts).to eq described_class::FAILOVER_ATTEMPTS - expect(failover_monitor.db_check_frequency).to eq described_class::DB_CHECK_FREQUENCY - expect(failover_monitor.failover_check_frequency).to eq described_class::FAILOVER_CHECK_FREQUENCY - end - end - - describe "#monitor" do - before do - params = { - :host => 'host.example.com', - :user => 'root', - :password => 'password' - } - allow(db_yml).to receive(:pg_params_from_database_yml).and_return(params) - end - - context "primary database is accessable" do - before do - allow(PG::Connection).to receive(:open).and_return(connection) - end - - it "updates 'failover_databases.yml'" do - expect(failover_db).to receive(:update_failover_yml) - failover_monitor.monitor - end - - it "does not stop evm server and does not execute failover" do - expect(failover_db).to receive(:update_failover_yml) - expect(linux_admin).not_to receive(:stop) - expect(linux_admin).not_to receive(:restart) - expect(failover_monitor).not_to receive(:execute_failover) - - failover_monitor.monitor - end - end - - context "primary database is not accessable" do - before do - allow(PG::Connection).to receive(:open).and_return(nil, connection, connection) - stub_monitor_constants - end - - it "stop evm server(if it is running) before failover attempt" do - expect(linux_admin).to receive(:stop).ordered - expect(failover_monitor).to receive(:execute_failover).ordered - failover_monitor.monitor - end - - it "does not update 'database.yml' and 'failover_databases.yml' if all standby DBs are in recovery mode" do - failover_not_executed - expect(failover_monitor).to receive(:database_in_recovery?).and_return(true, true, true).ordered - failover_monitor.monitor - end - - it "does not update 'database.yml' and 'failover_databases.yml' if there is no master database avaiable" do - failover_not_executed - expect(failover_monitor).to receive(:database_in_recovery?).and_return(false, false, false).ordered - expect(failover_db).to receive(:host_is_repmgr_primary?).and_return(false, false, false).ordered - failover_monitor.monitor - end - - it "updates 'database.yml' and 'failover_databases.yml' and restart evm server if new primary db available" do - failover_executed - expect(failover_monitor).to receive(:raise_failover_event) - expect(failover_monitor).to receive(:database_in_recovery?).and_return(false) - expect(failover_db).to receive(:host_is_repmgr_primary?).and_return(true) - failover_monitor.monitor - end - end - end - - describe "#active_servers_conninfo" do - it "merges settings from database yml and failover yml" do - active_servers_conninfo = [ - {:host => 'failover_host.example.com'}, - {:host => 'failover_host2.example.com'} - ] - expected_conninfo = [ - {:host => 'failover_host.example.com', :password => 'mypassword'}, - {:host => 'failover_host2.example.com', :password => 'mypassword'} - ] - settings_from_db_yml = {:host => 'host.example.com', :password => 'mypassword'} - expect(failover_db).to receive(:active_databases_conninfo_hash).and_return(active_servers_conninfo) - expect(db_yml).to receive(:pg_params_from_database_yml).and_return(settings_from_db_yml) - expect(failover_monitor.active_servers_conninfo).to match_array(expected_conninfo) - end - end - - describe "#raise_failover_event" do - it "invoke 'evm:raise_server_event' rake task" do - expect(AwesomeSpawn).to receive(:run).with( - "rake evm:raise_server_event", - :chdir => described_class::RAILS_ROOT, - :params => ["--", {:event => "db_failover_executed"}]) - failover_monitor.raise_failover_event - end - end - - def failover_executed - expect(linux_admin).to receive(:stop) - expect(failover_db).to receive(:active_databases_conninfo_hash).and_return(active_databases_conninfo) - expect(failover_db).to receive(:update_failover_yml) - expect(db_yml).to receive(:update_database_yml) - expect(linux_admin).to receive(:restart) - end - - def failover_not_executed - expect(linux_admin).to receive(:stop) - expect(failover_db).to receive(:active_databases_conninfo_hash).and_return(active_databases_conninfo) - expect(failover_db).not_to receive(:update_failover_yml) - expect(db_yml).not_to receive(:update_database_yml) - expect(linux_admin).not_to receive(:restart) - end - - def stub_monitor_constants - stub_const("PostgresHaAdmin::FailoverMonitor::FAILOVER_ATTEMPTS", 1) - stub_const("PostgresHaAdmin::FailoverMonitor::FAILOVER_CHECK_FREQUENCY", 1) - end - - def active_databases_conninfo - [{}, {}, {}] - end - - context "private" do - describe "#database_in_recovery?" do - before do - begin - @connection = PG::Connection.open(:dbname => 'travis', :user => 'travis') - rescue PG::ConnectionBad - skip "travis database does not exist" - end - end - - after do - @connection.finish if @connection - end - - it "returns false if postgres database not in recovery mode" do - expect(described_class.send(:database_in_recovery?, @connection)).to be false - end - end - end -end From 78a35b5a6c5e91545cd3928d6448a041414c67ff Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 19 Oct 2017 17:27:36 -0400 Subject: [PATCH 2/4] PostgresAdmin no longer uses 'pg' gem --- spec/util/postgres_admin_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/util/postgres_admin_spec.rb b/spec/util/postgres_admin_spec.rb index 4b9839bea..b4650a522 100644 --- a/spec/util/postgres_admin_spec.rb +++ b/spec/util/postgres_admin_spec.rb @@ -1,5 +1,4 @@ require "util/postgres_admin" -require 'pg' describe PostgresAdmin do context "ENV dependent" do From 8259431d6c912f828ea400409be8bde6d7f39988 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 19 Oct 2017 17:28:05 -0400 Subject: [PATCH 3/4] load the file in lib/ --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8b965d68d..3020bbe75 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ SimpleCov.start { command_name "spec" } $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) -require 'manageiq/gems/pending' +require 'manageiq-gems-pending' # Initialize the global logger that might be expected require 'logger' From c42f507a9eaa423f8435e00b5798778c4d14dd2f Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 19 Oct 2017 17:30:43 -0400 Subject: [PATCH 4/4] reintroduce "require 'active_support/all'" --- spec/spec_helper.rb | 3 +++ spec/util/extensions/miq-to_i_with_method_spec.rb | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3020bbe75..e7bb459ef 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,9 @@ # in ./support/ and its subdirectories. Dir[File.expand_path(File.join(__dir__, 'support/**/*.rb'))].each { |f| require f } +# A bunch of tests rely on ActiveSupport helper methods +require 'active_support/all' + RSpec.configure do |config| config.after(:each) do Module.clear_all_cache_with_timeout if Module.respond_to?(:clear_all_cache_with_timeout) diff --git a/spec/util/extensions/miq-to_i_with_method_spec.rb b/spec/util/extensions/miq-to_i_with_method_spec.rb index 226630f6d..75a9d10af 100644 --- a/spec/util/extensions/miq-to_i_with_method_spec.rb +++ b/spec/util/extensions/miq-to_i_with_method_spec.rb @@ -1,5 +1,4 @@ require 'util/extensions/miq-to_i_with_method' -require 'active_support/core_ext/numeric' describe "to_i_with_method" do it 'String#to_i_with_method' do