def POST_simulations_handler(body): examples_dir = '/usr/local/lib/python3.6/site-packages/cis_interface/examples' models_dir = './Models_AMQP' # List of paths to yaml files specifying the models that should be run # TODO: Pull this from POST body instead? # FIXME: temporary hack models = body.models yaml_paths = [] print(models) for model in models: name = model.name path = model.path # Temporary handling for running the examples if name.startswith('example:'): path = examples_dir + '/' + path else: path = models_dir + '/' + path if not path.endswith('.yml'): path = path + '.yml' yaml_paths.append(path) # Run "cisrun" with the given models and capture stdout/stderr f = io.StringIO() try: with redirect_stdout(f): runner.get_runner(yaml_paths).run() except e: print('error: ' + e) return f.getvalue() # TODO: Set model parameters somehow # FIXME: Writing parameters to files on disk doesn't allow for 2+ users # Experiment: Kubernetes Python Client #v1 = client.CoreV1Api() #print("Listing pods with their IPs:") #ret = v1.list_pod_for_all_namespaces(watch=False) #for i in ret.items: # print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name)) # Experiment: Raw Docker # subprocess.check_output(['docker', 'run', '-it', '--rm', '-e', 'RABBIT_NAMESPACE=apiserver', '-e', 'RABBIT_HOST=10.0.0.214', '-e', 'YAML_FILES=' + str(yaml_paths), 'bodom0015/cis_interface']) # Run "cisrun" with the given models with Capturing() as output: try: runner.get_runner(yaml_paths).run() except ValueError as valerr: print('ERROR: ' + valerr) return output
def POST_graphs_handler_v2(body): # List of paths to yaml files specifying the models that should be run # TODO: Pull this from POST body instead? # FIXME: temporary hack yaml = body.yaml base_path = os.path.dirname(os.path.realpath(__file__)) tmp_file_path = base_path + '/manifest.yml' # Write the received YAML to file print(yaml) with open(tmp_file_path, "w+") as f: f.write(yaml) # Run "cisrun" with the given models and capture stdout/stderr f = io.StringIO() try: with redirect_stdout(f): runner.get_runner([tmp_file_path]).run() except Exception as e: print('error: ' + str(e)) # Cleanup temporary manifest file at the end os.unlink(tmp_file_path) print('it worked!?') # Finally, return the stdout of our subprocess return f.getvalue() # TODO: Set model parameters somehow # FIXME: Writing parameters to files on disk doesn't allow for 2+ users # Experiment: Kubernetes Python Client #v1 = client.CoreV1Api() #print("Listing pods with their IPs:") #ret = v1.list_pod_for_all_namespaces(watch=False) #for i in ret.items: # print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name)) # Experiment: Raw Docker # subprocess.check_output(['docker', 'run', '-it', '--rm', '-e', 'RABBIT_NAMESPACE=apiserver', '-e', 'RABBIT_HOST=10.0.0.214', '-e', 'YAML_FILES=' + str(yaml_paths), 'bodom0015/cis_interface']) # Run "cisrun" with the given models with Capturing() as output: try: runner.get_runner(yaml_paths).run() except ValueError as valerr: print('ERROR: ' + valerr) return output
def test_runner_terminate(): r"""Start a runner, then stop it early.""" cr = runner.get_runner([ex_yamls['hello']['python']]) cr.loadDrivers() cr.startDrivers() cr.printStatus() cr.terminate()
def test_get_runner(): r"""Use get_runner to start a run.""" namespace = "test_get_runner_%s" % str(uuid.uuid4) cr = runner.get_runner([ex_yamls['hello']['python']], namespace=namespace) cr.run() cr.sleep()
def cisrun(): r"""Start a run.""" prog = sys.argv[0].split(os.path.sep)[-1] # Print help if '-h' in sys.argv: print('Usage: cisrun [YAMLFILE1] [YAMLFILE2]...') return models = sys.argv[1:] cisRunner = runner.get_runner(models, cis_debug_prefix=prog) try: cisRunner.run() cisRunner.debug("runner returns, exiting") except Exception as ex: cisRunner.pprint("cisrun exception: %s" % type(ex)) print(traceback.format_exc()) print('')
def test_Arunner_interrupt(): r"""Start a runner then stop it with a keyboard interrupt.""" cr = runner.get_runner([ex_yamls['hello']['python']]) if platform._is_win: # pragma: debug cr.debug_log() cr.loadDrivers() cr.startDrivers() cr.set_signal_handler() tools.kill(os.getpid(), signal.SIGINT) tools.kill(os.getpid(), signal.SIGINT) cr.reset_signal_handler() cr.waitModels() cr.closeChannels() cr.cleanup() if platform._is_win: # pragma: debug cr.reset_log()
def run_example(self): r"""This runs an example in the correct language.""" if self.yaml is None: if self.name is not None: warnings.warn("Could not locate example %s in language %s." % (self.name, self.language)) else: os.environ.update(self.env) self.runner = runner.get_runner(self.yaml, namespace=self.namespace) self.runner.run() if self.expects_error: assert(self.runner.error_flag) else: assert(not self.runner.error_flag) self.check_results() self.cleanup()
def test_matlab_runner(): # pragma: matlab r"""Use get_runner to start a Matlab run.""" cr = runner.get_runner([ex_yamls['hello']['matlab']]) cr.run()