stub logger in various places

This commit is contained in:
Anton Chuchkalov 2016-01-21 20:46:15 +03:00
parent b680b5cfa5
commit f016727f37
11 changed files with 17 additions and 43 deletions

View File

@ -9,7 +9,7 @@ module Validators
def validate!
raise InvalidRecord.new(message) unless valid?
rescue StandardError => e
puts [e.message, e.backtrace].join("\n")
DevopsLogger.logger.error [e.message, e.backtrace].join("\n")
raise InvalidRecord.new("An error raised during validation with #{self.class}: #{e.class}: #{e.message}")
end

View File

@ -300,6 +300,7 @@ module Devops
knife_instance.chef_node_list.include?(@server.chef_node_name) and knife_instance.chef_client_list.include?(@server.chef_node_name)
end
# returns a hash with :chef_node, :chef_client and :server keys
def unbootstrap
k = Devops::Db.connector.key(@server.key)
cert_path = k.path

View File

@ -412,45 +412,18 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(executor).to receive(:execute_system_command) { '' }
allow(executor).to receive(:last_command_successful?) { true }
allow(executor).to receive(:sleep)
allow(Net::SSH).to receive(:start)
end
it 'deletes node from chef server' do
allow(executor).to receive(:delete_from_chef_server).and_call_original
expect(executor).to receive(:delete_from_chef_server)
it 'connects by ssh' do
expect(Net::SSH).to receive(:start)
executor.unbootstrap
end
it "uses server's key" do
expect(executor).to receive(:execute_system_command).with(%r(ssh -i path_to_key))
executor.unbootstrap
end
it 'backups /etc/chef' do
expect(executor).to receive(:execute_system_command).with(%r(mv /etc/chef ))
executor.unbootstrap
end
it 'returns a hash with :chef_node, :chef_client and :server keys' do
expect(executor.unbootstrap).to be_a(Hash).and include(:chef_node, :chef_client, :server)
end
it "writes successful message into result's :server key" do
expect(executor.unbootstrap[:server]).to include('renamed')
end
context "when command returned 'not found'" do
it "writes error message into result's :server key" do
allow(executor).to receive(:execute_system_command) { 'not found' }
expect(executor.unbootstrap[:server]).to eq("Directory '/etc/chef' does not exists")
end
end
context "if command wasn't successful" do
it 'returns hash with error after 5.retries' do
allow(executor).to receive(:last_command_successful?) { false }
expect(executor).to receive(:sleep).with(1).exactly(5).times
expect(executor.unbootstrap).to be_a(Hash).and include(:error)
end
it 'returns hash with error after 5 unsuccessful retries' do
allow(Net::SSH).to receive(:start) { raise }
expect(Net::SSH).to receive(:start).exactly(5).times
expect(executor.unbootstrap).to be_a(Hash).and include(:error)
end
end

View File

@ -5,7 +5,7 @@ require_relative 'shared_cloud_deploy_env_specs'
RSpec.describe Devops::Model::DeployEnvEc2, type: :model do
let(:env) { build(:deploy_env_ec2) }
describe 'it inherits from cloud deploy_env', stubbed_connector: true do
describe 'it inherits from cloud deploy_env', stubbed_connector: true, stubbed_logger: true do
before do
provider_double = instance_double('Provider::Ec2',
flavors: [{'id' => 'flavor'}],

View File

@ -5,7 +5,7 @@ require_relative 'shared_cloud_deploy_env_specs'
RSpec.describe Devops::Model::DeployEnvOpenstack, type: :model do
let(:env) { build(:deploy_env_openstack) }
describe 'it inherits from cloud deploy_env', stubbed_connector: true do
describe 'it inherits from cloud deploy_env', stubbed_connector: true, stubbed_logger: true do
before do
provider_double = instance_double('Provider::Openstack',
flavors: [{'id' => 'flavor'}],

View File

@ -14,7 +14,7 @@ RSpec.describe Devops::Model::Image, type: :model do
expect(image).to be_valid
end
describe 'validation' do
describe 'validation', stubbed_logger: true do
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator

View File

@ -7,7 +7,7 @@ RSpec.describe Devops::Model::Key, type: :model do
expect(key).to be_valid
end
describe 'validations' do
describe 'validations', stubbed_logger: true do
it 'key file should exist in file system' do
expect(build(:key, path: './not_exist')).not_to be_valid
end

View File

@ -3,7 +3,7 @@ require 'db/mongo/models/project'
RSpec.describe Devops::Model::Project, type: :model do
let(:project) { build(:project) }
describe 'validation rules:', stubbed_connector: true do
describe 'validation rules:', stubbed_connector: true, stubbed_logger: true do
before do
provider_double = instance_double('Provider::Ec2',
flavors: [{'id' => 'flavor'}],

View File

@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Devops::Model::OpenstackProviderAccount, type: :model do
let(:provider_account) { build(:openstack_provider_account) }
it "should not validate access_key_id" do
it "should not validate access_key_id", stubbed_logger: true do
fields = described_class.field_validators.values.flatten.flatten.map{|t| t[:field]}
expect(fields).not_to include(:access_key_id, :secret_access_key)
end

View File

@ -11,7 +11,7 @@ RSpec.describe Devops::Model::Server, type: :model do
expect(server).to be_valid
end
describe 'validation rules:' do
describe 'validation rules:', stubbed_logger: true do
include_examples 'field type validation', :id, :not_nil, :non_empty_string
include_examples 'field type validation', :provider, :not_nil, :non_empty_string
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string

View File

@ -11,7 +11,7 @@ RSpec.describe Devops::Model::StackEc2, type: :model do
expect(build(:stack_ec2)).to be_valid
end
describe 'validation rules:' do
describe 'validation rules:', stubbed_logger: true do
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :project, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :deploy_env, :not_nil, :non_empty_string, :field_validator