def _paginate_resultset(result, function_ref, *argv, **kwargs): """ Paginate through a query that returns a :py:class:`boto.resultset.ResultSet` object, and return the combined result. All function calls are passed through :py:func:`~.invoke_with_throttling_retries`. :param result: the first ResultSet from the query :type result: :py:class:`boto.resultset.ResultSet` :param function_ref: the function to call :type function_ref: function :param argv: the parameters to pass to the function :type argv: tuple :param kwargs: keyword arguments to pass to the function (:py:func:`~.invoke_with_throttling_retries`) :type kwargs: dict """ logger.debug("Iterating all ResultSets for query of %s", function_ref) # we don't want any markers in the final result final_result = ResultSet() final_result.extend(result) while hasattr(result, 'next_token') and result.next_token is not None: logger.debug("Getting next response set; next_token=%s", result.next_token) next_kwargs = deepcopy(kwargs) next_kwargs['next_token'] = result.next_token result = invoke_with_throttling_retries( function_ref, *argv, **next_kwargs) final_result.extend(result) return final_result
def test_get_stacks_correctly_calls_aws_api(self, cloudformation_mock): stacks = [Mock(spec=Stack), Mock(spec=Stack)] result = ResultSet() result.extend(stacks) result.next_token = None cloudformation_mock.connect_to_region.return_value.describe_stacks.return_value = result cfn = CloudFormation() self.assertListEqual(stacks, cfn.get_stacks())
def test_get_stacks_correctly_aggregates_paged_results(self, cloudformation_mock): stacks_1 = [Mock(spec=Stack), Mock(spec=Stack)] stacks_2 = [Mock(spec=Stack), Mock(spec=Stack)] result_1 = ResultSet() result_1.extend(stacks_1) result_1.next_token = "my-next-token" result_2 = ResultSet() result_2.extend(stacks_2) result_2.next_token = None cloudformation_mock.connect_to_region.return_value.describe_stacks.side_effect = [result_1, result_2] cfn = CloudFormation() self.assertListEqual(stacks_1 + stacks_2, cfn.get_stacks())
def test_get_stacks_correctly_aggregates_paged_results( self, cloudformation_mock): stacks_1 = [Mock(spec=Stack), Mock(spec=Stack)] stacks_2 = [Mock(spec=Stack), Mock(spec=Stack)] result_1 = ResultSet() result_1.extend(stacks_1) result_1.next_token = "my-next-token" result_2 = ResultSet() result_2.extend(stacks_2) result_2.next_token = None cloudformation_mock.connect_to_region.return_value.describe_stacks.side_effect = [ result_1, result_2 ] cfn = CloudFormation() self.assertListEqual(stacks_1 + stacks_2, cfn.get_stacks())