Skip to content

Commit

Permalink
Merge pull request #1746 from buildtesters/change_pbs_and_torque_poll…
Browse files Browse the repository at this point in the history
…_commands_and_jobdata

Change Poll commands for PBS and Torque and add support for retrieving job data
  • Loading branch information
shahzebsiddiqui authored Apr 4, 2024
2 parents 04581b4 + 9210482 commit b79dd92
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
1 change: 0 additions & 1 deletion buildtest/buildsystem/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ def _skip_tests_by_tags(self, recipe, name):
if not recipe.get("tags"):
return True

found = False
# the input tag names from test can be list or string
tests_in_tags = recipe["tags"]
# if input is string, convert to list otherwise we assume its a list
Expand Down
38 changes: 29 additions & 9 deletions buildtest/scheduler/pbs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import os
import re
Expand All @@ -15,6 +16,8 @@ class PBSJob(Job):
to poll job state, gather job results upon completion and cancel job.
"""

poll_command = "qstat -xf"

def __init__(self, jobID):
self._outfile = None
self._errfile = None
Expand Down Expand Up @@ -54,7 +57,7 @@ def fail(self):

def get_output_error_files(self):
"""Fetch output and error files right after job submission."""
query = f"qstat -f {self.jobid}"
query = f"{self.poll_command} {self.jobid}"
cmd = BuildTestCommand(query)
cmd.execute()
output = " ".join(cmd.get_output())
Expand Down Expand Up @@ -198,7 +201,7 @@ def poll(self):
copy_on_rerun = False
"""
query = f"qstat -f {self.jobid}"
query = f"{self.poll_command} {self.jobid}"

logger.debug(f"Polling job by running: {query}")
cmd = BuildTestCommand(query)
Expand Down Expand Up @@ -252,14 +255,16 @@ def retrieve_jobdata(self):
for getting output file, error file and exit status of job.
"""

# job_data = json.loads(output)
query = f"{self.poll_command} -F json {self.jobid}"
logger.debug(f"Retrieving job data by running: {query}")
cmd = BuildTestCommand(query)
cmd.execute()
output = " ".join(cmd.get_output())
job_data = json.loads(output)

# output in the form of pbs:<path>
# self._outfile = job_data["Jobs"][self.jobid]["Output_Path"].split(":")[1]
# self._errfile = job_data["Jobs"][self.jobid]["Error_Path"].split(":")[1]
logger.debug(f"Retrieved job data for job: {self.jobid}:\n{job_data}")

# self._exitcode = self._get_exitcode()
return {}
return job_data

def cancel(self):
"""Cancel PBS job by running ``qdel <jobid>``."""
Expand All @@ -270,4 +275,19 @@ def cancel(self):


class TorqueJob(PBSJob):
pass

poll_command = "qstat -f"

def retrieve_jobdata(self):
"""This method is called once job is complete. We will gather record of job by running
`qstat -f <jobid>` and return the output as a string.
"""
query = f"{self.poll_command} {self.jobid}"
logger.debug(f"Retrieving job data by running: {query}")
cmd = BuildTestCommand(query)
cmd.execute()
output = " ".join(cmd.get_output())

logger.debug(f"Retrieved job data for job: {self.jobid}:\n{output}")

return output
7 changes: 4 additions & 3 deletions tests/test_pbs.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import os
import shutil

import pytest

from buildtest.cli.build import BuildTest
from buildtest.config import SiteConfiguration
from buildtest.scheduler.detection import PBS
from buildtest.system import BuildTestSystem
from buildtest.utils.file import walk_tree


def test_pbs():
"""Need to figure out a PBS environment where to run this regression test."""
if not shutil.which("pbsnodes"):
pytest.skip("Test runs only on PBS Cluster, must have pbsnodes command")
pbs = PBS()
if not pbs.active():
pytest.skip("Test runs only on PBS Cluster")

here = os.path.dirname(os.path.abspath(__file__))
settings_file = os.path.join(here, "settings", "pbs.yml")
Expand Down

0 comments on commit b79dd92

Please sign in to comment.