Example #1
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug("Detach_volume: %(instance_name)s, %(mountpoint)s", {
            'instance_name': instance_name,
            'mountpoint': mountpoint
        })

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warning(
                _LW('Skipping detach because VBD for %s was '
                    'not found'), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(
                _LI('Mountpoint %(mountpoint)s detached from instance'
                    ' %(instance_name)s'), {
                        'instance_name': instance_name,
                        'mountpoint': mountpoint
                    })
Example #2
0
    def test_find_vbd_by_number_no_vbds(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = []

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        self.assertFalse(session.VBD.get_userdevice.called)
Example #3
0
    def test_find_vbd_by_number_no_vbds(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = []

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        self.assertFalse(session.VBD.get_userdevice.called)
Example #4
0
    def test_find_vbd_by_number_works(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = ["a", "b"]
        session.VBD.get_userdevice.return_value = "1"

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertEqual("a", result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        session.VBD.get_userdevice.assert_called_once_with("a")
Example #5
0
    def test_find_vbd_by_number_works(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = ["a", "b"]
        session.VBD.get_userdevice.return_value = "1"

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertEqual("a", result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        session.VBD.get_userdevice.assert_called_once_with("a")
Example #6
0
    def test_find_vbd_by_number_ignores_exception(self):
        session = mock.Mock()
        session.XenAPI.Failure = test.TestingException
        session.VM.get_VBDs.return_value = ["a"]
        session.VBD.get_userdevice.side_effect = test.TestingException

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        session.VBD.get_userdevice.assert_called_once_with("a")
Example #7
0
    def test_find_vbd_by_number_ignores_exception(self):
        session = mock.Mock()
        session.XenAPI.Failure = test.TestingException
        session.VM.get_VBDs.return_value = ["a"]
        session.VBD.get_userdevice.side_effect = test.TestingException

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        session.VBD.get_userdevice.assert_called_once_with("a")
Example #8
0
    def test_find_vbd_by_number_no_matches(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = ["a", "b"]
        session.VBD.get_userdevice.return_value = "3"

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        expected = [mock.call("a"), mock.call("b")]
        self.assertEqual(expected, session.VBD.get_userdevice.call_args_list)
Example #9
0
    def test_find_vbd_by_number_no_matches(self):
        session = mock.Mock()
        session.VM.get_VBDs.return_value = ["a", "b"]
        session.VBD.get_userdevice.return_value = "3"

        result = volume_utils.find_vbd_by_number(session, "vm_ref", 1)

        self.assertIsNone(result)
        session.VM.get_VBDs.assert_called_once_with("vm_ref")
        expected = [mock.call("a"), mock.call("b")]
        self.assertEqual(expected, session.VBD.get_userdevice.call_args_list)
Example #10
0
    def detach_volume(self, connection_info, instance_name, mountpoint):
        """Detach volume storage to VM instance."""
        LOG.debug("Detach_volume: %(instance_name)s, %(mountpoint)s",
                  {'instance_name': instance_name, 'mountpoint': mountpoint})

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        device_number = volume_utils.get_device_number(mountpoint)
        vbd_ref = volume_utils.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)

        if vbd_ref is None:
            # NOTE(sirp): If we don't find the VBD then it must have been
            # detached previously.
            LOG.warning(_LW('Skipping detach because VBD for %s was '
                            'not found'), instance_name)
        else:
            self._detach_vbds_and_srs(vm_ref, [vbd_ref])
            LOG.info(_LI('Mountpoint %(mountpoint)s detached from instance'
                         ' %(instance_name)s'),
                     {'instance_name': instance_name,
                      'mountpoint': mountpoint})