Browse Source

ops-database refactor for Pike and Chef 13

- implemented foodcritic and cookstyle corrections
- deprecated node.foo.bar method access for node['foo']['bar'] bracket syntax
- removed deprecated postgresql support
- removed percona-cluster as the Percona cookbook has not been touched since 2015
- switched default rdbms to mariadb[0]

This change was largely born out of a discussion in #sous-chefs on the Chef
Community Slack. The notion of using the vendor-provided package is preferred
in the Chef Community versus the distro version if possible, due to
inconsistencies in outcome. As a result, this cookbook focuses on MariaDB, and
specifically from mariadb.org.

[0]: https://docs.openstack.org/install-guide/environment-sql-database.html

Implements blueprint modern-chef

Change-Id: I7ee0f5eae4e79e5c70ee8de4a0094a7c34fdd18f
changes/50/523050/8
Samuel Cassiba 3 years ago
committed by Samuel Cassiba
parent
commit
45a1623cb2
21 changed files with 218 additions and 336 deletions
  1. +9
    -4
      Berksfile
  2. +176
    -0
      LICENSE
  3. +7
    -8
      Rakefile
  4. +2
    -7
      metadata.rb
  5. +2
    -2
      recipes/mariadb-client.rb
  6. +7
    -34
      recipes/mariadb-server.rb
  7. +1
    -1
      recipes/mysql-server.rb
  8. +0
    -28
      recipes/percona-cluster-client.rb
  9. +0
    -62
      recipes/percona-cluster-server.rb
  10. +0
    -28
      recipes/postgresql-client.rb
  11. +0
    -38
      recipes/postgresql-server.rb
  12. +3
    -9
      spec/client_spec.rb
  13. +1
    -1
      spec/mariadb-client-redhat_spec.rb
  14. +1
    -5
      spec/mariadb-client_spec.rb
  15. +1
    -1
      spec/mariadb-server-redhat_spec.rb
  16. +4
    -16
      spec/mariadb-server_spec.rb
  17. +0
    -28
      spec/percona-cluster-client_spec.rb
  18. +0
    -19
      spec/percona-cluster-server_spec.rb
  19. +0
    -27
      spec/postgresql-server_spec.rb
  20. +3
    -14
      spec/server_spec.rb
  21. +1
    -4
      spec/spec_helper.rb

+ 9
- 4
Berksfile View File

@ -1,6 +1,11 @@
source "https://supermarket.chef.io"
source 'https://supermarket.chef.io'
metadata
%w(common).each do |cookbook|
if Dir.exist?("../cookbook-openstack-#{cookbook}")
cookbook "openstack-#{cookbook}", path: "../cookbook-openstack-#{cookbook}"
else
cookbook "openstack-#{cookbook}", github: "openstack/cookbook-openstack-#{cookbook}"
end
end
cookbook "openstack-common",
github: "openstack/cookbook-openstack-common"
metadata

+ 176
- 0
LICENSE View File

@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

+ 7
- 8
Rakefile View File

@ -1,32 +1,32 @@
task default: ["test"]
task :test => [:syntax, :lint, :unit]
task test: [:syntax, :lint, :unit]
desc "Vendor the cookbooks in the Berksfile"
task :berks_prep do
sh %{chef exec berks vendor}
sh %(chef exec berks vendor)
end
desc "Run FoodCritic (syntax) tests"
task :syntax do
sh %{chef exec foodcritic --exclude spec -f any .}
sh %(chef exec foodcritic --exclude spec -f any .)
end
desc "Run RuboCop (lint) tests"
task :lint do
sh %{chef exec cookstyle}
sh %(chef exec cookstyle)
end
desc "Run RSpec (unit) tests"
task :unit => :berks_prep do
sh %{chef exec rspec --format documentation}
task unit: :berks_prep do
sh %(chef exec rspec --format documentation)
end
desc "Remove the berks-cookbooks directory and the Berksfile.lock"
task :clean do
rm_rf [
'berks-cookbooks',
'Berksfile.lock'
'Berksfile.lock',
]
end
@ -37,4 +37,3 @@ task :integration do
load './Rakefile-Common'
Rake::Task["common_integration"].invoke
end

