Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
 def test_get_ssh_connection_obj_fail(self):
     obj = []
     with self.assertRaises(TypeError):
         utils.get_ssh_connection_obj(obj)
Example #6
0
 def test_get_ssh_connection_obj_SSHClient(self):
     ssh = self.credential.get_ssh_connection()
     self.assertEqual(utils.get_ssh_connection_obj(ssh), ssh)
Example #7
0
 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))
Example #8
0
 def test_get_ssh_connection_obj_fail(self):
     obj = []
     with self.assertRaises(TypeError):
         utils.get_ssh_connection_obj(obj)
Example #9
0
 def test_get_ssh_connection_obj_SSHClient(self):
     ssh = self.credential.get_ssh_connection()
     self.assertEqual(utils.get_ssh_connection_obj(ssh), ssh)
Example #10
0
 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))