
- changed the default RDBMS to MariaDB in accordance with install docs[0] - removed deprecated database, apt and yum cookbooks - incorporated `database' and MySQL-specific abstractions from database cookbook - implemented foodcritic and cookstyle corrections - deprecated node.foo.bar method access for node['foo']['bar'] bracket syntax - updated default recipe for core apt resource - use /etc/apt/apt.conf.d on Ubuntu instead of passing the dpkg overrides as command line options in every cookbook [0]: https://docs.openstack.org/install-guide/environment-sql-database.html Implements blueprint modern-chef Change-Id: I143e0ed0a2bdd76269fc0c402052696426d96d81 Depends-On: I00e2237cef0c9aa35f78d3ccec04a1c7b9271ce8 Depends-On: I7ee0f5eae4e79e5c70ee8de4a0094a7c34fdd18f
79 lines
2.9 KiB
Ruby
79 lines
2.9 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', socket: '/var/run/mysqld/mysqld.sock' },
|
|
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: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/var/run/mysqld/mysqld.sock' },
|
|
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: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/var/run/mysqld/mysqld.sock' },
|
|
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: 'localhost', port: 3306, username: 'root', password: 'root_pass', socket: '/var/run/mysqld/mysqld.sock' },
|
|
username: 'db_user',
|
|
password: 'db_pass',
|
|
database_name: 'service_db',
|
|
host: '%',
|
|
privileges: [:all]
|
|
)
|
|
end
|
|
|
|
context 'galera' do
|
|
before do
|
|
node.override['openstack']['db']['service'] = { service_type: 'galera', port: 3306, db_name: 'service_db' }
|
|
end
|
|
end
|
|
end
|