Beispiel #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')
    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')
Beispiel #3
0
    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)
Beispiel #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)
Beispiel #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)
Beispiel #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()
Beispiel #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)
    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')
Beispiel #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')
Beispiel #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')
Beispiel #14
0
def wrongCredentials(target):
    log.info("wrong username/password")
    raise PermissionDenied(target)