def test_re_compile_filters(self): """Test that both patterns return the expected values.""" patterns_owner = ['^.oot$'] patterns_name = ['.*'] values = re_compile_filters(patterns_owner=patterns_owner, patterns_name=patterns_name) self.assertIsInstance(values[0], re.Pattern) self.assertIsInstance(values[1], re.Pattern) self.assertTrue(values[0].match("root"))
async def gather_workflows(self): scanflows = {} cre_owner, cre_name = re_compile_filters(None, ['.*']) scan_args = ( (reg, host, port, CLIENT_TIMEOUT) for reg, host, port in get_scan_items_from_fs(cre_owner, cre_name)) gathers = () for arg in scan_args: gathers += (est_workflow(*arg), ) items = await asyncio.gather(*gathers) for reg, host, port, client, info in items: if info is not None and info != MSG_TIMEOUT: owner = info['owner'] scanflows[f"{owner}{ID_DELIM}{reg}"] = { 'name': info['name'], 'owner': owner, 'host': host, 'port': port, 'version': info['version'], 'req_client': client, } # Check existing against scan for w_id, info in list(self.workflows.items()): if w_id in scanflows: if (info['host'] == scanflows[w_id]['host'] and info['port'] == scanflows[w_id]['port']): client = scanflows[w_id]['req_client'] with suppress(IOError): client.socket.close() scanflows.pop(w_id) continue client = self.workflows[w_id]['req_client'] with suppress(IOError): client.socket.close() self.workflows.pop(w_id) # update with new self.workflows.update(scanflows)
def main(parser, options): """Implement "cylc scan".""" if options.full: options.describe = options.state_totals = options.publisher = True if options.format in ['raw', 'json']: options.color = False # color settings if options.color in ['auto', 'always'] and terminal.supports_color(): options.color = True else: options.color = False color_init(autoreset=True, strip=not options.color) # name and owner patterns if options.patterns_name: patterns_name = options.patterns_name else: patterns_name = ['.*'] # Any suite name. patterns_owner = None if options.patterns_owner: patterns_owner = options.patterns_owner try: # Compile and check "name" and "owner" regular expressions cre_owner, cre_name = re_compile_filters(patterns_owner, patterns_name) except ValueError as exc: parser.error(str(exc)) # list of endpoints to call methods = ['identify'] if options.describe: methods.append('describe') if options.state_totals: methods.append('state_totals') # suite generator suites = scan_many( get_scan_items_from_fs(cre_owner, cre_name), timeout=options.comms_timeout, methods=methods, ordered=options.ordered ) # determine output format if options.format == 'json': print(json.dumps(list(suites), indent=4)) elif options.format == 'raw': formatter = format_raw elif options.format == 'plain': formatter = format_plain else: raise UserInputError('Unknown format: %s' % options.format) # output state legend if necessary state_legend = "" if options.color and options.state_totals: n_states = len(TASK_STATUSES_ORDERED) for index, state in enumerate(TASK_STATUSES_ORDERED): state_legend += get_status_prop(state, 'ascii_ctrl') if index == n_states / 2: state_legend += "\n" print(state_legend.rstrip() + "\n") # work through scan results one by one for reg, host, port, pub_port, api, info in suites: if isinstance(info, str): print(ERROR_STYLE + ' '.join([reg, host, port, info])) elif info is None: print(ERROR_STYLE + ' '.join([reg, host, port, 'Error Connecting'])) elif info[KEY_NAME] != reg: # TODO - should we do anything here, is this likely? print(ERROR_STYLE + 'Warning: suite has changed name %s => %s' % ( reg, info[KEY_NAME])) else: formatter(reg, host, port, pub_port, api, info, options)
def test_re_compile_filters_bad_regex(self): """Test that it raises ValueError if a regex provided is invalid.""" with self.assertRaises(ValueError): re_compile_filters(patterns_name=["???"])
def test_re_compile_filters_nones(self): """Test with no arguments provided.""" self.assertEqual((None, None), re_compile_filters())