Refactor nova services to use generic_service
Previously, there was a lot of copy/paste code for handling the various nova services. This commit creates the define nova::generic_service which is used to capture common code for configuring nova services. It also updates the following classes to use that code: - nova::api - nova::cert - nova::compute - nova::objectstore - nova::network - nova::sceduler - nova::volume It also updates spec tests for all of these classes
This commit is contained in:
parent
7a14a659b1
commit
616c4763c7
@ -1,34 +1,21 @@
|
||||
class nova::api($enabled=false) {
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-api']
|
||||
Exec['nova-db-sync'] ~> Service['nova-api']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
}
|
||||
class nova::api(
|
||||
$enabled=false
|
||||
) inherits nova {
|
||||
|
||||
# TODO what exactly is this for?
|
||||
# This resource is adding a great deal of comlexity to the overall
|
||||
# modules. Removing it would be great
|
||||
exec { "initial-db-sync":
|
||||
command => "/usr/bin/nova-manage db sync",
|
||||
refreshonly => true,
|
||||
require => [Package[$::nova::params::common_package_name], Nova_config['sql_connection']],
|
||||
}
|
||||
|
||||
if($::nova::params::api_package_name != undef) {
|
||||
package { 'nova-api':
|
||||
name => $::nova::params::api_package_name,
|
||||
ensure => present,
|
||||
notify => Service['nova-api'],
|
||||
before => Exec['initial-db-sync']
|
||||
}
|
||||
}
|
||||
Package<| title == 'nova-api' |> -> Exec['initial-db-sync']
|
||||
|
||||
service { "nova-api":
|
||||
name => $::nova::params::api_service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package[$::nova::params::common_package_name],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
nova::generic_service { 'api':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::api_package_name,
|
||||
service_name => $::nova::params::api_service_name,
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,11 @@
|
||||
class nova::cert( $enabled=false ) {
|
||||
class nova::cert(
|
||||
$enabled=false
|
||||
) inherits nova{
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-cert']
|
||||
Exec['nova-db-sync'] ~> Service['nova-cert']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
nova::generic_service { 'cert':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::cert_package_name,
|
||||
service_name => $::nova::params::cert_service_name,
|
||||
}
|
||||
|
||||
service { "nova-cert":
|
||||
name => 'openstack-nova-cert',
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package["openstack-nova"],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
}
|
||||
}
|
||||
|
@ -2,30 +2,13 @@
|
||||
# from the virtualization implementation of the compute node
|
||||
class nova::compute(
|
||||
$enabled = false,
|
||||
) {
|
||||
) inherits nova {
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-compute']
|
||||
Exec['nova-db-sync'] ~> Service['nova-compute']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
nova::generic_service { 'compute':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::compute_package_name,
|
||||
service_name => $::nova::params::compute_service_name,
|
||||
before => Exec['networking-refresh']
|
||||
}
|
||||
|
||||
if($::nova::params::compute_package_name != undef) {
|
||||
package { 'nova-compute':
|
||||
name => $::nova::params::compute_package_name,
|
||||
ensure => present,
|
||||
notify => Service['nova-compute'],
|
||||
}
|
||||
}
|
||||
|
||||
service { "nova-compute":
|
||||
name => $::nova::params::compute_service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package[$::nova::params::common_package_name],
|
||||
before => Exec['networking-refresh'],
|
||||
}
|
||||
}
|
||||
|
53
manifests/generic_service.pp
Normal file
53
manifests/generic_service.pp
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# This class implements basic nova services.
|
||||
# It is introduced to attempt to consolidate
|
||||
# common code.
|
||||
#
|
||||
# It also allows users to specify ad-hoc services
|
||||
# as needed
|
||||
#
|
||||
#
|
||||
# This define creates a service resource with title nova-${name} and
|
||||
# conditionally creates a package resource with title nova-${name}
|
||||
#
|
||||
define nova::generic_service(
|
||||
$package_name,
|
||||
$service_name,
|
||||
$enabled = false,
|
||||
) {
|
||||
|
||||
include nova::params
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
}
|
||||
|
||||
$nova_title = "nova-${name}"
|
||||
# ensure that the service is only started after
|
||||
# all nova config entries have been set
|
||||
Exec['post-nova_config'] ~> Service[$nova_title]
|
||||
# ensure that the service has only been started
|
||||
# after the initial db sync
|
||||
Exec['nova-db-sync'] ~> Service[$nova_title]
|
||||
|
||||
|
||||
# I need to mark that ths package should be
|
||||
# installed before nova_config
|
||||
if($package_name) {
|
||||
package { $nova_title:
|
||||
name => $package_name,
|
||||
ensure => present,
|
||||
notify => Service[$nova_title],
|
||||
}
|
||||
}
|
||||
|
||||
service { $nova_title:
|
||||
name => $service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package['nova-common'],
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +1,12 @@
|
||||
class nova::network( $enabled=false ) {
|
||||
class nova::network(
|
||||
$enabled=false
|
||||
) inherits nova {
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-network']
|
||||
Exec['nova-db-sync'] ~> Service['nova-network']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
nova::generic_service { 'network':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::network_package_name,
|
||||
service_name => $::nova::params::network_service_name,
|
||||
before => Exec['networking-refresh']
|
||||
}
|
||||
|
||||
if($::nova::params::network_package_name != undef) {
|
||||
package { 'nova-network':
|
||||
name => $::nova::params::network_package_name,
|
||||
ensure => present,
|
||||
notify => Service['nova-network'],
|
||||
}
|
||||
}
|
||||
|
||||
service { "nova-network":
|
||||
name => $::nova::params::network_service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package[$::nova::params::common_package_name],
|
||||
before => Exec['networking-refresh'],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,11 @@
|
||||
class nova::objectstore( $enabled=false ) {
|
||||
class nova::objectstore(
|
||||
$enabled=false
|
||||
) inherits nova {
|
||||
|
||||
include nova::params
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-objectstore']
|
||||
Exec['nova-db-sync'] ~> Service['nova-objectstore']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
nova::generic_service { 'objectstore':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::objectstore_package_name,
|
||||
service_name => $::nova::params::objectstore_service_name,
|
||||
}
|
||||
|
||||
if($::nova::params::objectstore_package_name != undef) {
|
||||
package { 'nova-objectstore':
|
||||
name => $::nova::params::objectstore_package_name,
|
||||
ensure => present,
|
||||
notify => Service['nova-objectstore'],
|
||||
}
|
||||
}
|
||||
|
||||
service { "nova-objectstore":
|
||||
name => $::nova::params::objectstore_service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package[$::nova::params::common_package_name],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,11 @@
|
||||
class nova::scheduler( $enabled = false) {
|
||||
class nova::scheduler(
|
||||
$enabled = false
|
||||
) inherits nova {
|
||||
|
||||
include nova::params
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-scheduler']
|
||||
Exec['nova-db-sync'] -> Service['nova-scheduler']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
nova::generic_service { 'scheduler':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::scheduler_package_name,
|
||||
service_name => $::nova::params::scheduler_service_name,
|
||||
}
|
||||
|
||||
if($::nova::params::scheduler_package_name != undef) {
|
||||
package { 'nova-scheduler':
|
||||
name => $::nova::params::scheduler_package_name,
|
||||
ensure => present,
|
||||
notify => Service['nova-scheduler'],
|
||||
}
|
||||
}
|
||||
|
||||
service { "nova-scheduler":
|
||||
name => $::nova::params::scheduler_service_name,
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package[$::nova::params::common_package_name],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,21 @@
|
||||
class nova::volume( $enabled=false ) {
|
||||
class nova::volume(
|
||||
$enabled=false
|
||||
) inherits nova {
|
||||
|
||||
Exec['post-nova_config'] ~> Service['nova-volume']
|
||||
Exec['nova-db-sync'] ~> Service['nova-volume']
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
}
|
||||
|
||||
exec {volumes:
|
||||
exec { 'volumes':
|
||||
command => 'dd if=/dev/zero of=/tmp/nova-volumes.img bs=1M seek=20k count=0 && /sbin/vgcreate nova-volumes `/sbin/losetup --show -f /tmp/nova-volumes.img`',
|
||||
onlyif => 'test ! -e /tmp/nova-volumes.img',
|
||||
path => ["/usr/bin", "/bin", "/usr/local/bin"],
|
||||
before => Service['nova-volume'],
|
||||
}
|
||||
|
||||
service { "nova-volume":
|
||||
name => 'openstack-nova-volume',
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
require => Package["openstack-nova"],
|
||||
#subscribe => File["/etc/nova/nova.conf"]
|
||||
ova::generic_service { 'volume':
|
||||
enabled => $enabled,
|
||||
package_name => $::nova::params::volume_package_name,
|
||||
service_name => $::nova::params::volume_service_name,
|
||||
}
|
||||
|
||||
# TODO is this fedora specific?
|
||||
service {'tgtd':
|
||||
ensure => $service_ensure,
|
||||
enable => $enabled,
|
||||
|
@ -11,19 +11,24 @@ describe 'nova::cert' do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
it { should contain_service('nova-cert').with(
|
||||
'name' => 'openstack-nova-cert',
|
||||
'name' => 'nova-cert',
|
||||
'ensure' => 'stopped',
|
||||
'enable' => false
|
||||
)}
|
||||
it { should contain_package('nova-cert').with(
|
||||
'name' => 'nova-cert',
|
||||
'ensure' => 'present',
|
||||
'notify' => 'Service[nova-cert]'
|
||||
)}
|
||||
describe 'with enabled as true' do
|
||||
let :params do
|
||||
{:enabled => true}
|
||||
end
|
||||
it { should contain_service('nova-cert').with(
|
||||
'name' => 'openstack-nova-cert',
|
||||
'ensure' => 'running',
|
||||
'enable' => true
|
||||
)}
|
||||
it { should contain_service('nova-cert').with(
|
||||
'name' => 'nova-cert',
|
||||
'ensure' => 'running',
|
||||
'enable' => true
|
||||
)}
|
||||
end
|
||||
end
|
||||
describe 'on rhel' do
|
||||
@ -35,6 +40,6 @@ describe 'nova::cert' do
|
||||
'ensure' => 'stopped',
|
||||
'enable' => false
|
||||
)}
|
||||
it { should_not contain_package('nova-network') }
|
||||
it { should_not contain_package('nova-cert') }
|
||||
end
|
||||
end
|
||||
|
45
spec/classes/nova_volume_spec.rb
Normal file
45
spec/classes/nova_volume_spec.rb
Normal file
@ -0,0 +1,45 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'nova::volume' do
|
||||
|
||||
let :pre_condition do
|
||||
'include nova'
|
||||
end
|
||||
|
||||
describe 'on debian platforms' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Debian' }
|
||||
end
|
||||
it { should contain_service('nova-volume').with(
|
||||
'name' => 'nova-volume',
|
||||
'ensure' => 'stopped',
|
||||
'enable' => false
|
||||
)}
|
||||
it { should contain_package('nova-volume').with(
|
||||
'name' => 'nova-volume',
|
||||
'ensure' => 'present',
|
||||
'notify' => 'Service[nova-volume]'
|
||||
)}
|
||||
describe 'with enabled as true' do
|
||||
let :params do
|
||||
{:enabled => true}
|
||||
end
|
||||
it { should contain_service('nova-volume').with(
|
||||
'name' => 'nova-volume',
|
||||
'ensure' => 'running',
|
||||
'enable' => true
|
||||
)}
|
||||
end
|
||||
end
|
||||
describe 'on rhel' do
|
||||
let :facts do
|
||||
{ :osfamily => 'RedHat' }
|
||||
end
|
||||
it { should contain_service('nova-volume').with(
|
||||
'name' => 'openstack-nova-volume',
|
||||
'ensure' => 'stopped',
|
||||
'enable' => false
|
||||
)}
|
||||
it { should_not contain_package('nova-volume') }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user