Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 128 #153

Merged
merged 4 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
# limitations under the License.
#

# rubocop:disable Lint/EmptyWhen

Chef::Recipe.send(:include, MariaDB::Helper)

extend Chef::Util::Selinux
selinux_enabled = selinux_enabled?

case node['mariadb']['install']['type']
when 'package'
# Determine service name and register the resource
Expand Down Expand Up @@ -57,9 +59,6 @@
action :install
notifies :enable, 'service[mysql]'
end

when 'from_source'
# To be filled as soon as possible
end

include_recipe "#{cookbook_name}::config"
Expand All @@ -80,6 +79,14 @@
action :nothing
end

bash 'Restore security context' do
user 'root'
code "/usr/sbin/restorecon -v #{node['mariadb']['mysqld']['default_datadir']}"
only_if { selinux_enabled }
subscribes :run, 'bash[move-datadir]', :immediately
action :nothing
end

directory node['mariadb']['mysqld']['datadir'] do
owner 'mysql'
group 'mysql'
Expand Down
42 changes: 42 additions & 0 deletions spec/centos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,48 @@
expect(chef_run).to_not run_execute('change first install root password')
end

context 'Installation with alternative data directory' do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(
platform: 'centos', version: '7.0',
step_into: ['mariadb_configuration']
) do |node|
node.automatic['memory']['total'] = '2048kB'
node.automatic['ipaddress'] = '1.1.1.1'
node.override['mariadb']['install']['prefer_os_package'] = true
node.override['mariadb']['mysqld']['datadir'] = '/home/mysql'
end
runner.converge('mariadb::default')
end

it 'Create data directory' do
data_directory = chef_run.directory('/home/mysql')
expect(chef_run).to create_directory('/home/mysql')
expect(data_directory).to notify('service[mysql]')
.to(:stop)
.immediately
expect(data_directory).to notify('bash[move-datadir]')
.to(:run)
.immediately
expect(data_directory).to notify('service[mysql]')
.to(:start)
.immediately
end

it 'Move data directory' do
move_datadir_block = chef_run.bash('move-datadir')
expect(move_datadir_block).to do_nothing
end

it 'Restore security context' do
restore_security_context = chef_run.bash('Restore security context')
expect(restore_security_context).to do_nothing
expect(restore_security_context).to subscribe_to('bash[move-datadir]')
.on(:run)
.immediately
end
end

context 'Installation from MariaDB repository' do
let(:mariadb_package) { chef_run.package('MariaDB-server') }
let(:mariadb_service) { chef_run.service('mysql') }
Expand Down