Exemplo n.º 1
0
    def test_verify_module_status_negative(self):
        device = Device(name='Router',
                        os='iosxe',
                        custom=dict(abstraction=dict(order=['os'])))
        device.is_connected = Mock(return_value=True)
        device.cli = Mock()
        device.cli.execute = Mock(return_value=dedent('''
        Chassis type: ISR4451-X/K9

        Slot      Type                State                 Insert time (ago) 
        --------- ------------------- --------------------- ----------------- 
        0         ISR4451-X/K9        ok                    00:02:59      
        0/0      ISR4451-X-4x1GE     ok                    00:01:58      
        1         ISR4451-X/K9        ok                    00:02:59      
        2         ISR4451-X/K9        ok                    00:02:59      
        R0        ISR4451-X/K9        fail                  00:02:59      
        F0        ISR4451-X/K9        ok, active            00:02:59      
        P0        PWR-4450-AC         ok                    00:02:32      
        P1        Unknown             empty                 never         
        P2        ACS-4450-FANASSY    ok                    00:02:32      

        Slot      CPLD Version        Firmware Version                        
        --------- ------------------- --------------------------------------- 
        0         16092742            16.12(2r)                           
        1         16092742            16.12(2r)                           
        2         16092742            16.12(2r)                           
        R0        16092742            16.12(2r)                           
        F0        16092742            16.12(2r)                           
        '''))
        with self.assertRaisesRegex(
                Exception, "Modules on 'Router' are not in stable state"):
            verify_module_status(device, timeout=0.3, interval=0.1)
    def test_get_mgmt_ip_and_mgmt_src_ip_addresses(self):
        device = Device(
            name='Router',
            os='iosxr',
            platform='c8000',
            custom=dict(abstraction=dict(order=['os', 'platform']))
        )
        device.is_connected = Mock(return_value=True)
        device.execute = Mock(return_value=dedent('''
        Active Internet connections (servers and established)
        Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
        tcp        0      0 0.0.0.0:179             0.0.0.0:*               LISTEN      1131/bgp        
        tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      7756/sshd       
        tcp        0      0 0.0.0.0:830             0.0.0.0:*               LISTEN      7756/sshd       
        tcp        0    188 1.1.1.95:22             2.2.2.145:50173         ESTABLISHED 12021/sshd: admin [
        tcp6       0      0 :::179                  :::*                    LISTEN      1131/bgp        
        tcp6       0      0 :::22                   :::*                    LISTEN      7756/sshd       
        tcp6       0      0 :::830                  :::*                    LISTEN      7756/sshd       
        '''))

        with self.assertLogs('genie.libs.sdk.apis.iosxr.c8000.utils') as cm:
            result = get_mgmt_ip_and_mgmt_src_ip_addresses(device)
            self.assertEqual(cm.output,[
                "INFO:genie.libs.sdk.apis.iosxr.c8000.utils:Device management IP: 1.1.1.95",
                "INFO:genie.libs.sdk.apis.iosxr.c8000.utils:Device management source IP addresses: {'2.2.2.145'}"
            ])
            self.assertEqual(result, ('1.1.1.95', {'2.2.2.145'}))

        device.execute.assert_has_calls([call('bash netstat -antp')])
Exemplo n.º 3
0
    def test_verify_module_status(self):
        device = Device(name='Router',
                        os='iosxe',
                        custom=dict(abstraction=dict(order=['os'])))
        device.is_connected = Mock(return_value=True)
        device.cli = Mock()
        device.cli.execute = Mock(return_value=dedent('''
        Chassis type: ISR4451-X/K9

        Slot      Type                State                 Insert time (ago) 
        --------- ------------------- --------------------- ----------------- 
        0         ISR4451-X/K9        ok                    00:02:59      
        0/0      ISR4451-X-4x1GE     ok                    00:01:58      
        1         ISR4451-X/K9        ok                    00:02:59      
        2         ISR4451-X/K9        ok                    00:02:59      
        R0        ISR4451-X/K9        ok, active            00:02:59      
        F0        ISR4451-X/K9        ok, active            00:02:59      
        P0        PWR-4450-AC         ok                    00:02:32      
        P1        Unknown             empty                 never         
        P2        ACS-4450-FANASSY    ok                    00:02:32      

        Slot      CPLD Version        Firmware Version                        
        --------- ------------------- --------------------------------------- 
        0         16092742            16.12(2r)                           
        1         16092742            16.12(2r)                           
        2         16092742            16.12(2r)                           
        R0        16092742            16.12(2r)                           
        F0        16092742            16.12(2r)                           
        '''))
        with self.assertLogs(
                'genie.libs.sdk.apis.iosxe.platform.verify') as cm:
            verify_module_status(device)
            self.assertEqual(cm.output, [
                "INFO:genie.libs.sdk.apis.iosxe.platform.verify:All modules on 'Router' are in stable state"
            ])

        device.cli.execute.assert_has_calls([call('show platform')])