Пример #1
0
    def _convert_helper(self, in_path, out_path, in_type, disk_format):
        outbuf = io.StringIO()

        def print_cb(msg):
            print(msg, file=outbuf)

        conn = utils.URIs.open_kvm()
        converter = VirtConverter(conn, in_path, print_cb=print_cb)

        if converter.parser.name != in_type:
            raise AssertionError("find_parser_by_file for '%s' returned "
                                 "wrong parser type.\n"
                                 "Expected: %s\n"
                                 "Received: %s\n" %
                                 (in_path, in_type, converter.parser.name))

        converter.convert_disks(disk_format, dry=True)
        guest = converter.get_guest()
        installer = Installer(guest.conn)
        ignore, out_xml = installer.start_install(guest, return_xml=True)
        out_expect = out_xml
        if outbuf.getvalue():
            out_expect += ("\n\n" + outbuf.getvalue().replace(base_dir, ""))

        if not conn.check_support(conn.SUPPORT_CONN_VMPORT):
            self.skipTest("Not comparing XML because vmport isn't supported")

        utils.diff_compare(out_expect, out_path)
        utils.test_create(conn, out_xml)
Пример #2
0
    def __init__(self, conn, image, boot_index=None):
        Installer.__init__(self, conn)

        self._image = image

        # Set boot _boot_caps/_boot_parameters
        if boot_index is None:
            self._boot_caps = match_boots(self.conn.caps,
                                     self.image.domain.boots)
            if self._boot_caps is None:
                raise RuntimeError(_("Could not find suitable boot "
                                     "descriptor for this host"))
        else:
            if (boot_index < 0 or
                (boot_index + 1) > len(image.domain.boots)):
                raise ValueError(_("boot_index out of range."))
            self._boot_caps = image.domain.boots[boot_index]

        # Set up internal caps.guest object
        self._guest = self.conn.caps.guestForOSType(self.boot_caps.type,
                                                    self.boot_caps.arch)
        if self._guest is None:
            raise RuntimeError(_("Unsupported virtualization type: %s %s" %
                               (self.boot_caps.type, self.boot_caps.arch)))
        self._domain = self._guest.bestDomainType()
Пример #3
0
    def _convert_helper(self, in_path, out_path, in_type, disk_format):
        outbuf = io.StringIO()

        def print_cb(msg):
            print(msg, file=outbuf)

        conn = utils.URIs.open_kvm()
        converter = VirtConverter(conn, in_path, print_cb=print_cb)

        if converter.parser.name != in_type:
            raise AssertionError("find_parser_by_file for '%s' returned "
                                 "wrong parser type.\n"
                                 "Expected: %s\n"
                                 "Received: %s\n" %
                                 (in_path, in_type, converter.parser.name))

        converter.convert_disks(disk_format, dry=True)
        guest = converter.get_guest()
        installer = Installer(guest.conn)
        ignore, out_xml = installer.start_install(guest, return_xml=True)
        out_expect = out_xml
        if outbuf.getvalue():
            out_expect += ("\n\n" + outbuf.getvalue().replace(base_dir, ""))

        if not conn.check_support(conn.SUPPORT_CONN_VMPORT):
            self.skipTest("Not comparing XML because vmport isn't supported")

        utils.diff_compare(out_expect, out_path)
        utils.test_create(conn, out_xml)
Пример #4
0
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))
Пример #5
0
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
Пример #6
0
    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))
Пример #7
0
    def __init__(self, conn, image, boot_index=None):
        Installer.__init__(self, conn)

        self._image = image

        # Set boot _boot_caps/_boot_parameters
        if boot_index is None:
            self._boot_caps = match_boots(self.conn.caps,
                                     self.image.domain.boots)
            if self._boot_caps is None:
                raise RuntimeError(_("Could not find suitable boot "
                                     "descriptor for this host"))
        else:
            if (boot_index < 0 or
                (boot_index + 1) > len(image.domain.boots)):
                raise ValueError(_("boot_index out of range."))
            self._boot_caps = image.domain.boots[boot_index]

        # Set up internal caps.guest object
        self._guest, self._domain = self.conn.caps.guest_lookup(
            os_type=self.boot_caps.type, arch=self.boot_caps.arch)
Пример #8
0
    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))
Пример #9
0
    def __init__(self, *args, **kwargs):
        Installer.__init__(self, *args, **kwargs)

        self.livecd = False
        self._location_is_path = True
Пример #10
0
    def __init__(self, *args, **kwargs):
        Installer.__init__(self, *args, **kwargs)

        self.livecd = False