def test001BadURL(): badurl = "http://aksdkakskdfa-idontexist.com/foo/tree" with pytest.raises(ValueError, match=".*maybe you mistyped.*"): installer = Installer(hvmguest.conn, location=badurl) installer.detect_distro(hvmguest) # Non-existent cdrom fails with pytest.raises(ValueError, match=".*non-existent path.*"): installer = Installer(hvmguest.conn, cdrom="/not/exist/foobar") assert installer.detect_distro(hvmguest) is None # Ensure existing but non-distro file doesn't error installer = Installer(hvmguest.conn, cdrom="/dev/null") assert installer.detect_distro(hvmguest) is None
def _testGuest(testdata, guest): distname = testdata.name arch = testdata.arch url = testdata.url checkdistro = testdata.detectdistro guest.os.arch = arch if testdata.testshortcircuit: guest.set_os_name(checkdistro) installer = Installer(guest.conn, location=url) try: detected_distro = installer.detect_distro(guest) except Exception: raise AssertionError("\nFailed in installer detect_distro():\n" "name = %s\n" "url = %s\n\n%s" % (distname, url, "".join(traceback.format_exc()))) # Make sure the stores are reporting correct distro name/variant if checkdistro != detected_distro: raise AssertionError("Detected OS did not match expected values:\n" "found = %s\n" "expect = %s\n\n" "testname = %s\n" "url = %s\n" % (detected_distro, checkdistro, distname, url)) if guest is xenguest: return # Do this only after the distro detection, since we actually need # to fetch files for that part treemedia = installer._treemedia # pylint: disable=protected-access fetcher = treemedia._cached_fetcher # pylint: disable=protected-access def fakeAcquireFile(filename): logging.debug("Fake acquiring %s", filename) return filename fetcher.acquireFile = fakeAcquireFile # Fetch regular kernel kernel, initrd, kernelargs = treemedia.prepare(guest, meter) dummy = initrd if testdata.kernelregex and not re.match(testdata.kernelregex, kernel): raise AssertionError("kernel=%s but testdata.kernelregex='%s'" % (kernel, testdata.kernelregex)) if testdata.kernelarg == "None": if bool(kernelargs): raise AssertionError( "kernelargs='%s' but testdata.kernelarg='%s'" % (kernelargs, testdata.kernelarg)) elif testdata.kernelarg: if testdata.kernelarg != str(kernelargs).split("=")[0]: raise AssertionError( "kernelargs='%s' but testdata.kernelarg='%s'" % (kernelargs, testdata.kernelarg))
def test001BadURL(self): badurl = "http://aksdkakskdfa-idontexist.com/foo/tree" with self.assertRaises(ValueError) as cm: installer = Installer(hvmguest.conn, location=badurl) installer.detect_distro(hvmguest) self.assertTrue("maybe you mistyped" in str(cm.exception)) # Non-existent cdrom fails with self.assertRaises(ValueError) as cm: installer = Installer(hvmguest.conn, cdrom="/not/exist/foobar") self.assertEqual(None, installer.detect_distro(hvmguest)) self.assertTrue("non-existent path" in str(cm.exception)) # Ensure existing but non-distro file doesn't error installer = Installer(hvmguest.conn, cdrom="/dev/null") self.assertEqual(None, installer.detect_distro(hvmguest))
def test001BadURL(self): badurl = "http://aksdkakskdfa-idontexist.com/foo/tree" try: installer = Installer(hvmguest.conn, location=badurl) installer.detect_distro(hvmguest) raise AssertionError("Expected URL failure") except ValueError as e: self.assertTrue("maybe you mistyped" in str(e)) # Non-existent cdrom fails try: installer = Installer(hvmguest.conn, cdrom="/i/dont/exist/foobar") self.assertEqual(None, installer.detect_distro(hvmguest)) raise AssertionError("Expected cdrom failure") except ValueError as e: self.assertTrue("non-existent path" in str(e)) # Ensure existing but non-distro file doesn't error installer = Installer(hvmguest.conn, cdrom="/dev/null") self.assertEqual(None, installer.detect_distro(hvmguest))