From dbcb82fa36024d94e27e72f294c243470785f03c Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 11 Jul 2014 10:35:50 -0700 Subject: [PATCH] Migrate mysql backend to use openstacklib::db::mysql Implements: blueprint commmon-openstack-database-resource Change-Id: I03bd33d7c78ea69702650688c28e9d0b7cac2911 --- .fixtures.yml | 1 + Modulefile | 2 +- README.md | 2 - manifests/api.pp | 18 +++--- manifests/db/mysql.pp | 93 +++++++++++++--------------- manifests/db/mysql/host_access.pp | 33 ---------- manifests/registry.pp | 18 +++--- spec/classes/glance_api_spec.rb | 1 - spec/classes/glance_db_mysql_spec.rb | 38 +++--------- spec/classes/glance_registry_spec.rb | 1 - 10 files changed, 68 insertions(+), 139 deletions(-) delete mode 100644 manifests/db/mysql/host_access.pp diff --git a/.fixtures.yml b/.fixtures.yml index 58e7c877..70fa5d66 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,6 +5,7 @@ fixtures: "mysql": repo: "git://github.com/puppetlabs/puppetlabs-mysql.git" ref: 'origin/2.2.x' + 'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git' "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" "rabbitmq": repo: "git://github.com/puppetlabs/puppetlabs-rabbitmq" diff --git a/Modulefile b/Modulefile index 144009fa..cbd31e7d 100644 --- a/Modulefile +++ b/Modulefile @@ -9,5 +9,5 @@ source 'https://github.com/stackforge/puppet-glance' dependency 'puppetlabs/inifile', '>=1.0.0 <2.0.0' dependency 'puppetlabs/keystone', '>=4.0.0 <5.0.0' -dependency 'puppetlabs/mysql', '>=0.9.0 <3.0.0' dependency 'puppetlabs/stdlib', '>= 3.2.0' +dependency 'stackforge/openstacklib', '>=5.0.0' diff --git a/README.md b/README.md index 36dcb5b5..b79a172b 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,6 @@ Limitations * Only supports configuring the file, swift and rbd storage backends. -* The Glance Openstack service depends on a sqlalchemy database. If you are using puppetlabs-mysql to achieve this, there is a parameter called mysql_module that can be used to swap between the two supported versions: 0.9 and 2.2. This is needed because the puppetlabs-mysql module was rewritten and the custom type names have changed between versions. - Development ----------- diff --git a/manifests/api.pp b/manifests/api.pp index 881cffeb..ed3c69d4 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -146,9 +146,7 @@ # Defaults to false, not set # # [*mysql_module*] -# (optional) Mysql puppet module version to use -# Tested versions include 0.9 and 2.2 -# Defaults to '2.2'. +# (optional) Deprecated. Does nothing. # # [*known_stores*] # (optional)List of which store classes and store class locations are @@ -191,18 +189,22 @@ class glance::api( $cert_file = false, $key_file = false, $ca_file = false, - $mysql_module = '2.2', $known_stores = false, $database_connection = 'sqlite:///var/lib/glance/glance.sqlite', $database_idle_timeout = 3600, $image_cache_dir = '/var/lib/glance/image-cache', # DEPRECATED PARAMETERS + $mysql_module = undef, $sql_idle_timeout = false, $sql_connection = false, ) inherits glance { require keystone::python + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') + } + if ( $glance::params::api_package_name != $glance::params::registry_package_name ) { ensure_packages([$glance::params::api_package_name]) } @@ -244,12 +246,8 @@ class glance::api( if $database_connection_real { if($database_connection_real =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) { - if ($mysql_module >= 2.2) { - require 'mysql::bindings' - require 'mysql::bindings::python' - } else { - require 'mysql::python' - } + require 'mysql::bindings' + require 'mysql::bindings::python' } elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) { } elsif($database_connection_real =~ /sqlite:\/\//) { diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 852892ea..e4df4c89 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -1,11 +1,33 @@ +# The glance::db::mysql class creates a MySQL database for glance. +# It must be used on the MySQL server # -# I should change this to mysql -# for consistency +# == Parameters # -# [*mysql_module*] -# (optional) The mysql puppet module version to use. Tested -# versions include 0.9 and 2.2 -# Default to '2.2' +# [*password*] +# password to connect to the database. Mandatory. +# +# [*dbname*] +# name of the database. Optional. Defaults to glance. +# +# [*user*] +# user to connect to the database. Optional. Defaults to glance. +# +# [*host*] +# the default source host user is allowed to connect from. +# Optional. Defaults to 'localhost' +# +# [*allowed_hosts*] +# other hosts the user is allowd to connect from. +# Optional. Defaults to undef. +# +# [*charset*] +# the database charset. Optional. Defaults to 'utf8' +# +# [*collate*] +# the database collation. Optional. Defaults to 'utf8_unicode_ci' +# +# [*mysql_module*] +# (optional) Deprecated. Does nothing. # class glance::db::mysql( $password, @@ -16,54 +38,25 @@ class glance::db::mysql( $charset = 'utf8', $collate = 'utf8_unicode_ci', $cluster_id = 'localzone', - $mysql_module = '2.2' + $mysql_module = undef, ) { - Class['glance::db::mysql'] -> Exec<| title == 'glance-manage db_sync' |> - - if ($mysql_module >= 2.2) { - require mysql::bindings - require mysql::bindings::python - Mysql_database[$dbname] ~> Exec<| title == 'glance-manage db_sync' |> - - mysql::db { $dbname: - user => $user, - password => $password, - host => $host, - charset => $charset, - collate => $collate, - require => Class['mysql::server'], - } - - } else { - require mysql::python - Database[$dbname] ~> Exec<| title == 'glance-manage db_sync' |> - - mysql::db { $dbname: - user => $user, - password => $password, - host => $host, - charset => $charset, - require => Class['mysql::config'], - } + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') } - # Check allowed_hosts to avoid duplicate resource declarations - # If $host in $allowed_hosts, then remove it - if is_array($allowed_hosts) and delete($allowed_hosts,$host) != [] { - $real_allowed_hosts = delete($allowed_hosts,$host) - # If $host = $allowed_hosts, then set it to undef - } elsif is_string($allowed_hosts) and ($allowed_hosts != $host) { - $real_allowed_hosts = $allowed_hosts + validate_string($password) + + ::openstacklib::db::mysql { 'glance': + user => $user, + password_hash => mysql_password($password), + dbname => $dbname, + host => $host, + charset => $charset, + collate => $collate, + allowed_hosts => $allowed_hosts, } - if $real_allowed_hosts { - # TODO this class should be in the mysql namespace - glance::db::mysql::host_access { $real_allowed_hosts: - user => $user, - password => $password, - database => $dbname, - mysql_module => $mysql_module, - } - } + ::Openstacklib::Db::Mysql['glance'] ~> Exec<| title == 'glance-manage db_sync' |> + } diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp deleted file mode 100644 index 0b2bc1d4..00000000 --- a/manifests/db/mysql/host_access.pp +++ /dev/null @@ -1,33 +0,0 @@ -# -# Used to grant access to the glance mysql DB -# -define glance::db::mysql::host_access ($user, $password, $database, $mysql_module = '2.2') { - - if ($mysql_module >= 2.2) { - mysql_user { "${user}@${name}": - password_hash => mysql_password($password), - require => Mysql_database[$database], - } - - mysql_grant { "${user}@${name}/${database}.*": - privileges => ['ALL'], - options => ['GRANT'], - provider => 'mysql', - table => "${database}.*", - require => Mysql_user["${user}@${name}"], - user => "${user}@${name}" - } - } else { - database_user { "${user}@${name}": - password_hash => mysql_password($password), - provider => 'mysql', - require => Database[$database], - } - database_grant { "${user}@${name}/${database}": - # TODO figure out which privileges to grant. - privileges => 'all', - provider => 'mysql', - require => Database_user["${user}@${name}"] - } - } -} diff --git a/manifests/registry.pp b/manifests/registry.pp index 1261ca6a..cfda4f54 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -105,9 +105,7 @@ # Defaults to false, not set # # [*mysql_module*] -# (optional) The version of puppet-mysql to use. Tested versions -# include 0.9 and 2.2 -# Defaults to '2.2' +# (optional) Deprecated. Does nothing. # class glance::registry( $keystone_password, @@ -135,14 +133,18 @@ class glance::registry( $cert_file = false, $key_file = false, $ca_file = false, - $mysql_module = '2.2', # DEPRECATED PARAMETERS + $mysql_module = undef, $sql_idle_timeout = false, $sql_connection = false, ) inherits glance { require keystone::python + if $mysql_module { + warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') + } + if ( $glance::params::api_package_name != $glance::params::registry_package_name ) { ensure_packages([$glance::params::registry_package_name]) } @@ -178,12 +180,8 @@ class glance::registry( if $database_connection_real { if($database_connection_real =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) { - if ($mysql_module >= 2.2) { - require 'mysql::bindings' - require 'mysql::bindings::python' - } else { - require 'mysql::python' - } + require 'mysql::bindings' + require 'mysql::bindings::python' } elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) { } elsif($database_connection_real =~ /sqlite:\/\//) { diff --git a/spec/classes/glance_api_spec.rb b/spec/classes/glance_api_spec.rb index eb81fdf7..d36f53b9 100644 --- a/spec/classes/glance_api_spec.rb +++ b/spec/classes/glance_api_spec.rb @@ -35,7 +35,6 @@ describe 'glance::api' do :database_connection => 'sqlite:///var/lib/glance/glance.sqlite', :show_image_direct_url => false, :purge_config => false, - :mysql_module => '2.2', :known_stores => false, :image_cache_dir => '/var/lib/glance/image-cache', } diff --git a/spec/classes/glance_db_mysql_spec.rb b/spec/classes/glance_db_mysql_spec.rb index 4a729f29..ed14a9bb 100644 --- a/spec/classes/glance_db_mysql_spec.rb +++ b/spec/classes/glance_db_mysql_spec.rb @@ -15,16 +15,12 @@ describe 'glance::db::mysql' do let :params do { :password => 'glancepass1', - :mysql_module => '2.2' } end - it { should contain_class('mysql::bindings::python') } - - it { should contain_mysql__db('glance').with( - :password => 'glancepass1', - :require => 'Class[Mysql::Server]', - :charset => 'utf8' + it { should contain_openstacklib__db__mysql('glance').with( + :password_hash => '*41C910F70EB213CF4CB7B2F561B4995503C0A87B', + :charset => 'utf8' )} end @@ -38,9 +34,10 @@ describe 'glance::db::mysql' do } end - it { should contain_mysql__db('glancedb2').with( - :password => 'glancepass2', - :charset => 'utf8' + it { should contain_openstacklib__db__mysql('glance').with( + :password_hash => '*6F9A1CB9BD83EE06F3903BDFF9F4188764E694CA', + :dbname => 'glancedb2', + :charset => 'utf8' )} end @@ -54,17 +51,6 @@ describe 'glance::db::mysql' do } end - it {should_not contain_glance__db__mysql__host_access("127.0.0.1").with( - :user => 'glance', - :password => 'glancepass2', - :database => 'glancedb2' - )} - it {should contain_glance__db__mysql__host_access("%").with( - :user => 'glance', - :password => 'glancepass2', - :database => 'glancedb2' - )} - end describe "overriding allowed_hosts param to string" do @@ -76,11 +62,6 @@ describe 'glance::db::mysql' do } end - it {should contain_glance__db__mysql__host_access("192.168.1.1").with( - :user => 'glance', - :password => 'glancepass2', - :database => 'glancedb2' - )} end describe "overriding allowed_hosts param equals to host param " do @@ -92,11 +73,6 @@ describe 'glance::db::mysql' do } end - it {should_not contain_glance__db__mysql__host_access("127.0.0.1").with( - :user => 'glance', - :password => 'glancepass2', - :database => 'glancedb2' - )} end end diff --git a/spec/classes/glance_registry_spec.rb b/spec/classes/glance_registry_spec.rb index 95bf4050..690c9c13 100644 --- a/spec/classes/glance_registry_spec.rb +++ b/spec/classes/glance_registry_spec.rb @@ -27,7 +27,6 @@ describe 'glance::registry' do :keystone_user => 'glance', :keystone_password => 'ChangeMe', :purge_config => false, - :mysql_module => '2.2' } end