+ 2
- 7
metadata.rb View File

@ -1,8 +1,8 @@
name 'openstack-ops-database'
maintainer 'openstack-chef'
maintainer_email 'openstack-dev@lists.openstack.org'
license 'Apache 2.0'
description 'Provides the shared database configuration for Chef for OpenStack.'
license 'Apache-2.0'
description 'Provides the shared database configuration for OpenStack'
version '16.0.0'
recipe 'client', 'Installs client packages for the database used by the deployment.'
@ -11,8 +11,6 @@ recipe 'mysql-client', 'Installs MySQL client packages.'
recipe 'mysql-server', 'Installs and configures MySQL server packages.'
recipe 'mariadb-client', 'Installs MariaDB client packages.'
recipe 'mariadb-server', 'Installs and configures MariaDB server packages.'
recipe 'postgresql-client', 'Installs PostgreSQL client packages.'
recipe 'postgresql-server', 'Installs and configures PostgreSQL server packages.'
recipe 'openstack-db', 'Creates necessary tables, users, and grants for OpenStack.'
%w(ubuntu redhat centos).each do |os|
@ -21,12 +19,9 @@ end
depends 'openstack-common', '>= 16.0.0'
depends 'database', '~> 6.1'
depends 'mariadb', '~> 1.5'
depends 'mysql', '~> 8.2'
depends 'mysql2_chef_gem', '~> 2.0'
depends 'percona', '~> 0.16.1'
depends 'postgresql', '~> 5.1'
issues_url 'https://launchpad.net/openstack-chef' if respond_to?(:issues_url)
source_url 'https://github.com/openstack/cookbook-openstack-ops-database' if respond_to?(:source_url)


+ 2
- 2
recipes/mariadb-client.rb View File

@ -16,11 +16,11 @@
# limitations under the License.
#
node.override['mariadb']['install']['prefer_os_package'] = true
node.normal['mariadb']['use_default_repository'] = true
include_recipe 'mariadb::client'
mysql2_chef_gem_mariadb 'default' do
gem_version '0.4.5'
gem_version '0.4.9'
action :install
end


+ 7
- 34
recipes/mariadb-server.rb View File

@ -30,20 +30,20 @@ listen_address = if bind_db['interface']
super_password = get_password 'db', node['openstack']['db']['root_user_key']
node.override['mariadb']['allow_root_pass_change'] = true
node.override['mariadb']['server_root_password'] = super_password
node.override['mariadb']['mysqld']['bind_address'] = listen_address
node.override['mariadb']['install']['prefer_os_package'] = true
node.normal['mariadb']['remove_test_database'] = true
node.normal['mariadb']['allow_root_pass_change'] = true
node.normal['mariadb']['server_root_password'] = super_password
node.normal['mariadb']['mysqld']['bind_address'] = listen_address
unless listen_address == '127.0.0.1' || listen_address == 'localhost'
node.override['mariadb']['forbid_remote_root'] = false
node.normal['mariadb']['forbid_remote_root'] = false
end
include_recipe 'openstack-ops-database::mariadb-client'
# reuse mysql configuration for mariadb
node.override['mariadb']['mysqld']['default_storage_engine'] = node['openstack']['mysql']['default-storage-engine']
node.override['mariadb']['mysqld']['max_connections'] = node['openstack']['mysql']['max_connections']
node.normal['mariadb']['mysqld']['default_storage_engine'] = node['openstack']['mysql']['default-storage-engine']
node.normal['mariadb']['mysqld']['max_connections'] = node['openstack']['mysql']['max_connections']
include_recipe 'mariadb::server'
# reuse mysql configuration file for mariadb
@ -53,30 +53,3 @@ template "#{node['mariadb']['configuration']['includedir']}/openstack.cnf" do
source 'openstack.cnf.erb'
notifies :restart, 'service[mysql]'
end
# Current mariadb cookbook does not handle deleting anonymous users and default
# users. We need to delete them here.
mysql_connection_info = {
host: 'localhost',
username: 'root',
password: super_password,
}
mysql_database 'drop empty and default users' do
database_name 'mysql'
sql "DELETE FROM mysql.user WHERE User = '' OR Password = ''"
connection mysql_connection_info
action :query
end
mysql_database 'test' do
connection mysql_connection_info
action :drop
end
mysql_database 'flush priviledges after cleanup' do
database_name 'mysql'
sql 'FLUSH PRIVILEGES'
connection mysql_connection_info
action :query
end

