Merge branch '2018.3' into 50542_mysql_ensure_verify_login_uses_connection_host

This commit is contained in:
Gareth J. Greenaway 2018-11-20 08:44:05 -08:00 committed by GitHub
commit 6d2309da50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 6 deletions

View File

@ -84,12 +84,18 @@ def downloaded(name, artifact, target_dir='/tmp', target_file=None, use_literal_
'changes': {},
'comment': ''}
try:
fetch_result = __fetch_from_artifactory(artifact, target_dir, target_file, use_literal_group_id)
except Exception as exc:
ret['result'] = False
ret['comment'] = six.text_type(exc)
return ret
if 'test' in __opts__ and __opts__['test'] is True:
fetch_result = {}
fetch_result['status'] = True
fetch_result['comment'] = 'Artifact would be downloaded from URL: {0}'.format(artifact['artifactory_url'])
fetch_result['changes'] = {}
else:
try:
fetch_result = __fetch_from_artifactory(artifact, target_dir, target_file, use_literal_group_id)
except Exception as exc:
ret['result'] = False
ret['comment'] = six.text_type(exc)
return ret
log.debug('fetch_result = %s', fetch_result)

View File

@ -55,3 +55,34 @@ class ArtifactoryTestCase(TestCase, LoaderModuleMockMixin):
ret = artifactory.downloaded(name, artifact)
self.assertEqual(ret['result'], False)
self.assertEqual(ret['comment'], 'error')
# 'downloaded test=True' function tests: 1
def test_downloaded_test_true(self):
'''
Test to ensures that the artifact from artifactory exists at
given location.
'''
name = 'jboss'
arti_url = 'http://artifactory.intranet.example.com/artifactory'
artifact = {'artifactory_url': arti_url, 'artifact_id': 'module',
'repository': 'libs-release-local', 'packaging': 'jar',
'group_id': 'com.company.module', 'classifier': 'sources',
'version': '1.0'}
ret = {'name': name,
'result': True,
'changes': {},
'comment': 'Artifact would be downloaded from URL: http://artifactory.intranet.example.com/artifactory'}
mck = MagicMock(return_value={'status': False, 'changes': {},
'comment': ''})
with patch.dict(artifactory.__salt__, {'artifactory.get_release': mck}):
with patch.dict(artifactory.__opts__, {'test': True}):
self.assertDictEqual(artifactory.downloaded(name, artifact), ret)
with patch.object(artifactory, '__fetch_from_artifactory',
MagicMock(side_effect=Exception('error'))):
ret = artifactory.downloaded(name, artifact)
self.assertEqual(ret['result'], False)
self.assertEqual(ret['comment'], 'error')