Esempio n. 1
0
    def run(self, local_info, router_context, gql_token, fp):
        """
      """
        # Ugly!
        test_info = self.test_info(local_info, router_context)
        self.output.test_start(test_info, status=Output.Status.OK)
        params = self.get_params()

        if self.check_user("root") != Output.Status.OK:
            return self.output.test_end(fp)

        self.output.progress_start(fp)

        json_data = {}
        error_lines = []
        ethtool = Linux.Ethtool(debug=self.debug, progobj=self)
        # Ugly....
        self.fp = fp
        shell_status = ethtool.run_linux_args(local_info, router_context,
                                              params['node_type'],
                                              params['linux_device'],
                                              error_lines, json_data)
        # Ugly...
        self.fp = None

        if self.debug:
            print('........ flattened list ..........')
            pprint.pprint(json_data)

        engine = EntryTest.Parser(debug=self.debug)
        engine.eval_entry_by_tests(json_data, params["entry_tests"])

        self.output.proc_test_result(json_data)
        return self.output.test_end(fp)
Esempio n. 2
0
def test_LogFileMatches():
    log_file_matches_text = """
JSON: {"matches": [{"pindex": 0, "pattern": "LPA.*?observer", "matches": 1}, {"pindex": 1, "pattern": "HWMC", "matches": 0}], "total_matches": 1, "total_files": 1, "total_lines": 51159, "matching_lines": 1, "not_matching_lines": 51158, "matching_files": 1}
"""
    expected = {
        'matches': [{
            'matches': 1,
            'pattern': 'LPA.*?observer',
            'pindex': 0
        }, {
            'matches': 0,
            'pattern': 'HWMC',
            'pindex': 1
        }],
        'matching_files':
        1,
        'matching_lines':
        1,
        'not_matching_lines':
        51158,
        'total_files':
        1,
        'total_lines':
        51159,
        'total_matches':
        1
    }
    l = Linux.LogFileMatches(debug=True)
    output = log_file_matches_text.splitlines()
    json_dict = l.convert_to_json(output)
    assert json_dict == expected
Esempio n. 3
0
def test_coredumpctl_list(tz_string):
    coredumpctl_list_text = """
TIME                            PID   UID   GID SIG PRESENT EXE
Wed 2019-09-11 10:05:48 EDT    6355  1001  1001  11   /usr/bin/pdmTransportAgent
Wed 2019-09-11 20:58:20 EDT   10825  1001  1001  11   /usr/bin/pdmTransportAgent
Tue 2019-09-24 23:58:53 EDT    4994  1001  1001  11   /usr/bin/pdmTransportAgent
"""
    expected = [{
        'EPOCH_TIME': 1568210748,
        'EXE': '/usr/bin/pdmTransportAgent',
        'GID': '1001',
        'PID': '6355',
        'PRESENT': '',
        'SIG': '11',
        'TIME': 'Wed 2019-09-11 10:05:48 EDT',
        'UID': '1001'
    }, {
        'EPOCH_TIME': 1568249900,
        'EXE': '/usr/bin/pdmTransportAgent',
        'GID': '1001',
        'PID': '10825',
        'PRESENT': '',
        'SIG': '11',
        'TIME': 'Wed 2019-09-11 20:58:20 EDT',
        'UID': '1001'
    }, {
        'EPOCH_TIME': 1569383933,
        'EXE': '/usr/bin/pdmTransportAgent',
        'GID': '1001',
        'PID': '4994',
        'PRESENT': '',
        'SIG': '11',
        'TIME': 'Tue 2019-09-24 23:58:53 EDT',
        'UID': '1001'
    }]

    set_local_timezone(tz_string)

    c = Linux.Coredumpctl(debug=True)
    output = coredumpctl_list_text.splitlines()
    json_dict = c.convert_to_json(output)

    # toothless test: Fix this to independently calculate days, hours, etc.
    list_len = len(c.cores_newer_than_secs(2000000))
    assert list_len == 0
    # print(f"Length: {x}")

    # toothless test: Fix this to independently calculate days, hours, etc.
    keys = ['EPOCH_TIME', 'TIME']
    for key in keys:
        for entry in json_dict:
            assert key in entry
    for key in keys:
        for entry in expected:
            entry.pop(key, None)
        for entry in json_dict:
            entry.pop(key, None)

    assert json_dict == expected
