~pwlars/uci-engine/tr-pass-no-tests

« back to all changes in this revision

Viewing changes to ci-utils/ci_utils/health_check.py

  • Committer: Ubuntu CI Bot
  • Author(s): Ursula Junque (Ursinha)
  • Date: 2014-07-29 21:38:15 UTC
  • mfrom: (712.1.19 add-nagios_)
  • Revision ID: ubuntu_ci_bot-20140729213815-7hwguf44vsl2pxmx
[r=PS Jenkins bot, Francis Ginther, Vincent Ladeuil] Adding a <service_root>/nagios to store the check_*.health files, other tests and utilities.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import sys
18
18
import fcntl
19
19
 
20
 
 
21
 
RESULT_DIR = "/var/cache/"
 
20
from ci_utils import get_nagios_dir
22
21
 
23
22
 
24
23
class HealthCheck(object):
25
24
 
26
25
    def __init__(self, service_name):
27
26
        self.service_name = service_name
 
27
        self.result_file_path = os.path.join(
 
28
            get_nagios_dir(), '{}.health'.format(service_name))
28
29
 
29
30
    def __enter__(self):
30
31
        try:
31
 
            self.result_file = open(
32
 
                os.path.join(
33
 
                    RESULT_DIR, '{}.health'.format(self.service_name)),
34
 
                'w')
 
32
            self.result_file = open(self.result_file_path, 'w')
35
33
            fcntl.flock(self.result_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
36
34
            return self
37
35
        except IOError as exc:
51
49
    def write_result_failed(self, output=None):
52
50
        self.result_file.write("FAILED")
53
51
        if output is not None:
54
 
            self.result_file.write(str(output))
 
52
            self.result_file.write(': {}'.format(str(output)))