Skip to content

Commit

Permalink
Test for schedulers
Browse files Browse the repository at this point in the history
Test files for each plugin and methods apart from the prepare method
Some minor fixes for problems that arose from testing
  • Loading branch information
jimboid committed Nov 14, 2016
1 parent 5e37787 commit 84a728c
Show file tree
Hide file tree
Showing 22 changed files with 2,270 additions and 69 deletions.
10 changes: 5 additions & 5 deletions Longbow/corelibs/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,9 @@ def main():
"Lightweight Remote Job Submission Tool. Journal of "
"Open Research Software, 4: e1, "
"DOI: http://dx.doi.org/10.5334/jors.95")
LOG.info("Python version: {0}".format(PYTHONVERSION))
LOG.info("Longbow version: {0}".format(LONGBOWVERSION))
LOG.info("Longbow Commandline: {0}".format(commandline))
LOG.info("Python version: %s", PYTHONVERSION)
LOG.info("Longbow version: %s", LONGBOWVERSION)
LOG.info("Longbow Commandline: %s", commandline)

# Hosts - if a filename hasn't been provided default to hosts.conf
if parameters["hosts"] is "":
Expand Down Expand Up @@ -640,7 +640,7 @@ def main():
.format(parameters["job"], os.getcwd(),
os.path.dirname(os.path.realpath(__file__))))

LOG.info("hosts file is: '{0}'".format(parameters["hosts"]))
LOG.info("hosts file is: '%s'", parameters["hosts"])

# ---------------------------------------------------------------------
# Call one of the main methods at the top level of the library.
Expand Down Expand Up @@ -795,7 +795,7 @@ def recovery(recoveryfile):
# Load the jobs recovery file.
if os.path.isfile(jobfile):

LOG.info("Recovery file found at '{0}'".format(jobfile))
LOG.info("Recovery file found at '%s'", jobfile)

_, _, jobs = configuration.loadconfigs(jobfile)

Expand Down
15 changes: 0 additions & 15 deletions Longbow/corelibs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,6 @@ def __init__(self, message, path):
self.path = path


class ProtocolError(Exception):

"""
Unknown protocol exception.
"""

def __init__(self, message, protocol):

# Call the base class constructor.
super(ProtocolError, self).__init__(message)

# Bind the standard outputs.
self.path = protocol


class RemotecopyError(Exception):

