def testMapServiceStatusToDict(self): """Test mapping a manager.SERVICE_STATUS to a dict.""" def _func(): pass hcstatus = manager.HEALTHCHECK_STATUS('test', False, 'desc', [_func]) hcexpect = {'name': 'test', 'health': False, 'description': 'desc', 'actions': ['_func']} status = manager.SERVICE_STATUS('test-service', False, [hcstatus]) expect = {'service': 'test-service', 'health': False, 'healthchecks': [hcexpect]} self.assertEquals(expect, manager.MapServiceStatusToDict(status))
def RepairService(self, service, healthcheck, action, args, kwargs): """Execute the repair action on the specified service. Args: service: The service that the specified action will be applied to. healthcheck: The particular healthcheck we are repairing. action: The action to be applied. args: A list of the positional arguments for the given repair action. kwargs: A dictionary of keyword arguments for the given repair action. """ # The mobmonitor's RPC library encodes arguments as strings when # making a remote call to the monitor. The checkfile manager expects # lists and dicts for the arugments, so we convert them here. args = json.loads(args.replace('\'', '"')) kwargs = json.loads(kwargs.replace('\'', '"')) status = self.checkfile_manager.RepairService(service, healthcheck, action, args, kwargs) return json.dumps(manager.MapServiceStatusToDict(status))
def GetStatus(self, service=None): """Return the health status of the specified service. Args: service: The service whose health status is being queried. If service is None, return the health status of all monitored services. Returns: A list of dictionaries. Each dictionary contains the keys: service: The name of the service. health: A boolean describing the overall service health. healthchecks: A list of unhealthy or quasi-healthy health checks. """ service_statuses = self.checkfile_manager.GetStatus(service) if not isinstance(service_statuses, list): service_statuses = [service_statuses] result = [ manager.MapServiceStatusToDict(status) for status in service_statuses ] return json.dumps(result)