Exemplo n.º 1
0
    def test_determine_vm_mode_returns_hvm(self):
        self.mox.StubOutWithMock(vm_mode, "get_from_instance")

        fake_instance = "instance"
        vm_mode.get_from_instance(fake_instance).AndReturn(vm_mode.HVM)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.HVM, self._vmops._determine_vm_mode(fake_instance, None, None))
        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_determine_vm_mode_returns_hvm(self):
        self.mox.StubOutWithMock(vm_mode, 'get_from_instance')

        fake_instance = "instance"
        vm_mode.get_from_instance(fake_instance).AndReturn(vm_mode.HVM)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.HVM,
            self._vmops._determine_vm_mode(fake_instance, None, None))
        self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_determine_vm_mode_returns_is_not_pv_no_root_disk(self):
        self.mox.StubOutWithMock(vm_mode, "get_from_instance")
        self.mox.StubOutWithMock(vm_utils, "determine_is_pv")

        fake_instance = {"os_type": "foo"}
        fake_vdis = {"iso": {"ref": "fake"}}
        fake_disk_type = "disk"
        vm_mode.get_from_instance(fake_instance).AndReturn(None)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.HVM, self._vmops._determine_vm_mode(fake_instance, fake_vdis, fake_disk_type))
        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_determine_vm_mode_returns_is_not_pv_no_root_disk(self):
        self.mox.StubOutWithMock(vm_mode, 'get_from_instance')
        self.mox.StubOutWithMock(vm_utils, 'determine_is_pv')

        fake_instance = {"os_type": "foo"}
        fake_vdis = {'iso': {"ref": 'fake'}}
        fake_disk_type = "disk"
        vm_mode.get_from_instance(fake_instance).AndReturn(None)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.HVM,
            self._vmops._determine_vm_mode(fake_instance, fake_vdis,
                                     fake_disk_type))
        self.mox.VerifyAll()
Exemplo n.º 5
0
def get_disk_bus_for_device_type(virt_type,
                                 image_meta,
                                 device_type="disk",
                                 instance=None):
    """Determine the best disk bus to use for a device type.

       Considering the currently configured virtualization
       type, return the optimal disk_bus to use for a given
       device type. For example, for a disk on KVM it will
       return 'virtio', while for a CDROM it will return 'ide'
       on x86_64 and 'scsi' on ppc64.

       Returns the disk_bus, or returns None if the device
       type is not supported for this virtualization
    """

    # Prefer a disk bus set against the image first of all
    key = "hw_" + device_type + "_bus"
    disk_bus = image_meta.get('properties', {}).get(key)
    if disk_bus is not None:
        if not is_disk_bus_valid_for_virt(virt_type, disk_bus):
            raise exception.UnsupportedHardware(model=disk_bus,
                                                virt=virt_type)
        return disk_bus

    # Otherwise pick a hypervisor default disk bus
    if virt_type == "uml":
        if device_type == "disk":
            return "uml"
    elif virt_type == "lxc":
        return "lxc"
    elif virt_type == "xen":
        guest_vm_mode = None
        if instance:
            guest_vm_mode = vm_mode.get_from_instance(instance)
        if guest_vm_mode == vm_mode.HVM:
            return "ide"
        else:
            return "xen"
    elif virt_type in ("qemu", "kvm"):
        if device_type == "cdrom":
            guestarch = libvirt_utils.get_arch(image_meta)
            if guestarch in (arch.PPC, arch.PPC64, arch.S390, arch.S390X):
                return "scsi"
            else:
                return "ide"
        elif device_type == "disk":
            return "virtio"
        elif device_type == "floppy":
            return "fdc"
    elif virt_type == "parallels":
        if device_type == "cdrom":
            return "ide"
        elif device_type in ("disk", "fs"):
            return "sata"
    else:
        # If virt-type not in list then it is unsupported
        raise exception.UnsupportedVirtType(virt=virt_type)

    return None
Exemplo n.º 6
0
    def test_determine_vm_mode_returns_is_not_pv(self):
        self.mox.StubOutWithMock(vm_mode, 'get_from_instance')
        self.mox.StubOutWithMock(vm_utils, 'determine_is_pv')

        fake_instance = {"os_type": "foo"}
        fake_vdis = {'root': {"ref": 'fake'}}
        fake_disk_type = "disk"
        vm_mode.get_from_instance(fake_instance).AndReturn(None)
        vm_utils.determine_is_pv(self._session, "fake", fake_disk_type,
            "foo").AndReturn(False)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.HVM,
            self._vmops._determine_vm_mode(fake_instance, fake_vdis,
                                     fake_disk_type))
        self.mox.VerifyAll()
