diff --git a/recipes/default.rb b/recipes/default.rb index 22936ed..90a9a92 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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'] @@ -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'] @@ -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 @@ -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'] @@ -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] diff --git a/test/unit/recipes/default_spec.rb b/test/unit/recipes/default_spec.rb index 485687d..ef55f77 100644 --- a/test/unit/recipes/default_spec.rb +++ b/test/unit/recipes/default_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -306,7 +307,7 @@ 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 @@ -314,7 +315,7 @@ 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