Esempio n. 1
0
    def connect_volume(self, volume, **connect_opts):
        mountpoint = connect_opts.get('mountpoint', None)
        host_name = utils.get_hostname()

        try:
            self.cinderclient.volumes.reserve(volume)
        except cinder_exception.ClientException:
            LOG.error(_LE("Reserve volume %s failed"), volume)
            raise

        try:
            device_info = self._connect_volume(volume)
            self.cinderclient.volumes.attach(volume=volume,
                                             instance_uuid=None,
                                             mountpoint=mountpoint,
                                             host_name=host_name)
            LOG.info(_LI("Attach volume to this server successfully"))
        except Exception:
            LOG.error(_LE("Attach volume %s to this server failed"), volume)
            with excutils.save_and_reraise_exception():
                try:
                    self._disconnect_volume(volume)
                except Exception:
                    pass
                self.cinderclient.volumes.unreserve(volume)

        return device_info
Esempio n. 2
0
    def connect_volume(self, volume, **connect_opts):
        mountpoint = connect_opts.get('mountpoint', None)
        host_name = utils.get_hostname()

        try:
            self.cinderclient.volumes.reserve(volume)
        except cinder_exception.ClientException:
            LOG.error(_LE("Reserve volume %s failed"), volume)
            raise

        try:
            device_info = self._connect_volume(volume)
            self.cinderclient.volumes.attach(volume=volume,
                                             instance_uuid=None,
                                             mountpoint=mountpoint,
                                             host_name=host_name)
            LOG.info(_LI("Attach volume to this server successfully"))
        except Exception:
            LOG.error(_LE("Attach volume %s to this server failed"), volume)
            with excutils.save_and_reraise_exception():
                try:
                    self._disconnect_volume(volume)
                except Exception:
                    pass
                self.cinderclient.volumes.unreserve(volume)

        return device_info
Esempio n. 3
0
def get_host_id():
    """Get a value that could represent this server."""
    host_id = None
    volume_connector = cinder_conf.volume_connector
    if volume_connector == OPENSTACK:
        host_id = utils.get_instance_uuid()
    elif volume_connector == OSBRICK:
        host_id = utils.get_hostname().lower()
    return host_id
Esempio n. 4
0
def get_host_id():
    """Get a value that could represent this server."""
    host_id = None
    volume_connector = cinder_conf.volume_connector
    if volume_connector == OPENSTACK:
        host_id = utils.get_instance_uuid()
    elif volume_connector == OSBRICK:
        host_id = utils.get_hostname().lower()
    return host_id
Esempio n. 5
0
def mock_list_with_attach_to_other(cls, search_opts={}):
    attachments = [{
        u'server_id': u'123',
        u'attachment_id': u'123',
        u'attached_at': u'2016-05-20T09:19:57.000000',
        u'host_name': utils.get_hostname() + u'other',
        u'device': None,
        u'id': u'123'
    }]
    return [
        fake_object.FakeCinderVolume(name='fake-vol1', attachments=attachments)
    ]
Esempio n. 6
0
 def test_disconnect_volume_no_connection_info(self, mock_execute,
                                               mock_init_conn):
     attachments = [{
         u'server_id': u'123',
         u'attachment_id': u'123',
         u'attached_at': u'2016-05-20T09:19:57.000000',
         u'host_name': utils.get_hostname(),
         u'device': None,
         u'id': u'123'
     }]
     fake_cinder_volume = \
         fake_object.FakeCinderVolume(attachments=attachments)
     self.assertRaises(cinder_exception.ClientException,
                       self.connector.disconnect_volume, fake_cinder_volume)
Esempio n. 7
0
    def test_disconnect_volume(self, mock_brick_connector, mock_execute):
        attachments = [{
            u'server_id': u'123',
            u'attachment_id': u'123',
            u'attached_at': u'2016-05-20T09:19:57.000000',
            u'host_name': utils.get_hostname(),
            u'device': None,
            u'id': u'123'
        }]
        fake_cinder_volume = \
            fake_object.FakeCinderVolume(attachments=attachments)

        self.connector._get_connection_info = mock.MagicMock()
        self.connector.cinderclient.volumes.detach = mock.MagicMock()
        self.assertIsNone(self.connector.disconnect_volume(fake_cinder_volume))
Esempio n. 8
0
 def test_disconnect_volume_osbrick_disconnect_failed(
         self, mock_connector, mock_init_conn, mock_execute,
         mock_disconnect_vol):
     attachments = [{
         u'server_id': u'123',
         u'attachment_id': u'123',
         u'attached_at': u'2016-05-20T09:19:57.000000',
         u'host_name': utils.get_hostname(),
         u'device': None,
         u'id': u'123'
     }]
     fake_cinder_volume = \
         fake_object.FakeCinderVolume(attachments=attachments)
     self.assertRaises(processutils.ProcessExecutionError,
                       self.connector.disconnect_volume, fake_cinder_volume)
