diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index 819c89daa..1d9959bec 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -839,7 +839,19 @@ def _configure_computer(self, computer: orm.Computer, transport: str): raise common.ValidationError(msg) def _configure_computer_ssh(self, computer: orm.Computer, user: orm.User): - """Configure the computer with SSH transport""" + """Configure the computer with SSH transport + + There are three sources of authparams information: + - the SSH config file + - the computer_configure dictionary + - the default values + + Priority is given to the computer_configure dictionary, then to the SSH config file, then to the default values. + At the moment, there is no overlap between the SSH config file and the computer_configure dictionary. + + The proxyjump and proxycommend can be read from both the SSH config file and the computer_configure dictionary, + since the SSH config file is generated from the computer_configure dictionary in `SshComputerSetup._write_ssh_config`. + """ sshcfg = aiida_ssh_plugin.parse_sshconfig(self.hostname.value) authparams = { "port": int(sshcfg.get("port", 22)), @@ -871,10 +883,19 @@ def _configure_computer_ssh(self, computer: orm.Computer, user: orm.User): message = "SSH username is not provided" raise RuntimeError(message) from exc - if "proxycommand" in sshcfg: - authparams["proxy_command"] = sshcfg["proxycommand"] - elif "proxyjump" in sshcfg: - authparams["proxy_jump"] = sshcfg["proxyjump"] + if "proxy_jump" in self.computer_configure: + authparams["proxy_jump"] = self.computer_configure["proxy_jump"] + + if "proxy_command" in self.computer_configure: + authparams["proxy_command"] = self.computer_configure["proxy_command"] + + if "key_filename" in self.computer_configure: + authparams["key_filename"] = os.path.expanduser( + self.computer_configure["key_filename"] + ) + + if "key_policy" in self.computer_configure: + authparams["key_policy"] = self.computer_configure["key_policy"] computer.configure(user=user, **authparams) return True diff --git a/tests/test_computational_resources.py b/tests/test_computational_resources.py index aa07bf482..29dfbbfa6 100644 --- a/tests/test_computational_resources.py +++ b/tests/test_computational_resources.py @@ -113,6 +113,8 @@ def test_aiida_computer_setup_widget_default(): "proxy_jump": "ela.cscs.ch", "safe_interval": 10, "use_login_shell": True, + "key_filename": "~/.ssh/cscs-key", + "key_policy": "AutoAddPolicy", "username": "aiida", } @@ -124,6 +126,11 @@ def test_aiida_computer_setup_widget_default(): computer = orm.load_computer("daint") assert computer.label == "daint" assert computer.hostname == "daint.cscs.ch" + assert computer.configure().get_auth_params()["proxy_jump"] == "ela.cscs.ch" + assert computer.configure().get_auth_params()["safe_interval"] == 10 + assert computer.configure().get_auth_params()["use_login_shell"] is True + assert computer.configure().get_auth_params()["key_filename"] == "~/.ssh/cscs-key" + assert computer.configure().get_auth_params()["key_policy"] == "AutoAddPolicy" # Reset the widget and check that a few attributes are reset. widget.computer_setup = {}