switched from db_create_with_user to lwrp openstack_common_database

- replaced db_create_with_user with lwrp from common
- utilized new common attribute openstack.common.services to
dry recipe
- TODO: create test for rescue log message

related-Change-Id: I1940cd63aa1ae95586e6ecbed9476f7ce5fe19ab

Change-Id: Idb47c9b7e3ce954ddd1a544b71b96eed734e46e5
This commit is contained in:
Jan Klare 2015-06-03 14:37:22 +02:00
parent 069d3c0d8b
commit 1886e38a03
2 changed files with 36 additions and 77 deletions

View File

@ -22,55 +22,14 @@ class ::Chef::Recipe # rubocop:disable Documentation
include ::Openstack include ::Openstack
end end
db_create_with_user( node['openstack']['common']['services'].each do |service, project|
'compute', begin
node['openstack']['db']['compute']['username'], password = get_password('db', project)
get_password('db', 'nova') openstack_common_database service do
) user node['openstack']['db'][service]['username']
pass password
db_create_with_user( end
'dashboard', rescue Net::HTTPServerException
node['openstack']['db']['dashboard']['username'], log "No databag item containing the database password for #{project} was found, so no database was created"
get_password('db', 'horizon') end
) end
db_create_with_user(
'identity',
node['openstack']['db']['identity']['username'],
get_password('db', 'keystone')
)
db_create_with_user(
'image',
node['openstack']['db']['image']['username'],
get_password('db', 'glance')
)
db_create_with_user(
'telemetry',
node['openstack']['db']['telemetry']['username'],
get_password('db', 'ceilometer')
)
db_create_with_user(
'network',
node['openstack']['db']['network']['username'],
get_password('db', 'neutron')
)
db_create_with_user(
'block-storage',
node['openstack']['db']['block-storage']['username'],
get_password('db', 'cinder')
)
db_create_with_user(
'orchestration',
node['openstack']['db']['orchestration']['username'],
get_password('db', 'heat')
)
db_create_with_user(
'bare-metal',
node['openstack']['db']['bare-metal']['username'],
get_password('db', 'ironic')
)

View File

@ -4,31 +4,31 @@ require_relative 'spec_helper'
describe 'openstack-ops-database::openstack-db' do describe 'openstack-ops-database::openstack-db' do
include_context 'database-stubs' include_context 'database-stubs'
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) }
before do it 'creates all openstack service databases and the corresponding users' do
@chef_run = ::ChefSpec::SoloRunner.new ::UBUNTU_OPTS {
end 'bare-metal' => 'ironic',
'block-storage' => 'cinder',
it 'creates databases and users' do 'compute' => 'nova',
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) 'dashboard' => 'horizon',
.with('compute', 'nova', 'test-pass') 'database' => 'trove',
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) 'identity' => 'keystone',
.with 'dashboard', 'horizon', 'test-pass' 'image' => 'glance',
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) 'network' => 'neutron',
.with 'identity', 'keystone', 'test-pass' 'object-storage' => 'swift',
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) 'orchestration' => 'heat',
.with 'image', 'glance', 'test-pass' 'telemetry' => 'ceilometer'
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) }.each do |service, _project|
.with 'telemetry', 'ceilometer', 'test-pass' expect(chef_run).to create_openstack_common_database(service)
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) .with(user: node['openstack']['db'][service]['username'],
.with 'network', 'neutron', 'test-pass' pass: 'test-pass')
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) end
.with 'block-storage', 'cinder', 'test-pass' ## TODO: utilize _project and create test for rescue with specific log message
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user) ## when databag does not exist
.with 'orchestration', 'heat', 'test-pass' end
expect_any_instance_of(Chef::Recipe).to receive(:db_create_with_user)
.with 'bare-metal', 'ironic', 'test-pass'
@chef_run.converge(described_recipe)
end end
end end