From b5741ddad9a27f8b325ee679ccd6d2b90cc38d2e Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Wed, 23 Sep 2020 15:57:09 +0100 Subject: [PATCH 1/6] First attempt at allowing users to log board problems with spalloc --- spalloc/protocol_client.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spalloc/protocol_client.py b/spalloc/protocol_client.py index 0dd65599e..cb6c30f0d 100644 --- a/spalloc/protocol_client.py +++ b/spalloc/protocol_client.py @@ -426,6 +426,20 @@ def get_board_at_position(self, machine_name, x, y, z, return self.call("get_board_at_position", machine_name, x, y, z, timeout=timeout) + def report_problem_board(self, board_ip, timeout=None): + return self.call("report_problem", str(board_ip), + timeout=timeout) + + def report_problem_chip(self, board_ip, x, y, timeout=None): + # pylint: disable=too-many-arguments + return self.call("report_problem", str(board_ip), x=int(x), y=int(y), + timeout=timeout) + + def report_problem_core(self, board_ip, x, y, p, timeout=None): + return self.call( + "report_problem", str(board_ip), x=int(x), y=int(y), p=int(p), + timeout=timeout) + _acceptable_kwargs_for_where_is = frozenset([ frozenset("machine x y z".split()), frozenset("machine cabinet frame board".split()), From e86701a1ac39b8a6202603308a097d091b98fd9c Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Fri, 25 Sep 2020 15:09:47 +0100 Subject: [PATCH 2/6] Factor out the timestamp formatting, remove pytz usage All part of stabilizing the build --- setup.py | 1 - spalloc/_utils.py | 11 +++++++++++ spalloc/scripts/job.py | 9 ++------- spalloc/scripts/ps.py | 9 ++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 6598c3464..3a1a0cf2a 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ install_requires=["six>=1.8.0", "appdirs", "enum-compat", - "pytz", "tzlocal", "future"], # Scripts diff --git a/spalloc/_utils.py b/spalloc/_utils.py index 1efb1c13d..de2e4726f 100644 --- a/spalloc/_utils.py +++ b/spalloc/_utils.py @@ -13,7 +13,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from datetime import datetime, timezone import time +from tzlocal import get_localzone def time_left(timestamp): @@ -38,3 +40,12 @@ def make_timeout(delay_seconds): if delay_seconds is None: return None return time.time() + delay_seconds + + +def render_timestamp(timestamp): + """ Convert a timestamp (Unix seconds) into a local human-readable\ + timestamp string. + """ + utc_timestamp = datetime.fromtimestamp(timestamp, timezone.utc) + local_timestamp = utc_timestamp.astimezone(get_localzone()) + return local_timestamp.strftime('%d/%m/%Y %H:%M:%S') diff --git a/spalloc/scripts/job.py b/spalloc/scripts/job.py index 02f6af828..154170171 100644 --- a/spalloc/scripts/job.py +++ b/spalloc/scripts/job.py @@ -76,14 +76,12 @@ """ import argparse from collections import OrderedDict -import datetime import sys -from pytz import utc -from tzlocal import get_localzone from six import iteritems from spalloc import __version__, JobState from spalloc.term import ( Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES) +from spalloc._utils import render_timestamp from .support import Terminate, Script @@ -131,10 +129,7 @@ def show_job_info(t, client, timeout, job_id): info["Owner"] = job["owner"] info["State"] = _state_name(job) if job["start_time"] is not None: - utc_timestamp = datetime.datetime.fromtimestamp( - job["start_time"], utc) - local_timestamp = utc_timestamp.astimezone(get_localzone()) - info["Start time"] = local_timestamp.strftime('%d/%m/%Y %H:%M:%S') + info["Start time"] = render_timestamp(job["start_time"]) info["Keepalive"] = job["keepalive"] if "keepalivehost" in job and job["keepalivehost"] is not None: info["Owner host"] = job["keepalivehost"] diff --git a/spalloc/scripts/ps.py b/spalloc/scripts/ps.py index 60d7843a0..ddade5122 100644 --- a/spalloc/scripts/ps.py +++ b/spalloc/scripts/ps.py @@ -26,12 +26,10 @@ ``--machine`` arguments. """ import argparse -import datetime import sys -from pytz import utc -from tzlocal import get_localzone from spalloc import __version__, JobState from spalloc.term import Terminal, render_table +from spalloc._utils import render_timestamp from .support import Script @@ -90,10 +88,7 @@ def render_job_list(t, jobs, args): num_boards = "" if job["boards"] is None else len(job["boards"]) # Format start time - utc_timestamp = datetime.datetime.fromtimestamp( - job["start_time"], utc) - local_timestamp = utc_timestamp.astimezone(get_localzone()) - timestamp = local_timestamp.strftime('%d/%m/%Y %H:%M:%S') + timestamp = render_timestamp(job["start_time"]) if job["allocated_machine_name"] is not None: machine_name = job["allocated_machine_name"] From 42da498c206349ab010f806c3c3bc256e6b72d92 Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Fri, 25 Sep 2020 15:13:29 +0100 Subject: [PATCH 3/6] *sigh* --- requirements.txt | 3 +-- setup.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 95bea4840..26e04d145 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,6 +16,5 @@ six>=1.8.0 appdirs enum-compat -pytz -tzlocal +tzlocal<3 future diff --git a/setup.py b/setup.py index 3a1a0cf2a..ae6e17cfd 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ install_requires=["six>=1.8.0", "appdirs", "enum-compat", - "tzlocal", + "tzlocal<3", "future"], # Scripts entry_points={ From 7c2b8bacf5a44d8123309733689b5e8c14519154 Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Fri, 25 Sep 2020 15:39:24 +0100 Subject: [PATCH 4/6] Py2.7 has a different way of doing timezones --- spalloc/_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spalloc/_utils.py b/spalloc/_utils.py index de2e4726f..fe76228bd 100644 --- a/spalloc/_utils.py +++ b/spalloc/_utils.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from datetime import datetime, timezone +from datetime import datetime import time from tzlocal import get_localzone @@ -46,6 +46,6 @@ def render_timestamp(timestamp): """ Convert a timestamp (Unix seconds) into a local human-readable\ timestamp string. """ - utc_timestamp = datetime.fromtimestamp(timestamp, timezone.utc) + utc_timestamp = datetime.utcfromtimestamp(timestamp) local_timestamp = utc_timestamp.astimezone(get_localzone()) return local_timestamp.strftime('%d/%m/%Y %H:%M:%S') From 8ddc29c71bac7f3cbc384594c994f014111e5610 Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Fri, 25 Sep 2020 16:58:09 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Turns=20out=E2=80=A6=20don't=20need=20tzloc?= =?UTF-8?q?al=20either!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - setup.py | 1 - spalloc/_utils.py | 5 +---- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 26e04d145..58f3a7fe4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,4 @@ six>=1.8.0 appdirs enum-compat -tzlocal<3 future diff --git a/setup.py b/setup.py index ae6e17cfd..041f69331 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ install_requires=["six>=1.8.0", "appdirs", "enum-compat", - "tzlocal<3", "future"], # Scripts entry_points={ diff --git a/spalloc/_utils.py b/spalloc/_utils.py index fe76228bd..d627fd8d0 100644 --- a/spalloc/_utils.py +++ b/spalloc/_utils.py @@ -15,7 +15,6 @@ from datetime import datetime import time -from tzlocal import get_localzone def time_left(timestamp): @@ -46,6 +45,4 @@ def render_timestamp(timestamp): """ Convert a timestamp (Unix seconds) into a local human-readable\ timestamp string. """ - utc_timestamp = datetime.utcfromtimestamp(timestamp) - local_timestamp = utc_timestamp.astimezone(get_localzone()) - return local_timestamp.strftime('%d/%m/%Y %H:%M:%S') + return datetime.fromtimestamp(timestamp).strftime("%d/%m/%Y %H:%M:%S") From 2338234885e3821791e37bfceb94f038d5729839 Mon Sep 17 00:00:00 2001 From: Donal Fellows Date: Tue, 29 Sep 2020 12:31:50 +0100 Subject: [PATCH 6/6] Allow problem reports to be routed via Job --- spalloc/job.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spalloc/job.py b/spalloc/job.py index 540c5fe49..de9c86b8b 100644 --- a/spalloc/job.py +++ b/spalloc/job.py @@ -720,6 +720,13 @@ def where_is_machine(self, chip_x, chip_y): raise ValueError("received None instead of machine location") return result['physical'] + def report_problem_board(self, ip_address): + """ Reports a previously-unknown problem with an allocated board. + + :param str ip_address: + """ + self._client.report_problem_board(ip_address) + class StateChangeTimeoutError(Exception): """ Thrown when a state change takes too long to occur.