From 601c8149950ac08eca4b49a7588aa2a21966fcd4 Mon Sep 17 00:00:00 2001 From: "Dr. Jens Harbott" Date: Thu, 2 Apr 2020 11:43:16 +0000 Subject: [PATCH] Fix mariadb-cluster-server recipe The hadn't been changed yet to use the resources provided by the new mariadb cookbook. Also add spec testing. Change-Id: Ib49cab07c06c4441ae811ca811f614e303024b0b --- recipes/mariadb-cluster-server.rb | 33 ++++++++++++++---------- spec/mariadb-cluster-server_spec.rb | 39 +++++++++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 3 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 spec/mariadb-cluster-server_spec.rb diff --git a/recipes/mariadb-cluster-server.rb b/recipes/mariadb-cluster-server.rb index 351a15a..dfc7346 100644 --- a/recipes/mariadb-cluster-server.rb +++ b/recipes/mariadb-cluster-server.rb @@ -23,24 +23,20 @@ end ## INFO: to use this recipe, set node['openstack']['db']['service_type'] = 'mariadb-cluster' in your environment bind_db = node['openstack']['bind_service']['db'] -if bind_db['interface'] - listen_address = address_for bind_db['interface'] - node.default['mariadb']['galera']['options']['port'] = bind_db['port'] -else - listen_address = bind_db['host'] - node.default['mariadb']['galera']['options']['port'] = node['openstack']['endpoints']['db']['port'] +if bind_db['interface'].nil? + Chef::Log.fatal('Need to specify interface to bind to.') + raise end -node.default['mariadb']['galera']['options']['bind-address'] = listen_address +listen_address = address_for(bind_db['interface']) ## CLUSTER SPECIFIC CONFIG -node.default['mariadb']['galera']['cluster_name'] = 'openstack' -node.default['mariadb']['galera']['wsrep_provider_options']['gmcast.listen_addr'] = "tcp://#{listen_address}:4567" +gmcast_listen_addr = "tcp://#{listen_address}:4567" ### find all nodes in the mariadb cluster cluster_nodes = search(:node, 'recipes:"openstack-ops-database\:\:mariadb-cluster-server"').sort # if it's the first node make sure that wsrep_cluster_address is set to nothing to be able to bootstrap. is_first_node = cluster_nodes.empty? || (cluster_nodes.size == 1 && cluster_nodes.first['fqdn'] == node['fqdn']) if is_first_node - node.default['mariadb']['galera']['gcomm_address'] = 'gcomm://' + gcomm_address = 'gcomm://' else # otherwise set the correct cluster address with all cluster nodes family = node['openstack']['endpoints']['family'] @@ -50,11 +46,22 @@ else cluster_nodes_addresses << address end cluster_address = cluster_nodes_addresses.join(',') - node.default['mariadb']['galera']['gcomm_address'] = "gcomm://#{cluster_address}" + gcomm_address = "gcomm://#{cluster_address}" end -include_recipe 'openstack-ops-database::mariadb-client' -include_recipe 'mariadb::galera' +include_recipe 'openstack-ops-database::mariadb-server' + +provider_options = { 'gcache.size': '512M', + 'gmcast.listen_addr': gmcast_listen_addr } + +mariadb_galera_configuration 'MariaDB Galera Configuration' do + version node['openstack']['mariadb']['version'] + cluster_name 'openstack' + gcomm_address gcomm_address + wsrep_node_address_interface bind_db['interface'] + wsrep_provider_options provider_options + wsrep_sst_method 'rsync' +end # Install clustercheck tool cookbook_file '/usr/bin/clustercheck' do diff --git a/spec/mariadb-cluster-server_spec.rb b/spec/mariadb-cluster-server_spec.rb new file mode 100644 index 0000000..80ff16a --- /dev/null +++ b/spec/mariadb-cluster-server_spec.rb @@ -0,0 +1,39 @@ +# encoding: UTF-8 + +require_relative 'spec_helper' + +describe 'openstack-ops-database::mariadb-cluster-server' do + describe 'ubuntu' do + include_context 'database-stubs' + let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } + let(:node) { runner.node } + cached(:chef_run) do + node.override['openstack']['bind_service']['db']['interface'] = 'lo' + runner.converge(described_recipe) + end + + it 'includes mariadb recipes' do + expect(chef_run).to include_recipe('openstack-ops-database::mariadb-server') + end + + it do + expect(chef_run).to create_mariadb_galera_configuration('MariaDB Galera Configuration').with( + version: '10.3', + cluster_name: 'openstack', + gcomm_address: 'gcomm://', + wsrep_node_address_interface: 'lo', + wsrep_provider_options: { 'gcache.size': '512M', 'gmcast.listen_addr': 'tcp://127.0.0.1:4567' }, + wsrep_sst_method: 'rsync' + ) + end + + it do + expect(chef_run).to create_if_missing_cookbook_file('/usr/bin/clustercheck').with( + source: 'clustercheck', + owner: 'root', + group: 'root', + mode: '0755' + ) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index afc30c4..073f32a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,8 @@ shared_context 'database-stubs' do stub_command("\"/usr/bin/mysql\" -u root -e 'show databases;'") stub_command("mysqladmin --user=root --password='' version") + stub_search('node', 'recipes:"openstack-ops-database\:\:mariadb-cluster-server"').and_return([]) + allow_any_instance_of(Chef::Recipe).to receive(:address_for) .with('lo') .and_return('127.0.0.1')