From c4f24cb85c1862aa17da994484b2e34bef6be27d Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Tue, 27 Sep 2016 14:48:17 -0600 Subject: [PATCH] Finish rspec-puppet-facts update Since this module was last updated to use rspec-puppet-facts, a few additional tests were missed. This change updates the last two tests to use rspec-puppet-facts. Change-Id: Idd5f80e797574d0e5661e22ec4d631beba0e358e --- spec/classes/aodh_db_mysql_spec.rb | 81 ++++++----- spec/classes/aodh_keystone_auth_spec.rb | 182 +++++++++++++----------- spec/spec_helper.rb | 5 - 3 files changed, 140 insertions(+), 128 deletions(-) diff --git a/spec/classes/aodh_db_mysql_spec.rb b/spec/classes/aodh_db_mysql_spec.rb index c5c5875e..cda48df2 100644 --- a/spec/classes/aodh_db_mysql_spec.rb +++ b/spec/classes/aodh_db_mysql_spec.rb @@ -9,54 +9,63 @@ describe 'aodh::db::mysql' do ] end - let :facts do - { :osfamily => 'Debian' } - end - let :params do { 'password' => 'fooboozoo_default_password', } end - describe 'with only required params' do - it { is_expected.to contain_openstacklib__db__mysql('aodh').with( - 'user' => 'aodh', - 'password_hash' => '*3DDF34A86854A312A8E2C65B506E21C91800D206', - 'dbname' => 'aodh', - 'host' => '127.0.0.1', - 'charset' => 'utf8', - :collate => 'utf8_general_ci', - )} - end - - describe "overriding allowed_hosts param to array" do - let :params do - { - :password => 'aodhpass', - :allowed_hosts => ['127.0.0.1','%'] - } + shared_examples_for 'aodh::db::mysql' do + context 'with only required params' do + it { is_expected.to contain_openstacklib__db__mysql('aodh').with( + 'user' => 'aodh', + 'password_hash' => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + 'dbname' => 'aodh', + 'host' => '127.0.0.1', + 'charset' => 'utf8', + :collate => 'utf8_general_ci', + )} end - end - describe "overriding allowed_hosts param to string" do - let :params do - { - :password => 'aodhpass2', - :allowed_hosts => '192.168.1.1' - } + context "overriding allowed_hosts param to array" do + let :params do + { + :password => 'aodhpass', + :allowed_hosts => ['127.0.0.1','%'] + } + end + + end + context "overriding allowed_hosts param to string" do + let :params do + { + :password => 'aodhpass2', + :allowed_hosts => '192.168.1.1' + } + end + end - end + context "overriding allowed_hosts param equals to host param " do + let :params do + { + :password => 'aodhpass2', + :allowed_hosts => '127.0.0.1' + } + end - describe "overriding allowed_hosts param equals to host param " do - let :params do - { - :password => 'aodhpass2', - :allowed_hosts => '127.0.0.1' - } end - end + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'aodh::db::mysql' + end + end end diff --git a/spec/classes/aodh_keystone_auth_spec.rb b/spec/classes/aodh_keystone_auth_spec.rb index 381db917..5cb1b9cb 100644 --- a/spec/classes/aodh_keystone_auth_spec.rb +++ b/spec/classes/aodh_keystone_auth_spec.rb @@ -5,116 +5,124 @@ require 'spec_helper' describe 'aodh::keystone::auth' do + shared_examples_for 'aodh::keystone::auth' do + context 'with default class parameters' do + let :params do + { :password => 'aodh_password', + :tenant => 'foobar' } + end - let :facts do - { :osfamily => 'Debian' } - end + it { is_expected.to contain_keystone_user('aodh').with( + :ensure => 'present', + :password => 'aodh_password', + ) } - describe 'with default class parameters' do - let :params do - { :password => 'aodh_password', - :tenant => 'foobar' } + it { is_expected.to contain_keystone_user_role('aodh@foobar').with( + :ensure => 'present', + :roles => ['admin'] + )} + + it { is_expected.to contain_keystone_service('aodh::alarming').with( + :ensure => 'present', + :description => 'OpenStack Alarming Service' + ) } + + it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming').with( + :ensure => 'present', + :public_url => 'http://127.0.0.1:8042', + :admin_url => 'http://127.0.0.1:8042', + :internal_url => 'http://127.0.0.1:8042', + ) } end - it { is_expected.to contain_keystone_user('aodh').with( - :ensure => 'present', - :password => 'aodh_password', - ) } + context 'when overriding URL parameters' do + let :params do + { :password => 'aodh_password', + :public_url => 'https://10.10.10.10:80', + :internal_url => 'http://10.10.10.11:81', + :admin_url => 'http://10.10.10.12:81' } + end - it { is_expected.to contain_keystone_user_role('aodh@foobar').with( - :ensure => 'present', - :roles => ['admin'] - )} - - it { is_expected.to contain_keystone_service('aodh::alarming').with( - :ensure => 'present', - :description => 'OpenStack Alarming Service' - ) } - - it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming').with( - :ensure => 'present', - :public_url => 'http://127.0.0.1:8042', - :admin_url => 'http://127.0.0.1:8042', - :internal_url => 'http://127.0.0.1:8042', - ) } - end - - describe 'when overriding URL parameters' do - let :params do - { :password => 'aodh_password', + it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming').with( + :ensure => 'present', :public_url => 'https://10.10.10.10:80', :internal_url => 'http://10.10.10.11:81', - :admin_url => 'http://10.10.10.12:81' } + :admin_url => 'http://10.10.10.12:81' + ) } end - it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming').with( - :ensure => 'present', - :public_url => 'https://10.10.10.10:80', - :internal_url => 'http://10.10.10.11:81', - :admin_url => 'http://10.10.10.12:81' - ) } - end + context 'when overriding auth name' do + let :params do + { :password => 'foo', + :auth_name => 'aodhany' } + end - describe 'when overriding auth name' do - let :params do - { :password => 'foo', - :auth_name => 'aodhany' } + it { is_expected.to contain_keystone_user('aodhany') } + it { is_expected.to contain_keystone_user_role('aodhany@services') } + it { is_expected.to contain_keystone_service('aodh::alarming') } + it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming') } end - it { is_expected.to contain_keystone_user('aodhany') } - it { is_expected.to contain_keystone_user_role('aodhany@services') } - it { is_expected.to contain_keystone_service('aodh::alarming') } - it { is_expected.to contain_keystone_endpoint('RegionOne/aodh::alarming') } - end + context 'when overriding service name' do + let :params do + { :service_name => 'aodh_service', + :auth_name => 'aodh', + :password => 'aodh_password' } + end - describe 'when overriding service name' do - let :params do - { :service_name => 'aodh_service', - :auth_name => 'aodh', - :password => 'aodh_password' } + it { is_expected.to contain_keystone_user('aodh') } + it { is_expected.to contain_keystone_user_role('aodh@services') } + it { is_expected.to contain_keystone_service('aodh_service::alarming') } + it { is_expected.to contain_keystone_endpoint('RegionOne/aodh_service::alarming') } end - it { is_expected.to contain_keystone_user('aodh') } - it { is_expected.to contain_keystone_user_role('aodh@services') } - it { is_expected.to contain_keystone_service('aodh_service::alarming') } - it { is_expected.to contain_keystone_endpoint('RegionOne/aodh_service::alarming') } - end + context 'when disabling user configuration' do - describe 'when disabling user configuration' do + let :params do + { + :password => 'aodh_password', + :configure_user => false + } + end + + it { is_expected.not_to contain_keystone_user('aodh') } + it { is_expected.to contain_keystone_user_role('aodh@services') } + it { is_expected.to contain_keystone_service('aodh::alarming').with( + :ensure => 'present', + :description => 'OpenStack Alarming Service' + ) } - let :params do - { - :password => 'aodh_password', - :configure_user => false - } end - it { is_expected.not_to contain_keystone_user('aodh') } - it { is_expected.to contain_keystone_user_role('aodh@services') } - it { is_expected.to contain_keystone_service('aodh::alarming').with( - :ensure => 'present', - :description => 'OpenStack Alarming Service' - ) } + context 'when disabling user and user role configuration' do - end + let :params do + { + :password => 'aodh_password', + :configure_user => false, + :configure_user_role => false + } + end - describe 'when disabling user and user role configuration' do + it { is_expected.not_to contain_keystone_user('aodh') } + it { is_expected.not_to contain_keystone_user_role('aodh@services') } + it { is_expected.to contain_keystone_service('aodh::alarming').with( + :ensure => 'present', + :description => 'OpenStack Alarming Service' + ) } - let :params do - { - :password => 'aodh_password', - :configure_user => false, - :configure_user_role => false - } end - - it { is_expected.not_to contain_keystone_user('aodh') } - it { is_expected.not_to contain_keystone_user_role('aodh@services') } - it { is_expected.to contain_keystone_service('aodh::alarming').with( - :ensure => 'present', - :description => 'OpenStack Alarming Service' - ) } - end + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'aodh::keystone::auth' + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3bab73f..424ad754 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,11 +8,6 @@ include RspecPuppetFacts RSpec.configure do |c| c.alias_it_should_behave_like_to :it_configures, 'configures' c.alias_it_should_behave_like_to :it_raises, 'raises' - # TODO(aschultz): remove this after all tests converted to use OSDefaults - # instead of referencing @default_facts - c.before :each do - @default_facts = OSDefaults.get_facts - end end at_exit { RSpec::Puppet::Coverage.report! }