Standardize keys dir

We use new path in granular task for keys to
standardize also old keys generators should use
new path also.

* remove duplicated config value
* use new paths in generators and uploaders
* correct tests

implements blueprint granular-deployment-based-on-tasks

Change-Id: I83ae8966c8b933b9f590871cd456beff517df706
This commit is contained in:
Kamil Sambor 2015-02-13 12:38:51 +01:00
parent 1be5b9b827
commit 81e7ca7472
10 changed files with 36 additions and 36 deletions

View File

@ -66,8 +66,7 @@ module Astute
conf[:dump_timeout] = 3600 # maximum time it waits for the dump (meaningles to be larger
# than the specified in timeout of execute_shell_command mcagent
conf[:puppet_ssh_keys_dir] = '/var/lib/astute' # folder where ssh keys will be saved. Warning!
# Do not change this at least your clear know what you do!
conf[:keys_src_dir] = '/var/lib/fuel/keys' # path where ssh and openssl keys will be created
conf[:puppet_ssh_keys] = [
'neutron',
'nova',
@ -77,8 +76,7 @@ module Astute
conf[:puppet_keys] = [
'mongodb'
] # name of keys what will be generated and uploaded to all nodes before deploy
conf[:puppet_keys_dir] = '/var/lib/astute' # folder where ssh keys will be saved. Warning!
# Do not change this at least your clear know what you do!
conf[:keys_dst_dir] = '/var/lib/astute' # folder where keys will be uploaded. Warning!
conf[:max_nodes_per_call] = 50 # how many nodes to deploy in one puppet call
conf[:ssh_retries] = 5 # SSH tries to call ssh client before failure
conf[:ssh_retry_timeout] = 30 # SSH sleeps for ## sec between retries

View File

@ -25,7 +25,7 @@ module Astute
raise "Deployment_id is missing" unless deployment_id
Astute.config.puppet_keys.each do |key_name|
dir_path = File.join(Astute.config.puppet_keys_dir, deployment_id.to_s, key_name)
dir_path = File.join(Astute.config.keys_src_dir, deployment_id.to_s, key_name)
key_path = File.join(dir_path, key_name + '.key')
FileUtils.mkdir_p dir_path

View File

@ -25,7 +25,7 @@ module Astute
raise "Deployment_id is missing" unless deployment_id
Astute.config.puppet_ssh_keys.each do |key_name|
dir_path = File.join(Astute.config.puppet_ssh_keys_dir, deployment_id.to_s, key_name)
dir_path = File.join(Astute.config.keys_src_dir, deployment_id.to_s, key_name)
key_path = File.join(dir_path, key_name)
FileUtils.mkdir_p dir_path

View File

@ -31,13 +31,13 @@ module Astute
upload_mclient = MClient.new(context, "uploadfile", node_uids)
key = key_name + '.key'
source_path = File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_src_dir,
deployment_id,
key_name,
key
)
destination_path = File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_dst_dir,
key_name,
key
)

View File

@ -30,15 +30,17 @@ module Astute
Astute.config.puppet_ssh_keys.each do |key_name|
upload_mclient = MClient.new(context, "uploadfile", node_uids)
[key_name, key_name + ".pub"].each do |ssh_key|
source_path = File.join(
Astute.config.puppet_ssh_keys_dir,
deployment_id,
key_name,
ssh_key)
destination_path = File.join(
Astute.config.puppet_ssh_keys_dir,
key_name,
ssh_key)
source_path = File.join(
Astute.config.keys_src_dir,
deployment_id,
key_name,
ssh_key
)
destination_path = File.join(
Astute.config.keys_dst_dir,
key_name,
ssh_key
)
content = File.read(source_path)
upload_mclient.upload(:path => destination_path,
:content => content,

View File

@ -31,10 +31,10 @@ describe Astute::GenerateKeys do
let(:generate_keys) { Astute::GenerateKeys.new }
around(:each) do |example|
old_keys_dir = Astute.config.puppet_keys_dir
old_keys_dir = Astute.config.keys_src_dir
old_puppet_keys = Astute.config.puppet_keys
example.run
Astute.config.puppet_keys_dir = old_keys_dir
Astute.config.keys_src_dir = old_keys_dir
Astute.config.puppet_keys = old_puppet_keys
end
@ -48,7 +48,7 @@ describe Astute::GenerateKeys do
generate_keys.stubs(:run_system_command).returns([0, "", ""])
Dir.mktmpdir do |temp_dir|
Astute.config.puppet_keys_dir = temp_dir
Astute.config.keys_src_dir = temp_dir
generate_keys.process(deploy_data, ctx)
expect { File.directory? File.join(temp_dir, 'mongodb.key') }.to be_true
@ -86,7 +86,7 @@ describe Astute::GenerateKeys do
File.stubs(:directory?).returns(true)
key_path = File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_src_dir,
deploy_data.first['deployment_id'].to_s,
'mongodb',
'mongodb.key'
@ -99,7 +99,7 @@ describe Astute::GenerateKeys do
it 'should not overwrite files' do
Dir.mktmpdir do |temp_dir|
Astute.config.puppet_keys_dir = temp_dir
Astute.config.keys_src_dir = temp_dir
key_path = File.join(temp_dir,'mongodb', 'mongodb.key')
FileUtils.mkdir_p File.join(temp_dir, 'mongodb')
File.open(key_path, 'w') { |file| file.write("say no overwrite") }
@ -113,13 +113,13 @@ describe Astute::GenerateKeys do
it 'should check next key if find existing' do
Astute.config.puppet_keys = ['mongodb', 'test']
mongodb_key_path = File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_src_dir,
deploy_data.first['deployment_id'].to_s,
'mongodb',
'mongodb.key'
)
test_key_path = File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_src_dir,
deploy_data.first['deployment_id'].to_s,
'test',
'test.key'

