Skip to content

Commit

Permalink
Use dbhost attribute for the local database connections
Browse files Browse the repository at this point in the history
  • Loading branch information
zuazo committed Sep 21, 2015
1 parent 44de096 commit 3269e9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
mysql_service dbinstance do
data_dir node['owncloud']['mysql']['data_dir']
initial_root_password node['owncloud']['mysql']['server_root_password']
bind_address '127.0.0.1'
bind_address node['owncloud']['config']['dbhost']
port node['owncloud']['config']['dbport'].to_s
run_group node['owncloud']['mysql']['run_group']
run_user node['owncloud']['mysql']['run_user']
Expand All @@ -152,7 +152,7 @@
end

mysql_connection_info = {
host: '127.0.0.1',
host: node['owncloud']['config']['dbhost'],
port: node['owncloud']['config']['dbport'],
username: 'root',
password: node['owncloud']['mysql']['server_root_password']
Expand All @@ -166,7 +166,7 @@
mysql_database_user node['owncloud']['config']['dbuser'] do
connection mysql_connection_info
database_name node['owncloud']['config']['dbname']
host 'localhost'
host node['owncloud']['config']['dbhost']
password node['owncloud']['config']['dbpassword']
privileges [:all]
action :grant
Expand Down Expand Up @@ -196,7 +196,7 @@
include_recipe 'database::postgresql'

postgresql_connection_info = {
host: 'localhost',
host: node['owncloud']['config']['dbhost'],
port: node['owncloud']['config']['dbport'],
username: 'postgres',
password: node['postgresql']['password']['postgres']
Expand All @@ -210,7 +210,7 @@
postgresql_database_user node['owncloud']['config']['dbuser'] do
connection postgresql_connection_info
database_name node['owncloud']['config']['dbname']
host 'localhost'
host node['owncloud']['config']['dbhost']
password node['owncloud']['config']['dbpassword']
privileges [:all]
action [:create, :grant]
Expand Down
21 changes: 11 additions & 10 deletions test/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
require_relative '../spec_helper'

describe 'owncloud::default' do
let(:chef_runner) { ChefSpec::SoloRunner.new }
let(:chef_run) { chef_runner.converge(described_recipe) }
let(:node) { chef_runner.node }
let(:db_name) { 'owncloud_db' }
let(:db_user) { 'owncloud_user' }
let(:db_root_password) { 'root_db_pass' }
let(:db_password) { 'owncloud_pass' }
let(:db_host) { node['owncloud']['config']['dbhost'] }
let(:db_connection) do
{
host: '127.0.0.1', port: '3306',
host: db_host, port: '3306',
username: 'root', password: db_root_password
}
end
let(:admin_password) { 'owncloud_setup' }
let(:chef_runner) { ChefSpec::SoloRunner.new }
let(:chef_run) { chef_runner.converge(described_recipe) }
let(:node) { chef_runner.node }
before do
node.set['owncloud']['config']['dbname'] = db_name
node.set['owncloud']['config']['dbuser'] = db_user
Expand Down Expand Up @@ -214,7 +215,7 @@

it 'uses local databse by default' do
chef_run
expect(node['owncloud']['config']['dbhost']).to eq('127.0.0.1')
expect(node['owncloud']['config']['dbhost']).to eq(db_host)
end

it 'installs mysql2 gem' do
Expand All @@ -225,7 +226,7 @@
expect(chef_run).to create_mysql_service('default')
.with_data_dir(nil)
.with_version(nil)
.with_bind_address('127.0.0.1')
.with_bind_address(db_host)
.with_port('3306')
.with_initial_root_password(db_root_password)
end
Expand All @@ -243,7 +244,7 @@
expect(chef_run).to grant_mysql_database_user(db_user)
.with_connection(db_connection)
.with_database_name(db_name)
.with_host('localhost')
.with_host(db_host)
.with_password(db_password)
.with_privileges([:all])
end
Expand Down Expand Up @@ -272,7 +273,7 @@
context 'with PostgreSQL database' do
let(:db_connection) do
{
host: 'localhost', port: 5432,
host: db_host, port: 5432,
username: 'postgres', password: db_root_password
}
end
Expand Down Expand Up @@ -306,15 +307,15 @@
it 'creates PostgreSQL database user' do
expect(chef_run).to create_postgresql_database_user(db_user)
.with_connection(db_connection)
.with_host('localhost')
.with_host(db_host)
.with_password(db_password)
end

it 'grants PostgreSQL database user' do
expect(chef_run).to create_postgresql_database_user(db_user)
.with_connection(db_connection)
.with_database_name(db_name)
.with_host('localhost')
.with_host(db_host)
.with_password(db_password)
.with_privileges([:all])
end
Expand Down

0 comments on commit 3269e9f

Please sign in to comment.