Skip to content

Commit

Permalink
[powerdns_recursor] integration tests
Browse files Browse the repository at this point in the history
Build from source (:broken_heart:) and then test.
  • Loading branch information
degemer committed May 13, 2016
1 parent ca7a6aa commit 2298a51
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -71,6 +71,7 @@ env:
- TRAVIS_FLAVOR=postgres FLAVOR_VERSION=9.2.10
- TRAVIS_FLAVOR=postgres FLAVOR_VERSION=9.3.6
- TRAVIS_FLAVOR=postgres FLAVOR_VERSION=9.4.1
- TRAVIS_FLAVOR=powerdns_recursor
- TRAVIS_FLAVOR=rabbitmq
- TRAVIS_FLAVOR=redis FLAVOR_VERSION=2.4.18
- TRAVIS_FLAVOR=redis FLAVOR_VERSION=2.6.17
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -28,6 +28,7 @@ require './ci/nginx'
require './ci/pgbouncer'
require './ci/phpfpm'
require './ci/postgres'
require './ci/powerdns_recursor'
require './ci/rabbitmq'
require './ci/redis'
require './ci/riak'
Expand Down
87 changes: 87 additions & 0 deletions ci/powerdns_recursor.rb
@@ -0,0 +1,87 @@
# (C) Datadog, Inc. 2010-2016
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)

require './ci/common'

def powerdns_recursor_version
ENV['FLAVOR_VERSION'] || '3.7.3'
end

def powerdns_recursor_rootdir
"#{ENV['INTEGRATIONS_DIR']}/powerdns_recursor_#{powerdns_recursor_version}"
end

def boost_version
'1_55_0'
end

namespace :ci do
namespace :powerdns_recursor do |flavor|
task before_install: ['ci:common:before_install']

