diff options
Diffstat (limited to 'spec')
15 files changed, 597 insertions, 44 deletions
diff --git a/spec/classes/tripleo_certmonger_ca_crl_spec.rb b/spec/classes/tripleo_certmonger_ca_crl_spec.rb new file mode 100644 index 0000000..1e605ce --- /dev/null +++ b/spec/classes/tripleo_certmonger_ca_crl_spec.rb @@ -0,0 +1,104 @@ +# +# Copyright (C) 2017 Red Hat Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for tripleo +# + +require 'spec_helper' + +describe 'tripleo::certmonger::ca::crl' do + + shared_examples_for 'tripleo::certmonger::ca::crl' do + + context 'with default parameters (no crl_source)' do + it 'should ensure no CRL nor cron job are present' do + is_expected.to contain_file('tripleo-ca-crl').with( + :ensure => 'absent' + ) + is_expected.to contain_cron('tripleo-refresh-crl-file').with( + :ensure => 'absent' + ) + end + end + + context 'with defined CRL source' do + let :params do + { + :crl_dest => '/etc/pki/CA/crl/overcloud-crl.pem', + :crl_preprocessed => '/etc/pki/CA/crl/overcloud-crl.bin', + :crl_source => 'file://tmp/some/crl.bin', + } + end + + let :process_cmd do + "openssl crl -in #{params[:crl_preprocessed]} -inform DER -outform PEM -out #{params[:crl_dest]}" + end + + let :cron_cmd do + "curl -L -o #{params[:crl_preprocessed]} #{params[:crl_source]} && #{process_cmd}" + end + + it 'should create and process CRL file' do + is_expected.to contain_file('tripleo-ca-crl').with( + :ensure => 'present', + :source => params[:crl_source] + ) + is_expected.to contain_exec('tripleo-ca-crl-process-command').with( + :command => process_cmd + ) + is_expected.to contain_cron('tripleo-refresh-crl-file').with( + :ensure => 'present', + :command => cron_cmd + ) + end + end + + context 'with defined CRL source and no processing' do + let :params do + { + :crl_dest => '/etc/pki/CA/crl/overcloud-crl.pem', + :crl_source => 'file://tmp/some/crl.pem', + :process => false + } + end + + let :cron_cmd do + "curl -L -o #{params[:crl_dest]} #{params[:crl_source]}" + end + + it 'should create and process CRL file' do + is_expected.to contain_file('tripleo-ca-crl').with( + :ensure => 'present', + :source => params[:crl_source] + ) + is_expected.to_not contain_exec('tripleo-ca-crl-process-command') + is_expected.to contain_cron('tripleo-refresh-crl-file').with( + :ensure => 'present', + :command => cron_cmd + ) + end + end + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + end + + it_behaves_like 'tripleo::certmonger::ca::crl' + end + end +end diff --git a/spec/classes/tripleo_certmonger_ca_local.rb b/spec/classes/tripleo_certmonger_ca_local_spec.rb index 7ee9383..7ee9383 100644 --- a/spec/classes/tripleo_certmonger_ca_local.rb +++ b/spec/classes/tripleo_certmonger_ca_local_spec.rb diff --git a/spec/classes/tripleo_certmonger_etcd.rb b/spec/classes/tripleo_certmonger_etcd_spec.rb index fc0aad3..fc0aad3 100644 --- a/spec/classes/tripleo_certmonger_etcd.rb +++ b/spec/classes/tripleo_certmonger_etcd_spec.rb diff --git a/spec/classes/tripleo_certmonger_mysql.rb b/spec/classes/tripleo_certmonger_mysql_spec.rb index 23b1e4f..23b1e4f 100644 --- a/spec/classes/tripleo_certmonger_mysql.rb +++ b/spec/classes/tripleo_certmonger_mysql_spec.rb diff --git a/spec/classes/tripleo_certmonger_rabbitmq.rb b/spec/classes/tripleo_certmonger_rabbitmq_spec.rb index 5c011ce..5c011ce 100644 --- a/spec/classes/tripleo_certmonger_rabbitmq.rb +++ b/spec/classes/tripleo_certmonger_rabbitmq_spec.rb diff --git a/spec/classes/tripleo_haproxy_spec.rb b/spec/classes/tripleo_haproxy_spec.rb new file mode 100644 index 0000000..966729a --- /dev/null +++ b/spec/classes/tripleo_haproxy_spec.rb @@ -0,0 +1,115 @@ +# Copyright 2016 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +require 'spec_helper' + +describe 'tripleo::haproxy' do + + shared_examples_for 'tripleo::haproxy' do + let :params do { + :controller_virtual_ip => '10.1.0.1', + :public_virtual_ip => '192.168.0.1' + } + end + + describe "default settings" do + it 'should configure haproxy' do + is_expected.to contain_haproxy__listen('mysql').with( + :options => { + 'timeout client' => "90m", + 'timeout server' => "90m", + 'maxconn' => :undef + } + ) + end + end + + describe "set clustercheck" do + before :each do + params.merge!({ + :mysql_clustercheck => true, + }) + end + + it 'should configure haproxy with clustercheck' do + is_expected.to contain_haproxy__listen('mysql').with( + :options => { + 'timeout client' => "90m", + 'timeout server' => "90m", + 'option' => ["tcpka", "httpchk"], + 'timeout client' => "90m", + 'timeout server' => "90m", + 'stick-table' => "type ip size 1000", + 'stick' => "on dst", + 'maxconn' => :undef + } + ) + end + end + + describe "override maxconn with clustercheck" do + before :each do + params.merge!({ + :mysql_clustercheck => true, + :mysql_max_conn => 6500, + }) + end + + it 'should configure haproxy' do + is_expected.to contain_haproxy__listen('mysql').with( + :options => { + 'option' => ["tcpka", "httpchk"], + 'timeout client' => "90m", + 'timeout server' => "90m", + 'stick-table' => "type ip size 1000", + 'stick' => "on dst", + 'maxconn' => 6500 + } + ) + end + end + + describe "override maxconn without clustercheck" do + before :each do + params.merge!({ + :mysql_max_conn => 6500, + }) + end + + it 'should configure haproxy' do + is_expected.to contain_haproxy__listen('mysql').with( + :options => { + 'timeout client' => "90m", + 'timeout server' => "90m", + 'maxconn' => 6500 + } + ) + end + end + + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ }) + end + + it_behaves_like 'tripleo::haproxy' + end + end + +end
\ No newline at end of file diff --git a/spec/classes/tripleo_profile_base_ceilometer_spec.rb b/spec/classes/tripleo_profile_base_ceilometer_spec.rb index 8c1d507..bc4ffac 100644 --- a/spec/classes/tripleo_profile_base_ceilometer_spec.rb +++ b/spec/classes/tripleo_profile_base_ceilometer_spec.rb @@ -43,30 +43,6 @@ describe 'tripleo::profile::base::ceilometer' do end end - context 'with step 5 with bootstrap node' do - let(:params) { { - :bootstrap_node => 'node.example.com', - :step => 5, - :oslomsg_rpc_hosts => [ '127.0.0.1' ], - :oslomsg_rpc_username => 'ceilometer', - :oslomsg_rpc_password => 'foo', - } } - - it 'should trigger complete configuration' do - is_expected.to contain_exec('ceilometer-db-upgrade') - end - end - - context 'with step 5 without bootstrap node' do - let(:params) { { - :bootstrap_node => 'somethingelse.example.com', - :step => 5, - } } - - it 'should trigger complete configuration' do - is_expected.to_not contain_exec('ceilometer-db-upgrade') - end - end end diff --git a/spec/classes/tripleo_profile_base_database_redis_spec.rb b/spec/classes/tripleo_profile_base_database_redis_spec.rb new file mode 100644 index 0000000..8f94cc9 --- /dev/null +++ b/spec/classes/tripleo_profile_base_database_redis_spec.rb @@ -0,0 +1,106 @@ +# +# Copyright (C) 2017 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +require 'spec_helper' + +describe 'tripleo::profile::base::database::redis' do + shared_examples_for 'tripleo::profile::base::database::redis' do + + context 'with step less than 2' do + let(:params) { { + :step => 1, + :bootstrap_nodeid => 'node.example.com', + :redis_node_ips => [] + } } + + it 'should do nothing' do + is_expected.to contain_class('tripleo::profile::base::database::redis') + is_expected.to_not contain_class('redis') + is_expected.to_not contain_class('redis::sentinel') + is_expected.to_not contain_class('tripleo::redis_notification') + end + end + + context 'with step 2 on bootstrap node' do + let(:params) { { + :step => 2, + :bootstrap_nodeid => 'node.example.com', + :redis_node_ips => ['10.0.0.1'] + } } + + it 'should configure redis' do + is_expected.to contain_class('tripleo::profile::base::database::redis') + is_expected.to contain_class('redis') + is_expected.to_not contain_class('redis::sentinel') + is_expected.to_not contain_class('tripleo::redis_notification') + end + end + + context 'with step 2 on bootstrap node with capital letters' do + let(:params) { { + :step => 2, + :bootstrap_nodeid => 'NODE.example.com', + :redis_node_ips => ['10.0.0.1'] + } } + + it 'should configure redis' do + is_expected.to contain_class('tripleo::profile::base::database::redis') + is_expected.to contain_class('redis').with(:slaveof => nil) + end + end + + context 'with step 2 not on bootstrap node' do + let(:params) { { + :step => 2, + :bootstrap_nodeid => 'othernode.example.com', + :redis_node_ips => ['10.0.0.1'] + } } + + it 'should configure redis' do + is_expected.to contain_class('tripleo::profile::base::database::redis') + is_expected.to contain_class('redis').with(:slaveof => "#{params[:bootstrap_nodeid]} 6379") + is_expected.to_not contain_class('redis::sentinel') + is_expected.to_not contain_class('tripleo::redis_notification') + end + end + + context 'with step 2 with multiple nodes' do + let(:params) { { + :step => 2, + :bootstrap_nodeid => 'othernode.example.com', + :redis_node_ips => ['10.0.0.1', '10.0.0.2'] + } } + + it 'should configure redis' do + is_expected.to contain_class('tripleo::profile::base::database::redis') + is_expected.to contain_class('redis').with(:slaveof => "#{params[:bootstrap_nodeid]} 6379") + is_expected.to contain_class('redis::sentinel') + is_expected.to contain_class('tripleo::redis_notification') + end + end + + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ :hostname => 'node.example.com' }) + end + + it_behaves_like 'tripleo::profile::base::database::redis' + end + end +end diff --git a/spec/classes/tripleo_profile_base_docker_spec.rb b/spec/classes/tripleo_profile_base_docker_spec.rb index 0b988f6..bb21055 100644 --- a/spec/classes/tripleo_profile_base_docker_spec.rb +++ b/spec/classes/tripleo_profile_base_docker_spec.rb @@ -124,6 +124,85 @@ describe 'tripleo::profile::base::docker' do } end + context 'with step 4 and configure_libvirt_polkit disabled' do + let(:params) { { + :step => 4, + :configure_libvirt_polkit => false + } } + it { + is_expected.to_not contain_group('docker_nova_group') + is_expected.to_not contain_user('docker_nova_user') + is_expected.to_not contain_package('polkit') + is_expected.to_not contain_file('/etc/polkit-1/rules.d/50-nova.rules') + } + end + + context 'with step 4 and configure_libvirt_polkit enabled' do + let(:params) { { + :step => 4, + :configure_libvirt_polkit => true + } } + it { + is_expected.to contain_group('docker_nova_group').with( + :name => 'docker_nova', + :gid => 42436 + ) + is_expected.to contain_user('docker_nova_user').with( + :name => 'docker_nova', + :uid => 42436, + :gid => 42436, + :shell => '/sbin/nologin', + :groups => ['nobody'] + ) + is_expected.to contain_package('polkit') + is_expected.to contain_file('/etc/polkit-1/rules.d/50-nova.rules') + } + end + + context 'with step 4 and nova_compute service installed' do + let(:params) { { + :step => 4, + :services_enabled => ['docker', 'nova_compute'] + } } + it { + is_expected.to contain_group('docker_nova_group').with( + :name => 'docker_nova', + :gid => 42436 + ) + is_expected.to contain_user('docker_nova_user').with( + :name => 'docker_nova', + :uid => 42436, + :gid => 42436, + :shell => '/sbin/nologin', + :groups => ['nobody'] + ) + is_expected.to contain_package('polkit') + is_expected.to contain_file('/etc/polkit-1/rules.d/50-nova.rules') + } + end + + context 'with step 4 and configure_libvirt_polkit enabled and docker_nova uid' do + let(:params) { { + :step => 4, + :configure_libvirt_polkit => true, + :docker_nova_uid => 12345 + } } + it { + is_expected.to contain_group('docker_nova_group').with( + :name => 'docker_nova', + :gid => 12345 + ) + is_expected.to contain_user('docker_nova_user').with( + :name => 'docker_nova', + :uid => 12345, + :gid => 12345, + :shell => '/sbin/nologin', + :groups => ['nobody'] + ) + is_expected.to contain_package('polkit') + is_expected.to contain_file('/etc/polkit-1/rules.d/50-nova.rules') + } + end end on_supported_os.each do |os, facts| diff --git a/spec/classes/tripleo_profile_base_gnocchi_api_spec.rb b/spec/classes/tripleo_profile_base_gnocchi_api_spec.rb index 6c04e9d..90bdea0 100644 --- a/spec/classes/tripleo_profile_base_gnocchi_api_spec.rb +++ b/spec/classes/tripleo_profile_base_gnocchi_api_spec.rb @@ -36,9 +36,9 @@ describe 'tripleo::profile::base::gnocchi::api' do } end - context 'with step 3 on bootstrap' do + context 'with step 4 on bootstrap' do let(:params) { { - :step => 3, + :step => 4, :bootstrap_node => 'node.example.com', :gnocchi_redis_password => 'gnocchi', :redis_vip => '127.0.0.1' @@ -51,20 +51,6 @@ describe 'tripleo::profile::base::gnocchi::api' do } end - context 'with step 3' do - let(:params) { { - :step => 3, - :gnocchi_redis_password => 'gnocchi', - :redis_vip => '127.0.0.1' - } } - - it { - is_expected.to_not contain_class('gnocchi::db::sync') - is_expected.to contain_class('gnocchi::api') - is_expected.to contain_class('gnocchi::wsgi::apache') - } - end - context 'with step 4' do let(:params) { { :step => 4, @@ -129,10 +115,6 @@ describe 'tripleo::profile::base::gnocchi::api' do it { is_expected.to contain_class('gnocchi::api') is_expected.to contain_class('gnocchi::wsgi::apache') - is_expected.to contain_exec('run gnocchi upgrade with storage').with( - :command => 'gnocchi-upgrade --config-file=/etc/gnocchi/gnocchi.conf', - :path => ['/usr/bin', '/usr/sbin'] - ) } end end diff --git a/spec/classes/tripleo_profile_base_kernel_spec.rb b/spec/classes/tripleo_profile_base_kernel_spec.rb new file mode 100644 index 0000000..4c2aab2 --- /dev/null +++ b/spec/classes/tripleo_profile_base_kernel_spec.rb @@ -0,0 +1,59 @@ +# +# Copyright (C) 2017 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +require 'spec_helper' + +describe 'tripleo::profile::base::kernel' do + + shared_examples_for 'tripleo::profile::base::kernel' do + context 'with kernel modules' do + let :params do + { + :module_list => { + 'nf_conntrack' => {}, + } + } + end + + it 'should load kernel module' do + is_expected.to contain_kmod__load('nf_conntrack') + end + end + context 'with sysctl settings' do + let :params do + { + :sysctl_settings => { + 'net.ipv4.tcp_keepalive_intvl' => { 'value' => '1'}, + } + } + end + + it 'should load kernel module' do + is_expected.to contain_sysctl__value('net.ipv4.tcp_keepalive_intvl') + end + end + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) { + facts + } + + it_behaves_like 'tripleo::profile::base::kernel' + end + end +end diff --git a/spec/classes/tripleo_profile_base_novajoin_spec.rb b/spec/classes/tripleo_profile_base_novajoin_spec.rb new file mode 100644 index 0000000..e157d4f --- /dev/null +++ b/spec/classes/tripleo_profile_base_novajoin_spec.rb @@ -0,0 +1,126 @@ +# +# Copyright (C) 2017 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +require 'spec_helper' + +describe 'tripleo::profile::base::novajoin' do + + let :pre_condition do + "include nova + class { '::nova::metadata::novajoin::authtoken': + password => 'passw0rd', + }" + end + + let :params do + { :oslomsg_rpc_hosts => ['some.server.com'], + :oslomsg_rpc_password => 'somepassword', + :service_password => 'passw0rd', + :step => 5 + } + end + + shared_examples_for 'tripleo::profile::base::novajoin' do + + context 'with step less than 3' do + before do + params.merge!({ :step => 2 }) + end + + it 'should not do anything' do + is_expected.to_not contain_class('nova::metadata::novajoin::api') + end + end + + context 'with step 3' do + before do + params.merge!({ :step => 3 }) + end + + it 'should provide basic initialization' do + is_expected.to contain_class('nova::metadata::novajoin::api').with( + :transport_url => 'rabbit://guest:somepassword@some.server.com:5672/?ssl=0' + ) + end + end + + context 'with multiple hosts' do + before do + params.merge!({ :oslomsg_rpc_hosts => ['some.server.com', 'someother.server.com'] }) + end + + it 'should construct a multihost URL' do + is_expected.to contain_class('nova::metadata::novajoin::api').with( + :transport_url => 'rabbit://guest:somepassword@some.server.com:5672,guest:somepassword@someother.server.com:5672/?ssl=0' + ) + end + end + + context 'with username provided' do + before do + params.merge!({ :oslomsg_rpc_username => 'bunny' }) + end + + it 'should construct URL with username' do + is_expected.to contain_class('nova::metadata::novajoin::api').with( + :transport_url => 'rabbit://bunny:somepassword@some.server.com:5672/?ssl=0' + ) + end + end + + context 'with username and password provided' do + before do + params.merge!( + { :oslomsg_rpc_username => 'bunny', + :oslomsg_rpc_password => 'carrot' + } + ) + end + + it 'should construct URL with username and password' do + is_expected.to contain_class('nova::metadata::novajoin::api').with( + :transport_url => 'rabbit://bunny:carrot@some.server.com:5672/?ssl=0' + ) + end + end + + context 'with multiple hosts and user info provided' do + before do + params.merge!( + { :oslomsg_rpc_hosts => ['some.server.com', 'someother.server.com'], + :oslomsg_rpc_username => 'bunny', + :oslomsg_rpc_password => 'carrot' + } + ) + end + + it 'should distributed user info across hosts URL' do + is_expected.to contain_class('nova::metadata::novajoin::api').with( + :transport_url => 'rabbit://bunny:carrot@some.server.com:5672,bunny:carrot@someother.server.com:5672/?ssl=0' + ) + end + end + end + + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + end + it_behaves_like 'tripleo::profile::base::novajoin' + end + end +end diff --git a/spec/classes/tripleo_profile_base_swift_ringbuilder.rb b/spec/classes/tripleo_profile_base_swift_ringbuilder_spec.rb index 0139815..0139815 100644 --- a/spec/classes/tripleo_profile_base_swift_ringbuilder.rb +++ b/spec/classes/tripleo_profile_base_swift_ringbuilder_spec.rb diff --git a/spec/classes/tripleo_certmonger_httpd.rb b/spec/defines/tripleo_certmonger_httpd_spec.rb index da5ce94..f01e594 100644 --- a/spec/classes/tripleo_certmonger_httpd.rb +++ b/spec/defines/tripleo_certmonger_httpd_spec.rb @@ -20,6 +20,8 @@ require 'spec_helper' describe 'tripleo::certmonger::httpd' do + let(:title) { 'httpd-cert' } + shared_examples_for 'tripleo::certmonger::httpd' do let :params do { diff --git a/spec/fixtures/hieradata/default.yaml b/spec/fixtures/hieradata/default.yaml index ad2da39..a0f4efc 100644 --- a/spec/fixtures/hieradata/default.yaml +++ b/spec/fixtures/hieradata/default.yaml @@ -6,6 +6,7 @@ not_hash: string aodh::rabbit_password: 'password' aodh_redis_password: 'password' redis_vip: '127.0.0.1' +redis::bind: '10.0.0.1' aodh::auth::auth_password: 'password' aodh::db::mysql::password: 'password' aodh::keystone::authtoken::password: 'password' @@ -32,6 +33,9 @@ cinder::keystone::authtoken::password: 'password' gnocchi::keystone::authtoken::password: 'password' gnocchi::storage::ceph::ceph_username: 'gnocchi' gnocchi::storage::ceph::ceph_secret: 'password' +# haproxy related items +mysql_enabled: true +controller_node_ips: '10.1.0.1,10.1.0.2' # nova related items nova::rabbit_password: 'password' nova::keystone::authtoken::password: 'password' |