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
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