+ 1
- 1
recipes/mysql-server.rb View File

@ -40,7 +40,7 @@ mysql_service node['openstack']['mysql']['service_name'] do
data_dir node['openstack']['mysql']['data_dir'] if node['openstack']['mysql']['data_dir']
initial_root_password super_password
bind_address listen_address
port bind_db.port.to_s
port bind_db['port'].to_s
action [:create, :start]
end


+ 0
- 28
recipes/percona-cluster-client.rb View File

@ -1,28 +0,0 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-ops-database
# Recipe:: percona-cluster-client
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe 'percona::client'
mysql2_chef_gem 'default' do
provider Chef::Provider::Mysql2ChefGem::Percona
action :install
end
node['openstack']['db']['python_packages']['percona-cluster'].each do |pkg|
package pkg
end

+ 0
- 62
recipes/percona-cluster-server.rb View File

@ -1,62 +0,0 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-ops-database
# Recipe:: percona-cluster-server
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class ::Chef::Recipe
include ::Openstack
end
## INFO: to use this recipe, set node['percona']['server']['role'] = %w(cluster) in your environment
bind_db = node['openstack']['bind_service']['db']
if bind_db['interface']
listen_address = address_for bind_db['interface']
node.normal['percona']['cluster']['wsrep_sst_receive_address'] = listen_address
node.normal['percona']['server']['bind_address'] = listen_address
node.normal['percona']['server']['port'] = bind_db['port']
else
listen_address = bind_db['host']
node.normal['percona']['server']['bind_address'] = listen_address
node.normal['percona']['server']['port'] = node['openstack']['endpoints']['db']['port']
end
## CLUSTER SPECIFIC CONFIG
node.normal['percona']['cluster']['wsrep_node_name'] = node['fqdn']
node.normal['percona']['cluster']['wsrep_cluster_name'] = 'openstack'
node.normal['percona']['cluster']['wsrep_provider_options'] = "\"gmcast.listen_addr=tcp://#{listen_address}:4567;\""
# query_cache is not supported with wsrep
node.normal['percona']['server']['query_cache_size'] = 0
# find all nodes in the percona cluster
cluster_nodes = search(:node, 'recipes:"percona\:\:cluster"').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.normal['percona']['cluster']['wsrep_cluster_address'] = 'gcomm://'
else
# otherwise set the correct cluster address with all cluster nodes
family = node['openstack']['endpoints']['family']
cluster_nodes_addresses = []
cluster_nodes.each do |cluster_node|
address = address_for bind_db['interface'], family, cluster_node
cluster_nodes_addresses << address
end
cluster_address = cluster_nodes_addresses.join(',')
node.normal['percona']['cluster']['wsrep_cluster_address'] = "gcomm://#{cluster_address}"
end
include_recipe 'openstack-ops-database::percona-cluster-client'
include_recipe 'percona::cluster'

+ 0
- 28
recipes/postgresql-client.rb View File

@ -1,28 +0,0 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-ops-database
# Recipe:: postgresql-client
#
# Copyright 2013, Opscode, Inc.
# Copyright 2013, AT&T Services, Inc.
# Copyright 2013-2014, SUSE Linux GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe 'postgresql::ruby'
include_recipe 'postgresql::client'
node['openstack']['db']['python_packages']['postgresql'].each do |pkg|
package pkg
end

+ 0
- 38
recipes/postgresql-server.rb View File

@ -1,38 +0,0 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-ops-database
# Recipe:: postgresql-server
#
# Copyright 2013, Opscode, Inc.
# Copyright 2012-2013, Rackspace US, Inc.
# Copyright 2013, AT&T Services, Inc.
# Copyright 2013, SUSE Linux GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
class ::Chef::Recipe
include ::Openstack
end
bind_db = node['openstack']['bind_service']['db']
listen_address = if bind_db['interface']
address_for bind_db['interface']
else
bind_db['host']
end
node.override['postgresql']['config']['listen_addresses'] = listen_address
include_recipe 'openstack-ops-database::postgresql-client'
include_recipe 'postgresql::server'

