From 54a2e4b4b96cbf5207bf343127d691ff8be06fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 9 Feb 2016 00:20:25 -0800 Subject: [PATCH] Make changes to lma_collector::collectd::mysql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is related to the usage and documentation of the lma_collector::collectd::mysql class. The following changes are made: 1. Make the "username" and "password" parameters required. Today they default to the empty string, which doesn't make much sense. 2. Change the internal resource name from "nova" to "config". The name "nova" was confusing as the collection of MySQL statistics is unrelated to Nova. With this change the generated collectd configuration file is named "mysql-config.conf", which makes more sense than "mysql-nova.conf" and is consistent with other collectd config file names we have (e.g. "python-config.conf"). 3. Add a unit test for the class. 4. Adjust the documentation. Change-Id: I281c28d9f4da7ae728615041e175845ad5829b34 --- .../puppet/manifests/controller.pp | 1 - .../puppet/modules/lma_collector/README.md | 16 +++++----- .../lma_collector/manifests/collectd/mysql.pp | 9 +++--- .../modules/lma_collector/manifests/params.pp | 3 -- .../lma_collector_collectd_mysql_spec.rb | 31 +++++++++++++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 deployment_scripts/puppet/modules/lma_collector/spec/classes/lma_collector_collectd_mysql_spec.rb diff --git a/deployment_scripts/puppet/manifests/controller.pp b/deployment_scripts/puppet/manifests/controller.pp index 7161a802c..9594d9913 100644 --- a/deployment_scripts/puppet/manifests/controller.pp +++ b/deployment_scripts/puppet/manifests/controller.pp @@ -301,7 +301,6 @@ if $lma_collector['influxdb_mode'] != 'disabled' { } class { 'lma_collector::collectd::mysql': - database => 'nova', username => 'nova', password => $nova['db_password'], } diff --git a/deployment_scripts/puppet/modules/lma_collector/README.md b/deployment_scripts/puppet/modules/lma_collector/README.md index 60232806a..78f0da5c3 100644 --- a/deployment_scripts/puppet/modules/lma_collector/README.md +++ b/deployment_scripts/puppet/modules/lma_collector/README.md @@ -325,7 +325,10 @@ To make the collector collect statistics for MySQL declare the `lma_collector::collectd::mysql` class: ```puppet -class { 'lma_collector::collectd::mysql': } +class { 'lma_collector::collectd::mysql': + username => 'mysql_username', + password => 'mysql_password', +} ``` ### Collect OpenStack notifications @@ -650,17 +653,16 @@ which uses Pacemaker's `crm_resource` command to get statistics from Pacemaker. #### Class: `lma_collector::collectd::mysql` -Declare this class to configure collectd to collect statistics for MySQL. +Declare this class to configure collectd to collect statistics for the MySQL +instance local to the node. The collectd plugin used is the native collectd [MySQL -plugin](https://collectd.org/wiki/index.php/Plugin:MySQL). +plugin](https://collectd.org/wiki/index.php/Plugin:MySQL). It is configured +with `'localhost'` as the `Host`, meaning that the local MySQL Unix socket will +be used to connect to MySQL. ##### Parameters -* `host`: *Optional*. The host onto which the MySQL database runs. Valid - options: a string. Default: `'127.0.0.1'`. -* `port`: *Optional*. The port the MySQL database listens on. Valid options: an - integer. Default: `3306`. * `username`: *Required*. The database user to use to connect to the MySQL database. Valid options: a string. * `password`: *Required*. The database password to use to connect to the MySQL diff --git a/deployment_scripts/puppet/modules/lma_collector/manifests/collectd/mysql.pp b/deployment_scripts/puppet/modules/lma_collector/manifests/collectd/mysql.pp index bddb38542..eed00f7e9 100644 --- a/deployment_scripts/puppet/modules/lma_collector/manifests/collectd/mysql.pp +++ b/deployment_scripts/puppet/modules/lma_collector/manifests/collectd/mysql.pp @@ -13,12 +13,13 @@ # under the License. # class lma_collector::collectd::mysql ( - $database = $lma_collector::params::mysql_database, - $username = $lma_collector::params::mysql_username, - $password = $lma_collector::params::mysql_password, + $username, + $password, ) inherits lma_collector::params { - collectd::plugin::mysql::database { $database: + # With "config" as the resource title the collectd configuration + # file will be named "mysql-config.conf". + collectd::plugin::mysql::database { 'config': host => 'localhost', username => $username, password => $password, diff --git a/deployment_scripts/puppet/modules/lma_collector/manifests/params.pp b/deployment_scripts/puppet/modules/lma_collector/manifests/params.pp index d4b59450c..02c6edd12 100644 --- a/deployment_scripts/puppet/modules/lma_collector/manifests/params.pp +++ b/deployment_scripts/puppet/modules/lma_collector/manifests/params.pp @@ -106,9 +106,6 @@ class lma_collector::params { } } $additional_packages = [ 'python-dateutil' ] - $mysql_database = '' - $mysql_username = '' - $mysql_password = '' $openstack_user = '' $openstack_password = '' $openstack_tenant = '' diff --git a/deployment_scripts/puppet/modules/lma_collector/spec/classes/lma_collector_collectd_mysql_spec.rb b/deployment_scripts/puppet/modules/lma_collector/spec/classes/lma_collector_collectd_mysql_spec.rb new file mode 100644 index 000000000..4a647d7c3 --- /dev/null +++ b/deployment_scripts/puppet/modules/lma_collector/spec/classes/lma_collector_collectd_mysql_spec.rb @@ -0,0 +1,31 @@ +# Copyright 2016 Mirantis, 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 'lma_collector::collectd::mysql' do + let(:facts) do + {:kernel => 'Linux', :operatingsystem => 'Ubuntu', + :osfamily => 'Debian', :concat_basedir => '/foo'} + end + + describe 'with params' do + let(:params) do + {:username => 'user', :password => 'password'} + end + it { is_expected.to contain_collectd__plugin__mysql__database('config') \ + .with_host('localhost') \ + .with_username('user') \ + .with_password('password') } + end +end