'Poll the dataset state API until the supplied dataset exists.
:param Dataset expected_dataset: The configured dataset that
we\'re waiting for in state.
:returns: A ``Deferred`` which fires with the ``DatasetState`` of the
cluster when the cluster state matches the configuration for the
given dataset.'

@log_method
def wait_for_dataset(self, expected_dataset):

    expected_dataset_state = DatasetState(dataset_id=expected_dataset.dataset_id, primary=expected_dataset.primary, maximum_size=expected_dataset.maximum_size, path=None)
    def created():
        '\n                                                Check    the    dataset    state    list    for    the    expected    dataset.\n                                                '
        request = self.client.list_datasets_state()
        def got_results(results):
            actual_dataset_states = list((d for d in results if (d.set('path', None) == expected_dataset_state)))
            if actual_dataset_states:
                return actual_dataset_states[0]
            else:
                return None
        request.addCallback(got_results)
        return request
    waiting = loop_until(reactor, created)
    return waiting