+ 3
- 9
spec/client_spec.rb View File

@ -9,15 +9,9 @@ describe 'openstack-ops-database::client' do
let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) }
it 'uses mysql database client recipe by default' do
expect(chef_run).to include_recipe 'openstack-ops-database::mysql-client'
end
it 'uses postgresql database client recipe when configured' do
node.set['openstack']['db']['service_type'] = 'postgresql'
node.set['postgresql']['password']['postgres'] = 'secret'
expect(chef_run).to include_recipe 'openstack-ops-database::postgresql-client'
it 'uses mariadb client recipe by default' do
node.set['openstack']['db']['service_type'] = 'mariadb'
expect(chef_run).to include_recipe 'openstack-ops-database::mariadb-client'
end
end
end

+ 1
- 1
spec/mariadb-client-redhat_spec.rb View File

@ -6,7 +6,7 @@ describe 'openstack-ops-database::mariadb-client' do
describe 'redhat' do
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
let(:node) do
runner.node.set['openstack']['db']['service_type'] = 'mariadb'
runner.node.override['openstack']['db']['service_type'] = 'mariadb'
runner.node
end
let(:chef_run) { runner.converge(described_recipe) }


+ 1
- 5
spec/mariadb-client_spec.rb View File

@ -7,7 +7,7 @@ describe 'openstack-ops-database::mariadb-client' do
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) do
runner.node.set['openstack']['db']['service_type'] = 'mariadb'
runner.node.override['openstack']['db']['service_type'] = 'mariadb'
runner.node
end
let(:chef_run) { runner.converge(described_recipe) }
@ -19,9 +19,5 @@ describe 'openstack-ops-database::mariadb-client' do
it 'installs mariadb python client packages' do
expect(chef_run).to install_package('python-mysqldb')
end
it 'override prefer os package' do
expect(chef_run.node['mariadb']['install']['prefer_os_package']).to be true
end
end
end

+ 1
- 1
spec/mariadb-server-redhat_spec.rb View File

@ -11,7 +11,7 @@ describe 'openstack-ops-database::mariadb-server' do
let(:file) { chef_run.template('/etc/my.cnf.d/openstack.cnf') }
it 'creates template /etc/my.cnf.d/openstack.cnf' do
node.set['mariadb']['install']['version'] = '5.7'
node.override['mariadb']['install']['version'] = '5.7'
expect(chef_run).to create_template(file.name).with(
user: 'mysql',
group: 'mysql',


+ 4
- 16
spec/mariadb-server_spec.rb View File

@ -15,6 +15,8 @@ describe 'openstack-ops-database::mariadb-server' do
expect(chef_run.node['mariadb']['mysqld']['default_storage_engine']).to eq 'InnoDB'
expect(chef_run.node['mariadb']['mysqld']['max_connections']).to eq '307'
expect(chef_run.node['mariadb']['forbid_remote_root']).to be true
expect(chef_run.node['mariadb']['remove_anonymous_users']).to be true
expect(chef_run.node['mariadb']['remove_test_database']).to be true
end
it 'includes mariadb recipes' do
@ -23,7 +25,7 @@ describe 'openstack-ops-database::mariadb-server' do
end
it 'creates template /etc/mysql/conf.d/openstack.cnf' do
node.set['mariadb']['install']['version'] = '5.7'
node.override['mariadb']['install']['version'] = '10.1'
expect(chef_run).to create_template(file.name).with(
user: 'mysql',
group: 'mysql',
@ -54,23 +56,9 @@ describe 'openstack-ops-database::mariadb-server' do
expect(chef_run.node['mariadb']['server_root_password']).to eq 'abc123'
end
it 'override prefer os package' do
expect(chef_run.node['mariadb']['install']['prefer_os_package']).to be true
end
it 'allow root remote access' do
node.set['openstack']['bind_service']['db']['host'] = '192.168.1.1'
node.override['openstack']['bind_service']['db']['host'] = '192.168.1.1'
expect(chef_run.node['mariadb']['forbid_remote_root']).to be false
end
it 'drop anonymous and empty users' do
expect(chef_run).to query_mysql_database('drop empty and default users')\
.with(database_name: 'mysql',
sql: "DELETE FROM mysql.user WHERE User = '' OR Password = ''")
expect(chef_run).to drop_mysql_database('test')
expect(chef_run).to query_mysql_database('flush priviledges after cleanup')\
.with(database_name: 'mysql',
sql: 'FLUSH PRIVILEGES')
end
end
end

+ 0
- 28
spec/percona-cluster-client_spec.rb View File

@ -1,28 +0,0 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-ops-database::percona-cluster-client' do
include_context 'database-stubs'
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) do
runner.node.set['openstack']['db']['service_type'] = 'percona-cluster'
runner.node
end
let(:chef_run) { runner.converge(described_recipe) }
it 'includes percona client recipes' do
expect(chef_run).to include_recipe('percona::client')
end
it 'install mysql2 gem package' do
expect(chef_run).to install_mysql2_chef_gem('default')
.with(provider: Chef::Provider::Mysql2ChefGem::Percona)
end
it 'installs percona python client packages' do
expect(chef_run).to install_package('python-mysqldb')
end
end
end

+ 0
- 19
spec/percona-cluster-server_spec.rb View File

@ -1,19 +0,0 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-ops-database::percona-cluster-server' do
include_context 'database-stubs'
describe 'ubuntu' do
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) do
runner.node.set['openstack']['db']['service_type'] = 'percona-cluster'
runner.node
end
let(:chef_run) { runner.converge(described_recipe) }
it 'includes percona client recipes' do
expect(chef_run).to include_recipe('percona::cluster')
end
end
end

