Service Validation for Cinder-API

As an option, validate Cinder API service with a default or custom
command, and if the service is up and running, create a Puppet Anchor.

Change-Id: I602563420d915ce2b553c8bccca6f1260403d168
This commit is contained in:
Emilien Macchi 2014-12-08 18:55:33 -05:00
parent aaf023d2a8
commit 62823628ca
2 changed files with 76 additions and 3 deletions

View File

@ -86,6 +86,27 @@
# If not configured, it produces an error when creating a volume
# without specifying a type.
# Defaults to 'false'.
#
# [*validate*]
# (optional) Whether to validate the service is working after any service refreshes
# Defaults to false
#
# [*validation_options*]
# (optional) Service validation options
# Should be a hash of options defined in openstacklib::service_validation
# If empty, defaults values are taken from openstacklib function.
# Default command list volumes.
# Require validate set at True.
# Example:
# glance::api::validation_options:
# glance-api:
# command: check_cinder-api.py
# path: /usr/bin:/bin:/usr/sbin:/sbin
# provider: shell
# tries: 5
# try_sleep: 10
# Defaults to {}
#
class cinder::api (
$keystone_password,
$keystone_enabled = true,
@ -106,7 +127,9 @@ class cinder::api (
$ratelimits = undef,
$default_volume_type = false,
$ratelimits_factory =
'cinder.api.v1.limits:RateLimitingMiddleware.factory'
'cinder.api.v1.limits:RateLimitingMiddleware.factory',
$validate = false,
$validation_options = {},
) {
include cinder::params
@ -168,10 +191,11 @@ class cinder::api (
}
if $keystone_auth_uri {
cinder_api_paste_ini { 'filter:authtoken/auth_uri': value => $keystone_auth_uri; }
$auth_uri = $keystone_auth_uri
} else {
cinder_api_paste_ini { 'filter:authtoken/auth_uri': value => "${keystone_auth_protocol}://${keystone_auth_host}:${service_port}/"; }
$auth_uri = "${keystone_auth_protocol}://${keystone_auth_host}:${service_port}/"
}
cinder_api_paste_ini { 'filter:authtoken/auth_uri': value => $auth_uri; }
if $keystone_enabled {
cinder_config {
@ -218,4 +242,14 @@ class cinder::api (
}
}
if $validate {
$defaults = {
'cinder-api' => {
'command' => "cinder --os-auth-url ${auth_uri} --os-tenant-name ${keystone_tenant} --os-username ${keystone_user} --os-password ${keystone_password} list",
}
}
$validation_options_hash = merge ($defaults, $validation_options)
create_resources('openstacklib::service_validation', $validation_options_hash, {'subscribe' => 'Service[cinder-api]'})
}
}

View File

@ -184,4 +184,43 @@ describe 'cinder::api' do
)}
end
describe 'while validating the service with default command' do
let :params do
req_params.merge({
:validate => true,
})
end
it { should contain_exec('execute cinder-api validation').with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell',
:tries => '10',
:try_sleep => '2',
:command => 'cinder --os-auth-url http://localhost:5000/ --os-tenant-name services --os-username cinder --os-password foo list',
)}
it { should contain_anchor('create cinder-api anchor').with(
:require => 'Exec[execute cinder-api validation]',
)}
end
describe 'while validating the service with custom command' do
let :params do
req_params.merge({
:validate => true,
:validation_options => { 'cinder-api' => { 'command' => 'my-script' } }
})
end
it { should contain_exec('execute cinder-api validation').with(
:path => '/usr/bin:/bin:/usr/sbin:/sbin',
:provider => 'shell',
:tries => '10',
:try_sleep => '2',
:command => 'my-script',
)}
it { should contain_anchor('create cinder-api anchor').with(
:require => 'Exec[execute cinder-api validation]',
)}
end
end