"""
Expand Down
25 changes: 14 additions & 11 deletions Longbow/schedulers/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@ def prepare(job):
# Write the PBS script
jobfile.write("#!/bin/bash --login\n")

if job["jobname"] is not "":

# Single job
if int(job["replicates"]) == 1:
# Single job
if int(job["replicates"]) == 1:

jobfile.write("#BSUB -J " + job["jobname"] + "\n")
jobfile.write("#BSUB -J " + job["jobname"] + "\n")

# Job array
elif int(job["replicates"]) > 1:
# Job array
elif int(job["replicates"]) > 1:

jobfile.write("#BSUB -J " + job["jobname"] + "[1-" +
job["replicates"] + "]\n")
jobfile.write("#BSUB -J " + job["jobname"] + "[1-" +
job["replicates"] + "]\n")

if job["queue"] is not "":

Expand Down Expand Up @@ -205,9 +203,14 @@ def status(job):

# Now match the jobid against the list of jobs, extract the line and
# split it into a list
job = [line for line in stdout if job["jobid"] in line][0].split()
for line in stdout:

line = line.split()

if job["jobid"] in line[0]:

jobstate = states[job[2]]
jobstate = states[line[2]]
break

except (IndexError, KeyError):

Expand Down
18 changes: 9 additions & 9 deletions Longbow/schedulers/pbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def prepare(job):
jobfile.write("#!/bin/bash --login\n")

# Job name (if supplied)
if job["jobname"] is not "":

jobfile.write("#PBS -N " + job["jobname"] + "\n")
jobfile.write("#PBS -N " + job["jobname"] + "\n")

# Queue to submit to (if supplied)
if job["queue"] is not "":
Expand Down Expand Up @@ -251,12 +249,14 @@ def status(job):

try:

# Now match the jobid against the list of jobs, extract the line and
# split it into a list
job = [line for line in stdout if job["jobid"] in line][0].split()
for line in stdout:

line = line.split()

if job["jobid"] in line[0]:

# Look up the job state and convert it to Longbow terminology.
jobstate = states[job[9]]
jobstate = states[line[9]]
break

except (IndexError, KeyError):

Expand All @@ -280,7 +280,7 @@ def submit(job):

except exceptions.SSHError as inst:

if "would exceed" and "per-user limit" in inst.stderr:
if "would exceed" in inst.stderr and "per-user limit" in inst.stderr:

raise exceptions.QueuemaxError

Expand Down
15 changes: 9 additions & 6 deletions Longbow/schedulers/sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def prepare(job):
jobfile.write("#!/bin/bash --login\n"
"#$ -cwd -V\n")

if job["jobname"] is not "":

jobfile.write("#$ -N " + job["jobname"] + "\n")
jobfile.write("#$ -N " + job["jobname"] + "\n")

if job["queue"] is not "":

Expand Down Expand Up @@ -196,9 +194,14 @@ def status(job):

# Now match the jobid against the list of jobs, extract the line and
# split it into a list
job = [line for line in stdout if job["jobid"] in line][0].split()
for line in stdout:

line = line.split()

if job["jobid"] in line[0]:

jobstate = states[job[4]]
jobstate = states[line[4]]
break

except (IndexError, KeyError):

Expand All @@ -223,7 +226,7 @@ def submit(job):

except exceptions.SSHError as inst:

if "per user" or "per-user" in inst.stderr:
if "per user" in inst.stderr or "per-user" in inst.stderr:

raise exceptions.QueuemaxError

Expand Down
16 changes: 9 additions & 7 deletions Longbow/schedulers/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def prepare(job):
# Write the SLURM script
jobfile.write("#!/bin/bash --login\n")

# Job name (if supplied)
if job["jobname"] is not "":

jobfile.write("#SBATCH -J " + job["jobname"] + "\n")
jobfile.write("#SBATCH -J " + job["jobname"] + "\n")

# Queue to submit to (if supplied)
if job["queue"] is not "":
Expand Down Expand Up @@ -212,9 +209,14 @@ def status(job):

# Now match the jobid against the list of jobs, extract the line and
# split it into a list
job = [line for line in stdout if job["jobid"] in line][0].split()
for line in stdout:

line = line.split()

if job["jobid"] in line[0]:

jobstate = states[job[4]]
jobstate = states[line[4]]
break

except (IndexError, KeyError):

Expand All @@ -239,7 +241,7 @@ def submit(job):

except exceptions.SSHError as inst:

if "violates" and "job submit limit" in inst.stderr:
if "violates" in inst.stderr and "job submit limit" in inst.stderr:

raise exceptions.QueuemaxError

Expand Down
15 changes: 9 additions & 6 deletions Longbow/schedulers/soge.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def prepare(job):
jobfile.write("#!/bin/bash --login\n"
"#$ -cwd -V\n")

if job["jobname"] is not "":

jobfile.write("#$ -N " + job["jobname"] + "\n")
jobfile.write("#$ -N " + job["jobname"] + "\n")

if job["queue"] is not "":

Expand Down Expand Up @@ -214,9 +212,14 @@ def status(job):

# Now match the jobid against the list of jobs, extract the line and
# split it into a list
job = [line for line in stdout if job["jobid"] in line][0].split()
for line in stdout:

line = line.split()

if job["jobid"] in line[0]:

jobstate = states[job[4]]
jobstate = states[line[4]]
break

except (IndexError, KeyError):

Expand All @@ -241,7 +244,7 @@ def submit(job):

except exceptions.SSHError as inst:

if "per user" or "per-user" in inst.stderr:
if "per user" in inst.stderr or "per-user" in inst.stderr:

raise exceptions.QueuemaxError

Expand Down
78 changes: 78 additions & 0 deletions Tests/unit/schedulers_pbs/test_lsf_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Longbow is Copyright (C) of James T Gebbie-Rayet and Gareth B Shannon 2015.
#
# This file is part of the Longbow software which was developed as part of the
# HECBioSim project (http://www.hecbiosim.ac.uk/).
#
# HECBioSim facilitates and supports high-end computing within the UK
# biomolecular simulation community on resources such as ARCHER.
#
# Longbow is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 2 of the License, or (at your option) any later
# version.
#
# Longbow is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Longbow. If not, see <http://www.gnu.org/licenses/>.

"""
This test module contains tests for the LSF scheduler plugin.
"""

try:

from unittest import mock

except ImportError:

import mock

import pytest

import Longbow.corelibs.exceptions as exceptions
import Longbow.schedulers.lsf as lsf


@mock.patch('Longbow.corelibs.shellwrappers.sendtossh')
def test_delete_test1(mock_ssh):

"""
Test if job id is grabbed.
"""

job = {
"jobid": "12345",
"replicates": "1"
}

mock_ssh.return_value = ("Success", "", 0)

output = lsf.delete(job)

args = mock_ssh.call_args[0][1]

assert output == "Success"
assert " ".join(args) == "bkill 12345"


@mock.patch('Longbow.corelibs.shellwrappers.sendtossh')
def test_delete_except1(mock_ssh):

"""
Test if Queuemax exception is triggered based on output from scheduler.
"""

job = {
"jobid": "12345",
"replicates": "1"
}

mock_ssh.side_effect = exceptions.SSHError(
"Error", ("out", "", 0))

with pytest.raises(exceptions.JobdeleteError):

lsf.delete(job)

0 comments on commit 84a728c

Please sign in to comment.