def run_job(credential, gjfstring, jobstring=None, **kwargs): results = { "jobid": None, "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: jobid, error = _run_job(ssh, sftp, gjfstring, jobstring, **kwargs) results["jobid"] = jobid results["error"] = error if not error: job = Job( credential=credential, jobid=jobid, **kwargs ) job.save() return results
def run_job(credential, gjfstring, jobstring=None, **kwargs): results = { "jobid": None, "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: jobid, error = _run_job(ssh, sftp, gjfstring, jobstring, **kwargs) results["jobid"] = jobid results["error"] = error if not error: job = Job(credential=credential, jobid=jobid, **kwargs) job.save() return results
def run_jobs(credential, names, gjfstrings, jobstring=None, **kwargs): results = { "worked": [], "failed": [], "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results jobs = [] with ssh, sftp: for name, gjf in zip(names, gjfstrings): dnew = kwargs.copy() dnew["name"] = re.sub( r"{{\s*name\s*}}", name, dnew.get("name", "{{ name }}")) jobid, error = _run_job(ssh, sftp, gjf, jobstring, **dnew) if error is None: results["worked"].append((name, jobid)) job = Job( credential=credential, molecule=name, jobid=jobid, **dnew ) jobs.append(job) else: results["failed"].append((name, error)) Job.objects.bulk_create(jobs) return results
def run_jobs(credential, names, gjfstrings, jobstring=None, **kwargs): results = { "worked": [], "failed": [], "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results jobs = [] with ssh, sftp: for name, gjf in zip(names, gjfstrings): dnew = kwargs.copy() dnew["name"] = re.sub(r"{{\s*name\s*}}", name, dnew.get("name", "{{ name }}")) jobid, error = _run_job(ssh, sftp, gjf, jobstring, **dnew) if error is None: results["worked"].append((name, jobid)) job = Job(credential=credential, molecule=name, jobid=jobid, **dnew) jobs.append(job) else: results["failed"].append((name, error)) Job.objects.bulk_create(jobs) return results
def test_get_ssh_connection_obj_fail(self): obj = [] with self.assertRaises(TypeError): utils.get_ssh_connection_obj(obj)
def test_get_ssh_connection_obj_SSHClient(self): ssh = self.credential.get_ssh_connection() self.assertEqual(utils.get_ssh_connection_obj(ssh), ssh)
def test_get_ssh_connection_obj(self): ssh = self.credential.get_ssh_connection() self.assertTrue(isinstance(ssh, SSHClient)) obj = utils.get_ssh_connection_obj(self.credential) self.assertTrue(isinstance(obj, SSHClient))