'Waits for a server to swap the old volume to a new one.'

def _wait_for_server_volume_swap(self, server_id, old_volume_id, new_volume_id):

    volume_attachments = self.servers_client.list_volume_attachments(server_id)['volumeAttachments']
    attached_volume_ids = [attachment['volumeId'] for attachment in volume_attachments]
    start = int(time.time())
    while ((old_volume_id in attached_volume_ids) or (new_volume_id not in attached_volume_ids)):
        time.sleep(self.servers_client.build_interval)
        volume_attachments = self.servers_client.list_volume_attachments(server_id)['volumeAttachments']
        attached_volume_ids = [attachment['volumeId'] for attachment in volume_attachments]
        if ((int(time.time()) - start) >= self.servers_client.build_timeout):
            old_vol_bdm_status = ('in    BDM' if (old_volume_id in attached_volume_ids) else 'not    in    BDM')
            new_vol_bdm_status = ('in    BDM' if (new_volume_id in attached_volume_ids) else 'not    in    BDM')
            message = ('Failed    to    swap    old    volume    %(old_volume_id)s    (current    %(old_vol_bdm_status)s)    to    new    volume    %(new_volume_id)s    (current    %(new_vol_bdm_status)s)    on    server    %(server_id)s    within    the    required    time    (%(timeout)s    s)' % {'old_volume_id': old_volume_id, 'old_vol_bdm_status': old_vol_bdm_status, 'new_volume_id': new_volume_id, 'new_vol_bdm_status': new_vol_bdm_status, 'server_id': server_id, 'timeout': self.servers_client.build_timeout})
            raise lib_exc.TimeoutException(message)
