diff --git a/manifests/api.pp b/manifests/api.pp index d62a2e8..15fd811 100755 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -60,6 +60,7 @@ class magnum::api( $ssl_key_file = $::os_service_default, ) { + include ::magnum::deps include ::magnum::params include ::magnum::policy @@ -76,9 +77,6 @@ class magnum::api( include ::magnum::db::sync } - Magnum_config<||> ~> Service['magnum-api'] - Class['magnum::policy'] ~> Service['magnum-api'] - # Configure API conf magnum_config { 'api/port' : value => $port; @@ -91,8 +89,6 @@ class magnum::api( # Install package if $::magnum::params::api_package { - Package['magnum-api'] -> Class['magnum::policy'] - Package['magnum-api'] -> Service['magnum-api'] package { 'magnum-api': ensure => $package_ensure, name => $::magnum::params::api_package, diff --git a/manifests/certificates.pp b/manifests/certificates.pp index 4e61e6c..f1a56a3 100644 --- a/manifests/certificates.pp +++ b/manifests/certificates.pp @@ -12,6 +12,8 @@ class magnum::certificates ( $cert_manager_type = $::os_service_default, ) { + include ::magnum::deps + magnum_config { 'certificates/cert_manager_type': value => $cert_manager_type; } diff --git a/manifests/client.pp b/manifests/client.pp index ac58600..638c152 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -12,6 +12,7 @@ class magnum::client ( $package_ensure = present ) { + include ::magnum::deps include ::magnum::params package { 'python-magnumclient': diff --git a/manifests/clients.pp b/manifests/clients.pp index fe6a18c..7f0d807 100644 --- a/manifests/clients.pp +++ b/manifests/clients.pp @@ -19,6 +19,7 @@ class magnum::clients ( $endpoint_type = 'publicURL', ) { + include ::magnum::deps include ::magnum::params magnum_config { diff --git a/manifests/conductor.pp b/manifests/conductor.pp index 7405363..f039fae 100644 --- a/manifests/conductor.pp +++ b/manifests/conductor.pp @@ -29,10 +29,10 @@ class magnum::conductor( ) { include ::magnum::db + include ::magnum::deps include ::magnum::params # Install package - Package['magnum-conductor'] -> Service['magnum-conductor'] package { 'magnum-conductor': ensure => $package_ensure, name => $::magnum::params::conductor_package, diff --git a/manifests/config.pp b/manifests/config.pp index fa0e2e7..f51fa4f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -28,6 +28,8 @@ class magnum::config ( $magnum_api_paste_ini = {}, ) { + include ::magnum::deps + validate_hash($magnum_config) validate_hash($magnum_api_paste_ini) diff --git a/manifests/db.pp b/manifests/db.pp index 380be05..ab5bda0 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -49,6 +49,8 @@ class magnum::db ( $database_db_max_retries = $::os_service_default, ) { + include ::magnum::deps + validate_re($database_connection, '^(mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index a683b1c..973c9d8 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -47,6 +47,8 @@ class magnum::db::mysql( $allowed_hosts = undef ) { + include ::magnum::deps + validate_string($password) ::openstacklib::db::mysql { 'magnum': @@ -59,5 +61,8 @@ class magnum::db::mysql( allowed_hosts => $allowed_hosts, } - ::Openstacklib::Db::Mysql['magnum'] ~> Exec<| title == 'magnum-db-sync' |> + Anchor['magnum::db::begin'] + ~> Class['magnum::db::mysql'] + ~> Anchor['magnum::db::end'] + } diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index bb19413..0508e98 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -32,7 +32,7 @@ class magnum::db::postgresql( $privileges = 'ALL', ) { - Class['magnum::db::postgresql'] -> Service<| title == 'magnum' |> + include ::magnum::deps ::openstacklib::db::postgresql { 'magnum': password_hash => postgresql_password($user, $password), @@ -42,6 +42,8 @@ class magnum::db::postgresql( privileges => $privileges, } - ::Openstacklib::Db::Postgresql['magnum'] ~> Exec<| title == 'magnum-db-sync' |> + Anchor['magnum::db::begin'] + ~> Class['magnum::db::postgresql'] + ~> Anchor['magnum::db::end'] } diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index a6cfe92..5a28c75 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -16,6 +16,9 @@ class magnum::db::sync( $user = 'magnum', $extra_params = '--config-file /etc/magnum/magnum.conf', ) { + + include ::magnum::deps + exec { 'magnum-db-sync': command => "magnum-db-manage ${extra_params} upgrade head", path => '/usr/bin', @@ -24,10 +27,12 @@ class magnum::db::sync( try_sleep => 5, tries => 10, logoutput => on_failure, + subscribe => [ + Anchor['magnum::install::end'], + Anchor['magnum::config::end'], + Anchor['magnum::dbsync::begin'] + ], + notify => Anchor['magnum::dbsync::end'], } - Package<| tag == 'magnum-package' |> ~> Exec['magnum-db-sync'] - Exec['magnum-db-sync'] ~> Service<| tag == 'magnum-db-sync-service' |> - Magnum_config<| title == 'database/connection' |> ~> Exec['magnum-db-sync'] - Magnum_config <| |> ~> Exec['magnum-db-sync'] } diff --git a/manifests/deps.pp b/manifests/deps.pp new file mode 100644 index 0000000..0e878ce --- /dev/null +++ b/manifests/deps.pp @@ -0,0 +1,35 @@ +# == Class: magnum::deps +# +# Magnum anchors and dependency management +# +class magnum::deps { + # Setup anchors for install, config and service phases of the module. These + # anchors allow external modules to hook the begin and end of any of these + # phases. Package or service management can also be replaced by ensuring the + # package is absent or turning off service management and having the + # replacement depend on the appropriate anchors. When applicable, end tags + # should be notified so that subscribers can determine if installation, + # config or service state changed and act on that if needed. + anchor { 'magnum::install::begin': } + -> Package<| tag == 'magnum-package'|> + ~> anchor { 'magnum::install::end': } + -> anchor { 'magnum::config::begin': } + -> Magnum_config<||> + ~> anchor { 'magnum::config::end': } + -> anchor { 'magnum::db::begin': } + -> anchor { 'magnum::db::end': } + ~> anchor { 'magnum::dbsync::begin': } + -> anchor { 'magnum::dbsync::end': } + ~> anchor { 'magnum::service::begin': } + ~> Service<| tag == 'magnum-service' |> + ~> anchor { 'magnum::service::end': } + + # policy config should occur in the config block also. + Anchor['magnum::config::begin'] + -> Openstacklib::Policy::Base<||> + ~> Anchor['magnum::config::end'] + + # Installation or config changes will always restart services. + Anchor['magnum::install::end'] ~> Anchor['magnum::service::begin'] + Anchor['magnum::config::end'] ~> Anchor['magnum::service::begin'] +} diff --git a/manifests/init.pp b/manifests/init.pp index e7bf33b..6ab35a7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -96,6 +96,7 @@ class magnum( $rabbit_password = $::os_service_default, ) { + include ::magnum::deps include ::magnum::params include ::magnum::logging include ::magnum::policy diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index 83169ee..728fbc6 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -64,7 +64,9 @@ class magnum::keystone::auth ( $internal_url = 'http://127.0.0.1:9511/v1', ) { - $real_service_name = pick($service_name, $auth_name) + include ::magnum::deps + + $real_service_name = pick($service_name, $auth_name) if $configure_user_role { Keystone_user_role["${auth_name}@${tenant}"] ~> Service <| name == 'magnum-server' |> diff --git a/manifests/keystone/authtoken.pp b/manifests/keystone/authtoken.pp index bd38433..004eff4 100755 --- a/manifests/keystone/authtoken.pp +++ b/manifests/keystone/authtoken.pp @@ -219,6 +219,8 @@ class magnum::keystone::authtoken( $token_cache_time = $::os_service_default, ) { + include ::magnum::deps + keystone::resource::authtoken { 'magnum_config': username => $username, password => $password, diff --git a/manifests/keystone/domain.pp b/manifests/keystone/domain.pp index ec69890..a307a20 100644 --- a/manifests/keystone/domain.pp +++ b/manifests/keystone/domain.pp @@ -38,7 +38,9 @@ class magnum::keystone::domain ( $manage_domain = true, $manage_user = true, $manage_role = true, - ) { +) { + + include ::magnum::deps include ::magnum::params if $manage_domain { diff --git a/manifests/logging.pp b/manifests/logging.pp index 1c7ed41..eb63019 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -108,6 +108,8 @@ class magnum::logging( $log_date_format = $::os_service_default, ) { + include ::magnum::deps + oslo::log { 'magnum_config': debug => $debug, use_syslog => $use_syslog, diff --git a/manifests/policy.pp b/manifests/policy.pp index 8dcc5de..3796f68 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -28,6 +28,8 @@ class magnum::policy ( $policy_path = '/etc/magnum/policy.json', ) { + include ::magnum::deps + validate_hash($policies) Openstacklib::Policy::Base { diff --git a/releasenotes/notes/external_install_mgmt_hook-a91729a7e9151378.yaml b/releasenotes/notes/external_install_mgmt_hook-a91729a7e9151378.yaml new file mode 100644 index 0000000..eeb3c9b --- /dev/null +++ b/releasenotes/notes/external_install_mgmt_hook-a91729a7e9151378.yaml @@ -0,0 +1,10 @@ +--- +prelude: > + Add hooks for external install & svc management. +features: + - This adds defined anchor points for external modules to + hook into the software install, config and service dependency + chain. This allows external modules to manage software + installation (virtualenv, containers, etc) and service management + (pacemaker) without needing rely on resources that may change or + be renamed. diff --git a/spec/classes/magnum_api_spec.rb b/spec/classes/magnum_api_spec.rb index fe3aff4..3f9be3c 100755 --- a/spec/classes/magnum_api_spec.rb +++ b/spec/classes/magnum_api_spec.rb @@ -31,6 +31,7 @@ describe 'magnum::api' do default_params.merge(params) end + it { is_expected.to contain_class('magnum::deps') } it { is_expected.to contain_class('magnum::params') } it { is_expected.to contain_class('magnum::policy') } @@ -41,7 +42,6 @@ describe 'magnum::api' do :name => platform_params[:api_package], :tag => ['openstack', 'magnum-package'], ) - is_expected.to contain_package('magnum-api').with_before(/Service\[magnum-api\]/) end end diff --git a/spec/classes/magnum_db_sync_spec.rb b/spec/classes/magnum_db_sync_spec.rb index f6d6264..2819d38 100644 --- a/spec/classes/magnum_db_sync_spec.rb +++ b/spec/classes/magnum_db_sync_spec.rb @@ -12,7 +12,11 @@ describe 'magnum::db::sync' do :refreshonly => 'true', :try_sleep => 5, :tries => 10, - :logoutput => 'on_failure' + :logoutput => 'on_failure', + :subscribe => ['Anchor[magnum::install::end]', + 'Anchor[magnum::config::end]', + 'Anchor[magnum::dbsync::begin]'], + :notify => 'Anchor[magnum::dbsync::end]', ) end @@ -31,7 +35,11 @@ describe 'magnum::db::sync' do :refreshonly => 'true', :try_sleep => 5, :tries => 10, - :logoutput => 'on_failure' + :logoutput => 'on_failure', + :subscribe => ['Anchor[magnum::install::end]', + 'Anchor[magnum::config::end]', + 'Anchor[magnum::dbsync::begin]'], + :notify => 'Anchor[magnum::dbsync::end]', ) } end diff --git a/spec/classes/magnum_init_spec.rb b/spec/classes/magnum_init_spec.rb index 12e05b6..4ae28cc 100644 --- a/spec/classes/magnum_init_spec.rb +++ b/spec/classes/magnum_init_spec.rb @@ -11,6 +11,7 @@ describe 'magnum' do it 'contains other classes' do is_expected.to contain_class('magnum::logging') + is_expected.to contain_class('magnum::deps') is_expected.to contain_class('magnum::params') is_expected.to contain_class('magnum::policy') is_expected.to contain_class('magnum::db')