Merge "Initial rubocop support for ChefSpec tests."
This commit is contained in:
commit
aa9f7a0bf0
@ -1,8 +1,9 @@
|
||||
# Strainerfile
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/attributes/
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/metadata.rb
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/recipes/
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile --config $SANDBOX/$COOKBOOK/.rubocop.yml
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/metadata.rb --config $SANDBOX/$COOKBOOK/.rubocop.yml
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/attributes/ --config $SANDBOX/$COOKBOOK/attributes/.rubocop.yml
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/recipes/ --config $SANDBOX/$COOKBOOK/recipes/.rubocop.yml
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/spec/ --config $SANDBOX/$COOKBOOK/spec/.rubocop.yml
|
||||
# rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
|
||||
# may want to add rubocop check for Berksfile and Gemfile
|
||||
knife test: bundle exec knife cookbook test $COOKBOOK
|
||||
|
@ -21,6 +21,7 @@ Since there are slight style differences between the coding of attributes, recip
|
||||
[Gemfile and metadata.rb](.rubocop.yml)
|
||||
[attributes/*.rb](attributes/.rubocop.yml)
|
||||
[recipes/.rubocop.yml](recipes/.rubocop.yml)
|
||||
[spec/.rubocop.yml](spec/.rubocop.yml)
|
||||
|
||||
## Knife ##
|
||||
|
||||
|
17
spec/.rubocop-todo.yml
Normal file
17
spec/.rubocop-todo.yml
Normal file
@ -0,0 +1,17 @@
|
||||
# This configuration was generated by `rubocop --auto-gen-config`.
|
||||
# The point is for the user to remove these configuration records
|
||||
# one by one as the offences are removed from the code base.
|
||||
|
||||
HashSyntax:
|
||||
Enabled: false
|
||||
|
||||
MethodLength:
|
||||
Enabled: false
|
||||
|
||||
StringLiterals:
|
||||
Enabled: false
|
||||
|
||||
### in the .rubocop.yml
|
||||
# embedded attributes make for long lines
|
||||
LineLength:
|
||||
Enabled: false
|
3
spec/.rubocop.yml
Normal file
3
spec/.rubocop.yml
Normal file
@ -0,0 +1,3 @@
|
||||
# embedded attributes make for long lines
|
||||
LineLength:
|
||||
Enabled: false
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::api" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::api" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::api" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::cinder-common" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::cinder-common" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::cinder-common" do
|
||||
@ -18,7 +22,7 @@ describe "openstack-block-storage::cinder-common" do
|
||||
|
||||
describe "/etc/cinder" do
|
||||
before do
|
||||
@dir = @chef_run.directory "/etc/cinder"
|
||||
@dir = @chef_run.directory "/etc/cinder"
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
@ -27,13 +31,13 @@ describe "openstack-block-storage::cinder-common" do
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
expect(sprintf("%o", @dir.mode)).to eq "750"
|
||||
expect(sprintf("%o", @dir.mode)).to eq "750"
|
||||
end
|
||||
end
|
||||
|
||||
describe "cinder.conf" do
|
||||
before do
|
||||
@file = @chef_run.template "/etc/cinder/cinder.conf"
|
||||
@file = @chef_run.template "/etc/cinder/cinder.conf"
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
@ -42,7 +46,7 @@ describe "openstack-block-storage::cinder-common" do
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
expect(sprintf("%o", @file.mode)).to eq "644"
|
||||
expect(sprintf("%o", @file.mode)).to eq "644"
|
||||
end
|
||||
|
||||
it "has rpc_thread_pool_size" do
|
||||
@ -189,7 +193,7 @@ describe "openstack-block-storage::cinder-common" do
|
||||
|
||||
describe "/var/lock/cinder" do
|
||||
before do
|
||||
@dir = @chef_run.directory "/var/lock/cinder"
|
||||
@dir = @chef_run.directory "/var/lock/cinder"
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
@ -198,7 +202,7 @@ describe "openstack-block-storage::cinder-common" do
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
expect(sprintf("%o", @dir.mode)).to eq "700"
|
||||
expect(sprintf("%o", @dir.mode)).to eq "700"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::default" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::identity_registration" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::scheduler" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::scheduler" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::scheduler" do
|
||||
@ -54,40 +58,40 @@ describe "openstack-block-storage::scheduler" do
|
||||
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::Recipe.any_instance.stub(:search)
|
||||
.with(:node, "roles:os-block-storage-scheduler")
|
||||
.and_return([OpenStruct.new(:name => "fauxhai.local")])
|
||||
chef_run = ::ChefSpec::Runner.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"
|
||||
bin_str="/usr/bin/cinder-volume-usage-audit > /var/log/cinder/audit.log"
|
||||
bin_str = "/usr/bin/cinder-volume-usage-audit > /var/log/cinder/audit.log"
|
||||
expect(cron.command).to match(/#{bin_str}/)
|
||||
crontests = [ [:minute, '00'], [:hour, '*'], [:day, '*'],
|
||||
[:weekday, '*'], [:month, '*'], [:user, 'cinder'] ]
|
||||
crontests.each do |k,v|
|
||||
crontests = [[:minute, '00'], [:hour, '*'], [:day, '*'],
|
||||
[:weekday, '*'], [:month, '*'], [:user, 'cinder']]
|
||||
crontests.each do |k, v|
|
||||
expect(cron.send(k)).to eq v
|
||||
end
|
||||
expect(cron.action).to include :create
|
||||
end
|
||||
|
||||
it "creates cron metering custom" do
|
||||
crontests = [ [:minute, '50'], [:hour, '23'], [:day, '6'],
|
||||
[:weekday, '5'], [:month, '11'], [:user, 'foobar'] ]
|
||||
::Chef::Recipe.any_instance.stub(:search).
|
||||
with(:node, "roles:os-block-storage-scheduler").
|
||||
and_return([OpenStruct.new(:name => "foobar")])
|
||||
crontests = [[:minute, '50'], [:hour, '23'], [:day, '6'],
|
||||
[:weekday, '5'], [:month, '11'], [:user, 'foobar']]
|
||||
::Chef::Recipe.any_instance.stub(:search)
|
||||
.with(:node, "roles:os-block-storage-scheduler")
|
||||
.and_return([OpenStruct.new(:name => "foobar")])
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set["openstack"]["metering"] = true
|
||||
crontests.each do |k,v|
|
||||
crontests.each do |k, v|
|
||||
n.set["openstack"]["block-storage"]["cron"][k.to_s] = v
|
||||
end
|
||||
n.set["openstack"]["block-storage"]["user"] = "foobar"
|
||||
end
|
||||
chef_run.converge "openstack-block-storage::scheduler"
|
||||
cron = chef_run.cron "cinder-volume-usage-audit"
|
||||
crontests.each do |k,v|
|
||||
crontests.each do |k, v|
|
||||
expect(cron.send(k)).to eq v
|
||||
end
|
||||
expect(cron.action).to include :delete
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require "chefspec"
|
||||
require "chefspec/berkshelf"
|
||||
require "chef/application"
|
||||
@ -21,20 +25,20 @@ require_relative "support/matcher"
|
||||
}
|
||||
|
||||
def block_storage_stubs
|
||||
::Chef::Recipe.any_instance.stub(:rabbit_servers).
|
||||
and_return "1.1.1.1:5672,2.2.2.2:5672"
|
||||
::Chef::Recipe.any_instance.stub(:secret).
|
||||
with("secrets", "openstack_identity_bootstrap_token").
|
||||
and_return "bootstrap-token"
|
||||
::Chef::Recipe.any_instance.stub(:db_password).and_return String.new
|
||||
::Chef::Recipe.any_instance.stub(:user_password).and_return String.new
|
||||
::Chef::Recipe.any_instance.stub(:user_password).
|
||||
with("guest").
|
||||
and_return "rabbit-pass"
|
||||
::Chef::Recipe.any_instance.stub(:service_password).and_return String.new
|
||||
::Chef::Recipe.any_instance.stub(:service_password).
|
||||
with("openstack-block-storage").
|
||||
and_return "cinder-pass"
|
||||
::Chef::Recipe.any_instance.stub(:rabbit_servers)
|
||||
.and_return "1.1.1.1:5672,2.2.2.2:5672"
|
||||
::Chef::Recipe.any_instance.stub(:secret)
|
||||
.with("secrets", "openstack_identity_bootstrap_token")
|
||||
.and_return "bootstrap-token"
|
||||
::Chef::Recipe.any_instance.stub(:db_password).and_return ''
|
||||
::Chef::Recipe.any_instance.stub(:user_password).and_return ''
|
||||
::Chef::Recipe.any_instance.stub(:user_password)
|
||||
.with("guest")
|
||||
.and_return "rabbit-pass"
|
||||
::Chef::Recipe.any_instance.stub(:service_password).and_return ''
|
||||
::Chef::Recipe.any_instance.stub(:service_password)
|
||||
.with("openstack-block-storage")
|
||||
.and_return "cinder-pass"
|
||||
::Chef::Application.stub(:fatal!)
|
||||
end
|
||||
|
||||
@ -44,7 +48,7 @@ def expect_runs_openstack_common_logging_recipe
|
||||
end
|
||||
end
|
||||
|
||||
def expect_creates_cinder_conf service, user, group, action=:restart
|
||||
def expect_creates_cinder_conf(service, user, group, action = :restart)
|
||||
describe "cinder.conf" do
|
||||
before do
|
||||
@file = @chef_run.template "/etc/cinder/cinder.conf"
|
||||
@ -65,7 +69,7 @@ def expect_creates_cinder_conf service, user, group, action=:restart
|
||||
end
|
||||
end
|
||||
|
||||
def expect_creates_policy_json service, user, group, action=:restart
|
||||
def expect_creates_policy_json(service, user, group, action = :restart)
|
||||
describe "policy.json" do
|
||||
before do
|
||||
@file = @chef_run.template "/etc/cinder/policy.json"
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
def upgrade_python_pip(pkgname)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :upgrade, pkgname)
|
||||
end
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::volume" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::volume" do
|
||||
|
@ -1,3 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe "openstack-block-storage::volume" do
|
||||
@ -60,8 +64,8 @@ describe "openstack-block-storage::volume" do
|
||||
end
|
||||
|
||||
it "configures netapp dfm password" do
|
||||
::Chef::Recipe.any_instance.stub(:service_password).with("netapp").
|
||||
and_return "netapp-pass"
|
||||
::Chef::Recipe.any_instance.stub(:service_password).with("netapp")
|
||||
.and_return "netapp-pass"
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set["openstack"]["block-storage"]["volume"]["driver"] = "cinder.volume.drivers.netapp.iscsi.NetAppISCSIDriver"
|
||||
end
|
||||
@ -72,8 +76,8 @@ describe "openstack-block-storage::volume" do
|
||||
end
|
||||
|
||||
it "configures rbd password" do
|
||||
::Chef::Recipe.any_instance.stub(:service_password).with("rbd").
|
||||
and_return "rbd-pass"
|
||||
::Chef::Recipe.any_instance.stub(:service_password).with("rbd")
|
||||
.and_return "rbd-pass"
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set["openstack"]["block-storage"]["volume"]["driver"] = "cinder.volume.drivers.RBDDriver"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user