Merge lp:~mbruzek/charms/trusty/kibana/tests into lp:charms/trusty/kibana

Proposed by Matt Bruzek
Status: Merged
Merged at revision: 25
Proposed branch: lp:~mbruzek/charms/trusty/kibana/tests
Merge into: lp:charms/trusty/kibana
Diff against target: 379 lines (+90/-260)
6 files modified
tests/10-bundles-test.py (+0/-77)
tests/10-deploy.py (+90/-0)
tests/11-scale-elastic-query.json (+0/-49)
tests/11-scale-elastic.py (+0/-86)
tests/12-port-change.py (+0/-38)
tests/bundles.yaml (+0/-10)
To merge this branch: bzr merge lp:~mbruzek/charms/trusty/kibana/tests
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+300007@code.launchpad.net

Description of the change

I replaced the tests with a comprehensive test that passes bundletester.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'tests/10-bundles-test.py'
2--- tests/10-bundles-test.py 2016-05-19 15:00:44 +0000
3+++ tests/10-bundles-test.py 1970-01-01 00:00:00 +0000
4@@ -1,77 +0,0 @@
5-#!/usr/bin/env python3
6-
7-# This amulet test deploys the bundles.yaml file in this directory.
8-
9-import os
10-import unittest
11-import yaml
12-import amulet
13-import requests
14-
15-seconds_to_wait = 960
16-
17-
18-class BundleTest(unittest.TestCase):
19- """ Create a class for testing the charm in the unit test framework. """
20- @classmethod
21- def setUpClass(cls):
22- """ Set up an amulet deployment using the bundle. """
23- d = amulet.Deployment()
24- bundle_path = os.path.join(os.path.dirname(__file__), 'bundles.yaml')
25- with open(bundle_path, 'r') as bundle_file:
26- contents = yaml.safe_load(bundle_file)
27- d.load(contents)
28- d.setup(seconds_to_wait, cleanup=False)
29- d.sentry.wait(seconds_to_wait)
30- cls.d = d
31-
32- def test_deployed(self):
33- """ Test to see if the bundle deployed successfully. """
34- self.assertTrue(self.d.deployed)
35-
36- def test_port_change(self):
37- """ Change kibana port and validate the change happened """
38- self.d.configure('kibana', {'port': 81})
39- self.d.sentry.wait()
40-
41- url = 'http://%s:81/' % kibana_unit.info['public-address']
42- r = requests.get(url)
43- assert r.ok
44-
45- def test_web_interface():
46-
47- elasticsearch_unit.run("""
48- curl -X POST 'http://127.0.0.1:9200/person/1' -d '{
49- "info" : {
50- "height" : 2,
51- "width" : 20
52- }
53- }'
54- """)
55-
56- time.sleep(3)
57-
58- # Ensure the kibana unit can query ES via localhost (it proxies local 9200
59- # queries to ES)
60- url = 'http://127.0.0.1:9200/_all/_search'
61- result = kibana_unit.run(
62- "curl -XGET {url} -d '@11-scale-elastic-query.json'".format(url=url))
63- if not result[1] == 0:
64- amulet.raise_status(
65- amulet.FAIL, msg="Error performing search. Error code: {}. "
66- "Result:\n{}".format(result[1], result[0]))
67- try:
68- result = json.loads(result[0])
69- if result['hits']['total'] != 1:
70- amulet.raise_status(amulet.FAIL,
71- msg="Error inserting value in elasticsearch.")
72- except ValueError:
73- exc_type, value, traceback = sys.exc_info()
74- exc_text = "Exception: (%s) %s. %s" % (value, exc_type, traceback)
75- amulet.raise_status(
76- amulet.FAIL, msg="Value returned not a valid json.\n{}\n{}".format(
77- result[0], exc_text))
78-
79-
80-if __name__ == '__main__':
81- unittest.main()
82
83=== added file 'tests/10-deploy.py'
84--- tests/10-deploy.py 1970-01-01 00:00:00 +0000
85+++ tests/10-deploy.py 2016-07-13 21:06:25 +0000
86@@ -0,0 +1,90 @@
87+#!/usr/bin/python3
88+
89+# This is a very basic test for to verify the kibana charm.
90+
91+import amulet
92+import unittest
93+
94+seconds = 1100
95+port = 82
96+
97+
98+class TestDeployment(unittest.TestCase):
99+
100+ @classmethod
101+ def setUpClass(cls):
102+ """Perform a one time setup for this class deploying the charms."""
103+ cls.deployment = amulet.Deployment(series='trusty')
104+
105+ cls.deployment.add('kibana')
106+ cls.deployment.configure('kibana', {'port': port})
107+ cls.deployment.add('elasticsearch', units=3)
108+ cls.deployment.relate('kibana:rest', 'elasticsearch:client')
109+ cls.deployment.expose('kibana')
110+
111+ try:
112+ cls.deployment.setup(timeout=seconds)
113+ cls.deployment.sentry.wait()
114+ except amulet.helpers.TimeoutError:
115+ message = "The deploy did not setup in {0} seconds".format(seconds)
116+ amulet.raise_status(amulet.SKIP, msg=message)
117+ except:
118+ raise
119+ cls.kibana_unit = cls.deployment.sentry['kibana'][0]
120+ cls.elasticsearch_units = cls.deployment.sentry['elasticsearch']
121+
122+ def test_elasticsearch(self):
123+ """Make sure elasticsearch is running and get health status."""
124+ for unit in self.elasticsearch_units:
125+ # Verify the Elasticsearch service is installed and running.
126+ status = 'service elasticsearch status'
127+ output, code = unit.run(status)
128+ print(output)
129+ if code != 0:
130+ message = 'Elasticsearch is not running.'
131+ amulet.raise_status(amulet.FAIL, msg=message)
132+ # Get the health from Elasticsearch.
133+ get = 'curl -X GET http://127.0.0.1:9200/_cat/health'
134+ output, code = unit.run(get)
135+ print(output)
136+ if 'green' not in output:
137+ message = 'Health output is not green:\n{0}'.format(output)
138+ amulet.raise_status(amulet.FAIL, msg=message)
139+
140+ def test_kibana(self):
141+ """Make sure that kibana is installed and running correctly."""
142+ # Verify the service is installed and running.
143+ status = 'service kibana status'
144+ output, code = self.kibana_unit.run(status)
145+ print(output)
146+ if code != 0:
147+ message = 'Kibana is not running.'
148+ amulet.raise_status(amulet.FAIL, msg=message)
149+ # Ensure each elasticsearch node address is in the ngnix site file.
150+ file = '/etc/nginx/sites-available/es_cluster'
151+ es_cluster = self.kibana_unit.file_contents(file)
152+ for es_unit in self.elasticsearch_units:
153+ address, code = es_unit.run('unit-get private-address')
154+ if address in es_cluster:
155+ print('Found {0} in the nginx config file.'.format(address))
156+ else:
157+ message = 'Elasticsearch {0} was not in {0}'.format(address,
158+ file)
159+ amulet.raise_status(amulet.FAIL, msg=message)
160+ # Test the proxy from Kibana to Elasticsearch is working.
161+ get = 'curl -X GET http://localhost:9200/_cat/health/'
162+ output, code = self.kibana_unit.run(get)
163+ print(output)
164+ if 'green' not in output or code != 0:
165+ message = 'The proxy to Elasticsearch is not working.'
166+ amulet.raise_status(amulet.FAIL, msg=message)
167+ # Test that Kibana is running and hosting http on this unit.
168+ kibana = 'curl http://localhost:{0}'.format(port)
169+ output, code = self.kibana_unit.run(kibana)
170+ print(output)
171+ if 'kibana' not in output or code != 0:
172+ amulet.raise_status(amulet.FAIL,
173+ msg="Error getting kibana page.")
174+
175+if __name__ == '__main__':
176+ unittest.main()
177
178=== removed file 'tests/11-scale-elastic-query.json'
179--- tests/11-scale-elastic-query.json 2015-03-12 18:48:08 +0000
180+++ tests/11-scale-elastic-query.json 1970-01-01 00:00:00 +0000
181@@ -1,49 +0,0 @@
182-{
183- "query": {
184- "filtered": {
185- "query": {
186- "bool": {
187- "should": [
188- {
189- "query_string": {
190- "query": "*"
191- }
192- }
193- ]
194- }
195- },
196- "filter": {
197- "bool": {
198- "must": [
199- {
200- "terms": {
201- "_type": [
202- "1"
203- ]
204- }
205- }
206- ]
207- }
208- }
209- }
210- },
211- "highlight": {
212- "fields": {},
213- "fragment_size": 2147483647,
214- "pre_tags": [
215- "@start-highlight@"
216- ],
217- "post_tags": [
218- "@end-highlight@"
219- ]
220- },
221- "size": 500,
222- "sort": [
223- {
224- "_score": {
225- "order": "desc",
226- "ignore_unmapped": true
227- }
228- }
229- ]
230-}
231
232=== removed file 'tests/11-scale-elastic.py'
233--- tests/11-scale-elastic.py 2016-05-19 15:00:44 +0000
234+++ tests/11-scale-elastic.py 1970-01-01 00:00:00 +0000
235@@ -1,86 +0,0 @@
236-#!/usr/bin/python3
237-import os
238-import sys
239-import time
240-import json
241-
242-import amulet
243-import requests
244-
245-seconds = 20000
246-
247-d = amulet.Deployment(series='trusty')
248-
249-d.add('kibana')
250-d.add('elasticsearch')
251-d.add('logstash-indexer', charm='cs:precise/logstash-indexer')
252-
253-d.add_unit('elasticsearch', 2)
254-
255-d.relate('logstash-indexer:cluster', 'elasticsearch:client')
256-d.relate('kibana:rest', 'elasticsearch:client')
257-
258-d.expose('kibana')
259-
260-try:
261- d.setup(timeout=seconds)
262-except amulet.helpers.TimeoutError:
263- amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
264-except:
265- raise
266-
267-
268-##
269-# Set relationship aliases
270-##
271-kibana_unit = d.sentry['kibana'][0]
272-elasticsearch_unit = d.sentry['elasticsearch'][1]
273-
274-
275-def test_web_interface():
276- hits = get_total_hits()
277-
278- elasticsearch_unit.run("""
279- curl -X POST 'http://127.0.0.1:9200/person/1' -d '{
280- "info" : {
281- "height" : 2,
282- "width" : 20
283- }
284- }'
285- """)
286-
287- iteration = 0
288- newhits = get_total_hits()
289- while iteration < 10 and newhits-hits != 1:
290- time.sleep(3)
291- newhits = get_total_hits()
292- iteration += 1
293-
294- if newhits-hits != 1:
295- amulet.raise_status(amulet.FAIL,
296- msg="Error inserting value in elasticsearch.")
297-
298-
299-def get_total_hits():
300- # Ensure the kibana unit can query ES via localhost (it proxies local 9200
301- # queries to ES)
302- url = 'http://127.0.0.1:9200/_all/_search'
303- result = kibana_unit.run(
304- "curl -XGET {url} -d '@11-scale-elastic-query.json'".format(url=url))
305- if not result[1] == 0:
306- amulet.raise_status(
307- amulet.FAIL, msg="Error performing search. Error code: {}. "
308- "Result:\n{}".format(result[1], result[0]))
309-
310- try:
311- result = json.loads(result[0])
312- return result['hits']['total']
313- except ValueError:
314- exc_type, value, traceback = sys.exc_info()
315- exc_text = "Exception: (%s) %s. %s" % (value, exc_type, traceback)
316- amulet.raise_status(
317- amulet.FAIL, msg="Value returned not a valid json.\n{}\n{}".format(
318- result[0], exc_text))
319-
320-
321-test_web_interface()
322
323=== removed file 'tests/12-port-change.py'
324--- tests/12-port-change.py 2015-11-04 21:49:41 +0000
325+++ tests/12-port-change.py 1970-01-01 00:00:00 +0000
326@@ -1,38 +0,0 @@
327-#!/usr/bin/python3
328-
329-import amulet
330-import requests
331-
332-seconds = 20000
333-
334-d = amulet.Deployment(series='trusty')
335-
336-d.add('kibana')
337-d.add('elasticsearch')
338-
339-d.configure('kibana', {'port': 81})
340-
341-d.add_unit('elasticsearch', 2)
342-
343-d.relate('kibana:rest', 'elasticsearch:client')
344-
345-d.expose('kibana')
346-
347-try:
348- d.setup(timeout=seconds)
349-except amulet.helpers.TimeoutError:
350- amulet.raise_status(amulet.SKIP, msg="Environment wasn't stood up in time")
351-except:
352- raise
353-
354-
355-def test_web_interface():
356- kibana_unit = d.sentry['kibana'][0]
357- url = 'http://%s:81/' % kibana_unit.info['public-address']
358- r = requests.get(url)
359- if not r.ok:
360- amulet.raise_status(amulet.FAIL,
361- msg="Error getting kibana page.")
362-
363-
364-test_web_interface()
365
366=== removed file 'tests/bundles.yaml'
367--- tests/bundles.yaml 2016-05-19 15:00:44 +0000
368+++ tests/bundles.yaml 1970-01-01 00:00:00 +0000
369@@ -1,10 +0,0 @@
370-kibana-bundle:
371- relations: []
372- series: trusty
373- services:
374- kibana:
375- charm: kibana
376- num_units: 1
377- elasticsearch:
378- charm: cs:trusty/elasticsearch
379- num_units: 1

Subscribers

People subscribed via source and target branches