Ejemplo n.º 1
0
    def testAutologin(self):
        from Exscript.util.decorator import autologin

        job = FakeJob()
        host = job.data["host"]
        conn = job.data["conn"] = FakeConnection()

        # Test simple login.
        decor = autologin(flush=False)
        bound = decor(self.autologin_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.login = partial(fail, data)

        # Test retry functionality.
        decor = autologin(flush=False, attempts=5)
        bound = decor(self.autologin_cb)
        job = FakeJob()
        job.data["conn"] = conn
        self.assertRaises(LoginFailure, bound, job, host, conn, "one", "two", three=3)
        self.assertEqual(data.value, 5)
Ejemplo n.º 2
0
    def testAutologin(self):
        from Exscript.util.decorator import autologin
        job  = FakeJob()
        host = job.data['host']
        conn = job.data['conn'] = FakeConnection()

        # Test simple login.
        decor  = autologin(flush = False)
        bound  = decor(self.autologin_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.login = partial(fail, data)

        # Test retry functionality.
        decor = autologin(flush = False, attempts = 5)
        bound = decor(self.autologin_cb)
        job   = FakeJob()
        job.data['conn'] = conn
        self.assertRaises(LoginFailure,
                          bound,
                          job,
                          host,
                          conn,
                          'one',
                          'two',
                          three = 3)
        self.assertEqual(data.value, 5)
Ejemplo n.º 3
0
def quickstart(hosts, func, **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  kwargs: dict
    @param kwargs: Passed to the Exscript.Queue constructor.
    """
    quickrun(hosts, autologin()(func), **kwargs)
Ejemplo n.º 4
0
def start(users, hosts, func, **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  kwargs: dict
    @param kwargs: Passed to the Exscript.Queue constructor.
    """
    run(users, hosts, autologin()(func), **kwargs)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)