def test_run_e2e(self): # hack to skip running the base Test class (which is the nose default behavior) if self.__class__.__name__ in ('PbTestApp', 'PbTestScatterApp', 'PbTestGatherApp'): return if self.REQUIRES_PBCORE: if not HAS_PBCORE: self.assertTrue(True, pbcore_skip_msg("Skipping running e2e for {d}".format(d=self.DRIVER_EMIT))) return output_dir = get_temp_dir(suffix="rtc-test") tmp_dir = get_temp_dir(suffix="rtc-temp") log.debug("Driver {e}".format(e=self.DRIVER_EMIT)) log.debug("input files {i}".format(i=self.INPUT_FILES)) log.debug("running in {p}".format(p=output_dir)) output_tc = get_temp_file("-{n}-tool_contract.json".format(n=self.__class__.__name__), output_dir) emit_tc_exe = "{e} > {o}".format(e=self.DRIVER_EMIT, o=output_tc) rcode = subprocess.call([emit_tc_exe], shell=True) self.assertEquals(rcode, 0, "Emitting tool contract failed for '{e}'".format(e=emit_tc_exe)) # sanity marshall-unmashalling log.debug("Loading tool-contract from {p}".format(p=output_tc)) tc = load_tool_contract_from(output_tc) log.info("Resolving tool contract to RTC") rtc = self._to_rtc(tc, output_dir, tmp_dir) output_json_rtc = get_temp_file("resolved_tool_contract.json", output_dir) write_resolved_tool_contract(rtc, output_json_rtc) # sanity loaded_rtc = load_resolved_tool_contract_from(output_json_rtc) self.assertIsInstance(loaded_rtc, ResolvedToolContract) # Test Resolved options if specified. for opt, resolved_value in self.RESOLVED_TASK_OPTIONS.iteritems(): self.assertTrue(opt in rtc.task.options, "Resolved option {x} not in RTC options.".format(x=opt)) # this needs to support polymorphic equals (i.e., almostEquals if not isinstance(resolved_value, float): emsg = "Resolved option {o} are not equal. Expected {a}, got {b}".format(o=opt, b=rtc.task.options[opt], a=resolved_value) self.assertEquals(rtc.task.options[opt], resolved_value, emsg) # Resolved NPROC self.assertEquals(rtc.task.nproc, self.RESOLVED_NPROC) log.info("running resolved contract {r}".format(r=output_json_rtc)) exe = "{d} {p}".format(p=output_json_rtc, d=self.DRIVER_RESOLVE) log.info("Running exe '{e}'".format(e=exe)) rcode = subprocess.call([exe], shell=True) self.assertEqual(rcode, 0, "Running from resolved tool contract failed from {e}".format(e=exe)) log.info("Successfully completed running e2e for {d}".format(d=self.DRIVER_EMIT)) self._test_outputs_exists(rtc) self.run_after(rtc, output_dir)
def _w(args): # FIXME. setup_log(log, level=logging.DEBUG) log.info("Registry {r}".format(r=registry)) log.info("loading RTC from {i}".format(i=args.rtc_path)) rtc = load_resolved_tool_contract_from(args.rtc_path) id_funcs = {t.task.task_id:func for t, func in registry.rtc_runners.iteritems()} func = id_funcs.get(rtc.task.task_id, None) if func is None: sys.stderr.write("ERROR. Unknown tool contract id {x}".format(x=rtc.task.task_id)) return -1 else: exit_code = func(rtc) log.info("Completed running {r} exitcode {e}".format(r=rtc, e=exit_code))
def _w(args): started_at = time.time() def run_time(): return time.time() - started_at def exit_msg(rcode_): return "Completed running {r} exitcode {e} in {t:.2f} sec.".format( r=rtc, e=rcode_, t=run_time()) level = get_parsed_args_log_level(args) setup_logger(None, level=level) log.info("Loading pbcommand {v}".format(v=pbcommand.get_version())) log.info("Registry {r}".format(r=registry)) log.info("Setting log-level to {d}".format(d=level)) log.debug("args {a}".format(a=args)) log.info("loading RTC from {i}".format(i=args.rtc_path)) rtc = load_resolved_tool_contract_from(args.rtc_path) id_funcs = { t.task.task_id: func for t, func in registry.rtc_runners.iteritems() } func = id_funcs.get(rtc.task.task_id, None) if func is None: rcode = 1 log.error( "Unknown tool contract id '{x}' Registered TC ids {i}".format( x=rtc.task.task_id, i=id_funcs.keys())) log.error(exit_msg(rcode)) return rcode else: log.info("Running id:{i} Resolved Tool Contract {r}".format( r=rtc, i=rtc.task.task_id)) log.info("Runner func {f}".format(f=func)) exit_code = func(rtc) if exit_code == 0: log.info(exit_msg(exit_code)) else: log.error(exit_msg(exit_code)) return exit_code
def _w(args): # FIXME. setup_log(log, level=logging.DEBUG) log.info("Registry {r}".format(r=registry)) log.info("loading RTC from {i}".format(i=args.rtc_path)) rtc = load_resolved_tool_contract_from(args.rtc_path) id_funcs = { t.task.task_id: func for t, func in registry.rtc_runners.iteritems() } func = id_funcs.get(rtc.task.task_id, None) if func is None: sys.stderr.write("ERROR. Unknown tool contract id {x}".format( x=rtc.task.task_id)) return -1 else: exit_code = func(rtc) log.info("Completed running {r} exitcode {e}".format(r=rtc, e=exit_code))
def _w(args): default_level = logging.INFO level = args.log_level if hasattr(args, 'log_level') else default_level setup_log(log, level=level) log.info("Loading pbcommand {v}".format(v=pbcommand.get_version())) log.info("Registry {r}".format(r=registry)) log.info("loading RTC from {i}".format(i=args.rtc_path)) rtc = load_resolved_tool_contract_from(args.rtc_path) id_funcs = {t.task.task_id:func for t, func in registry.rtc_runners.iteritems()} func = id_funcs.get(rtc.task.task_id, None) if func is None: sys.stderr.write("ERROR. Unknown tool contract id {x}".format(x=rtc.task.task_id)) return -1 else: log.info("Running id:{i} Resolved Tool Contract {r}".format(r=rtc, i=rtc.task.task_id)) log.info("Runner func {f}".format(f=func)) exit_code = func(rtc) log.info("Completed running {r} exitcode {e}".format(r=rtc, e=exit_code)) return exit_code
def loadRtcs(cls): cls.tasks_dir = op.join(cls.job_dir, "tasks") cls.resolved_tool_contracts = [] cls.runnable_tasks = [] tasks_rpt = op.join(cls.job_dir, "workflow", "report-tasks.json") rpt = load_report_from_json(tasks_rpt) table = {t.id: t for t in rpt.tables}['tasks'] tasks = {c.id: c.values for c in table.columns}['task_id'] for task_id_str in tasks: fields = task_id_str.split() task_name = fields[1].split(":")[-1] task_dir = op.join(cls.tasks_dir, task_name) if not op.isdir(task_dir): continue task_id, job_id = task_name.split("-") rtc_json = op.join(task_dir, "resolved-tool-contract.json") if not op.isfile(rtc_json): log.warn("Can't find %s" % rtc_json) continue rtc = load_resolved_tool_contract_from(rtc_json) cls.resolved_tool_contracts.append(rtc) rt_json = op.join(task_dir, "runnable-task.json") rt = RunnableTask.from_manifest_json(rt_json) cls.runnable_tasks.append(rt)
def _w(args): started_at = time.time() def run_time(): return time.time() - started_at def exit_msg(rcode_): return "Completed running {r} exitcode {e} in {t:.2f} sec.".format(r=rtc, e=rcode_, t=run_time()) level = get_parsed_args_log_level(args) setup_logger(None, level=level) log.info("Loading pbcommand {v}".format(v=pbcommand.get_version())) log.info("Registry {r}".format(r=registry)) log.info("Setting log-level to {d}".format(d=level)) log.debug("args {a}".format(a=args)) log.info("loading RTC from {i}".format(i=args.rtc_path)) rtc = load_resolved_tool_contract_from(args.rtc_path) id_funcs = {t.task.task_id: func for t, func in registry.rtc_runners.iteritems()} func = id_funcs.get(rtc.task.task_id, None) if func is None: rcode = 1 log.error("Unknown tool contract id '{x}' Registered TC ids {i}".format(x=rtc.task.task_id, i=id_funcs.keys())) log.error(exit_msg(rcode)) return rcode else: log.info("Running id:{i} Resolved Tool Contract {r}".format(r=rtc, i=rtc.task.task_id)) log.info("Runner func {f}".format(f=func)) exit_code = func(rtc) if exit_code == 0: log.info(exit_msg(exit_code)) else: log.error(exit_msg(exit_code)) return exit_code
def test_validate_resolved_tool_contracts(self): for path in _get_all_from(DATA_DIR, _filter_rtc): f = _to_assertion(path, validate_rtc) f(self) self.assertIsInstance(load_resolved_tool_contract_from(path), ResolvedToolContract)
def test_run_e2e(self): # hack to skip running the base Test class (which is the nose default behavior) if self.__class__.__name__ in ('PbTestApp', 'PbTestScatterApp', 'PbTestGatherApp'): return if self.REQUIRES_PBCORE: if not HAS_PBCORE: self.assertTrue( True, pbcore_skip_msg("Skipping running e2e for {d}".format( d=self.DRIVER_EMIT))) return output_dir = get_temp_dir(suffix="rtc-test") tmp_dir = get_temp_dir(suffix="rtc-temp") log.debug("Driver {e}".format(e=self.DRIVER_EMIT)) log.debug("input files {i}".format(i=self.INPUT_FILES)) log.debug("running in {p}".format(p=output_dir)) output_tc = get_temp_file( "-{n}-tool_contract.json".format(n=self.__class__.__name__), output_dir) emit_tc_exe = "{e} > {o}".format(e=self.DRIVER_EMIT, o=output_tc) rcode = subprocess.call([emit_tc_exe], shell=True) self.assertEquals( rcode, 0, "Emitting tool contract failed for '{e}'".format(e=emit_tc_exe)) # sanity marshall-unmashalling log.debug("Loading tool-contract from {p}".format(p=output_tc)) tc = load_tool_contract_from(output_tc) log.info("Resolving tool contract to RTC") rtc = self._to_rtc(tc, output_dir, tmp_dir) output_json_rtc = get_temp_file("resolved_tool_contract.json", output_dir) write_resolved_tool_contract(rtc, output_json_rtc) # sanity loaded_rtc = load_resolved_tool_contract_from(output_json_rtc) self.assertIsInstance(loaded_rtc, ResolvedToolContract) # Test Resolved options if specified. for opt, resolved_value in self.RESOLVED_TASK_OPTIONS.iteritems(): self.assertTrue( opt in rtc.task.options, "Resolved option {x} not in RTC options.".format(x=opt)) # this needs to support polymorphic equals (i.e., almostEquals if not isinstance(resolved_value, float): emsg = "Resolved option {o} are not equal. Expected {a}, got {b}".format( o=opt, b=rtc.task.options[opt], a=resolved_value) self.assertEquals(rtc.task.options[opt], resolved_value, emsg) # Resolved NPROC self.assertEquals(rtc.task.nproc, self.RESOLVED_NPROC) self.assertEquals(rtc.task.is_distributed, self.RESOLVED_IS_DISTRIBUTED) log.info("running resolved contract {r}".format(r=output_json_rtc)) exe = "{d} {p}".format(p=output_json_rtc, d=self.DRIVER_RESOLVE) log.info("Running exe '{e}'".format(e=exe)) with tempfile.TemporaryFile() as stdout: rcode = subprocess.call([exe], shell=True, stdout=stdout) self.assertEquals( rcode, 0, "Running from resolved tool contract failed from {x}".format( x=exe)) log.info("Successfully completed running e2e for {d}".format( d=self.DRIVER_EMIT)) self._test_outputs_exists(rtc) self.run_after(rtc, output_dir)
def test_validate_resolved_tool_contracts(self): for path in _get_all_from(DATA_DIR, _filter_rtc): f = _to_assertion(path, validate_rtc) f(self) self.assertIsInstance(load_resolved_tool_contract_from(path), ResolvedToolContract)
def test_validate_resolved_tool_contracts(self): for path in walker(DATA_DIR_RTC, json_filter): f = _to_assertion(path, validate_rtc) f(self) self.assertIsInstance(load_resolved_tool_contract_from(path), ResolvedToolContract)
def test_validate_resolved_tool_contracts(self): for path in walker(DATA_DIR_RTC, json_filter): f = _to_assertion(path, validate_rtc) f(self) self.assertIsInstance(load_resolved_tool_contract_from(path), ResolvedToolContract)