diff --git a/README.md b/README.md index adc7f12..0402c00 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ monasca is a combination of Puppet manifest that configures the monasca client a #### monasca_config -The `monasca_config` provider is a children of the ini_setting provider. It allows one to write an entry in the `/etc/monasca/monasca.conf` file. +The `monasca_config` provider is a child of the ini_setting provider. It allows one to write an entry in the `/etc/monasca/monasca.conf` file. ```puppet monasca_config { 'DEFAULT/debug' : diff --git a/manifests/checks/ovs.pp b/manifests/checks/ovs.pp index 9988618..9803eb1 100644 --- a/manifests/checks/ovs.pp +++ b/manifests/checks/ovs.pp @@ -27,6 +27,13 @@ # (Optional) Cache directory to persist data. # Defaults to /dev/shm. # +# [*metadata*] +# (Optional) A list of router metadata to be submitted as dimensions +# with service data. For example, 'tenant_name' in the list will +# add the tenant name dimension to router metrics posted to the +# infrastructure project. +# Defaults to an empty list in the config file. +# # [*neutron_refresh*] # (Optional) Interval to force data refresh from neutron. # Defaults to 14400 seconds (4 hours).. @@ -67,6 +74,7 @@ class monasca::checks::ovs( $check_router_ha = true, $identity_uri = undef, $included_interface_re = 'qg.*', + $metadata = [], $network_use_bits = true, $neutron_refresh = '14400', $ovs_cmd = 'sudo /usr/bin/ovs-vsctl', diff --git a/spec/classes/monasca_checks_ovs_spec.rb b/spec/classes/monasca_checks_ovs_spec.rb new file mode 100644 index 0000000..c716295 --- /dev/null +++ b/spec/classes/monasca_checks_ovs_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'monasca::checks::ovs' do + describe 'on debian platforms' do + let :facts do + @default_facts.merge({ + :osfamily => 'Debian', + }) + end + + let :ovs_file do + "/etc/monasca/agent/conf.d/ovs.yaml" + end + + let :pre_condition do + "class { 'monasca::agent': + url => 'http://127.0.0.1', + username => 'user', + password => 'password', + keystone_url => 'http://127.0.0.1:5000', + install_python_deps => false, + }" + end + + let(:params) { { + :admin_password => 'password', + :admin_tenant_name => 'tenant_name', + :admin_user => 'user', + :identity_uri => 'uri', + :metadata => ['tenant_name'], + } } + + it 'builds the ovs config file properly' do + is_expected.to contain_file(ovs_file).with_content(/^\s*admin_password: password$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*admin_tenant_name: tenant_name$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*admin_user: user$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*cache_dir: \/dev\/shm$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*identity_uri: uri$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*network_use_bits: true$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*metadata: \["tenant_name"\]$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*neutron_refresh: 14400$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*ovs_cmd: 'sudo \/usr\/bin\/ovs-vsctl'$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*included_interface_re: qg\.\*$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*use_absolute_metrics: true$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*use_rate_metrics: true$/) + is_expected.to contain_file(ovs_file).with_content(/^\s*use_health_metrics: true$/) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 45654e7..a558483 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,12 @@ +# 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/facts' 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.default_facts = { :concat_basedir => '/var/lib/puppet/concat' } end + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/templates/checks/ovs.yaml.erb b/templates/checks/ovs.yaml.erb index a0b84fb..6d7e6a8 100644 --- a/templates/checks/ovs.yaml.erb +++ b/templates/checks/ovs.yaml.erb @@ -6,6 +6,9 @@ init_config: cache_dir: <%= @cache_dir %> check_router_ha: <%= @check_router_ha %> identity_uri: <%= @identity_uri %> +<%- if @metadata -%> + metadata: <%= @metadata %> +<%- end -%> network_use_bits: <%= @network_use_bits %> neutron_refresh: <%= @neutron_refresh %> ovs_cmd: '<%= @ovs_cmd %>' diff --git a/templates/monasca-agent.init.erb b/templates/monasca-agent.init.erb index 9493767..b7cf55e 100755 --- a/templates/monasca-agent.init.erb +++ b/templates/monasca-agent.init.erb @@ -15,19 +15,19 @@ PATH=$PATH:/usr/local/bin # supervisord might live here PATH=$PATH:/sbin -AGENTPATH="<%= virtual_env %>/bin/monasca-collector" -AGENTCONF="<%= agent_dir %>/agent.yaml" -MONASCASTATSDPATH="<%= virtual_env %>/bin/monasca-statsd" -AGENTUSER="<%= agent_user %>" -FORWARDERPATH="<%= virtual_env %>/bin/monasca-forwarder" +AGENTPATH="<%= @virtual_env %>/bin/monasca-collector" +AGENTCONF="<%= @agent_dir %>/agent.yaml" +MONASCASTATSDPATH="<%= @virtual_env %>/bin/monasca-statsd" +AGENTUSER="<%= @agent_user %>" +FORWARDERPATH="<%= @virtual_env %>/bin/monasca-forwarder" NAME="monasca-agent" DESC="Monasca Monitoring Agent" AGENT_PID_PATH="/var/tmp/monasca-agent.pid" SUPERVISOR_PIDFILE="/var/tmp/monasca-agent-supervisord.pid" -SUPERVISOR_FILE="<%= agent_dir %>/supervisor.conf" +SUPERVISOR_FILE="<%= @agent_dir %>/supervisor.conf" SUPERVISOR_SOCK="/var/tmp/monasca-agent-supervisor.sock" -SUPERVISORD="<%= virtual_env %>/bin/supervisord" -SUPERVISORCTL="<%= virtual_env %>/bin/supervisorctl" +SUPERVISORD="<%= @virtual_env %>/bin/supervisord" +SUPERVISORCTL="<%= @virtual_env %>/bin/supervisorctl" # This script is considered a configuration file and will not be # removed by dpkg unless the --purge option it set. Therefore we diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb index bf6d0f5..339af43 100644 --- a/templates/supervisor.conf.erb +++ b/templates/supervisor.conf.erb @@ -11,37 +11,37 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface minfds = 1024 minprocs = 200 loglevel = info -logfile = <%= log_dir %>/supervisord.log +logfile = <%= @log_dir %>/supervisord.log logfile_maxbytes = 50MB nodaemon = false pidfile = /var/run/monasca-agent-supervisord.pid logfile_backups = 10 [program:collector] -command=<%= virtual_env %>/bin/monasca-collector foreground +command=<%= @virtual_env %>/bin/monasca-collector foreground stdout_logfile=NONE stderr_logfile=NONE priority=999 startsecs=2 -user=<%= agent_user %> +user=<%= @agent_user %> autorestart=true [program:forwarder] -command=<%= virtual_env %>/bin/monasca-forwarder +command=<%= @virtual_env %>/bin/monasca-forwarder stdout_logfile=NONE stderr_logfile=NONE startsecs=3 priority=998 -user=<%= agent_user %> +user=<%= @agent_user %> autorestart=true [program:statsd] -command=<%= virtual_env %>/bin/monasca-statsd +command=<%= @virtual_env %>/bin/monasca-statsd stdout_logfile=NONE stderr_logfile=NONE startsecs=3 priority=998 -user=<%= agent_user %> +user=<%= @agent_user %> autorestart=true [group:monasca-agent]