Add in rspec-puppet-facts support

This change pulls in rspec-puppet-facts to provide the basic default
facts for puppet-tripleo rspec tests. rspec-puppet-facts provides an
easy to use interface to allow for the same set of tests to be executed
with multiple sets of operating system facts. In most cases this
includes defaults for Debian/RedHat based systems. In puppet-tripleo's
case this is just RHEL/CentOS. We are removing the Fedora listing from
the metadata.json as we only support RHEL and CentOS for tripleo.
This change also updates the existing rspec tests to leverage
rspec-puppet-facts to be more consistent with how facts are defined.

Change-Id: I0ddc71799d74ee95b9828aea6a8dcb4abb4e4e62
This commit is contained in:
Alex Schultz 2016-09-21 13:41:58 -06:00
parent ceccbfdd7b
commit 223c88460b
12 changed files with 138 additions and 186 deletions

View File

@ -3,6 +3,7 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org"
group :development, :test do group :development, :test do
gem 'puppetlabs_spec_helper', :require => 'false' gem 'puppetlabs_spec_helper', :require => 'false'
gem 'rspec-puppet', '~> 2.2.0', :require => 'false' gem 'rspec-puppet', '~> 2.2.0', :require => 'false'
gem 'rspec-puppet-facts', :require => 'false'
gem 'metadata-json-lint', :require => 'false' gem 'metadata-json-lint', :require => 'false'
gem 'puppet-lint-param-docs', :require => 'false' gem 'puppet-lint-param-docs', :require => 'false'
gem 'puppet-lint-absolute_classname-check', :require => 'false' gem 'puppet-lint-absolute_classname-check', :require => 'false'

View File

@ -14,11 +14,11 @@
], ],
"operatingsystem_support": [ "operatingsystem_support": [
{ {
"operatingsystem": "Fedora", "operatingsystem": "RedHat",
"operatingsystemrelease": ["20"] "operatingsystemrelease": ["7"]
}, },
{ {
"operatingsystem": "RedHat", "operatingsystem": "CentOS",
"operatingsystemrelease": ["7"] "operatingsystemrelease": ["7"]
} }
], ],

View File

