def test_search_driver_disabled(self): '''D-BUS API: Search for a noninstalled driver''' # search_driver() should not display available==True handlers open(os.path.join(OSLib.inst.handler_dir, 'kmod_avail.py'), 'w').write(sandbox.h_availability_py) ui = sandbox.TestUI() self.assert_('kmod:spam' not in ui.backend().available()) sandbox.start_driverdb_server() try: ui.backend().add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) # first match is kmod:mint:UbuOne in our fake db result = ui.search_driver('pci:9876/FEDC') finally: sandbox.stop_driverdb_server() self.stop_capture() self.assertEqual(result, (False, [])) self.assertEqual(ui.get_displayed_handlers(), ['kmod:spam']) info = ui.backend().handler_info('kmod:spam') self.assertEqual(info['enabled'], 'True')
def test_zz_add_driverdb(self): '''D-BUS Backend.add_driverdb()''' self.assertRaises(dbus.DBusException, self.i_drv.add_driverdb, 'UnknownClass', []) self.assertRaises(dbus.DBusException, self.i_drv.add_driverdb, 'XMLRPCDriverDB', []) try: sandbox.start_driverdb_server() self.i_drv.add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) self.i_drv.update_driverdb() drvs = set(self.i_drv.available('nonfree')) finally: sandbox.stop_driverdb_server() self.assertEqual(drvs, set(['kmod:mint', 'kmod:mint:UbuOne', 'kmod:mint:UbunTwo', 'kmod:vanilla3d', 'firmware:firmwifi', 'kmod:apple:Apple'])) hi = self.i_drv.handler_info('kmod:apple:Apple') self.assertEqual(hi['driver_vendor'], 'Apple') self.assertEqual(hi['package'], 'pretzel') self.assertEqual(hi['free'], 'False') self.assertEqual(hi['license'], 'Kills kittens')
def test_zz_add_driverdb(self): """D-BUS Backend.add_driverdb()""" self.assertRaises(dbus.DBusException, self.i_drv.add_driverdb, "UnknownClass", []) self.assertRaises(dbus.DBusException, self.i_drv.add_driverdb, "XMLRPCDriverDB", []) try: sandbox.start_driverdb_server() self.i_drv.add_driverdb("XMLRPCDriverDB", ["http://localhost:8080"]) self.i_drv.update_driverdb() drvs = set(self.i_drv.available("nonfree")) finally: sandbox.stop_driverdb_server() self.assertEqual( drvs, set( [ "kmod:mint", "kmod:mint:UbuOne", "kmod:mint:UbunTwo", "kmod:vanilla3d", "firmware:firmwifi", "kmod:apple:Apple", ] ), ) hi = self.i_drv.handler_info("kmod:apple:Apple") self.assertEqual(hi["driver_vendor"], "Apple") self.assertEqual(hi["package"], "pretzel") self.assertEqual(hi["free"], "False") self.assertEqual(hi["license"], "Kills kittens")
def test_xmlrpc_driverdb_no_systemid(self): '''XMLRPCDriverDB with a working (local) server and no system ID''' backend = jockey.backend.Backend() # should *not* contact server, do that before starting server OSLib.inst.set_dmi('', '') db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') # until we update, there is no data self.assertEqual(jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() # this should now give the same result as TestDriverDB, except for the # custom handlers (which we did not define here, they should be ignored) result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual(out, # note custom description for spam '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:mint([KernelModuleHandler, nonfree, enabled] nonfree module with available hardware, wifi) kmod:spam([KernelModuleHandler, free, enabled] free mystical module without modaliases)''') # previous DB should have written a cache cache_path = db.cache_path self.assert_(os.path.exists(db.cache_path)) db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual(out, '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:mint([KernelModuleHandler, nonfree, enabled] nonfree module with available hardware, wifi) kmod:spam([KernelModuleHandler, free, enabled] free mystical module without modaliases)''') # the cache should *not* apply to a different URL; also, invalid URLs # should not cause a crash db = jockey.detection.XMLRPCDriverDB('http://localhost:12345') self.assertEqual(jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) # should not fall over on damaged cache files open(cache_path, 'wb').write('bogus') db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') self.assertEqual(jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set())
def test_driver_search_redundancy(self): '''Backend.add_driverdb() and search_driver() avoid redundant actions''' b = jockey.backend.Backend() self.assertRaises(dbus.DBusException, b.add_driverdb, 'UnknownClass', []) self.assertEqual(b.search_driver('pci:9876/FEDC'), []) log_offset = sandbox.log.tell() try: sandbox.start_driverdb_server() b.add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) #b.update_driverdb() drvs = set(b.available()) log_add = sandbox.log.getvalue()[log_offset:] log_offset = sandbox.log.tell() self.assertEqual(b.search_driver('pci:9876/FEDC'), ['kmod:spam']) log_search = sandbox.log.getvalue()[log_offset:] finally: sandbox.stop_driverdb_server() # add_driverdb() checks new DB against all devices self.assert_("about HardwareID('modalias', 'fire:1.2'" in log_add) self.assert_("about HardwareID('modalias', 'pci:v0000AAAAd" in log_add) # search_driver() queries all databases self.assert_('LocalKernelModulesDriverDB' in log_search) self.assert_('OpenPrintingDriverDB' in log_search) self.assert_('XMLRPCDriverDB' in log_search) # no redundant actions self.failIf('all custom handlers loaded' in log_add, 'add_driverdb() does not re-read local handlers') self.failIf('reading modalias' in log_add, 'add_driverdb() does not re-read modaliases') self.assert_('reading modalias' in log_search, 'search_driver() updates all driver DBs') self.failIf('querying driver db <jockey.detection.LocalKernelModulesDriverDB ' in log_add, 'add_driverdb() does not query unrelated DBs again') self.failIf('OpenPrinting' in log_add, 'add_driverdb() should not use OpenPrintingDriverDB') self.failIf('openprinting.org' in log_add, 'add_driverdb() should not query OpenPrinting.org')
def test_xmlrpc_driverdb_i18n(self): '''XMLRPCDriverDB return localized strings''' backend = jockey.backend.Backend() db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() orig_getlocale = locale.getlocale try: locale.getlocale = lambda c: ('de_DE', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual([str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] German description)') locale.getlocale = lambda c: ('de_DE', 'ISO8859-1') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual([str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] German description)') # DB only has de_DE, thus this should be C locale.getlocale = lambda c: ('de', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual([str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] VaporTech choc handler)') locale.getlocale = lambda c: ('cs', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual([str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] Czech description)') # DB has cs, cs_CZ should fallback to cs locale.getlocale = lambda c: ('cs_CZ', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual([str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] Czech description)') finally: locale.getlocale = orig_getlocale
def test_driver_search_redundancy(self): """Backend.add_driverdb() and search_driver() avoid redundant actions""" b = jockey.backend.Backend() self.assertRaises(dbus.DBusException, b.add_driverdb, "UnknownClass", []) self.assertEqual(b.search_driver("pci:9876/FEDC"), []) log_offset = sandbox.log.tell() try: sandbox.start_driverdb_server() b.add_driverdb("XMLRPCDriverDB", ["http://localhost:8080"]) # b.update_driverdb() drvs = set(b.available()) log_add = sandbox.log.getvalue()[log_offset:] log_offset = sandbox.log.tell() self.assertEqual(b.search_driver("pci:9876/FEDC"), ["kmod:spam"]) log_search = sandbox.log.getvalue()[log_offset:] finally: sandbox.stop_driverdb_server() # add_driverdb() checks new DB against all devices self.assert_("about HardwareID('modalias', 'fire:1.2'" in log_add) self.assert_("about HardwareID('modalias', 'pci:v0000AAAAd" in log_add) # search_driver() queries all databases self.assert_("LocalKernelModulesDriverDB" in log_search) self.assert_("OpenPrintingDriverDB" in log_search) self.assert_("XMLRPCDriverDB" in log_search) # no redundant actions self.failIf("all custom handlers loaded" in log_add, "add_driverdb() does not re-read local handlers") self.failIf("reading modalias" in log_add, "add_driverdb() does not re-read modaliases") self.assert_("reading modalias" in log_search, "search_driver() updates all driver DBs") self.failIf( "querying driver db <jockey.detection.LocalKernelModulesDriverDB " in log_add, "add_driverdb() does not query unrelated DBs again", ) self.failIf("OpenPrinting" in log_add, "add_driverdb() should not use OpenPrintingDriverDB") self.failIf("openprinting.org" in log_add, "add_driverdb() should not query OpenPrinting.org")
def test_xmlrpc_driverdb_errors(self): '''XMLRPCDriverDB with a working (local) server, error conditions''' # cache writing error backend = jockey.backend.Backend() db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') db.cache_path = '/proc/null' sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() # survives self.assertNotEqual(db.cache, {}) # return protocol mismatch db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') sandbox.start_driverdb_server(correct_protocol=False) try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() # survives self.assertEqual(db.cache, {})
def test_search_driver_disabled(self): '''D-BUS API: Search for a noninstalled driver''' # search_driver() should not display available==True handlers open (os.path.join(OSLib.inst.handler_dir, 'kmod_avail.py'), 'w').write( sandbox.h_availability_py) ui = sandbox.TestUI() self.assert_('kmod:spam' not in ui.backend().available()) sandbox.start_driverdb_server() try: ui.backend().add_driverdb('XMLRPCDriverDB', ['http://localhost:8080']) # first match is kmod:mint:UbuOne in our fake db result = ui.search_driver('pci:9876/FEDC') finally: sandbox.stop_driverdb_server() self.stop_capture() self.assertEqual(result, (False, [])) self.assertEqual(ui.get_displayed_handlers(), ['kmod:spam']) info = ui.backend().handler_info('kmod:spam') self.assertEqual(info['enabled'], 'True')
def test_xmlrpc_driverdb_i18n(self): '''XMLRPCDriverDB return localized strings''' backend = jockey.backend.Backend() db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() orig_getlocale = locale.getlocale try: locale.getlocale = lambda c: ('de_DE', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual( [str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] German description)' ) locale.getlocale = lambda c: ('de_DE', 'ISO8859-1') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual( [str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] German description)' ) # DB only has de_DE, thus this should be C locale.getlocale = lambda c: ('de', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual( [str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] VaporTech choc handler)' ) locale.getlocale = lambda c: ('cs', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual( [str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] Czech description)' ) # DB has cs, cs_CZ should fallback to cs locale.getlocale = lambda c: ('cs_CZ', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) self.assertEqual( [str(h) for h in result if h.module == 'chocolate'][0], 'kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] Czech description)' ) finally: locale.getlocale = orig_getlocale
def test_xmlrpc_driverdb_systemid(self): '''XMLRPCDriverDB with a working (local) server and VaporTech system ID''' open(os.path.join(OSLib.inst.handler_dir, 'ndmod.py'), 'w').write('import jockey.handlers\n' + sandbox.h_nodetectmod) backend = jockey.backend.Backend() # should *not* contact server, do that before starting server db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') # until we update, there is no data self.assertEqual( jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() orig_getlocale = locale.getlocale try: locale.getlocale = lambda c: ('en_US', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) finally: locale.getlocale = orig_getlocale out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual( out, '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:apple:Apple([KernelModuleHandler, nonfree, disabled] Unknown local kmod) kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] VaporTech choc handler) kmod:mint:UbuOne([KernelModuleHandler, nonfree, enabled] UbuOne mintmod) kmod:mint:UbunTwo([KernelModuleHandler, nonfree, enabled] UbunTwo mintmod) kmod:spam:Black_Hat([NoDetectMod, free, enabled] BlackHat ndmod) kmod:spam:White_Hat([NoDetectMod, free, enabled] WhiteHat ndmod)''') for h in result: if h.module == 'firmwifi': self.assertEqual(h.description(), None) self.assertEqual(h.version, None) self.assertEqual(h.repository, None) self.assertEqual(h.package, None) self.assertEqual(h.driver_vendor, None) if h.module == 'chocolate': choc_h = h if h.module == 'apple': self.assertEqual(h.license, 'Kills kittens') else: self.assertEqual(h.license, None) self.assertEqual(h.recommended(), h.id() == 'kmod:mint:UbunTwo') self.assertEqual(choc_h.description(), 'Multi\nline') self.assertEqual(choc_h.version, '1.1-foo42-vt3') self.assertEqual(choc_h.repository, 'http://vaportech.com/x1') self.assertEqual(choc_h.package, 'spam-x1') self.assertEqual(choc_h.driver_vendor, 'VaporTech') self.assertEqual(choc_h.enabled(), False) choc_h.enable() self.assertEqual(choc_h.enabled(), True) self.assertEqual(OSLib.inst.package_installed(choc_h.package), True)
def test_xmlrpc_driverdb_no_systemid(self): '''XMLRPCDriverDB with a working (local) server and no system ID''' backend = jockey.backend.Backend() # should *not* contact server, do that before starting server OSLib.inst.set_dmi('', '') db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') # until we update, there is no data self.assertEqual( jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() # this should now give the same result as TestDriverDB, except for the # custom handlers (which we did not define here, they should be ignored) result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual( out, # note custom description for spam '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:mint([KernelModuleHandler, nonfree, enabled] nonfree module with available hardware, wifi) kmod:spam([KernelModuleHandler, free, enabled] free mystical module without modaliases)''' ) # previous DB should have written a cache cache_path = db.cache_path self.assert_(os.path.exists(db.cache_path)) db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual( out, '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:mint([KernelModuleHandler, nonfree, enabled] nonfree module with available hardware, wifi) kmod:spam([KernelModuleHandler, free, enabled] free mystical module without modaliases)''' ) # the cache should *not* apply to a different URL; also, invalid URLs # should not cause a crash db = jockey.detection.XMLRPCDriverDB('http://localhost:12345') self.assertEqual( jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) # should not fall over on damaged cache files open(cache_path, 'wb').write('bogus') db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') self.assertEqual( jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set())
def test_xmlrpc_driverdb_systemid(self): '''XMLRPCDriverDB with a working (local) server and VaporTech system ID''' open (os.path.join(OSLib.inst.handler_dir, 'ndmod.py'), 'w').write( 'import jockey.handlers\n' + sandbox.h_nodetectmod) backend = jockey.backend.Backend() # should *not* contact server, do that before starting server db = jockey.detection.XMLRPCDriverDB('http://localhost:8080') # until we update, there is no data self.assertEqual(jockey.detection.get_handlers(backend, db, hardware=backend.hardware), set()) sandbox.start_driverdb_server() try: db.update(backend.hardware) finally: sandbox.stop_driverdb_server() orig_getlocale = locale.getlocale try: locale.getlocale = lambda c: ('en_US', 'UTF-8') result = jockey.detection.get_handlers(backend, db, hardware=backend.hardware) finally: locale.getlocale = orig_getlocale out = '\n'.join(sorted([str(h) for h in result])) self.assertEqual(out, '''firmware:firmwifi([FirmwareHandler, nonfree, disabled] standard module which needs firmware) kmod:apple:Apple([KernelModuleHandler, nonfree, disabled] Unknown local kmod) kmod:chocolate:VaporTech([KernelModuleHandler, free, disabled] VaporTech choc handler) kmod:mint:UbuOne([KernelModuleHandler, nonfree, enabled] UbuOne mintmod) kmod:mint:UbunTwo([KernelModuleHandler, nonfree, enabled] UbunTwo mintmod) kmod:spam:Black_Hat([NoDetectMod, free, enabled] BlackHat ndmod) kmod:spam:White_Hat([NoDetectMod, free, enabled] WhiteHat ndmod)''') for h in result: if h.module == 'firmwifi': self.assertEqual(h.description(), None) self.assertEqual(h.version, None) self.assertEqual(h.repository, None) self.assertEqual(h.package, None) self.assertEqual(h.driver_vendor, None) if h.module == 'chocolate': choc_h = h if h.module == 'apple': self.assertEqual(h.license, 'Kills kittens') else: self.assertEqual(h.license, None) self.assertEqual(h.recommended(), h.id() == 'kmod:mint:UbunTwo') self.assertEqual(choc_h.description(), 'Multi\nline') self.assertEqual(choc_h.version, '1.1-foo42-vt3') self.assertEqual(choc_h.repository, 'http://vaportech.com/x1') self.assertEqual(choc_h.package, 'spam-x1') self.assertEqual(choc_h.driver_vendor, 'VaporTech') self.assertEqual(choc_h.enabled(), False) choc_h.enable() self.assertEqual(choc_h.enabled(), True) self.assertEqual(OSLib.inst.package_installed(choc_h.package), True)