Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Python version to determine if base package should be installed #65

Closed
wants to merge 7 commits into from
@@ -41,6 +41,14 @@
# Agent Version
default['datadog']['agent_version'] = nil

# Set to true to always install datadog-agent-base (usually only installed on
# systems with a version of Python lower than 2.6) instead of datadog-agent
begin
default['datadog']['install_base'] = Gem::Version.new(node['languages']['python']['version']) < Gem::Version.new('2.6.0')
rescue NoMethodError # nodes['languages']['python'] == nil
Chef::Log.warn 'no version of python found'
end

# Boolean to enable debug_mode, which outputs massive amounts of log messages
# to the /tmp/ directory.
default['datadog']['debug'] = false
@@ -17,7 +17,7 @@
supports os
end

depends "apt"
depends "apt", "< 2.0.0"
depends "chef_handler", "~> 1.1.0"
depends "yum"

@@ -22,8 +22,7 @@
include_recipe "datadog::repository"
end

case node['platform_family']
when "debian"
if node['platform_family'] == 'debian'
# Thanks to @joepcds for the Ubuntu 11.04 fix
# setuptools has been packaged with a bug
# https://bugs.launchpad.net/ubuntu/+source/supervisor/+bug/777862
@@ -38,28 +37,15 @@
notifies :run, "execute[apt-get update]", :immediately
not_if "apt-cache search datadog-agent | grep datadog-agent"
end
end

# datadog-agent requires python2.6, not available on LTS till 10.04
if (node['platform'] == "ubuntu") and (node['platform_version'].to_f <= 8.04)
package "datadog-agent-base" do
version node['datadog']['agent_version']
end
else
package "datadog-agent" do
version node['datadog']['agent_version']
end
if node['datadog']['install_base']
package "datadog-agent-base" do
version node['datadog']['agent_version']
end

when "rhel"
# datadog-agent requires python2.6, not available on RH5 by default
if node['platform_version'].to_i <= 5
package "datadog-agent-base" do
version node['datadog']['agent_version']
end
elsif node['platform_version'].to_i >= 6
package "datadog-agent" do
version node['datadog']['agent_version']
end
else
package "datadog-agent" do
version node['datadog']['agent_version']
end
end

@@ -1,37 +1,85 @@
require 'spec_helper'

shared_examples_for 'datadog-agent' do
it 'installs the datadog-agent' do
expect(@chef_run).to install_package 'datadog-agent'
end

it 'does not install the datadog-agent-base package' do
expect(@chef_run).not_to install_package 'datadog-agent-base'
end

it 'enables the datadog-agent service' do
expect(@chef_run).to set_service_to_start_on_boot 'datadog-agent'
end

it 'ensures the dd-agent directory exists' do
expect(@chef_run).to create_directory '/etc/dd-agent'
end

it 'drops an agent config file' do
expect(@chef_run).to create_file '/etc/dd-agent/datadog.conf'
end
end

shared_examples_for 'datadog-agent-base' do
it 'installs the datadog-agent-base package' do
expect(@chef_run).to install_package 'datadog-agent-base'
end

it 'does not install the datadog-agent package' do
expect(@chef_run).not_to install_package 'datadog-agent'
end

it 'enables the datadog-agent service' do
expect(@chef_run).to set_service_to_start_on_boot 'datadog-agent'
end

it 'ensures the dd-agent directory exists' do
expect(@chef_run).to create_directory '/etc/dd-agent'
end

it 'drops an agent config file' do
expect(@chef_run).to create_file '/etc/dd-agent/datadog.conf'
end
end



describe 'datadog::dd-agent' do

# This recipe needs to have an api_key, otherwise `raise` is called.
# It also depends on specific platofrm versions for software install
# It also depends on the version of Python present on the platform:
# 2.6 and up => datadog-agent is installed
# below 2.6 => datadog-agent-base is installed
context 'when using a debian-family distro' do

before(:all) do
@chef_run = ChefSpec::ChefRunner.new(
:platform => 'ubuntu',
:version => '12.04'
) do |node|
node.set['datadog'] = {
'api_key' => "somethingnotnil"
}
node.set['datadog'] = { 'api_key' => 'somethingnotnil' }
node.set['languages'] = { 'python' => { 'version' => '2.6.2' } }
end.converge('datadog::dd-agent')
end

it 'installs the datadog-agent' do
expect(@chef_run).to install_package 'datadog-agent'
end
it_behaves_like 'datadog-agent'
end

it 'enables the datadog-agent service' do
expect(@chef_run).to set_service_to_start_on_boot 'datadog-agent'
end
context 'when using a debian-family distro and installing base' do

it 'ensures the dd-agent directory exists' do
expect(@chef_run).to create_directory '/etc/dd-agent'
before(:all) do
@chef_run = ChefSpec::ChefRunner.new(
:platform => 'ubuntu',
:version => '12.04'
) do |node|
node.set['datadog'] = { 'api_key' => 'somethingnotnil' }
node.set['languages'] = { 'python' => { 'version' => '2.4' } }
end.converge('datadog::dd-agent')
end

it 'drops an agent config file' do
expect(@chef_run).to create_file '/etc/dd-agent/datadog.conf'
end
it_behaves_like 'datadog-agent-base'
end

context 'when using a redhat-family distro above 6.x' do
@@ -41,28 +89,27 @@
:platform => 'centos',
:version => '6.3'
) do |node|
node.set['datadog'] = {
'api_key' => "somethingnotnil"
}
node.set['datadog'] = { 'api_key' => 'somethingnotnil' }
node.set['languages'] = { 'python' => { 'version' => '2.6.2' } }
end.converge('datadog::dd-agent')
end

it 'installs the datadog-agent package' do
expect(@chef_run).to install_package 'datadog-agent'
end

it 'does not install the datadog-agent-base package' do
expect(@chef_run).not_to install_package 'datadog-agent-base'
end
it_behaves_like 'datadog-agent'
end

it 'enables the datadog-agent service' do
expect(@chef_run).to set_service_to_start_on_boot 'datadog-agent'
end
context 'when using a redhat-family distro above 6.x and installing base' do

This comment has been minimized.

Copy link
@miketheman

miketheman Jul 16, 2013

Collaborator

This could probably change to be more like a CentOS 5.9, which has python 2.4.3. This is the general use case, and should be reflected in the kitchen.yml config.


it 'creates a configuration file' do
expect(@chef_run).to create_file '/etc/dd-agent/datadog.conf'
before(:all) do
@chef_run = ChefSpec::ChefRunner.new(
:platform => 'centos',
:version => '6.3'

This comment has been minimized.

Copy link
@miketheman

miketheman Jul 16, 2013

Collaborator

as well as here. Fauxhai has 5.8, not 5.9. https://github.com/customink/fauxhai/blob/master/lib/fauxhai/platforms/centos/5.8.json The differences would be minimal enough for our purposes.

) do |node|
node.set['datadog'] = { 'api_key' => 'somethingnotnil' }
node.set['languages'] = { 'python' => { 'version' => '2.4' } }
end.converge('datadog::dd-agent')
end

it_behaves_like 'datadog-agent-base'
end

end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.