Esempio n. 1
0
def test_clone():

    sess = arcomm.Session(HOST, creds=OPS_CREDS)
    sess.connect()
    cloned = sess.clone('other')
    assert cloned.hostname != sess.hostname
    assert cloned._conn != sess._conn
Esempio n. 2
0
def _worker(endpoint, commands, **kwargs):

    creds = None
    protocol = None
    authorize = None

    if "creds" in kwargs:
        creds = kwargs["creds"]
        del(kwargs["creds"])

    if "protocol" in kwargs:
        protocol = kwargs["protocol"]
        del(kwargs["protocol"])

    if "authorize" in kwargs:
        authorize = kwargs["authorize"]
        del(kwargs["authorize"])

    session = arcomm.Session(endpoint, creds=creds, protocol=protocol,
                             authorize=authorize)
    try:
        responses = session.execute(commands, **kwargs)
    except (arcomm.AuthenticationFailed, arcomm.AuthorizationFailed):
        # if we get kicked out of the session... we have to make our own
        # response object... :(
        exc_type, exc_value, _ = sys.exc_info()
        err_type = exc_type.__name__
        error = "[{}] {}".format(err_type, exc_value)
        responses = arcomm.ResponseStore(session, **kwargs)
        responses.append(("!" + err_type.lower(), error, True))

    return responses
Esempio n. 3
0
def test_execute_until():
    with arcomm.Session(HOST, creds=ARCOMM_CREDS) as sess:
        sess.execute_until(['show clock'], condition=r'\:[0-5]0', timeout=30,
                           sleep=.1)

        with pytest.raises(ValueError):
            sess.execute_while(['show version'], condition=r'.*', timeout=5,
                               sleep=1)
Esempio n. 4
0
def test_uri_parsing():
    pe = arcomm.util.parse_endpoint
    print
    pprint(arcomm.Session('eapi://vswitch1'))
    pprint(arcomm.Session('eapi+http://vswitch1'))
    pprint(arcomm.Session('eapi+https://vswitch1'))