def test_basic(self): """Test basic functions.""" i = _Iface({ 'name': 'NAME', 'order': 42, 'type': 'static', 'start': 'yes', 'address': '1.2.3.4', 'netmask': '255.255.255.0', 'network': '1.2.3.0', 'broadcast': '1.2.3.255', 'options/2': '2', 'options/1': '1', 'route/3': 'foo', 'route/2': 'host 192.168.0.240', 'route/1': 'net 192.168.0.0 netmask 255.255.255.128', }) assert 'NAME' == i.name assert 42 == i.order assert 'static' == i.type assert i.start assert IPv4Address(u'1.2.3.0') == i.network assert IPv4Address(u'1.2.3.255') == i.broadcast assert IPv4Interface(u'1.2.3.4/24') == i.ipv4_address() assert i.ipv6_address() is None assert ['1', '2'] == list(i.options) assert [ 'net 192.168.0.0 netmask 255.255.255.128', 'host 192.168.0.240' ] == list(i.routes)
def test_incomplete_net(self): """Test incomplete interface with netmask/prefix.""" i = _Iface({ 'netmask': '255.255.255.0', 'ipv6/default/prefix': '64', }) assert i.ipv4_address() is None assert i.ipv6_address() is None
def test_incomplete_addr(self): """Test incomplete interface with address.""" i = _Iface({ 'address': '2.3.4.5', 'ipv6/default/address': '1:2:3:4:5:6:7:8', }) assert i.ipv4_address() is None assert i.ipv6_address() is None
def test_invalid(self): """Test invalid interface address.""" i = _Iface({ 'address': '2.3.4.5', 'netmask': '42', 'ipv6/default/address': '1:2:3:4:5:6:7:8', 'ipv6/default/prefix': '4711', }) assert not i.ipv4_address() assert not i.ipv6_address()
def test_ipv6(self): """Test IPv6 functions.""" i = _Iface({ 'name': 'NAME', 'ipv6/default/address': '1:2:3:4:5:6:7:8', 'ipv6/default/prefix': '64', 'ipv6/other/address': '2:3:4:5:6:7:8:9', 'ipv6/other/prefix': '80', }) assert 'NAME' == i.name assert i.ipv4_address() is None assert IPv6Interface(u'1:2:3:4:5:6:7:8/64') == i.ipv6_address() assert IPv6Interface(u'1:2:3:4:5:6:7:8/64') == i.ipv6_address( 'default') assert IPv6Interface(u'2:3:4:5:6:7:8:9/80') == i.ipv6_address('other')