Example #1
0
"""
Created on Mar 21, 2011

@author: adona
"""
import unittest  # @UnresolvedImport
from pyco.device import device, ConnectionRefused, PermissionDenied
from os import environ

from pyco import log


TELNET_PORT = 7777

# create logger
log = log.getLogger("test")


class Test(unittest.TestCase):

    # @unittest.skip("skipping")
    def testFakeOk(self):
        log.debug("testFakeOk ...")
        h = device("telnet://%s:%s@%s:%d" % ("username", "secret", "localhost", TELNET_PORT))

        h.maxWait = 2
        out = h("id")
        print("--> %s" % out)
        self.assertRegex(out, "uid=[0-9]+\(pyco\).*")

    @unittest.skip("skipping")
Example #2
0
@author: adona
'''
import sys
import io #@UnresolvedImport
if sys.platform != 'win32':
    from pexpect import spawnu, TIMEOUT, EOF #@UnresolvedImport
else:
    from winpexpect import winspawnu as spawnu, TIMEOUT, EOF #@UnresolvedImport

    
from pyco.device import Event, device, ConnectionTimedOut #@UnresolvedImport
from pyco import log


# create logger
log = log.getLogger("exp-session")

       
def loginSuccessfull(device):
    '''
    The checkpoint loginSuccessfull has 3 exit point:
     * return True if the state is 'USER_PROMPT'
     * raise the ConnectionTimedOut exception if the current event is timeout
     * return False otherwise
    '''
    log.debug("[%s] loginSuccessfull: current_state [%s]" % (device.name, device.state))
    if device.state == 'USER_PROMPT':
        device.loggedin = True
        return True
#    if device.currentEvent.name == 'timeout':
#        raise ConnectionTimedOut(device)
Example #3
0
'''
Created on Feb 22, 2011

@author: adona
'''
from pyco import log
from pyco.device import Prompt, ConnectionRefused, PermissionDenied, MissingDeviceParameter, cliIsConnected


log = log.getLogger("actions")

def send(target, command):
    log.debug("sending string [%s] ..." % command)
    target.send_line(command)
    

def sendUsername(target):
    if target.username is None:
        raise MissingDeviceParameter(target, '%s username undefined' % target.name)

    log.debug("sending username  [%s] ..." % target.username)
    target.send_line(target.username)

def sendPassword(target):
    
    if target.password is None:
        raise MissingDeviceParameter(target, '%s password undefined' % target.name)
    
    log.debug("[%s] sending password [%s] ..." % (target.name, target.password))
    target.send_line(target.password)
Example #4
0
'''
import re #@UnresolvedImport
import sys

if sys.platform != 'win32':
    from pexpect import TIMEOUT, EOF #@UnresolvedImport
    spawnFunction = 'pexpect.spawn'
else:
    from winpexpect import TIMEOUT, EOF #@UnresolvedImport
    spawnFunction = 'winpexpect.winspawn'

from mock import Mock, patch, patch_object, sentinel #@UnresolvedImport
from pyco import log

# create logger
log = log.getLogger("sim")


def responder(mock, responses, patterns, maxTime):
    
    log.debug('entering MOCK responder')
    print(patterns)

    #return the index relative to event_name
    response = responses.pop(0)
    log.debug('current response [%s]' % (response))
    
    idx = 0
    toBeMatched = True
    while toBeMatched and idx < len(patterns):
        
Example #5
0
'''
import re  #@UnresolvedImport
import sys

if sys.platform != 'win32':
    from pexpect import TIMEOUT, EOF  #@UnresolvedImport
    spawnFunction = 'pexpect.spawn'
else:
    from winpexpect import TIMEOUT, EOF  #@UnresolvedImport
    spawnFunction = 'winpexpect.winspawn'

from mock import Mock, patch, patch_object, sentinel  #@UnresolvedImport
from pyco import log

# create logger
log = log.getLogger("sim")


def responder(mock, responses, patterns, maxTime):

    log.debug('entering MOCK responder')
    print(patterns)

    #return the index relative to event_name
    response = responses.pop(0)
    log.debug('current response [%s]' % (response))

    idx = 0
    toBeMatched = True
    while toBeMatched and idx < len(patterns):
Example #6
0
'''
Created on Jun 28, 2011

@author: adona
'''
from pyco import log
from pyco.device import ConnectionRefused, PermissionDenied, MissingDeviceParameter, cliIsConnected

log = log.getLogger("handlers")


def initCiscoTerminal(target):
    target.send('terminal length 0')


def sendWhitespace(target):
    target.send(' ')
Example #7
0
@author: adona
'''
import unittest  #@UnresolvedImport
import logging
from pyco.device import device

#from IPython.parallel import Client
from multiprocessing import Pool

from pyco import log
from utils import setface

TELNET_PORT = 7777

# create logger
log = log.getLogger("test")


def cioscoios_show_ip_local_pool(host):
    out = host.send("show ip local pool")
    return out


def command(host):
    try:
        print("----> [%s]" % host.driver)
        if (host.driver.name == "ciscoios"):
            return cioscoios_show_ip_local_pool(host)
        elif (host.driver.name == 'juniper'):
            print("Thommy lets happen!")
        else:
Example #8
0
Created on Feb 21, 2011

@author: adona
'''
import sys
import io  #@UnresolvedImport
if sys.platform != 'win32':
    from pexpect import spawnu, TIMEOUT, EOF  #@UnresolvedImport
else:
    from winpexpect import winspawnu as spawnu, TIMEOUT, EOF  #@UnresolvedImport

from pyco.device import Event, device, ConnectionTimedOut  #@UnresolvedImport
from pyco import log

# create logger
log = log.getLogger("exp-session")


def loginSuccessfull(device):
    '''
    The checkpoint loginSuccessfull has 3 exit point:
     * return True if the state is 'USER_PROMPT'
     * raise the ConnectionTimedOut exception if the current event is timeout
     * return False otherwise
    '''
    log.debug("[%s] loginSuccessfull: current_state [%s]" %
              (device.name, device.state))
    if device.state == 'USER_PROMPT':
        device.loggedin = True
        return True
Example #9
0
'''
Created on Jun 28, 2011

@author: adona
'''
from pyco import log
from pyco.device import ConnectionRefused, PermissionDenied, MissingDeviceParameter, cliIsConnected


log = log.getLogger("handlers")


def initCiscoTerminal(target):
    target.send('terminal length 0')

def sendWhitespace(target):
    target.send(' ')