Esempio n. 4
0
def test_T1Detail_2():
    t1_detail_text_2 = """
     ***** w1g1: T1 Rx Alarms (Framer) *****

     ALOS:     OFF     | LOS:  OFF
     RED:      OFF     | AIS:  OFF
     LOF:      OFF     | RAI:  OFF
 
     ***** w1g1: T1 Rx Alarms (LIU) *****

     Short Circuit:    OFF
     Open Circuit:     OFF
     Loss of Signal:   OFF

     ***** w1g1: T1 Tx Alarms *****

     AIS:      OFF     | YEL:  OFF


    ***** w1g1: T1 Performance Monitoring Counters *****

     Line Code Violation       : 0
     Bit Errors (CRC6/Ft/Fs)   : 16
     Out of Frame Errors       : 7
     Sync Errors               : 0


     Rx Level  : -7.5db to -10db
"""
    expected = {
        'AIS': 'OFF',
        'ALOS': 'OFF',
        'Bit_Errors_CRC6/Ft/Fs': '16',
        'LOF': 'OFF',
        'LOS': 'OFF',
        'Line_Code_Violation': '0',
        'Loss_of_Signal': 'OFF',
        'Open_Circuit': 'OFF',
        'Out_of_Frame_Errors': '7',
        'RAI': 'OFF',
        'RED': 'OFF',
        'Rx_Level_High': '-7.5',
        'Rx_Level_Low': '-10',
        'Short_Circuit': 'OFF',
        'Sync_Errors': '0',
        'TxAIS': 'OFF',
        'YEL': 'OFF'
    }
    t = Linux.T1Detail(debug=True)
    output = t1_detail_text_2.splitlines()
    json_dict = t.convert_to_json(output)
    assert json_dict == expected
Esempio n. 5
0
def test_ethtool():
    ethtool_info_text = """
Settings for enp0s20f0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: Symmetric
    Supports auto-negotiation: Yes
    Supported FEC modes: Not reported
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: Symmetric
    Advertised auto-negotiation: Yes
    Advertised FEC modes: Not reported
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: on (auto)
    Supports Wake-on: pumbg
    Wake-on: g
    Current message level: 0x00000007 (7)
    drv probe link
    Link detected: yes
"""

    expected = {
        'Advertised_FEC_modes': 'Not reported',
        'Advertised_link_modes': '10baseT/Half 10baseT/Full ',
        'Advertised_pause_frame_use': 'Symmetric',
        'Current_message_level': '0x00000007 (7)',
        'Duplex': 'Full',
        'Link_detected': 'yes',
        'PHYAD': '0',
        'Port': 'Twisted Pair',
        'Speed': '1000Mb/s',
        'Supported_FEC_modes': 'Not reported',
        'Supported_link_modes': '10baseT/Half 10baseT/Full ',
        'Supported_pause_frame_use': 'Symmetric',
        'Supported_ports': '[ TP ]',
        'Transceiver': 'internal'
    }

    e = Linux.Ethtool(debug=True)
    output = ethtool_info_text.splitlines()
    json_dict = e.convert_to_json(output)
    assert json_dict == expected
Esempio n. 6
0
    def run(self, local_info, router_context, gql_token, fp):
        """
      """
        test_info = self.test_info(local_info, router_context)
        self.output.test_start(test_info, status=Output.Status.OK)
        params = self.get_params()

        if self.check_user("root") != Output.Status.OK:
            return self.output.test_end(fp)

        self.output.progress_start(fp)
        router_context.query_node_info()

        json_data = {}
        error_lines = []

        t1_detail = Linux.T1Detail(debug=self.debug, progobj=self)

        # Ugly....
        self.fp = fp
        shell_status = t1_detail.run_linux_args(local_info, router_context,
                                                params['node_type'],
                                                params['namespace'],
                                                params['linux_device'],
                                                error_lines, json_data)
        # Ugly...
        self.fp = None

        # reset results for multi-router invocation
        self.results = []

        if len(error_lines) == 0:
            # This should return a list of all entry_test entries which FAIL
            # These will be passed to test.output
            engine = EntryTest.Parser(debug=False)
            engine.eval_tests_by_entry(json_data, params['entry_tests'], self)
        else:
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        command = t1_detail.get_command(params['namespace'],
                                        params['linux_device'])
        self.output.proc_test_result(self.results, params, command)
        return self.output.test_end(fp)
