def update(self): """Update tree, if necessary.""" if self.next_scan_time is not None and self.next_scan_time > time(): return # Scan for running suites choices = [] for host, scan_result in scan_all(timeout=self.timeout): try: port, suite_identity = scan_result except ValueError: # Back-compat <= 6.5.0 port, name, owner = scan_result else: name = suite_identity['name'] owner = suite_identity['owner'] if is_remote_user(owner): continue # current user only auth = "%s:%d" % (host, port) choices.append((name, auth)) choices.sort() self.next_scan_time = time() + self.SCAN_INTERVAL if choices == self.running_choices: return # Update tree if running suites changed self.running_choices = choices self.construct_newtree() self.update_treestore( self.newtree, self.regd_treestore.get_iter_first())
def get_hosts_suites_info(hosts, timeout=None, owner=None): """Return a dictionary of hosts, suites, and their properties.""" host_suites_map = {} for host, port_results in scan_all(hosts=hosts, pyro_timeout=timeout): port, result = port_results if owner and owner != result.get(KEY_OWNER): continue if host not in host_suites_map: host_suites_map[host] = {} try: host_suites_map[host][result[KEY_NAME]] = {} props = host_suites_map[host][result[KEY_NAME]] props["port"] = port for key, value in result.items(): if key == KEY_NAME: continue elif key == KEY_STATES: # Overall states props[KEY_STATES] = value[0] for cycle, cycle_states in value[1].items(): name = "%s:%s" % (KEY_STATES, cycle) props[name] = cycle_states elif key == KEY_UPDATE_TIME: props[key] = int(float(value)) else: props[key] = value except (AttributeError, IndexError, KeyError): pass for host, suites_map in host_suites_map.items(): for suite, suite_info in suites_map.items(): if suite_info.keys() == ["port"]: # Just the port file - could be an older suite daemon. suite_info.update(get_unscannable_suite_info(host, suite, owner=owner)) return host_suites_map
def update(self): """Update tree, if necessary.""" if self.next_scan_time is not None and self.next_scan_time > time(): return # Scan for running suites choices = [] for host, scan_result in scan_all(pyro_timeout=self.pyro_timeout): try: port, suite_identity = scan_result except ValueError: # Back-compat <= 6.5.0 port, name, owner = scan_result else: name = suite_identity['name'] owner = suite_identity['owner'] if is_remote_user(owner): continue # current user only auth = "%s:%d" % (host, port) choices.append((name, auth)) choices.sort() self.next_scan_time = time() + self.SCAN_INTERVAL if choices == self.running_choices: return # Update tree if running suites changed self.running_choices = choices self.construct_newtree() self.update_treestore(self.newtree, self.regd_treestore.get_iter_first())
def get_hosts_suites_info(hosts, timeout=None, owner=None): """Return a dictionary of hosts, suites, and their properties.""" host_suites_map = {} for host, (port, result) in scan_all(hosts=hosts, pyro_timeout=timeout): if owner and owner != result.get(KEY_OWNER): continue if host not in host_suites_map: host_suites_map[host] = {} try: host_suites_map[host][result[KEY_NAME]] = {} props = host_suites_map[host][result[KEY_NAME]] props["port"] = port for key, value in result.items(): if key == KEY_NAME: continue elif key == KEY_STATES: # Overall states props[KEY_STATES] = value[0] for cycle, cycle_states in value[1].items(): name = "%s:%s" % (KEY_STATES, cycle) props[name] = cycle_states elif key == KEY_UPDATE_TIME: props[key] = int(float(value)) else: props[key] = value except (AttributeError, IndexError, KeyError): pass for host, suites_map in host_suites_map.items(): for suite, suite_info in suites_map.items(): if suite_info.keys() == ["port"]: # Just the port file - could be an older suite daemon. suite_info.update( get_unscannable_suite_info(host, suite, owner=owner)) return host_suites_map
def update_suites_info(hosts=None, timeout=None, owner_pattern=None, name_pattern=None, prev_results=None): """Return mapping of suite info by host, owner and suite name. hosts - hosts to scan, or the default set in the site/user global.rc timeout - communication timeout owner_pattern - return only suites with owners matching this compiled re name_pattern - return only suites with names matching this compiled re prev_results - previous results returned by this function Return a dict of the form: {(host, owner, name): suite_info, ...} where each "suite_info" is a dict with keys: KEY_GROUP - group name of suite KEY_OWNER - suite owner name KEY_PORT - suite port, for running suites only KEY_STATES - suite state KEY_STATES:cycle - states by cycle KEY_TASKS_BY_STATE - tasks by state KEY_TITLE - suite title KEY_UPDATE_TIME - last update time of suite """ results = {} for host, port, result in scan_all(hosts=hosts, timeout=timeout): if (name_pattern and not name_pattern.match(result[KEY_NAME]) or owner_pattern and not owner_pattern.match(result[KEY_OWNER])): continue try: result[KEY_PORT] = port results[(host, result[KEY_OWNER], result[KEY_NAME])] = result result[KEY_UPDATE_TIME] = int(float(result[KEY_UPDATE_TIME])) except (KeyError, TypeError, ValueError): pass expire_threshold = time() - DURATION_EXPIRE_STOPPED for (host, owner, name), prev_result in prev_results.items(): if ((host, owner, name) in results or host not in hosts or owner_pattern and not owner_pattern.match(owner) or name_pattern and not name_pattern.match(name)): # OK if suite already in current results set. # Don't bother if: # * previous host not in current hosts list # * previous owner does not match current owner pattern # * previous suite name does not match current name pattern continue if prev_result.get(KEY_PORT): # A previously running suite is no longer running. # Get suite info with "cat-state", if possible, and include in the # results set. try: prev_result = _update_stopped_suite_info((host, owner, name)) except (IndexError, TypeError, ValueError): continue if prev_result.get(KEY_UPDATE_TIME, 0) > expire_threshold: results[(host, owner, name)] = prev_result return results
def update(self): """Update tree, if necessary.""" if self.next_scan_time is not None and self.next_scan_time > time(): return # Scan for running suites choices = [] for host, port, suite_identity in scan_all(timeout=self.timeout): name = suite_identity["name"] owner = suite_identity["owner"] if is_remote_user(owner): continue # current user only auth = "%s:%d" % (host, port) choices.append((name, auth)) choices.sort() self.next_scan_time = time() + self.SCAN_INTERVAL if choices == self.running_choices: return # Update tree if running suites changed self.running_choices = choices self.construct_newtree() self.update_treestore(self.newtree, self.regd_treestore.get_iter_first())