'Attaches volume to server and waits for \'in-use\' volume status.
The volume will be detached when the test tears down.
:param server: The server to which the volume will be attached.
:param volume: The volume to attach.
:param device: Optional mountpoint for the attached volume. Note that
this is not guaranteed for all hypervisors and is not recommended.
:param check_reserved: Consider a status of reserved as valid for
completion. This is to handle new Cinder attach where we more
accurately use \'reserved\' for things like attaching to a shelved
server.'

def attach_volume(self, server, volume, device=None, check_reserved=False):

    attach_kwargs = dict(volumeId=volume['id'])
    if device:
        attach_kwargs['device'] = device
    attachment = self.servers_client.attach_volume(server['id'], **attach_kwargs)['volumeAttachment']
    self.addCleanup(waiters.wait_for_volume_resource_status, self.volumes_client, volume['id'], 'available')
    self.addCleanup(test_utils.call_and_ignore_notfound_exc, self.servers_client.detach_volume, server['id'], volume['id'])
    statuses = ['in-use']
    if check_reserved:
        statuses.append('reserved')
    waiters.wait_for_volume_resource_status(self.volumes_client, volume['id'], statuses)
    return attachment
