Name changes for the agent package.

Added initial ChefSpec files

Change-Id: I7ee471dfef4e592672046e0543727216cf664a82
This commit is contained in:
gary-hessler 2014-07-18 15:37:03 -06:00
parent 0058373a3d
commit f0979a143a
10 changed files with 131 additions and 42 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.project
Berksfile.lock

View File

@ -1,23 +1,23 @@
cookbooks-mon-agent
cookbooks-monasca-agent
===================
# Overview
This cookbook installs and configures the [Monitoring Agent](https://github.com/hpcloud-mon/mon-agent)
This cookbook installs and configures the [Monasca Monitoring Agent](https://github.com/stackforge/monasca-agent)
# Data Bags
For use with configuration, the `mon_agent` data bag contains parameters
For use with configuration, the `monasca_agent` data bag contains parameters
for interfacing with the Monitoring API, global dimensions (a set of
comma-delimited name:value pairs to be included in the Agent metrics),
and logging levels.
## Example
{
"id": "mon_agent",
"id": "monasca_agent",
"keystone_url": "http://192.168.10.4:5000/v2.0",
"username": "joe_user",
"password": "correcthorsebatterystaple",
"project_name": "worldpeace",
"mon_api_url": "http://192.168.10.4:8080/v2.0",
"monasca_api_url": "http://192.168.10.4:8080/v2.0",
"service": "mini-mon"
}
@ -27,23 +27,23 @@ and logging levels.
The default recipe sets up the Monitoring Agent and runs mon-setup to configure.
## plugin_cfg
mon-agent plugins are configured in `/etc/mon-agent/conf.d/` as YAML files ending
monasca-agent plugins are configured in `/etc/monasca-agent/conf.d/` as YAML files ending
in .yaml which are created by this recipe. The Agent will walk through these
files when the Collector (`/usr/local/bin/mon-collector`) starts. The name of
the file must match a Python plugin in `/etc/mon-agent/checks.d/` or
files when the Collector (`/usr/local/bin/monasca-collector`) starts. The name of
the file must match a Python plugin in `/etc/monasca-agent/checks.d/` or
`/usr/local/lib/python2.7/dist-packages/monagent/collector/checks_d/`
- `conf.d/` file: `process.yaml`
- `checks_d/` file: `process.py`
- data bag item: `node.default[:mon_agent][:plugin][:process]`
- data bag item: `node.default[:monasca_agent][:plugin][:process]`
The .yaml files are comprised of two different sections, `init_config`
containing global configuration parameters, and 'instances' containing one or
more stanzas containing details about the particular check to run. These are
defined in
`node.default[:mon_agent][:plugin][:process][:init_config]`
`node.default[:monasca_agent][:plugin][:process][:init_config]`
and
`node.default[:mon_agent][:plugin][:process][:instances]`
`node.default[:monasca_agent][:plugin][:process][:instances]`
respectively.
The `nagios_wrapper` is a special case in the `plugin_cfg` recipe in that
@ -55,8 +55,8 @@ installed to provide many standard Nagios plugins.
These are global attributes for use with the agent.conf file and installation
settings.
With the case of dimensions, `default['mon-agent']['dimensions'] = nil` appends
to the list of dimensions, if any, specified in the `mon_agent` data bag.
With the case of dimensions, `default['monasca-agent']['dimensions'] = nil` appends
to the list of dimensions, if any, specified in the `monasca_agent` data bag.
## network
These attributes configure the network plugin.
@ -64,11 +64,11 @@ These attributes configure the network plugin.
## plugin_config_basenode
These attributes configure a basic set of plugins to be installed on every instance.
These are in addition to the Monitoring Agent's existing set of basic metrics, listed
on the [mon-agent wiki](https://github.com/hpcloud-mon/mon-agent/wiki/mon-agent-User-Guide#standard-set-of-dimensions)
on the [monasca-agent wiki](https://github.com/hpcloud-mon/mon-agent/wiki/mon-agent-User-Guide#standard-set-of-dimensions)
# Templates
## agent.conf.erb
This is the primary configuration file for the Agent, in `/etc/mon-agent/agent.conf`
This is the primary configuration file for the Agent, in `/etc/monasca-agent/agent.conf`
## plugin_yaml.erb
This template provides the basis for plugin .yaml configuration files.

View File

@ -1,4 +1,4 @@
# encoding: UTF-8#
#
default[:mon_agent][:data_bag] = 'mon_agent'
default[:mon_agent][:plugin] = {}
default[:monasca_agent][:data_bag] = 'monasca_agent'
default[:monasca_agent][:plugin] = {}

View File

@ -1,10 +1,10 @@
# encoding: UTF-8#
#
name 'mon_agent'
maintainer 'HP_Cloud_Monitoring'
maintainer_email 'hpcs-mon@hp.com'
description 'Installs/Configures mon-agent components'
name 'monasca_agent'
maintainer 'monasca'
maintainer_email 'monasca@lists.launchpad.net'
description 'Installs/Configures monasca-agent components'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.1.2'
version '1.1.3'
depends 'python'
recipe 'mon_api::default', 'Default'

View File

@ -9,15 +9,15 @@ include_recipe 'python'
end
end
settings = data_bag_item(node[:mon_agent][:data_bag], 'mon_agent')
execute 'mon-setup' do
settings = data_bag_item(node[:monasca_agent][:data_bag], 'monasca_agent')
execute 'monasca-setup' do
action :nothing
command "/usr/local/bin/mon-setup -u #{settings['username']} -p #{settings['password']} -s #{settings['service']} --keystone_url #{settings['keystone_url']} --project_name #{settings['project_name']} --mon_url #{settings['mon_api_url']}"
command "/usr/local/bin/monasca-setup -u #{settings['username']} -p #{settings['password']} -s #{settings['service']} --keystone_url #{settings['keystone_url']} --project_name #{settings['project_name']} --monasca_url #{settings['monasca_api_url']}"
end
python_pip 'mon-agent' do
python_pip 'monasca-agent' do
action :install
notifies :run, 'execute[mon-setup]'
notifies :run, 'execute[monasca-setup]'
end
include_recipe 'mon_agent::plugin_cfg'
include_recipe 'monasca_agent::plugin_cfg'

View File

@ -1,31 +1,31 @@
# encoding: UTF-8#
#
# Cookbook Name:: mon_agent
# Cookbook Name:: monasca_agent
# Recipe:: plugin_cfg
#
# Load nagios-plugins package if it's needed
package 'nagios-plugins-basic' do
action :install
only_if { node[:mon_agent][:plugin].key?(:nagios_wrapper) }
only_if { node[:monasca_agent][:plugin].key?(:nagios_wrapper) }
end
# Configures the plugin yaml files based on node[:mon_agent][:plugin]
# Configures the plugin yaml files based on node[:monasca_agent][:plugin]
# attributes
node[:mon_agent][:plugin].each_key do |plugin|
unless node[:mon_agent][:plugin][plugin].key?(:init_config)
node.normal[:mon_agent][:plugin][plugin][:init_config] = {}
node[:monasca_agent][:plugin].each_key do |plugin|
unless node[:monasca_agent][:plugin][plugin].key?(:init_config)
node.normal[:monasca_agent][:plugin][plugin][:init_config] = {}
end
template "/etc/mon-agent/conf.d/#{plugin}.yaml" do
template "/etc/monasca-agent/conf.d/#{plugin}.yaml" do
source 'plugin_yaml.erb'
action :create
owner node[:mon_agent][:owner]
group node[:mon_agent][:group]
owner node[:monasca_agent][:owner]
group node[:monasca_agent][:group]
mode 0644
variables(
init_config: node[:mon_agent][:plugin][plugin][:init_config],
instances: node[:mon_agent][:plugin][plugin][:instances]
init_config: node[:monasca_agent][:plugin][plugin][:init_config],
instances: node[:monasca_agent][:plugin][plugin][:instances]
)
notifies :run, 'execute[mon-setup]'
notifies :run, 'execute[monasca-setup]'
end
end

39
spec/default_spec.rb Normal file
View File

@ -0,0 +1,39 @@
# Encoding: utf-8
require_relative 'spec_helper'
def nothing_execute(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:execute, :nothing, resource_name)
end
describe 'monasca_agent::default' do
describe 'ubuntu' do
include_context 'monasca_stubs'
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['monasca']['data_bag'] = 'monasca_agent'
runner.converge(described_recipe)
end
it 'includes the other recipes' do
expect(chef_run).to include_recipe('python')
expect(chef_run).to include_recipe('monasca_agent::plugin_cfg')
end
%w(python-pymongo python-yaml supervisor sysstat).each do |pkg|
it "installs package #{pkg}" do
expect(chef_run).to install_package pkg
end
end
it 'python_pip installs monasca-agent' do
expect(chef_run).to install_python_pip 'monasca-agent'
end
it 'executes the monasca-setup program' do
execute = chef_run.execute('monasca-setup')
expect(execute).to do_nothing
end
end
end

View File

@ -1,2 +0,0 @@
# encoding: UTF-8
# No unit tests at this time.

14
spec/plugin_cfg_spec.rb Normal file
View File

@ -0,0 +1,14 @@
# Encoding: utf-8
require_relative 'spec_helper'
describe 'monasca_agent::plugin_cfg' do
describe 'ubuntu' do
include_context 'monasca_stubs'
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) do
node.set['monasca_agent']['plugin'] = 'monasca_agent'
runner.converge(described_recipe)
end
end
end

36
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,36 @@
# encoding: UTF-8
require 'chefspec'
require 'chefspec/berkshelf'
ChefSpec::Coverage.start! { add_filter 'monasca_agent' }
require 'chef/application'
LOG_LEVEL = :fatal
SUSE_OPTS = {
platform: 'suse',
version: '11.3',
log_level: ::LOG_LEVEL
}
REDHAT_OPTS = {
platform: 'redhat',
version: '6.5',
log_level: ::LOG_LEVEL
}
UBUNTU_OPTS = {
platform: 'ubuntu',
version: '12.04',
log_level: ::LOG_LEVEL
}
shared_context 'monasca_stubs' do
before do
stub_data_bag_item('monasca_agent', 'monasca_agent').and_return(
'keystone_url' => 'http://192.168.10.5:35357/v3',
'username' => 'mini-mon',
'password' => 'password',
'project_name' => 'mini-mon',
'monasca_api_url' => 'http://192.168.10.4:8080/v2.0',
'service' => 'mini-mon')
end
end