Refactoring chefspec tests
Change-Id: I35dfca684039512e2a238466ff7df5f3fd34d956 Addresses: blueprint refactor-spec-files Closes-Bug: 1282996
This commit is contained in:
parent
4ad20f5e56
commit
ffe0d05a0d
@ -15,7 +15,7 @@ recipe 'openstack-common::sysctl', 'Configures sysctl settings'
|
||||
supports os
|
||||
end
|
||||
|
||||
depends 'apt'
|
||||
depends 'apt', '~> 2.3.8'
|
||||
depends 'database'
|
||||
depends 'yum', '~> 3.0'
|
||||
depends 'yum-epel'
|
||||
|
@ -4,27 +4,29 @@ require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::ceph_client' do
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
opts = ::UBUNTU_OPTS.merge(step_into: ['apt_repository'])
|
||||
@chef_run = ::ChefSpec::Runner.new(opts) do |n|
|
||||
n.set['openstack']['ceph']['global']['fsid'] = '9e5038a9-4329-4cad-8c24-0813a49d1125'
|
||||
n.set['openstack']['ceph']['global']['mon_initial_members'] = %w{ 10.0.1.10 10.0.1.20 }
|
||||
n.set['openstack']['ceph']['global']['mon_hosts'] = %w{ mon01 mon02 }
|
||||
n.set['lsb']['codename'] = 'precise'
|
||||
end
|
||||
@filename = '/etc/ceph/ceph.conf'
|
||||
@chef_run.converge 'openstack-common::ceph_client'
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.set['openstack']['ceph']['global']['fsid'] = '9e5038a9-4329-4cad-8c24-0813a49d1125'
|
||||
node.set['openstack']['ceph']['global']['mon_initial_members'] = %w{ 10.0.1.10 10.0.1.20 }
|
||||
node.set['openstack']['ceph']['global']['mon_hosts'] = %w{ mon01 mon02 }
|
||||
node.set['lsb']['codename'] = 'precise'
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/ceph/ceph.conf') }
|
||||
|
||||
it 'configures ceph repository' do
|
||||
file = '/etc/apt/sources.list.d/ceph.list'
|
||||
expected = 'deb http://ceph.com/debian-emperor precise main'
|
||||
|
||||
expect(@chef_run).to render_file(file).with_content(expected)
|
||||
# Using cookbook(apt) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to add_apt_repository('ceph').with(
|
||||
uri: 'http://ceph.com/debian-emperor',
|
||||
components: ['main'],
|
||||
distribution: 'precise')
|
||||
end
|
||||
|
||||
it 'creates the /etc/ceph/ceph.conf file' do
|
||||
expect(@chef_run).to create_template(@filename).with(
|
||||
expect(chef_run).to create_template(file.name).with(
|
||||
owner: 'root',
|
||||
group: 'root',
|
||||
mode: '644'
|
||||
@ -36,9 +38,8 @@ describe 'openstack-common::ceph_client' do
|
||||
/^fsid = 9e5038a9-4329-4cad-8c24-0813a49d1125$/,
|
||||
/^mon_initial_members = 10.0.1.10, 10.0.1.20$/,
|
||||
/^mon_hosts = mon01, mon02$/].each do |content|
|
||||
expect(@chef_run).to render_file(@filename).with_content(content)
|
||||
expect(chef_run).to render_file(file.name).with_content(content)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,41 +1,48 @@
|
||||
# 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'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
@subject.stub :include_recipe
|
||||
end
|
||||
describe 'openstack-common::default' do
|
||||
describe 'Openstack Database' do
|
||||
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
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
|
||||
end
|
||||
include_context 'library-stubs'
|
||||
|
||||
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 eq('127.0.0.1')
|
||||
result['port'].should eq('3306')
|
||||
end
|
||||
describe '#db_create_with_user' do
|
||||
before do
|
||||
subject.stub(:include_recipe)
|
||||
.with('database::mysql')
|
||||
.and_return('')
|
||||
end
|
||||
|
||||
it 'creates database' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
it 'returns nil when no such service was found' do
|
||||
expect(
|
||||
subject.db_create_with_user('nonexisting', 'user', 'pass')
|
||||
).to be_nil
|
||||
end
|
||||
|
||||
it 'creates database user' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
it 'returns db info and creates database with user when service found' do
|
||||
subject.stub(:database).and_return({})
|
||||
subject.stub(:database_user).and_return({})
|
||||
result = subject.db_create_with_user('compute', 'user', 'pass')
|
||||
expect(result['host']).to eq('127.0.0.1')
|
||||
expect(result['port']).to eq('3306')
|
||||
end
|
||||
|
||||
it 'grants privs to database user' 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'
|
||||
end
|
||||
|
||||
it 'grants privs to database user' do
|
||||
pending 'TODO: test this LWRP'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,40 +1,46 @@
|
||||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::default' do
|
||||
describe 'rhel-rdo' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::REDHAT_OPTS) do |n|
|
||||
n.set['openstack']['release'] = 'testrelease'
|
||||
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.set['openstack']['release'] = 'testrelease'
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
context 'enabling RDO' do
|
||||
before do
|
||||
node.set['openstack']['yum']['rdo_enabled'] = true
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
end
|
||||
|
||||
it 'configures RDO yum repository' do
|
||||
repo_name = 'RDO-testrelease'
|
||||
expect(@chef_run).to add_yum_repository(repo_name)
|
||||
end
|
||||
|
||||
it 'includes yum-epel recipe' do
|
||||
expect(@chef_run).to include_recipe('yum-epel')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'rhel-no-rdo' do
|
||||
before do
|
||||
@chef_run = ::ChefSpec::Runner.new(::REDHAT_OPTS) do |n|
|
||||
n.set['openstack']['release'] = 'testrelease'
|
||||
n.set['openstack']['yum']['rdo_enabled'] = false
|
||||
it 'adds RDO yum repository' do
|
||||
# Using cookbook(yum) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to add_yum_repository('RDO-testrelease')
|
||||
end
|
||||
|
||||
it 'includes yum-epel recipe' do
|
||||
expect(chef_run).to include_recipe('yum-epel')
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
end
|
||||
|
||||
it 'configures RDO yum repository' do
|
||||
repo_name = 'RDO-testrelease'
|
||||
expect(@chef_run).to remove_yum_repository(repo_name)
|
||||
end
|
||||
context 'disabling RDO' do
|
||||
before do
|
||||
node.set['openstack']['yum']['rdo_enabled'] = false
|
||||
end
|
||||
|
||||
it 'does not include yum-epel recipe' do
|
||||
expect(@chef_run).to_not include_recipe('yum-epel')
|
||||
it 'removes RDO yum repository' do
|
||||
# Using cookbook(yum) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to remove_yum_repository('RDO-testrelease')
|
||||
end
|
||||
|
||||
it 'does not include yum-epel recipe' do
|
||||
expect(chef_run).to_not include_recipe('yum-epel')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::default' do
|
||||
|
@ -1,26 +1,26 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::default' do
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
opts = ::UBUNTU_OPTS.merge step_into: ['apt_repository']
|
||||
@chef_run = ::ChefSpec::Runner.new(opts) do |n|
|
||||
n.set['lsb']['codename'] = 'precise'
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.set['lsb']['codename'] = 'precise'
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
# Using cookbook(apt) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to add_apt_repository('openstack-ppa').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
components: ['precise-updates/havana', 'main'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,164 +1,187 @@
|
||||
# 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'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
end
|
||||
describe 'openstack-common::set_endpoints_by_interface' do
|
||||
describe 'Openstack endpoints' do
|
||||
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
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
|
||||
end
|
||||
it 'returns nil when no such endpoint was found' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.endpoint('nonexisting').should be_nil
|
||||
end
|
||||
it 'handles a URI needing escaped' do
|
||||
uri_hash = {
|
||||
'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'
|
||||
end
|
||||
it 'returns endpoint URI object when uri key in endpoint hash' do
|
||||
uri_hash = {
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost:8080/path'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return uri_hash
|
||||
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
|
||||
uri_hash = {
|
||||
'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'
|
||||
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')
|
||||
uri_hash = {
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'host' => 'localhost',
|
||||
'port' => '8080'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return uri_hash
|
||||
@subject.endpoint 'compute-api'
|
||||
end
|
||||
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'
|
||||
chef_run.node.set['network'] = {
|
||||
'interfaces' => {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
'127.0.0.1' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.0.0.0',
|
||||
'scope' => 'Node'
|
||||
}
|
||||
}
|
||||
},
|
||||
'eth0' => {
|
||||
'addresses' => {
|
||||
'10.0.0.100' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.255.255.0',
|
||||
'scope' => 'Global'
|
||||
describe '#endpoint' do
|
||||
it 'returns nil when no openstack.endpoints not in node attrs' do
|
||||
subject.stub(:node).and_return({})
|
||||
expect(
|
||||
subject.endpoint('nonexisting')
|
||||
).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when no such endpoint was found' do
|
||||
subject.stub(:node).and_return(node)
|
||||
expect(
|
||||
subject.endpoint('nonexisting')
|
||||
).to be_nil
|
||||
end
|
||||
|
||||
it 'handles a URI needing escaped' do
|
||||
uri_hash = {
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost:8080/v2/%(tenant_id)s'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
chef_run.converge 'openstack-common::set_endpoints_by_interface'
|
||||
expect(chef_run.node['openstack']['endpoints']['identity-api']['host']).to eql('10.0.0.100')
|
||||
end
|
||||
end
|
||||
|
||||
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' => {} })
|
||||
@count = 0
|
||||
@subject.endpoints do | ep |
|
||||
@count += 1
|
||||
subject.stub(:node).and_return(uri_hash)
|
||||
expect(
|
||||
subject.endpoint('compute-api').path
|
||||
).to eq('/v2/%25(tenant_id)s')
|
||||
end
|
||||
@count.should == 0
|
||||
end
|
||||
it 'executes block count when have endpoints' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@count = 0
|
||||
@subject.endpoints do |ep|
|
||||
@count += 1
|
||||
|
||||
it 'returns endpoint URI object when uri key in endpoint hash' do
|
||||
uri_hash = {
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'uri' => 'http://localhost:8080/path'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subject.stub(:node).and_return(uri_hash)
|
||||
expect(
|
||||
subject.endpoint('compute-api').port
|
||||
).to eq(8080)
|
||||
end
|
||||
@count.should >= 1
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
it 'returns nil when no such service was found' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.db('nonexisting').should be_nil
|
||||
end
|
||||
it 'returns db info hash when service found' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.db('compute')['host'].should eq('127.0.0.1')
|
||||
@subject.db('compute').key?('uri').should be_false
|
||||
end
|
||||
end
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subject.stub(:node).and_return(uri_hash)
|
||||
expect(subject.endpoint('compute-api').to_s).to eq('http://localhost')
|
||||
end
|
||||
|
||||
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
|
||||
it 'returns endpoint URI object when uri key not in endpoint hash but host is in hash' do
|
||||
pending 'TODO: implement'
|
||||
subject.should_receive(:uri_from_hash).with('host' => 'localhost', 'port' => '8080')
|
||||
uri_hash = {
|
||||
'openstack' => {
|
||||
'endpoints' => {
|
||||
'compute-api' => {
|
||||
'host' => 'localhost',
|
||||
'port' => '8080'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subject.stub(:node).and_return(uri_hash)
|
||||
subject.endpoint 'compute-api'
|
||||
end
|
||||
|
||||
it 'endpoints recipe bind_interface sets host' do
|
||||
node.set['openstack']['endpoints']['identity-api']['bind_interface'] = 'eth0'
|
||||
node.set['network'] = {
|
||||
'interfaces' => {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
'127.0.0.1' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.0.0.0',
|
||||
'scope' => 'Node'
|
||||
}
|
||||
}
|
||||
},
|
||||
'eth0' => {
|
||||
'addresses' => {
|
||||
'10.0.0.100' => {
|
||||
'family' => 'inet',
|
||||
'netmask' => '255.255.255.0',
|
||||
'scope' => 'Global'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
subject.stub('address_for').and_return('10.0.0.100')
|
||||
expect(
|
||||
chef_run.node['openstack']['endpoints']['identity-api']['host']
|
||||
).to eq('10.0.0.100')
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
describe '#endpoints' do
|
||||
it 'does nothing when no endpoints' do
|
||||
subject.stub(:node).and_return({})
|
||||
expect(subject.endpoints).to be_nil
|
||||
end
|
||||
|
||||
it 'does nothing when empty endpoints' do
|
||||
subject.stub(:node).and_return('openstack' => { 'endpoints' => {} })
|
||||
count = 0
|
||||
subject.endpoints do | ep |
|
||||
count += 1
|
||||
end
|
||||
expect(count).to eq(0)
|
||||
end
|
||||
|
||||
it 'executes block count when have endpoints' do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
count = 0
|
||||
subject.endpoints do |ep|
|
||||
count += 1
|
||||
end
|
||||
expect(count).to be >= 1
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
describe '#db' do
|
||||
it 'returns nil when no openstack.db not in node attrs' do
|
||||
subject.stub(:node).and_return({})
|
||||
expect(subject.db('nonexisting')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when no such service was found' do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
expect(subject.db('nonexisting')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns db info hash when service found' do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
expect(subject.db('compute')['host']).to eq('127.0.0.1')
|
||||
expect(subject.db('compute').key?('uri')).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#db_uri' do
|
||||
it 'returns nil when no openstack.db not in node attrs' do
|
||||
subject.stub(:node).and_return({})
|
||||
expect(subject.db_uri('nonexisting', 'user', 'pass')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when no such service was found' do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
expect(
|
||||
subject.db_uri('nonexisting', 'user', 'pass')
|
||||
).to be_nil
|
||||
end
|
||||
|
||||
it 'returns db info hash when service found' do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
expected = 'mysql://user:pass@127.0.0.1:3306/nova?charset=utf8'
|
||||
expect(
|
||||
subject.db_uri('compute', 'user', 'pass')
|
||||
).to eq(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,48 +1,38 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
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'
|
||||
end
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
|
||||
describe '/etc/openstack' do
|
||||
before do
|
||||
@dir = @chef_run.directory '/etc/openstack'
|
||||
end
|
||||
let(:dir) { chef_run.directory('/etc/openstack') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@dir.owner).to eq('root')
|
||||
expect(@dir.group).to eq('root')
|
||||
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'
|
||||
expect(sprintf('%o', dir.mode)).to eq '755'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'logging.conf' do
|
||||
before do
|
||||
@file = '/etc/openstack/logging.conf'
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/openstack/logging.conf') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@chef_run.template(@file).owner).to eq('root')
|
||||
expect(@chef_run.template(@file).group).to eq('root')
|
||||
expect(file.owner).to eq('root')
|
||||
expect(file.group).to eq('root')
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
m = @chef_run.template(@file).mode
|
||||
expect(sprintf('%o', m)).to eq '644'
|
||||
expect(sprintf('%o', file.mode)).to eq '644'
|
||||
end
|
||||
|
||||
it 'templates openstack.logging.ignore block' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
chef_run.converge 'openstack-common::logging'
|
||||
node = chef_run.node
|
||||
node.set['openstack']['logging']['ignore'] = {
|
||||
'test.nova.api.openstack.wsgi' => 'WARNING'
|
||||
}
|
||||
@ -53,7 +43,7 @@ describe 'openstack-common::logging' do
|
||||
'handlers = prod,debug',
|
||||
'qualname = test.nova.api.openstack.wsgi'
|
||||
]
|
||||
expect(chef_run).to render_file(@file).with_content(tmp.join('
|
||||
expect(chef_run).to render_file(file.name).with_content(tmp.join('
|
||||
'))
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,13 @@
|
||||
# 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'] = {
|
||||
describe 'openstack-common::default' do
|
||||
describe 'Openstack address_for' do
|
||||
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.set['network'] = {
|
||||
'interfaces' => {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
@ -25,24 +26,25 @@ describe ::Openstack do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
describe '#address_for' do
|
||||
it 'returns ipv4 address' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
resp = @subject.address_for 'lo'
|
||||
include_context 'library-stubs'
|
||||
|
||||
expect(resp).to eq '127.0.0.1'
|
||||
end
|
||||
describe '#address_for' do
|
||||
it 'returns ipv4 address' do
|
||||
expect(
|
||||
subject.address_for('lo')
|
||||
).to eq('127.0.0.1')
|
||||
end
|
||||
|
||||
it 'returns ipv4 address' do
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
resp = @subject.address_for 'lo', 'inet6'
|
||||
|
||||
expect(resp).to eq '::1'
|
||||
it 'returns ipv4 address' do
|
||||
expect(
|
||||
subject.address_for('lo', 'inet6')
|
||||
).to eq('::1')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,20 +1,21 @@
|
||||
# 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 'Openstack parse' do
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
describe '#prettytable_to_array' do
|
||||
it 'returns [] when no table provided' do
|
||||
@subject.prettytable_to_array(nil).should == []
|
||||
expect(
|
||||
subject.prettytable_to_array(nil)
|
||||
).to eq([])
|
||||
end
|
||||
it 'returns [] when table provided is empty' do
|
||||
@subject.prettytable_to_array('').should == []
|
||||
expect(
|
||||
subject.prettytable_to_array('')
|
||||
).to eq([])
|
||||
end
|
||||
it 'returns proper array of hashes when proper table provided' do
|
||||
table =
|
||||
@ -23,10 +24,12 @@ describe ::Openstack do
|
||||
+---------+----------------------------------+----------------------------------+
|
||||
| service | 91af731b3be244beb8f30fc59b7bc96d | ce811442cfb549c39390a203778a4bf5 |
|
||||
+---------+----------------------------------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
expect(
|
||||
subject.prettytable_to_array(table)
|
||||
).to eq(
|
||||
[{ 'tenant' => 'service',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
|
||||
end
|
||||
it 'returns proper array of hashes when proper table provided including whitespace' do
|
||||
table =
|
||||
@ -38,10 +41,12 @@ describe ::Openstack do
|
||||
|
||||
|
||||
'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
expect(
|
||||
subject.prettytable_to_array(table)
|
||||
).to eq(
|
||||
[{ 'tenant' => 'service',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }]
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5' }])
|
||||
end
|
||||
it 'returns a flatten hash when provided a Property/Value table' do
|
||||
table =
|
||||
@ -53,11 +58,13 @@ describe ::Openstack do
|
||||
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
|
||||
| user_id | 1c4fc229560f40689c490c5d0838fd84 |
|
||||
+-----------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
expect(
|
||||
subject.prettytable_to_array(table)
|
||||
).to eq(
|
||||
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5',
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
|
||||
end
|
||||
it 'returns a flatten hash when provided a Property/Value table including whitespace' do
|
||||
table =
|
||||
@ -71,11 +78,13 @@ describe ::Openstack do
|
||||
| tenant_id | 429271dd1cf54b7ca921a0017524d8ea |
|
||||
| user_id | 1c4fc229560f40689c490c5d0838fd84 |
|
||||
+-----------+----------------------------------+'
|
||||
@subject.prettytable_to_array(table).should ==
|
||||
expect(
|
||||
subject.prettytable_to_array(table)
|
||||
).to eq(
|
||||
[{ 'tenant_id' => '429271dd1cf54b7ca921a0017524d8ea',
|
||||
'access' => '91af731b3be244beb8f30fc59b7bc96d',
|
||||
'secret' => 'ce811442cfb549c39390a203778a4bf5',
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }]
|
||||
'user_id' => '1c4fc229560f40689c490c5d0838fd84' }])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,92 +1,80 @@
|
||||
# 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'
|
||||
@subject = ::Object.new.extend(::Openstack)
|
||||
end
|
||||
describe 'openstack-common::default' do
|
||||
describe 'Passwords' do
|
||||
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
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
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.secret('passwords', 'nova')
|
||||
result.should == 'this'
|
||||
end
|
||||
end
|
||||
include_context 'library-stubs'
|
||||
|
||||
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
|
||||
describe '#secret' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
node.set['openstack']['developer_mode'] = true
|
||||
expect(subject.secret('passwords', 'nova')).to eq('nova')
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
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)
|
||||
expect(subject.secret('passwords', 'nova')).to eq('this')
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@chef_run = ::ChefSpec::Runner.new(::CHEFSPEC_OPTS) do |n|
|
||||
n.set['openstack']['developer_mode'] = true
|
||||
describe '#get_password_service_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
node.set['openstack']['developer_mode'] = true
|
||||
expect(subject.get_password('service', 'nova')).to eq('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)
|
||||
expect(
|
||||
subject.get_password('service', 'nova')
|
||||
).to eq('this')
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
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
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
result = @subject.get_password('user', 'nova')
|
||||
result.should == 'this'
|
||||
|
||||
describe '#get_password_db_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
node.set['openstack']['developer_mode'] = true
|
||||
expect(
|
||||
subject.get_password('db', 'nova')
|
||||
).to eq('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)
|
||||
expect(
|
||||
subject.get_password('db', 'nova')
|
||||
).to eq('this')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get_password_user_password' do
|
||||
it 'returns index param when developer_mode is true' do
|
||||
node.set['openstack']['developer_mode'] = true
|
||||
expect(
|
||||
subject.get_password('user', 'nova')
|
||||
).to eq('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)
|
||||
expect(
|
||||
subject.get_password('user', 'nova')
|
||||
).to eq('this')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,142 +1,139 @@
|
||||
# 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
|
||||
}
|
||||
describe 'openstack-common::default' do
|
||||
describe 'Openstack Search' do
|
||||
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.set['openstack']['mq']['server_role'] = 'openstack-ops-mq'
|
||||
node.set['openstack']['mq']['port'] = 5672
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
@chef_run.converge 'openstack-common::default'
|
||||
@subject = ::Object.new.extend ::Openstack
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
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')
|
||||
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')
|
||||
expect(resp[0]['fqdn']).to eq('chefspec.local')
|
||||
end
|
||||
|
||||
expect(resp[0]['fqdn']).to eq 'chefspec.local'
|
||||
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([])
|
||||
expect(
|
||||
subject.search_for('empty-role')
|
||||
).to eq([])
|
||||
end
|
||||
|
||||
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)
|
||||
expect(
|
||||
subject.search_for('empty-role')
|
||||
).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
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' } }
|
||||
]
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
subject.stub(:search_for)
|
||||
.with('role')
|
||||
.and_return(nodes)
|
||||
expect(
|
||||
subject.memcached_servers('role')
|
||||
).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
|
||||
end
|
||||
|
||||
expect(resp).to eq []
|
||||
end
|
||||
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' } }
|
||||
]
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
subject.stub(:search_for)
|
||||
.with('role')
|
||||
.and_return(nodes)
|
||||
expect(
|
||||
subject.memcached_servers('role')
|
||||
).to eq(['1.1.1.1:11211', '2.2.2.2:11211', '3.3.3.3:11211'])
|
||||
end
|
||||
|
||||
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')
|
||||
|
||||
expect(resp).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
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' } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@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']
|
||||
end
|
||||
|
||||
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' } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@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']
|
||||
end
|
||||
|
||||
it 'returns memcached servers as defined by attributes' do
|
||||
nodes = {
|
||||
'openstack' => {
|
||||
'memcached_servers' => ['1.1.1.1:11211', '2.2.2.2:11211']
|
||||
it 'returns memcached servers as defined by attributes' do
|
||||
nodes = {
|
||||
'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')
|
||||
subject.stub(:node).and_return(chef_run.node.merge(nodes))
|
||||
expect(
|
||||
subject.memcached_servers('role')
|
||||
).to eq(['1.1.1.1:11211', '2.2.2.2:11211'])
|
||||
end
|
||||
|
||||
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
|
||||
nodes = {
|
||||
'openstack' => {
|
||||
'memcached_servers' => []
|
||||
it 'returns empty memcached servers as defined by attributes' do
|
||||
nodes = {
|
||||
'openstack' => {
|
||||
'memcached_servers' => []
|
||||
}
|
||||
}
|
||||
}
|
||||
@subject.stub(:node).and_return @chef_run.node.merge nodes
|
||||
resp = @subject.memcached_servers('empty-role')
|
||||
|
||||
expect(resp).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
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' } } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@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'
|
||||
subject.stub(:node).and_return(chef_run.node.merge(nodes))
|
||||
expect(
|
||||
subject.memcached_servers('empty-role')
|
||||
).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
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' } } }
|
||||
]
|
||||
@subject.stub(:node).and_return @chef_run.node
|
||||
@subject.stub(:search_for)
|
||||
.and_return nodes
|
||||
resp = @subject.rabbit_servers
|
||||
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' } } }
|
||||
]
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
subject.stub(:search_for)
|
||||
.and_return(nodes)
|
||||
expect(
|
||||
subject.rabbit_servers).to eq('1.1.1.1:5672,2.2.2.2:5672')
|
||||
end
|
||||
|
||||
expect(resp).to eq '1.1.1.1:5672,2.2.2.2:5672,3.3.3.3:5672'
|
||||
end
|
||||
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' } } }
|
||||
]
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
subject.stub(:search_for)
|
||||
.and_return(nodes)
|
||||
expect(
|
||||
subject.rabbit_servers
|
||||
).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
|
||||
node = @chef_run.node
|
||||
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'
|
||||
it 'returns rabbit servers when not searching' do
|
||||
chef_run.node.set['openstack']['mq']['servers'] = ['1.1.1.1', '2.2.2.2']
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
expect(
|
||||
subject.rabbit_servers
|
||||
).to eq('1.1.1.1:5672,2.2.2.2:5672')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,26 +3,32 @@
|
||||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::UBUNTU_OPTS = {
|
||||
LOG_LEVEL = :fatal
|
||||
UBUNTU_OPTS = {
|
||||
platform: 'ubuntu',
|
||||
version: '12.04',
|
||||
log_level: ::LOG_LEVEL
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
::REDHAT_OPTS = {
|
||||
REDHAT_OPTS = {
|
||||
platform: 'redhat',
|
||||
version: '6.3',
|
||||
log_level: ::LOG_LEVEL
|
||||
version: '6.5',
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
::SUSE_OPTS = {
|
||||
SUSE_OPTS = {
|
||||
platform: 'suse',
|
||||
version: '11.03',
|
||||
log_lovel: ::LOG_LEVEL
|
||||
log_lovel: LOG_LEVEL
|
||||
}
|
||||
::CHEFSPEC_OPTS = {
|
||||
log_level: ::LOG_LEVEL
|
||||
CHEFSPEC_OPTS = {
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
|
||||
shared_context 'library-stubs' do
|
||||
before do
|
||||
subject.stub(:node).and_return(chef_run.node)
|
||||
end
|
||||
end
|
||||
|
||||
# README(galstrom21): This will remove any coverage warnings from
|
||||
# dependent cookbooks
|
||||
ChefSpec::Coverage.filters << '*/openstack-common'
|
||||
|
@ -1,36 +1,29 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
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'
|
||||
end
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
|
||||
describe '60-openstack.conf' do
|
||||
before do
|
||||
@file = @chef_run.template '/etc/sysctl.d/60-openstack.conf'
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/sysctl.d/60-openstack.conf') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@file.owner).to eq('root')
|
||||
expect(@file.group).to eq('root')
|
||||
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'
|
||||
expect(sprintf('%o', file.mode)).to eq '644'
|
||||
end
|
||||
|
||||
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
|
||||
match = 'net.ipv4.conf.default.rp_filter = 0'
|
||||
expect(@chef_run).to render_file(@file.name).with_content(match)
|
||||
{ 'net.ipv4.conf.all.rp_filter' => 0,
|
||||
'net.ipv4.conf.default.rp_filter' => 0 }.each do |k, v|
|
||||
it "sets the #{k}" do
|
||||
expect(chef_run).to render_file(file.name).with_content("#{k} = #{v}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,13 +1,10 @@
|
||||
# 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 'Openstack uri' do
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
describe '#uri_from_hash' do
|
||||
it 'returns nil when no host or uri key found' do
|
||||
@ -15,8 +12,11 @@ describe ::Openstack do
|
||||
'port' => 8888,
|
||||
'path' => '/path'
|
||||
}
|
||||
@subject.uri_from_hash(hash).should be_nil
|
||||
expect(
|
||||
subject.uri_from_hash(hash)
|
||||
).to be_nil
|
||||
end
|
||||
|
||||
it 'returns uri when uri key found, ignoring other parts' do
|
||||
uri = 'http://localhost/'
|
||||
hash = {
|
||||
@ -24,10 +24,11 @@ describe ::Openstack do
|
||||
'path' => '/path',
|
||||
'uri' => uri
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.should be_a URI
|
||||
result.to_s.should == uri
|
||||
result = subject.uri_from_hash(hash)
|
||||
expect(result).to be_a URI
|
||||
expect(result.to_s).to eq(uri)
|
||||
end
|
||||
|
||||
it 'constructs from host' do
|
||||
uri = 'https://localhost:8888/path'
|
||||
hash = {
|
||||
@ -36,52 +37,65 @@ describe ::Openstack do
|
||||
'path' => '/path',
|
||||
'host' => 'localhost'
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
expect(
|
||||
subject.uri_from_hash(hash).to_s
|
||||
).to eq(uri)
|
||||
end
|
||||
|
||||
it 'constructs with defaults' do
|
||||
uri = 'https://localhost'
|
||||
hash = {
|
||||
'scheme' => 'https',
|
||||
'host' => 'localhost'
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
expect(
|
||||
subject.uri_from_hash(hash).to_s
|
||||
).to eq(uri)
|
||||
end
|
||||
|
||||
it 'constructs with extraneous keys' do
|
||||
uri = 'http://localhost'
|
||||
hash = {
|
||||
'host' => 'localhost',
|
||||
'network' => 'public' # To emulate the osops-utils::ip_location way...
|
||||
}
|
||||
result = @subject.uri_from_hash(hash)
|
||||
result.to_s.should == uri
|
||||
expect(
|
||||
subject.uri_from_hash(hash).to_s
|
||||
).to eq(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
|
||||
expect(subject.uri_join_paths).to be_nil
|
||||
end
|
||||
|
||||
it 'preserves absolute path when only absolute path passed in' do
|
||||
path = '/abspath'
|
||||
result = @subject.uri_join_paths(path)
|
||||
result.should == path
|
||||
expect(
|
||||
subject.uri_join_paths(path)
|
||||
).to eq(path)
|
||||
end
|
||||
|
||||
it 'preserves relative path when only relative path passed in' do
|
||||
path = 'abspath/'
|
||||
result = @subject.uri_join_paths(path)
|
||||
result.should == path
|
||||
expect(
|
||||
subject.uri_join_paths(path)
|
||||
).to eq(path)
|
||||
end
|
||||
|
||||
it 'preserves leadng and trailing slashes' do
|
||||
expected = '/path/to/resource/'
|
||||
result = @subject.uri_join_paths('/path', 'to', 'resource/')
|
||||
result.should == expected
|
||||
expect(
|
||||
subject.uri_join_paths('/path', 'to', 'resource/')
|
||||
).to eq(expected)
|
||||
end
|
||||
|
||||
it 'removes extraneous intermediate slashes' do
|
||||
expected = '/path/to/resource'
|
||||
result = @subject.uri_join_paths('/path', '//to/', '/resource')
|
||||
result.should == expected
|
||||
expect(
|
||||
subject.uri_join_paths('/path', '//to/', '/resource')
|
||||
).to eq(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user