def test_build_message(self): """Unit test supervisord build service check message.""" time_stop = 0 time_start = 1414815388 time_now = 1414815513 process = { 'now': time_now, 'group': 'mysql', 'description': 'pid 787, uptime 0:02:05', 'pid': 787, 'stderr_logfile': '/var/log/supervisor/mysql-stderr---supervisor-3ATI82.log', 'stop': time_stop, 'statename': 'RUNNING', 'start': time_start, 'state': 20, 'stdout_logfile': '/var/log/mysql/mysql.log', 'logfile': '/var/log/mysql/mysql.log', 'exitstatus': 0, 'spawnerr': '', 'name': 'mysql' } expected_message = """Current time: {time_now} Process name: mysql Process group: mysql Description: pid 787, uptime 0:02:05 Error log file: /var/log/supervisor/mysql-stderr---supervisor-3ATI82.log Stdout log file: /var/log/mysql/mysql.log Log file: /var/log/mysql/mysql.log State: RUNNING Start time: {time_start} Stop time: {time_stop}\nExit Status: 0""".format( time_now=FORMAT_TIME(time_now), time_start=FORMAT_TIME(time_start), time_stop='' if time_stop == 0 else FORMAT_TIME(time_stop)) agentConfig = {'version': '0.1', 'api_key': 'tota'} check = load_check('supervisord', { 'init_config': {}, 'instances': self.TEST_CASES[0]['instances'] }, agentConfig) self.assertEquals(expected_message, check._build_message(process))
def test_build_message(check): """Unit test supervisord build service check message.""" time_stop = 0 time_start = 1414815388 time_now = 1414815513 process = { 'now': time_now, 'group': 'mysql', 'description': 'pid 787, uptime 0:02:05', 'pid': 787, 'stderr_logfile': '/var/log/supervisor/mysql-stderr---supervisor-3ATI82.log', 'stop': time_stop, 'statename': 'RUNNING', 'start': time_start, 'state': 20, 'stdout_logfile': '/var/log/mysql/mysql.log', 'logfile': '/var/log/mysql/mysql.log', 'exitstatus': 0, 'spawnerr': '', 'name': 'mysql', } expected_message = """Current time: {time_now} Process name: mysql Process group: mysql Description: pid 787, uptime 0:02:05 Error log file: /var/log/supervisor/mysql-stderr---supervisor-3ATI82.log Stdout log file: /var/log/mysql/mysql.log Log file: /var/log/mysql/mysql.log State: RUNNING Start time: {time_start} Stop time: {time_stop}\nExit Status: 0""".format( time_now=FORMAT_TIME(time_now), time_start=FORMAT_TIME(time_start), time_stop='' if time_stop == 0 else FORMAT_TIME(time_stop), ) assert expected_message == check._build_message(process)