@ -19,15 +19,7 @@ require 'spec_helper'
describe 'tripleo::cluster::cassandra' do describe 'tripleo::cluster::cassandra' do
shared_examples_for 'cassandra cluster service' do shared_examples_for 'tripleo::cluster::cassandra' do
let :facts do
{
:hostname => 'host1.midonet',
:osfamily => 'RedHat',
:operatingsystemmajrelease => 7,
}
end
let :params do let :params do
{ {
@ -49,6 +41,14 @@ describe 'tripleo::cluster::cassandra' do
end end
end end
it_configures 'cassandra cluster service' on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::cluster::cassandra'
end
end
end end

View File

@ -19,97 +19,68 @@ require 'spec_helper'
describe 'tripleo::cluster::zookeeper' do describe 'tripleo::cluster::zookeeper' do
let :default_params do shared_examples_for 'tripleo::cluster::zookeeper' do
{ let :params do
:zookeeper_server_ips => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:zookeeper_hostnames => ['host1.midonet', 'host2.midonet', 'host3.midonet']
}
end
context 'on host1' do
let :facts do
{ {
:hostname => 'host1.midonet', :zookeeper_server_ips => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:osfamily => 'RedHat', :zookeeper_hostnames => ['host1.midonet', 'host2.midonet', 'host3.midonet']
:operatingsystemmajrelease => 7,
} }
end end
let :params do context 'on host1' do
{ before :each do
:zookeeper_client_ip => '23.43.2.34' facts.merge!({ :hostname => 'host1.midonet'})
} params.merge!({ :zookeeper_client_ip => '23.43.2.34' })
end
it 'should call zookeeper using id==1' do
is_expected.to contain_class('zookeeper').with(
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:client_ip => '23.43.2.34',
:id => 1
)
end
end end
before do context 'on host2' do
params.merge!(default_params) before :each do
facts.merge!({ :hostname => 'host2.midonet'})
params.merge!({ :zookeeper_client_ip => '23.43.2.35' })
end
it 'should call zookeeper using id==1' do
is_expected.to contain_class('zookeeper').with(
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:client_ip => '23.43.2.35',
:id => 2
)
end
end end
it 'should call zookeeper using id==1' do context 'on host3' do
is_expected.to contain_class('zookeeper').with( before :each do
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'], facts.merge!({ :hostname => 'host3.midonet'})
:client_ip => '23.43.2.34', params.merge!({ :zookeeper_client_ip => '23.43.2.36' })
:id => 1 end
)
end
end it 'should call zookeeper using id==1' do
is_expected.to contain_class('zookeeper').with(
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:client_ip => '23.43.2.36',
:id => 3
)
end
context 'on host2' do
let :facts do
{
:hostname => 'host2.midonet',
:osfamily => 'RedHat',
:operatingsystemmajrelease => 7,
}
end
let :params do
{
:zookeeper_client_ip => '23.43.2.35'
}
end
before do
params.merge!(default_params)
end
it 'should call zookeeper using id==1' do
is_expected.to contain_class('zookeeper').with(
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:client_ip => '23.43.2.35',
:id => 2
)
end end
end end
context 'on host3' do on_supported_os.each do |os, facts|
let :facts do context "on #{os}" do
{ let(:facts) do
:hostname => 'host3.midonet', facts.merge({})
:osfamily => 'RedHat', end
:operatingsystemmajrelease => 7,
}
end
let :params do it_behaves_like 'tripleo::cluster::zookeeper'
{
:zookeeper_client_ip => '23.43.2.36'
}
end end
before do
params.merge!(default_params)
end
it 'should call zookeeper using id==1' do
is_expected.to contain_class('zookeeper').with(
:servers => ['23.43.2.34', '23.43.2.35', '24.43.2.36'],
:client_ip => '23.43.2.36',
:id => 3
)
end
end end
end end

View File

@ -24,7 +24,7 @@ describe 'tripleo::firewall' do
{ } { }
end end
shared_examples_for 'tripleo node' do shared_examples_for 'tripleo::firewall' do
context 'with firewall enabled' do context 'with firewall enabled' do
before :each do before :each do
@ -114,23 +114,13 @@ describe 'tripleo::firewall' do
end end
context 'on Debian platforms' do on_supported_os.each do |os, facts|
let :facts do context "on #{os}" do
{ :osfamily => 'Debian' } let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::firewall'
end end
it_configures 'tripleo node'
end end
context 'on RedHat platforms' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
}
end
it_configures 'tripleo node'
end
end end

View File

@ -2,15 +2,7 @@ require 'spec_helper'
describe 'tripleo::host::sriov' do describe 'tripleo::host::sriov' do
shared_examples_for 'sriov vfs configuration for Red Hat distributions' do shared_examples_for 'tripleo::host::sriov' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemmajrelease => 7,
}
end
let :params do let :params do
{:number_of_vfs => []} {:number_of_vfs => []}
end end
@ -35,5 +27,13 @@ describe 'tripleo::host::sriov' do
end end
end end
it_configures 'sriov vfs configuration for Red Hat distributions' on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::host::sriov'
end
end
end end

View File

