Implement api.pp

Deploy Octavia API.

Change-Id: I5947f8d3fd060e043e8f1b3563d2ee9c371da406
This commit is contained in:
Emilien Macchi 2016-06-06 17:20:35 -04:00
parent b8a280f5ea
commit 6f701d6b38
4 changed files with 247 additions and 0 deletions

109
manifests/api.pp Normal file
View File

@ -0,0 +1,109 @@
# Installs & configure the octavia service
#
# == Parameters
#
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
# [*keystone_user*]
# (optional) The name of the auth user
# Defaults to octavia
#
# [*keystone_tenant*]
# (optional) Tenant to authenticate with.
# Defaults to 'services'.
#
# [*keystone_password*]
# (Required) Password to authenticate with.
#
# [*keystone_auth_uri*]
# (optional) Public Identity API endpoint.
# Defaults to 'http://127.0.0.0:5000'.
#
# [*keystone_identity_uri*]
# (optional) Complete admin Identity API endpoint.
# Defaults to: $::os_service_default
#
# [*host*]
# (optional) The octavia api bind address.
# Defaults to 0.0.0.0
#
# [*port*]
# (optional) The octavia api port.
# Defaults to 9876
#
# [*package_ensure*]
# (optional) ensure state for package.
# Defaults to 'present'
#
# [*sync_db*]
# (optional) Run octavia-db-manage upgrade head on api nodes after installing the package.
# Defaults to false
class octavia::api (
$keystone_password,
$manage_service = true,
$enabled = true,
$package_ensure = 'present',
$keystone_user = 'octavia',
$keystone_tenant = 'services',
$keystone_auth_uri = 'http://127.0.0.0:5000',
$keystone_identity_uri = $::os_service_default,
$host = '0.0.0.0',
$port = '9876',
$sync_db = false,
) inherits octavia::params {
include ::octavia::policy
validate_string($keystone_password)
Octavia_config<||> ~> Service['octavia-api']
Class['octavia::policy'] ~> Service['octavia-api']
Package['octavia-api'] -> Service['octavia-api']
Package['octavia-api'] -> Class['octavia::policy']
package { 'octavia-api':
ensure => $package_ensure,
name => $::octavia::params::api_package_name,
tag => ['openstack', 'octavia-package'],
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}
if $sync_db {
include ::octavia::db::sync
}
service { 'octavia-api':
ensure => $service_ensure,
name => $::octavia::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
require => Class['octavia::db'],
tag => ['octavia-service', 'octavia-db-sync-service'],
}
octavia_config {
'keystone_authtoken/auth_uri' : value => $keystone_auth_uri;
'keystone_authtoken/admin_tenant_name' : value => $keystone_tenant;
'keystone_authtoken/admin_user' : value => $keystone_user;
'keystone_authtoken/admin_password' : value => $keystone_password, secret => true;
'keystone_authtoken/identity_uri' : value => $keystone_identity_uri;
'api/host' : value => $host;
'api/port' : value => $port;
}
}

View File

@ -2,12 +2,15 @@
#
class octavia::params {
$api_service_name = 'octavia-api'
case $::osfamily {
'RedHat': {
$common_package_name = 'openstack-octavia-common'
$api_package_name = 'openstack-octavia-api'
}
'Debian': {
$common_package_name = 'octavia-common'
$api_package_name = 'octavia-api'
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem")

View File

@ -47,6 +47,9 @@ describe 'basic octavia' do
rabbit_password => 'an_even_bigger_secret',
rabbit_host => '127.0.0.1',
}
class { '::octavia::api':
keystone_password => 'a_big_secret',
}
}
EOS

View File

@ -0,0 +1,132 @@
require 'spec_helper'
describe 'octavia::api' do
let :pre_condition do
"class { 'octavia': }
include ::octavia::db"
end
let :params do
{ :enabled => true,
:manage_service => true,
:keystone_auth_uri => 'http://127.0.0.0:5000',
:keystone_password => 'octavia-passw0rd',
:keystone_tenant => 'services',
:keystone_user => 'octavia',
:package_ensure => 'latest',
:port => '9876',
:host => '0.0.0.0',
}
end
shared_examples_for 'octavia-api' do
context 'without required parameter keystone_password' do
before { params.delete(:keystone_password) }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
it { is_expected.to contain_class('octavia::params') }
it { is_expected.to contain_class('octavia::policy') }
it 'installs octavia-api package' do
is_expected.to contain_package('octavia-api').with(
:ensure => 'latest',
:name => platform_params[:api_package_name],
:tag => ['openstack', 'octavia-package'],
)
end
it 'configures keystone authentication middleware' do
is_expected.to contain_octavia_config('keystone_authtoken/auth_uri').with_value( params[:keystone_auth_uri] )
is_expected.to contain_octavia_config('keystone_authtoken/admin_tenant_name').with_value( params[:keystone_tenant] )
is_expected.to contain_octavia_config('keystone_authtoken/admin_user').with_value( params[:keystone_user] )
is_expected.to contain_octavia_config('keystone_authtoken/admin_password').with_value( params[:keystone_password] )
is_expected.to contain_octavia_config('keystone_authtoken/admin_password').with_value( params[:keystone_password] ).with_secret(true)
is_expected.to contain_octavia_config('api/host').with_value( params[:host] )
is_expected.to contain_octavia_config('api/port').with_value( params[:port] )
end
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
before do
params.merge!(param_hash)
end
it 'configures octavia-api service' do
is_expected.to contain_service('octavia-api').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
:hasrestart => true,
:require => 'Class[Octavia::Db]',
:tag => ['octavia-service', 'octavia-db-sync-service'],
)
end
end
end
context 'with sync_db set to true' do
before do
params.merge!({
:sync_db => true})
end
it { is_expected.to contain_class('octavia::db::sync') }
end
context 'with disabled service managing' do
before do
params.merge!({
:manage_service => false,
:enabled => false })
end
it 'configures octavia-api service' do
is_expected.to contain_service('octavia-api').with(
:ensure => nil,
:name => platform_params[:api_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => ['octavia-service', 'octavia-db-sync-service'],
)
end
end
context 'with custom identity_uri' do
before do
params.merge!({
:keystone_identity_uri => 'https://foo.bar:1234/',
})
end
it 'should configure custom identity_uri correctly' do
is_expected.to contain_octavia_config('keystone_authtoken/identity_uri').with_value( 'https://foo.bar:1234/' )
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
let(:platform_params) do
case facts[:osfamily]
when 'Debian'
{ :api_package_name => 'octavia-api',
:api_service_name => 'octavia-api' }
when 'RedHat'
{ :api_package_name => 'openstack-octavia-api',
:api_service_name => 'octavia-api' }
end
end
it_behaves_like 'octavia-api'
end
end
end