First implementation of trove::guestagent

Change-Id: I26fe3bd55474e3e83e545d304abc77caf8942a0f
This commit is contained in:
Sylvain Baubeau 2014-07-04 11:17:39 +02:00
parent 6cad2a1474
commit e53fce5c92
2 changed files with 295 additions and 0 deletions

190
manifests/guestagent.pp Normal file
View File

@ -0,0 +1,190 @@
# == Class: trove::guestagent
#
# Manages trove guest agent package and service
#
# === Parameters:
#
# [*enabled*]
# (optional) Whether to enable the trove guest agent service
# Defaults to true
#
# [*manage_service*]
# (optional) Whether to start/stop the service
# Defaults to true
#
# [*ensure_package*]
# (optional) The state of the trove guest agent package
# Defaults to 'present'
#
# [*verbose*]
# (optional) Rather to log the trove guest agent service at verbose level.
# Default: false
#
# [*debug*]
# (optional) Rather to log the trove guest agent service at debug level.
# Default: false
#
# [*log_file*]
# (optional) The path of file used for logging
# If set to boolean false, it will not log to any file.
# Default: /var/log/trove/guestagent.log
#
# [*log_dir*]
# (optional) directory to which trove logs are sent.
# If set to boolean false, it will not log to any directory.
# Defaults to '/var/log/trove'
#
# [*use_syslog*]
# (optional) Use syslog for logging.
# Defaults to false.
#
# [*log_facility*]
# (optional) Syslog facility to receive log lines.
# Defaults to 'LOG_USER'.
#
# [*auth_url*]
# (optional) Authentication URL.
# Defaults to 'http://localhost:5000/v2.0'.
#
# [*swift_url*]
# (optional) Swift URL.
# Defaults to 'http://localhost:8080/v1/AUTH_'.
#
# [*control_exchange*]
# (optional) Control exchange.
# Defaults to 'trove'.
#
class trove::guestagent(
$enabled = true,
$manage_service = true,
$ensure_package = 'present',
$verbose = false,
$debug = false,
$log_file = '/var/log/trove/guestagent.log',
$log_dir = '/var/log/trove',
$use_syslog = false,
$log_facility = 'LOG_USER',
$auth_url = 'http://localhost:5000/v2.0',
$swift_url = 'http://localhost:8080/v1/AUTH_',
$control_exchange = 'trove'
) inherits trove {
include trove::params
Package[$::trove::params::guestagent_package_name] -> Trove_guestagent_config<||>
Trove_guestagent_config<||> ~> Exec['post-trove_config']
Trove_guestagent_config<||> ~> Service['trove-guestagent']
# basic service config
trove_guestagent_config {
'DEFAULT/verbose': value => $verbose;
'DEFAULT/debug': value => $debug;
'DEFAULT/trove_auth_url': value => $auth_url;
'DEFAULT/swift_url': value => $swift_url;
'DEFAULT/nova_proxy_admin_user': value => $::trove::nova_proxy_admin_user;
'DEFAULT/nova_proxy_admin_tenant_name': value => $::trove::nova_proxy_admin_tenant_name;
'DEFAULT/nova_proxy_admin_pass': value => $::trove::nova_proxy_admin_pass;
'DEFAULT/control_exchange': value => $control_exchange;
}
if $::trove::rpc_backend == 'trove.openstack.common.rpc.impl_kombu' {
# I may want to support exporting and collecting these
trove_guestagent_config {
'DEFAULT/rabbit_password': value => $::trove::rabbit_password, secret => true;
'DEFAULT/rabbit_userid': value => $::trove::rabbit_userid;
'DEFAULT/rabbit_virtual_host': value => $::trove::rabbit_virtual_host;
'DEFAULT/rabbit_use_ssl': value => $::trove::rabbit_use_ssl;
'DEFAULT/amqp_durable_queues': value => $::trove::amqp_durable_queues;
'DEFAULT/rabbit_notification_topic': value => $::trove::rabbit_notification_topic;
}
if $::trove::rabbit_use_ssl {
trove_guestagent_config {
'DEFAULT/kombu_ssl_ca_certs': value => $::trove::kombu_ssl_ca_certs;
'DEFAULT/kombu_ssl_certfile': value => $::trove::kombu_ssl_certfile;
'DEFAULT/kombu_ssl_keyfile': value => $::trove::kombu_ssl_keyfile;
'DEFAULT/kombu_ssl_version': value => $::trove::kombu_ssl_version;
}
} else {
trove_guestagent_config {
'DEFAULT/kombu_ssl_ca_certs': ensure => absent;
'DEFAULT/kombu_ssl_certfile': ensure => absent;
'DEFAULT/kombu_ssl_keyfile': ensure => absent;
'DEFAULT/kombu_ssl_version': ensure => absent;
}
}
if $::trove::rabbit_hosts {
trove_guestagent_config {
'DEFAULT/rabbit_hosts': value => join($::trove::rabbit_hosts, ',');
'DEFAULT/rabbit_ha_queues': value => true
}
} else {
trove_guestagent_config {
'DEFAULT/rabbit_host': value => $::trove::rabbit_host;
'DEFAULT/rabbit_port': value => $::trove::rabbit_port;
'DEFAULT/rabbit_hosts': value => "${::trove::rabbit_host}:${::trove::rabbit_port}";
'DEFAULT/rabbit_ha_queues': value => false
}
}
}
if $::trove::rpc_backend == 'trove.openstack.common.rpc.impl_qpid' {
trove_guestagent_config {
'DEFAULT/qpid_hostname': value => $::trove::qpid_hostname;
'DEFAULT/qpid_port': value => $::trove::qpid_port;
'DEFAULT/qpid_username': value => $::trove::qpid_username;
'DEFAULT/qpid_password': value => $::trove::qpid_password, secret => true;
'DEFAULT/qpid_heartbeat': value => $::trove::qpid_heartbeat;
'DEFAULT/qpid_protocol': value => $::trove::qpid_protocol;
'DEFAULT/qpid_tcp_nodelay': value => $::trove::qpid_tcp_nodelay;
}
if is_array($::trove::qpid_sasl_mechanisms) {
trove_guestagent_config {
'DEFAULT/qpid_sasl_mechanisms': value => join($::trove::qpid_sasl_mechanisms, ' ');
}
}
}
# Logging
if $log_file {
trove_guestagent_config {
'DEFAULT/log_file': value => $log_file;
}
} else {
trove_guestagent_config {
'DEFAULT/log_file': ensure => absent;
}
}
if $log_dir {
trove_guestagent_config {
'DEFAULT/log_dir': value => $log_dir;
}
} else {
trove_guestagent_config {
'DEFAULT/log_dir': ensure => absent;
}
}
# Syslog
if $use_syslog {
trove_guestagent_config {
'DEFAULT/use_syslog' : value => true;
'DEFAULT/syslog_log_facility' : value => $log_facility;
}
} else {
trove_guestagent_config {
'DEFAULT/use_syslog': value => false;
}
}
trove::generic_service { 'guestagent':
enabled => $enabled,
manage_service => $manage_service,
package_name => $::trove::params::guestagent_package_name,
service_name => $::trove::params::guestagent_service_name,
ensure_package => $ensure_package,
}
}

