2013-11-21 23:33:09 +01:00
|
|
|
#
|
|
|
|
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
|
|
|
|
#
|
|
|
|
# Author: Emilien Macchi <emilien.macchi@enovance.com>
|
|
|
|
#
|
|
|
|
# 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 neutron::plugins::metering class
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'neutron::agents::metering' do
|
|
|
|
|
|
|
|
let :pre_condition do
|
|
|
|
"class { 'neutron':
|
|
|
|
service_plugins => ['neutron.services.metering.metering_plugin.MeteringPlugin'] }"
|
|
|
|
end
|
|
|
|
|
|
|
|
let :params do
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
|
|
|
let :default_params do
|
|
|
|
{ :package_ensure => 'present',
|
|
|
|
:enabled => true,
|
|
|
|
:interface_driver => 'neutron.agent.linux.interface.OVSInterfaceDriver',
|
2015-10-21 14:48:58 +03:00
|
|
|
:driver => 'neutron.services.metering.drivers.noop.noop_driver.NoopMeteringDriver',
|
2016-04-12 17:20:25 -06:00
|
|
|
:purge_config => false,
|
2013-11-21 23:33:09 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-11-02 19:25:12 +03:00
|
|
|
let :test_facts do
|
2015-06-09 12:20:49 -07:00
|
|
|
{ :operatingsystem => 'default',
|
|
|
|
:operatingsystemrelease => 'default'
|
|
|
|
}
|
|
|
|
end
|
2013-11-21 23:33:09 +01:00
|
|
|
|
|
|
|
shared_examples_for 'neutron metering agent' do
|
|
|
|
let :p do
|
|
|
|
default_params.merge(params)
|
|
|
|
end
|
|
|
|
|
2015-03-19 14:34:18 +01:00
|
|
|
it { is_expected.to contain_class('neutron::params') }
|
2013-11-21 23:33:09 +01:00
|
|
|
|
2016-04-12 17:20:25 -06:00
|
|
|
it 'passes purge to resource' do
|
|
|
|
is_expected.to contain_resources('neutron_metering_agent_config').with({
|
|
|
|
:purge => false
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2013-11-21 23:33:09 +01:00
|
|
|
it 'configures metering_agent.ini' do
|
2017-11-18 11:03:11 -03:30
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/debug').with_value('<SERVICE DEFAULT>');
|
2015-03-19 14:34:18 +01:00
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/interface_driver').with_value(p[:interface_driver]);
|
2015-10-21 14:48:58 +03:00
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/driver').with_value(p[:driver]);
|
2015-12-04 13:01:44 +03:00
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/measure_interval').with_value('<SERVICE DEFAULT>');
|
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/report_interval').with_value('<SERVICE DEFAULT>');
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'installs neutron metering agent package' do
|
|
|
|
if platform_params.has_key?(:metering_agent_package)
|
2015-03-19 14:34:18 +01:00
|
|
|
is_expected.to contain_package('neutron-metering-agent').with(
|
2013-11-21 23:33:09 +01:00
|
|
|
:name => platform_params[:metering_agent_package],
|
2014-11-11 12:37:20 +03:00
|
|
|
:ensure => p[:package_ensure],
|
2015-07-22 23:08:04 +02:00
|
|
|
:tag => ['openstack', 'neutron-package'],
|
2013-11-21 23:33:09 +01:00
|
|
|
)
|
2016-05-17 12:08:58 +00:00
|
|
|
is_expected.to contain_package('neutron').that_requires('Anchor[neutron::install::begin]')
|
|
|
|
is_expected.to contain_package('neutron').that_notifies('Anchor[neutron::install::end]')
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures neutron metering agent service' do
|
2015-03-19 14:34:18 +01:00
|
|
|
is_expected.to contain_service('neutron-metering-service').with(
|
2013-11-21 23:33:09 +01:00
|
|
|
:name => platform_params[:metering_agent_service],
|
|
|
|
:enable => true,
|
|
|
|
:ensure => 'running',
|
2015-07-22 23:08:04 +02:00
|
|
|
:tag => 'neutron-service',
|
2013-11-21 23:33:09 +01:00
|
|
|
)
|
2016-05-17 12:08:58 +00:00
|
|
|
is_expected.to contain_service('neutron-metering-service').that_subscribes_to('Anchor[neutron::service::begin]')
|
|
|
|
is_expected.to contain_service('neutron-metering-service').that_notifies('Anchor[neutron::service::end]')
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
2014-01-15 22:52:03 -06:00
|
|
|
|
|
|
|
context 'with manage_service as false' do
|
|
|
|
before :each do
|
|
|
|
params.merge!(:manage_service => false)
|
|
|
|
end
|
|
|
|
it 'should not start/stop service' do
|
2015-03-19 14:34:18 +01:00
|
|
|
is_expected.to contain_service('neutron-metering-service').without_ensure
|
2014-01-15 22:52:03 -06:00
|
|
|
end
|
|
|
|
end
|
2015-07-29 17:51:44 +03:00
|
|
|
|
2015-10-21 14:48:58 +03:00
|
|
|
context 'with non-default driver' do
|
|
|
|
before :each do
|
|
|
|
params.merge!(:driver => 'neutron.services.metering.drivers.iptables.iptables_driver.IptablesMeteringDriver')
|
|
|
|
end
|
|
|
|
it 'should properly set driver option' do
|
|
|
|
is_expected.to contain_neutron_metering_agent_config('DEFAULT/driver').with_value(p[:driver])
|
|
|
|
end
|
|
|
|
end
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
|
|
|
|
2014-02-27 14:08:18 +01:00
|
|
|
context 'on Debian platforms' do
|
|
|
|
let :facts do
|
2015-11-02 19:25:12 +03:00
|
|
|
@default_facts.merge(test_facts.merge({
|
2018-09-27 22:09:00 +05:30
|
|
|
:osfamily => 'Debian',
|
|
|
|
:os => { :name => 'Debian', :family => 'Debian', :release => { :major => '8', :minor => '0' } },
|
2015-11-02 19:25:12 +03:00
|
|
|
}))
|
2014-02-27 14:08:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
let :platform_params do
|
|
|
|
{ :metering_agent_package => 'neutron-metering-agent',
|
|
|
|
:metering_agent_service => 'neutron-metering-agent' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_configures 'neutron metering agent'
|
2015-07-07 16:57:14 -06:00
|
|
|
it 'configures subscription to neutron-metering-agent package' do
|
2016-05-17 12:08:58 +00:00
|
|
|
is_expected.to contain_service('neutron-metering-service').that_subscribes_to('Anchor[neutron::service::begin]')
|
|
|
|
is_expected.to contain_service('neutron-metering-service').that_notifies('Anchor[neutron::service::end]')
|
2015-07-07 16:57:14 -06:00
|
|
|
end
|
2014-02-27 14:08:18 +01:00
|
|
|
end
|
|
|
|
|
2013-11-21 23:33:09 +01:00
|
|
|
context 'on RedHat platforms' do
|
|
|
|
let :facts do
|
2015-11-02 19:25:12 +03:00
|
|
|
@default_facts.merge(test_facts.merge({
|
|
|
|
:osfamily => 'RedHat',
|
2018-09-27 22:09:00 +05:30
|
|
|
:operatingsystemrelease => '7',
|
|
|
|
:os => { :name => 'CentOS', :family => 'RedHat', :release => { :major => '7', :minor => '0' } },
|
2015-11-02 19:25:12 +03:00
|
|
|
}))
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
let :platform_params do
|
2014-04-30 15:00:25 -07:00
|
|
|
{ :metering_agent_package => 'openstack-neutron-metering-agent',
|
|
|
|
:metering_agent_service => 'neutron-metering-agent' }
|
2013-11-21 23:33:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it_configures 'neutron metering agent'
|
|
|
|
end
|
|
|
|
end
|