Update spec files to be rubocop compliant

- Move to use a single .rubocop.yml file
- Adjust Strainerfile to use single .rubocop.yml file
- Ensure all spec files are rubocop compliant

Addresses: blueprint rubocop-for-common
Change-Id: I550c50c55edd4725782385de2c0f66bedff3004e
This commit is contained in:
Andy McCrae 2014-01-24 15:00:19 +00:00
parent 4be974630f
commit 0b40a0686b
15 changed files with 396 additions and 362 deletions

View File

@ -1,7 +1,22 @@
# UTF-8 headers not generally in these files AllCops:
Encoding: Includes:
Enabled: false - metadata.rb
- Gemfile
- attributes/**
- recipes/**
- spec/**
Excludes:
- libraries/**
- providers/**
- resources/**
Encoding:
Exclude:
- metadata.rb
- Gemfile
# ignore long lines
LineLength: LineLength:
Enabled: false Enabled: false
WordArray:
MinSize: 3

View File

@ -1,8 +1,5 @@
# Strainerfile # Strainerfile
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile $SANDBOX/$COOKBOOK/metadata.rb --config $SANDBOX/$COOKBOOK/.rubocop.yml rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
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
knife test: bundle exec knife cookbook test $COOKBOOK knife test: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK
chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec

View File

@ -1,3 +0,0 @@
# embedded attributes make for long lines
LineLength:
Enabled: false

View File

@ -1,39 +1,41 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "database"
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'database'
describe ::Openstack do describe ::Openstack do
before do before do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS @chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject = ::Object.new.extend ::Openstack @subject = ::Object.new.extend ::Openstack
@subject.stub :include_recipe @subject.stub :include_recipe
end end
describe "#db_create_with_user" do describe '#db_create_with_user' do
it "returns nil when no such service was found" do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.db_create_with_user("nonexisting", "user", "pass").should be_nil @subject.db_create_with_user('nonexisting', 'user', 'pass').should be_nil
end end
it "returns db info and creates database with user when service found" do it 'returns db info and creates database with user when service found' do
@subject.stub(:database).and_return {} @subject.stub(:database).and_return {}
@subject.stub(:database_user).and_return {} @subject.stub(:database_user).and_return {}
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.db_create_with_user "compute", "user", "pass" result = @subject.db_create_with_user 'compute', 'user', 'pass'
result['host'].should == "127.0.0.1" result['host'].should eq('127.0.0.1')
result['port'].should == "3306" result['port'].should eq('3306')
end end
it "creates database" do it 'creates database' do
pending "TODO: test this LWRP" pending 'TODO: test this LWRP'
end end
it "creates database user" do it 'creates database user' do
pending "TODO: test this LWRP" pending 'TODO: test this LWRP'
end end
it "grants privs to database user" do it 'grants privs to database user' do
pending "TODO: test this LWRP" pending 'TODO: test this LWRP'
end end
end end
end end

View File

@ -1,9 +1,11 @@
require_relative "spec_helper" # encoding: UTF-8
describe "openstack-common::default" do require_relative 'spec_helper'
describe "suse" do
it "configures openstack repository" do describe 'openstack-common::default' do
pending "TODO: implement" describe 'suse' do
it 'configures openstack repository' do
pending 'TODO: implement'
end end
end end
end end

View File

@ -1,22 +1,24 @@
require_relative "spec_helper" # encoding: UTF-8
describe "openstack-common::default" do require_relative 'spec_helper'
describe "ubuntu" do
describe 'openstack-common::default' do
describe 'ubuntu' do
before do before do
opts = ::UBUNTU_OPTS.merge :step_into => ["apt_repository"] opts = ::UBUNTU_OPTS.merge step_into: ['apt_repository']
@chef_run = ::ChefSpec::Runner.new(opts) do |n| @chef_run = ::ChefSpec::Runner.new(opts) do |n|
n.set["lsb"]["codename"] = "precise" n.set['lsb']['codename'] = 'precise'
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
end end
it "installs ubuntu-cloud-keyring package" do it 'installs ubuntu-cloud-keyring package' do
expect(@chef_run).to install_package "ubuntu-cloud-keyring" expect(@chef_run).to install_package 'ubuntu-cloud-keyring'
end end
it "configures openstack repository" do it 'configures openstack repository' do
file = "/etc/apt/sources.list.d/openstack-ppa.list" file = '/etc/apt/sources.list.d/openstack-ppa.list'
expected = "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/havana main" expected = 'deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/havana main'
expect(@chef_run).to render_file(file).with_content(expected) expect(@chef_run).to render_file(file).with_content(expected)
end end

View File

@ -1,80 +1,82 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "endpoints"
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'endpoints'
describe ::Openstack do describe ::Openstack do
before do before do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS @chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::set_endpoints_by_interface" @chef_run.converge 'openstack-common::set_endpoints_by_interface'
@subject = ::Object.new.extend ::Openstack @subject = ::Object.new.extend ::Openstack
end end
describe "#endpoint" do describe '#endpoint' do
it "returns nil when no openstack.endpoints not in node attrs" do it 'returns nil when no openstack.endpoints not in node attrs' do
@subject.stub(:node).and_return {} @subject.stub(:node).and_return {}
@subject.endpoint("nonexisting").should be_nil @subject.endpoint('nonexisting').should be_nil
end end
it "returns nil when no such endpoint was found" do it 'returns nil when no such endpoint was found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.endpoint("nonexisting").should be_nil @subject.endpoint('nonexisting').should be_nil
end end
it "handles a URI needing escaped" do it 'handles a URI needing escaped' do
uri_hash = { uri_hash = {
"openstack" => { 'openstack' => {
"endpoints" => { 'endpoints' => {
"compute-api" => { 'compute-api' => {
"uri" => "http://localhost:8080/v2/%(tenant_id)s" 'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
} }
} }
} }
} }
@subject.stub(:node).and_return uri_hash @subject.stub(:node).and_return uri_hash
result = @subject.endpoint "compute-api" result = @subject.endpoint 'compute-api'
result.path.should == "/v2/%25(tenant_id)s" result.path.should == '/v2/%25(tenant_id)s'
end end
it "returns endpoint URI object when uri key in endpoint hash" do it 'returns endpoint URI object when uri key in endpoint hash' do
uri_hash = { uri_hash = {
"openstack" => { 'openstack' => {
"endpoints" => { 'endpoints' => {
"compute-api" => { 'compute-api' => {
"uri" => "http://localhost:8080/path" 'uri' => 'http://localhost:8080/path'
} }
} }
} }
} }
@subject.stub(:node).and_return uri_hash @subject.stub(:node).and_return uri_hash
result = @subject.endpoint "compute-api" result = @subject.endpoint 'compute-api'
result.port.should == 8080 result.port.should == 8080
end end
it "returns endpoint URI string when uri key in endpoint hash and host also in hash" do it 'returns endpoint URI string when uri key in endpoint hash and host also in hash' do
uri_hash = { uri_hash = {
"openstack" => { 'openstack' => {
"endpoints" => { 'endpoints' => {
"compute-api" => { 'compute-api' => {
"uri" => "http://localhost", 'uri' => 'http://localhost',
"host" => "ignored" 'host' => 'ignored'
} }
} }
} }
} }
@subject.stub(:node).and_return uri_hash @subject.stub(:node).and_return uri_hash
@subject.endpoint("compute-api").to_s.should == "http://localhost" @subject.endpoint('compute-api').to_s.should == 'http://localhost'
end end
it "returns endpoint URI object when uri key not in endpoint hash but host is in hash" do it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do
@subject.should_receive(:uri_from_hash).with({"host"=>"localhost", "port"=>"8080"}) @subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '8080')
uri_hash = { uri_hash = {
"openstack" => { 'openstack' => {
"endpoints" => { 'endpoints' => {
"compute-api" => { 'compute-api' => {
"host" => "localhost", 'host' => 'localhost',
"port" => "8080" 'port' => '8080'
} }
} }
} }
} }
@subject.stub(:node).and_return uri_hash @subject.stub(:node).and_return uri_hash
@subject.endpoint "compute-api" @subject.endpoint 'compute-api'
end end
it "endpoints recipe bind_interface sets host" do it 'endpoints recipe bind_interface sets host' do
@subject.stub('address_for').and_return '10.0.0.100' @subject.stub('address_for').and_return '10.0.0.100'
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0' chef_run.node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
@ -82,7 +84,7 @@ describe ::Openstack do
'interfaces' => { 'interfaces' => {
'lo' => { 'lo' => {
'addresses' => { 'addresses' => {
'127.0.0.1'=> { '127.0.0.1' => {
'family' => 'inet', 'family' => 'inet',
'netmask' => '255.0.0.0', 'netmask' => '255.0.0.0',
'scope' => 'Node' 'scope' => 'Node'
@ -91,7 +93,7 @@ describe ::Openstack do
}, },
'eth0' => { 'eth0' => {
'addresses' => { 'addresses' => {
'10.0.0.100'=> { '10.0.0.100' => {
'family' => 'inet', 'family' => 'inet',
'netmask' => '255.255.255.0', 'netmask' => '255.255.255.0',
'scope' => 'Global' 'scope' => 'Global'
@ -105,20 +107,20 @@ describe ::Openstack do
end end
end end
describe "#endpoints" do describe '#endpoints' do
it "does nothing when no endpoints" do it 'does nothing when no endpoints' do
@subject.stub(:node).and_return {} @subject.stub(:node).and_return {}
@subject.endpoints.should be_nil @subject.endpoints.should be_nil
end end
it "does nothing when empty endpoints" do it 'does nothing when empty endpoints' do
@subject.stub(:node).and_return({"openstack" => { "endpoints" => {}}}) @subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
@count = 0 @count = 0
@subject.endpoints do | ep | @subject.endpoints do | ep |
@count += 1 @count += 1
end end
@count.should == 0 @count.should == 0
end end
it "executes block count when have endpoints" do it 'executes block count when have endpoints' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@count = 0 @count = 0
@subject.endpoints do |ep| @subject.endpoints do |ep|
@ -128,35 +130,35 @@ describe ::Openstack do
end end
end end
describe "#db" do describe '#db' do
it "returns nil when no openstack.db not in node attrs" do it 'returns nil when no openstack.db not in node attrs' do
@subject.stub(:node).and_return {} @subject.stub(:node).and_return {}
@subject.db("nonexisting").should be_nil @subject.db('nonexisting').should be_nil
end end
it "returns nil when no such service was found" do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.db("nonexisting").should be_nil @subject.db('nonexisting').should be_nil
end end
it "returns db info hash when service found" do it 'returns db info hash when service found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.db("compute")['host'].should == "127.0.0.1" @subject.db('compute')['host'].should eq('127.0.0.1')
@subject.db("compute").has_key?("uri").should be_false @subject.db('compute').key?('uri').should be_false
end end
end end
describe "#db_uri" do describe '#db_uri' do
it "returns nil when no openstack.db not in node attrs" do it 'returns nil when no openstack.db not in node attrs' do
@subject.stub(:node).and_return {} @subject.stub(:node).and_return {}
@subject.db_uri("nonexisting", "user", "pass").should be_nil @subject.db_uri('nonexisting', 'user', 'pass').should be_nil
end end
it "returns nil when no such service was found" do it 'returns nil when no such service was found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.db_uri("nonexisting", "user", "pass").should be_nil @subject.db_uri('nonexisting', 'user', 'pass').should be_nil
end end
it "returns db info hash when service found" do it 'returns db info hash when service found' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
expect = "mysql://user:pass@127.0.0.1:3306/nova?charset=utf8" expect = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
@subject.db_uri("compute", "user", "pass").should == expect @subject.db_uri('compute', 'user', 'pass').should == expect
end end
end end
end end

View File

@ -1,57 +1,60 @@
require_relative "spec_helper" # encoding: UTF-8
describe "openstack-common::logging" do require_relative 'spec_helper'
describe "ubuntu" do
describe 'openstack-common::logging' do
describe 'ubuntu' do
before do before do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-common::logging" @chef_run.converge 'openstack-common::logging'
end end
describe "/etc/openstack" do describe '/etc/openstack' do
before do before do
@dir = @chef_run.directory "/etc/openstack" @dir = @chef_run.directory '/etc/openstack'
end end
it "has proper owner" do it 'has proper owner' do
expect(@dir.owner).to eq("root") expect(@dir.owner).to eq('root')
expect(@dir.group).to eq("root") expect(@dir.group).to eq('root')
end end
it "has proper modes" do it 'has proper modes' do
expect(sprintf("%o", @dir.mode)).to eq "755" expect(sprintf('%o', @dir.mode)).to eq '755'
end end
end end
describe "logging.conf" do describe 'logging.conf' do
before do before do
@file = "/etc/openstack/logging.conf" @file = '/etc/openstack/logging.conf'
end end
it "has proper owner" do it 'has proper owner' do
expect(@chef_run.template(@file).owner).to eq("root") expect(@chef_run.template(@file).owner).to eq('root')
expect(@chef_run.template(@file).group).to eq("root") expect(@chef_run.template(@file).group).to eq('root')
end end
it "has proper modes" do it 'has proper modes' do
m = @chef_run.template(@file).mode m = @chef_run.template(@file).mode
expect(sprintf("%o", m)).to eq "644" expect(sprintf('%o', m)).to eq '644'
end end
it "templates openstack.logging.ignore block" do it 'templates openstack.logging.ignore block' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
chef_run.converge "openstack-common::logging" chef_run.converge 'openstack-common::logging'
node = chef_run.node node = chef_run.node
node.set["openstack"]["logging"]["ignore"] = { node.set['openstack']['logging']['ignore'] = {
"test.nova.api.openstack.wsgi" => "WARNING" 'test.nova.api.openstack.wsgi' => 'WARNING'
} }
tmp = [ tmp = [
"[logger_test_nova_api_openstack_wsgi]", '[logger_test_nova_api_openstack_wsgi]',
"level = WARNING", 'level = WARNING',
"handlers = prod,debug", 'handlers = prod,debug',
"qualname = test.nova.api.openstack.wsgi" 'qualname = test.nova.api.openstack.wsgi'
] ]
expect(chef_run).to render_file(@file).with_content(tmp.join("\n")) expect(chef_run).to render_file(@file).with_content(tmp.join('
'))
end end
end end
end end

View File

@ -1,46 +1,48 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "network"
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'network'
describe ::Openstack do describe ::Openstack do
before do before do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["network"] = { n.set['network'] = {
"interfaces" => { 'interfaces' => {
"lo" => { 'lo' => {
"addresses" => { 'addresses' => {
"127.0.0.1"=> { '127.0.0.1' => {
"family" => "inet", 'family' => 'inet',
"prefixlen" => "8", 'prefixlen' => '8',
"netmask" => "255.0.0.0", 'netmask' => '255.0.0.0',
"scope" => "Node" 'scope' => 'Node'
}, },
"::1" => { '::1' => {
"family" => "inet6", 'family' => 'inet6',
"prefixlen" => "128", 'prefixlen' => '128',
"scope" => "Node" 'scope' => 'Node'
} }
} }
} }
} }
} }
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject = ::Object.new.extend ::Openstack @subject = ::Object.new.extend ::Openstack
end end
describe "#address_for" do describe '#address_for' do
it "returns ipv4 address" do it 'returns ipv4 address' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
resp = @subject.address_for "lo" resp = @subject.address_for 'lo'
expect(resp).to eq "127.0.0.1" expect(resp).to eq '127.0.0.1'
end end
it "returns ipv4 address" do it 'returns ipv4 address' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
resp = @subject.address_for "lo", "inet6" resp = @subject.address_for 'lo', 'inet6'
expect(resp).to eq "::1" expect(resp).to eq '::1'
end end
end end
end end

View File

@ -1,65 +1,67 @@
require_relative "spec_helper" # encoding: UTF-8
require "uri"
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "parse" require_relative 'spec_helper'
require 'uri'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'parse'
describe ::Openstack do describe ::Openstack do
before do before do
@subject = ::Object.new.extend(::Openstack) @subject = ::Object.new.extend(::Openstack)
end end
describe "#prettytable_to_array" do describe '#prettytable_to_array' do
it "returns [] when no table provided" do it 'returns [] when no table provided' do
@subject.prettytable_to_array(nil).should == [] @subject.prettytable_to_array(nil).should == []
end end
it "returns [] when table provided is empty" do it 'returns [] when table provided is empty' do
@subject.prettytable_to_array("").should == [] @subject.prettytable_to_array('').should == []
end end
it "returns proper array of hashes when proper table provided" do it 'returns proper array of hashes when proper table provided' do
table = table =
"+---------+----------------------------------+----------------------------------+ '+---------+----------------------------------+----------------------------------+
| tenant | access | secret | | tenant | access | secret |
+---------+----------------------------------+----------------------------------+ +---------+----------------------------------+----------------------------------+
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 | | service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
+---------+----------------------------------+----------------------------------+" +---------+----------------------------------+----------------------------------+'
@subject.prettytable_to_array(table).should == @subject.prettytable_to_array(table).should ==
[{"tenant" => "service", [{ 'tenant' => 'service',
"access" => "91af731b3be244beb8f30fc59b7bc96d", 'access' => '91af731b3be244beb8f30fc59b7bc96d',
"secret" => "ce811442cfb549c39390a203778a4bf5"}] 'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
end end
it "returns proper array of hashes when proper table provided including whitespace" do it 'returns proper array of hashes when proper table provided including whitespace' do
table = table =
"+---------+----------------------------------+----------------------------------+ '+---------+----------------------------------+----------------------------------+
| tenant | access | secret | | tenant | access | secret |
+---------+----------------------------------+----------------------------------+ +---------+----------------------------------+----------------------------------+
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 | | service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
+---------+----------------------------------+----------------------------------+ +---------+----------------------------------+----------------------------------+
" '
@subject.prettytable_to_array(table).should == @subject.prettytable_to_array(table).should ==
[{"tenant" => "service", [{ 'tenant' => 'service',
"access" => "91af731b3be244beb8f30fc59b7bc96d", 'access' => '91af731b3be244beb8f30fc59b7bc96d',
"secret" => "ce811442cfb549c39390a203778a4bf5"}] 'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
end end
it "returns a flatten hash when provided a Property/Value table" do it 'returns a flatten hash when provided a Property/Value table' do
table = table =
"+-----------+----------------------------------+ '+-----------+----------------------------------+
| Property | Value | | Property | Value |
+-----------+----------------------------------+ +-----------+----------------------------------+
| access | 91af731b3be244beb8f30fc59b7bc96d | | access | 91af731b3be244beb8f30fc59b7bc96d |
| secret | ce811442cfb549c39390a203778a4bf5 | | secret | ce811442cfb549c39390a203778a4bf5 |
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea | | tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
| user_id | 1c4fc229560f40689c490c5d0838fd84 | | user_id | 1c4fc229560f40689c490c5d0838fd84 |
+-----------+----------------------------------+" +-----------+----------------------------------+'
@subject.prettytable_to_array(table).should == @subject.prettytable_to_array(table).should ==
[{"tenant_id" => "429271dd1cf54b7ca921a0017524d8ea", [{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
"access" => "91af731b3be244beb8f30fc59b7bc96d", 'access' => '91af731b3be244beb8f30fc59b7bc96d',
"secret" => "ce811442cfb549c39390a203778a4bf5", 'secret' => 'ce811442cfb549c39390a203778a4bf5',
"user_id" => "1c4fc229560f40689c490c5d0838fd84"}] 'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
end end
it "returns a flatten hash when provided a Property/Value table including whitespace" do it 'returns a flatten hash when provided a Property/Value table including whitespace' do
table = table =
" '
+-----------+----------------------------------+ +-----------+----------------------------------+
| Property | Value | | Property | Value |
@ -68,12 +70,12 @@ describe ::Openstack do
| secret | ce811442cfb549c39390a203778a4bf5 | | secret | ce811442cfb549c39390a203778a4bf5 |
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea | | tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
| user_id | 1c4fc229560f40689c490c5d0838fd84 | | user_id | 1c4fc229560f40689c490c5d0838fd84 |
+-----------+----------------------------------+" +-----------+----------------------------------+'
@subject.prettytable_to_array(table).should == @subject.prettytable_to_array(table).should ==
[{"tenant_id" => "429271dd1cf54b7ca921a0017524d8ea", [{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
"access" => "91af731b3be244beb8f30fc59b7bc96d", 'access' => '91af731b3be244beb8f30fc59b7bc96d',
"secret" => "ce811442cfb549c39390a203778a4bf5", 'secret' => 'ce811442cfb549c39390a203778a4bf5',
"user_id" => "1c4fc229560f40689c490c5d0838fd84"}] 'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
end end
end end
end end

View File

@ -1,90 +1,92 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "passwords"
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'passwords'
describe ::Openstack do describe ::Openstack do
before do before do
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS @chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject = ::Object.new.extend(::Openstack) @subject = ::Object.new.extend(::Openstack)
end end
describe "#secret" do describe '#secret' do
it "returns index param when developer_mode is true" do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true n.set['openstack']['developer_mode'] = true
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.secret("passwords", "nova") result = @subject.secret('passwords', 'nova')
result.should == "nova" result.should == 'nova'
end end
it "returns databag when developer_mode is false" do it 'returns databag when developer_mode is false' do
value = {"nova" => "this"} value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret" ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret'
::Chef::EncryptedDataBagItem.stub(:load).with("passwords", "nova", "secret").and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('passwords', 'nova', 'secret').and_return value
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.secret("passwords", "nova") result = @subject.secret('passwords', 'nova')
result.should == "this" result.should == 'this'
end end
end end
describe "#get_password_service_password" do describe '#get_password_service_password' do
it "returns index param when developer_mode is true" do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true n.set['openstack']['developer_mode'] = true
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("service", "nova") result = @subject.get_password('service', 'nova')
result.should == "nova" result.should == 'nova'
end end
it "returns databag when developer_mode is false" do it 'returns databag when developer_mode is false' do
value = {"nova" => "this"} value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret" ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret'
::Chef::EncryptedDataBagItem.stub(:load).with("service_passwords", "nova", "secret").and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('service_passwords', 'nova', 'secret').and_return value
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("service", "nova") result = @subject.get_password('service', 'nova')
result.should == "this" result.should == 'this'
end end
end end
describe "#get_password_db_password" do describe '#get_password_db_password' do
it "returns index param when developer_mode is true" do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true n.set['openstack']['developer_mode'] = true
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("db", "nova") result = @subject.get_password('db', 'nova')
result.should == "nova" result.should == 'nova'
end end
it "returns databag when developer_mode is false" do it 'returns databag when developer_mode is false' do
value = {"nova" => "this"} value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret" ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret'
::Chef::EncryptedDataBagItem.stub(:load).with("db_passwords", "nova", "secret").and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('db_passwords', 'nova', 'secret').and_return value
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("db", "nova") result = @subject.get_password('db', 'nova')
result.should == "this" result.should == 'this'
end end
end end
describe "#get_password_user_password" do describe '#get_password_user_password' do
it "returns index param when developer_mode is true" do it 'returns index param when developer_mode is true' do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true n.set['openstack']['developer_mode'] = true
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("user", "nova") result = @subject.get_password('user', 'nova')
result.should == "nova" result.should == 'nova'
end end
it "returns databag when developer_mode is false" do it 'returns databag when developer_mode is false' do
value = {"nova" => "this"} value = { 'nova' => 'this' }
::Chef::EncryptedDataBagItem.stub(:load_secret).with("/etc/chef/openstack_data_bag_secret").and_return "secret" ::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return 'secret'
::Chef::EncryptedDataBagItem.stub(:load).with("user_passwords", "nova", "secret").and_return value ::Chef::EncryptedDataBagItem.stub(:load).with('user_passwords', 'nova', 'secret').and_return value
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
result = @subject.get_password("user", "nova") result = @subject.get_password('user', 'nova')
result.should == "this" result.should == 'this'
end end
end end
end end

View File

@ -1,140 +1,142 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "search"
require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'search'
describe ::Openstack do describe ::Openstack do
before do before do
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n| @chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["mq"] = { n.set['openstack']['mq'] = {
"server_role" => "openstack-ops-mq", 'server_role' => 'openstack-ops-mq',
"port" => 5672 'port' => 5672
} }
end end
@chef_run.converge "openstack-common::default" @chef_run.converge 'openstack-common::default'
@subject = ::Object.new.extend ::Openstack @subject = ::Object.new.extend ::Openstack
end end
describe "#search_for" do describe '#search_for' do
it "returns results" do it 'returns results' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search). @subject.stub(:search)
with(:node, "(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)"). .with(:node, '(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)')
and_return [@chef_run.node] .and_return [@chef_run.node]
resp = @subject.search_for("role") resp = @subject.search_for('role')
expect(resp[0]['fqdn']).to eq "chefspec.local" expect(resp[0]['fqdn']).to eq 'chefspec.local'
end end
it "returns empty results" do it 'returns empty results' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search). @subject.stub(:search)
with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)"). .with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
and_return [] .and_return []
resp = @subject.search_for("empty-role") resp = @subject.search_for('empty-role')
expect(resp).to eq [] expect(resp).to eq []
end end
it "always returns empty results" do it 'always returns empty results' do
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search). @subject.stub(:search)
with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)"). .with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
and_return nil .and_return nil
resp = @subject.search_for("empty-role") resp = @subject.search_for('empty-role')
expect(resp).to eq [] expect(resp).to eq []
end end
end end
describe "#memcached_servers" do describe '#memcached_servers' do
it "returns memcached list" do it 'returns memcached list' do
nodes = [ nodes = [
{ "memcached" => { "listen" => "1.1.1.1", "port" => "11211" }}, { 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
{ "memcached" => { "listen" => "2.2.2.2", "port" => "11211" }} { 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
] ]
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search_for). @subject.stub(:search_for)
with("role"). .with('role')
and_return nodes .and_return nodes
resp = @subject.memcached_servers("role") resp = @subject.memcached_servers('role')
expect(resp).to eq ["1.1.1.1:11211", "2.2.2.2:11211"] expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211']
end end
it "returns sorted memcached list" do it 'returns sorted memcached list' do
nodes = [ nodes = [
{ "memcached" => { "listen" => "3.3.3.3", "port" => "11211" }}, { 'memcached' => { 'listen' => '3.3.3.3', 'port' => '11211' } },
{ "memcached" => { "listen" => "1.1.1.1", "port" => "11211" }}, { 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
{ "memcached" => { "listen" => "2.2.2.2", "port" => "11211" }} { 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
] ]
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search_for). @subject.stub(:search_for)
with("role"). .with('role')
and_return nodes .and_return nodes
resp = @subject.memcached_servers("role") resp = @subject.memcached_servers('role')
expect(resp).to eq ["1.1.1.1:11211", "2.2.2.2:11211", "3.3.3.3:11211"] expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211']
end end
it "returns memcached servers as defined by attributes" do it 'returns memcached servers as defined by attributes' do
nodes = { nodes = {
"openstack" => { 'openstack' => {
"memcached_servers" => ["1.1.1.1:11211", "2.2.2.2:11211"] 'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211']
} }
} }
@subject.stub(:node).and_return @chef_run.node.merge nodes @subject.stub(:node).and_return @chef_run.node.merge nodes
resp = @subject.memcached_servers("role") resp = @subject.memcached_servers('role')
expect(resp).to eq ["1.1.1.1:11211", "2.2.2.2:11211"] expect(resp).to eq ['1.1.1.1:11211', '2.2.2.2:11211']
end end
it "returns empty memcached servers as defined by attributes" do it 'returns empty memcached servers as defined by attributes' do
nodes = { nodes = {
"openstack" => { 'openstack' => {
"memcached_servers" => [] 'memcached_servers' => []
} }
} }
@subject.stub(:node).and_return @chef_run.node.merge nodes @subject.stub(:node).and_return @chef_run.node.merge nodes
resp = @subject.memcached_servers("empty-role") resp = @subject.memcached_servers('empty-role')
expect(resp).to eq [] expect(resp).to eq []
end end
end end
describe "#rabbit_servers" do describe '#rabbit_servers' do
it "returns rabbit servers" do it 'returns rabbit servers' do
nodes = [ nodes = [
{ "openstack" => { "mq" => { "listen" => "1.1.1.1", "port" => "5672" }}}, { 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
{ "openstack" => { "mq" => { "listen" => "2.2.2.2", "port" => "5672" }}}, { 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } },
] ]
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search_for). @subject.stub(:search_for)
and_return nodes .and_return nodes
resp = @subject.rabbit_servers resp = @subject.rabbit_servers
expect(resp).to eq "1.1.1.1:5672,2.2.2.2:5672" expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672'
end end
it "returns sorted rabbit servers" do it 'returns sorted rabbit servers' do
nodes = [ nodes = [
{ "openstack" => { "mq" => { "listen" => "3.3.3.3", "port" => "5672" }}}, { 'openstack' => { 'mq' => { 'listen' => '3.3.3.3', 'port' => '5672' } } },
{ "openstack" => { "mq" => { "listen" => "1.1.1.1", "port" => "5672" }}}, { 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
{ "openstack" => { "mq" => { "listen" => "2.2.2.2", "port" => "5672" }}} { 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
] ]
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
@subject.stub(:search_for). @subject.stub(:search_for)
and_return nodes .and_return nodes
resp = @subject.rabbit_servers resp = @subject.rabbit_servers
expect(resp).to eq "1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672" expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672'
end end
it "returns rabbit servers when not searching" do it 'returns rabbit servers when not searching' do
node = @chef_run.node node = @chef_run.node
node.set["openstack"]["mq"]["servers"] = ["1.1.1.1", "2.2.2.2"] node.set['openstack']['mq']['servers'] = ['1.1.1.1', '2.2.2.2']
@subject.stub(:node).and_return @chef_run.node @subject.stub(:node).and_return @chef_run.node
resp = @subject.rabbit_servers resp = @subject.rabbit_servers
expect(resp).to eq "1.1.1.1:5672,2.2.2.2:5672" expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672'
end end
end end
end end

View File

@ -1,12 +1,14 @@
require "chefspec" # encoding: UTF-8
require "chefspec/berkshelf"
require 'chefspec'
require 'chefspec/berkshelf'
::LOG_LEVEL = :fatal ::LOG_LEVEL = :fatal
::UBUNTU_OPTS = { ::UBUNTU_OPTS = {
:platform => "ubuntu", platform: 'ubuntu',
:version => "12.04", version: '12.04',
:log_level => ::LOG_LEVEL log_level: ::LOG_LEVEL
} }
::CHEFSPEC_OPTS = { ::CHEFSPEC_OPTS = {
:log_level => ::LOG_LEVEL log_level: ::LOG_LEVEL
} }

View File

@ -1,32 +1,34 @@
require_relative "spec_helper" # encoding: UTF-8
describe "openstack-common::sysctl" do require_relative 'spec_helper'
describe "ubuntu" do
describe 'openstack-common::sysctl' do
describe 'ubuntu' do
before do before do
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS @chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-common::sysctl" @chef_run.converge 'openstack-common::sysctl'
end end
describe "60-openstack.conf" do describe '60-openstack.conf' do
before do before do
@file = @chef_run.template "/etc/sysctl.d/60-openstack.conf" @file = @chef_run.template '/etc/sysctl.d/60-openstack.conf'
end end
it "has proper owner" do it 'has proper owner' do
expect(@file.owner).to eq("root") expect(@file.owner).to eq('root')
expect(@file.group).to eq("root") expect(@file.group).to eq('root')
end end
it "has proper modes" do it 'has proper modes' do
expect(sprintf("%o", @file.mode)).to eq "644" expect(sprintf('%o', @file.mode)).to eq '644'
end end
it "sets the all.rp_filter" do it 'sets the all.rp_filter' do
match = 'net.ipv4.conf.all.rp_filter = 0' match = 'net.ipv4.conf.all.rp_filter = 0'
expect(@chef_run).to render_file(@file.name).with_content(match) expect(@chef_run).to render_file(@file.name).with_content(match)
end end
it "sets the default.rp_filter" do it 'sets the default.rp_filter' do
match = 'net.ipv4.conf.default.rp_filter = 0' match = 'net.ipv4.conf.default.rp_filter = 0'
expect(@chef_run).to render_file(@file.name).with_content(match) expect(@chef_run).to render_file(@file.name).with_content(match)
end end

View File

@ -1,84 +1,86 @@
require_relative "spec_helper" # encoding: UTF-8
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "uri"
require "uri" require_relative 'spec_helper'
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri'
require 'uri'
describe ::Openstack do describe ::Openstack do
before do before do
@subject = ::Object.new.extend(::Openstack) @subject = ::Object.new.extend(::Openstack)
end end
describe "#uri_from_hash" do describe '#uri_from_hash' do
it "returns nil when no host or uri key found" do it 'returns nil when no host or uri key found' do
hash = { hash = {
"port" => 8888, 'port' => 8888,
"path" => "/path" 'path' => '/path'
} }
@subject.uri_from_hash(hash).should be_nil @subject.uri_from_hash(hash).should be_nil
end end
it "returns uri when uri key found, ignoring other parts" do it 'returns uri when uri key found, ignoring other parts' do
uri = "http://localhost/" uri = 'http://localhost/'
hash = { hash = {
"port" => 8888, 'port' => 8888,
"path" => "/path", 'path' => '/path',
"uri" => uri 'uri' => uri
} }
result = @subject.uri_from_hash(hash) result = @subject.uri_from_hash(hash)
result.should be_a URI result.should be_a URI
result.to_s.should == uri result.to_s.should == uri
end end
it "constructs from host" do it 'constructs from host' do
uri = "https://localhost:8888/path" uri = 'https://localhost:8888/path'
hash = { hash = {
"scheme" => 'https', 'scheme' => 'https',
"port" => 8888, 'port' => 8888,
"path" => "/path", 'path' => '/path',
"host" => "localhost" 'host' => 'localhost'
} }
result = @subject.uri_from_hash(hash) result = @subject.uri_from_hash(hash)
result.to_s.should == uri result.to_s.should == uri
end end
it "constructs with defaults" do it 'constructs with defaults' do
uri = "https://localhost" uri = 'https://localhost'
hash = { hash = {
"scheme" => 'https', 'scheme' => 'https',
"host" => "localhost" 'host' => 'localhost'
} }
result = @subject.uri_from_hash(hash) result = @subject.uri_from_hash(hash)
result.to_s.should == uri result.to_s.should == uri
end end
it "constructs with extraneous keys" do it 'constructs with extraneous keys' do
uri = "http://localhost" uri = 'http://localhost'
hash = { hash = {
"host" => "localhost", 'host' => 'localhost',
"network" => "public" # To emulate the osops-utils::ip_location way... 'network' => 'public' # To emulate the osops-utils::ip_location way...
} }
result = @subject.uri_from_hash(hash) result = @subject.uri_from_hash(hash)
result.to_s.should == uri result.to_s.should == uri
end end
end end
describe "#uri_join_paths" do describe '#uri_join_paths' do
it "returns nil when no paths are passed in" do it 'returns nil when no paths are passed in' do
@subject.uri_join_paths().should be_nil @subject.uri_join_paths.should be_nil
end end
it "preserves absolute path when only absolute path passed in" do it 'preserves absolute path when only absolute path passed in' do
path = "/abspath" path = '/abspath'
result = @subject.uri_join_paths(path) result = @subject.uri_join_paths(path)
result.should == path result.should == path
end end
it "preserves relative path when only relative path passed in" do it 'preserves relative path when only relative path passed in' do
path = "abspath/" path = 'abspath/'
result = @subject.uri_join_paths(path) result = @subject.uri_join_paths(path)
result.should == path result.should == path
end end
it "preserves leadng and trailing slashes" do it 'preserves leadng and trailing slashes' do
expected = "/path/to/resource/" expected = '/path/to/resource/'
result = @subject.uri_join_paths("/path", "to", "resource/") result = @subject.uri_join_paths('/path', 'to', 'resource/')
result.should == expected result.should == expected
end end
it "removes extraneous intermediate slashes" do it 'removes extraneous intermediate slashes' do
expected = "/path/to/resource" expected = '/path/to/resource'
result = @subject.uri_join_paths("/path", "//to/", "/resource") result = @subject.uri_join_paths('/path', '//to/', '/resource')
result.should == expected result.should == expected
end end
end end