Skip to content

Commit

Permalink
fix Job.working_dir behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
BerndSchuller committed Nov 8, 2024
1 parent 247d35c commit 622f718
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ Changelog for PyUNICORE

Issue tracker: https://github.com/HumanBrainProject/pyunicore

Version 1.2.0 (MMM dd, 2024)
Version 1.2.0 (Nov 08, 2024)
----------------------------

- UFTP FUSE driver: add '--read-only' option
- New feature: commandline client script 'unicore' with a number
of commands modeled after the 'ucc' commandline client
- fix: the Job.working_dir function was hanging in case the working
directory could not be created

Version 1.1.1 (Oct 01, 2024)
----------------------------
Expand Down
6 changes: 4 additions & 2 deletions pyunicore/cli/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
""" Base command class """

from __future__ import annotations

import argparse
Expand Down Expand Up @@ -122,6 +120,8 @@ def human_readable(self, value, decimals=0):


class IssueToken(Base):
"""Get an authentication token from a UNICORE server"""

def add_command_args(self):
self.parser.prog = "unicore issue-token"
self.parser.description = self.get_synopsis()
Expand Down Expand Up @@ -204,6 +204,8 @@ def show_token_details(self, token: str):


class REST(Base):
"""Low-level REST API operations (GET, PUT, POST, DELETE)"""

def add_command_args(self):
self.parser.prog = "unicore rest"
self.parser.description = self.get_synopsis()
Expand Down
14 changes: 13 additions & 1 deletion pyunicore/cli/exec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Exec and related commands """
from __future__ import annotations

import json

Expand All @@ -9,6 +9,7 @@


class JobExecutionBase(Base):
"""Base class for job execution commands"""

def add_command_args(self):
self.parser.add_argument("-s", "--sitename", required=False, type=str, help="Site name")
Expand Down Expand Up @@ -80,6 +81,8 @@ def fetch_output(self, job: Job):


class Exec(JobExecutionBase):
"""Execute a non batch command (i.e. on a login node)"""

def add_command_args(self):
super().add_command_args()
self.parser.prog = "unicore exec"
Expand Down Expand Up @@ -131,6 +134,7 @@ def run(self, args):


class Run(JobExecutionBase):
"""Run a UNICORE job"""

def add_command_args(self):
super().add_command_args()
Expand Down Expand Up @@ -174,6 +178,8 @@ def run(self, args):


class ListJobs(Base):
"""List UNICORE jobs"""

def add_command_args(self):
self.parser.prog = "unicore list-jobs"
self.parser.description = self.get_synopsis()
Expand Down Expand Up @@ -224,6 +230,8 @@ def run(self, args):


class CancelJob(Base):
"""Cancel a UNICORE job"""

def add_command_args(self):
self.parser.prog = "unicore cancel-job"
self.parser.description = self.get_synopsis()
Expand All @@ -246,6 +254,10 @@ def run(self, args):


class GetJobStatus(Base):
"""Get the status of a UNICORE job. Also, allow to wait for the job to reach
a certain state.
"""

def add_command_args(self):
self.parser.prog = "unicore job-status"
self.parser.description = self.get_synopsis()
Expand Down
9 changes: 8 additions & 1 deletion pyunicore/cli/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Storage-related commands """
from __future__ import annotations

import fnmatch
import os
Expand All @@ -13,6 +13,7 @@


class IOBase(Base):
"""Base class for storage related commands"""

def get_group(self):
return "Data management"
Expand All @@ -33,6 +34,8 @@ def parse_location(self, location: str):


class LS(IOBase):
"""List remote directories"""

def add_command_args(self):
self.parser.prog = "unicore ls"
self.parser.description = self.get_synopsis()
Expand Down Expand Up @@ -80,6 +83,8 @@ def run(self, args):


class CP(IOBase):
"""Copy file(s)"""

def add_command_args(self):
self.parser.prog = "unicore cp"
self.parser.description = self.get_synopsis()
Expand Down Expand Up @@ -131,6 +136,8 @@ def run(self, args):


class Cat(IOBase):
"""Print a remote file to standard output"""

def add_command_args(self):
self.parser.prog = "unicore cat"
self.parser.description = self.get_synopsis()
Expand Down
3 changes: 2 additions & 1 deletion pyunicore/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
""" Main client class """
from __future__ import annotations

import platform
import sys

import pyunicore.cli.base
import pyunicore.cli.exec
import pyunicore.cli.info
import pyunicore.cli.io

_commands = {
Expand Down
24 changes: 15 additions & 9 deletions pyunicore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ def __init__(
def working_dir(self):
"""return the Storage for accessing this job's working directory"""
wd = Storage(self.transport, self.links["workingDirectory"])
wd._wait_until_ready()
if self.is_running():
wd._wait_until_ready(timeout=self.transport.timeout)
return wd

@property
Expand Down Expand Up @@ -687,16 +688,21 @@ def __init__(
):
super().__init__(security, storage_url, cache_time)

def _wait_until_ready(self, timeout=-1):
"""since some storages take some time to initialise, this method allows to wait
until the storage is READY
def _wait_until_ready(self, timeout=30):
"""since some storages take some time to initialise, this method attempts to wait
until the storage is READY. If the storage does not become "READY" in the
given time, or the storage reports an "ERROR" status, an IOError is raised
"""
i = 0
while "READY" != self.properties.get("resourceStatus", "n/a"):
time.sleep(1)
i += 1
if timeout > 0 and i > timeout:
raise TimeoutError()
while True:
st = self.properties.get("resourceStatus", "n/a")
if st == "READY":
break
if "INITIALIZING" == st:
time.sleep(1)
i += 1
if "ERROR" == st or (timeout > 0 and i > timeout):
raise OSError()

def _to_file_url(self, path):
return (
Expand Down

0 comments on commit 622f718

Please sign in to comment.