Example #1
0
def test_execute_not_authorized(protocol):

    with pytest.raises(arcomm.AuthorizationFailed):
        arcomm.execute(HOST, ['show restricted'], authorize=('bad', 'bad'))

    response = arcomm.execute(HOST, ['show restricted'])
    assert response.status == 'failed' and 'not authorized' in str(response)
Example #2
0
def test_response_store_access():
    responses = arcomm.execute(HOST, ['show version'])
    assert hasattr(responses, '__iter__'), "response must be an iterable"
    assert str(responses.last().command) == 'show version', \
        "Last item should have been 'show version'"

    for r in responses:
        assert hasattr(r, 'command')
        assert hasattr(r, 'output')
Example #3
0
def test_callback(protocol):

    def _cb(response):
        global called_back
        assert isinstance(response, arcomm.response.Response)
        called_back = 'test_callback'

    response = arcomm.execute(HOST, ['show bogus'], protocol=protocol,
                              callback=_cb)

    assert called_back == 'test_callback'
Example #4
0
def test_global_subscriber(protocol):
    import functools
    def cb(response, key):
        global called_back
        called_back = 'test_response_monitor:' + str(key)

    p1 = functools.partial(cb, key=1)
    p2 = functools.partial(cb, key=2)
    p3 = functools.partial(cb, key=3)
    arcomm.subscribe(p3)
    arcomm.subscribe(p1)
    arcomm.subscribe(p1)
    arcomm.subscribe(p2)

    # unsub two funcs
    arcomm.unsubscribe([p1, p2])
    # bugus
    arcomm.unsubscribe("sdfsdf")

    arcomm.execute(HOST, ['show clock'], protocol=protocol)
    assert called_back == 'test_response_monitor:3'
Example #5
0
#!/usr/bin/env python

import os
import sh
import sys
import arcomm

_, local, host = sys.argv[:3]

sh.scp(local, "{}:/tmp/".format(host))

package = os.path.basename(local)

script = """
no extension {0}
delete extension:{0}
""".format(package)
print arcomm.execute('eapi://{}'.format(host), script.splitlines())

script = """
copy file:/tmp/{0} extension:
extension {0}
copy installed-extensions boot-extensions
""".format(package)

print arcomm.execute('eapi://{}'.format(host), script.splitlines())
Example #6
0
def test_authorize(protocol):
    response = arcomm.execute(HOST, ['show running-config'], creds=OPS_CREDS,
        authorize=ENABLE_SECRET, protocol=protocol)
Example #7
0
def test_execute_not_authorized(protocol):

    response = arcomm.execute(HOST, ['show running-config'], creds=OPS_CREDS)[0]
    assert response.errored and 'privileged mode required' in response.output
Example #8
0
def test_execute_invalid_command(protocol):
    response = arcomm.execute(HOST, ['show bogus'], protocol=protocol)
    assert response.status == 'failed'
Example #9
0
def test_encoding_text():
    arcomm.execute(HOST, ['show version'], encoding="text")
Example #10
0
def test_execute_sess():
    conn = arcomm.connect(HOST, creds=ARCOMM_CREDS)
    arcomm.execute(conn, 'show version')
Example #11
0
def test_execute_ok(protocol):
    response = arcomm.execute(HOST, ['show clock'], protocol=protocol)
Example #12
0
def test_execute_bad_command(protocol):
    response = arcomm.execute(HOST, ['show gloc'], protocol=protocol)
    assert response.status == 'failed'
Example #13
0
def test_raise_for_error(protocol):
    response = arcomm.execute(HOST, ['show bogus'], protocol=protocol)
    with pytest.raises(arcomm.ExecuteFailed):
        response.raise_for_error()
Example #14
0
def test_response_slice(protocol):
    response = arcomm.execute(HOST, ['show version'], protocol=protocol)
    response[0][0:5]
    response[0][0:5:2]
Example #15
0
import os
import sh
import sys
import arcomm

_, local, host = sys.argv[:3]

sh.scp(local, "{}:/tmp/".format(host))

package = os.path.basename(local)

script = """
no extension {0}
delete extension:{0}
""".format(package)
print arcomm.execute('eapi://{}'.format(host), script.splitlines())

script = """
copy file:/tmp/{0} extension:
extension {0}
copy installed-extensions boot-extensions
configure
no snmp-server extension .1.3.6.1.4.1.8072.1.3.1.5
snmp-server extension .1.3.6.1.4.1.8072.1.3.1.5 file:/var/tmp/snmpext
end
write
""".format(package)

print arcomm.execute('eapi://{}'.format(host), script.splitlines())
Example #16
0
def test_execute_eapi_unconverted_command():

    response = arcomm.execute(HOST, ['show clock'], encoding='json',
                              protocol='eapi+http')
    assert response.status == 'failed'
Example #17
0
def test_not_authorized(protocol):
    response = arcomm.execute(HOST, ['show running-config'],
                              creds=OPS_CREDS, protocol=protocol)

    assert response.status == 'failed'