-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[master] S3 Pillar Pagination Fixes #55694
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9398830
Fixing S3 pillar when the keys in a bucket exceed 1000, ensure we are…
garethgreenaway 28700f8
Open cache file as binary so writing works under Python3.
garethgreenaway 9d5d96c
Adding test to test s3 pillar.
garethgreenaway 77eb90d
Fixing lint
garethgreenaway 52cf5f4
Merge branch 'master' into 55662_s3_pillar_fixes
dwoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Import python libs | ||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
import logging | ||
|
||
# Import Salt Testing libs | ||
from tests.support.mixins import LoaderModuleMockMixin | ||
from tests.support.unit import TestCase | ||
from tests.support.mock import patch, mock_open, MagicMock | ||
|
||
# Import Salt Libs | ||
import salt.pillar.s3 as s3_pillar | ||
from salt.ext.six.moves import range | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class S3PillarTestCase(TestCase, LoaderModuleMockMixin): | ||
''' | ||
TestCase for salt.pillar.s3 | ||
''' | ||
def setup_loader_modules(self): | ||
s3_pillar_globals = { | ||
'__utils__': {} | ||
} | ||
return {s3_pillar: s3_pillar_globals} | ||
|
||
def test_refresh_buckets_cache_file(self): | ||
''' | ||
Test pagination with refresh_buckets_cache_file | ||
''' | ||
key = 'XXXXXXXXXXXXXXXXXXXXX' | ||
keyid = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
bucket = 'dummy_bucket' | ||
service_url = 's3.amazonaws.com' | ||
cache_file = 'dummy_file' | ||
|
||
s3_creds = s3_pillar.S3Credentials(key, keyid, bucket, service_url) | ||
|
||
mock_return_first = [{'Name': 'pillar-bucket'}, | ||
{'Prefix': 'test'}, | ||
{'KeyCount': '10'}, | ||
{'MaxKeys': '10'}, | ||
{'NextContinuationToken': 'XXXXX'}, | ||
{'IsTruncated': 'true'}] | ||
|
||
mock_return_second = [{'Name': 'pillar-bucket'}, | ||
{'Prefix': 'test'}, | ||
{'KeyCount': '10'}, | ||
{'MaxKeys': '10'}, | ||
{'IsTruncated': 'true'}] | ||
|
||
first_range_end = 999 | ||
second_range_end = 1200 | ||
for i in range(0, first_range_end): | ||
key_name = '{0}/init.sls'.format(i) | ||
tmp = {'Key': key_name, | ||
'LastModified': '2019-12-18T15:54:39.000Z', | ||
'ETag': '"fba0a053704e8b357c94be90b44bb640"', | ||
'Size': '5 ', | ||
'StorageClass': 'STANDARD'} | ||
mock_return_first.append(tmp) | ||
|
||
for i in range(first_range_end, second_range_end): | ||
key_name = '{0}/init.sls'.format(i) | ||
tmp = {'Key': key_name, | ||
'LastModified': '2019-12-18T15:54:39.000Z', | ||
'ETag': '"fba0a053704e8b357c94be90b44bb640"', | ||
'Size': '5 ', | ||
'StorageClass': 'STANDARD'} | ||
mock_return_second.append(tmp) | ||
|
||
_expected = {'base': {'dummy_bucket': []}} | ||
for i in range(0, second_range_end): | ||
key_name = '{0}/init.sls'.format(i) | ||
tmp = {'Key': key_name, | ||
'LastModified': '2019-12-18T15:54:39.000Z', | ||
'ETag': '"fba0a053704e8b357c94be90b44bb640"', | ||
'Size': '5 ', | ||
'StorageClass': 'STANDARD'} | ||
_expected['base']['dummy_bucket'].append(tmp) | ||
|
||
mock_s3_query = MagicMock(side_effect=[mock_return_first, mock_return_second]) | ||
with patch.dict(s3_pillar.__utils__, {'s3.query': mock_s3_query}): | ||
with patch('salt.utils.files.fopen', mock_open(read_data=b'')): | ||
ret = s3_pillar._refresh_buckets_cache_file(s3_creds, | ||
cache_file, | ||
False, | ||
'base', | ||
'') | ||
self.assertEqual(ret, _expected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be rewritten as an iterator?
I think the function would just be:
Or something to that effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if that approach will work. There is only ever one
NextContinuationToken
in s3_meta, but it could be different when s3_meta is updated after subsequent calls to__get_s3_meta
. Once it's not longer in s3_meta then it should exist the loop since there are no more results to pull down.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooooh. I see!
What about something like this?
Then it could simply be
Would that work?