@ -19,17 +19,7 @@ require 'spec_helper'
describe 'tripleo::network::midonet::agent' do describe 'tripleo::network::midonet::agent' do
let :facts do shared_examples_for 'tripleo::network::midonet::agent' do
{
:hostname => 'host2.midonet',
:osfamily => 'RedHat',
:operatingsystem => 'CentOS',
:operatingsystemrelease => '7.1',
:operatingsystemmajrelease => 7,
}
end
shared_examples_for 'midonet agent test' do
let :params do let :params do
{ {
@ -56,7 +46,13 @@ describe 'tripleo::network::midonet::agent' do
end end
end end
it_configures 'midonet agent test' on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::network::midonet::agent'
end
end
end end

View File

@ -19,13 +19,7 @@ require 'spec_helper'
describe 'tripleo::network::midonet::api' do describe 'tripleo::network::midonet::api' do
let :facts do shared_examples_for 'tripleo::midonet::api' do
{
:augeasversion => '1.0.0'
}
end
shared_examples_for 'midonet api test' do
let :params do let :params do
{ {
@ -67,6 +61,16 @@ describe 'tripleo::network::midonet::api' do
end end
it_configures 'midonet api test' on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({
:augeasversion => '1.0.0'
})
end
it_behaves_like 'tripleo::midonet::api'
end
end
end end

View File

@ -17,19 +17,12 @@ require 'spec_helper'
describe 'tripleo::packages' do describe 'tripleo::packages' do
shared_examples_for 'Red Hat distributions' do shared_examples_for 'tripleo::packages' do
let :pre_condition do let :pre_condition do
"service{'nova-compute': ensure => 'running'}" "service{'nova-compute': ensure => 'running'}"
end end
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemmajrelease => 7,
}
end
let :params do let :params do
{ {
:enable_upgrade => true :enable_upgrade => true
@ -43,6 +36,15 @@ describe 'tripleo::packages' do
end end
it_configures 'Red Hat distributions'
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::packages'
end
end
end end

View File

@ -21,7 +21,7 @@ describe 'tripleo::profile::base::swift::proxy' do
{ } { }
end end
shared_examples_for 'tripleo swift proxy base profile' do shared_examples_for 'tripleo::profile::base::swift::proxy' do
let :pre_condition do let :pre_condition do
"class { '::swift': "class { '::swift':
@ -65,25 +65,13 @@ describe 'tripleo::profile::base::swift::proxy' do
end end
context 'on Debian platforms' do on_supported_os.each do |os, facts|
let :facts do context "on #{os}" do
{ :osfamily => 'Debian', let(:facts) do
:processorcount => 1 } facts.merge({})
end
it_behaves_like 'tripleo::profile::base::swift::proxy'
end end
it_configures 'tripleo swift proxy base profile'
end end
context 'on RedHat platforms' do
let :facts do
{
:osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
:processorcount => 1,
}
end
it_configures 'tripleo swift proxy base profile'
end
end end

View File

@ -19,11 +19,14 @@ require 'spec_helper'
describe 'tripleo::selinux' do describe 'tripleo::selinux' do
shared_examples_for 'manage selinux' do shared_examples_for 'tripleo::selinux' do
context 'with selinux enforcing' do context 'with selinux enforcing' do
before :each do before :each do
facts.merge!( :selinux_current_mode => 'enforcing' ) facts.merge!({
:selinux => true,
:selinux_current_mode => 'enforcing'
})
end end
let :params do let :params do
@ -55,7 +58,7 @@ describe 'tripleo::selinux' do
context 'with selinux disabled' do context 'with selinux disabled' do
before :each do before :each do
facts.merge!( :selinux => 'false' ) facts.merge!({ :selinux => 'false' })
end end
let :params do let :params do
@ -89,18 +92,19 @@ describe 'tripleo::selinux' do
context 'on Debian platforms' do context 'on Debian platforms' do
let :facts do let :facts do
{ :osfamily => 'Debian' } { :osfamily => 'Debian' }
end end
it_raises 'a Puppet::Error', /OS family unsuppored yet \(Debian\), SELinux support is only limited to RedHat family OS/ it_raises 'a Puppet::Error', /OS family unsuppored yet \(Debian\), SELinux support is only limited to RedHat family OS/
end end
context 'on RedHat platforms' do on_supported_os.each do |os, facts|
let :facts do context "on #{os}" do
{ :osfamily => 'RedHat' } let(:facts) do
facts.merge({})
end
it_behaves_like 'tripleo::selinux'
end end
it_configures 'manage selinux'
end end
end end

View File

@ -1,5 +1,7 @@
require 'puppetlabs_spec_helper/module_spec_helper' require 'puppetlabs_spec_helper/module_spec_helper'
require 'shared_examples' require 'shared_examples'
require 'rspec-puppet-facts'
include RspecPuppetFacts
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
@ -10,14 +12,8 @@ RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules') c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests') c.manifest_dir = File.join(fixture_path, 'manifests')
c.default_facts = { # custom global facts for all rspec tests
:kernel => 'Linux', add_custom_fact :concat_basedir, '/var/lib/puppet/concat'
:concat_basedir => '/var/lib/puppet/concat',
:memorysize => '1000 MB',
:processorcount => '1',
:puppetversion => '3.7.3',
:uniqueid => '123'
}
end end
at_exit { RSpec::Puppet::Coverage.report! } at_exit { RSpec::Puppet::Coverage.report! }