Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompResourcesWidget: do not raise when computer test fails #506

Merged
merged 6 commits into from
Sep 8, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def observe_memory_per_machine(change):
self.setup_button.on_click(self.on_setup_computer)
test_button = ipw.Button(description="Test computer")
test_button.on_click(self.test)
self._test_out = ipw.Output(layout=LAYOUT)
self._test_out = ipw.HTML(layout=LAYOUT)

# Organize the widgets
children = [
Expand Down Expand Up @@ -884,14 +884,18 @@ def _configure_computer_local(self, computer: orm.Computer, user: orm.User):

def _run_callbacks_if_computer_exists(self, label):
"""Run things on an existing computer"""
try:
orm.Computer.objects.get(label=label)
if self._computer_exists(label):
for function in self._on_setup_computer_success:
function()
return True
return False

def _computer_exists(self, label):
try:
orm.Computer.objects.get(label=label)
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved
except common.NotExistent:
return False
else:
return True
return True

def _validate_computer_settings(self):
if self.label.value == "": # check computer label
Expand Down Expand Up @@ -963,13 +967,30 @@ def on_setup_computer_success(self, function):
self._on_setup_computer_success.append(function)

def test(self, _=None):
with self._test_out:
clear_output()
print(
subprocess.check_output(
["verdi", "computer", "test", "--print-traceback", self.label.value]
).decode("utf-8")
if self.label.value == "":
self._test_out.value = "Please specify the computer name (for AiiDA)."
return False
elif not self._computer_exists(self.label.value):
self._test_out.value = (
f"A computer called <b>{self.label.value}</b> does not exist."
)
return False

process_result = subprocess.run(
yakutovicha marked this conversation as resolved.
Show resolved Hide resolved
["verdi", "computer", "test", "--print-traceback", self.label.value],
capture_output=True,
)

if process_result.returncode == 0:
self._test_out.value = process_result.stdout.decode("utf-8").replace(
"\n", "<br>"
)
return True
else:
self._test_out.value = process_result.stderr.decode("utf-8").replace(
"\n", "<br>"
)
return False

def _reset(self):
self.label.value = ""
Expand Down
Loading