Exemplo n.º 7
0
    def test_determine_vm_mode_returns_is_pv(self):
        self.mox.StubOutWithMock(vm_mode, 'get_from_instance')
        self.mox.StubOutWithMock(vm_utils, 'determine_is_pv')

        fake_instance = {"os_type": "foo"}
        fake_vdis = {'root': {"ref": 'fake'}}
        fake_disk_type = "disk"
        vm_mode.get_from_instance(fake_instance).AndReturn(None)
        vm_utils.determine_is_pv(self._session, "fake", fake_disk_type,
            "foo").AndReturn(True)

        self.mox.ReplayAll()
        self.assertEquals(vm_mode.XEN,
            self._vmops._determine_vm_mode(fake_instance, fake_vdis,
                                     fake_disk_type))
        self.mox.VerifyAll()
Exemplo n.º 8
0
def get_disk_bus_for_device_type(virt_type,
                                 image_meta,
                                 device_type="disk",
                                 instance=None):
    """Determine the best disk bus to use for a device type.

       Considering the currently configured virtualization
       type, return the optimal disk_bus to use for a given
       device type. For example, for a disk on KVM it will
       return 'virtio', while for a CDROM it will return 'ide'
       on x86_64 and 'scsi' on ppc64.

       Returns the disk_bus, or returns None if the device
       type is not supported for this virtualization
    """

    # Prefer a disk bus set against the image first of all
    key = "hw_" + device_type + "_bus"
    disk_bus = image_meta.get('properties', {}).get(key)
    if disk_bus is not None:
        if not is_disk_bus_valid_for_virt(virt_type, disk_bus):
            raise exception.UnsupportedHardware(model=disk_bus,
                                                virt=virt_type)
        return disk_bus

    # Otherwise pick a hypervisor default disk bus
    if virt_type == "uml":
        if device_type == "disk":
            return "uml"
    elif virt_type == "lxc":
        return "lxc"
    elif virt_type == "xen":
        guest_vm_mode = None
        if instance:
            guest_vm_mode = vm_mode.get_from_instance(instance)
        if guest_vm_mode == vm_mode.HVM:
            return "ide"
        else:
            return "xen"
    elif virt_type in ("qemu", "kvm"):
        if device_type == "cdrom":
            guestarch = libvirt_utils.get_arch(image_meta)
            if guestarch in (arch.PPC, arch.PPC64, arch.S390, arch.S390X):
                return "scsi"
            else:
                return "ide"
        elif device_type == "disk":
            return "virtio"
        elif device_type == "floppy":
            return "fdc"
    elif virt_type == "parallels":
        if device_type == "cdrom":
            return "ide"
        elif device_type == "disk":
            return "sata"
    else:
        # If virt-type not in list then it is unsupported
        raise exception.UnsupportedVirtType(virt=virt_type)

    return None
Exemplo n.º 9
0
 def test_good(self):
     inst = dict(vm_mode="hvm")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "hvm")
Exemplo n.º 10
0
 def test_legacy_pv(self):
     inst = dict(vm_mode="pv")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "xen")
Exemplo n.º 11
0
 def test_good(self):
     inst = ComputeVMModeTest.testinstance("hvm")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "hvm")
Exemplo n.º 12
0
 def test_legacy_pv(self):
     inst = ComputeVMModeTest.testinstance("pv")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "xen")
Exemplo n.º 13
0
 def test_good(self):
     inst = self._fake_object(dict(vm_mode="hvm"))
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "hvm")
Exemplo n.º 14
0
 def test_legacy_pv(self):
     inst = ComputeVMModeTest.testinstance("pv")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "xen")
 def test_legacy_pv(self):
     inst = dict(vm_mode="pv")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "xen")
 def test_good(self):
     inst = dict(vm_mode="hvm")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "hvm")
Exemplo n.º 17
0
 def test_good(self):
     inst = ComputeVMModeTest.testinstance("hvm")
     mode = vm_mode.get_from_instance(inst)
     self.assertEqual(mode, "hvm")