Skip to content
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

git_pillar: Fix all_saltenvs on base env #51661

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion salt/utils/gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,7 @@ def checkout(self):
if repo.branch == '__env__' and hasattr(repo, 'all_saltenvs'):
env = self.opts.get('pillarenv') \
or self.opts.get('saltenv') \
or self.opts.get('git_pillar_base')
or 'base'
elif repo.env:
env = repo.env
else:
Expand Down
181 changes: 181 additions & 0 deletions tests/integration/pillar/test_git_pillar.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,33 @@ def test_all_saltenvs(self):
'nested_dict': {'dev': True}}}
)

def test_all_saltenvs_base(self):
'''
Test all_saltenvs parameter with base pillarenv.
'''
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: gitpython
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- __env__ {url}:
- mountpoint: nowhere
''')
self.assertEqual(
ret,
{'branch': 'master',
'motd': 'The force will be with you. Always.',
'mylist': ['master'],
'mydict': {'master': True,
'nested_list': ['master'],
'nested_dict': {'master': True}}}
)


@destructiveTest
@skipIf(NO_MOCK, NO_MOCK_REASON)
Expand Down Expand Up @@ -1742,6 +1769,103 @@ def test_all_saltenvs(self, grains):
''')
self.assertEqual(ret, expected)

@requires_system_grains
def test_all_saltenvs_base(self, grains):
'''
Test all_saltenvs parameter.
'''
expected = {'branch': 'master',
'motd': 'The force will be with you. Always.',
'mylist': ['master'],
'mydict': {'master': True,
'nested_list': ['master'],
'nested_dict': {'master': True}
}
}

# Test with passphraseless key and global credential options
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
git_pillar_pubkey: {pubkey_nopass}
git_pillar_privkey: {privkey_nopass}
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- __env__ {url}:
- mountpoint: nowhere
''')
self.assertEqual(ret, expected)

# Test with passphraseless key and per-repo credential options
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- pubkey: {pubkey_nopass}
- privkey: {privkey_nopass}
- __env__ {url}:
- mountpoint: nowhere
- pubkey: {pubkey_nopass}
- privkey: {privkey_nopass}
''')
self.assertEqual(ret, expected)

if grains['os_family'] == 'Debian':
# passphrase-protected currently does not work here
return

# Test with passphrase-protected key and global credential options
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
git_pillar_pubkey: {pubkey_withpass}
git_pillar_privkey: {privkey_withpass}
git_pillar_passphrase: {passphrase}
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- __env__ {url}:
- mountpoint: nowhere
''')
self.assertEqual(ret, expected)

# Test with passphrase-protected key and per-repo credential options
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- pubkey: {pubkey_nopass}
- privkey: {privkey_nopass}
- passphrase: {passphrase}
- __env__ {url}:
- mountpoint: nowhere
- pubkey: {pubkey_nopass}
- privkey: {privkey_nopass}
- passphrase: {passphrase}
''')
self.assertEqual(ret, expected)


@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(_windows_or_mac(), 'minion is windows or mac')
Expand Down Expand Up @@ -2119,6 +2243,33 @@ def test_all_saltenvs(self):
'nested_dict': {'dev': True}}}
)

def test_all_saltenvs_base(self):
'''
Test all_saltenvs parameter with base pillarenv.
'''
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- __env__ {url}:
- mountpoint: nowhere
''')
self.assertEqual(
ret,
{'branch': 'master',
'motd': 'The force will be with you. Always.',
'mylist': ['master'],
'mydict': {'master': True,
'nested_list': ['master'],
'nested_dict': {'master': True}}}
)


@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(_windows_or_mac(), 'minion is windows or mac')
Expand Down Expand Up @@ -2719,3 +2870,33 @@ def test_all_saltenvs(self):
'nested_list': ['dev'],
'nested_dict': {'dev': True}}}
)

def test_all_saltenvs_base(self):
'''
Test all_saltenvs parameter with base pillarenv.
'''
ret = self.get_pillar('''\
file_ignore_regex: []
file_ignore_glob: []
git_pillar_provider: pygit2
git_pillar_user: {user}
git_pillar_password: {password}
git_pillar_insecure_auth: True
cachedir: {cachedir}
extension_modules: {extmods}
ext_pillar:
- git:
- __env__ {url_extra_repo}:
- all_saltenvs: master
- __env__ {url}:
- mountpoint: nowhere
''')
self.assertEqual(
ret,
{'branch': 'master',
'motd': 'The force will be with you. Always.',
'mylist': ['master'],
'mydict': {'master': True,
'nested_list': ['master'],
'nested_dict': {'master': True}}}
)