From f0979a143a0c11246209c0ff63d67a0fdeab29d9 Mon Sep 17 00:00:00 2001 From: gary-hessler Date: Fri, 18 Jul 2014 15:37:03 -0600 Subject: [PATCH] Name changes for the agent package. Added initial ChefSpec files Change-Id: I7ee471dfef4e592672046e0543727216cf664a82 --- .gitignore | 2 ++ README.md | 30 +++++++++++++++--------------- attributes/default.rb | 4 ++-- metadata.rb | 10 +++++----- recipes/default.rb | 12 ++++++------ recipes/plugin_cfg.rb | 24 ++++++++++++------------ spec/default_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ spec/empty.rb | 2 -- spec/plugin_cfg_spec.rb | 14 ++++++++++++++ spec/spec_helper.rb | 36 ++++++++++++++++++++++++++++++++++++ 10 files changed, 131 insertions(+), 42 deletions(-) create mode 100644 .gitignore create mode 100644 spec/default_spec.rb delete mode 100644 spec/empty.rb create mode 100644 spec/plugin_cfg_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0dfbaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.project +Berksfile.lock diff --git a/README.md b/README.md index 988bc7f..805dca0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/attributes/default.rb b/attributes/default.rb index 99e592a..1a52917 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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] = {} diff --git a/metadata.rb b/metadata.rb index 2e521a7..8165c1c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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' diff --git a/recipes/default.rb b/recipes/default.rb index dda81ae..a3c4f90 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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' diff --git a/recipes/plugin_cfg.rb b/recipes/plugin_cfg.rb index 646c461..355a909 100644 --- a/recipes/plugin_cfg.rb +++ b/recipes/plugin_cfg.rb @@ -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 diff --git a/spec/default_spec.rb b/spec/default_spec.rb new file mode 100644 index 0000000..3126106 --- /dev/null +++ b/spec/default_spec.rb @@ -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 diff --git a/spec/empty.rb b/spec/empty.rb deleted file mode 100644 index fc2f6d6..0000000 --- a/spec/empty.rb +++ /dev/null @@ -1,2 +0,0 @@ -# encoding: UTF-8 -# No unit tests at this time. diff --git a/spec/plugin_cfg_spec.rb b/spec/plugin_cfg_spec.rb new file mode 100644 index 0000000..f1dd63e --- /dev/null +++ b/spec/plugin_cfg_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..76c6adf --- /dev/null +++ b/spec/spec_helper.rb @@ -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