Esempio n. 7
0
def test_BGP_summary():
    bgp_summary_text = """

IPv4 Unicast Summary:
BGP router identifier 10.53.151.115, local AS number 65310 vrf-id 0
BGP table version 415
RIB entries 79, using 12 KiB of memory
Peers 2, using 41 KiB of memory

Neighbor        V         AS MsgRcvd MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd
172.27.232.15   4      64794  317684  264701        0    0    0 01w6d21h           40
172.27.233.15   4      64894  260245  217685        0    0    0 3d15h04m           40

Total number of neighbors 2
"""

    expected = [{
        'AS': 64794,
        'InQ': 0,
        'MsgRcvd': 317684,
        'MsgSent': 264701,
        'Neighbor': '172.27.232.15',
        'OutQ': 0,
        'PfxRcvd': 40,
        'TblVer': 0,
        'Up/Down': '01w6d21h',
        'Version': 4
    }, {
        'AS': 64894,
        'InQ': 0,
        'MsgRcvd': 260245,
        'MsgSent': 217685,
        'Neighbor': '172.27.233.15',
        'OutQ': 0,
        'PfxRcvd': 40,
        'TblVer': 0,
        'Up/Down': '3d15h04m',
        'Version': 4
    }]

    b = Linux.BGPSummary(debug=True)
    output = bgp_summary_text.splitlines()
    json_dict = b.convert_to_json(output)
    assert json_dict == expected
