From 794dd21bc57648ecdb68640df26f3b2dc1f5758b Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 1 Aug 2016 18:23:24 -0600 Subject: [PATCH] Fix fuel module tests This change adds a Gemfile and updates the rspec tests for the fuel module so they actually work. Change-Id: Idb40cf3e7762c9460fc8ecbc700857829ef22627 Closes-Bug: #1608732 --- deployment/puppet/fuel/.fixtures.yml | 12 ++++ deployment/puppet/fuel/Gemfile | 18 ++++++ .../fuel/spec/classes/fuel__rabbitmq__spec.rb | 9 +-- .../fuel/spec/classes/fuel_keystone_spec.rb | 4 +- .../fuel/spec/classes/nginx_nailgun_spec.rb | 29 +++++---- .../fuel/spec/classes/nginx_service_spec.rb | 13 +++- .../puppet/fuel/spec/hosts/default_spec.rb | 60 ------------------- deployment/puppet/fuel/spec/spec_helper.rb | 23 +++++-- 8 files changed, 85 insertions(+), 83 deletions(-) create mode 100644 deployment/puppet/fuel/Gemfile delete mode 100644 deployment/puppet/fuel/spec/hosts/default_spec.rb diff --git a/deployment/puppet/fuel/.fixtures.yml b/deployment/puppet/fuel/.fixtures.yml index 74f257e4cd..f279f5e609 100644 --- a/deployment/puppet/fuel/.fixtures.yml +++ b/deployment/puppet/fuel/.fixtures.yml @@ -1,3 +1,15 @@ fixtures: symlinks: fuel: "#{source_dir}" + stdlib: "#{source_dir}/../stdlib" + apache: "#{source_dir}/../apache" + rabbitmq: "#{source_dir}/../rabbitmq" + concat: "#{source_dir}/../concat" + inifile: "#{source_dir}/../inifile" + keystone: "#{source_dir}/../keystone" + openstacklib: "#{source_dir}/../openstacklib" + oslo: "#{source_dir}/../oslo" + apt: "#{source_dir}/../apt" + openssl: "#{source_dir}/../openssl" + postgresql: "#{source_dir}/../postgresql" + staging: "#{source_dir}/../staging" diff --git a/deployment/puppet/fuel/Gemfile b/deployment/puppet/fuel/Gemfile new file mode 100644 index 0000000000..45217b9f90 --- /dev/null +++ b/deployment/puppet/fuel/Gemfile @@ -0,0 +1,18 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'rake', :require => false + gem 'rspec', '~>3.3', :require => false + gem 'rspec-puppet', '~>2.1.0', :require => false + gem 'rspec-puppet-facts', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment/puppet/fuel/spec/classes/fuel__rabbitmq__spec.rb b/deployment/puppet/fuel/spec/classes/fuel__rabbitmq__spec.rb index 1024f8b35e..b50a81ccc6 100644 --- a/deployment/puppet/fuel/spec/classes/fuel__rabbitmq__spec.rb +++ b/deployment/puppet/fuel/spec/classes/fuel__rabbitmq__spec.rb @@ -3,10 +3,11 @@ require 'spec_helper' describe 'fuel::rabbitmq', :type => :class do context 'on supported platform' do let(:facts) {{ - :osfamily => 'Debian', - :lsbdistid => 'Ubuntu', - :operatingsystem => 'Ubuntu', - :operatingsystemrelease => '14.04', + :osfamily => 'RedHat', + :lsbdistid => 'CentOS', + :operatingsystem => 'CentOS', + :operatingsystemrelease => '7.2', + :operatingsystemmajrelease => '7', }} context 'with default parameters' do describe 'declares rabbitmq class' do diff --git a/deployment/puppet/fuel/spec/classes/fuel_keystone_spec.rb b/deployment/puppet/fuel/spec/classes/fuel_keystone_spec.rb index dd1f6492b8..1ed0ec404a 100644 --- a/deployment/puppet/fuel/spec/classes/fuel_keystone_spec.rb +++ b/deployment/puppet/fuel/spec/classes/fuel_keystone_spec.rb @@ -38,7 +38,7 @@ describe "fuel::keystone" do :priority => '05', :threads => 3, :vhost_custom_fragment => 'LimitRequestFieldSize 81900', - :workers => 6, + :workers => 1, :access_log_format => 'forwarded', ) end @@ -49,7 +49,7 @@ describe "fuel::keystone" do on_supported_os(supported_os: supported_os).each do |os, facts| context "on #{os}" do - let(:facts) { facts } + let(:facts) { facts.merge!(@default_facts) } it_configures "keystone configuration" end end diff --git a/deployment/puppet/fuel/spec/classes/nginx_nailgun_spec.rb b/deployment/puppet/fuel/spec/classes/nginx_nailgun_spec.rb index c5295ff1da..0b86697f35 100644 --- a/deployment/puppet/fuel/spec/classes/nginx_nailgun_spec.rb +++ b/deployment/puppet/fuel/spec/classes/nginx_nailgun_spec.rb @@ -1,17 +1,26 @@ require 'spec_helper' describe 'fuel::nginx::services' do - context 'when TLS enabled' do - let :params do - { - :staticdir => '/var/www/static/', - :logdumpdir => '/var/log/', - :ssl_enabled => true, - } - end + shared_examples_for "fuel nginx services" do + context 'when TLS enabled' do + let :params do + { + :staticdir => '/var/www/static/', + :logdumpdir => '/var/log/', + :ssl_enabled => true, + } + end - it 'should create new Diffie-Hellmann parameters file' do - should contain_exec('create new dhparam file') + it 'should create ssl file' do + should contain_openssl__certificate__x509('nginx') + end + end + end + + on_supported_os(supported_os: supported_os).each do |os, facts| + context "on #{os}" do + let(:facts) { facts } + it_configures "fuel nginx services" end end end diff --git a/deployment/puppet/fuel/spec/classes/nginx_service_spec.rb b/deployment/puppet/fuel/spec/classes/nginx_service_spec.rb index 20032f29a5..8bc936dfc2 100644 --- a/deployment/puppet/fuel/spec/classes/nginx_service_spec.rb +++ b/deployment/puppet/fuel/spec/classes/nginx_service_spec.rb @@ -1,7 +1,16 @@ require 'spec_helper' describe 'fuel::nginx' do - it 'should contain X-Frame-Options SAMEORIGIN header' do - should contain_file('/etc/nginx/nginx.conf').with_content(/^\s*add_header X-Frame-Options SAMEORIGIN;$/) + shared_examples_for "fuel nginx" do + it 'should contain X-Frame-Options SAMEORIGIN header' do + should contain_file('/etc/nginx/nginx.conf').with_content(/^\s*add_header X-Frame-Options SAMEORIGIN;$/) + end + end + + on_supported_os(supported_os: supported_os).each do |os, facts| + context "on #{os}" do + let(:facts) { facts } + it_configures "fuel nginx" + end end end diff --git a/deployment/puppet/fuel/spec/hosts/default_spec.rb b/deployment/puppet/fuel/spec/hosts/default_spec.rb deleted file mode 100644 index 747c452eed..0000000000 --- a/deployment/puppet/fuel/spec/hosts/default_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'spec_helper' -require 'zlib' -require 'ipaddr' - -describe 'default' do - admin_nets = [ - {"id"=>1, - "node_group_name"=>nil, - "node_group_id"=>nil, - "cluster_name"=>nil, - "cluster_id"=>nil, - "cidr"=>"10.145.0.0/24", - "gateway"=>"10.145.0.2", - "ip_ranges"=>[["10.145.0.3", "10.145.0.250"]]}, - {"id"=>2, - "node_group_name"=>"default2", - "node_group_id"=>22, - "cluster_name"=>"default2", - "cluster_id"=>2, - "cidr"=>"10.144.0.0/24", - "gateway"=>"10.144.0.5", - "ip_ranges"=>[["10.144.0.10", "10.144.0.254"]]}, - # Network with parameters shared with id=2 - {"id"=>3, - "node_group_name"=>"default3", - "node_group_id"=>23, - "cluster_name"=>"default3", - "cluster_id"=>3, - "cidr"=>"10.144.0.0/24", - "gateway"=>"10.144.0.5", - "ip_ranges"=>[["10.144.0.10", "10.144.0.254"]]} - ] - admin_network = {"interface"=>"eth0", - "ipaddress"=>"10.145.0.2", - "netmask"=>"255.255.255.0", - "cidr"=>"10.20.0.0/24", - "size"=>"256", - "dhcp_pool_start"=>"10.145.0.3", - "dhcp_pool_end"=>"10.145.0.254", - "mac"=>"64:42:d3:10:64:68", - "dhcp_gateway"=>"10.145.0.1"} - - admin_nets.each do |net| - net['ip_ranges'].each do |ip_range| - netmask = IPAddr.new('255.255.255.255').mask(net['cidr'].split('/')[1]).to_s - print_range = ip_range.join('_') - resource_name = sprintf("range_%08x", Zlib::crc32("#{print_range}_#{net['cidr']}").to_i) - it { should contain_file("/etc/dnsmasq.d/#{resource_name}.conf") \ - .with_content(/^dhcp-range=#{resource_name}.*#{netmask},120m\n|,boothost,#{admin_network['ipaddress']}\n/) - } - it { should contain_file("/etc/dnsmasq.d/#{resource_name}.conf") \ - .with_content(/^dhcp-match=set:ipxe,175$/) - } - it { should contain_file("/etc/dnsmasq.d/#{resource_name}.conf") \ - .with_content(/^dhcp-option-force=tag:ipxe,210,http:/) - } - end - end - -end diff --git a/deployment/puppet/fuel/spec/spec_helper.rb b/deployment/puppet/fuel/spec/spec_helper.rb index 9384c6916f..255342c74e 100644 --- a/deployment/puppet/fuel/spec/spec_helper.rb +++ b/deployment/puppet/fuel/spec/spec_helper.rb @@ -1,12 +1,25 @@ require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' - -fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) +require 'rspec-puppet-facts' +include RspecPuppetFacts RSpec.configure do |c| - c.module_path = File.join(fixture_path, 'modules') - c.manifest_dir = File.join(fixture_path, 'manifests') - c.mock_with(:mocha) + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' + c.before :each do + @default_facts = { :os_service_default => '' } + end +end + +# TODO(aschultz): remove these and switch rspec-puppet-facts to use +# metadata.json values +def supported_os + [ + { 'operatingsystem' => 'CentOS', + 'operatingsystemrelease' => [ '7.0' ] }, + { 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => [ '14.04' ] } + ] end def puppet_debug_override