+ 0
- 27
spec/postgresql-server_spec.rb View File

@ -1,27 +0,0 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-ops-database::postgresql-server' do
describe 'ubuntu' do
include_context 'database-stubs'
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
# The postgresql cookbook will raise an 'uninitialized constant
# Chef::Application' error without this attribute when running
# the tests
node.set['postgresql']['password']['postgres'] = 'postgres_password'
runner.converge(described_recipe)
end
it 'includes postgresql recipes' do
expect(chef_run).to include_recipe(
'openstack-ops-database::postgresql-client'
)
expect(chef_run).to include_recipe('postgresql::server')
end
end
end

+ 3
- 14
spec/server_spec.rb View File

@ -9,20 +9,9 @@ describe 'openstack-ops-database::server' do
let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) }
it 'uses mysql database server recipe by default' do
expect(chef_run).to include_recipe('openstack-ops-database::mysql-server')
end
it 'uses postgresql database server recipe when configured' do
node.set['openstack']['db']['service_type'] = 'postgresql'
# The postgresql cookbook will raise an 'uninitialized constant
# Chef::Application' error without this attribute when running
# the tests
node.set['postgresql']['password']['postgres'] = 'postgres_password'
expect(chef_run).to include_recipe(
'openstack-ops-database::postgresql-server'
)
it 'uses mariadb server recipe by default' do
node.set['openstack']['db']['service_type'] = 'mariadb'
expect(chef_run).to include_recipe('openstack-ops-database::mariadb-server')
end
end
end

+ 1
- 4
spec/spec_helper.rb View File

@ -7,7 +7,7 @@ ChefSpec::Coverage.start! { add_filter 'openstack-ops-database' }
LOG_LEVEL = :fatal
REDHAT_OPTS = {
platform: 'redhat',
version: '7.1',
version: '7.3',
log_level: ::LOG_LEVEL,
}.freeze
UBUNTU_OPTS = {
@ -23,9 +23,6 @@ shared_context 'database-stubs' do
# for debian
stub_command("\"/usr/bin/mysql\" -u root -e 'show databases;'")
stub_command("mysqladmin --user=root --password='' version")
# for postgresql
stub_command('ls /var/lib/postgresql/9.5/main/recovery.conf')
stub_search('node', "recipes:\"percona\\:\\:cluster\"").and_return([])
allow_any_instance_of(Chef::Recipe).to receive(:address_for)
.with('lo')


Loading…
Cancel
Save