def testAutoauthenticate(self): from Exscript.util.decorator import autoauthenticate job = FakeJob() host = job.data['host'] conn = job.data['conn'] = FakeConnection() # Test simple authentication. decor = autoauthenticate(flush = False) bound = decor(self.autoauthenticate_cb) result = bound(job, host, conn, 'one', 'two', three = 3) self.assertEqual(result, 123) # Monkey patch the fake connection such that the login fails. conn = FakeConnection() data = Value('i', 0) def fail(data, *args, **kwargs): data.value += 1 raise LoginFailure('intended login failure') conn.authenticate = partial(fail, data) # Test retry functionality. decor = autoauthenticate(flush = False, attempts = 5) bound = decor(self.autoauthenticate_cb) job = FakeJob() job.data['conn'] = conn self.assertRaises(LoginFailure, bound, job, host, conn, 'one', 'two', three = 3) self.assertEqual(data.value, 5)
def quickstart(hosts, func, only_authenticate=False, **kwargs): """ Like quickrun(), but automatically logs into the host before passing the connection to the callback function. :type hosts: Host|list[Host] :param hosts: A list of Host objects. :type func: function :param func: The callback function. :type only_authenticate: bool :param only_authenticate: don't authorize, just authenticate? :type kwargs: dict :param kwargs: Passed to the Exscript.Queue constructor. """ if only_authenticate: quickrun(hosts, autoauthenticate()(func), **kwargs) else: quickrun(hosts, autologin()(func), **kwargs)
def quickstart(hosts, func, only_authenticate=False, **kwargs): """ Like quickrun(), but automatically logs into the host before passing the connection to the callback function. @type hosts: Host|list[Host] @param hosts: A list of Host objects. @type func: function @param func: The callback function. @type only_authenticate: bool @param only_authenticate: don't authorize, just authenticate? @type kwargs: dict @param kwargs: Passed to the Exscript.Queue constructor. """ if only_authenticate: quickrun(hosts, autoauthenticate()(func), **kwargs) else: quickrun(hosts, autologin()(func), **kwargs)
def start(users, hosts, func, only_authenticate=False, **kwargs): """ Like run(), but automatically logs into the host before passing the host to the callback function. :type users: Account|list[Account] :param users: The account(s) to use for logging in. :type hosts: Host|list[Host] :param hosts: A list of Host objects. :type func: function :param func: The callback function. :type only_authenticate: bool :param only_authenticate: don't authorize, just authenticate? :type kwargs: dict :param kwargs: Passed to the Exscript.Queue constructor. """ if only_authenticate: run(users, hosts, autoauthenticate()(func), **kwargs) else: run(users, hosts, autologin()(func), **kwargs)
def start(users, hosts, func, only_authenticate=False, **kwargs): """ Like run(), but automatically logs into the host before passing the host to the callback function. @type users: Account|list[Account] @param users: The account(s) to use for logging in. @type hosts: Host|list[Host] @param hosts: A list of Host objects. @type func: function @param func: The callback function. @type only_authenticate: bool @param only_authenticate: don't authorize, just authenticate? @type kwargs: dict @param kwargs: Passed to the Exscript.Queue constructor. """ if only_authenticate: run(users, hosts, autoauthenticate()(func), **kwargs) else: run(users, hosts, autologin()(func), **kwargs)