def test_set_sensor_interface_error (self): print ("Testing set_sensor_interfacesa with an unknown interface name") sys_ifaces = [iface.name for iface in netinterfaces.get_network_interfaces() if iface.name !='lo'] #print "Traza 1:" + str(sys_ifaces) nose.tools.ok_ (len(sys_ifaces)>0, msg="The system needs at least one network interface disting of lo") (result, resp) = set_sensor_interfaces ("127.0.0.1", ["gamusino", "ascodevida"]) nose.tools.ok_ (result == False, msg="gamusiono must be no a valid iface name")
def test_get_iface_list(self): print ("Testing get_iface_list") (result, ifaces_list) = get_iface_list ("127.0.0.1") nose.tools.ok_ (result == True, "Error:get_iface_list: Can't get iface list") nose.tools.ok_ (type(ifaces_list).__name__ == 'dict', "Error:get_iface_list: Bad type") ifaces = [x.strip() for x in ifaces_list.keys() if x != 'lo'] sys_ifaces = [iface.name for iface in netinterfaces.get_network_interfaces() if iface.name !='lo'] nose.tools.ok_ (len (sys_ifaces) == len (ifaces), msg="Number of interfaces mismatch") sys_set = set (sys_ifaces) ansible_set = set (ifaces) nose.tools.ok_ (ansible_set.issubset(sys_set))
def test_set_sensor_interfaces (self): print ("Testing set_sensor_interfaces") sys_ifaces = [iface.name for iface in netinterfaces.get_network_interfaces() if iface.name !='lo'] #print "Traza 1:" + str(sys_ifaces) nose.tools.ok_ (len(sys_ifaces)>0, msg="The system needs at least one network interface disting of lo") # Generate a list of ramdom ifaces test_ifaces = random.sample (sys_ifaces, random.randint(1, len(sys_ifaces))) # Backup de system interfaces (result, backup_ifaces) = get_sensor_interfaces ("127.0.0.1") nose.tools.ok_ (result == True, msg="Can't get backup of ossim_setup.conf interfaces") (result, resp) = set_sensor_interfaces ("127.0.0.1", ",".join(test_ifaces)) nose.tools.ok_ (result == True, msg="Error in set_sensor_interfaces") # Verify nose.tools.ok_ (self.__verify_iface_list (test_ifaces) == True, msg="Can't verify interface list") # Restore backup (result, resp) = set_sensor_interfaces ("127.0.0.1", ",".join (backup_ifaces)) nose.tools.ok_ (result == True, msg="Can't restore backup interfaces =>" + str(resp) + " Result: " + str(result)) nose.tools.ok_ (self.__verify_iface_list (backup_ifaces) == True, msg="Can't verify interface list")
def test_get_iface_stats (self): print ("Testing get_iface_stats") # This difficult to test, because the dynamic nature of the counter # I'm only test if the function return all the ifaces in the system (result, dstats) = get_iface_stats ("127.0.0.1") nose.tools.ok_ (result == True, msg="Error:get_iface_list: Can't get iface list") nose.tools.ok_ (type(dstats).__name__ == 'dict', msg="Error:get_iface_list: Bad type") ifaces = [x.strip() for x in dstats.keys() if x != 'lo'] sys_ifaces = [iface.name for iface in netinterfaces.get_network_interfaces() if iface.name !='lo'] nose.tools.ok_ (len (sys_ifaces) == len (ifaces), msg="Number of interfaces mismatch") sys_set = set(sys_ifaces) ansible_set = set(ifaces) nose.tools.ok_(ansible_set.issubset(sys_set)) # verify each result #print d for value in dstats.values(): #print v,type(v).__name__ nose.tools.ok_ (type(value).__name__ == 'dict', msg="Error:get_iface_stats: Bad type") nose.tools.ok_ (len(value) ==2, msg="Error:get_iface_stats: Bad response in key " + str(value)) nose.tools.ok_ (value.get('TX') != None, msg="Error:get_iface_stats: No TX key in response" + str(value)) nose.tools.ok_ (value.get('RX') != None, msg="Error:get_iface_stats: No RX key in response" + str(value))