Merge lp:~lazypower/charms/precise/nagios/amulet-tests into lp:charms/nagios

Proposed by Charles Butler
Status: Merged
Merged at revision: 11
Proposed branch: lp:~lazypower/charms/precise/nagios/amulet-tests
Merge into: lp:charms/nagios
Diff against target: 121 lines (+111/-0)
2 files modified
tests/00-setup (+5/-0)
tests/100-deploy (+106/-0)
To merge this branch: bzr merge lp:~lazypower/charms/precise/nagios/amulet-tests
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+211827@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Charles Butler (lazypower) wrote :

Reviewers: mp+211827_code.launchpad.net,

Message:
Please take a look.

Description:
Amulet Tests

https://code.launchpad.net/~lazypower/charms/precise/nagios/amulet-tests/+merge/211827

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/77940043/

Affected files (+113, -0 lines):
   A [revision details]
   A tests/00-setup
   A tests/100-deploy

12. By Charles Butler

Adds juju-local for lxc substrates

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'tests'
2=== added file 'tests/00-setup'
3--- tests/00-setup 1970-01-01 00:00:00 +0000
4+++ tests/00-setup 2014-03-19 22:05:28 +0000
5@@ -0,0 +1,5 @@
6+#!/bin/bash
7+
8+sudo add-apt-repository -y ppa:juju/stable
9+apt-get update
10+sudo apt-get install -y amulet juju-local python3-requests
11
12=== added file 'tests/100-deploy'
13--- tests/100-deploy 1970-01-01 00:00:00 +0000
14+++ tests/100-deploy 2014-03-19 22:05:28 +0000
15@@ -0,0 +1,106 @@
16+#!/usr/bin/python3
17+
18+#TODO - Discover what service mymonitors was designed for - as the charm store has nothing listed for this interface.
19+import amulet
20+import requests
21+
22+###
23+# Quick Config
24+###
25+seconds = 900
26+
27+
28+d = amulet.Deployment()
29+
30+d.add('haproxy')
31+d.add('nagios')
32+d.add('mysql')
33+d.add('nrpe')
34+
35+#TODO - configure nagios with SSL options in branch
36+# lp:~lazypower/charms/precise/nagios/ssl-everywhere
37+# pending lp #1293793
38+d.configure('nagios', {'extraconfig': '#amulet'})
39+d.configure('haproxy', {})
40+d.configure('mysql', {})
41+
42+d.relate('nagios:website', 'haproxy:reverseproxy')
43+d.relate('nagios:monitors', 'mysql:monitors')
44+d.relate('nrpe:general-info', 'haproxy:juju-info')
45+d.relate('nrpe:monitors', 'nagios:monitors')
46+
47+d.expose('nagios')
48+d.expose('haproxy')
49+
50+try:
51+ d.setup(timeout=seconds)
52+ #d.sentry.wait()
53+except amulet.helpers.TimeoutError:
54+ amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
55+except:
56+ raise
57+
58+
59+##
60+# Set relationship aliases
61+##
62+mysql_unit = d.sentry.unit['mysql/0']
63+nagios_unit = d.sentry.unit['nagios/0']
64+haproxy_unit = d.sentry.unit['haproxy/0']
65+
66+# Fetch nagios private address through the relation data
67+sql_paddr = d.sentry.unit['nagios/0'].relation('monitors', 'mysql:monitors')['private-address']
68+
69+
70+# Mysql has a nice built in monitoring relationship with nagios
71+# Validate that we get the proper tables setup
72+def test_mysql_monitoring_connection():
73+ validation_sql = "select * from information_schema.user_privileges where grantee like \\\"'monitors'%\\\";"
74+ validation_command = "mysql -u root -p`cat /var/lib/mysql/mysql.passwd` -e \"%s\"" % validation_sql
75+ output, code = mysql_unit.run(validation_command)
76+ #We know that we need a GRANT USAGE permission for this to work properly
77+ if output.find("USAGE") == -1:
78+ amulet.raise_status(amulet.FAIL, msg="Missing GRANT on MySQL unit")
79+
80+
81+# We have an issue here. We cannot assign a sentry unit to a
82+# subordinate. This poses an interesting problem.
83+# validate that haproxy has an nrpe config, and *assume* its ok for now - needs
84+# some love otherwise.
85+def test_nrpe_monitor():
86+ #On join the NRPE unit generates an allowed hosts config
87+ ahosts = haproxy_unit.file_stat('/etc/nagios/nrpe.d/allowed.hosts.cfg')
88+ if not ahosts:
89+ amulet.raise_status(amulet.FAIL, msg="Missing nrpe config")
90+ running, code = haproxy_unit.run('service nagios-nrpe-server status')
91+ if running.find('running') == -1:
92+ amulet.raise_status(amulet.FAIL, msg="Failed to find running nrpe daemon")
93+
94+
95+#Validate that the web interface has htpasswd authentication
96+def test_web_interface_is_protected():
97+ r = requests.get("http://%s/nagios3/" % nagios_unit.info['public-address'])
98+ if r.status_code != 401:
99+ amulet.raise_status(amulet.FAIL, msg="Web Interface open to the world")
100+ #validate that our configured admin is valid
101+ nagpwd = nagios_unit.file_contents('/var/lib/juju/nagios.passwd').strip()
102+ r = requests.get("http://%s/nagios3/" % nagios_unit.info['public-address'],
103+ auth=('nagiosadmin', nagpwd))
104+ if r.status_code != 200:
105+ amulet.raise_status(amulet.FAIL, msg="Web Admin login failed")
106+
107+
108+def text_extra_config_is_written():
109+ extracfg = nagios_unit.file_stat('/etc/nagios3/conf.d/extra.cfg')
110+ if not extracfg:
111+ amulet.raise_status(amulet.FAIL, msg="Extra Config missing")
112+ extracont = nagios_unit.file_contents('/etc/nagios3/conf.d/extra.cfg')
113+ if extracont.find('#amulet') == -1:
114+ amulet.raise_status(amulet.FAIL, msg="Missing extra config contents")
115+
116+#TODO validate SQLite database entries for units
117+
118+
119+test_mysql_monitoring_connection()
120+test_nrpe_monitor()
121+test_web_interface_is_protected()

Subscribers

People subscribed via source and target branches

to all changes: