def test_disk_ops_vm_suspended(self):
        """ Attach/detach a disk from a vm when vm is suspended
        """
        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        handler.hypervisor = MagicMock()
        handler.hypervisor.vm_manager.attach_disk.side_effect = VmPowerStateException
        handler.hypervisor.vm_manager.detach_disk.side_effect = VmPowerStateException

        response = handler.attach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
        response = handler.detach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
Example #2
0
    def test_disk_ops_vm_suspended(self):
        """ Attach/detach a disk from a vm when vm is suspended
        """
        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        handler.hypervisor = MagicMock()
        vm = Vm(id="vm.id", state=VmState.SUSPENDED)
        handler.hypervisor.vm_manager.get_resource.return_value = vm

        response = handler.attach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
        response = handler.detach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
    def test_disk_ops_vm_not_found(self):
        """
        Attaching/detaching a disk from a vm that doesn't exist should report
        error
        """
        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        handler.hypervisor = MagicMock()
        handler.hypervisor.vm_manager.attach_disk.side_effect = VmNotFoundException
        handler.hypervisor.vm_manager.detach_disk.side_effect = VmNotFoundException

        response = handler.attach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.VM_NOT_FOUND))
        response = handler.detach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.VM_NOT_FOUND))
    def test_disk_ops_disk_not_found(self):
        """Attaching/detaching a disk that doesn't exist should report error"""

        def _raise_disk_not_found_exception(disk_id):
            raise DiskNotFoundException

        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        get_resource = MagicMock()
        get_resource.side_effect = _raise_disk_not_found_exception
        handler.hypervisor.disk_manager.get_resource = get_resource

        response = handler.attach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.DISK_NOT_FOUND))
        response = handler.detach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.DISK_NOT_FOUND))
    def test_disk_ops_vm_suspended(self):
        """ Attach/detach a disk from a vm when vm is suspended
        """
        req = VmDisksDetachRequest(vm_id="vm.id",
                                   disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        handler.hypervisor = MagicMock()
        vm = Vm(id="vm.id", state=VmState.SUSPENDED)
        handler.hypervisor.vm_manager.get_resource.return_value = vm

        response = handler.attach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
        response = handler.detach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.INVALID_VM_POWER_STATE))
Example #6
0
    def test_disk_ops_disk_not_found(self):
        """Attaching/detaching a disk that doesn't exist should report error"""
        def _raise_disk_not_found_exception(disk_id):
            raise DiskNotFoundException

        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        get_resource = MagicMock()
        get_resource.side_effect = _raise_disk_not_found_exception
        handler.hypervisor.disk_manager.get_resource = get_resource

        response = handler.attach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.DISK_NOT_FOUND))
        response = handler.detach_disks(req)
        assert_that(response.result,
                    equal_to(VmDiskOpResultCode.DISK_NOT_FOUND))
Example #7
0
    def test_disk_ops_vm_not_found(self):
        """
        Attaching/detaching a disk from a vm that doesn't exist should report
        error
        """
        req = VmDisksDetachRequest(vm_id="vm.id", disk_ids=["disk.id"])

        handler = HostHandler(MagicMock())
        handler.hypervisor = MagicMock()
        handler.hypervisor.disk_manager.get_resource = MagicMock()
        handler.hypervisor.vm_manager.get_vm_config.side_effect = \
            VmNotFoundException
        handler.hypervisor.vm_manager.get_resource.side_effect = \
            VmNotFoundException

        response = handler.attach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.VM_NOT_FOUND))
        response = handler.detach_disks(req)
        assert_that(response.result, equal_to(VmDiskOpResultCode.VM_NOT_FOUND))