View File

@ -19,9 +19,9 @@ describe Astute::GenerateSshKeys do
around(:each) do |example|
old_puppet_ssh_keys = Astute.config.puppet_keys
old_ssh_keys_dir = Astute.config.puppet_ssh_keys_dir
old_ssh_keys_dir = Astute.config.keys_src_dir
example.run
Astute.config.puppet_ssh_keys_dir = old_ssh_keys_dir
Astute.config.keys_src_dir = old_ssh_keys_dir
Astute.config.puppet_keys = old_puppet_ssh_keys
end
@ -48,7 +48,7 @@ describe Astute::GenerateSshKeys do
generate_ssh_keys.stubs(:run_system_command).returns([0, "", ""])
Dir.mktmpdir do |temp_dir|
Astute.config.puppet_ssh_keys_dir = temp_dir
Astute.config.keys_src_dir = temp_dir
generate_ssh_keys.process(deploy_data, ctx)
expect { File.directory? File.join(temp_dir, 'nova') }.to be_true
@ -85,7 +85,7 @@ describe Astute::GenerateSshKeys do
FileUtils.stubs(:mkdir_p).returns(true)
File.stubs(:directory?).returns(true)
key_path = File.join(Astute.config.puppet_ssh_keys_dir, deploy_data.first['deployment_id'].to_s, 'nova', 'nova')
key_path = File.join(Astute.config.keys_src_dir, deploy_data.first['deployment_id'].to_s, 'nova', 'nova')
cmd = "ssh-keygen -b 2048 -t rsa -N '' -f #{key_path} 2>&1"
generate_ssh_keys.expects(:run_system_command).with(cmd).returns([0, "", ""])
@ -94,7 +94,7 @@ describe Astute::GenerateSshKeys do
it 'should not overwrite files' do
Dir.mktmpdir do |temp_dir|
Astute.config.puppet_ssh_keys_dir = temp_dir
Astute.config.keys_src_dir = temp_dir
key_path = File.join(temp_dir,'nova', 'nova')
FileUtils.mkdir_p File.join(temp_dir,'nova')
File.open(key_path, 'w') { |file| file.write("say no overwrite") }
@ -107,8 +107,8 @@ describe Astute::GenerateSshKeys do
it 'should check next key if find existing' do
Astute.config.puppet_ssh_keys = ['nova', 'test']
nova_key_path = File.join(Astute.config.puppet_ssh_keys_dir, deploy_data.first['deployment_id'].to_s, 'nova', 'nova')
test_key_path = File.join(Astute.config.puppet_ssh_keys_dir, deploy_data.first['deployment_id'].to_s, 'test', 'test')
nova_key_path = File.join(Astute.config.keys_src_dir, deploy_data.first['deployment_id'].to_s, 'nova', 'nova')
test_key_path = File.join(Astute.config.keys_src_dir, deploy_data.first['deployment_id'].to_s, 'test', 'test')
FileUtils.stubs(:mkdir_p).returns(true).twice
File.stubs(:directory?).returns(true).twice

View File

@ -52,9 +52,9 @@ describe Astute::UpdateRepoSources do
let(:update_repo_sources) { Astute::UpdateRepoSources.new }
around(:each) do |example|
old_ssh_keys_dir = Astute.config.puppet_ssh_keys_dir
old_ssh_keys_dir = Astute.config.keys_src_dir
example.run
Astute.config.puppet_ssh_keys_dir = old_ssh_keys_dir
Astute.config.keys_src_dir = old_ssh_keys_dir
end
context 'source configuration generation' do

View File

@ -45,7 +45,7 @@ describe Astute::UploadKeys do
File.stubs(:read).returns("private key").once
mclient.expects(:upload).with(
:path => File.join(
Astute.config.puppet_keys_dir,
Astute.config.keys_dst_dir,
'mongodb',
'mongodb.key'
),

View File

@ -43,7 +43,7 @@ describe Astute::UploadSshKeys do
Astute::MClient.any_instance.stubs(:check_results_with_retries).returns(mclient)
File.stubs(:read).returns("private key").then.returns("public key")
mclient.expects(:upload).with(:path => File.join(Astute.config.puppet_ssh_keys_dir, 'nova', 'nova'),
mclient.expects(:upload).with(:path => File.join(Astute.config.keys_dst_dir, 'nova', 'nova'),
:content => "private key",
:user_owner => 'root',
:group_owner => 'root',
@ -52,7 +52,7 @@ describe Astute::UploadSshKeys do
:overwrite => true,
:parents => true
)
mclient.expects(:upload).with(:path => File.join(Astute.config.puppet_ssh_keys_dir, 'nova', 'nova.pub'),
mclient.expects(:upload).with(:path => File.join(Astute.config.keys_dst_dir, 'nova', 'nova.pub'),
:content => "public key",
:user_owner => 'root',
:group_owner => 'root',