diff --git a/spec/classes/tripleo_profile_base_neutron_dhcp_spec.rb b/spec/classes/tripleo_profile_base_neutron_dhcp_spec.rb index 9c4c3af26..ec0d93546 100644 --- a/spec/classes/tripleo_profile_base_neutron_dhcp_spec.rb +++ b/spec/classes/tripleo_profile_base_neutron_dhcp_spec.rb @@ -24,11 +24,20 @@ describe 'tripleo::profile::base::neutron::dhcp' do facts.merge!({ :step => params[:step] }) end - context 'with defaults for all parameters' do - let(:params) { { :step => 4 } } - + context 'with step less than 4' do + let(:params) { { :step => 3 } } it 'should do nothing' do is_expected.to contain_class('tripleo::profile::base::neutron::dhcp') + is_expected.to_not contain_class('tripleo::profile::base::neutron') + is_expected.to_not contain_class('neutron::agents::dhcp') + end + end + + context 'with step 4 and later' do + let(:params) { { :step => 4 } } + it 'should trigger complete configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::dhcp') + is_expected.to contain_class('tripleo::profile::base::neutron') is_expected.to contain_class('neutron::agents::dhcp') end end diff --git a/spec/classes/tripleo_profile_base_neutron_l3_spec.rb b/spec/classes/tripleo_profile_base_neutron_l3_spec.rb index d04b2dfe4..fae7fcdba 100644 --- a/spec/classes/tripleo_profile_base_neutron_l3_spec.rb +++ b/spec/classes/tripleo_profile_base_neutron_l3_spec.rb @@ -24,11 +24,20 @@ describe 'tripleo::profile::base::neutron::l3' do facts.merge!({ :step => params[:step] }) end - context 'with defaults for all parameters' do - let(:params) { { :step => 4 } } - + context 'with step less than 4' do + let(:params) { { :step => 3 } } it 'should do nothing' do is_expected.to contain_class('tripleo::profile::base::neutron::l3') + is_expected.to_not contain_class('tripleo::profile::base::neutron') + is_expected.to_not contain_class('neutron::agents::l3') + end + end + + context 'with step 4 and later' do + let(:params) { { :step => 4 } } + it 'should trigger complete configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::l3') + is_expected.to contain_class('tripleo::profile::base::neutron') is_expected.to contain_class('neutron::agents::l3') end end diff --git a/spec/classes/tripleo_profile_base_neutron_ovs_spec.rb b/spec/classes/tripleo_profile_base_neutron_ovs_spec.rb index 5b9040b11..c5ec01f7d 100644 --- a/spec/classes/tripleo_profile_base_neutron_ovs_spec.rb +++ b/spec/classes/tripleo_profile_base_neutron_ovs_spec.rb @@ -24,15 +24,23 @@ describe 'tripleo::profile::base::neutron::ovs' do facts.merge!({ :step => params[:step] }) end - context 'with defaults for all parameters' do - let(:params) { { :step => 3 } } - - it 'should do nothing in step 3' do + context 'with step less than 5 and defaults for all parameters' do + let(:params) { { :step => 4 } } + it 'should do nothing' do is_expected.to contain_class('tripleo::profile::base::neutron') is_expected.to_not contain_class('neutron::agents::ml2::ovs') is_expected.not_to contain_file('/var/lib/vhostuser_sockets') end end + + context 'with step 5 and defaults for all parameters' do + let(:params) { { :step => 5 } } + it 'should trigger complete configuration except for vhostuser sockets' do + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('neutron::agents::ml2::ovs') + is_expected.not_to contain_file('/var/lib/vhostuser_sockets') + end + end end shared_examples_for 'tripleo::profile::base::neutron::ovs with vhostuser_socketdir' do diff --git a/spec/classes/tripleo_profile_base_neutron_server_spec.rb b/spec/classes/tripleo_profile_base_neutron_server_spec.rb new file mode 100644 index 000000000..a26722de7 --- /dev/null +++ b/spec/classes/tripleo_profile_base_neutron_server_spec.rb @@ -0,0 +1,187 @@ +# +# Copyright (C) 2019 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::neutron::server' do + shared_examples_for 'tripleo::profile::base::neutron::server' do + before :each do + facts.merge!({ :step => params[:step] }) + end + + let(:pre_condition) do + <<-eos + class { '::tripleo::profile::base::neutron': + oslomsg_rpc_hosts => [ 'localhost' ], + oslomsg_rpc_username => 'neutron', + oslomsg_rpc_password => 'foo' + } +eos + end + + context 'with step less than 3' do + let(:params) { { + :step => 1, + :bootstrap_node => 'node.example.com', + } } + it 'should od nothing' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to_not contain_class('tripleo::profile::base::apache') + is_expected.to_not contain_class('neutron::server::notifications') + is_expected.to_not contain_class('neutron::server') + is_expected.to_not contain_class('neutron::quota') + end + end + + context 'with step 3 on bootstrap node' do + let(:params) { { + :step => 3, + :bootstrap_node => 'node.example.com', + } } + it 'should trigger apache configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to contain_class('tripleo::profile::base::apache') + is_expected.to_not contain_class('neutron::server::notifications') + is_expected.to_not contain_class('neutron::server') + is_expected.to_not contain_class('neutron::quota') + end + end + + context 'with step 3 not on bootstrap node' do + let(:params) { { + :step => 3, + :bootstrap_node => 'other.example.com', + } } + it 'should do nothing' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to_not contain_class('tripleo::profile::base::apache') + is_expected.to_not contain_class('neutron::server::notifications') + is_expected.to_not contain_class('neutron::server') + is_expected.to_not contain_class('neutron::quota') + end + end + + context 'with step 4 on bootstrap node' do + let(:params) { { + :step => 4, + :bootstrap_node => 'node.example.com', + } } + it 'should trigger complete configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to contain_class('tripleo::profile::base::apache') + is_expected.to contain_class('neutron::server::notifications') + is_expected.to contain_class('neutron::server').with( + :sync_db => true, + :l3_ha => false, + ) + is_expected.to contain_class('neutron::quota') + end + end + + context 'with step 4 not on bootstrap node' do + let(:params) { { + :step => 4, + :bootstrap_node => 'other.example.com', + } } + it 'should trigger apache configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to contain_class('tripleo::profile::base::apache') + is_expected.to_not contain_class('neutron::server::notifications') + is_expected.to_not contain_class('neutron::server') + is_expected.to_not contain_class('neutron::quota') + end + end + + context 'with step 5 not on bootstrap nodes' do + let(:params) { { + :step => 5, + :bootstrap_node => 'other.example.com', + } } + it 'should trigger complete configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron::server') + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('tripleo::profile::base::neutron::authtoken') + is_expected.to contain_class('tripleo::profile::base::apache') + is_expected.to contain_class('neutron::server::notifications') + is_expected.to contain_class('neutron::server').with( + :sync_db => false, + :l3_ha => false, + ) + is_expected.to contain_class('neutron::quota') + end + end + + context 'with multiple l3 nods' do + let(:params) { { + :step => 5, + :bootstrap_node => 'node.example.com', + :l3_nodes => ['netcont1.localdomain', 'netcont2.localdomain', 'netcont3.localdomain'], + } } + it 'should enable l3_ha' do + is_expected.to contain_class('neutron::server').with( + :l3_ha => true, + ) + end + end + + context 'with multiple l3 nods and dvr enabled' do + let(:params) { { + :step => 5, + :bootstrap_node => 'node.example.com', + :l3_nodes => ['netcont1.localdomain', 'netcont2.localdomain', 'netcont3.localdomain'], + :dvr_enabled => true + } } + it 'should disable l3_ha' do + is_expected.to contain_class('neutron::server').with( + :l3_ha => false, + ) + end + end + + context 'with l3_ha_override passed' do + let(:params) { { + :step => 5, + :bootstrap_node => 'node.example.com', + :l3_ha_override => 'true' + } } + it 'should enable l3_ha' do + is_expected.to contain_class('neutron::server').with( + :l3_ha => true, + ) + 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::neutron::server' + end + end +end diff --git a/spec/classes/tripleo_profile_base_neutron_spec.rb b/spec/classes/tripleo_profile_base_neutron_spec.rb index 0363bd1d3..a6735aeb1 100644 --- a/spec/classes/tripleo_profile_base_neutron_spec.rb +++ b/spec/classes/tripleo_profile_base_neutron_spec.rb @@ -17,49 +17,72 @@ require 'spec_helper' describe 'tripleo::profile::base::neutron' do - let :params do - { :step => 5, - :oslomsg_notify_password => 'foobar', - :oslomsg_rpc_password => 'foobar' - } - end - shared_examples_for 'tripleo::profile::base::neutron' do before :each do facts.merge!({ :step => params[:step] }) end - context 'when no dhcp agents per network set' do - before do - params.merge!({ - :dhcp_nodes => ['netcont1.localdomain', 'netcont2.localdomain', 'netcont3.localdomain'] - }) - end - it 'should equal the number of dhcp agents' do - is_expected.to contain_class('neutron').with(:dhcp_agents_per_network => 3) + context 'with step less than 3' do + let(:params) { { :step => 1 } } + it 'should od nothing' do + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to_not contain_class('neutron') + is_expected.to_not contain_class('neutron::config') + is_expected.to_not contain_class('neutron::logging') end end - context 'when dhcp agents per network is set' do - before do - params.merge!({ - :dhcp_agents_per_network => 2 - }) + context 'with step 3' do + let(:params) { { + :step => 3, + :oslomsg_rpc_hosts => [ '192.168.0.1' ], + :oslomsg_rpc_username => 'neutron1', + :oslomsg_rpc_password => 'foo', + :oslomsg_rpc_port => '1234', + :oslomsg_notify_hosts => [ '192.168.0.2' ], + :oslomsg_notify_username => 'neutron2', + :oslomsg_notify_password => 'baa', + :oslomsg_notify_port => '5678', + :dhcp_agents_per_network => 2 + } } + it 'should trigger complete configuration' do + is_expected.to contain_class('tripleo::profile::base::neutron') + is_expected.to contain_class('neutron').with( + :default_transport_url => 'rabbit://neutron1:foo@192.168.0.1:1234/?ssl=0', + :notification_transport_url => 'rabbit://neutron2:baa@192.168.0.2:5678/?ssl=0', + :dhcp_agents_per_network => 2 + ) + is_expected.to contain_class('neutron::config') + is_expected.to contain_class('neutron::logging') end - it 'should set the value' do - is_expected.to contain_class('neutron').with(:dhcp_agents_per_network => 2) + end + + context 'when not dhcp agents per network is set' do + let(:params) { { + :step => 3, + :oslomsg_rpc_password => 'foo', + :oslomsg_notify_password => 'baa', + :dhcp_nodes => ['netcont1.localdomain', 'netcont2.localdomain', 'netcont3.localdomain'] + } } + it 'should equal the number of dhcp agents' do + is_expected.to contain_class('neutron').with( + :dhcp_agents_per_network => 3 + ) end end context 'when dhcp agents per network is greater than number of agents' do - before do - params.merge!({ - :dhcp_nodes => ['netcont1.localdomain', 'netcont2.localdomain'], - :dhcp_agents_per_network => 5 - }) - end + let(:params) { { + :step => 3, + :oslomsg_rpc_password => 'foo', + :oslomsg_notify_password => 'baa', + :dhcp_nodes => ['netcont1.localdomain', 'netcont2.localdomain'], + :dhcp_agents_per_network => 5 + } } it 'should set value and complain about not enough agents' do - is_expected.to contain_class('neutron').with(:dhcp_agents_per_network => 5) + is_expected.to contain_class('neutron').with( + :dhcp_agents_per_network => 5 + ) end end end diff --git a/spec/fixtures/hieradata/default.yaml b/spec/fixtures/hieradata/default.yaml index f5b90cbb3..bf6b3082a 100644 --- a/spec/fixtures/hieradata/default.yaml +++ b/spec/fixtures/hieradata/default.yaml @@ -91,6 +91,7 @@ horizon_node_names: #Neutron related neutron::rabbit_password: 'password' neutron::keystone::authtoken::password: 'password' +neutron::server::notifications::password: 'password' # oslo.messaging related oslo_messaging_rpc_password: 'password' oslo_messaging_notify_password: 'password'