diff --git a/Berksfile.lock b/Berksfile.lock index 308084b..f6b37ee 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -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": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 2762a8b..d135563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ------ diff --git a/attributes/default.rb b/attributes/default.rb index c2d0025..540aafd 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/metadata.rb b/metadata.rb index b8a4a53..8b37e15 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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" diff --git a/recipes/scheduler.rb b/recipes/scheduler.rb index a092fdd..1730674 100644 --- a/recipes/scheduler.rb +++ b/recipes/scheduler.rb @@ -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 diff --git a/spec/scheduler_spec.rb b/spec/scheduler_spec.rb index bb4ceea..54042e2 100644 --- a/spec/scheduler_spec.rb +++ b/spec/scheduler_spec.rb @@ -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