task install: ['ci:common:install'] do
unless Dir.exist? File.expand_path(File.join(powerdns_recursor_rootdir), 'pdns_recursor')
# Downloads
# https://downloads.powerdns.com/releases/pdns-recursor-{powerdns_recursor_version}.tar.bz2
# http://downloads.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.tar.bz2
sh %(curl -s -L\
-o $VOLATILE_DIR/powerdns_recursor-#{powerdns_recursor_version}.tar.bz2\
https://s3.amazonaws.com/dd-agent-tarball-mirror/pdns-recursor-#{powerdns_recursor_version}.tar.bz2)
sh %(mkdir -p #{powerdns_recursor_rootdir})
sh %(tar xf $VOLATILE_DIR/powerdns_recursor-#{powerdns_recursor_version}.tar.bz2\
-C #{powerdns_recursor_rootdir} --strip-components=1)
sh %(curl -s -L\
-o $VOLATILE_DIR/boost_#{boost_version}.tar.bz2\
https://s3.amazonaws.com/dd-agent-tarball-mirror/boost_#{boost_version}.tar.bz2)
sh %(tar xf $VOLATILE_DIR/boost_#{boost_version}.tar.bz2\
-C #{powerdns_recursor_rootdir} --strip-components=1)
ENV['CPATH'] = powerdns_recursor_rootdir
sh %(cd #{powerdns_recursor_rootdir} && ./configure)
sh %(cd #{powerdns_recursor_rootdir} && make || echo "make didn't succeed")
end
end

task before_script: ['ci:common:before_script'] do
sh %(#{powerdns_recursor_rootdir}/pdns_recursor\
--config-dir=tests/checks/fixtures/powerdns-recursor/\
--socket-dir=#{powerdns_recursor_rootdir})
Wait.for 5353, 5
end

task script: ['ci:common:script'] do
this_provides = [
'powerdns_recursor'
]
Rake::Task['ci:common:run_tests'].invoke(this_provides)
end

task cleanup: ['ci:common:cleanup'] do
sh %(kill `cat #{powerdns_recursor_rootdir}/pdns_recursor.pid` || echo 'Already dead')
end

task before_cache: ['ci:common:before_cache']

task cache: ['ci:common:cache']

task :execute do
exception = nil
begin
%w(before_install install before_script
script before_cache cache).each do |t|
Rake::Task["#{flavor.scope.path}:#{t}"].invoke
end
rescue => e
exception = e
puts "Failed task: #{e.class} #{e.message}".red
end
if ENV['SKIP_CLEANUP']
puts 'Skipping cleanup, disposable environments are great'.yellow
else
puts 'Cleaning up'
Rake::Task["#{flavor.scope.path}:cleanup"].invoke
end
raise exception if exception
end
end
end
6 changes: 6 additions & 0 deletions tests/checks/fixtures/powerdns-recursor/recursor.conf
@@ -0,0 +1,6 @@
local-port=5353

experimental-webserver=on
experimental-webserver-address=127.0.0.1
experimental-webserver-port=8082
experimental-api-key=pdns_api_key
105 changes: 105 additions & 0 deletions tests/checks/integration/test_powerdns_recursor.py
@@ -0,0 +1,105 @@
# 3p
from nose.plugins.attrib import attr

# project
from tests.checks.common import AgentCheckTest


@attr(requires='powerdns_recursor')
class TestPowerDNSRecursorCheck(AgentCheckTest):
CHECK_NAME = 'powerdns_recursor'

GAUGE_METRICS = [
'cache-entries',
'concurrent-queries',
]
RATE_METRICS = [
'all-outqueries',
'answers-slow',
'answers0-1',
'answers1-10',
'answers10-100',
'answers100-1000',
'cache-hits',
'cache-misses',
'noerror-answers',
'outgoing-timeouts',
'questions',
'servfail-answers',
'tcp-outqueries',
'tcp-questions',
]

METRIC_FORMAT = 'powerdns.recursor.{}'

def __init__(self, *args, **kwargs):
AgentCheckTest.__init__(self, *args, **kwargs)
self.config = {"instances": [{
"host": "127.0.0.1",
"port": "8082",
"api_key": "pdns_api_key"
}]}

# Really a basic check to see if all metrics are there
def test_check(self):
self.run_check_twice(self.config)

# Assert metrics
for metric in self.GAUGE_METRICS:
self.assertMetric(self.METRIC_FORMAT.format(metric), tags=[])

for metric in self.RATE_METRICS:
self.assertMetric(self.METRIC_FORMAT.format(metric), tags=[])

service_check_tags = ['recursor_host:127.0.0.1', 'recursor_port:8082']
self.assertServiceCheckOK('powerdns.recursor.can_connect', tags=service_check_tags)

self.coverage_report()

def test_tags(self):
config = self.config.copy()
tags = ['foo:bar']
config['instances'][0]['tags'] = ['foo:bar']
self.run_check_twice(config)

# Assert metrics
for metric in self.GAUGE_METRICS:
self.assertMetric(self.METRIC_FORMAT.format(metric), tags=tags)

for metric in self.RATE_METRICS:
self.assertMetric(self.METRIC_FORMAT.format(metric), tags=tags)

service_check_tags = ['recursor_host:127.0.0.1', 'recursor_port:8082']
self.assertServiceCheckOK('powerdns.recursor.can_connect', tags=service_check_tags)

self.coverage_report()

def test_bad_config(self):
config = self.config.copy()
config['instances'][0]['port'] = 1111
service_check_tags = ['recursor_host:127.0.0.1', 'recursor_port:1111']
self.assertRaises(
Exception,
lambda: self.run_check(config)
)
self.assertServiceCheckCritical('powerdns.recursor.can_connect', tags=service_check_tags)
self.coverage_report()

def test_bad_api_key(self):
config = self.config.copy()
config['instances'][0]['api_key'] = 'nope'
service_check_tags = ['recursor_host:127.0.0.1', 'recursor_port:8082']
self.assertRaises(
Exception,
lambda: self.run_check(config)
)
self.assertServiceCheckCritical('powerdns.recursor.can_connect', tags=service_check_tags)
self.coverage_report()

def test_very_bad_config(self):
for config in [{}, {"host": "localhost"}, {"port": 1000}, {"host": "localhost", "port": 1000}]:
self.assertRaises(
Exception,
lambda: self.run_check({"instances": [config]})
)
self.coverage_report()

0 comments on commit 2298a51

Please sign in to comment.