9a2c4ee365
- increments Ubuntu release to 16.04 - increments release to newton for Ubuntu and CentOS - increments apt cookbook version to 4.0 - increments mysql cookbook version to 7.2 Change-Id: I07ad79a93642d0f0c934a864fcb9bcd7b764e35f Implements: blueprint newton-xenial
118 lines
4.2 KiB
Ruby
118 lines
4.2 KiB
Ruby
# encoding: UTF-8
|
|
|
|
require_relative 'spec_helper'
|
|
|
|
describe 'test-openstack-common-database::default' do
|
|
let(:runner) do
|
|
ChefSpec::SoloRunner.new(platform: 'ubuntu',
|
|
version: '16.04',
|
|
log_level: :fatal,
|
|
step_into: ['openstack_common_database'])
|
|
end
|
|
let(:node) { runner.node }
|
|
let(:chef_run) do
|
|
node.set['openstack']['use_databags'] = false
|
|
node.set['openstack']['secret']['mysqlroot']['db'] = 'root_pass'
|
|
node.set['openstack']['db']['service'] = { service_type: 'mysql', port: 3306, db_name: 'service_db' }
|
|
runner.converge(described_recipe)
|
|
end
|
|
|
|
it 'uses the lwrp openstack_common_database' do
|
|
expect(chef_run).to create_openstack_common_database('service')
|
|
.with(user: 'db_user', pass: 'db_pass')
|
|
end
|
|
|
|
context 'specific root user db endpoint' do
|
|
before do
|
|
node.set['openstack']['endpoints']['db']['host_for_db_root_user'] = 'localhost123'
|
|
end
|
|
it 'connects to the database via a specific endpoint for the root user' do
|
|
expect(chef_run).to create_database('create database service_db')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::Mysql,
|
|
connection: { host: 'localhost123', port: 3306, username: 'root', password: 'root_pass' },
|
|
database_name: 'service_db',
|
|
encoding: 'utf8'
|
|
)
|
|
end
|
|
end
|
|
|
|
it 'creates the database with the database resource' do
|
|
expect(chef_run).to create_database('create database service_db')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::Mysql,
|
|
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
|
|
database_name: 'service_db',
|
|
encoding: 'utf8'
|
|
)
|
|
end
|
|
|
|
it 'creates the database use with the database_user resource' do
|
|
expect(chef_run).to create_database_user('create database user db_user')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::MysqlUser,
|
|
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
|
|
username: 'db_user',
|
|
password: 'db_pass'
|
|
)
|
|
end
|
|
|
|
it 'grants database privileges to the user with the database_user resource' do
|
|
expect(chef_run).to grant_database_user('grant database user db_user')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::MysqlUser,
|
|
connection: { host: '127.0.0.1', port: 3306, username: 'root', password: 'root_pass' },
|
|
username: 'db_user',
|
|
password: 'db_pass',
|
|
database_name: 'service_db',
|
|
host: '%',
|
|
privileges: [:all]
|
|
)
|
|
end
|
|
|
|
context 'postgresql' do
|
|
before do
|
|
node.override['openstack']['db']['service'] = { service_type: 'postgresql', port: 5432, db_name: 'service_postgres' }
|
|
end
|
|
|
|
it 'creates the database with the database resource' do
|
|
expect(chef_run).to create_database('create database service_postgres')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::Postgresql,
|
|
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
|
|
database_name: 'service_postgres',
|
|
encoding: 'DEFAULT'
|
|
)
|
|
end
|
|
|
|
it 'creates the database use with the database_user resource' do
|
|
expect(chef_run).to create_database_user('create database user db_user')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::PostgresqlUser,
|
|
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
|
|
username: 'db_user',
|
|
password: 'db_pass'
|
|
)
|
|
end
|
|
|
|
it 'grants database privileges to the user with the database_user resource' do
|
|
expect(chef_run).to grant_database_user('grant database user db_user')
|
|
.with(
|
|
provider: ::Chef::Provider::Database::PostgresqlUser,
|
|
connection: { host: '127.0.0.1', port: 5432, username: 'postgres', password: 'root_pass' },
|
|
username: 'db_user',
|
|
password: 'db_pass',
|
|
database_name: 'service_postgres',
|
|
host: '%',
|
|
privileges: [:all]
|
|
)
|
|
end
|
|
end
|
|
|
|
context 'galera' do
|
|
before do
|
|
node.override['openstack']['db']['service'] = { service_type: 'galera', port: 3306, db_name: 'service_db' }
|
|
end
|
|
end
|
|
end
|