def test_get_controllers(self, mock_controller_disks, mock_vm_info):
        mock_controller_disks.return_value = mock.sentinel.disks
        mock_vm_info.return_value = {
            'storagecontrollername1': fake.FAKE_SYSTEM_BUS_IDE,
            'storagecontrollername2': fake.FAKE_SYSTEM_BUS_SATA,
            'storagecontrollername3': fake.FAKE_SYSTEM_BUS_SCSI,
            'key': None
        }
        controllers = {fake.FAKE_SYSTEM_BUS_IDE: mock.sentinel.disks,
                       fake.FAKE_SYSTEM_BUS_SATA: mock.sentinel.disks,
                       fake.FAKE_SYSTEM_BUS_SCSI: mock.sentinel.disks}
        response = vhdutils.get_controllers(self._instance)

        mock_vm_info.assert_called_once_with(self._instance)
        self.assertEqual(len(controllers), mock_controller_disks.call_count)
        self.assertEqual(controllers, response)
예제 #2
0
    def test_get_controllers(self, mock_controller_disks, mock_vm_info):
        mock_controller_disks.return_value = mock.sentinel.disks
        mock_vm_info.return_value = {
            'storagecontrollername1': fake.FAKE_SYSTEM_BUS_IDE,
            'storagecontrollername2': fake.FAKE_SYSTEM_BUS_SATA,
            'storagecontrollername3': fake.FAKE_SYSTEM_BUS_SCSI,
            'key': None
        }
        controllers = {
            fake.FAKE_SYSTEM_BUS_IDE: mock.sentinel.disks,
            fake.FAKE_SYSTEM_BUS_SATA: mock.sentinel.disks,
            fake.FAKE_SYSTEM_BUS_SCSI: mock.sentinel.disks
        }
        response = vhdutils.get_controllers(self._instance)

        mock_vm_info.assert_called_once_with(self._instance)
        self.assertEqual(len(controllers), mock_controller_disks.call_count)
        self.assertEqual(controllers, response)
예제 #3
0
    def _detach_storage(self, instance):
        """Detach all disks and volumes attached to the current instance.

        Return a list with all disks detached.
        """
        disks = []
        for controller in vhdutils.get_controllers(instance):
            for attach_point, disk in controller.items():
                if not disk['path']:
                    continue

                LOG.debug(
                    "Trying to detach %(disk)s from %(controller)s: "
                    "%(attach_point)s", {
                        "disk": disk,
                        "controller": controller,
                        "attach_point": attach_point
                    })
                try:
                    self._vbox_manage.storage_attach(
                        instance,
                        controller,
                        port=attach_point[0],
                        device=attach_point[1],
                        drive_type=constants.STORAGE_HDD,
                        medium=constants.MEDIUM_NONE,
                    )
                except vbox_exc.VBoxException as exc:
                    LOG.warning(
                        i18n._LW("Failed to detach distk %(disk)s: "
                                 "%(reason)s"), {
                                     "disk": disk,
                                     "reason": exc
                                 })

                if '|' in disk["path"]:
                    LOG.debug("Trying to unregister %(path)s",
                              {"path": disk["path"]})
                    self._vbox_manage.close_medium(constants.MEDIUM_DISK,
                                                   disk["path"])
                else:
                    disks.append(disk)

        return disks
    def _detach_storage(self, instance):
        """Detach all disks and volumes attached to the current instance.

        Return a list with all disks detached.
        """
        disks = []
        for controller in vhdutils.get_controllers(instance):
            for attach_point, disk in controller.items():
                if not disk['path']:
                    continue

                LOG.debug("Trying to detach %(disk)s from %(controller)s: "
                          "%(attach_point)s",
                          {"disk": disk, "controller": controller,
                           "attach_point": attach_point})
                try:
                    self._vbox_manage.storage_attach(
                        instance, controller,
                        port=attach_point[0], device=attach_point[1],
                        drive_type=constants.STORAGE_HDD,
                        medium=constants.MEDIUM_NONE,
                    )
                except vbox_exc.VBoxException as exc:
                    LOG.warning(i18n._LW("Failed to detach distk %(disk)s: "
                                         "%(reason)s"),
                                         {"disk": disk, "reason": exc})

                if '|' in disk["path"]:
                    LOG.debug("Trying to unregister %(path)s",
                              {"path": disk["path"]})
                    self._vbox_manage.close_medium(constants.MEDIUM_DISK,
                                                   disk["path"])
                else:
                    disks.append(disk)

        return disks