Browse Source

Create interface to create mysql resources via hieradata

This added the "tripleo::<service name>::mysql_user" interface, which
allows folks to create databases, users and grants via hieradata instead
of having to modify puppet-tripleo.

Change-Id: I975d64c73e314159db0f6c1ada14a26491a46d1a
changes/00/600000/6
Juan Antonio Osorio Robles 3 years ago
parent
commit
0730ff23b9
5 changed files with 154 additions and 0 deletions
  1. +6
    -0
      manifests/profile/base/database/mysql.pp
  2. +62
    -0
      manifests/profile/base/database/mysql/user.pp
  3. +37
    -0
      manifests/profile/base/database/mysql/users.pp
  4. +6
    -0
      releasenotes/notes/introduce-mysql-user-interface-e16d62f3743128a0.yaml
  5. +43
    -0
      spec/defines/tripleo_profile_base_database_mysql_user_spec.rb

+ 6
- 0
manifests/profile/base/database/mysql.pp View File

@ -169,6 +169,12 @@ class tripleo::profile::base::database::mysql (
}
}
$service_names = hiera('enabled_services', undef)
if $service_names {
tripleo::profile::base::database::mysql::users { $service_names: }
}
if $step >= 2 and $sync_db {
Class['::mysql::server'] -> Mysql_database<||>
if hiera('aodh_api_enabled', false) {


+ 62
- 0
manifests/profile/base/database/mysql/user.pp View File

@ -0,0 +1,62 @@
# The tripleo::profile::base::database::mysql::user resource implements
# a generic resource to create databases, users and grants in MySQL
#
# == parameters
#
# [*password*]
# (Required) Password to connect to the database.
#
# [*dbname*]
# (Required) Name of the database.
#
# [*user*]
# (Required) User to connect to the database.
#
# [*host*]
# (Optional) The default source host user is allowed to connect from.
# Defaults to '127.0.0.1'
#
# [*allowed_hosts*]
# (Optional) Other hosts the user is allowed to connect from.
# Defaults to 'undef'.
#
# [*charset*]
# (Optional) The database charset.
# Defaults to 'utf8'
#
# [*collate*]
# (Optional) The database collate.
# Only used with mysql modules >= 2.2.
# Defaults to 'utf8_general_ci'
#
# == Dependencies
# Class['mysql::server']
#
# == Examples
#
# == Authors
#
# == Copyright
#
define tripleo::profile::base::database::mysql::user (
$password,
$dbname,
$user,
$host = '127.0.0.1',
$charset = 'utf8',
$collate = 'utf8_general_ci',
$allowed_hosts = undef
) {
validate_string($password)
::openstacklib::db::mysql { $title :
user => $user,
password_hash => mysql_password($password),
dbname => $dbname,
host => $host,
charset => $charset,
collate => $collate,
allowed_hosts => $allowed_hosts,
}
}

+ 37
- 0
manifests/profile/base/database/mysql/users.pp View File

@ -0,0 +1,37 @@
# Copyright 2017 Red Hat, Inc.
#
# 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.
#
# == Define: tripleo::haproxy::service_endpoints
#
# Define used to create haproxyendpoints for composable services.
#
# === Parameters:
#
# [*service_name*]
# (optional) The service_name to create the myql resources for.
# Defaults to $title
#
define tripleo::profile::base::database::mysql::users ($service_name = $title) {
$underscore_name = regsubst($service_name, '-', '_', 'G')
# This allows each composable service to load its own custom rules by
# creating its own flat hiera key named:
# tripleo::<service name with underscores>::mysql_user
$mysql_users = hiera("tripleo::${underscore_name}::mysql_user", undef)
if $mysql_users {
ensure_resource('tripleo::profile::base::database::mysql::user', $service_name, $mysql_users)
}
}

+ 6
- 0
releasenotes/notes/introduce-mysql-user-interface-e16d62f3743128a0.yaml View File

@ -0,0 +1,6 @@
---
features:
- |
The interface ``tripleo::<service name>::mysql_user`` was created. It
allows service writes to create databases, database users and grants via
hieradata instead of having to modify puppet-tripleo.

+ 43
- 0
spec/defines/tripleo_profile_base_database_mysql_user_spec.rb View File

@ -0,0 +1,43 @@
require 'spec_helper'
describe 'tripleo::profile::base::database::mysql::user' do
let(:title) { 'barbican' }
let :pre_condition do
'include mysql::server'
end
let :params do {
:password => 'secrete',
:dbname => 'barbican',
:user => 'barbican',
:host => '127.0.0.1',
:charset => 'utf8',
:collate => 'utf8_general_ci'
}
end
shared_examples_for 'tripleo profile base database mysql user' do
context 'with basic parameters to configure barbican database' do
it 'should configure mysql' do
is_expected.to contain_openstacklib__db__mysql('barbican').with(
:dbname => params[:dbname],
:user => params[:user],
:host => params[:host],
:charset => params[:charset],
:collate => params[:collate],
)
end
end
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo profile base database mysql user'
end
end
end

Loading…
Cancel
Save