def test_get_transport(self): """ Test the get_transport method of Computer """ import tempfile new_comp = orm.Computer(label='bbb', hostname='localhost', transport_type='local', scheduler_type='direct', workdir='/tmp/aiida').store() # Configure the computer - no parameters for local transport authinfo = orm.AuthInfo(computer=new_comp, user=orm.User.objects.get_default()) authinfo.store() transport = new_comp.get_transport() # It's on localhost, so I see files that I create with transport: with tempfile.NamedTemporaryFile() as handle: self.assertEqual(transport.isfile(handle.name), True) # Here the file should have been deleted self.assertEqual(transport.isfile(handle.name), False)
def _configure_computer(self): """Create AuthInfo.""" sshcfg = parse_sshconfig(self.hostname.value) authparams = { "compress": True, "key_filename": os.path.expanduser( sshcfg.get("identityfile", ["~/.ssh/id_rsa"])[0]), "gss_auth": False, "gss_deleg_creds": False, "gss_host": self.hostname.value, "gss_kex": False, "key_policy": "WarningPolicy", "load_system_host_keys": True, "port": sshcfg.get("port", 22), "timeout": 60, "use_login_shell": self.use_login_shell.value, "safe_interval": self.safe_interval.value, } if "user" in sshcfg: authparams["username"] = sshcfg["user"] else: print( f"SSH username is not provided, please run `verdi computer configure {self.label.value}` " "from the command line.") return False if "proxycommand" in sshcfg: authparams["proxy_command"] = sshcfg["proxycommand"] elif "proxyjump" in sshcfg: authparams["proxy_jump"] = sshcfg["proxyjump"] aiidauser = orm.User.objects.get_default() authinfo = orm.AuthInfo( computer=orm.Computer.objects.get(label=self.label.value), user=aiidauser) authinfo.set_auth_params(authparams) authinfo.store() return True
def get_default(ctx): """Determine the default value from the context.""" from aiida import orm user = ctx.params['user'] or orm.User.objects.get_default() computer = ctx.params['computer'] try: authinfo = orm.AuthInfo.objects.get(dbcomputer_id=computer.id, aiidauser_id=user.id) except NotExistent: authinfo = orm.AuthInfo(computer=computer, user=user) non_interactive = ctx.params['non_interactive'] old_authparams = authinfo.get_auth_params() if not also_noninteractive and non_interactive: raise click.MissingParameter() suggestion = old_authparams.get(key) suggestion = suggestion or transport_option_default(key, computer) return suggestion
def setUpClass(cls): # pylint: disable=arguments-differ super().setUpClass() user = orm.User.objects.get_default() orm.AuthInfo(cls.computer, user).store()
def setUp(self, *args, **kwargs): # pylint: disable=arguments-differ """ Set up a simple authinfo and for later use """ super().setUp(*args, **kwargs) self.authinfo = orm.AuthInfo( computer=self.computer, user=orm.User.objects.get_default()).store()
def setUpClass(cls): super(TestVerdiDataRemote, cls).setUpClass() user = orm.User.objects.get_default() orm.AuthInfo(cls.computer, user).store()
def setUpClass(cls, *args, **kwargs): super().setUpClass(*args, **kwargs) from aiida.common.links import LinkType from aiida.engine import ProcessState cls.computer = orm.Computer(name='comp', hostname='localhost', transport_type='local', scheduler_type='direct', workdir='/tmp/aiida').store() cls.code = orm.Code(remote_computer_exec=(cls.computer, '/bin/true')).store() cls.group = orm.Group(label='test_group').store() cls.node = orm.Data().store() cls.calcs = [] user = orm.User.objects.get_default() authinfo = orm.AuthInfo(computer=cls.computer, user=user) authinfo.store() process_class = CalculationFactory('templatereplacer') process_type = get_entry_point_string_from_class( process_class.__module__, process_class.__name__) # Create 5 CalcJobNodes (one for each CalculationState) for calculation_state in CalcJobState: calc = orm.CalcJobNode(computer=cls.computer, process_type=process_type) calc.set_option('resources', { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }) calc.store() calc.set_process_state(ProcessState.RUNNING) cls.calcs.append(calc) if calculation_state == CalcJobState.PARSING: cls.KEY_ONE = 'key_one' cls.KEY_TWO = 'key_two' cls.VAL_ONE = 'val_one' cls.VAL_TWO = 'val_two' output_parameters = orm.Dict(dict={ cls.KEY_ONE: cls.VAL_ONE, cls.KEY_TWO: cls.VAL_TWO, }).store() output_parameters.add_incoming(calc, LinkType.CREATE, 'output_parameters') # Create shortcut for easy dereferencing cls.result_job = calc # Add a single calc to a group cls.group.add_nodes([calc]) # Create a single failed CalcJobNode cls.EXIT_STATUS = 100 calc = orm.CalcJobNode(computer=cls.computer) calc.set_option('resources', { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 }) calc.store() calc.set_exit_status(cls.EXIT_STATUS) calc.set_process_state(ProcessState.FINISHED) cls.calcs.append(calc) # Load the fixture containing a single ArithmeticAddCalculation node import_archive('calcjob/arithmetic.add.aiida') # Get the imported ArithmeticAddCalculation node ArithmeticAddCalculation = CalculationFactory('arithmetic.add') calculations = orm.QueryBuilder().append( ArithmeticAddCalculation).all()[0] cls.arithmetic_job = calculations[0]
def setUpClass(cls, *args, **kwargs): """Set up a simple authinfo and for later use.""" super().setUpClass(*args, **kwargs) cls.authinfo = orm.AuthInfo(computer=cls.computer, user=orm.User.objects.get_default()) cls.authinfo.store()
def setUp(self, *args, **kwargs): """ Set up a simple authinfo and for later use """ super(TestTransportQueue, self).setUp(*args, **kwargs) self.authinfo = orm.AuthInfo(computer=self.computer, user=orm.User.objects.get_default()).store()