def run_in_consumer(mocker, msg: BaseMessage, planner: WorkPlanner, consumer: ConsumerThread, motr: Motr) -> None: mocker.patch.object(planner, 'get_next_command', side_effect=[msg, Die()]) profile = Profile(fid=create_profile_fid(22), name='the_pool', pool_names=['name1']) motr.start('endpoint', create_process_fid(120), create_process_fid(15), profile) consumer._do_work(planner, motr)
def to_ha_states(data: Any, consul_util: ConsulUtil) -> List[HAState]: """Converts a dictionary, obtained from JSON data, into a list of HA states. Format of an HA state: HAState(fid= <service fid>, status= <state>), where <state> is either 'online' or 'offline'. """ if not data: return [] def get_svc_node(checks: List[Dict[str, Any]], svc_id: str) -> str: for x in checks: if x.get('ServiceID') == svc_id: return str(x.get('Node')) return "" def get_svc_health(item: Any) -> ServiceHealth: node = get_svc_node(item['Checks'], item['Service']['ID']) LOG.debug('Checking current state of the process %s', item['Service']['ID']) status: ServiceHealth = consul_util.get_service_health( item['Service']['Service'], node, int(item['Service']['ID'])) return status return [ HAState(fid=create_process_fid(int(t['Service']['ID'])), status=get_svc_health(t)) for t in data ]
def to_ha_states(data: Any, consul_util: ConsulUtil) -> List[HAState]: """Converts a dictionary, obtained from JSON data, into a list of HA states. Format of an HA state: HAState(fid= <service fid>, status= <state>), where <state> is either 'online' or 'offline'. """ if not data: return [] def get_status(checks: List[Dict[str, Any]]) -> ServiceHealth: ok = all(x.get('Status') == 'passing' for x in checks) return ServiceHealth.OK if ok else ServiceHealth.FAILED return [ HAState(fid=create_process_fid(int(t['Service']['ID'])), status=get_status(t['Checks'])) for t in data ]
def to_ha_states(data: Any, consul_util: ConsulUtil) -> List[HAState]: """Converts a dictionary, obtained from JSON data, into a list of HA states. Format of an HA state: HAState(fid= <service fid>, status= <state>), where <state> is either 'online' or 'offline'. """ if not data: return [] ha_states = [] for node in data: svc_status = ObjHealth.OK for check in node['Checks']: if check.get('Status') != 'passing': svc_status = ObjHealth.FAILED svc_id = check.get('ServiceID') if svc_id: ha_states.append( HAState(fid=create_process_fid(int(svc_id)), status=svc_status)) LOG.debug('Reporting ha states: %s', ha_states) return ha_states