Beispiel #1
0
    def testMultipleItems(self):
        ipv4 = ipaddress.IPv4Address('42.0.255.32')
        address1 = jobs_pb2.NetworkAddress()
        address1.address_type = jobs_pb2.NetworkAddress.INET
        address1.packed_bytes = ipv4.packed

        ipv6 = ipaddress.IPv6Address('2001:db8::1000')
        address2 = jobs_pb2.NetworkAddress()
        address2.address_type = jobs_pb2.NetworkAddress.INET6
        address2.packed_bytes = ipv6.packed

        iface1 = jobs_pb2.Interface()
        iface1.mac_address = b'\xaa\x12\x42\xff\xa5\xd0'
        iface1.ifname = 'foo'
        iface1.addresses.extend([address1])

        iface2 = jobs_pb2.Interface()
        iface2.mac_address = b'\xaa\x12\x42\xff\xa5\xd1'
        iface2.ifname = 'bar'
        iface2.addresses.extend([address2])

        ifaces = representer.InterfaceList([iface1, iface2])

        out = io.StringIO()
        ifaces._repr_pretty_(pretty.PrettyPrinter(out), cycle=False)

        expected = """
foo (MAC: aa:12:42:ff:a5:d0):
    inet 42.0.255.32

bar (MAC: aa:12:42:ff:a5:d1):
    inet6 2001:db8::1000
"""
        self.assertEqual(out.getvalue(), expected)
Beispiel #2
0
    def testMultipleAddresses(self):
        ipv4 = ipaddress.IPv4Address('42.0.255.32')
        address1 = jobs_pb2.NetworkAddress()
        address1.address_type = jobs_pb2.NetworkAddress.INET
        address1.packed_bytes = ipv4.packed

        ipv6 = ipaddress.IPv6Address('2001:db8::1000')
        address2 = jobs_pb2.NetworkAddress()
        address2.address_type = jobs_pb2.NetworkAddress.INET6
        address2.packed_bytes = ipv6.packed

        iface = jobs_pb2.Interface()
        iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0'
        iface.ifname = 'foo'
        iface.addresses.extend([address1, address2])

        out = io.StringIO()
        pp = pretty.PrettyPrinter(out)
        representer.interface_pretty(iface, pp, cycle=False)

        expected = """\
foo (MAC: aa:12:42:ff:a5:d0):
    inet 42.0.255.32
    inet6 2001:db8::1000
"""
        self.assertEqual(out.getvalue(), expected)
Beispiel #3
0
    def testNoAddresses(self):
        iface = jobs_pb2.Interface()
        iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0'
        iface.ifname = 'foo'

        out = io.StringIO()
        pp = pretty.PrettyPrinter(out)
        representer.interface_pretty(iface, pp, cycle=False)

        expected = """\
foo (MAC: aa:12:42:ff:a5:d0):
"""
        self.assertEqual(out.getvalue(), expected)
Beispiel #4
0
  def testSingleAddress(self):
    ipv4 = ipaddress.IPv4Address('42.0.255.32')
    address = jobs_pb2.NetworkAddress()
    address.address_type = jobs_pb2.NetworkAddress.INET
    address.packed_bytes = ipv4.packed

    iface = jobs_pb2.Interface()
    iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0'
    iface.ifname = 'foo'
    iface.addresses.extend([address])

    out = StringIO()
    pp = pretty.PrettyPrinter(out)
    representer.interface_pretty(iface, pp, cycle=False)

    expected = """\
foo (MAC: aa:12:42:ff:a5:d0):
    inet 42.0.255.32
"""
    self.assertEqual(out.getvalue(), expected)
Beispiel #5
0
    def testSlice(self):
        iface1 = jobs_pb2.Interface()
        iface2 = jobs_pb2.Interface()

        ifaces = representer.InterfaceList([iface1, iface2])
        self.assertIsInstance(ifaces[:1], representer.InterfaceList)