stub logger in various places
This commit is contained in:
parent
b680b5cfa5
commit
f016727f37
@ -9,7 +9,7 @@ module Validators
|
|||||||
def validate!
|
def validate!
|
||||||
raise InvalidRecord.new(message) unless valid?
|
raise InvalidRecord.new(message) unless valid?
|
||||||
rescue StandardError => e
|
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}")
|
raise InvalidRecord.new("An error raised during validation with #{self.class}: #{e.class}: #{e.message}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
knife_instance.chef_node_list.include?(@server.chef_node_name) and knife_instance.chef_client_list.include?(@server.chef_node_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# returns a hash with :chef_node, :chef_client and :server keys
|
||||||
def unbootstrap
|
def unbootstrap
|
||||||
k = Devops::Db.connector.key(@server.key)
|
k = Devops::Db.connector.key(@server.key)
|
||||||
cert_path = k.path
|
cert_path = k.path
|
||||||
|
|||||||
@ -412,45 +412,18 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
|
|||||||
allow(executor).to receive(:execute_system_command) { '' }
|
allow(executor).to receive(:execute_system_command) { '' }
|
||||||
allow(executor).to receive(:last_command_successful?) { true }
|
allow(executor).to receive(:last_command_successful?) { true }
|
||||||
allow(executor).to receive(:sleep)
|
allow(executor).to receive(:sleep)
|
||||||
|
allow(Net::SSH).to receive(:start)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes node from chef server' do
|
it 'connects by ssh' do
|
||||||
allow(executor).to receive(:delete_from_chef_server).and_call_original
|
expect(Net::SSH).to receive(:start)
|
||||||
expect(executor).to receive(:delete_from_chef_server)
|
|
||||||
executor.unbootstrap
|
executor.unbootstrap
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses server's key" do
|
it 'returns hash with error after 5 unsuccessful retries' do
|
||||||
expect(executor).to receive(:execute_system_command).with(%r(ssh -i path_to_key))
|
allow(Net::SSH).to receive(:start) { raise }
|
||||||
executor.unbootstrap
|
expect(Net::SSH).to receive(:start).exactly(5).times
|
||||||
end
|
expect(executor.unbootstrap).to be_a(Hash).and include(:error)
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require_relative 'shared_cloud_deploy_env_specs'
|
|||||||
RSpec.describe Devops::Model::DeployEnvEc2, type: :model do
|
RSpec.describe Devops::Model::DeployEnvEc2, type: :model do
|
||||||
let(:env) { build(:deploy_env_ec2) }
|
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
|
before do
|
||||||
provider_double = instance_double('Provider::Ec2',
|
provider_double = instance_double('Provider::Ec2',
|
||||||
flavors: [{'id' => 'flavor'}],
|
flavors: [{'id' => 'flavor'}],
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require_relative 'shared_cloud_deploy_env_specs'
|
|||||||
RSpec.describe Devops::Model::DeployEnvOpenstack, type: :model do
|
RSpec.describe Devops::Model::DeployEnvOpenstack, type: :model do
|
||||||
let(:env) { build(:deploy_env_openstack) }
|
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
|
before do
|
||||||
provider_double = instance_double('Provider::Openstack',
|
provider_double = instance_double('Provider::Openstack',
|
||||||
flavors: [{'id' => 'flavor'}],
|
flavors: [{'id' => 'flavor'}],
|
||||||
|
|||||||
@ -14,7 +14,7 @@ RSpec.describe Devops::Model::Image, type: :model do
|
|||||||
expect(image).to be_valid
|
expect(image).to be_valid
|
||||||
end
|
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', :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', :remote_user, :not_nil, :non_empty_string, :field_validator
|
||||||
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator
|
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator
|
||||||
|
|||||||
@ -7,7 +7,7 @@ RSpec.describe Devops::Model::Key, type: :model do
|
|||||||
expect(key).to be_valid
|
expect(key).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'validations', stubbed_logger: true do
|
||||||
it 'key file should exist in file system' do
|
it 'key file should exist in file system' do
|
||||||
expect(build(:key, path: './not_exist')).not_to be_valid
|
expect(build(:key, path: './not_exist')).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'db/mongo/models/project'
|
|||||||
RSpec.describe Devops::Model::Project, type: :model do
|
RSpec.describe Devops::Model::Project, type: :model do
|
||||||
let(:project) { build(:project) }
|
let(:project) { build(:project) }
|
||||||
|
|
||||||
describe 'validation rules:', stubbed_connector: true do
|
describe 'validation rules:', stubbed_connector: true, stubbed_logger: true do
|
||||||
before do
|
before do
|
||||||
provider_double = instance_double('Provider::Ec2',
|
provider_double = instance_double('Provider::Ec2',
|
||||||
flavors: [{'id' => 'flavor'}],
|
flavors: [{'id' => 'flavor'}],
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||||||
RSpec.describe Devops::Model::OpenstackProviderAccount, type: :model do
|
RSpec.describe Devops::Model::OpenstackProviderAccount, type: :model do
|
||||||
let(:provider_account) { build(:openstack_provider_account) }
|
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]}
|
fields = described_class.field_validators.values.flatten.flatten.map{|t| t[:field]}
|
||||||
expect(fields).not_to include(:access_key_id, :secret_access_key)
|
expect(fields).not_to include(:access_key_id, :secret_access_key)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,7 +11,7 @@ RSpec.describe Devops::Model::Server, type: :model do
|
|||||||
expect(server).to be_valid
|
expect(server).to be_valid
|
||||||
end
|
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', :id, :not_nil, :non_empty_string
|
||||||
include_examples 'field type validation', :provider, :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
|
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string
|
||||||
|
|||||||
@ -11,7 +11,7 @@ RSpec.describe Devops::Model::StackEc2, type: :model do
|
|||||||
expect(build(:stack_ec2)).to be_valid
|
expect(build(:stack_ec2)).to be_valid
|
||||||
end
|
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', :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', :project, :not_nil, :non_empty_string, :field_validator
|
||||||
include_examples 'field type validation', :deploy_env, :not_nil, :non_empty_string, :field_validator
|
include_examples 'field type validation', :deploy_env, :not_nil, :non_empty_string, :field_validator
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user