diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/classes/tripleo_cluster_cassandra_spec.rb | 20 | ||||
-rw-r--r-- | spec/classes/tripleo_cluster_zookeeper_spec.rb | 125 | ||||
-rw-r--r-- | spec/classes/tripleo_firewall_spec.rb | 24 | ||||
-rw-r--r-- | spec/classes/tripleo_host_sriov_spec.rb | 39 | ||||
-rw-r--r-- | spec/classes/tripleo_midonet_agent_spec.rb | 22 | ||||
-rw-r--r-- | spec/classes/tripleo_midonet_api_spec.rb | 20 | ||||
-rw-r--r-- | spec/classes/tripleo_packages_spec.rb | 20 | ||||
-rw-r--r-- | spec/classes/tripleo_profile_base_swift_proxy_spec.rb | 92 | ||||
-rw-r--r-- | spec/classes/tripleo_selinux_spec.rb | 24 | ||||
-rw-r--r-- | spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb | 40 | ||||
-rw-r--r-- | spec/spec_helper.rb | 17 | ||||
-rw-r--r-- | spec/unit/provider/sriov_vf_config/numvfs_spec.rb | 40 | ||||
-rw-r--r-- | spec/unit/type/sriov_vf_config_spec.rb | 47 |
13 files changed, 378 insertions, 152 deletions
diff --git a/spec/classes/tripleo_cluster_cassandra_spec.rb b/spec/classes/tripleo_cluster_cassandra_spec.rb index 13be98e..3f7d471 100644 --- a/spec/classes/tripleo_cluster_cassandra_spec.rb +++ b/spec/classes/tripleo_cluster_cassandra_spec.rb @@ -19,15 +19,7 @@ require 'spec_helper' describe 'tripleo::cluster::cassandra' do - shared_examples_for 'cassandra cluster service' do - - let :facts do - { - :hostname => 'host1.midonet', - :osfamily => 'RedHat', - :operatingsystemmajrelease => 7, - } - end + shared_examples_for 'tripleo::cluster::cassandra' do let :params do { @@ -49,6 +41,14 @@ describe 'tripleo::cluster::cassandra' do 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 diff --git a/spec/classes/tripleo_cluster_zookeeper_spec.rb b/spec/classes/tripleo_cluster_zookeeper_spec.rb index ed46164..fc003b6 100644 --- a/spec/classes/tripleo_cluster_zookeeper_spec.rb +++ b/spec/classes/tripleo_cluster_zookeeper_spec.rb @@ -19,97 +19,68 @@ require 'spec_helper' describe 'tripleo::cluster::zookeeper' do - let :default_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', - :osfamily => 'RedHat', - :operatingsystemmajrelease => 7, - } - end - + shared_examples_for 'tripleo::cluster::zookeeper' do let :params do - { - :zookeeper_client_ip => '23.43.2.34' - } - 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.34', - :id => 1 - ) - end - - end - - context 'on host2' do - let :facts do { - :hostname => 'host2.midonet', - :osfamily => 'RedHat', - :operatingsystemmajrelease => 7, + :zookeeper_server_ips => ['23.43.2.34', '23.43.2.35', '24.43.2.36'], + :zookeeper_hostnames => ['host1.midonet', 'host2.midonet', 'host3.midonet'] } end - let :params do - { - :zookeeper_client_ip => '23.43.2.35' - } + context 'on host1' do + before :each do + 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 - before do - params.merge!(default_params) + context 'on host2' do + 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 - 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 + context 'on host3' do + before :each do + facts.merge!({ :hostname => 'host3.midonet'}) + params.merge!({ :zookeeper_client_ip => '23.43.2.36' }) + end - context 'on host3' do - let :facts do - { - :hostname => 'host3.midonet', - :osfamily => 'RedHat', - :operatingsystemmajrelease => 7, - } - 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 - let :params do - { - :zookeeper_client_ip => '23.43.2.36' - } end + end - before do - params.merge!(default_params) - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + 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 - ) + it_behaves_like 'tripleo::cluster::zookeeper' end - end - end diff --git a/spec/classes/tripleo_firewall_spec.rb b/spec/classes/tripleo_firewall_spec.rb index 27ac62a..1270aa7 100644 --- a/spec/classes/tripleo_firewall_spec.rb +++ b/spec/classes/tripleo_firewall_spec.rb @@ -24,7 +24,7 @@ describe 'tripleo::firewall' do { } end - shared_examples_for 'tripleo node' do + shared_examples_for 'tripleo::firewall' do context 'with firewall enabled' do before :each do @@ -114,23 +114,13 @@ describe 'tripleo::firewall' do end - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian' } - end - - it_configures 'tripleo node' - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + end - context 'on RedHat platforms' do - let :facts do - { - :osfamily => 'RedHat', - :operatingsystemrelease => '7.1', - } + it_behaves_like 'tripleo::firewall' end - - it_configures 'tripleo node' end - end diff --git a/spec/classes/tripleo_host_sriov_spec.rb b/spec/classes/tripleo_host_sriov_spec.rb new file mode 100644 index 0000000..920eb9b --- /dev/null +++ b/spec/classes/tripleo_host_sriov_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'tripleo::host::sriov' do + + shared_examples_for 'tripleo::host::sriov' do + let :params do + {:number_of_vfs => []} + end + + it 'does not configure numvfs by default' do + is_expected.not_to contain_sriov_vf_config([]) + end + + context 'when number_of_vfs is configured' do + let :params do + {:number_of_vfs => ['eth0:4','eth1:5']} + end + + it 'configures numvfs' do + is_expected.to contain_sriov_vf_config('eth0:4').with( :ensure => 'present' ) + is_expected.to contain_sriov_vf_config('eth1:5').with( :ensure => 'present') + is_expected.to contain_tripleo__host__sriov__numvfs_persistence('persistent_numvfs').with( + :vf_defs => ['eth0:4','eth1:5'], + :content_string => "#!/bin/bash\n" + ) + end + end + end + + 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 diff --git a/spec/classes/tripleo_midonet_agent_spec.rb b/spec/classes/tripleo_midonet_agent_spec.rb index eb3abfe..73d90b6 100644 --- a/spec/classes/tripleo_midonet_agent_spec.rb +++ b/spec/classes/tripleo_midonet_agent_spec.rb @@ -19,17 +19,7 @@ require 'spec_helper' describe 'tripleo::network::midonet::agent' do - let :facts do - { - :hostname => 'host2.midonet', - :osfamily => 'RedHat', - :operatingsystem => 'CentOS', - :operatingsystemrelease => '7.1', - :operatingsystemmajrelease => 7, - } - end - - shared_examples_for 'midonet agent test' do + shared_examples_for 'tripleo::network::midonet::agent' do let :params do { @@ -56,7 +46,13 @@ describe 'tripleo::network::midonet::agent' do 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 diff --git a/spec/classes/tripleo_midonet_api_spec.rb b/spec/classes/tripleo_midonet_api_spec.rb index 4b47294..25b375b 100644 --- a/spec/classes/tripleo_midonet_api_spec.rb +++ b/spec/classes/tripleo_midonet_api_spec.rb @@ -19,13 +19,7 @@ require 'spec_helper' describe 'tripleo::network::midonet::api' do - let :facts do - { - :augeasversion => '1.0.0' - } - end - - shared_examples_for 'midonet api test' do + shared_examples_for 'tripleo::midonet::api' do let :params do { @@ -67,6 +61,16 @@ describe 'tripleo::network::midonet::api' do 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 diff --git a/spec/classes/tripleo_packages_spec.rb b/spec/classes/tripleo_packages_spec.rb index 80e5d7e..076d9cd 100644 --- a/spec/classes/tripleo_packages_spec.rb +++ b/spec/classes/tripleo_packages_spec.rb @@ -17,19 +17,12 @@ require 'spec_helper' describe 'tripleo::packages' do - shared_examples_for 'Red Hat distributions' do + shared_examples_for 'tripleo::packages' do let :pre_condition do "service{'nova-compute': ensure => 'running'}" end - let :facts do - { - :osfamily => 'RedHat', - :operatingsystemmajrelease => 7, - } - end - let :params do { :enable_upgrade => true @@ -43,6 +36,15 @@ describe 'tripleo::packages' do 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 diff --git a/spec/classes/tripleo_profile_base_swift_proxy_spec.rb b/spec/classes/tripleo_profile_base_swift_proxy_spec.rb new file mode 100644 index 0000000..68d7dde --- /dev/null +++ b/spec/classes/tripleo_profile_base_swift_proxy_spec.rb @@ -0,0 +1,92 @@ +# +# Copyright (C) 2016 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::swift::proxy' do + + let :params do + { } + end + + shared_examples_for 'tripleo::profile::base::swift::proxy' do + + let :pre_condition do + "class { '::swift': + swift_hash_path_prefix => 'foo', + } + include ::memcached + class { '::swift::proxy': + proxy_local_net_ip => '127.0.0.1', + }" + end + + context 'with ipv4 memcache servers' do + before :each do + params.merge!( + :step => 4, + :memcache_servers => ['192.168.0.1', '192.168.0.2'], + ) + end + + it 'configure swift proxy cache with ipv4 ips' do + is_expected.to contain_class('swift::proxy::cache').with({ + :memcache_servers => ['192.168.0.1:11211', '192.168.0.2:11211'] + }) + end + end + + context 'with ipv6 memcache servers' do + before :each do + params.merge!( + :step => 4, + :memcache_servers => ['::1', '::2'], + ) + end + + it 'configure swift proxy cache with ipv6 ips' do + is_expected.to contain_class('swift::proxy::cache').with({ + :memcache_servers => ['[::1]:11211', '[::2]:11211'] + }) + end + end + + context 'with ipv4, ipv6 and fqdn memcache servers' do + before :each do + params.merge!( + :step => 4, + :memcache_servers => ['192.168.0.1', '::2', 'myserver.com'], + ) + end + + it 'configure swift proxy cache with ips and fqdn' do + is_expected.to contain_class('swift::proxy::cache').with({ + :memcache_servers => ['192.168.0.1:11211', '[::2]:11211', 'myserver.com:11211'] + }) + 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::swift::proxy' + end + end +end diff --git a/spec/classes/tripleo_selinux_spec.rb b/spec/classes/tripleo_selinux_spec.rb index 301006b..f49f87b 100644 --- a/spec/classes/tripleo_selinux_spec.rb +++ b/spec/classes/tripleo_selinux_spec.rb @@ -19,11 +19,14 @@ require 'spec_helper' describe 'tripleo::selinux' do - shared_examples_for 'manage selinux' do + shared_examples_for 'tripleo::selinux' do context 'with selinux enforcing' do before :each do - facts.merge!( :selinux_current_mode => 'enforcing' ) + facts.merge!({ + :selinux => true, + :selinux_current_mode => 'enforcing' + }) end let :params do @@ -55,7 +58,7 @@ describe 'tripleo::selinux' do context 'with selinux disabled' do before :each do - facts.merge!( :selinux => 'false' ) + facts.merge!({ :selinux => 'false' }) end let :params do @@ -89,18 +92,19 @@ describe 'tripleo::selinux' do context 'on Debian platforms' do let :facts do - { :osfamily => 'Debian' } + { :osfamily => 'Debian' } end it_raises 'a Puppet::Error', /OS family unsuppored yet \(Debian\), SELinux support is only limited to RedHat family OS/ end - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({}) + end - it_configures 'manage selinux' + it_behaves_like 'tripleo::selinux' + end end - end diff --git a/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb new file mode 100644 index 0000000..57559a2 --- /dev/null +++ b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'tripleo::host::sriov::numvfs_persistence' do + + describe 'confugure numvfs for persistence' do + + let :title do + 'numvfs' + end + + let :params do + { + :name => 'persistence', + :vf_defs => ['eth0:10','eth1:8'], + :content_string => "Hashbang\n" + } + end + + it 'configures persistence' do + is_expected.to contain_file('/etc/sysconfig/allocate_vfs').with( + :ensure => 'file', + :content => "Hashbang\n[ \"eth0\" == \"\$1\" ] && echo 10 > /sys/class/net/eth0/device/sriov_numvfs\n[ \"eth1\" == \"\$1\" ] && echo 8 > /sys/class/net/eth1/device/sriov_numvfs\n", + :group => 'root', + :mode => '0755', + :owner => 'root', + ) + is_expected.to contain_file('/sbin/ifup-local').with( + :group => 'root', + :mode => '0755', + :owner => 'root', + :content => '#!/bin/bash', + :replace => false, + ) + is_expected.to contain_file_line('call_ifup-local').with( + :path => '/sbin/ifup-local', + :line => '/etc/sysconfig/allocate_vfs $1', + ) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 251160e..b06b436 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,23 +1,24 @@ +# Load libraries from openstacklib here to simulate how they live together in a real puppet run (for provider unit tests) +$LOAD_PATH.push(File.join(File.dirname(__FILE__), 'fixtures', 'modules', 'openstacklib', 'lib')) require 'puppetlabs_spec_helper/module_spec_helper' require 'shared_examples' +require 'puppet-openstack_spec_helper/defaults' +require 'rspec-puppet-facts' +include RspecPuppetFacts + fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| c.alias_it_should_behave_like_to :it_configures, 'configures' c.alias_it_should_behave_like_to :it_raises, 'raises' + c.hiera_config = File.join(fixture_path, 'hiera.yaml') c.module_path = File.join(fixture_path, 'modules') c.manifest_dir = File.join(fixture_path, 'manifests') - c.default_facts = { - :kernel => 'Linux', - :concat_basedir => '/var/lib/puppet/concat', - :memorysize => '1000 MB', - :processorcount => '1', - :puppetversion => '3.7.3', - :uniqueid => '123' - } + # custom global facts for all rspec tests + add_custom_fact :concat_basedir, '/var/lib/puppet/concat' end at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/unit/provider/sriov_vf_config/numvfs_spec.rb b/spec/unit/provider/sriov_vf_config/numvfs_spec.rb new file mode 100644 index 0000000..ac1a398 --- /dev/null +++ b/spec/unit/provider/sriov_vf_config/numvfs_spec.rb @@ -0,0 +1,40 @@ +require 'puppet' +require 'spec_helper' +require 'puppet/provider/sriov_vf_config/numvfs' + +provider_class = Puppet::Type.type(:sriov_vf_config). + provider(:numvfs) + +describe provider_class do + + let(:test_cfg_path) { "/tmp/test-ifup-local.txt" } + let :numvfs_conf do + { + :name => 'eth0:10', + :ensure => 'present', + } + end + + describe 'when setting the attributes' do + let :resource do + Puppet::Type::Sriov_vf_config.new(numvfs_conf) + end + + let :provider do + provider_class.new(resource) + end + + it 'should return the correct interface name' do + expect(provider.sriov_get_interface).to eql('eth0') + end + + it 'should return the correct numvfs value' do + expect(provider.sriov_numvfs_value).to eql(10) + end + + it 'should return path of the file to enable vfs' do + expect(provider.sriov_numvfs_path).to eql('/sys/class/net/eth0/device/sriov_numvfs') + end + end + +end diff --git a/spec/unit/type/sriov_vf_config_spec.rb b/spec/unit/type/sriov_vf_config_spec.rb new file mode 100644 index 0000000..9a911f6 --- /dev/null +++ b/spec/unit/type/sriov_vf_config_spec.rb @@ -0,0 +1,47 @@ +require 'puppet' +require 'puppet/type/sriov_vf_config' + +describe 'Puppet::Type.type(:sriov_vf_config)' do + it 'should allow name to be passed' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth0:10', + :ensure => 'present' + )}.not_to raise_error + end + it 'should allow name to be passed with -' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth-0:10', + :ensure => 'present' + )}.not_to raise_error + end + it 'should allow name to be passed with _' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth_0:10', + :ensure => 'present' + )}.not_to raise_error + end + it 'should throw error for invalid format' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth0', + :ensure => 'present' + )}.to raise_error(Puppet::ResourceError) + end + it 'should throw error for invalid format without interface name' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => ':9', + :ensure => 'present' + )}.to raise_error(Puppet::ResourceError) + end + it 'should throw error for invalid format for numvfs' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth8:none', + :ensure => 'present' + )}.to raise_error(Puppet::ResourceError) + end + it 'should throw error for invalid format without numvfs' do + expect{Puppet::Type.type(:sriov_vf_config).new( + :name => 'eth0:', + :ensure => 'present' + )}.to raise_error(Puppet::ResourceError) + end +end |