View File

@ -0,0 +1,105 @@
require 'spec_helper'
describe 'trove::guestagent' do
shared_examples 'trove-guestagent' do
context 'with default parameters' do
let :pre_condition do
"class { 'trove':
nova_proxy_admin_pass => 'verysecrete'}"
end
it 'installs trove-guestagent package and service' do
should contain_service('trove-guestagent').with(
:name => platform_params[:guestagent_service_name],
:ensure => 'running',
:hasstatus => true,
:enable => true
)
should contain_package('trove-guestagent').with(
:name => platform_params[:guestagent_package_name],
:ensure => 'present',
:notify => 'Service[trove-guestagent]'
)
end
it 'configures trove-guestagent with default parameters' do
should contain_trove_guestagent_config('DEFAULT/verbose').with_value(false)
should contain_trove_guestagent_config('DEFAULT/debug').with_value(false)
should contain_trove_guestagent_config('DEFAULT/nova_proxy_admin_user').with_value('admin')
should contain_trove_guestagent_config('DEFAULT/nova_proxy_admin_pass').with_value('verysecrete')
should contain_trove_guestagent_config('DEFAULT/nova_proxy_admin_tenant_name').with_value('admin')
end
context 'when using a single RabbitMQ server' do
let :pre_condition do
"class { 'trove':
nova_proxy_admin_pass => 'verysecrete',
rabbit_host => '10.0.0.1'}"
end
it 'configures trove-guestagent with RabbitMQ' do
should contain_trove_guestagent_config('DEFAULT/rabbit_host').with_value('10.0.0.1')
end
end
context 'when using multiple RabbitMQ servers' do
let :pre_condition do
"class { 'trove':
nova_proxy_admin_pass => 'verysecrete',
rabbit_hosts => ['10.0.0.1','10.0.0.2']}"
end
it 'configures trove-guestagent with RabbitMQ' do
should contain_trove_guestagent_config('DEFAULT/rabbit_hosts').with_value(['10.0.0.1,10.0.0.2'])
end
end
end
context 'with custom parameters' do
let :pre_condition do
"class { 'trove':
nova_proxy_admin_pass => 'verysecrete'}"
end
let :params do
{ :auth_url => "http://10.0.0.1:5000/v2.0",
:swift_url => "http://10.0.0.1:8080/v1/AUTH_" }
end
it 'configures trove-guestagent with custom parameters' do
should contain_trove_guestagent_config('DEFAULT/trove_auth_url').with_value('http://10.0.0.1:5000/v2.0')
should contain_trove_guestagent_config('DEFAULT/swift_url').with_value('http://10.0.0.1:8080/v1/AUTH_')
end
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian',
:processorcount => 8 }
end
let :platform_params do
{ :guestagent_package_name => 'trove-guestagent',
:guestagent_service_name => 'trove-guestagent' }
end
it_configures 'trove-guestagent'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat',
:processorcount => 8 }
end
let :platform_params do
{ :guestagent_package_name => 'openstack-trove-guestagent',
:guestagent_service_name => 'openstack-trove-guestagent' }
end
it_configures 'trove-guestagent'
end
end