예제 #1
0
    def testCommandTimeout(self, MockExpect):
        '''
        If after invoking a cli command the expected prompt is not found in the response a timeout event is triggered. 
        '''

        responses = [
            'pyco@localhost password: '******'''Linux cencenighe 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:46 UTC 2011 x86_64 GNU/Linux\r
        Ubuntu 10.04.2 LTS\r
        \r
        Welcome to Ubuntu!\r
         * Documentation:  https://help.ubuntu.com/\r
        \r
        Last login: Thu Feb 24 09:05:39 2011 from localhost\r\n$ ''',
            'to be cleared by clear_buffer', '$ ',
            'to be cleared by clear_buffer', 'no prompt'
        ]
        log.info("testLoginTimeout ...")
        h = device('telnet://*****:*****@h')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        h.login()

        self.failUnlessRaises(ConnectionTimedOut, h.send, 'id')
예제 #2
0
    def testPromptDiscoveryDisabled(self, MockExpect):
        '''
        Disable the prompt discovery. 
        '''

        responses = [
            'pyco@localhost password: '******'''Linux cencenighe 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:46 UTC 2011 x86_64 GNU/Linux\r
        Ubuntu 10.04.2 LTS\r
        \r
        Welcome to Ubuntu!\r
         * Documentation:  https://help.ubuntu.com/\r
        \r
        Last login: Thu Feb 24 09:05:39 2011 from localhost\r\n$ some output''',
            'i am pyco'
        ]

        log.info("testLoginTimeout ...")
        h = device('telnet://*****:*****@h')
        h.discoverPrompt = False

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        h.login()

        h.send('id')
예제 #3
0
파일: test_fake.py 프로젝트: ThomaxG/pyco
    def testNativeTelnet(self):
        log.info("testNative ...")
        user = environ["USER"]
        log.info("USER: [%s]" % user)
        h = device("telnet://%s:%s@%s" % (user, user, "localhost"))
        h.maxWait = 10

        self.assertRaises(PermissionDenied, h, "id")
    def testTC1(self, MockExpect):
        log.info("testTC1 ...")
        h = device('ssh://*****:*****@host')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        self.failUnlessRaises(PermissionDenied, h.login)
예제 #5
0
    def testTC1(self, MockExpect):
        log.info("testTC1 ...")
        h = device('ssh://*****:*****@host')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        self.failUnlessRaises(PermissionDenied, h.login)
예제 #6
0
    def _testLoginTimeout(self, MockExpect):
        responses = ['unexpected response (expected password prompt)', 'to be cleared by clear_buffer'] 

        log.info("testLoginTimeout ...")
        h = device('telnet://*****:*****@h')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        self.failUnlessRaises(LoginFailed, h.login)
예제 #7
0
    def testNoPassword(self, MockExpect):
        from pyco.device import cliIsConnected
        log.info("testNoPassword ...")
        #h = device('telnet://%s:%s@%s' % (hop1['username'], hop1['password'], hop1['name']))
        h = device('telnet://*****:*****@h')
        
        h.remove_event('username_event', 'GROUND')
        h.add_event_action('timeout', action=cliIsConnected, endState='USER_PROMPT')
        
        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = self.responses

        out = h.login()
예제 #8
0
    def _testLoginTimeout(self, MockExpect):
        responses = [
            'unexpected response (expected password prompt)',
            'to be cleared by clear_buffer'
        ]

        log.info("testLoginTimeout ...")
        h = device('telnet://*****:*****@h')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        self.failUnlessRaises(LoginFailed, h.login)
예제 #9
0
    def testTC1(self, MockExpect):
        log.info("testTC1 ...")
        h = device('telnet://*****:*****@h')
        h.maxWait = 20

        print(h.patternMap['GROUND'])

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        out = h.login()
    
        h.send('id')
    def testNoPromptAfterResponse(self, MockExpect):
        from pyco.device import cliIsConnected
        log.info("testNoPromptAfterResponse ...")
        cisco = device('telnet://*****:*****@h')
        
        from pyco.actions import sendUsername
        cisco.add_event_action('username-event', pattern='Username: '******'GROUND')
        
        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = self.responses

        out = cisco.login()
    
        self.failUnlessRaises(ConnectionTimedOut, cisco.send, 'show version')
예제 #11
0
    def testNoPassword(self, MockExpect):
        from pyco.device import cliIsConnected
        log.info("testNoPassword ...")
        #h = device('telnet://%s:%s@%s' % (hop1['username'], hop1['password'], hop1['name']))
        h = device('telnet://*****:*****@h')

        h.remove_event('username_event', 'GROUND')
        h.add_event_action('timeout',
                           action=cliIsConnected,
                           endState='USER_PROMPT')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = self.responses

        out = h.login()
    def testNoPromptAfterResponse(self, MockExpect):
        from pyco.device import cliIsConnected
        log.info("testNoPromptAfterResponse ...")
        cisco = device('telnet://*****:*****@h')

        from pyco.actions import sendUsername
        cisco.add_event_action('username-event',
                               pattern='Username: '******'GROUND')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = self.responses

        out = cisco.login()

        self.failUnlessRaises(ConnectionTimedOut, cisco.send, 'show version')
예제 #13
0
    def testCommandTimeout(self, MockExpect):
        '''
        If after invoking a cli command the expected prompt is not found in the response a timeout event is triggered. 
        '''
        
        responses = ['pyco@localhost password: '******'''Linux cencenighe 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:46 UTC 2011 x86_64 GNU/Linux\r
        Ubuntu 10.04.2 LTS\r
        \r
        Welcome to Ubuntu!\r
         * Documentation:  https://help.ubuntu.com/\r
        \r
        Last login: Thu Feb 24 09:05:39 2011 from localhost\r\n$ ''',
        'to be cleared by clear_buffer', '$ ','to be cleared by clear_buffer', 'no prompt']
        log.info("testLoginTimeout ...")
        h = device('telnet://*****:*****@h')

        MockExpect.side_effect = simulator.side_effect
        simulator.side_effect.responses = responses

        h.login()
         
        self.failUnlessRaises(ConnectionTimedOut, h.send, 'id')
예제 #14
0
파일: actions.py 프로젝트: attdona/pyco
def wrongCredentials(target):
    log.info("wrong username/password")
    raise PermissionDenied(target)