Esempio n. 9
0
    def test_delete(self, mock_execute):
        fd, tmpfname = tempfile.mkstemp()
        attachments = [{u'server_id': u'123',
                        u'attachment_id': u'123',
                        u'attached_at': u'2016-05-20T09:19:57.000000',
                        u'host_name': utils.get_hostname(),
                        u'device': None,
                        u'id': u'123'}]

        self.cinderprovider._get_docker_volume = mock.MagicMock()
        self.cinderprovider._get_docker_volume.return_value = (
            fake_object.FakeCinderVolume(id=tmpfname,
                                         attachments=attachments),
            consts.ATTACH_TO_THIS)
        self.cinderprovider._delete_volume = mock.MagicMock()

        self.assertTrue(self.cinderprovider.delete('fake-vol'))
Esempio n. 10
0
    def disconnect_volume(self, volume, **disconnect_opts):
        self._disconnect_volume(volume)

        attachments = volume.attachments
        attachment_uuid = None
        for am in attachments:
            if am['host_name'].lower() == utils.get_hostname().lower():
                attachment_uuid = am['attachment_id']
                break
        try:
            self.cinderclient.volumes.detach(volume.id,
                                             attachment_uuid=attachment_uuid)
            LOG.info(_LI("Disconnect volume successfully"))
        except cinder_exception.ClientException as e:
            msg = _LE("Error happened when detach volume {0} {1} from this "
                      "server. Error: {2}").format(volume.name, volume, e)
            LOG.error(msg)
            raise
Esempio n. 11
0
    def disconnect_volume(self, volume, **disconnect_opts):
        self._disconnect_volume(volume)

        attachments = volume.attachments
        attachment_uuid = None
        for am in attachments:
            if am['host_name'].lower() == utils.get_hostname().lower():
                attachment_uuid = am['attachment_id']
                break
        try:
            self.cinderclient.volumes.detach(volume.id,
                                             attachment_uuid=attachment_uuid)
            LOG.info(_LI("Disconnect volume successfully"))
        except cinder_exception.ClientException as e:
            msg = _LE("Error happened when detach volume {0} {1} from this "
                      "server. Error: {2}").format(volume.name, volume, e)
            LOG.error(msg)
            raise
Esempio n. 12
0
    def test_delete_failed(self, mock_execute, mock_delete):
        fd, tmpfname = tempfile.mkstemp()
        attachments = [{
            u'server_id': u'123',
            u'attachment_id': u'123',
            u'attached_at': u'2016-05-20T09:19:57.000000',
            u'host_name': utils.get_hostname(),
            u'device': None,
            u'id': u'123'
        }]

        self.cinderprovider._get_docker_volume = mock.MagicMock()
        self.cinderprovider._get_docker_volume.return_value = (
            fake_object.FakeCinderVolume(id=tmpfname, attachments=attachments),
            consts.ATTACH_TO_THIS)

        self.assertRaises(cinder_exception.ClientException,
                          self.cinderprovider.delete, 'fake-vol')
Esempio n. 13
0
    def test_delete_timeout(self, mock_execute):
        consts.DESTROY_VOLUME_TIMEOUT = 4
        fd, tmpfname = tempfile.mkstemp()
        attachments = [{u'server_id': u'123',
                        u'attachment_id': u'123',
                        u'attached_at': u'2016-05-20T09:19:57.000000',
                        u'host_name': utils.get_hostname(),
                        u'device': None,
                        u'id': u'123'}]

        self.cinderprovider._get_docker_volume = mock.MagicMock()
        self.cinderprovider._get_docker_volume.return_value = (
            fake_object.FakeCinderVolume(id=tmpfname,
                                         attachments=attachments),
            consts.ATTACH_TO_THIS)

        self.assertRaises(exceptions.TimeoutException,
                          self.cinderprovider.delete,
                          'fake-vol')
Esempio n. 14
0
    def disconnect_volume(self, volume, **disconnect_opts):
        self._disconnect_volume(volume)

        attachments = volume.attachments
        attachment_uuid = None
        for am in attachments:
            if am['host_name'].lower() == utils.get_hostname().lower():
                attachment_uuid = am['attachment_id']
                break
        try:
            self.cinderclient.volumes.detach(volume.id,
                                             attachment_uuid=attachment_uuid)
            LOG.info("Disconnect volume successfully")
        except cinder_exception.ClientException as e:
            LOG.error(
                "Error happened when detach volume %(vol)s from this"
                " server. Error: %(err)s", {
                    'vol': volume,
                    'err': e
                })
            raise