From c31b7364dbab01e0e852d1553835023e452e26b6 Mon Sep 17 00:00:00 2001 From: Peter Zhurba Date: Fri, 30 Sep 2016 11:49:51 +0300 Subject: [PATCH] Add hooks for external install & svc management 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. Change-Id: I374c60ca08176d85c7b0c0efbdc481205d763376 Co-Authored-By: Clayton O'Neill --- manifests/config.pp | 1 + manifests/db.pp | 1 + manifests/db/mysql.pp | 5 ++++ manifests/db/postgresql.pp | 4 +++ manifests/db/sync.pp | 11 ++++++-- manifests/deps.pp | 50 +++++++++++++++++++++++++++++++++ manifests/init.pp | 5 +++- manifests/keystone/auth.pp | 1 + manifests/keystone/authtoken.pp | 1 + manifests/logging.pp | 1 + manifests/policy.pp | 1 + 11 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 manifests/deps.pp diff --git a/manifests/config.pp b/manifests/config.pp index 365051a..1a730f5 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -23,6 +23,7 @@ class glare::config ( $glare_config = {}, ) { + include ::glare::deps validate_hash($glare_config) diff --git a/manifests/db.pp b/manifests/db.pp index df25eb8..cb12e1b 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -42,6 +42,7 @@ class glare::db ( $database_retry_interval = $::os_service_default, $database_max_overflow = $::os_service_default, ) { + include ::glare::deps validate_re($database_connection, '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 1c018da..9f47ba9 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -52,6 +52,7 @@ class glare::db::mysql( $collate = 'utf8_general_ci', $allowed_hosts = undef ) { + include ::glare::deps validate_string($password) @@ -66,4 +67,8 @@ class glare::db::mysql( } ::Openstacklib::Db::Mysql['glare'] ~> Exec<| title == 'glare-db-sync' |> + + Anchor['glare::db::begin'] + ~> Class['glare::db::mysql'] + ~> Anchor['glare::db::end'] } diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index 6db865a..88a421b 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -39,6 +39,7 @@ class glare::db::postgresql( $encoding = undef, $privileges = 'ALL', ) { + include ::glare::deps Class['glare::db::postgresql'] -> Service<| title == 'glare' |> @@ -51,5 +52,8 @@ class glare::db::postgresql( } ::Openstacklib::Db::Postgresql['glare'] ~> Exec<| title == 'glare-db-sync' |> + Anchor['glare::db::begin'] + ~> Class['glare::db::postgresql'] + ~> Anchor['glare::db::end'] } diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index 36b12be..c80c888 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -12,14 +12,19 @@ class glare::db::sync( $extra_params = '', ) { + include ::glare::deps + exec { 'glare-db-sync': command => "glare-db-manage ${extra_params} upgrade", user => 'glare', path => [ '/bin/', '/usr/bin/' , '/usr/local/bin' ], refreshonly => true, - try_sleep => 5, - tries => 10, - subscribe => [Package['glare'], Glare_config['database/connection']], + subscribe => [ + Anchor['glare::install::end'], + Anchor['glare::config::end'], + Anchor['glare::dbsync::begin'] + ], + notify => Anchor['glare::dbsync::end'], } Exec['glare-db-sync'] ~> Service<| title == 'glare' |> } diff --git a/manifests/deps.pp b/manifests/deps.pp new file mode 100644 index 0000000..8a415b4 --- /dev/null +++ b/manifests/deps.pp @@ -0,0 +1,50 @@ +# == Class: glare::deps +# +# glare anchors and dependency management +# +class glare::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 { 'glare::install::begin': } + -> Package<| tag == 'glare'|> + ~> anchor { 'glare::install::end': } + -> anchor { 'glare::config::begin': } + -> File<| tag == 'glare-config-file' |> + ~> anchor { 'glare::config::end': } + -> anchor { 'glare::db::begin': } + -> anchor { 'glare::db::end': } + ~> anchor { 'glare::dbsync::begin': } + -> anchor { 'glare::dbsync::end': } + ~> anchor { 'glare::service::begin': } + ~> Service<| tag == 'glare' |> + ~> anchor { 'glare::service::end': } + + # Ensure files are modified in the config block + Anchor['glare::config::begin'] + -> File_line<| tag == 'glare-file-line' |> + ~> Anchor['glare::config::end'] + + # Ensure all files are in place before modifying them + File<| tag == 'glare-config-file' |> -> File_line<| tag == 'glare-file-line' |> + + # All other inifile providers need to be processed in the config block + Anchor['glare::config::begin'] -> Glare_config<||> ~> Anchor['glare::config::end'] + Anchor['glare::config::begin'] -> Glare_paste_ini<||> ~> Anchor['glare::config::end'] + + # Support packages need to be installed in the install phase, but we don't + # put them in the chain above because we don't want any false dependencies + # between packages with the glare-package tag and the glare-support-package + # tag. Note: the package resources here will have a 'before' relationshop on + # the glare::install::end anchor. The line between glare-support-package and + # glare-package should be whether or not glare services would need to be + # restarted if the package state was changed. + + # Installation or config changes will always restart services. + Anchor['glare::install::end'] ~> Anchor['glare::service::begin'] + Anchor['glare::config::end'] ~> Anchor['glare::service::begin'] +} diff --git a/manifests/init.pp b/manifests/init.pp index a80f2ac..ec96277 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -112,10 +112,12 @@ class glare ( include ::glare::params include ::glare::db include ::glare::logging + include ::glare::deps ensure_packages ( 'glare' , { ensure => $package_ensure, name => $::glare::params::glare_package_name, + tag => ['openstack', 'glare-package'], }) glare_config { @@ -171,6 +173,7 @@ class glare ( service { 'glare': ensure => $service_ensure, name => $::glare::params::glare_service_name, - enable => $enabled + enable => $enabled, + tag => 'glare', } } diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index 0997cb7..38644a2 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -68,6 +68,7 @@ class glare::keystone::auth ( $admin_url = 'http://127.0.0.1:FIXME', $internal_url = 'http://127.0.0.1:FIXME', ) { + include ::glare::deps if $configure_user_role { Keystone_user_role["${auth_name}@${tenant}"] ~> Service <| name == 'glare-server' |> diff --git a/manifests/keystone/authtoken.pp b/manifests/keystone/authtoken.pp index 62112fe..f6bf4d4 100644 --- a/manifests/keystone/authtoken.pp +++ b/manifests/keystone/authtoken.pp @@ -221,6 +221,7 @@ class glare::keystone::authtoken( $signing_dir = $::os_service_default, $token_cache_time = $::os_service_default, ) { + include ::glare::deps keystone::resource::authtoken { 'glare_config': username => $username, diff --git a/manifests/logging.pp b/manifests/logging.pp index c047384..a301d72 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -112,6 +112,7 @@ class glare::logging( $instance_uuid_format = $::os_service_default, $log_date_format = $::os_service_default, ) { + include ::glare::deps oslo::log { 'glare_config': use_stderr => $use_stderr, diff --git a/manifests/policy.pp b/manifests/policy.pp index 0d6a6a1..d0232f8 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -27,6 +27,7 @@ class glare::policy ( $policies = {}, $policy_path = '/etc/glare/policy.json', ) { + include ::glare::deps validate_hash($policies)