Fixed remote DB installations
This patch fixes host resolution for MySQL/MariaDB remote installation. Relevant Puppet providers have been moved to separate module because remote installation for AMQP backend will be implemented in this module. Initialization for MySQL/MariaDB client has been fixed, so it is now working also with MariaDB client (RHEL-7+, Fedora-20+). Change-Id: Ic9328562226ecceebff11f9021457d1338977e77 Fixes: rhbz#1128212
This commit is contained in:
parent
4a1b6a93f6
commit
bfdf666bec
|
@ -86,13 +86,13 @@ def initSequences(controller):
|
|||
|
||||
def create_manifest(config, messages):
|
||||
if config['CONFIG_MYSQL_INSTALL'] == 'y':
|
||||
install = True
|
||||
suffix = 'install'
|
||||
host = config['CONFIG_MYSQL_HOST']
|
||||
else:
|
||||
install = False
|
||||
suffix = 'noinstall'
|
||||
host = config['CONFIG_CONTROLLER_HOST']
|
||||
|
||||
manifestfile = "%s_mysql.pp" % config['CONFIG_MYSQL_HOST']
|
||||
manifestfile = "%s_mysql.pp" % host
|
||||
manifestdata = [getManifestTemplate('mysql_%s.pp' % suffix)]
|
||||
|
||||
def append_for(module, suffix):
|
||||
|
|
|
@ -160,9 +160,9 @@ def copy_puppet_modules(config, messages):
|
|||
'concat', 'firewall', 'glance', 'heat', 'horizon',
|
||||
'inifile', 'keystone', 'memcached', 'mongodb',
|
||||
'mysql', 'neutron', 'nova', 'nssdb', 'openstack',
|
||||
'packstack', 'qpid', 'rabbitmq', 'rsync', 'ssh',
|
||||
'stdlib', 'swift', 'sysctl', 'tempest', 'vcsrepo',
|
||||
'vlan', 'vswitch', 'xinetd'))
|
||||
'packstack', 'qpid', 'rabbitmq', 'remote', 'rsync',
|
||||
'ssh', 'stdlib', 'swift', 'sysctl', 'tempest',
|
||||
'vcsrepo', 'vlan', 'vswitch', 'xinetd'))
|
||||
|
||||
# write puppet manifest to disk
|
||||
manifestfiles.writeManifests()
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
Puppet::Type.type(:remote_database).provide(:mysql) do
|
||||
|
||||
desc "Manages remote MySQL database."
|
||||
|
||||
defaultfor :kernel => 'Linux'
|
||||
|
||||
optional_commands :mysql => 'mysql'
|
||||
optional_commands :mysqladmin => 'mysqladmin'
|
||||
|
||||
def self.instances
|
||||
mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-NBe', "show databases").split("\n").collect do |name|
|
||||
new(:name => name)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}")
|
||||
end
|
||||
|
||||
def destroy
|
||||
mysqladmin("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-f', 'drop', @resource[:name])
|
||||
end
|
||||
|
||||
def charset
|
||||
mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-NBe', "show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\//)[1]
|
||||
end
|
||||
|
||||
def charset=(value)
|
||||
mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}")
|
||||
end
|
||||
|
||||
def exists?
|
||||
begin
|
||||
mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}", '-NBe', "show databases").match(/^#{@resource[:name]}$/)
|
||||
rescue => e
|
||||
debug(e.message)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,99 @@
|
|||
Puppet::Type.type(:remote_database).provide(:mysql) do
|
||||
|
||||
desc "Manages remote MySQL database."
|
||||
|
||||
defaultfor :kernel => 'Linux'
|
||||
|
||||
optional_commands :mysql => 'mysql'
|
||||
optional_commands :mysqladmin => 'mysqladmin'
|
||||
|
||||
def self.instances
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"show databases"
|
||||
).split("\n").collect do |name|
|
||||
new(:name => name)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"create database `#{@resource[:name]}`
|
||||
character set #{@resource[:charset]}
|
||||
collate #{@resource[:collate]}"
|
||||
)
|
||||
end
|
||||
|
||||
def destroy
|
||||
mysqladmin(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
'-f',
|
||||
'drop', @resource[:name]
|
||||
)
|
||||
end
|
||||
|
||||
def charset
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\//
|
||||
)[1]
|
||||
end
|
||||
|
||||
def charset=(value)
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"alter database `#{resource[:name]}` character set #{value}"
|
||||
)
|
||||
end
|
||||
|
||||
def collate
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"use #{resource[:name]}; show variables like 'collation_database'"
|
||||
).match(/\s*collation_database\s+(\S+)/)[1]
|
||||
end
|
||||
|
||||
def collate=(value)
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"alter database `#{resource[:name]}` collate #{value}"
|
||||
)
|
||||
end
|
||||
|
||||
def exists?
|
||||
begin
|
||||
mysql(
|
||||
"--host=#{@resource[:db_host]}",
|
||||
"--user=#{@resource[:db_user]}",
|
||||
"--password=#{@resource[:db_password]}",
|
||||
"-NBe",
|
||||
"show databases"
|
||||
).match(/^#{@resource[:name]}$/)
|
||||
rescue => e
|
||||
debug(e.message)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -26,4 +26,10 @@ Puppet::Type.newtype(:remote_database) do
|
|||
newvalue(/^\S+$/)
|
||||
end
|
||||
|
||||
newproperty(:collate) do
|
||||
desc 'The collate setting for the database'
|
||||
defaultto :utf8_general_ci
|
||||
newvalue(/^\S+$/)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
class remote::db (
|
||||
$mysql_client_package = $remote::params::mysql_client_package,
|
||||
$mysql_client_package_ensure = 'present',
|
||||
) inherits remote::params {
|
||||
|
||||
package { $mysql_client_package:
|
||||
ensure => $mysql_client_package_ensure,
|
||||
}
|
||||
|
||||
Package[$mysql_client_package] -> Remote_database<||>
|
||||
Package[$mysql_client_package] -> Remote_database_user<||>
|
||||
Package[$mysql_client_package] -> Remote_database_grant<||>
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
class remote::params {
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
case $::operatingsystem {
|
||||
|
||||
'Fedora': {
|
||||
if (is_integer($::operatingsystemrelease) and $::operatingsystemrelease >= 19) or $::operatingsystemrelease == 'Rawhide' {
|
||||
$mysql_client_package = 'mariadb'
|
||||
} else {
|
||||
$mysql_client_package = 'mysql'
|
||||
}
|
||||
}
|
||||
|
||||
'RedHat', 'CentOS', 'Scientific': {
|
||||
if $::operatingsystemmajrelease >= 7 {
|
||||
$mysql_client_package = 'mariadb'
|
||||
} else {
|
||||
$mysql_client_package = 'mysql'
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
$mysql_client_package = 'mysql'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$mysql_client_package = 'mysql'
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported platform")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,3 @@
|
|||
|
||||
package { 'mysql':
|
||||
ensure => 'present',
|
||||
class { 'remote::db':
|
||||
}
|
||||
|
||||
Package ['mysql'] -> Remote_database<||>
|
||||
Package ['mysql'] -> Remote_database_user<||>
|
||||
Package ['mysql'] -> Remote_database_grant<||>
|
||||
|
|
19
setup.py
19
setup.py
|
@ -56,13 +56,18 @@ class InstallModulesCommand(Command):
|
|||
out, err = proc.communicate()
|
||||
if proc.returncode:
|
||||
raise RuntimeError('Failed:\n%s' % err)
|
||||
# install Packstack module
|
||||
packstack_path = os.path.join(self.destination, 'packstack')
|
||||
print 'Copying Packstack module to %(packstack_path)s' % locals()
|
||||
source = os.path.join(os.path.dirname(__file__),
|
||||
'packstack/puppet/modules/packstack')
|
||||
shutil.rmtree(packstack_path, ignore_errors=True)
|
||||
shutil.copytree(source, packstack_path)
|
||||
# install Packstack modules
|
||||
module_source = os.path.join(os.path.dirname(__file__),
|
||||
'packstack/puppet/modules')
|
||||
for module in os.listdir(module_source):
|
||||
source = os.path.join(module_source, module)
|
||||
if not os.path.isdir(source):
|
||||
continue
|
||||
|
||||
dest = os.path.join(self.destination, module)
|
||||
print 'Copying module %(module)s to %(dest)s' % locals()
|
||||
shutil.rmtree(dest, ignore_errors=True)
|
||||
shutil.copytree(source, dest)
|
||||
|
||||
|
||||
# Utility function to read the README file.
|
||||
|
|
Loading…
Reference in New Issue