From dca9fe942b99b9c30e31167e4736058767738f21 Mon Sep 17 00:00:00 2001 From: Clayton O'Neill Date: Tue, 20 Oct 2015 09:54:12 -0400 Subject: [PATCH] Move deps & external hooks into a standalone class Previously the anchors and dependencies that allow external hooks were all in the main ::heat class. However, if you wanted to include just ::heat::db::mysql, then it would fail, since it assumed the main heat class was included. This moves all of those resources and relationships into a new class, ::heat::deps. All of the classes will now include this class so that the anchors and deps are always evaluated even if only a portion of the classes are used, and even if ::heat isn't pulled in. Change-Id: I4297df160a7afae2b66c1ac76e37de313fa4fb09 Closes-Bug: #1507934 --- manifests/api.pp | 1 + manifests/api_cfn.pp | 1 + manifests/api_cloudwatch.pp | 1 + manifests/client.pp | 1 + manifests/config.pp | 2 ++ manifests/db.pp | 2 ++ manifests/db/mysql.pp | 2 ++ manifests/db/postgresql.pp | 2 ++ manifests/db/sync.pp | 1 + manifests/deps.pp | 30 ++++++++++++++++++++++++++++++ manifests/engine.pp | 2 ++ manifests/init.pp | 26 +------------------------- manifests/keystone/auth.pp | 2 ++ manifests/keystone/auth_cfn.pp | 2 ++ manifests/keystone/domain.pp | 1 + manifests/logging.pp | 2 ++ manifests/policy.pp | 2 ++ spec/classes/heat_deps_spec.rb | 17 +++++++++++++++++ 18 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 manifests/deps.pp create mode 100644 spec/classes/heat_deps_spec.rb diff --git a/manifests/api.pp b/manifests/api.pp index 37b8da2d..49ef142a 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -59,6 +59,7 @@ class heat::api ( ) { include ::heat + include ::heat::deps include ::heat::params include ::heat::policy diff --git a/manifests/api_cfn.pp b/manifests/api_cfn.pp index cc6a5798..acc7c04f 100644 --- a/manifests/api_cfn.pp +++ b/manifests/api_cfn.pp @@ -62,6 +62,7 @@ class heat::api_cfn ( ) { include ::heat + include ::heat::deps include ::heat::params include ::heat::policy diff --git a/manifests/api_cloudwatch.pp b/manifests/api_cloudwatch.pp index 94097908..bf313b72 100644 --- a/manifests/api_cloudwatch.pp +++ b/manifests/api_cloudwatch.pp @@ -61,6 +61,7 @@ class heat::api_cloudwatch ( ) { include ::heat + include ::heat::deps include ::heat::params include ::heat::policy diff --git a/manifests/client.pp b/manifests/client.pp index 3fdd35fa..67035d94 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -11,6 +11,7 @@ class heat::client ( $ensure = 'present' ) { + include ::heat::deps include ::heat::params package { 'python-heatclient': diff --git a/manifests/config.pp b/manifests/config.pp index 2425fa4f..173744d1 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -24,6 +24,8 @@ class heat::config ( $heat_config = {}, ) { + include ::heat::deps + validate_hash($heat_config) create_resources('heat_config', $heat_config) diff --git a/manifests/db.pp b/manifests/db.pp index 7d1fce5d..4a691bf3 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -48,6 +48,8 @@ class heat::db ( $sync_db = true, ) { + include ::heat::deps + # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function # to use heat:: if heat::db:: isn't specified. $database_connection_real = pick($::heat::database_connection, $database_connection) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index de56e497..e27cab42 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -50,6 +50,8 @@ class heat::db::mysql( $mysql_module = undef ) { + include ::heat::deps + if $mysql_module { warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.') } diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index 3cd9fcf4..9307df3f 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -32,6 +32,8 @@ class heat::db::postgresql( $privileges = 'ALL', ) { + include ::heat::deps + ::openstacklib::db::postgresql { 'heat': password_hash => postgresql_password($user, $password), dbname => $dbname, diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index 8944da9d..4703cf90 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -3,6 +3,7 @@ # class heat::db::sync { + include ::heat::deps include ::heat::params exec { 'heat-dbsync': diff --git a/manifests/deps.pp b/manifests/deps.pp new file mode 100644 index 00000000..213af22f --- /dev/null +++ b/manifests/deps.pp @@ -0,0 +1,30 @@ +# == Class: heat::deps +# +# Heat anchors and dependency management +# +class heat::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 { 'heat::install::begin': } + -> Package<| tag == 'heat-package'|> + ~> anchor { 'heat::install::end': } + -> anchor { 'heat::config::begin': } + -> Heat_config<||> + ~> anchor { 'heat::config::end': } + -> anchor { 'heat::db::begin': } + -> anchor { 'heat::db::end': } + ~> anchor { 'heat::dbsync::begin': } + -> anchor { 'heat::dbsync::end': } + ~> anchor { 'heat::service::begin': } + ~> Service<| tag == 'heat-service' |> + ~> anchor { 'heat::service::end': } + + # Installation or config changes will always restart services. + Anchor['heat::install::end'] ~> Anchor['heat::service::begin'] + Anchor['heat::config::end'] ~> Anchor['heat::service::begin'] +} diff --git a/manifests/engine.pp b/manifests/engine.pp index abf48d0b..e29483d7 100644 --- a/manifests/engine.pp +++ b/manifests/engine.pp @@ -93,6 +93,8 @@ class heat::engine ( $trusts_delegated_roles = ['heat_stack_owner'], ) { + include ::heat::deps + # Validate Heat Engine AES key # must be either 16, 24, or 32 bytes long # https://bugs.launchpad.net/heat/+bug/1415887 diff --git a/manifests/init.pp b/manifests/init.pp index 22fd324c..2532ae17 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -299,6 +299,7 @@ class heat( include ::heat::logging include ::heat::db + include ::heat::deps include ::heat::params if $kombu_ssl_ca_certs and !$rabbit_use_ssl { @@ -544,29 +545,4 @@ class heat( } else { heat_config { 'DEFAULT/enable_stack_abandon': ensure => absent; } } - - # 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 { 'heat::install::begin': } - -> Package<| tag == 'heat-package'|> - ~> anchor { 'heat::install::end': } - -> anchor { 'heat::config::begin': } - -> Heat_config<||> - ~> anchor { 'heat::config::end': } - -> anchor { 'heat::db::begin': } - -> anchor { 'heat::db::end': } - ~> anchor { 'heat::dbsync::begin': } - -> anchor { 'heat::dbsync::end': } - ~> anchor { 'heat::service::begin': } - ~> Service<| tag == 'heat-service' |> - ~> anchor { 'heat::service::end': } - - # Installation or config changes will always restart services. - Anchor['heat::install::end'] ~> Anchor['heat::service::begin'] - Anchor['heat::config::end'] ~> Anchor['heat::service::begin'] } diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index b5b02154..7e819af1 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -168,6 +168,8 @@ class heat::keystone::auth ( $admin_address = undef, ) { + include ::heat::deps + validate_string($password) if $version { diff --git a/manifests/keystone/auth_cfn.pp b/manifests/keystone/auth_cfn.pp index 5f97534d..3414a7f1 100644 --- a/manifests/keystone/auth_cfn.pp +++ b/manifests/keystone/auth_cfn.pp @@ -137,6 +137,8 @@ class heat::keystone::auth_cfn ( $admin_address = undef, ) { + include ::heat::deps + validate_string($password) if $version { diff --git a/manifests/keystone/domain.pp b/manifests/keystone/domain.pp index 3d7750e3..a28b68ae 100644 --- a/manifests/keystone/domain.pp +++ b/manifests/keystone/domain.pp @@ -49,6 +49,7 @@ class heat::keystone::domain ( $keystone_tenant = undef, ) { + include ::heat::deps include ::heat::params if $auth_url { diff --git a/manifests/logging.pp b/manifests/logging.pp index 745b80b5..426c14a6 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -110,6 +110,8 @@ class heat::logging( $log_date_format = undef, ) { + include ::heat::deps + # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function # to use heat:: first then heat::logging::. $use_syslog_real = pick($::heat::use_syslog,$use_syslog) diff --git a/manifests/policy.pp b/manifests/policy.pp index 11ff910e..1f575d94 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -23,6 +23,8 @@ class heat::policy ( $policy_path = '/etc/heat/policy.json', ) { + include ::heat::deps + validate_hash($policies) Openstacklib::Policy::Base { diff --git a/spec/classes/heat_deps_spec.rb b/spec/classes/heat_deps_spec.rb new file mode 100644 index 00000000..11bb63d2 --- /dev/null +++ b/spec/classes/heat_deps_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'heat::deps' do + + it 'set up the anchors' do + is_expected.to contain_anchor('heat::install::begin') + is_expected.to contain_anchor('heat::install::end') + is_expected.to contain_anchor('heat::config::begin') + is_expected.to contain_anchor('heat::config::end') + is_expected.to contain_anchor('heat::db::begin') + is_expected.to contain_anchor('heat::db::end') + is_expected.to contain_anchor('heat::dbsync::begin') + is_expected.to contain_anchor('heat::dbsync::end') + is_expected.to contain_anchor('heat::service::begin') + is_expected.to contain_anchor('heat::service::end') + end +end