Merge "Add hooks for external install & svc management"

This commit is contained in:
Jenkins 2016-12-09 08:19:55 +00:00 committed by Gerrit Code Review
commit a4ee5cde8c
19 changed files with 115 additions and 55 deletions

View File

@ -285,6 +285,8 @@ class ec2api::api (
$enabled = true,
) inherits ::ec2api::params {
include ::ec2api::deps
validate_bool($manage_service)
validate_string($service_name)
validate_bool($enabled)
@ -351,7 +353,4 @@ class ec2api::api (
tag => 'ec2api-service',
}
Ec2api_config <||> ~>
Service['openstack-ec2-api-service']
}

View File

@ -28,6 +28,8 @@ class ec2api::config (
$ec2api_api_paste_ini = {},
) {
include ::ec2api::deps
validate_hash($ec2api_config)
validate_hash($ec2api_api_paste_ini)

View File

@ -49,6 +49,8 @@ class ec2api::db (
$database_max_overflow = $::os_service_default,
) {
include ::ec2api::deps
validate_re($database_connection, '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
oslo::db { 'ec2api_config':

View File

@ -51,6 +51,9 @@ class ec2api::db::mysql (
$collate = 'utf8_general_ci',
$allowed_hosts = undef
) {
include ::ec2api::deps
validate_string($password)
validate_string($dbname)
validate_string($user)
@ -68,6 +71,8 @@ class ec2api::db::mysql (
allowed_hosts => $allowed_hosts,
}
::Openstacklib::Db::Mysql['ec2api'] ~>
Exec<| title == 'ec2api_db_sync' |>
Anchor['ec2api::db::begin']
~> Class['ec2api::db::mysql']
~> Anchor['ec2api::db::end']
}

View File

@ -40,8 +40,7 @@ class ec2api::db::postgresql (
$privileges = 'ALL',
) {
Class['ec2api::db::postgresql'] ->
Service<| tag == 'ec2api' |>
include ::ec2api::deps
::openstacklib::db::postgresql { 'ec2api':
password_hash => postgresql_password($user, $password),
@ -51,6 +50,8 @@ class ec2api::db::postgresql (
privileges => $privileges,
}
::Openstacklib::Db::Postgresql['ec2api'] ~>
Exec<| title == 'ec2api_db_sync' |>
Anchor['ec2api::db::begin']
~> Class['ec2api::db::postgresql']
~> Anchor['ec2api::db::end']
}

View File

@ -17,6 +17,8 @@ class ec2api::db::sync (
$system_group = 'ec2api',
) inherits ::ec2api::params {
include ::ec2api::deps
exec { 'ec2api_db_sync' :
command => 'ec2-api-manage db_sync',
path => '/usr/bin',
@ -25,17 +27,12 @@ class ec2api::db::sync (
refreshonly => true,
try_sleep => 5,
tries => 10,
subscribe => [
Anchor['ec2api::install::end'],
Anchor['ec2api::config::end'],
Anchor['ec2api::dbsync::begin']
],
notify => Anchor['ec2api::dbsync::end'],
}
Package <| title == 'ec2api' |> ~>
Exec['ec2api_db_sync']
Ec2api_config <| title == 'database/connection' |> ~>
Exec['ec2api_db_sync']
User <| title == 'ec2api' |> ->
Exec['ec2api_db_sync']
Exec['ec2api_db_sync'] ~>
Service<| tag == 'ec2api-service' |>
}

35
manifests/deps.pp Normal file
View File

@ -0,0 +1,35 @@
# == Class: ec2api::deps
#
# Ec2api anchors and dependency management
#
class ec2api::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 { 'ec2api::install::begin': }
-> Package<| tag == 'ec2api-package'|>
~> anchor { 'ec2api::install::end': }
-> anchor { 'ec2api::config::begin': }
-> Ec2api_config<||>
~> anchor { 'ec2api::config::end': }
-> anchor { 'ec2api::db::begin': }
-> anchor { 'ec2api::db::end': }
~> anchor { 'ec2api::dbsync::begin': }
-> anchor { 'ec2api::dbsync::end': }
~> anchor { 'ec2api::service::begin': }
~> Service<| tag == 'ec2api-service' |>
~> anchor { 'ec2api::service::end': }
# policy config should occur in the config block also.
Anchor['ec2api::config::begin']
-> Openstacklib::Policy::Base<||>
~> Anchor['ec2api::config::end']
# Installation or config changes will always restart services.
Anchor['ec2api::install::end'] ~> Anchor['ec2api::service::begin']
Anchor['ec2api::config::end'] ~> Anchor['ec2api::service::begin']
}

View File

@ -32,6 +32,12 @@ class ec2api (
$purge_config = false,
) inherits ::ec2api::params {
include ::ec2api::deps
include ::ec2api::config
include ::ec2api::logging
include ::ec2api::policy
include ::ec2api::db
validate_string($package_ensure)
validate_bool($package_manage)
validate_string($package_name)
@ -41,26 +47,12 @@ class ec2api (
ensure => $package_ensure,
name => $package_name,
provider => $package_provider,
tag => ['openstack', 'ec2api-package']
}
Package['ec2api'] ->
Class['ec2api::config']
}
resources { 'ec2api_config':
purge => $purge_config,
}
include '::ec2api::config'
include '::ec2api::logging'
include '::ec2api::policy'
include '::ec2api::db'
anchor { 'ec2api-start' :} ->
Class['ec2api::config'] ->
Class['ec2api::db'] ->
Class['ec2api::policy'] ->
Class['ec2api::logging'] ->
anchor { 'ec2api-end' :}
}

View File

@ -68,6 +68,9 @@ class ec2api::keystone::auth (
$admin_url = 'http://127.0.0.1:8788',
$internal_url = 'http://127.0.0.1:8788',
) inherits ::ec2api::params {
include ::ec2api::deps
validate_string($password)
validate_string($auth_name)
validate_string($email)
@ -79,18 +82,13 @@ class ec2api::keystone::auth (
$real_service_name = pick($service_name, $auth_name)
if $configure_user_role {
Keystone_user_role["${auth_name}@${tenant}"] ~>
Service <| title == 'openstack-ec2api-api-service' |>
Keystone_user_role["${auth_name}@${tenant}"] ~>
Service <| title == 'openstack-ec2-api-metadata' |>
Keystone_user_role["${auth_name}@${tenant}"] ~> Anchor['ec2api::service::end']
}
Keystone_endpoint["${region}/${real_service_name}::${service_type}"] ~>
Service <| title == 'openstack-ec2api-api-service' |>
Keystone_endpoint["${region}/${real_service_name}::${service_type}"] ~>
Service <| title == 'openstack-ec2-api-metadata' |>
if $configure_endpoint {
Keystone_endpoint["${region}/${real_service_name}::${service_type}"] ~>
Anchor['ec2api::service::end']
}
keystone::resource::service_identity { 'ec2api':
configure_user => $configure_user,

View File

@ -222,6 +222,8 @@ class ec2api::keystone::authtoken(
$token_cache_time = $::os_service_default,
) {
include ::ec2api::deps
keystone::resource::authtoken { 'ec2api_config':
username => $username,
password => $password,

View File

@ -113,6 +113,8 @@ class ec2api::logging(
$log_date_format = $::os_service_default,
) {
include ::ec2api::deps
oslo::log { 'ec2api_config':
use_stderr => $use_stderr,
use_syslog => $use_syslog,

View File

@ -92,6 +92,8 @@ class ec2api::metadata (
$enabled = true,
) inherits ::ec2api::params {
include ::ec2api::deps
validate_bool($manage_service)
validate_string($service_name)
validate_bool($enabled)
@ -128,7 +130,4 @@ class ec2api::metadata (
tag => 'ec2api-service',
}
Ec2api_config <||> ~>
Service['openstack-ec2-metadata-service']
}

View File

@ -28,6 +28,8 @@ class ec2api::policy (
$policy_path = '/etc/ec2api/policy.json',
) {
include ::ec2api::deps
validate_hash($policies)
validate_absolute_path($policy_path)

View File

@ -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.

View File

@ -54,7 +54,7 @@ describe 'ec2api::api', type: :class do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('ec2api::api') }
it { is_expected.to contain_class('ec2api::deps') }
it { is_expected.to contain_class('ec2api::params') }
config_items.each do |item|

View File

@ -8,11 +8,17 @@ describe 'ec2api::db::sync' do
describe 'with default parameters' do
exec_parameters = {
command: 'ec2-api-manage db_sync',
path: '/usr/bin',
user: 'ec2api',
group: 'ec2api',
refreshonly: true,
:command => 'ec2-api-manage db_sync',
:path =>'/usr/bin',
:user => 'ec2api',
:group => 'ec2api',
:refreshonly => true,
:subscribe => [
'Anchor[ec2api::install::end]',
'Anchor[ec2api::config::end]',
'Anchor[ec2api::dbsync::begin]'
],
:notify => 'Anchor[ec2api::dbsync::end]',
}
it { is_expected.to compile.with_all_deps }
@ -21,6 +27,8 @@ describe 'ec2api::db::sync' do
it { is_expected.to contain_class('ec2api::params') }
it { is_expected.to contain_class('ec2api::deps') }
it { is_expected.to contain_exec('ec2api_db_sync').with(exec_parameters) }
end

View File

@ -23,6 +23,8 @@ describe 'ec2api' do
it { is_expected.to contain_class('ec2api::params') }
it { is_expected.to contain_class('ec2api::deps') }
it { is_expected.to contain_class('ec2api::config') }
it { is_expected.to contain_class('ec2api::db') }

View File

@ -19,6 +19,8 @@ describe 'ec2api::keystone::auth' do
it { is_expected.to contain_class('ec2api::params') }
it { is_expected.to contain_class('ec2api::deps') }
it do
parameters = {
:configure_user => true,
@ -89,4 +91,4 @@ describe 'ec2api::keystone::auth' do
end
end
end
end

View File

@ -25,6 +25,8 @@ describe 'ec2api::metadata', type: :class do
it { is_expected.to contain_class('ec2api::metadata') }
it { is_expected.to contain_class('ec2api::deps') }
it { is_expected.to contain_class('ec2api::params') }
config_items.each do |item|