Ensure mysql client ip address is an ip

If the hieradata is set to '' for the client ip address, puppet may
consider this as a true condition. This change changes out the check to
ensure that the value is an ip address, otherwise remove it from the
configuration file.

Change-Id: Idbf6bec3ec66f7018dc30e5f1e6d1ba5f48180d7
Partial-Bug: #1748180
This commit is contained in:
Alex Schultz 2018-02-08 11:53:03 -07:00
parent 2fca0708cc
commit ff88c8929c
2 changed files with 126 additions and 1 deletions

View File

@ -53,7 +53,7 @@ class tripleo::profile::base::database::mysql::client (
$step = Integer(hiera('step')),
) {
if $step >= 1 {
if $mysql_client_bind_address {
if is_ip_address($mysql_client_bind_address) {
$client_bind_changes = [
"set ${mysql_read_default_group}/bind-address '${mysql_client_bind_address}'"
]

View File

@ -0,0 +1,125 @@
#
# Copyright (C) 2018 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.
#
require 'spec_helper'
describe 'tripleo::profile::base::database::mysql::client' do
shared_examples_for 'tripleo::profile::base::database::mysql::client' do
context 'with defaults' do
let (:params) do
{ :step => 1 }
end
before (:each) do
facts.merge!({ :uuid => 'notdocker' })
end
it {
is_expected.to contain_exec('directory-create-etc-my.cnf.d')
is_expected.to contain_augeas('tripleo-mysql-client-conf').with(
:incl => '/etc/my.cnf.d/tripleo.cnf',
:changes => [
'rm tripleo/bind-address',
'rm tripleo/ssl',
'rm tripleo/ssl-ca'
]
)
}
end
context 'with defaults on docker' do
let (:params) do
{ :step => 1 }
end
before (:each) do
facts.merge!({ :uuid => 'docker' })
end
it {
is_expected.to contain_file('/etc/my.cnf.d').with(:ensure => 'directory')
is_expected.to contain_augeas('tripleo-mysql-client-conf').with(
:incl => '/etc/my.cnf.d/tripleo.cnf',
:changes => [
'rm tripleo/bind-address',
'rm tripleo/ssl',
'rm tripleo/ssl-ca'
]
)
}
end
context 'with ip address set to "" LP#1748180' do
let (:params) do
{ :step => 1,
:mysql_client_bind_address => ''
}
end
before (:each) do
facts.merge!({ :uuid => 'notdocker' })
end
it {
is_expected.to contain_exec('directory-create-etc-my.cnf.d')
is_expected.to contain_augeas('tripleo-mysql-client-conf').with(
:incl => '/etc/my.cnf.d/tripleo.cnf',
:changes => [
'rm tripleo/bind-address',
'rm tripleo/ssl',
'rm tripleo/ssl-ca'
]
)
}
end
context 'with ip address and ssl enabled' do
let (:params) do
{ :step => 1,
:enable_ssl => true,
:mysql_client_bind_address => '127.0.0.1'
}
end
before (:each) do
facts.merge!({ :uuid => 'notdocker' })
end
it {
is_expected.to contain_exec('directory-create-etc-my.cnf.d')
is_expected.to contain_augeas('tripleo-mysql-client-conf').with(
:incl => '/etc/my.cnf.d/tripleo.cnf',
:changes => [
"set tripleo/bind-address '#{params[:mysql_client_bind_address]}'",
"set tripleo/ssl '1'",
"set tripleo/ssl-ca '/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt'"
]
)
}
end
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({ :hostname => 'node.example.com' })
end
it_behaves_like 'tripleo::profile::base::database::mysql::client'
end
end
end