def test_get_interface(self): assert_equal(get_interface(''), None) assert_equal(get_interface('notreal'), None) assert_is_instance(get_interface(self.iface_name, address_family=4), IPv4Address) # can't enable this until there's a v6 address on the ci hosts # assert_is_instance(get_interface( # self.iface_name, # address_family=6), IPv6Address) assert_raises(IPUtilsException, get_interface, self.iface_name, 0)
def find_ip(args): """ Get and print the IP from a specific interface Args: - interface: string network interface name - address_family: int 4 or 6, respective to ipv4 or ipv6 """ interface = ip_utils.get_interface(args.interface, args.address_family) if interface: print(interface.ip)
def test_find_gateway(self): assert_is_instance(find_gateway(self.iface), str) iface_virbr0 = get_interface('virbr0') assert_equal(find_gateway(iface_virbr0), None)
def setup_class(klass): """This method is run once for each class before any tests are run""" klass.iface_name = get_default_gateway_linux() iface = get_interface(klass.iface_name) klass.iface = iface