~tal-it-innovation/charms/precise/nagios/include-password

« back to all changes in this revision

Viewing changes to hooks/test-common.py

  • Committer: Mark Mims
  • Date: 2012-08-07 21:42:35 UTC
  • mfrom: (7.1.31 nagios)
  • Revision ID: mark.mims@canonical.com-20120807214235-0iw0v2afxhy7ovlt
mergingĀ lp:~clint-fewbar/charms/precise/nagios/add-monitors-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from common import ObjectTagCollection
 
2
import os
 
3
 
 
4
from tempfile import NamedTemporaryFile
 
5
 
 
6
""" This is meant to test the ObjectTagCollection bits. It should
 
7
    probably be made into a proper unit test. """
 
8
 
 
9
x = ObjectTagCollection('test-units')
 
10
y = ObjectTagCollection('test-relids')
 
11
 
 
12
o = NamedTemporaryFile(delete=False)
 
13
o2 = NamedTemporaryFile(delete=False)
 
14
o3 = NamedTemporaryFile(delete=True)
 
15
o.write('some content')
 
16
o.flush()
 
17
 
 
18
x.tag_object(o.name, 'box-9')
 
19
x.tag_object(o.name, 'nrpe-1')
 
20
y.tag_object(o.name, 'monitors:2')
 
21
x.tag_object(o2.name, 'box-10')
 
22
x.tag_object(o2.name, 'nrpe-2')
 
23
y.tag_object(o2.name, 'monitors:2')
 
24
x.tag_object(o3.name, 'other-0')
 
25
y.tag_object(o3.name, 'monitors:3')
 
26
x.untag_object(o.name, 'box-9')
 
27
x.cleanup_untagged()
 
28
 
 
29
if not os.path.exists(o.name):
 
30
    raise RuntimeError(o.name)
 
31
 
 
32
x.kill_tag('nrpe-1')
 
33
x.cleanup_untagged()
 
34
 
 
35
if os.path.exists(o.name):
 
36
    raise RuntimeError(o.name)
 
37
 
 
38
if not os.path.exists(o2.name):
 
39
    raise RuntimeError(o2.name)
 
40
 
 
41
y.kill_tag('monitors:2')
 
42
y.cleanup_untagged(['monitors:1','monitors:3'])
 
43
 
 
44
if os.path.exists(o.name):
 
45
    raise RuntimeError(o2.name)
 
46
 
 
47
if os.path.exists(o2.name):
 
48
    raise RuntimeError(o2.name)
 
49
 
 
50
x.destroy()