diff --git a/manifests/api.pp b/manifests/api.pp index 16eeeb95..03551980 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -57,6 +57,7 @@ class aodh::api ( ) inherits aodh::params { + include ::aodh::deps include ::aodh::params include ::aodh::policy @@ -64,12 +65,6 @@ class aodh::api ( include ::aodh::keystone::authtoken } - Aodh_config<||> ~> Service[$service_name] - Class['aodh::policy'] ~> Service[$service_name] - - Package['aodh-api'] -> Service[$service_name] - Package['aodh-api'] -> Service['aodh-api'] - Package['aodh-api'] -> Class['aodh::policy'] package { 'aodh-api': ensure => $package_ensure, name => $::aodh::params::api_package_name, @@ -95,7 +90,6 @@ class aodh::api ( enable => $enabled, hasstatus => true, hasrestart => true, - require => Class['aodh::db'], tag => 'aodh-service', } } elsif $service_name == 'httpd' { @@ -106,7 +100,6 @@ class aodh::api ( enable => false, tag => 'aodh-service', } - Class['aodh::db'] -> Service[$service_name] # we need to make sure aodh-api/eventlet is stopped before trying to start apache Service['aodh-api'] -> Service[$service_name] diff --git a/manifests/auth.pp b/manifests/auth.pp index 30bf8235..e8019703 100644 --- a/manifests/auth.pp +++ b/manifests/auth.pp @@ -61,6 +61,8 @@ class aodh::auth ( $auth_endpoint_type = $::os_service_default, ) { + include ::aodh::deps + aodh_config { 'service_credentials/auth_url' : value => $auth_url; 'service_credentials/region_name' : value => $auth_region; diff --git a/manifests/client.pp b/manifests/client.pp index 208792d0..af604c26 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -9,6 +9,7 @@ class aodh::client ( $ensure = 'present' ) { + include ::aodh::deps include ::aodh::params package { 'python-aodhclient': diff --git a/manifests/config.pp b/manifests/config.pp index 5ef19ac1..f1b9b976 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -28,6 +28,8 @@ class aodh::config ( $aodh_api_paste_ini = {}, ) { + include ::aodh::deps + validate_hash($aodh_config) validate_hash($aodh_api_paste_ini) diff --git a/manifests/db.pp b/manifests/db.pp index a5795694..d1dd8923 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -49,6 +49,8 @@ class aodh::db ( $database_max_overflow = $::os_service_default, ) { + include ::aodh::deps + $database_connection_real = pick($::aodh::database_connection, $database_connection) $database_idle_timeout_real = pick($::aodh::database_idle_timeout, $database_idle_timeout) $database_min_pool_size_real = pick($::aodh::database_min_pool_size, $database_min_pool_size) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index c8261ef1..63504403 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -53,6 +53,8 @@ class aodh::db::mysql( $allowed_hosts = undef ) { + include ::aodh::deps + validate_string($password) ::openstacklib::db::mysql { 'aodh': @@ -65,5 +67,8 @@ class aodh::db::mysql( allowed_hosts => $allowed_hosts, } - ::Openstacklib::Db::Mysql['aodh'] ~> Exec<| title == 'aodh-db-sync' |> + Anchor['aodh::db::begin'] + ~> Class['aodh::db::mysql'] + ~> Anchor['aodh::db::end'] + } diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index d34aa9d9..0f6e9362 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -40,7 +40,7 @@ class aodh::db::postgresql( $privileges = 'ALL', ) { - Class['aodh::db::postgresql'] -> Service<| title == 'aodh' |> + include ::aodh::deps ::openstacklib::db::postgresql { 'aodh': password_hash => postgresql_password($user, $password), @@ -50,6 +50,8 @@ class aodh::db::postgresql( privileges => $privileges, } - ::Openstacklib::Db::Postgresql['aodh'] ~> Exec<| title == 'aodh-db-sync' |> + Anchor['aodh::db::begin'] + ~> Class['aodh::db::postgresql'] + ~> Anchor['aodh::db::end'] } diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index 0e11d3d0..09937ff3 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -8,6 +8,9 @@ class aodh::db::sync ( $user = 'aodh', ){ + + include ::aodh::deps + exec { 'aodh-db-sync': command => 'aodh-dbsync --config-file /etc/aodh/aodh.conf', path => '/usr/bin', @@ -16,10 +19,12 @@ class aodh::db::sync ( try_sleep => 5, tries => 10, logoutput => on_failure, + subscribe => [ + Anchor['aodh::install::end'], + Anchor['aodh::config::end'], + Anchor['aodh::dbsync::begin'] + ], + notify => Anchor['aodh::dbsync::end'], } - Package<| tag == 'aodh-package' |> ~> Exec['aodh-db-sync'] - Exec['aodh-db-sync'] ~> Service<| tag == 'aodh-db-sync-service' |> - Aodh_config<||> ~> Exec['aodh-db-sync'] - Aodh_config<| title == 'database/connection' |> ~> Exec['aodh-db-sync'] } diff --git a/manifests/deps.pp b/manifests/deps.pp new file mode 100644 index 00000000..79aa525a --- /dev/null +++ b/manifests/deps.pp @@ -0,0 +1,35 @@ +# == Class: aodh::deps +# +# Aodh anchors and dependency management +# +class aodh::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 { 'aodh::install::begin': } + -> Package<| tag == 'aodh-package'|> + ~> anchor { 'aodh::install::end': } + -> anchor { 'aodh::config::begin': } + -> Aodh_config<||> + ~> anchor { 'aodh::config::end': } + -> anchor { 'aodh::db::begin': } + -> anchor { 'aodh::db::end': } + ~> anchor { 'aodh::dbsync::begin': } + -> anchor { 'aodh::dbsync::end': } + ~> anchor { 'aodh::service::begin': } + ~> Service<| tag == 'aodh-service' |> + ~> anchor { 'aodh::service::end': } + + # policy config should occur in the config block also. + Anchor['aodh::config::begin'] + -> Openstacklib::Policy::Base<||> + ~> Anchor['aodh::config::end'] + + # Installation or config changes will always restart services. + Anchor['aodh::install::end'] ~> Anchor['aodh::service::begin'] + Anchor['aodh::config::end'] ~> Anchor['aodh::service::begin'] +} diff --git a/manifests/evaluator.pp b/manifests/evaluator.pp index 7270b79b..01be8251 100644 --- a/manifests/evaluator.pp +++ b/manifests/evaluator.pp @@ -24,17 +24,15 @@ class aodh::evaluator ( $coordination_url = undef, ) { + include ::aodh::deps include ::aodh::params - Aodh_config<||> ~> Service['aodh-evaluator'] - if $coordination_url { aodh_config { 'coordination/backend_url' : value => $coordination_url; } } - Package[$::aodh::params::evaluator_package_name] -> Service['aodh-evaluator'] ensure_resource( 'package', [$::aodh::params::evaluator_package_name], { ensure => $package_ensure, tag => ['openstack', 'aodh-package'] } @@ -48,7 +46,6 @@ class aodh::evaluator ( } } - Package['aodh'] -> Service['aodh-evaluator'] service { 'aodh-evaluator': ensure => $service_ensure, name => $::aodh::params::evaluator_service_name, diff --git a/manifests/init.pp b/manifests/init.pp index 0a4a5aa2..ad71009f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -309,6 +309,7 @@ class aodh ( $rabbit_virtual_host = $::os_service_default, ) inherits aodh::params { + include ::aodh::deps include ::aodh::db include ::aodh::logging diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index 4d507121..933fc701 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -65,6 +65,8 @@ class aodh::keystone::auth ( $admin_url = 'http://127.0.0.1:8042', ) { + include ::aodh::deps + keystone::resource::service_identity { 'aodh': configure_user => $configure_user, configure_user_role => $configure_user_role, diff --git a/manifests/keystone/authtoken.pp b/manifests/keystone/authtoken.pp index 0b571240..b88d2cc0 100644 --- a/manifests/keystone/authtoken.pp +++ b/manifests/keystone/authtoken.pp @@ -223,6 +223,8 @@ class aodh::keystone::authtoken( $token_cache_time = $::os_service_default, ) { + include ::aodh::deps + if is_service_default($password) { fail('Please set password for Aodh service user') } diff --git a/manifests/listener.pp b/manifests/listener.pp index 7de3b4b6..c78202c8 100644 --- a/manifests/listener.pp +++ b/manifests/listener.pp @@ -19,11 +19,9 @@ class aodh::listener ( $package_ensure = 'present', ) { + include ::aodh::deps include ::aodh::params - Aodh_config<||> ~> Service['aodh-listener'] - - Package[$::aodh::params::listener_package_name] -> Service['aodh-listener'] ensure_resource( 'package', [$::aodh::params::listener_package_name], { ensure => $package_ensure, tag => ['openstack', 'aodh-package'] } @@ -37,7 +35,6 @@ class aodh::listener ( } } - Package['aodh'] -> Service['aodh-listener'] service { 'aodh-listener': ensure => $service_ensure, name => $::aodh::params::listener_service_name, diff --git a/manifests/logging.pp b/manifests/logging.pp index c587a3e1..88a85a04 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -105,6 +105,8 @@ class aodh::logging( $log_date_format = $::os_service_default, ) { + include ::aodh::deps + # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function # to use aodh:: first then aodh::logging::. $use_syslog_real = pick($::aodh::use_syslog,$use_syslog) diff --git a/manifests/notifier.pp b/manifests/notifier.pp index f4629738..5c54db05 100644 --- a/manifests/notifier.pp +++ b/manifests/notifier.pp @@ -19,11 +19,9 @@ class aodh::notifier ( $package_ensure = 'present', ) { + include ::aodh::deps include ::aodh::params - Aodh_config<||> ~> Service['aodh-notifier'] - - Package[$::aodh::params::notifier_package_name] -> Service['aodh-notifier'] ensure_resource( 'package', [$::aodh::params::notifier_package_name], { ensure => $package_ensure, tag => ['openstack', 'aodh-package'] } @@ -37,7 +35,6 @@ class aodh::notifier ( } } - Package['aodh'] -> Service['aodh-notifier'] service { 'aodh-notifier': ensure => $service_ensure, name => $::aodh::params::notifier_service_name, diff --git a/manifests/policy.pp b/manifests/policy.pp index 3321e49f..97a7b641 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -28,6 +28,8 @@ class aodh::policy ( $policy_path = '/etc/aodh/policy.json', ) { + include ::aodh::deps + validate_hash($policies) Openstacklib::Policy::Base { diff --git a/manifests/wsgi/apache.pp b/manifests/wsgi/apache.pp index efb69932..efb9a68b 100644 --- a/manifests/wsgi/apache.pp +++ b/manifests/wsgi/apache.pp @@ -94,6 +94,7 @@ class aodh::wsgi::apache ( $priority = '10', ) { + include ::aodh::deps include ::aodh::params include ::apache include ::apache::mod::wsgi diff --git a/releasenotes/notes/external_install_mgmt_hook-891a29ef391d1921.yaml b/releasenotes/notes/external_install_mgmt_hook-891a29ef391d1921.yaml new file mode 100644 index 00000000..eeb3c9b5 --- /dev/null +++ b/releasenotes/notes/external_install_mgmt_hook-891a29ef391d1921.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/aodh_api_spec.rb b/spec/classes/aodh_api_spec.rb index 428b7856..e753c122 100644 --- a/spec/classes/aodh_api_spec.rb +++ b/spec/classes/aodh_api_spec.rb @@ -21,6 +21,7 @@ describe 'aodh::api' do shared_examples_for 'aodh-api' do + it { is_expected.to contain_class('aodh::deps') } it { is_expected.to contain_class('aodh::params') } it { is_expected.to contain_class('aodh::policy') } @@ -51,10 +52,11 @@ describe 'aodh::api' do :enable => params[:enabled], :hasstatus => true, :hasrestart => true, - :require => 'Class[Aodh::Db]', :tag => 'aodh-service', ) end + it { is_expected.to contain_service('aodh-api').that_subscribes_to('Anchor[aodh::service::begin]')} + it { is_expected.to contain_service('aodh-api').that_notifies('Anchor[aodh::service::end]')} end end diff --git a/spec/classes/aodh_client_spec.rb b/spec/classes/aodh_client_spec.rb index a9c5ec8c..b519f896 100644 --- a/spec/classes/aodh_client_spec.rb +++ b/spec/classes/aodh_client_spec.rb @@ -4,6 +4,7 @@ describe 'aodh::client' do shared_examples_for 'aodh client' do + it { is_expected.to contain_class('aodh::deps') } it { is_expected.to contain_class('aodh::params') } it 'installs aodh client package' do diff --git a/spec/classes/aodh_db_sync_spec.rb b/spec/classes/aodh_db_sync_spec.rb index aa53175c..93c64da2 100644 --- a/spec/classes/aodh_db_sync_spec.rb +++ b/spec/classes/aodh_db_sync_spec.rb @@ -4,13 +4,19 @@ describe 'aodh::db::sync' do shared_examples_for 'aodh-dbsync' do + it { is_expected.to contain_class('aodh::deps') } + it 'runs aodh-db-sync' do is_expected.to contain_exec('aodh-db-sync').with( :command => 'aodh-dbsync --config-file /etc/aodh/aodh.conf', :path => '/usr/bin', :refreshonly => 'true', :user => 'aodh', - :logoutput => 'on_failure' + :logoutput => 'on_failure', + :subscribe => ['Anchor[aodh::install::end]', + 'Anchor[aodh::config::end]', + 'Anchor[aodh::dbsync::begin]'], + :notify => 'Anchor[aodh::dbsync::end]', ) end diff --git a/spec/classes/aodh_init_spec.rb b/spec/classes/aodh_init_spec.rb index e54155b3..67c34e6a 100644 --- a/spec/classes/aodh_init_spec.rb +++ b/spec/classes/aodh_init_spec.rb @@ -4,9 +4,13 @@ describe 'aodh' do shared_examples 'aodh' do + it { is_expected.to contain_class('aodh::deps') } + it { is_expected.to contain_class('aodh::db') } + it { is_expected.to contain_class('aodh::logging') } + context 'with default parameters' do let :params do - { :purge_config => false } + { :purge_config => false } end it 'contains the logging class' do diff --git a/spec/classes/aodh_wsgi_apache_spec.rb b/spec/classes/aodh_wsgi_apache_spec.rb index 2c6a1b6a..89294cbc 100644 --- a/spec/classes/aodh_wsgi_apache_spec.rb +++ b/spec/classes/aodh_wsgi_apache_spec.rb @@ -4,6 +4,7 @@ describe 'aodh::wsgi::apache' do shared_examples_for 'apache serving aodh with mod_wsgi' do it { is_expected.to contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) } + it { is_expected.to contain_class('aodh::deps') } it { is_expected.to contain_class('aodh::params') } it { is_expected.to contain_class('apache') } it { is_expected.to contain_class('apache::mod::wsgi') }