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:
parent
4be974630f
commit
0b40a0686b
23
.rubocop.yml
23
.rubocop.yml
@ -1,7 +1,22 @@
|
||||
# UTF-8 headers not generally in these files
|
||||
Encoding:
|
||||
Enabled: false
|
||||
AllCops:
|
||||
Includes:
|
||||
- metadata.rb
|
||||
- Gemfile
|
||||
- attributes/**
|
||||
- recipes/**
|
||||
- spec/**
|
||||
Excludes:
|
||||
- libraries/**
|
||||
- providers/**
|
||||
- resources/**
|
||||
|
||||
Encoding:
|
||||
Exclude:
|
||||
- metadata.rb
|
||||
- Gemfile
|
||||
|
||||
# ignore long lines
|
||||
LineLength:
|
||||
Enabled: false
|
||||
|
||||
WordArray:
|
||||
MinSize: 3
|
||||
|
@ -1,8 +1,5 @@
|
||||
# Strainerfile
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile $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
|
||||
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
|
||||
knife test: bundle exec knife cookbook test $COOKBOOK
|
||||
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK
|
||||
chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec
|
||||
|
@ -1,3 +0,0 @@
|
||||
# embedded attributes make for long lines
|
||||
LineLength:
|
||||
Enabled: false
|
@ -1,39 +1,41 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "database"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'database'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@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.stub :include_recipe
|
||||
end
|
||||
|
||||
describe "#db_create_with_user" do
|
||||
it "returns nil when no such service was found" do
|
||||
describe '#db_create_with_user' do
|
||||
it 'returns nil when no such service was found' do
|
||||
@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
|
||||
|
||||
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_user).and_return {}
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.db_create_with_user "compute", "user", "pass"
|
||||
result['host'].should == "127.0.0.1"
|
||||
result['port'].should == "3306"
|
||||
result = @subject.db_create_with_user 'compute', 'user', 'pass'
|
||||
result['host'].should eq('127.0.0.1')
|
||||
result['port'].should eq('3306')
|
||||
end
|
||||
|
||||
it "creates database" do
|
||||
pending "TODO: test this LWRP"
|
||||
it 'creates database' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
|
||||
it "creates database user" do
|
||||
pending "TODO: test this LWRP"
|
||||
it 'creates database user' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
|
||||
it "grants privs to database user" do
|
||||
pending "TODO: test this LWRP"
|
||||
it 'grants privs to database user' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,11 @@
|
||||
require_relative "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
describe "openstack-common::default" do
|
||||
describe "suse" do
|
||||
it "configures openstack repository" do
|
||||
pending "TODO: implement"
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::default' do
|
||||
describe 'suse' do
|
||||
it 'configures openstack repository' do
|
||||
pending 'TODO: implement'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,22 +1,24 @@
|
||||
require_relative "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
describe "openstack-common::default" do
|
||||
describe "ubuntu" do
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::default' do
|
||||
describe 'ubuntu' 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|
|
||||
n.set["lsb"]["codename"] = "precise"
|
||||
n.set['lsb']['codename'] = 'precise'
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
end
|
||||
|
||||
it "installs ubuntu-cloud-keyring package" do
|
||||
expect(@chef_run).to install_package "ubuntu-cloud-keyring"
|
||||
it 'installs ubuntu-cloud-keyring package' do
|
||||
expect(@chef_run).to install_package 'ubuntu-cloud-keyring'
|
||||
end
|
||||
|
||||
it "configures openstack repository" do
|
||||
file = "/etc/apt/sources.list.d/openstack-ppa.list"
|
||||
expected = "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/havana main"
|
||||
it 'configures openstack repository' do
|
||||
file = '/etc/apt/sources.list.d/openstack-ppa.list'
|
||||
expected = 'deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/havana main'
|
||||
|
||||
expect(@chef_run).to render_file(file).with_content(expected)
|
||||
end
|
||||
|
@ -1,80 +1,82 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "endpoints"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'endpoints'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@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
|
||||
end
|
||||
|
||||
describe "#endpoint" do
|
||||
it "returns nil when no openstack.endpoints not in node attrs" do
|
||||
describe '#endpoint' do
|
||||
it 'returns nil when no openstack.endpoints not in node attrs' do
|
||||
@subject.stub(:node).and_return {}
|
||||
@subject.endpoint("nonexisting").should be_nil
|
||||
@subject.endpoint('nonexisting').should be_nil
|
||||
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.endpoint("nonexisting").should be_nil
|
||||
@subject.endpoint('nonexisting').should be_nil
|
||||
end
|
||||
it "handles a URI needing escaped" do
|
||||
it 'handles a URI needing escaped' do
|
||||
uri_hash = {
|
||||
"openstack" => {
|
||||
"endpoints" => {
|
||||
"compute-api" => {
|
||||
"uri" => "http://localhost:8080/v2/%(tenant_id)s"
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return uri_hash
|
||||
result = @subject.endpoint "compute-api"
|
||||
result.path.should == "/v2/%25(tenant_id)s"
|
||||
result = @subject.endpoint 'compute-api'
|
||||
result.path.should == '/v2/%25(tenant_id)s'
|
||||
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 = {
|
||||
"openstack" => {
|
||||
"endpoints" => {
|
||||
"compute-api" => {
|
||||
"uri" => "http://localhost:8080/path"
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost:8080/path'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return uri_hash
|
||||
result = @subject.endpoint "compute-api"
|
||||
result = @subject.endpoint 'compute-api'
|
||||
result.port.should == 8080
|
||||
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 = {
|
||||
"openstack" => {
|
||||
"endpoints" => {
|
||||
"compute-api" => {
|
||||
"uri" => "http://localhost",
|
||||
"host" => "ignored"
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost',
|
||||
'host' => 'ignored'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@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
|
||||
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"})
|
||||
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')
|
||||
uri_hash = {
|
||||
"openstack" => {
|
||||
"endpoints" => {
|
||||
"compute-api" => {
|
||||
"host" => "localhost",
|
||||
"port" => "8080"
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'host' => 'localhost',
|
||||
'port' => '8080'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return uri_hash
|
||||
@subject.endpoint "compute-api"
|
||||
@subject.endpoint 'compute-api'
|
||||
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'
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
chef_run.node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
|
||||
@ -82,7 +84,7 @@ describe ::Openstack do
|
||||
'interfaces' => {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
'127.0.0.1'=> {
|
||||
'127.0.0.1' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.0.0.0',
|
||||
'scope' => 'Node'
|
||||
@ -91,7 +93,7 @@ describe ::Openstack do
|
||||
},
|
||||
'eth0' => {
|
||||
'addresses' => {
|
||||
'10.0.0.100'=> {
|
||||
'10.0.0.100' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.255.255.0',
|
||||
'scope' => 'Global'
|
||||
@ -105,20 +107,20 @@ describe ::Openstack do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#endpoints" do
|
||||
it "does nothing when no endpoints" do
|
||||
describe '#endpoints' do
|
||||
it 'does nothing when no endpoints' do
|
||||
@subject.stub(:node).and_return {}
|
||||
@subject.endpoints.should be_nil
|
||||
end
|
||||
it "does nothing when empty endpoints" do
|
||||
@subject.stub(:node).and_return({"openstack" => { "endpoints" => {}}})
|
||||
it 'does nothing when empty endpoints' do
|
||||
@subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
|
||||
@count = 0
|
||||
@subject.endpoints do | ep |
|
||||
@count += 1
|
||||
end
|
||||
@count.should == 0
|
||||
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
|
||||
@count = 0
|
||||
@subject.endpoints do |ep|
|
||||
@ -128,35 +130,35 @@ describe ::Openstack do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#db" do
|
||||
it "returns nil when no openstack.db not in node attrs" do
|
||||
describe '#db' do
|
||||
it 'returns nil when no openstack.db not in node attrs' do
|
||||
@subject.stub(:node).and_return {}
|
||||
@subject.db("nonexisting").should be_nil
|
||||
@subject.db('nonexisting').should be_nil
|
||||
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.db("nonexisting").should be_nil
|
||||
@subject.db('nonexisting').should be_nil
|
||||
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.db("compute")['host'].should == "127.0.0.1"
|
||||
@subject.db("compute").has_key?("uri").should be_false
|
||||
@subject.db('compute')['host'].should eq('127.0.0.1')
|
||||
@subject.db('compute').key?('uri').should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#db_uri" do
|
||||
it "returns nil when no openstack.db not in node attrs" do
|
||||
describe '#db_uri' do
|
||||
it 'returns nil when no openstack.db not in node attrs' do
|
||||
@subject.stub(:node).and_return {}
|
||||
@subject.db_uri("nonexisting", "user", "pass").should be_nil
|
||||
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil
|
||||
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.db_uri("nonexisting", "user", "pass").should be_nil
|
||||
@subject.db_uri('nonexisting', 'user', 'pass').should be_nil
|
||||
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
|
||||
expect = "mysql://user:pass@127.0.0.1:3306/nova?charset=utf8"
|
||||
@subject.db_uri("compute", "user", "pass").should == expect
|
||||
expect = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
|
||||
@subject.db_uri('compute', 'user', 'pass').should == expect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,57 +1,60 @@
|
||||
require_relative "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
describe "openstack-common::logging" do
|
||||
describe "ubuntu" do
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::logging' do
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
@chef_run.converge "openstack-common::logging"
|
||||
@chef_run.converge 'openstack-common::logging'
|
||||
end
|
||||
|
||||
describe "/etc/openstack" do
|
||||
describe '/etc/openstack' do
|
||||
before do
|
||||
@dir = @chef_run.directory "/etc/openstack"
|
||||
@dir = @chef_run.directory '/etc/openstack'
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
expect(@dir.owner).to eq("root")
|
||||
expect(@dir.group).to eq("root")
|
||||
it 'has proper owner' do
|
||||
expect(@dir.owner).to eq('root')
|
||||
expect(@dir.group).to eq('root')
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
expect(sprintf("%o", @dir.mode)).to eq "755"
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @dir.mode)).to eq '755'
|
||||
end
|
||||
end
|
||||
|
||||
describe "logging.conf" do
|
||||
describe 'logging.conf' do
|
||||
before do
|
||||
@file = "/etc/openstack/logging.conf"
|
||||
@file = '/etc/openstack/logging.conf'
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
expect(@chef_run.template(@file).owner).to eq("root")
|
||||
expect(@chef_run.template(@file).group).to eq("root")
|
||||
it 'has proper owner' do
|
||||
expect(@chef_run.template(@file).owner).to eq('root')
|
||||
expect(@chef_run.template(@file).group).to eq('root')
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
it 'has proper modes' do
|
||||
m = @chef_run.template(@file).mode
|
||||
expect(sprintf("%o", m)).to eq "644"
|
||||
expect(sprintf('%o', m)).to eq '644'
|
||||
end
|
||||
|
||||
it "templates openstack.logging.ignore block" do
|
||||
it 'templates openstack.logging.ignore block' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
chef_run.converge "openstack-common::logging"
|
||||
chef_run.converge 'openstack-common::logging'
|
||||
node = chef_run.node
|
||||
node.set["openstack"]["logging"]["ignore"] = {
|
||||
"test.nova.api.openstack.wsgi" => "WARNING"
|
||||
node.set['openstack']['logging']['ignore'] = {
|
||||
'test.nova.api.openstack.wsgi' => 'WARNING'
|
||||
}
|
||||
|
||||
tmp = [
|
||||
"[logger_test_nova_api_openstack_wsgi]",
|
||||
"level = WARNING",
|
||||
"handlers = prod,debug",
|
||||
"qualname = test.nova.api.openstack.wsgi"
|
||||
'[logger_test_nova_api_openstack_wsgi]',
|
||||
'level = WARNING',
|
||||
'handlers = prod,debug',
|
||||
'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
|
||||
|
@ -1,46 +1,48 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "network"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'network'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["network"] = {
|
||||
"interfaces" => {
|
||||
"lo" => {
|
||||
"addresses" => {
|
||||
"127.0.0.1"=> {
|
||||
"family" => "inet",
|
||||
"prefixlen" => "8",
|
||||
"netmask" => "255.0.0.0",
|
||||
"scope" => "Node"
|
||||
n.set['network'] = {
|
||||
'interfaces' => {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
'127.0.0.1' => {
|
||||
'family' => 'inet',
|
||||
'prefixlen' => '8',
|
||||
'netmask' => '255.0.0.0',
|
||||
'scope' => 'Node'
|
||||
},
|
||||
"::1" => {
|
||||
"family" => "inet6",
|
||||
"prefixlen" => "128",
|
||||
"scope" => "Node"
|
||||
'::1' => {
|
||||
'family' => 'inet6',
|
||||
'prefixlen' => '128',
|
||||
'scope' => 'Node'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
end
|
||||
|
||||
describe "#address_for" do
|
||||
it "returns ipv4 address" do
|
||||
describe '#address_for' do
|
||||
it 'returns ipv4 address' do
|
||||
@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
|
||||
|
||||
it "returns ipv4 address" do
|
||||
it 'returns ipv4 address' do
|
||||
@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
|
||||
|
@ -1,65 +1,67 @@
|
||||
require_relative "spec_helper"
|
||||
require "uri"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "parse"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require 'uri'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'parse'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@subject = ::Object.new.extend(::Openstack)
|
||||
end
|
||||
|
||||
describe "#prettytable_to_array" do
|
||||
it "returns [] when no table provided" do
|
||||
describe '#prettytable_to_array' do
|
||||
it 'returns [] when no table provided' do
|
||||
@subject.prettytable_to_array(nil).should == []
|
||||
end
|
||||
it "returns [] when table provided is empty" do
|
||||
@subject.prettytable_to_array("").should == []
|
||||
it 'returns [] when table provided is empty' do
|
||||
@subject.prettytable_to_array('').should == []
|
||||
end
|
||||
it "returns proper array of hashes when proper table provided" do
|
||||
it 'returns proper array of hashes when proper table provided' do
|
||||
table =
|
||||
"+---------+----------------------------------+----------------------------------+
|
||||
'+---------+----------------------------------+----------------------------------+
|
||||
| tenant | access | secret |
|
||||
+---------+----------------------------------+----------------------------------+
|
||||
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
|
||||
+---------+----------------------------------+----------------------------------+"
|
||||
+---------+----------------------------------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
[{"tenant" => "service",
|
||||
"access" => "91af731b3be244beb8f30fc59b7bc96d",
|
||||
"secret" => "ce811442cfb549c39390a203778a4bf5"}]
|
||||
[{ 'tenant' => 'service',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
|
||||
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 =
|
||||
"+---------+----------------------------------+----------------------------------+
|
||||
'+---------+----------------------------------+----------------------------------+
|
||||
| tenant | access | secret |
|
||||
+---------+----------------------------------+----------------------------------+
|
||||
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
|
||||
+---------+----------------------------------+----------------------------------+
|
||||
|
||||
|
||||
"
|
||||
'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
[{"tenant" => "service",
|
||||
"access" => "91af731b3be244beb8f30fc59b7bc96d",
|
||||
"secret" => "ce811442cfb549c39390a203778a4bf5"}]
|
||||
[{ 'tenant' => 'service',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
|
||||
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 =
|
||||
"+-----------+----------------------------------+
|
||||
'+-----------+----------------------------------+
|
||||
| Property | Value |
|
||||
+-----------+----------------------------------+
|
||||
| access | 91af731b3be244beb8f30fc59b7bc96d |
|
||||
| secret | ce811442cfb549c39390a203778a4bf5 |
|
||||
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
|
||||
| user_id | 1c4fc229560f40689c490c5d0838fd84 |
|
||||
+-----------+----------------------------------+"
|
||||
+-----------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
[{"tenant_id" => "429271dd1cf54b7ca921a0017524d8ea",
|
||||
"access" => "91af731b3be244beb8f30fc59b7bc96d",
|
||||
"secret" => "ce811442cfb549c39390a203778a4bf5",
|
||||
"user_id" => "1c4fc229560f40689c490c5d0838fd84"}]
|
||||
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5',
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
|
||||
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 =
|
||||
"
|
||||
'
|
||||
|
||||
+-----------+----------------------------------+
|
||||
| Property | Value |
|
||||
@ -68,12 +70,12 @@ describe ::Openstack do
|
||||
| secret | ce811442cfb549c39390a203778a4bf5 |
|
||||
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
|
||||
| user_id | 1c4fc229560f40689c490c5d0838fd84 |
|
||||
+-----------+----------------------------------+"
|
||||
+-----------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
[{"tenant_id" => "429271dd1cf54b7ca921a0017524d8ea",
|
||||
"access" => "91af731b3be244beb8f30fc59b7bc96d",
|
||||
"secret" => "ce811442cfb549c39390a203778a4bf5",
|
||||
"user_id" => "1c4fc229560f40689c490c5d0838fd84"}]
|
||||
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5',
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,90 +1,92 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "passwords"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'passwords'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new ::CHEFSPEC_OPTS
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject = ::Object.new.extend(::Openstack)
|
||||
end
|
||||
|
||||
describe "#secret" do
|
||||
it "returns index param when developer_mode is true" do
|
||||
describe '#secret' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["openstack"]["developer_mode"] = true
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.secret("passwords", "nova")
|
||||
result.should == "nova"
|
||||
result = @subject.secret('passwords', 'nova')
|
||||
result.should == 'nova'
|
||||
end
|
||||
it "returns databag when developer_mode is false" do
|
||||
value = {"nova" => "this"}
|
||||
::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
|
||||
it 'returns databag when developer_mode is false' do
|
||||
value = { 'nova' => 'this' }
|
||||
::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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.secret("passwords", "nova")
|
||||
result.should == "this"
|
||||
result = @subject.secret('passwords', 'nova')
|
||||
result.should == 'this'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_password_service_password" do
|
||||
it "returns index param when developer_mode is true" do
|
||||
describe '#get_password_service_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["openstack"]["developer_mode"] = true
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("service", "nova")
|
||||
result.should == "nova"
|
||||
result = @subject.get_password('service', 'nova')
|
||||
result.should == 'nova'
|
||||
end
|
||||
it "returns databag when developer_mode is false" do
|
||||
value = {"nova" => "this"}
|
||||
::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
|
||||
it 'returns databag when developer_mode is false' do
|
||||
value = { 'nova' => 'this' }
|
||||
::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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("service", "nova")
|
||||
result.should == "this"
|
||||
result = @subject.get_password('service', 'nova')
|
||||
result.should == 'this'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_password_db_password" do
|
||||
it "returns index param when developer_mode is true" do
|
||||
describe '#get_password_db_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["openstack"]["developer_mode"] = true
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("db", "nova")
|
||||
result.should == "nova"
|
||||
result = @subject.get_password('db', 'nova')
|
||||
result.should == 'nova'
|
||||
end
|
||||
it "returns databag when developer_mode is false" do
|
||||
value = {"nova" => "this"}
|
||||
::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
|
||||
it 'returns databag when developer_mode is false' do
|
||||
value = { 'nova' => 'this' }
|
||||
::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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("db", "nova")
|
||||
result.should == "this"
|
||||
result = @subject.get_password('db', 'nova')
|
||||
result.should == 'this'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#get_password_user_password" do
|
||||
it "returns index param when developer_mode is true" do
|
||||
describe '#get_password_user_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["openstack"]["developer_mode"] = true
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("user", "nova")
|
||||
result.should == "nova"
|
||||
result = @subject.get_password('user', 'nova')
|
||||
result.should == 'nova'
|
||||
end
|
||||
it "returns databag when developer_mode is false" do
|
||||
value = {"nova" => "this"}
|
||||
::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
|
||||
it 'returns databag when developer_mode is false' do
|
||||
value = { 'nova' => 'this' }
|
||||
::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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password("user", "nova")
|
||||
result.should == "this"
|
||||
result = @subject.get_password('user', 'nova')
|
||||
result.should == 'this'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,140 +1,142 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "search"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'search'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set["openstack"]["mq"] = {
|
||||
"server_role" => "openstack-ops-mq",
|
||||
"port" => 5672
|
||||
n.set['openstack']['mq'] = {
|
||||
'server_role' => 'openstack-ops-mq',
|
||||
'port' => 5672
|
||||
}
|
||||
end
|
||||
@chef_run.converge "openstack-common::default"
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
end
|
||||
|
||||
describe "#search_for" do
|
||||
it "returns results" do
|
||||
describe '#search_for' do
|
||||
it 'returns results' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search).
|
||||
with(:node, "(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)").
|
||||
and_return [@chef_run.node]
|
||||
resp = @subject.search_for("role")
|
||||
@subject.stub(:search)
|
||||
.with(:node, '(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)')
|
||||
.and_return [@chef_run.node]
|
||||
resp = @subject.search_for('role')
|
||||
|
||||
expect(resp[0]['fqdn']).to eq "chefspec.local"
|
||||
expect(resp[0]['fqdn']).to eq 'chefspec.local'
|
||||
end
|
||||
|
||||
it "returns empty results" do
|
||||
it 'returns empty results' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search).
|
||||
with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)").
|
||||
and_return []
|
||||
resp = @subject.search_for("empty-role")
|
||||
@subject.stub(:search)
|
||||
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
||||
.and_return []
|
||||
resp = @subject.search_for('empty-role')
|
||||
|
||||
expect(resp).to eq []
|
||||
end
|
||||
|
||||
it "always returns empty results" do
|
||||
it 'always returns empty results' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search).
|
||||
with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)").
|
||||
and_return nil
|
||||
resp = @subject.search_for("empty-role")
|
||||
@subject.stub(:search)
|
||||
.with(:node, '(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)')
|
||||
.and_return nil
|
||||
resp = @subject.search_for('empty-role')
|
||||
|
||||
expect(resp).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
describe "#memcached_servers" do
|
||||
it "returns memcached list" do
|
||||
describe '#memcached_servers' do
|
||||
it 'returns memcached list' do
|
||||
nodes = [
|
||||
{ "memcached" => { "listen" => "1.1.1.1", "port" => "11211" }},
|
||||
{ "memcached" => { "listen" => "2.2.2.2", "port" => "11211" }}
|
||||
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
||||
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search_for).
|
||||
with("role").
|
||||
and_return nodes
|
||||
resp = @subject.memcached_servers("role")
|
||||
@subject.stub(:search_for)
|
||||
.with('role')
|
||||
.and_return nodes
|
||||
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
|
||||
|
||||
it "returns sorted memcached list" do
|
||||
it 'returns sorted memcached list' do
|
||||
nodes = [
|
||||
{ "memcached" => { "listen" => "3.3.3.3", "port" => "11211" }},
|
||||
{ "memcached" => { "listen" => "1.1.1.1", "port" => "11211" }},
|
||||
{ "memcached" => { "listen" => "2.2.2.2", "port" => "11211" }}
|
||||
{ 'memcached' => { 'listen' => '3.3.3.3', 'port' => '11211' } },
|
||||
{ 'memcached' => { 'listen' => '1.1.1.1', 'port' => '11211' } },
|
||||
{ 'memcached' => { 'listen' => '2.2.2.2', 'port' => '11211' } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search_for).
|
||||
with("role").
|
||||
and_return nodes
|
||||
resp = @subject.memcached_servers("role")
|
||||
@subject.stub(:search_for)
|
||||
.with('role')
|
||||
.and_return nodes
|
||||
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
|
||||
|
||||
it "returns memcached servers as defined by attributes" do
|
||||
it 'returns memcached servers as defined by attributes' do
|
||||
nodes = {
|
||||
"openstack" => {
|
||||
"memcached_servers" => ["1.1.1.1:11211", "2.2.2.2:11211"]
|
||||
'openstack' => {
|
||||
'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211']
|
||||
}
|
||||
}
|
||||
@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
|
||||
|
||||
it "returns empty memcached servers as defined by attributes" do
|
||||
it 'returns empty memcached servers as defined by attributes' do
|
||||
nodes = {
|
||||
"openstack" => {
|
||||
"memcached_servers" => []
|
||||
'openstack' => {
|
||||
'memcached_servers' => []
|
||||
}
|
||||
}
|
||||
@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 []
|
||||
end
|
||||
end
|
||||
|
||||
describe "#rabbit_servers" do
|
||||
it "returns rabbit servers" do
|
||||
describe '#rabbit_servers' do
|
||||
it 'returns rabbit servers' do
|
||||
nodes = [
|
||||
{ "openstack" => { "mq" => { "listen" => "1.1.1.1", "port" => "5672" }}},
|
||||
{ "openstack" => { "mq" => { "listen" => "2.2.2.2", "port" => "5672" }}},
|
||||
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
|
||||
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } },
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search_for).
|
||||
and_return nodes
|
||||
@subject.stub(:search_for)
|
||||
.and_return nodes
|
||||
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
|
||||
|
||||
it "returns sorted rabbit servers" do
|
||||
it 'returns sorted rabbit servers' do
|
||||
nodes = [
|
||||
{ "openstack" => { "mq" => { "listen" => "3.3.3.3", "port" => "5672" }}},
|
||||
{ "openstack" => { "mq" => { "listen" => "1.1.1.1", "port" => "5672" }}},
|
||||
{ "openstack" => { "mq" => { "listen" => "2.2.2.2", "port" => "5672" }}}
|
||||
{ 'openstack' => { 'mq' => { 'listen' => '3.3.3.3', 'port' => '5672' } } },
|
||||
{ 'openstack' => { 'mq' => { 'listen' => '1.1.1.1', 'port' => '5672' } } },
|
||||
{ 'openstack' => { 'mq' => { 'listen' => '2.2.2.2', 'port' => '5672' } } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search_for).
|
||||
and_return nodes
|
||||
@subject.stub(:search_for)
|
||||
.and_return nodes
|
||||
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
|
||||
|
||||
it "returns rabbit servers when not searching" do
|
||||
it 'returns rabbit servers when not searching' do
|
||||
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
|
||||
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
|
||||
|
@ -1,12 +1,14 @@
|
||||
require "chefspec"
|
||||
require "chefspec/berkshelf"
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::UBUNTU_OPTS = {
|
||||
:platform => "ubuntu",
|
||||
:version => "12.04",
|
||||
:log_level => ::LOG_LEVEL
|
||||
platform: 'ubuntu',
|
||||
version: '12.04',
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
::CHEFSPEC_OPTS = {
|
||||
:log_level => ::LOG_LEVEL
|
||||
log_level: ::LOG_LEVEL
|
||||
}
|
||||
|
@ -1,32 +1,34 @@
|
||||
require_relative "spec_helper"
|
||||
# encoding: UTF-8
|
||||
|
||||
describe "openstack-common::sysctl" do
|
||||
describe "ubuntu" do
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::sysctl' do
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
@chef_run.converge "openstack-common::sysctl"
|
||||
@chef_run.converge 'openstack-common::sysctl'
|
||||
end
|
||||
|
||||
describe "60-openstack.conf" do
|
||||
describe '60-openstack.conf' do
|
||||
before do
|
||||
@file = @chef_run.template "/etc/sysctl.d/60-openstack.conf"
|
||||
@file = @chef_run.template '/etc/sysctl.d/60-openstack.conf'
|
||||
end
|
||||
|
||||
it "has proper owner" do
|
||||
expect(@file.owner).to eq("root")
|
||||
expect(@file.group).to eq("root")
|
||||
it 'has proper owner' do
|
||||
expect(@file.owner).to eq('root')
|
||||
expect(@file.group).to eq('root')
|
||||
end
|
||||
|
||||
it "has proper modes" do
|
||||
expect(sprintf("%o", @file.mode)).to eq "644"
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @file.mode)).to eq '644'
|
||||
end
|
||||
|
||||
it "sets the all.rp_filter" do
|
||||
it 'sets the all.rp_filter' do
|
||||
match = 'net.ipv4.conf.all.rp_filter = 0'
|
||||
expect(@chef_run).to render_file(@file.name).with_content(match)
|
||||
end
|
||||
|
||||
it "sets the default.rp_filter" do
|
||||
it 'sets the default.rp_filter' do
|
||||
match = 'net.ipv4.conf.default.rp_filter = 0'
|
||||
expect(@chef_run).to render_file(@file.name).with_content(match)
|
||||
end
|
||||
|
@ -1,84 +1,86 @@
|
||||
require_relative "spec_helper"
|
||||
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "uri"
|
||||
require "uri"
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri'
|
||||
require 'uri'
|
||||
|
||||
describe ::Openstack do
|
||||
before do
|
||||
@subject = ::Object.new.extend(::Openstack)
|
||||
end
|
||||
|
||||
describe "#uri_from_hash" do
|
||||
it "returns nil when no host or uri key found" do
|
||||
describe '#uri_from_hash' do
|
||||
it 'returns nil when no host or uri key found' do
|
||||
hash = {
|
||||
"port" => 8888,
|
||||
"path" => "/path"
|
||||
'port' => 8888,
|
||||
'path' => '/path'
|
||||
}
|
||||
@subject.uri_from_hash(hash).should be_nil
|
||||
end
|
||||
it "returns uri when uri key found, ignoring other parts" do
|
||||
uri = "http://localhost/"
|
||||
it 'returns uri when uri key found, ignoring other parts' do
|
||||
uri = 'http://localhost/'
|
||||
hash = {
|
||||
"port" => 8888,
|
||||
"path" => "/path",
|
||||
"uri" => uri
|
||||
'port' => 8888,
|
||||
'path' => '/path',
|
||||
'uri' => uri
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.should be_a URI
|
||||
result.to_s.should == uri
|
||||
end
|
||||
it "constructs from host" do
|
||||
uri = "https://localhost:8888/path"
|
||||
it 'constructs from host' do
|
||||
uri = 'https://localhost:8888/path'
|
||||
hash = {
|
||||
"scheme" => 'https',
|
||||
"port" => 8888,
|
||||
"path" => "/path",
|
||||
"host" => "localhost"
|
||||
'scheme' => 'https',
|
||||
'port' => 8888,
|
||||
'path' => '/path',
|
||||
'host' => 'localhost'
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
end
|
||||
it "constructs with defaults" do
|
||||
uri = "https://localhost"
|
||||
it 'constructs with defaults' do
|
||||
uri = 'https://localhost'
|
||||
hash = {
|
||||
"scheme" => 'https',
|
||||
"host" => "localhost"
|
||||
'scheme' => 'https',
|
||||
'host' => 'localhost'
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
end
|
||||
it "constructs with extraneous keys" do
|
||||
uri = "http://localhost"
|
||||
it 'constructs with extraneous keys' do
|
||||
uri = 'http://localhost'
|
||||
hash = {
|
||||
"host" => "localhost",
|
||||
"network" => "public" # To emulate the osops-utils::ip_location way...
|
||||
'host' => 'localhost',
|
||||
'network' => 'public' # To emulate the osops-utils::ip_location way...
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
end
|
||||
end
|
||||
|
||||
describe "#uri_join_paths" do
|
||||
it "returns nil when no paths are passed in" do
|
||||
@subject.uri_join_paths().should be_nil
|
||||
describe '#uri_join_paths' do
|
||||
it 'returns nil when no paths are passed in' do
|
||||
@subject.uri_join_paths.should be_nil
|
||||
end
|
||||
it "preserves absolute path when only absolute path passed in" do
|
||||
path = "/abspath"
|
||||
it 'preserves absolute path when only absolute path passed in' do
|
||||
path = '/abspath'
|
||||
result = @subject.uri_join_paths(path)
|
||||
result.should == path
|
||||
end
|
||||
it "preserves relative path when only relative path passed in" do
|
||||
path = "abspath/"
|
||||
it 'preserves relative path when only relative path passed in' do
|
||||
path = 'abspath/'
|
||||
result = @subject.uri_join_paths(path)
|
||||
result.should == path
|
||||
end
|
||||
it "preserves leadng and trailing slashes" do
|
||||
expected = "/path/to/resource/"
|
||||
result = @subject.uri_join_paths("/path", "to", "resource/")
|
||||
it 'preserves leadng and trailing slashes' do
|
||||
expected = '/path/to/resource/'
|
||||
result = @subject.uri_join_paths('/path', 'to', 'resource/')
|
||||
result.should == expected
|
||||
end
|
||||
it "removes extraneous intermediate slashes" do
|
||||
expected = "/path/to/resource"
|
||||
result = @subject.uri_join_paths("/path", "//to/", "/resource")
|
||||
it 'removes extraneous intermediate slashes' do
|
||||
expected = '/path/to/resource'
|
||||
result = @subject.uri_join_paths('/path', '//to/', '/resource')
|
||||
result.should == expected
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user