Esempio n. 8
0
def test_uptime_2():
    uptime_text = """
    23:11:40 up  8:16,  1 user,  load average: 2.71, 2.30, 2.01 
    """
    expected = {
        'load_1': 2.71,
        'load_15': 2.01,
        'load_5': 2.3,
        'uptime_as_seconds': 29760,
        'uptime_days': 0,
        'uptime_hours': 8,
        'uptime_minutes': 16,
        'users': 1
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
Esempio n. 9
0
def test_uptime_1():
    uptime_text = """
    12:34:35 up 58 days, 10:18,  5 users,  load average: 0.76, 1.28, 1.19  
    """
    expected = {
        'load_1': 0.76,
        'load_15': 1.19,
        'load_5': 1.28,
        'uptime_as_seconds': 5048280,
        'uptime_days': 58,
        'uptime_hours': 10,
        'uptime_minutes': 18,
        'users': 5
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
Esempio n. 10
0
def test_systemctl_status(tz_string):
    systemctl_status_text = """
● 128T.service - 128T service
   Loaded: loaded (/usr/lib/systemd/system/128T.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-09-11 00:25:02 EDT; 1 months 2 days ago
 Main PID: 28049 (processManager)
    Tasks: 2404
   Memory: 25.1G
   CGroup: /system.slice/128T.service
"""

    expected = {
        'Main_PID': '28049',
        'Main_Process': 'processManager',
        'epoch_time': 1568161502.0,
        'state_1': 'active',
        'state_2': 'running',
        'time': 'Wed 2019-09-11 00:25:02 EDT',
        'uptime_days': 92,
        'uptime_hours': 20,
        'uptime_minutes': 19,
        'uptime_seconds': 22
    }

    set_local_timezone(tz_string)

    s = Linux.SystemctlStatus(debug=True)
    output = systemctl_status_text.splitlines()
    json_dict = s.convert_to_json(output)

    # toothless test: Fix this to independently calculate days, hours, etc.
    keys = [
        'epoch_time', 'uptime_days', 'uptime_hours', 'uptime_minutes',
        'uptime_seconds'
    ]
    for key in keys:
        assert key in json_dict
    for key in keys:
        expected.pop(key, None)
        json_dict.pop(key, None)

    assert json_dict == expected
Esempio n. 11
0
def test_uptime_4():
    uptime_text = """
    20:19:54 up 54 min,  4 users,  load average: 1.69, 1.96, 1.92
    """

    expected = {
        'load_1': 1.69,
        'load_15': 1.92,
        'load_5': 1.96,
        'uptime_as_seconds': 3240,
        'uptime_days': 0,
        'uptime_hours': 0,
        'uptime_minutes': 54,
        'users': 4
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
Esempio n. 12
0
def test_uptime_3():
    uptime_text = """
    02:25:02 up 73 days, 40 min,  1 user,  load average: 2.01, 1.56, 1.60
    """

    expected = {
        'load_1': 2.01,
        'load_15': 1.6,
        'load_5': 1.56,
        'uptime_as_seconds': 6309600,
        'uptime_days': 73,
        'uptime_hours': 0,
        'uptime_minutes': 40,
        'users': 1
    }

    u = Linux.Uptime(debug=True)
    output = uptime_text.splitlines()
    json_dict = u.convert_to_json(output)
    assert json_dict == expected
Esempio n. 13
0
def test_LogfilesSince():
    log_files_since_text = """
  JSON: {"files": [{"file": "/var/log/128technology/highwayManager.1.log", "start": "Oct 19 19:53:45", "end": "Oct 19 19:56:14"}, {"file": "/var/log/128technology/highwayManager.22.log", "start": "Oct 29 21:02:28", "end": "Oct 29 21:04:55"}, {"file": "/var/log/128technology/highwayManager.21.log", "start": "Oct 29 21:04:55", "end": "Oct 29 21:07:20"}, {"file": "/var/log/128technology/highwayManager.19.log", "start": "Oct 29 21:09:45", "end": "Oct 29 21:12:15"}, {"file": "/var/log/128technology/highwayManager.log", "start": "Oct 29 21:56:14", "end": "Oct 29 21:56:43"}, {"file": "/var/log/128technology/highwayManager.20.log", "start": "Oct 29 21:07:20", "end": "Oct 29 21:09:45"}, {"file": "/var/log/128technology/highwayManager.11.log", "start": "Oct 29 21:29:20", "end": "Oct 29 21:31:45"}, {"file": "/var/log/128technology/highwayManager.10.log", "start": "Oct 29 21:31:45", "end": "Oct 29 21:34:15"}, {"file": "/var/log/128technology/highwayManager.18.log", "start": "Oct 29 21:12:15", "end": "Oct 29 21:14:40"}, {"file": "/var/log/128technology/highwayManager.23.log", "start": "Oct 29 21:00:00", "end": "Oct 29 21:02:28"}, {"file": "/var/log/128technology/highwayManager.16.log", "start": "Oct 29 21:17:05", "end": "Oct 29 21:19:35"}, {"file": "/var/log/128technology/highwayManager.14.log", "start": "Oct 29 21:22:00", "end": "Oct 29 21:24:25"}, {"file": "/var/log/128technology/highwayManager.12.log", "start": "Oct 29 21:26:55", "end": "Oct 29 21:29:20"}, {"file": "/var/log/128technology/highwayManager.3.log", "start": "Oct 29 21:48:54", "end": "Oct 29 21:51:20"}, {"file": "/var/log/128technology/highwayManager.5.log", "start": "Oct 29 21:44:00", "end": "Oct 29 21:46:25"}, {"file": "/var/log/128technology/highwayManager.24.log", "start": "Oct 29 20:57:35", "end": "Oct 29 21:00:00"}, {"file": "/var/log/128technology/highwayManager.2.log", "start": "Oct 29 21:51:20", "end": "Oct 29 21:53:45"}, {"file": "/var/log/128technology/highwayManager.7.log", "start": "Oct 29 21:39:05", "end": "Oct 29 21:41:35"}, {"file": "/var/log/128technology/highwayManager.6.log", "start": "Oct 29 21:41:35", "end": "Oct 29 21:44:00"}, {"file": "/var/log/128technology/highwayManager.15.log", "start": "Oct 29 21:19:35", "end": "Oct 29 21:22:00"}, {"file": "/var/log/128technology/highwayManager.17.log", "start": "Oct 29 21:14:40", "end": "Oct 29 21:17:05"}, {"file": "/var/log/128technology/highwayManager.13.log", "start": "Oct 29 21:24:25", "end": "Oct 29 21:26:55"}, {"file": "/var/log/128technology/highwayManager.9.log", "start": "Oct 29 21:34:15", "end": "Oct 29 21:36:40"}, {"file": "/var/log/128technology/highwayManager.8.log", "start": "Oct 29 21:36:40", "end": "Oct 29 21:39:05"}, {"file": "/var/log/128technology/highwayManager.4.log", "start": "Oct 29 21:46:25", "end": "Oct 29 21:48:54"}], "now": "Oct 29 21:56:44 2019 [UTC]"}
"""
    expected = [{
        'end': 'Oct 29 21:56:43',
        'file': '/var/log/128technology/highwayManager.log',
        'start': 'Oct 29 21:56:14'
    }, {
        'end': 'Oct 29 21:53:45',
        'file': '/var/log/128technology/highwayManager.2.log',
        'start': 'Oct 29 21:51:20'
    }, {
        'end': 'Oct 29 21:51:20',
        'file': '/var/log/128technology/highwayManager.3.log',
        'start': 'Oct 29 21:48:54'
    }, {
        'end': 'Oct 29 21:48:54',
        'file': '/var/log/128technology/highwayManager.4.log',
        'start': 'Oct 29 21:46:25'
    }, {
        'end': 'Oct 29 21:46:25',
        'file': '/var/log/128technology/highwayManager.5.log',
        'start': 'Oct 29 21:44:00'
    }, {
        'end': 'Oct 29 21:44:00',
        'file': '/var/log/128technology/highwayManager.6.log',
        'start': 'Oct 29 21:41:35'
    }, {
        'end': 'Oct 29 21:41:35',
        'file': '/var/log/128technology/highwayManager.7.log',
        'start': 'Oct 29 21:39:05'
    }, {
        'end': 'Oct 29 21:39:05',
        'file': '/var/log/128technology/highwayManager.8.log',
        'start': 'Oct 29 21:36:40'
    }, {
        'end': 'Oct 29 21:36:40',
        'file': '/var/log/128technology/highwayManager.9.log',
        'start': 'Oct 29 21:34:15'
    }, {
        'end': 'Oct 29 21:34:15',
        'file': '/var/log/128technology/highwayManager.10.log',
        'start': 'Oct 29 21:31:45'
    }, {
        'end': 'Oct 29 21:31:45',
        'file': '/var/log/128technology/highwayManager.11.log',
        'start': 'Oct 29 21:29:20'
    }, {
        'end': 'Oct 29 21:29:20',
        'file': '/var/log/128technology/highwayManager.12.log',
        'start': 'Oct 29 21:26:55'
    }, {
        'end': 'Oct 29 21:26:55',
        'file': '/var/log/128technology/highwayManager.13.log',
        'start': 'Oct 29 21:24:25'
    }, {
        'end': 'Oct 29 21:24:25',
        'file': '/var/log/128technology/highwayManager.14.log',
        'start': 'Oct 29 21:22:00'
    }, {
        'end': 'Oct 29 21:22:00',
        'file': '/var/log/128technology/highwayManager.15.log',
        'start': 'Oct 29 21:19:35'
    }, {
        'end': 'Oct 29 21:19:35',
        'file': '/var/log/128technology/highwayManager.16.log',
        'start': 'Oct 29 21:17:05'
    }, {
        'end': 'Oct 29 21:17:05',
        'file': '/var/log/128technology/highwayManager.17.log',
        'start': 'Oct 29 21:14:40'
    }, {
        'end': 'Oct 29 21:14:40',
        'file': '/var/log/128technology/highwayManager.18.log',
        'start': 'Oct 29 21:12:15'
    }, {
        'end': 'Oct 29 21:12:15',
        'file': '/var/log/128technology/highwayManager.19.log',
        'start': 'Oct 29 21:09:45'
    }, {
        'end': 'Oct 29 21:09:45',
        'file': '/var/log/128technology/highwayManager.20.log',
        'start': 'Oct 29 21:07:20'
    }, {
        'end': 'Oct 29 21:07:20',
        'file': '/var/log/128technology/highwayManager.21.log',
        'start': 'Oct 29 21:04:55'
    }, {
        'end': 'Oct 29 21:04:55',
        'file': '/var/log/128technology/highwayManager.22.log',
        'start': 'Oct 29 21:02:28'
    }, {
        'end': 'Oct 29 21:02:28',
        'file': '/var/log/128technology/highwayManager.23.log',
        'start': 'Oct 29 21:00:00'
    }, {
        'end': 'Oct 29 21:00:00',
        'file': '/var/log/128technology/highwayManager.24.log',
        'start': 'Oct 29 20:57:35'
    }]
    # This is a lame test, need actual log files to process
    l = Linux.LogFilesSince(debug=True, past_hours=1)
    output = log_files_since_text.splitlines()
    json_dict = l.convert_to_json(output)
    assert json_dict == expected
Esempio n. 14
0
def test_IPA_ns_lte():
    netns_lte_ip_a_text = """
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
8: enp0s22u1u2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 5e:a9:e0:9f:a4:19 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.128/24 brd 192.168.1.255 scope global enp0s22u1u2
       valid_lft forever preferred_lft forever
    inet6 2600:380:9e1e:6d2a:5ca9:e0ff:fe9f:a419/64 scope global mngtmpaddr dynamic 
       valid_lft 86364sec preferred_lft 14364sec
    inet6 fe80::5ca9:e0ff:fe9f:a419/64 scope link 
       valid_lft forever preferred_lft forever
25: lte: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether fa:67:97:45:f3:e1 brd ff:ff:ff:ff:ff:ff
    inet 169.254.151.114/31 brd 255.255.255.255 scope global lte
       valid_lft forever preferred_lft forever
    inet6 fe80::f867:97ff:fe45:f3e1/64 scope link 
       valid_lft forever preferred_lft forever
"""
    expected = [{
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': False,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': True,
        'Flags_LOWER_UP': False,
        'Flags_MASTER': False,
        'Flags_MULTICAST': False,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': False,
        'device': 'lo',
        'group': 'default',
        'index': 1,
        'mtu': '65536',
        'qdisc': 'noop',
        'qlen': '1000',
        'state': 'DOWN'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'address': '192.168.1.128',
        'address-prefix': '24',
        'broadcast-address': '192.168.1.255',
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'enp0s22u1u2',
        'group': 'default',
        'index': 8,
        'mac': '5e:a9:e0:9f:a4:19',
        'mtu': '1500',
        'qdisc': 'pfifo_fast',
        'qlen': '1000',
        'state': 'UP'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'address': '169.254.151.114',
        'address-prefix': '31',
        'broadcast-address': '255.255.255.255',
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'lte',
        'group': 'default',
        'index': 25,
        'mac': 'fa:67:97:45:f3:e1',
        'mtu': '1500',
        'qdisc': 'pfifo_fast',
        'qlen': '1000',
        'state': 'UNKNOWN'
    }]

    i = Linux.IPA(debug=True)
    output = netns_lte_ip_a_text.splitlines()
    json_dict = i.convert_to_json(output)
    assert json_dict == expected
Esempio n. 15
0
def test_IPA():
    ip_a_text = """
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s20f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master habr state UP group default qlen 1000
    link/ether 00:90:0b:5b:80:d7 brd ff:ff:ff:ff:ff:ff
6: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 00:90:0b:5b:80:db brd ff:ff:ff:ff:ff:ff
7: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 00:90:0b:5b:80:dc brd ff:ff:ff:ff:ff:ff
9: habr: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:90:0b:5b:80:d7 brd ff:ff:ff:ff:ff:ff
    inet 30.254.255.1/30 brd 30.254.255.3 scope global noprefixroute habr
       valid_lft forever preferred_lft forever
    inet6 fe80::290:bff:fe5b:80d7/64 scope link 
       valid_lft forever preferred_lft forever
23: kni20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 42:3d:6f:4d:83:70 brd ff:ff:ff:ff:ff:ff
    inet 169.254.1.2/30 brd 169.254.1.3 scope global kni20
       valid_lft forever preferred_lft forever
    inet6 fe80::403d:6fff:fe4d:8370/64 scope link 
       valid_lft forever preferred_lft forever
24: kni254: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 6e:8e:df:e3:4e:ae brd ff:ff:ff:ff:ff:ff
    inet 169.254.127.127/31 brd 255.255.255.255 scope global kni254
       valid_lft forever preferred_lft forever
    inet6 fe80::6c8e:dfff:fee3:4eae/64 scope link 
       valid_lft forever preferred_lft forever
"""
    expected = [{
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': False,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': True,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': False,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'device': 'lo',
        'group': 'default',
        'index': 1,
        'mtu': '65536',
        'qdisc': 'noqueue',
        'qlen': '1000',
        'state': 'UNKNOWN'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'enp0s20f0',
        'group': 'default',
        'index': 2,
        'mac': '00:90:0b:5b:80:dc',
        'master': 'habr',
        'mtu': '1500',
        'qdisc': 'mq',
        'qlen': '1000',
        'state': 'UP'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'address': '30.254.255.1',
        'address-prefix': '30',
        'broadcast-address': '30.254.255.3',
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'habr',
        'group': 'default',
        'index': 9,
        'mac': '00:90:0b:5b:80:d7',
        'mtu': '1500',
        'qdisc': 'noqueue',
        'qlen': '1000',
        'state': 'UP'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'address': '169.254.1.2',
        'address-prefix': '30',
        'broadcast-address': '169.254.1.3',
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'kni20',
        'group': 'default',
        'index': 23,
        'mac': '42:3d:6f:4d:83:70',
        'mtu': '1500',
        'qdisc': 'pfifo_fast',
        'qlen': '1000',
        'state': 'UNKNOWN'
    }, {
        'Flags_ALLMULTI': False,
        'Flags_AUTOMEDIA': False,
        'Flags_BROADCAST': True,
        'Flags_DEBUG': False,
        'Flags_DORMANT': False,
        'Flags_DYNAMIC': False,
        'Flags_ECHO': False,
        'Flags_LOOPBACK': False,
        'Flags_LOWER_UP': True,
        'Flags_MASTER': False,
        'Flags_MULTICAST': True,
        'Flags_NOARP': False,
        'Flags_NOTRAILERS': False,
        'Flags_POINTTOPOINT': False,
        'Flags_PORTSEL': False,
        'Flags_PROMISC': False,
        'Flags_RUNNING': False,
        'Flags_SLAVE': False,
        'Flags_UP': True,
        'address': '169.254.127.127',
        'address-prefix': '31',
        'broadcast-address': '255.255.255.255',
        'broadcast-mac': 'ff:ff:ff:ff:ff:ff',
        'device': 'kni254',
        'group': 'default',
        'index': 24,
        'mac': '6e:8e:df:e3:4e:ae',
        'mtu': '1500',
        'qdisc': 'pfifo_fast',
        'qlen': '1000',
        'state': 'UNKNOWN'
    }]

    i = Linux.IPA(debug=True)
    output = ip_a_text.splitlines()
    json_dict = i.convert_to_json(output)
    assert json_dict == expected
Esempio n. 16
0
    def run(self, local_info, router_context, gql_token, fp):
        status = Output.Status.OK

        test_info = self.test_info(local_info, router_context)
        self.output.test_start(test_info, status=status)
        params = self.get_params()

        self.output.progress_start(fp)

        if self.check_user("root") != Output.Status.OK:
            return self.output.test_end(fp)

        router_context.query_node_info()

        # find the node with the active RouteManager and its primary etc.
        active_node_id = router_context.active_process_node('routingManager')
        if active_node_id == '':
            self.output.proc_inactive_routing_manager(local_info,
                                                      router_context)
            return self.output.test_end(fp)

        active_node_type = router_context.node_type(active_node_id)
        if local_info.get_node_type() != 'conductor' and \
           local_info.get_node_name() != active_node_id:
            self.output.proc_inactive_routing_manager(local_info,
                                                      router_context)
            return self.output.test_end(fp)

        error_lines = []
        json_data = []
        bs = Linux.BGPSummary(self.debug, progobj=self)
        # ugly..
        self.fp = fp
        retval = bs.run_linux_args(local_info, router_context,
                                   active_node_type, error_lines, json_data)
        # ugly...
        self.fp = None

        # Lame, but currently the only way to detect an error...
        if len(error_lines) > 0:
            self.output.proc_run_linux_error(retval, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ flattened list ..........')
            pprint.pprint(json_data)

        stats = {}
        Output.init_result_stats(stats)
        stats["total_count"] = len(json_data)

        if params["minimum_count"] > 0 and \
           stats["total_count"] < params["minimum_count"]:
            self.output.proc_too_few_peers(stats, params)
            return self.output.test_end(fp)

        engine = EntryTest.Parser(self.debug)
        for entry in json_data:
            if engine.exclude_entry(entry, params["exclude_tests"]):
                stats["exclude_count"] += 1
                continue
            test_result = engine.eval_entry_by_tests(entry,
                                                     params["entry_tests"])
            Output.update_stats(stats, test_result)
            self.output.proc_entry_result(entry)

        if stats["FAIL"] > 0:
            status = Output.Status.FAIL
        elif stats["WARN"] > 0:
            status = Output.Status.WARN
        elif stats["PASS"] == stats["total_count"]:
            status = Output.Status.OK

        self.output.proc_test_result(active_node_id,
                                     params["entry_tests"],
                                     stats,
                                     status=status)
        return self.output.test_end(fp)
Esempio n. 17
0
    def run(self, local_info, router_context, gql_token, fp):
        """
      """
        test_info = self.test_info(local_info, router_context)
        self.output.test_start(test_info, status=Output.Status.OK)
        params = self.get_params()

        if self.check_user("root") != Output.Status.OK:
            return self.output.test_end(fp)

        self.output.progress_start(fp)
        router_context.query_node_info()

        uptime_data = {}
        service_data = {}
        cores_data = []

        # Ugly....
        self.fp = fp
        error_lines = []
        uptime = Linux.Uptime(self.debug, progobj=self)
        shell_status = uptime.run_linux_args(local_info, router_context,
                                             params['node_type'], error_lines,
                                             uptime_data)

        if len(error_lines) > 0:
            # Ugly...
            self.fp = None
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ uptime flattened list ..........')
            pprint.pprint(uptime_data)

        error_lines = []
        sys_status = Linux.SystemctlStatus(self.debug, progobj=self)
        shell_status = sys_status.run_linux_args(local_info, router_context,
                                                 params['node_type'],
                                                 params['service'],
                                                 error_lines, service_data)

        if len(error_lines) > 0:
            # Ugly...
            self.fp = None
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ systemctl flattened list ..........')
            pprint.pprint(service_data)

        error_lines = []
        cores = Linux.Coredumpctl(self.debug, progobj=self)
        shell_status = cores.run_linux_args(local_info, router_context,
                                            params['node_type'], error_lines,
                                            cores_data)
        # Ugly...
        self.fp = None

        if len(error_lines) > 0:
            self.output.proc_run_linux_error(shell_status, error_lines[0])
            return self.output.test_end(fp)

        if self.debug:
            print('........ cores flattened list ..........')
            pprint.pprint(cores_data)

        status = Output.Status.OK
        uptime_cores = cores.cores_newer_than_secs(
            uptime_data['uptime_as_seconds'])
        if len(uptime_cores) > 0:
            self.output.proc_uptime_match(uptime_cores)
            status = Output.Status.WARN

        # TODO -- add error if epoch_time does not exist???
        service_cores = []
        if 'epoch_time' in service_data:
            service_cores = cores.cores_newer_than_epoch(
                service_data['epoch_time'])
        if len(service_cores) > 0:
            self.output.proc_service_match(params['service'], service_cores)
            status = Output.Status.WARN

        node_name = router_context.get_node_by_type(params['node_type'])
        message = f"{node_name}:  Uptime OS: {uptime_data['uptime_days']}d " + \
                  f"{uptime_data['uptime_hours']}h {uptime_data['uptime_minutes']}m  " + \
                  " 128T: "
        if service_data["uptime_days"] > 0:
            message += f"{service_data['uptime_days']}d "
        message += f"{service_data['uptime_hours']}h "
        message += f"{service_data['uptime_minutes']}m"
        if service_data["uptime_days"] == 0:
            message += f" {service_data['uptime_seconds']}s"

        self.output.proc_test_result(message, status)
        self.output.test_end(fp)