configurable audit cron and ensure only one
Prior, the cronjobs were being set if there was more than one scheduler node. This logic will ensure only one node at a time will be set to run the audit. Cron job is also now configurable to preference. Prior was setting to every minute, which is more frequent than necessary. Change-Id: I27b760b9260963bad3459bf2eb220e2c2966eb0f
This commit is contained in:
parent
a5cff83f5c
commit
af20b1e521
|
@ -2,8 +2,8 @@
|
|||
"sha": "ba71763fac936d414bd4a63f004357f86f6e1bfb",
|
||||
"sources": {
|
||||
"openstack-block-storage": {
|
||||
"locked_version": "7.0.1",
|
||||
"constraint": "= 7.0.1",
|
||||
"locked_version": "7.0.2",
|
||||
"constraint": "= 7.0.2",
|
||||
"path": "."
|
||||
},
|
||||
"openstack-image": {
|
||||
|
|
|
@ -2,6 +2,10 @@ openstack-block-storage Cookbook CHANGELOG
|
|||
==============================
|
||||
This file is used to list changes made in each version of the openstack-block-storage cookbook.
|
||||
|
||||
v7.0.2
|
||||
------
|
||||
### Improvement
|
||||
- ensure cronjob runs on only one node and make cronjob configurable
|
||||
|
||||
v7.0.1
|
||||
------
|
||||
|
|
|
@ -39,6 +39,7 @@ default["openstack"]["block-storage"]["debug"] = "False"
|
|||
default["openstack"]["block-storage"]["lock_path"] = "/var/lock/cinder"
|
||||
# Availability zone/region for the Openstack"]["Block-Storage service
|
||||
default["openstack"]["block-storage"]["region"] = "RegionOne"
|
||||
default["openstack"]["block-storage"]["scheduler_role"] = "os-block-storage-scheduler"
|
||||
|
||||
# The name of the Chef role that knows about the message queue server
|
||||
# that Cinder uses
|
||||
|
|
|
@ -4,7 +4,7 @@ maintainer_email "cookbooks@lists.tfoundry.com"
|
|||
license "Apache 2.0"
|
||||
description "The OpenStack Advanced Volume Management service Cinder."
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version "7.0.1"
|
||||
version "7.0.2"
|
||||
|
||||
recipe "openstack-block-storage::common", "Defines the common pieces of repeated code from the other recipes"
|
||||
recipe "openstack-block-storage::api", "Installs the cinder-api, sets up the cinder database, and cinder service/user/endpoints in keystone"
|
||||
|
|
|
@ -56,9 +56,19 @@ service "cinder-scheduler" do
|
|||
end
|
||||
|
||||
if node["openstack"]["metering"]
|
||||
scheduler_role = node["openstack"]["block-storage"]["scheduler_role"]
|
||||
results = search(:node, "roles:#{scheduler_role}")
|
||||
cron_node = results.collect{|a| a.name}.sort[0]
|
||||
Chef::Log.debug("Volume audit cron node: #{cron_node}")
|
||||
|
||||
cron "cinder-volume-usage-audit" do
|
||||
command "cinder-volume-usage-audit > /var/log/cinder/audit.log 2>&1"
|
||||
action :create
|
||||
day node["openstack"]["block-storage"]["cron"]["day"] || '*'
|
||||
hour node["openstack"]["block-storage"]["cron"]["hour"] || '*'
|
||||
minute node["openstack"]["block-storage"]["cron"]["minute"]
|
||||
month node["openstack"]["block-storage"]["cron"]["month"] || '*'
|
||||
weekday node["openstack"]["block-storage"]["cron"]["weekday"] || '*'
|
||||
command "/usr/local/bin/cinder-volume-usage-audit > /var/log/cinder/audit.log 2>&1"
|
||||
action cron_node == node.name ? :create : :delete
|
||||
user node["openstack"]["block-storage"]["user"]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,6 +57,58 @@ describe "openstack-block-storage::scheduler" do
|
|||
expect(@chef_run).to set_service_to_start_on_boot "cinder-scheduler"
|
||||
end
|
||||
|
||||
it "doesn't run logging recipe" do
|
||||
expect(@chef_run).to set_service_to_start_on_boot "cinder-scheduler"
|
||||
end
|
||||
|
||||
it "doesn't setup cron when no metering" do
|
||||
expect(@chef_run.cron("cinder-volume-usage-audit")).to be_nil
|
||||
end
|
||||
|
||||
it "creates cron metering default" do
|
||||
::Chef::Recipe.any_instance.stub(:search).
|
||||
with(:node, "roles:os-block-storage-scheduler").
|
||||
and_return([OpenStruct.new(:name => "fauxhai.local")])
|
||||
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
|
||||
n.set["openstack"]["metering"] = true
|
||||
end
|
||||
chef_run.converge "openstack-block-storage::scheduler"
|
||||
cron = chef_run.cron "cinder-volume-usage-audit"
|
||||
expect(cron.command).to match(/\/usr\/local\/bin\/cinder-volume-usage-audit/)
|
||||
expect(cron.command).to match(/\/var\/log\/cinder\/audit.log/)
|
||||
expect(cron.minute).to eq "00"
|
||||
expect(cron.hour).to eq "*"
|
||||
expect(cron.day).to eq "*"
|
||||
expect(cron.weekday).to eq "*"
|
||||
expect(cron.month).to eq "*"
|
||||
expect(cron.user).to eq "cinder"
|
||||
expect(cron.action).to include :create
|
||||
end
|
||||
|
||||
it "creates cron metering custom" do
|
||||
::Chef::Recipe.any_instance.stub(:search).
|
||||
with(:node, "roles:os-block-storage-scheduler").
|
||||
and_return([OpenStruct.new(:name => "foobar")])
|
||||
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
|
||||
n.set["openstack"]["metering"] = true
|
||||
n.set["openstack"]["block-storage"]["cron"]["minute"] = 50
|
||||
n.set["openstack"]["block-storage"]["cron"]["hour"] = 23
|
||||
n.set["openstack"]["block-storage"]["cron"]["day"] = 6
|
||||
n.set["openstack"]["block-storage"]["cron"]["weekday"] = 5
|
||||
n.set["openstack"]["block-storage"]["cron"]["month"] = 11
|
||||
n.set["openstack"]["block-storage"]["user"] = "foobar"
|
||||
end
|
||||
chef_run.converge "openstack-block-storage::scheduler"
|
||||
cron = chef_run.cron "cinder-volume-usage-audit"
|
||||
expect(cron.minute).to eq "50"
|
||||
expect(cron.hour).to eq "23"
|
||||
expect(cron.day).to eq "6"
|
||||
expect(cron.weekday).to eq "5"
|
||||
expect(cron.month).to eq "11"
|
||||
expect(cron.user).to eq "foobar"
|
||||
expect(cron.action).to include :delete
|
||||
end
|
||||
|
||||
expect_creates_cinder_conf "service[cinder-scheduler]", "cinder", "cinder"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue