From 1fb892afd70783b4bf35816839cb8b5b5629745b Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Mon, 18 Jun 2012 10:14:53 -0700 Subject: [PATCH] Add enabled parameter to glance services. This commit adds the parameter enabled to both glance::api as well as glance::registry. Setting enabled to false ensures that the service is not running and that the db schema is not create/migrated. This flag is being added to all nova services to allow the deployment of the openstack controller in active-passive for HA. --- manifests/api.pp | 13 +++++++++--- manifests/registry.pp | 30 +++++++++++++++++----------- spec/classes/glance_api_spec.rb | 9 ++++++--- spec/classes/glance_registry_spec.rb | 29 +++++++++++++++++---------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index fb452f13..e8ab7aee 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -46,7 +46,8 @@ class glance::api( $auth_uri = "http://127.0.0.1:5000/", $keystone_tenant = 'admin', $keystone_user = 'admin', - $keystone_password = 'ChangeMe' + $keystone_password = 'ChangeMe', + $enabled = true ) inherits glance { # used to configure concat @@ -100,10 +101,16 @@ class glance::api( content => template('glance/glance-cache.conf.erb'), } + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + service { 'glance-api': name => $::glance::params::api_service_name, - ensure => running, - enable => true, + ensure => $service_ensure, + enable => $enabled, hasstatus => true, hasrestart => true, subscribe => Concat['/etc/glance/glance-api.conf'], diff --git a/manifests/registry.pp b/manifests/registry.pp index 760679b7..b70fd1ba 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -13,7 +13,8 @@ class glance::registry( $auth_uri = 'http://127.0.0.1:5000/', $keystone_tenant = 'admin', $keystone_user = 'admin', - $keystone_password = 'ChangeMe' + $keystone_password = 'ChangeMe', + $enabled = true ) inherits glance { require 'keystone::python' @@ -35,21 +36,26 @@ class glance::registry( content => template('glance/glance-registry-paste.ini.erb'), } - exec { 'glance-manage db_sync': - command => $::glance::params::db_sync_command, - path => '/usr/bin', - user => 'glance', - refreshonly => true, - logoutput => on_failure, - subscribe => [Package['glance'], File['/etc/glance/glance-registry.conf']], - notify => Service['glance-registry'], - } + if $enabled { + exec { 'glance-manage db_sync': + command => $::glance::params::db_sync_command, + path => '/usr/bin', + user => 'glance', + refreshonly => true, + logoutput => on_failure, + subscribe => [Package['glance'], File['/etc/glance/glance-registry.conf']], + notify => Service['glance-registry'], + } + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } service { 'glance-registry': name => $::glance::params::registry_service_name, - ensure => running, - enable => true, + ensure => $service_ensure, + enable => $enabled, hasstatus => true, hasrestart => true, subscribe => File['/etc/glance/glance-registry.conf'], diff --git a/spec/classes/glance_api_spec.rb b/spec/classes/glance_api_spec.rb index eabec91d..30ac576e 100644 --- a/spec/classes/glance_api_spec.rb +++ b/spec/classes/glance_api_spec.rb @@ -18,7 +18,8 @@ describe 'glance::api' do :registry_host => '0.0.0.0', :registry_port => '9191', :log_file => '/var/log/glance/api.log', - :auth_type => 'keystone' + :auth_type => 'keystone', + :enabled => true } end @@ -31,7 +32,8 @@ describe 'glance::api' do :registry_host => '127.0.0.1', :registry_port => '9111', :log_file => '/var/log/glance-api.log', - :auth_type => 'not_keystone' + :auth_type => 'not_keystone', + :enabled => false } ].each do |param_set| @@ -48,7 +50,8 @@ describe 'glance::api' do it { should contain_class 'glance' } it { should contain_service('glance-api').with( - 'ensure' => 'running', + 'ensure' => param_hash[:enabled] ? 'running': 'stopped', + 'enable' => param_hash[:enabled], 'hasstatus' => 'true', 'hasrestart' => 'true', 'subscribe' => 'Concat[/etc/glance/glance-api.conf]' diff --git a/spec/classes/glance_registry_spec.rb b/spec/classes/glance_registry_spec.rb index f8aca1fd..d710c196 100644 --- a/spec/classes/glance_registry_spec.rb +++ b/spec/classes/glance_registry_spec.rb @@ -16,7 +16,8 @@ describe 'glance::registry' do :bind_port => '9191', :log_file => '/var/log/glance/registry.log', :sql_connection => 'sqlite:///var/lib/glance/glance.sqlite', - :sql_idle_timeout => '3600' + :sql_idle_timeout => '3600', + :enabled => true } end @@ -29,7 +30,8 @@ describe 'glance::registry' do :bind_port => '9111', :log_file => '/var/log/glance-registry.log', :sql_connection => 'sqlite:///var/lib/glance.sqlite', - :sql_idle_timeout => '360' + :sql_idle_timeout => '360', + :enabled => false } ].each do |param_set| @@ -45,21 +47,26 @@ describe 'glance::registry' do it { should contain_class 'glance::registry' } it { should contain_service('glance-registry').with( - 'ensure' => 'running', - 'enable' => 'true', + 'ensure' => param_hash[:enabled] ? 'running' : 'stopped', + 'enable' => param_hash[:enabled], 'hasstatus' => 'true', 'hasrestart' => 'true', 'subscribe' => 'File[/etc/glance/glance-registry.conf]', 'require' => 'Class[Glance]' )} - it { should contain_exec('glance-manage db_sync').with( - 'path' => '/usr/bin', - 'refreshonly' => true, - 'logoutput' => 'on_failure', - 'subscribe' => ['Package[glance]', 'File[/etc/glance/glance-registry.conf]'], - 'notify' => 'Service[glance-registry]' - )} + it 'should only sync the db if the service is enabled' do + + if param_hash[:enabled] + should contain_exec('glance-manage db_sync').with( + 'path' => '/usr/bin', + 'refreshonly' => true, + 'logoutput' => 'on_failure', + 'subscribe' => ['Package[glance]', 'File[/etc/glance/glance-registry.conf]'], + 'notify' => 'Service[glance-registry]' + ) + end + end it 'should compile the template based on the class parameters' do content = param_value(subject, 'file', '/etc/glance/glance-registry.conf', 'content')