diff --git a/manifests/api.pp b/manifests/api.pp index 1d1ffea5e..e8746a685 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -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, } } diff --git a/manifests/cert.pp b/manifests/cert.pp index 41a460a2d..a2e424343 100644 --- a/manifests/cert.pp +++ b/manifests/cert.pp @@ -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"] - } } diff --git a/manifests/compute.pp b/manifests/compute.pp index f40fc74a5..b8c2e30d9 100644 --- a/manifests/compute.pp +++ b/manifests/compute.pp @@ -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'], - } } diff --git a/manifests/generic_service.pp b/manifests/generic_service.pp new file mode 100644 index 000000000..5875de796 --- /dev/null +++ b/manifests/generic_service.pp @@ -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'], + } + +} diff --git a/manifests/network.pp b/manifests/network.pp index 64d1c9057..3f1522fd4 100644 --- a/manifests/network.pp +++ b/manifests/network.pp @@ -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"] - } } diff --git a/manifests/objectstore.pp b/manifests/objectstore.pp index e4909cab2..8a7a32899 100644 --- a/manifests/objectstore.pp +++ b/manifests/objectstore.pp @@ -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"] - } } diff --git a/manifests/scheduler.pp b/manifests/scheduler.pp index 39aaa1564..62a0aee0c 100644 --- a/manifests/scheduler.pp +++ b/manifests/scheduler.pp @@ -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"] - } } diff --git a/manifests/volume.pp b/manifests/volume.pp index eb9d692ca..2cc9cb9f2 100644 --- a/manifests/volume.pp +++ b/manifests/volume.pp @@ -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, diff --git a/spec/classes/nova_cert_spec.rb b/spec/classes/nova_cert_spec.rb index da3499cde..dd953b6cb 100644 --- a/spec/classes/nova_cert_spec.rb +++ b/spec/classes/nova_cert_spec.rb @@ -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 diff --git a/spec/classes/nova_volume_spec.rb b/spec/classes/nova_volume_spec.rb new file mode 100644 index 000000000..3f413ea88 --- /dev/null +++ b/spec/classes/nova_volume_spec.rb @@ -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