desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test to returns successful.'
| def test_succeed_without_changes(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
with patch.dict(test.__opts__, {'test': False}):
ret.update({'comment': 'Success!'})
self.assertDictEqual(test.succeed_without_changes('salt'), ret)
|
'Test to returns failure.'
| def test_fail_without_changes(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
with patch.dict(test.__opts__, {'test': False}):
ret.update({'comment': 'Failure!'})
self.assertDictEqual(test.fail_without_changes('salt'), ret)
|
'Test to returns successful and changes is not empty'
| def test_succeed_with_changes(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
with patch.dict(test.__opts__, {'test': False}):
ret.update({'changes': {'testing': {'new': 'Something pretended to change', 'old': 'Unchanged'}}, 'comment': 'Success!', 'result': True})
self.assertDictEqual(test.succeed_with_changes('salt'), ret)
|
'Test to returns failure and changes is not empty.'
| def test_fail_with_changes(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
with patch.dict(test.__opts__, {'test': False}):
ret.update({'changes': {'testing': {'new': 'Something pretended to change', 'old': 'Unchanged'}}, 'comment': 'Success!', 'result': True})
self.assertDictEqual(test.succeed_with_changes('salt'), ret)
|
'Test test.configurable_test_state with and without comment'
| def test_configurable_test_state(self):
| mock_name = 'cheese_shop'
mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
mock_changes = {'testing': {'old': 'Unchanged', 'new': 'Something pretended to change'}}
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': True, 'comment': ''}
ret = test.configurable_test_state(mock_name)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': True, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
|
'Test test.configurable_test_state with permutations of changes and with
comment'
| def test_configurable_test_state_changes(self):
| mock_name = 'cheese_shop'
mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
mock_changes = {'testing': {'old': 'Unchanged', 'new': 'Something pretended to change'}}
with patch.dict(test.__opts__, {'test': False}):
ret = test.configurable_test_state(mock_name, changes='Random', comment=mock_comment)
self.assertEqual(ret['name'], mock_name)
self.assertIn(ret['changes'], [mock_changes, {}])
self.assertEqual(ret['result'], True)
self.assertEqual(ret['comment'], mock_comment)
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': True, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, changes=True, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': {}, 'result': True, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, changes=False, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': False}):
self.assertRaises(SaltInvocationError, test.configurable_test_state, mock_name, changes='Cheese')
|
'Test test.configurable_test_state with permutations of result and with
comment'
| def test_configurable_test_state_result(self):
| mock_name = 'cheese_shop'
mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
mock_changes = {'testing': {'old': 'Unchanged', 'new': 'Something pretended to change'}}
with patch.dict(test.__opts__, {'test': False}):
ret = test.configurable_test_state(mock_name, result='Random', comment=mock_comment)
self.assertEqual(ret['name'], mock_name)
self.assertEqual(ret['changes'], mock_changes)
self.assertIn(ret['result'], [True, False])
self.assertEqual(ret['comment'], mock_comment)
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': True, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, result=True, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': False}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': False, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, result=False, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': False}):
self.assertRaises(SaltInvocationError, test.configurable_test_state, mock_name, result='Cheese')
|
'Test test.configurable_test_state with test=True with and without
comment'
| def test_configurable_test_state_test(self):
| mock_name = 'cheese_shop'
mock_comment = "I'm afraid we're fresh out of Red Leicester sir."
mock_changes = {'testing': {'old': 'Unchanged', 'new': 'Something pretended to change'}}
with patch.dict(test.__opts__, {'test': True}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': None, 'comment': 'This is a test'}
ret = test.configurable_test_state(mock_name)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': True}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': None, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': True}):
mock_ret = {'name': mock_name, 'changes': mock_changes, 'result': None, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, changes=True, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
with patch.dict(test.__opts__, {'test': True}):
mock_ret = {'name': mock_name, 'changes': {}, 'result': True, 'comment': mock_comment}
ret = test.configurable_test_state(mock_name, changes=False, comment=mock_comment)
self.assertDictEqual(ret, mock_ret)
|
'Test to call this function via a watch statement'
| def test_mod_watch(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
ret.update({'changes': {'Requisites with changes': []}, 'comment': 'Watch statement fired.'})
self.assertDictEqual(test.mod_watch('salt'), ret)
|
'Test to ensure the check_pillar function
works properly with the \'present\' keyword in
the absence of a \'type\' keyword.'
| def test_check_pillar_present(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
pillar_return = 'I am a pillar.'
pillar_mock = MagicMock(return_value=pillar_return)
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
self.assertEqual(test.check_pillar('salt', present='my_pillar'), ret)
|
'Test to ensure the check_pillar function
works properly with the \'key_type\' checks,
using the dictionary key_type.'
| def test_check_pillar_dictionary(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
pillar_return = {'this': 'dictionary'}
pillar_mock = MagicMock(return_value=pillar_return)
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
|
'Test to ensure that the user is present with the specified properties.'
| def test_present(self):
| name = 'myapp'
passwd = 'password-of-myapp'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Port ({}) is not an integer.'
ret.update({'comment': comt})
self.assertDictEqual(mongodb_user.present(name, passwd, port={}), ret)
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=[])
with patch.dict(mongodb_user.__salt__, {'mongodb.user_create': mock_t, 'mongodb.user_find': mock_f}):
comt = 'User {0} is not present and needs to be created'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(mongodb_user.present(name, passwd), ret)
with patch.dict(mongodb_user.__opts__, {'test': True}):
comt = 'User {0} is not present and needs to be created'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(mongodb_user.present(name, passwd), ret)
with patch.dict(mongodb_user.__opts__, {'test': False}):
comt = 'User {0} has been created'.format(name)
ret.update({'comment': comt, 'result': True, 'changes': {name: 'Present'}})
self.assertDictEqual(mongodb_user.present(name, passwd), ret)
|
'Test to ensure that the named user is absent.'
| def test_absent(self):
| name = 'myapp'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock = MagicMock(side_effect=[True, True, False])
mock_t = MagicMock(return_value=True)
with patch.dict(mongodb_user.__salt__, {'mongodb.user_exists': mock, 'mongodb.user_remove': mock_t}):
with patch.dict(mongodb_user.__opts__, {'test': True}):
comt = 'User {0} is present and needs to be removed'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(mongodb_user.absent(name), ret)
with patch.dict(mongodb_user.__opts__, {'test': False}):
comt = 'User {0} has been removed'.format(name)
ret.update({'comment': comt, 'result': True, 'changes': {name: 'Absent'}})
self.assertDictEqual(mongodb_user.absent(name), ret)
comt = 'User {0} is not present, so it cannot be removed'.format(name)
ret.update({'comment': comt, 'result': True, 'changes': {}})
self.assertDictEqual(mongodb_user.absent(name), ret)
|
'Test to manage a elasticsearch index.'
| def test_index_absent(self):
| name = 'foo'
ret = {'name': name, 'result': True, 'comment': 'Index foo is already absent', 'changes': {}}
mock_get = MagicMock(side_effect=[None, {name: {'test': 'key'}}, {name: {}}, {name: {'test': 'key'}}, CommandExecutionError, {name: {'test': 'key'}}])
mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.index_get': mock_get, 'elasticsearch.index_delete': mock_delete}):
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': 'Successfully removed index foo', 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': 'Failed to remove index foo for unknown reasons', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Index foo will be removed', 'result': None, 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
|
'Test to manage a elasticsearch index.'
| def test_index_present(self):
| name = 'foo'
ret = {'name': name, 'result': True, 'comment': 'Index foo is already present', 'changes': {}}
mock_exists = MagicMock(side_effect=[True, False, False, False, CommandExecutionError, False, False])
mock_get = MagicMock(side_effect=[{name: {'test': 'key'}}, CommandExecutionError])
mock_create = MagicMock(side_effect=[True, False, CommandExecutionError, True])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.index_get': mock_get, 'elasticsearch.index_exists': mock_exists, 'elasticsearch.index_create': mock_create}):
self.assertDictEqual(elasticsearch.index_present(name), ret)
ret.update({'comment': 'Successfully created index foo', 'changes': {'new': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_present(name), ret)
ret.update({'comment': 'Cannot create index foo, False', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_present(name), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Index foo does not exist and will be created', 'result': None, 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.index_present(name, {'test2': 'key'}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_absent(name), ret)
|
'Test to manage a elasticsearch alias.'
| def test_alias_absent(self):
| name = 'foo'
index = 'bar'
alias = {index: {'aliases': {name: {'test': 'key'}}}}
ret = {'name': name, 'result': True, 'comment': 'Alias foo for index bar is already absent', 'changes': {}}
mock_get = MagicMock(side_effect=[None, {'foo2': {}}, alias, alias, alias, CommandExecutionError, alias])
mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.alias_get': mock_get, 'elasticsearch.alias_delete': mock_delete}):
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
ret.update({'comment': 'Successfully removed alias foo for index bar', 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
ret.update({'comment': 'Failed to remove alias foo for index bar for unknown reasons', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Alias foo for index bar will be removed', 'result': None, 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.alias_absent(name, index), ret)
|
'Test to manage a elasticsearch alias.'
| def test_alias_present(self):
| name = 'foo'
index = 'bar'
alias = {index: {'aliases': {name: {'test': 'key'}}}}
ret = {'name': name, 'result': True, 'comment': 'Alias foo for index bar is already present', 'changes': {}}
mock_get = MagicMock(side_effect=[alias, alias, None, None, None, alias, CommandExecutionError, None])
mock_create = MagicMock(side_effect=[True, True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.alias_get': mock_get, 'elasticsearch.alias_create': mock_create}):
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test': 'key'}), ret)
ret.update({'comment': 'Successfully replaced alias foo for index bar', 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test2': 'key'}), ret)
ret.update({'comment': 'Successfully created alias foo for index bar', 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test2': 'key'}), ret)
ret.update({'comment': 'Cannot create alias foo for index bar, False', 'result': False})
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test2': 'key'}), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Alias foo for index bar does not exist and will be created', 'result': None, 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test2': 'key'}), ret)
ret.update({'comment': 'Alias foo for index bar exists with wrong configuration and will be overriden', 'result': None, 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.alias_present(name, index, {'test2': 'key'}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.alias_present(name, index), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.alias_present(name, index), ret)
|
'Test to manage a elasticsearch index template.'
| def test_index_template_absent(self):
| name = 'foo'
index_template = {name: {'test': 'key'}}
ret = {'name': name, 'result': True, 'comment': 'Index template foo is already absent', 'changes': {}}
mock_get = MagicMock(side_effect=[None, {'bar': {}}, index_template, index_template, index_template, CommandExecutionError, index_template])
mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.index_template_get': mock_get, 'elasticsearch.index_template_delete': mock_delete}):
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
ret.update({'comment': 'Successfully removed index template foo', 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
ret.update({'comment': 'Failed to remove index template foo for unknown reasons', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Index template foo will be removed', 'result': None, 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_absent(name), ret)
|
'Test to manage a elasticsearch index template.'
| def test_index_template_present(self):
| name = 'foo'
index_template = {name: {'test': 'key'}}
ret = {'name': name, 'result': True, 'comment': 'Index template foo is already present', 'changes': {}}
mock_exists = MagicMock(side_effect=[True, False, False, False, CommandExecutionError, False, False])
mock_create = MagicMock(side_effect=[True, False, CommandExecutionError, True])
mock_get = MagicMock(side_effect=[index_template, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.index_template_get': mock_get, 'elasticsearch.index_template_create': mock_create, 'elasticsearch.index_template_exists': mock_exists}):
self.assertDictEqual(elasticsearch.index_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Successfully created index template foo', 'changes': {'new': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.index_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Cannot create index template foo, False', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_present(name, {'test2': 'key'}), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Index template foo does not exist and will be created', 'result': None, 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.index_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_present(name, {}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_present(name, {}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.index_template_present(name, {}), ret)
|
'Test to manage a elasticsearch pipeline.'
| def test_pipeline_absent(self):
| name = 'foo'
pipeline = {name: {'test': 'key'}}
ret = {'name': name, 'result': True, 'comment': 'Pipeline foo is already absent', 'changes': {}}
mock_get = MagicMock(side_effect=[None, {'foo2': {}}, pipeline, pipeline, pipeline, CommandExecutionError, pipeline])
mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.pipeline_get': mock_get, 'elasticsearch.pipeline_delete': mock_delete}):
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
ret.update({'comment': 'Successfully removed pipeline foo', 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
ret.update({'comment': 'Failed to remove pipeline foo for unknown reasons', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Pipeline foo will be removed', 'result': None, 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.pipeline_absent(name), ret)
|
'Test to manage a elasticsearch pipeline.'
| def test_pipeline_present(self):
| name = 'foo'
pipeline = {name: {'test': 'key'}}
ret = {'name': name, 'result': True, 'comment': 'Pipeline foo is already present', 'changes': {}}
mock_get = MagicMock(side_effect=[pipeline, pipeline, None, None, None, pipeline, CommandExecutionError, None])
mock_create = MagicMock(side_effect=[True, True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.pipeline_get': mock_get, 'elasticsearch.pipeline_create': mock_create}):
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test': 'key'}), ret)
ret.update({'comment': 'Successfully replaced pipeline foo', 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Successfully created pipeline foo', 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Cannot create pipeline foo, False', 'result': False})
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test2': 'key'}), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Pipeline foo does not exist and will be created', 'result': None, 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Pipeline foo exists with wrong configuration and will be overriden', 'result': None, 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {'test2': 'key'}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.pipeline_present(name, {}), ret)
|
'Test to manage a elasticsearch search template.'
| def test_search_template_absent(self):
| name = 'foo'
template = {'template': '{"test": "key"}'}
ret = {'name': name, 'result': True, 'comment': 'Search template foo is already absent', 'changes': {}}
mock_get = MagicMock(side_effect=[None, template, template, template, CommandExecutionError, template])
mock_delete = MagicMock(side_effect=[True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.search_template_get': mock_get, 'elasticsearch.search_template_delete': mock_delete}):
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
ret.update({'comment': 'Successfully removed search template foo', 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
ret.update({'comment': 'Failed to remove search template foo for unknown reasons', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Search template foo will be removed', 'result': None, 'changes': {'old': {'test': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.search_template_absent(name), ret)
|
'Test to manage a elasticsearch search template.'
| def test_search_template_present(self):
| name = 'foo'
template = {'template': '{"test": "key"}'}
ret = {'name': name, 'result': True, 'comment': 'Search template foo is already present', 'changes': {}}
mock_get = MagicMock(side_effect=[template, template, None, None, None, template, CommandExecutionError, None])
mock_create = MagicMock(side_effect=[True, True, False, CommandExecutionError])
with patch.dict(elasticsearch.__salt__, {'elasticsearch.search_template_get': mock_get, 'elasticsearch.search_template_create': mock_create}):
self.assertDictEqual(elasticsearch.search_template_present(name, {'test': 'key'}), ret)
ret.update({'comment': 'Successfully replaced search template foo', 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Successfully created search template foo', 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Cannot create search template foo, False', 'result': False})
self.assertDictEqual(elasticsearch.search_template_present(name, {'test2': 'key'}), ret)
with patch.dict(elasticsearch.__opts__, {'test': True}):
ret.update({'comment': 'Search template foo does not exist and will be created', 'result': None, 'changes': {'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': 'Search template foo exists with wrong configuration and will be overriden', 'result': None, 'changes': {'old': {'test': 'key'}, 'new': {'test2': 'key'}}})
self.assertDictEqual(elasticsearch.search_template_present(name, {'test2': 'key'}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.search_template_present(name, {}), ret)
ret.update({'comment': '', 'result': False, 'changes': {}})
self.assertDictEqual(elasticsearch.search_template_present(name, {}), ret)
|
'Test docker_network.present'
| def test_present(self):
| docker_create_network = Mock(return_value='created')
docker_connect_container_to_network = Mock(return_value='connected')
docker_inspect_container = Mock(return_value={'Id': 'abcd'})
docker_networks = Mock(return_value=[{'Name': 'network_foobar', 'Containers': {'container': {}}}])
__salt__ = {'docker.create_network': docker_create_network, 'docker.inspect_container': docker_inspect_container, 'docker.connect_container_to_network': docker_connect_container_to_network, 'docker.networks': docker_networks}
with patch.dict(docker_state.__dict__, {'__salt__': __salt__}):
ret = docker_state.present('network_foo', containers=['container'])
docker_create_network.assert_called_with('network_foo', driver=None, driver_opts=None, check_duplicate=True)
docker_connect_container_to_network.assert_called_with('abcd', 'network_foo')
self.assertEqual(ret, {'name': 'network_foo', 'comment': '', 'changes': {'connected': 'connected', 'created': 'created'}, 'result': True})
|
'Test docker_network.absent'
| def test_absent(self):
| docker_remove_network = Mock(return_value='removed')
docker_disconnect_container_from_network = Mock(return_value='disconnected')
docker_networks = Mock(return_value=[{'Name': 'network_foo', 'Containers': {'container': {}}}])
__salt__ = {'docker.remove_network': docker_remove_network, 'docker.disconnect_container_from_network': docker_disconnect_container_from_network, 'docker.networks': docker_networks}
with patch.dict(docker_state.__dict__, {'__salt__': __salt__}):
ret = docker_state.absent('network_foo')
docker_disconnect_container_from_network.assert_called_with('container', 'network_foo')
docker_remove_network.assert_called_with('network_foo')
self.assertEqual(ret, {'name': 'network_foo', 'comment': '', 'changes': {'disconnected': 'disconnected', 'removed': 'removed'}, 'result': True})
|
'Test docker_network.absent when the specified network does not exist,
but another network with a name which is a superset of the specified
name does exist. In this case we expect there to be no attempt to remove
any network.
Regression test for #41982.'
| def test_absent_with_matching_network(self):
| docker_remove_network = Mock(return_value='removed')
docker_disconnect_container_from_network = Mock(return_value='disconnected')
docker_networks = Mock(return_value=[{'Name': 'network_foobar', 'Containers': {'container': {}}}])
__salt__ = {'docker.remove_network': docker_remove_network, 'docker.disconnect_container_from_network': docker_disconnect_container_from_network, 'docker.networks': docker_networks}
with patch.dict(docker_state.__dict__, {'__salt__': __salt__}):
ret = docker_state.absent('network_foo')
docker_disconnect_container_from_network.assert_not_called()
docker_remove_network.assert_not_called()
self.assertEqual(ret, {'name': 'network_foo', 'comment': "Network 'network_foo' already absent", 'changes': {}, 'result': True})
|
'Test to Make sure the repository is cloned to
the given directory and is up to date'
| def test_latest(self):
| ret = {'changes': {}, 'comment': '', 'name': 'salt', 'result': True}
mock = MagicMock(return_value=True)
with patch.object(hg, '_fail', mock):
self.assertTrue(hg.latest('salt'))
mock = MagicMock(side_effect=[False, True, False, False, False, False])
with patch.object(os.path, 'isdir', mock):
mock = MagicMock(return_value=True)
with patch.object(hg, '_handle_existing', mock):
self.assertTrue(hg.latest('salt', target='c:\\salt'))
with patch.dict(hg.__opts__, {'test': True}):
mock = MagicMock(return_value=True)
with patch.object(hg, '_neutral_test', mock):
self.assertTrue(hg.latest('salt', target='c:\\salt'))
with patch.dict(hg.__opts__, {'test': False}):
mock = MagicMock(return_value=True)
with patch.object(hg, '_clone_repo', mock):
self.assertDictEqual(hg.latest('salt', target='c:\\salt'), ret)
|
'Test to make sure we don\'t update even if we have changes'
| def test_latest_update_changes(self):
| ret = {'changes': {}, 'comment': '', 'name': 'salt', 'result': True}
revision_mock = MagicMock(return_value='abcdef')
pull_mock = MagicMock(return_value='Blah.')
update_mock = MagicMock()
with patch.dict(hg.__salt__, {'hg.revision': revision_mock, 'hg.pull': pull_mock, 'hg.update': update_mock}):
mock = MagicMock(side_effect=[True, True])
with patch.object(os.path, 'isdir', mock):
mock = MagicMock(return_value=True)
with patch.dict(hg.__opts__, {'test': False}):
with patch.object(hg, '_clone_repo', mock):
self.assertDictEqual(hg.latest('salt', target='c:\\salt', update_head=True), ret)
assert update_mock.called
|
'Test to make sure we don\'t update even if we have changes'
| def test_latest_no_update_changes(self):
| ret = {'changes': {}, 'comment': 'Update is probably required but update_head=False so we will skip updating.', 'name': 'salt', 'result': True}
revision_mock = MagicMock(return_value='abcdef')
pull_mock = MagicMock(return_value='Blah.')
update_mock = MagicMock()
with patch.dict(hg.__salt__, {'hg.revision': revision_mock, 'hg.pull': pull_mock, 'hg.update': update_mock}):
mock = MagicMock(side_effect=[True, True])
with patch.object(os.path, 'isdir', mock):
mock = MagicMock(return_value=True)
with patch.dict(hg.__opts__, {'test': False}):
with patch.object(hg, '_clone_repo', mock):
self.assertDictEqual(hg.latest('salt', target='c:\\salt', update_head=False), ret)
assert (not update_mock.called)
|
'Test to Make sure the repository is cloned to
the given directory and is up to date'
| def test_latest_no_update_no_changes(self):
| ret = {'changes': {}, 'comment': 'No changes found and update_head=False so will skip updating.', 'name': 'salt', 'result': True}
revision_mock = MagicMock(return_value='abcdef')
pull_mock = MagicMock(return_value='Blah no changes found.')
update_mock = MagicMock()
with patch.dict(hg.__salt__, {'hg.revision': revision_mock, 'hg.pull': pull_mock, 'hg.update': update_mock}):
mock = MagicMock(side_effect=[True, True])
with patch.object(os.path, 'isdir', mock):
mock = MagicMock(return_value=True)
with patch.dict(hg.__opts__, {'test': False}):
with patch.object(hg, '_clone_repo', mock):
self.assertDictEqual(hg.latest('salt', target='c:\\salt', update_head=False), ret)
assert (not update_mock.called)
|
'Test to set a physical device to be used as an LVM physical volume'
| def test_pv_present(self):
| name = '/dev/sda5'
comt = 'Physical Volume {0} already present'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[True, False])
with patch.dict(lvm.__salt__, {'lvm.pvdisplay': mock}):
self.assertDictEqual(lvm.pv_present(name), ret)
comt = 'Physical Volume {0} is set to be created'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.pv_present(name), ret)
|
'Test to ensure that a Physical Device is not being used by lvm'
| def test_pv_absent(self):
| name = '/dev/sda5'
comt = 'Physical Volume {0} does not exist'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[False, True])
with patch.dict(lvm.__salt__, {'lvm.pvdisplay': mock}):
self.assertDictEqual(lvm.pv_absent(name), ret)
comt = 'Physical Volume {0} is set to be removed'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.pv_absent(name), ret)
|
'Test to create an LVM volume group'
| def test_vg_present(self):
| name = '/dev/sda5'
comt = 'Failed to create Volume Group {0}'.format(name)
ret = {'name': name, 'changes': {}, 'result': False, 'comment': comt}
mock = MagicMock(return_value=False)
with patch.dict(lvm.__salt__, {'lvm.vgdisplay': mock, 'lvm.vgcreate': mock}):
with patch.dict(lvm.__opts__, {'test': False}):
self.assertDictEqual(lvm.vg_present(name), ret)
comt = 'Volume Group {0} is set to be created'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.vg_present(name), ret)
|
'Test to remove an LVM volume group'
| def test_vg_absent(self):
| name = '/dev/sda5'
comt = 'Volume Group {0} already absent'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[False, True])
with patch.dict(lvm.__salt__, {'lvm.vgdisplay': mock}):
self.assertDictEqual(lvm.vg_absent(name), ret)
comt = 'Volume Group {0} is set to be removed'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.vg_absent(name), ret)
|
'Test to create a new logical volume'
| def test_lv_present(self):
| name = '/dev/sda5'
comt = 'Logical Volume {0} already present'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[True, False])
with patch.dict(lvm.__salt__, {'lvm.lvdisplay': mock}):
self.assertDictEqual(lvm.lv_present(name), ret)
comt = 'Logical Volume {0} is set to be created'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.lv_present(name), ret)
|
'Test to create a new logical volume with force=True'
| def test_lv_present_with_force(self):
| name = '/dev/sda5'
comt = 'Logical Volume {0} already present'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[True, False])
with patch.dict(lvm.__salt__, {'lvm.lvdisplay': mock}):
self.assertDictEqual(lvm.lv_present(name, force=True), ret)
comt = 'Logical Volume {0} is set to be created'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.lv_present(name, force=True), ret)
|
'Test to remove a given existing logical volume
from a named existing volume group'
| def test_lv_absent(self):
| name = '/dev/sda5'
comt = 'Logical Volume {0} already absent'.format(name)
ret = {'name': name, 'changes': {}, 'result': True, 'comment': comt}
mock = MagicMock(side_effect=[False, True])
with patch.dict(lvm.__salt__, {'lvm.lvdisplay': mock}):
self.assertDictEqual(lvm.lv_absent(name), ret)
comt = 'Logical Volume {0} is set to be removed'.format(name)
ret.update({'comment': comt, 'result': None})
with patch.dict(lvm.__opts__, {'test': True}):
self.assertDictEqual(lvm.lv_absent(name), ret)
|
'Test to invoke a state run on a given target'
| def test_state(self):
| name = 'state'
tgt = 'minion1'
comt = "Passed invalid value for 'allow_fail', must be an int"
ret = {'name': name, 'changes': {}, 'result': False, 'comment': comt}
test_ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'States ran successfully.'}
test_batch_return = {'minion1': {'ret': {'test_|-notify_me_|-this is a name_|-show_notification': {'comment': 'Notify me', 'name': 'this is a name', 'start_time': '10:43:41.487565', 'result': True, 'duration': 0.35, '__run_num__': 0, '__sls__': 'demo', 'changes': {}, '__id__': 'notify_me'}, 'retcode': 0}, 'out': 'highstate'}, 'minion2': {'ret': {'test_|-notify_me_|-this is a name_|-show_notification': {'comment': 'Notify me', 'name': 'this is a name', 'start_time': '10:43:41.487565', 'result': True, 'duration': 0.35, '__run_num__': 0, '__sls__': 'demo', 'changes': {}, '__id__': 'notify_me'}, 'retcode': 0}, 'out': 'highstate'}, 'minion3': {'ret': {'test_|-notify_me_|-this is a name_|-show_notification': {'comment': 'Notify me', 'name': 'this is a name', 'start_time': '10:43:41.487565', 'result': True, 'duration': 0.35, '__run_num__': 0, '__sls__': 'demo', 'changes': {}, '__id__': 'notify_me'}, 'retcode': 0}, 'out': 'highstate'}}
self.assertDictEqual(saltmod.state(name, tgt, allow_fail='a'), ret)
comt = 'No highstate or sls specified, no execution made'
ret.update({'comment': comt})
self.assertDictEqual(saltmod.state(name, tgt), ret)
comt = "Must pass in boolean for value of 'concurrent'"
ret.update({'comment': comt})
self.assertDictEqual(saltmod.state(name, tgt, highstate=True, concurrent='a'), ret)
ret.update({'comment': comt, 'result': None})
with patch.dict(saltmod.__opts__, {'test': True}):
self.assertDictEqual(saltmod.state(name, tgt, highstate=True), test_ret)
ret.update({'comment': 'States ran successfully. No changes made to silver.', 'result': True, '__jid__': '20170406104341210934'})
with patch.dict(saltmod.__opts__, {'test': False}):
mock = MagicMock(return_value={'silver': {'jid': '20170406104341210934', 'retcode': 0, 'ret': {'test_|-notify_me_|-this is a name_|-show_notification': {'comment': 'Notify me', 'name': 'this is a name', 'start_time': '10:43:41.487565', 'result': True, 'duration': 0.35, '__run_num__': 0, '__sls__': 'demo', 'changes': {}, '__id__': 'notify_me'}}, 'out': 'highstate'}})
with patch.dict(saltmod.__salt__, {'saltutil.cmd': mock}):
self.assertDictEqual(saltmod.state(name, tgt, highstate=True), ret)
ret.update({'comment': 'States ran successfully. No changes made to minion1, minion3, minion2.'})
del ret['__jid__']
with patch.dict(saltmod.__opts__, {'test': False}):
with patch.dict(saltmod.__salt__, {'saltutil.cmd': MagicMock(return_value=test_batch_return)}):
state_run = saltmod.state(name, tgt, highstate=True)
comment = state_run.pop('comment')
ret.pop('comment')
self.assertDictEqual(state_run, ret)
self.assertIn('States ran successfully. No changes made to', comment)
for minion in ['minion1', 'minion2', 'minion3']:
self.assertIn(minion, comment)
|
'Test to execute a single module function on a remote
minion via salt or salt-ssh'
| def test_function(self):
| name = 'state'
tgt = 'larry'
comt = 'Function state will be executed on target {0} as test=False'.format(tgt)
ret = {'name': name, 'changes': {}, 'result': None, 'comment': comt}
with patch.dict(saltmod.__opts__, {'test': True}):
self.assertDictEqual(saltmod.function(name, tgt), ret)
ret.update({'result': True, 'changes': {'out': 'highstate', 'ret': {tgt: ''}}, 'comment': 'Function ran successfully. Function state ran on {0}.'.format(tgt)})
with patch.dict(saltmod.__opts__, {'test': False}):
mock_ret = {'larry': {'ret': '', 'retcode': 0, 'failed': False}}
mock_cmd = MagicMock(return_value=mock_ret)
with patch.dict(saltmod.__salt__, {'saltutil.cmd': mock_cmd}):
self.assertDictEqual(saltmod.function(name, tgt), ret)
|
'Test to watch Salt\'s event bus and block until a condition is met'
| def test_wait_for_event(self):
| name = 'state'
tgt = 'minion1'
comt = 'Timeout value reached.'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': comt}
class Mockevent(object, ):
'\n Mock event class\n '
flag = None
def __init__(self):
self.full = None
def get_event(self, full):
'\n Mock get_event method\n '
self.full = full
if self.flag:
return {'tag': name, 'data': {}}
return None
with patch.object(salt.utils.event, 'get_event', MagicMock(return_value=Mockevent())):
with patch.dict(saltmod.__opts__, {'sock_dir': True, 'transport': True}):
with patch.object(time, 'time', MagicMock(return_value=1.0)):
self.assertDictEqual(saltmod.wait_for_event(name, 'salt', timeout=(-1.0)), ret)
Mockevent.flag = True
ret.update({'comment': 'All events seen in 0.0 seconds.', 'result': True})
self.assertDictEqual(saltmod.wait_for_event(name, ''), ret)
ret.update({'comment': 'Timeout value reached.', 'result': False})
self.assertDictEqual(saltmod.wait_for_event(name, tgt, timeout=(-1.0)), ret)
|
'Test to execute a runner module on the master'
| def test_runner(self):
| name = 'state'
ret = {'changes': True, 'name': 'state', 'result': True, 'comment': "Runner function 'state' executed.", '__orchestration__': True}
runner_mock = MagicMock(return_value={'return': True})
with patch.dict(saltmod.__salt__, {'saltutil.runner': runner_mock}):
self.assertDictEqual(saltmod.runner(name), ret)
|
'Test to execute a wheel module on the master'
| def test_wheel(self):
| name = 'state'
ret = {'changes': True, 'name': 'state', 'result': True, 'comment': "Wheel function 'state' executed.", '__orchestration__': True}
wheel_mock = MagicMock(return_value={'return': True})
with patch.dict(saltmod.__salt__, {'saltutil.wheel': wheel_mock}):
self.assertDictEqual(saltmod.wheel(name), ret)
|
'Smoke test for for salt.states.statemod.state(). Ensures that we
don\'t take an exception if optional parameters are not specified in
__opts__ or __env__.'
| def test_statemod_state(self):
| args = ('webserver_setup', 'webserver2')
kwargs = {'tgt_type': 'glob', 'fail_minions': None, 'pillar': None, 'top': None, 'batch': None, 'orchestration_jid': None, 'sls': 'vroom', 'queue': False, 'concurrent': False, 'highstate': None, 'expr_form': None, 'ret': '', 'ssh': False, 'timeout': None, 'test': False, 'allow_fail': 0, 'saltenv': None, 'expect_minions': False}
ret = saltmod.state(*args, **kwargs)
expected = {'comment': 'States ran successfully.', 'changes': {}, 'name': 'webserver_setup', 'result': True}
self.assertEqual(ret, expected)
|
'Test to verify that the raid is present'
| def test_present(self):
| ret = [{'changes': {}, 'comment': 'Raid salt already present', 'name': 'salt', 'result': True}, {'changes': {}, 'comment': "Devices are a mix of RAID constituents (['dev0']) and non-RAID-constituents(['dev1']).", 'name': 'salt', 'result': False}, {'changes': {}, 'comment': 'Raid will be created with: True', 'name': 'salt', 'result': None}, {'changes': {}, 'comment': 'Raid salt failed to be created.', 'name': 'salt', 'result': False}]
mock = MagicMock(side_effect=[{'salt': True}, {'salt': False}, {'salt': False}, {'salt': False}, {'salt': False}])
with patch.dict(mdadm.__salt__, {'raid.list': mock}):
self.assertEqual(mdadm.present('salt', 5, 'dev0'), ret[0])
mock = MagicMock(side_effect=[0, 1])
with patch.dict(mdadm.__salt__, {'cmd.retcode': mock}):
self.assertDictEqual(mdadm.present('salt', 5, ['dev0', 'dev1']), ret[1])
mock = MagicMock(return_value=True)
with patch.dict(mdadm.__salt__, {'cmd.retcode': mock}):
with patch.dict(mdadm.__opts__, {'test': True}):
with patch.dict(mdadm.__salt__, {'raid.create': mock}):
self.assertDictEqual(mdadm.present('salt', 5, 'dev0'), ret[2])
with patch.dict(mdadm.__opts__, {'test': False}):
with patch.dict(mdadm.__salt__, {'raid.create': mock}):
self.assertDictEqual(mdadm.present('salt', 5, 'dev0'), ret[3])
|
'Test to verify that the raid is absent'
| def test_absent(self):
| ret = [{'changes': {}, 'comment': 'Raid salt already absent', 'name': 'salt', 'result': True}, {'changes': {}, 'comment': 'Raid saltstack is set to be destroyed', 'name': 'saltstack', 'result': None}, {'changes': {}, 'comment': 'Raid saltstack has been destroyed', 'name': 'saltstack', 'result': True}]
mock = MagicMock(return_value=['saltstack'])
with patch.dict(mdadm.__salt__, {'raid.list': mock}):
self.assertDictEqual(mdadm.absent('salt'), ret[0])
with patch.dict(mdadm.__opts__, {'test': True}):
self.assertDictEqual(mdadm.absent('saltstack'), ret[1])
with patch.dict(mdadm.__opts__, {'test': False}):
mock = MagicMock(return_value=True)
with patch.dict(mdadm.__salt__, {'raid.destroy': mock}):
self.assertDictEqual(mdadm.absent('saltstack'), ret[2])
|
'Test to set the locale for the system'
| def test_system(self):
| ret = [{'changes': {}, 'comment': 'System locale salt already set', 'name': 'salt', 'result': True}, {'changes': {}, 'comment': 'System locale saltstack needs to be set', 'name': 'saltstack', 'result': None}, {'changes': {'locale': 'saltstack'}, 'comment': 'Set system locale saltstack', 'name': 'saltstack', 'result': True}, {'changes': {}, 'comment': 'Failed to set system locale to saltstack', 'name': 'saltstack', 'result': False}]
mock = MagicMock(return_value='salt')
with patch.dict(locale.__salt__, {'locale.get_locale': mock}):
self.assertDictEqual(locale.system('salt'), ret[0])
with patch.dict(locale.__opts__, {'test': True}):
self.assertDictEqual(locale.system('saltstack'), ret[1])
with patch.dict(locale.__opts__, {'test': False}):
mock = MagicMock(side_effect=[True, False])
with patch.dict(locale.__salt__, {'locale.set_locale': mock}):
self.assertDictEqual(locale.system('saltstack'), ret[2])
self.assertDictEqual(locale.system('saltstack'), ret[3])
|
'Test to generate a locale if it is not present'
| def test_present(self):
| ret = [{'changes': {}, 'comment': 'Locale salt is already present', 'name': 'salt', 'result': True}, {'changes': {}, 'comment': 'Locale salt needs to be generated', 'name': 'salt', 'result': None}, {'changes': {'locale': 'salt'}, 'comment': 'Generated locale salt', 'name': 'salt', 'result': True}, {'changes': {}, 'comment': 'Failed to generate locale salt', 'name': 'salt', 'result': False}]
mock = MagicMock(side_effect=[True, False, False, False])
with patch.dict(locale.__salt__, {'locale.avail': mock}):
self.assertDictEqual(locale.present('salt'), ret[0])
with patch.dict(locale.__opts__, {'test': True}):
self.assertDictEqual(locale.present('salt'), ret[1])
with patch.dict(locale.__opts__, {'test': False}):
mock = MagicMock(side_effect=[True, False])
with patch.dict(locale.__salt__, {'locale.gen_locale': mock}):
self.assertDictEqual(locale.present('salt'), ret[2])
self.assertDictEqual(locale.present('salt'), ret[3])
|
'Test to ensure a job is present in the schedule.'
| def test_present(self):
| name = 'job1'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_dict = MagicMock(side_effect=[ret, []])
mock_mod = MagicMock(return_value=ret)
mock_lst = MagicMock(side_effect=[{name: {}}, {name: {}}, {}, {}])
with patch.dict(schedule.__salt__, {'schedule.list': mock_lst, 'schedule.build_schedule_item': mock_dict, 'schedule.modify': mock_mod, 'schedule.add': mock_mod}):
self.assertDictEqual(schedule.present(name), ret)
with patch.dict(schedule.__opts__, {'test': False}):
self.assertDictEqual(schedule.present(name), ret)
self.assertDictEqual(schedule.present(name), ret)
with patch.dict(schedule.__opts__, {'test': True}):
ret.update({'result': True})
self.assertDictEqual(schedule.present(name), ret)
|
'Test to ensure a job is absent from the schedule.'
| def test_absent(self):
| name = 'job1'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_mod = MagicMock(return_value=ret)
mock_lst = MagicMock(side_effect=[{name: {}}, {}])
with patch.dict(schedule.__salt__, {'schedule.list': mock_lst, 'schedule.delete': mock_mod}):
with patch.dict(schedule.__opts__, {'test': False}):
self.assertDictEqual(schedule.absent(name), ret)
with patch.dict(schedule.__opts__, {'test': True}):
comt = 'Job job1 not present in schedule'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(schedule.absent(name), ret)
|
'Test to ensure that the named interface is configured properly.'
| def test_managed(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
ret.update({'comment': 'dns_proto must be one of the following: static, dhcp. ip_proto must be one of the following: static, dhcp.'})
self.assertDictEqual(win_network.managed('salt'), ret)
mock = MagicMock(return_value=False)
mock1 = MagicMock(side_effect=[False, True, True, True, True, True, True])
mock2 = MagicMock(side_effect=[False, True, True, {'salt': 'True'}, {'salt': 'True'}])
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock, 'ip.is_disabled': mock1, 'ip.enable': mock, 'ip.get_interface': mock2, 'ip.set_dhcp_dns': mock, 'ip.set_dhcp_ip': mock}):
ret.update({'comment': "Interface 'salt' is up to date. (already disabled)", 'result': True})
self.assertDictEqual(win_network.managed('salt', dns_proto='static', ip_proto='static', enabled=False), ret)
with patch.dict(win_network.__opts__, {'test': False}):
ret.update({'comment': "Failed to enable interface 'salt' to make changes", 'result': False})
self.assertDictEqual(win_network.managed('salt', dns_proto='static', ip_proto='static'), ret)
mock = MagicMock(side_effect=['True', False, False, False, False, False])
with patch.object(win_network, '_validate', mock):
ret.update({'comment': 'The following SLS configuration errors were detected: T r u e'})
self.assertDictEqual(win_network.managed('salt', dns_proto='static', ip_proto='static'), ret)
ret.update({'comment': "Unable to get current configuration for interface 'salt'", 'result': False})
self.assertDictEqual(win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'), ret)
mock = MagicMock(side_effect=[False, [''], {'dns_proto': 'dhcp', 'ip_proto': 'dhcp'}, {'dns_proto': 'dhcp', 'ip_proto': 'dhcp'}])
ret.update({'comment': "Interface 'salt' is up to date.", 'result': True})
with patch.object(win_network, '_changes', mock):
self.assertDictEqual(win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'), ret)
ret.update({'comment': "The following changes will be made to interface 'salt': ", 'result': None})
with patch.dict(win_network.__opts__, {'test': True}):
self.assertDictEqual(win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'), ret)
with patch.dict(win_network.__opts__, {'test': False}):
ret.update({'comment': "Failed to set desired configuration settings for interface 'salt'", 'result': False})
self.assertDictEqual(win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'), ret)
|
'Test to ensure the RabbitMQ plugin is enabled.'
| def test_enabled(self):
| name = 'some_plugin'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[True, False])
with patch.dict(rabbitmq_plugin.__salt__, {'rabbitmq.plugin_is_enabled': mock}):
comment = "Plugin 'some_plugin' is already enabled."
ret.update({'comment': comment})
self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
comment = "Plugin 'some_plugin' is set to be enabled."
changes = {'new': 'some_plugin', 'old': ''}
ret.update({'comment': comment, 'result': None, 'changes': changes})
self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
|
'Test to ensure the RabbitMQ plugin is disabled.'
| def test_disabled(self):
| name = 'some_plugin'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[False, True])
with patch.dict(rabbitmq_plugin.__salt__, {'rabbitmq.plugin_is_enabled': mock}):
comment = "Plugin 'some_plugin' is already disabled."
ret.update({'comment': comment})
self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)
with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
comment = "Plugin 'some_plugin' is set to be disabled."
changes = {'new': '', 'old': 'some_plugin'}
ret.update({'comment': comment, 'result': None, 'changes': changes})
self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)
|
'Test to ensure a sysrc variable is set to a specific value.'
| def test_managed(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[{'key1': {'salt': 'stack'}}, None, None])
mock1 = MagicMock(return_value=True)
with patch.dict(sysrc.__salt__, {'sysrc.get': mock, 'sysrc.set': mock1}):
ret.update({'comment': 'salt is already set to the desired value.'})
self.assertDictEqual(sysrc.managed('salt', 'stack'), ret)
with patch.dict(sysrc.__opts__, {'test': True}):
ret.update({'changes': {'new': 'salt = stack will be set.', 'old': None}, 'comment': 'The value of "salt" will be changed!', 'result': None})
self.assertDictEqual(sysrc.managed('salt', 'stack'), ret)
with patch.dict(sysrc.__opts__, {'test': False}):
ret.update({'changes': {'new': True, 'old': None}, 'comment': 'The value of "salt" was changed!', 'result': True})
self.assertDictEqual(sysrc.managed('salt', 'stack'), ret)
|
'Test to ensure a sysrc variable is absent.'
| def test_absent(self):
| ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[None, True, True])
mock1 = MagicMock(return_value=True)
with patch.dict(sysrc.__salt__, {'sysrc.get': mock, 'sysrc.remove': mock1}):
ret.update({'comment': '"salt" is already absent.'})
self.assertDictEqual(sysrc.absent('salt'), ret)
with patch.dict(sysrc.__opts__, {'test': True}):
ret.update({'changes': {'new': '"salt" will be removed.', 'old': True}, 'comment': '"salt" will be removed!', 'result': None})
self.assertDictEqual(sysrc.absent('salt'), ret)
with patch.dict(sysrc.__opts__, {'test': False}):
ret.update({'changes': {'new': True, 'old': True}, 'comment': '"salt" was removed!', 'result': True})
self.assertDictEqual(sysrc.absent('salt'), ret)
|
'Test adding an attribute when it doesn\'t exist'
| def test_exists_not(self):
| with patch('os.path.exists') as exists_mock:
expected = {'changes': {'key': 'value'}, 'comment': '', 'name': '/path/to/file', 'result': True}
exists_mock.return_value = True
list_mock = MagicMock(return_value={'other.id': 'value2'})
write_mock = MagicMock()
with patch.dict(xattr.__salt__, {'xattr.list': list_mock, 'xattr.write': write_mock}):
out = xattr.exists('/path/to/file', ['key=value'])
list_mock.assert_called_once_with('/path/to/file')
write_mock.assert_called_once_with('/path/to/file', 'key', 'value', False)
self.assertEqual(out, expected)
|
'Test changing and attribute value'
| def test_exists_change(self):
| with patch('os.path.exists') as exists_mock:
expected = {'changes': {'key': 'other_value'}, 'comment': '', 'name': '/path/to/file', 'result': True}
exists_mock.return_value = True
list_mock = MagicMock(return_value={'key': 'value'})
write_mock = MagicMock()
with patch.dict(xattr.__salt__, {'xattr.list': list_mock, 'xattr.write': write_mock}):
out = xattr.exists('/path/to/file', ['key=other_value'])
list_mock.assert_called_once_with('/path/to/file')
write_mock.assert_called_once_with('/path/to/file', 'key', 'other_value', False)
self.assertEqual(out, expected)
|
'Test that having the same value does nothing'
| def test_exists_already(self):
| with patch('os.path.exists') as exists_mock:
expected = {'changes': {}, 'comment': 'All values existed correctly.', 'name': '/path/to/file', 'result': True}
exists_mock.return_value = True
list_mock = MagicMock(return_value={'key': 'value'})
write_mock = MagicMock()
with patch.dict(xattr.__salt__, {'xattr.list': list_mock, 'xattr.write': write_mock}):
out = xattr.exists('/path/to/file', ['key=value'])
list_mock.assert_called_once_with('/path/to/file')
assert (not write_mock.called)
self.assertEqual(out, expected)
|
'Test deleting an attribute from a file'
| def test_delete(self):
| with patch('os.path.exists') as exists_mock:
expected = {'changes': {'key': 'delete'}, 'comment': '', 'name': '/path/to/file', 'result': True}
exists_mock.return_value = True
list_mock = MagicMock(return_value={'key': 'value2'})
delete_mock = MagicMock()
with patch.dict(xattr.__salt__, {'xattr.list': list_mock, 'xattr.delete': delete_mock}):
out = xattr.delete('/path/to/file', ['key'])
list_mock.assert_called_once_with('/path/to/file')
delete_mock.assert_called_once_with('/path/to/file', 'key')
self.assertEqual(out, expected)
|
'Test deleting an attribute that doesn\'t exist from a file'
| def test_delete_not(self):
| with patch('os.path.exists') as exists_mock:
expected = {'changes': {}, 'comment': 'All attributes were already deleted.', 'name': '/path/to/file', 'result': True}
exists_mock.return_value = True
list_mock = MagicMock(return_value={'other.key': 'value2'})
delete_mock = MagicMock()
with patch.dict(xattr.__salt__, {'xattr.list': list_mock, 'xattr.delete': delete_mock}):
out = xattr.delete('/path/to/file', ['key'])
list_mock.assert_called_once_with('/path/to/file')
assert (not delete_mock.called)
self.assertEqual(out, expected)
|
'Test to run chef-client'
| def test_client(self):
| name = 'my-chef-run'
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
mock = MagicMock(return_value={'retcode': 1, 'stdout': '', 'stderr': 'error'})
with patch.dict(chef.__salt__, {'chef.client': mock}):
with patch.dict(chef.__opts__, {'test': True}):
comt = '\nerror'
ret.update({'comment': comt})
self.assertDictEqual(chef.client(name), ret)
|
'Test to run chef-solo'
| def test_solo(self):
| name = 'my-chef-run'
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
mock = MagicMock(return_value={'retcode': 1, 'stdout': '', 'stderr': 'error'})
with patch.dict(chef.__salt__, {'chef.solo': mock}):
with patch.dict(chef.__opts__, {'test': True}):
comt = '\nerror'
ret.update({'comment': comt})
self.assertDictEqual(chef.solo(name), ret)
|
'Test to ensure that the named group is present
with the specified privileges.'
| def test_present(self):
| name = 'frank'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_t = MagicMock(return_value=True)
mock = MagicMock(return_value=None)
with patch.dict(postgres_group.__salt__, {'postgres.role_get': mock, 'postgres.group_create': mock_t}):
with patch.dict(postgres_group.__opts__, {'test': True}):
comt = 'Group {0} is set to be created'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(postgres_group.present(name), ret)
with patch.dict(postgres_group.__opts__, {'test': False}):
comt = 'The group {0} has been created'.format(name)
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(postgres_group.present(name), ret)
|
'Test to ensure that the named group is absent.'
| def test_absent(self):
| name = 'frank'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_t = MagicMock(return_value=True)
mock = MagicMock(side_effect=[True, True, False])
with patch.dict(postgres_group.__salt__, {'postgres.user_exists': mock, 'postgres.group_remove': mock_t}):
with patch.dict(postgres_group.__opts__, {'test': True}):
comt = 'Group {0} is set to be removed'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(postgres_group.absent(name), ret)
with patch.dict(postgres_group.__opts__, {'test': False}):
comt = 'Group {0} has been removed'.format(name)
ret.update({'comment': comt, 'result': True, 'changes': {name: 'Absent'}})
self.assertDictEqual(postgres_group.absent(name), ret)
comt = 'Group {0} is not present, so it cannot be removed'.format(name)
ret.update({'comment': comt, 'result': True, 'changes': {}})
self.assertDictEqual(postgres_group.absent(name), ret)
|
'Test to verify that the specified python is installed with pyenv.'
| def test_installed(self):
| name = 'python-2.7.6'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
with patch.dict(pyenv.__opts__, {'test': True}):
comt = 'python 2.7.6 is set to be installed'
ret.update({'comment': comt})
self.assertDictEqual(pyenv.installed(name), ret)
with patch.dict(pyenv.__opts__, {'test': False}):
mock_f = MagicMock(side_effect=[False, False, True])
mock_fa = MagicMock(side_effect=[False, True])
mock_str = MagicMock(return_value='2.7.6')
mock_lst = MagicMock(return_value=['2.7.6'])
with patch.dict(pyenv.__salt__, {'pyenv.is_installed': mock_f, 'pyenv.install': mock_fa, 'pyenv.default': mock_str, 'pyenv.versions': mock_lst}):
comt = 'pyenv failed to install'
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(pyenv.installed(name), ret)
comt = 'Requested python exists.'
ret.update({'comment': comt, 'result': True, 'default': True})
self.assertDictEqual(pyenv.installed(name), ret)
self.assertDictEqual(pyenv.installed(name), ret)
|
'Test to verify that the specified python is not installed with pyenv.'
| def test_absent(self):
| name = 'python-2.7.6'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
with patch.dict(pyenv.__opts__, {'test': True}):
comt = 'python 2.7.6 is set to be uninstalled'
ret.update({'comment': comt})
self.assertDictEqual(pyenv.absent(name), ret)
with patch.dict(pyenv.__opts__, {'test': False}):
mock_f = MagicMock(side_effect=[False, True])
mock_t = MagicMock(return_value=True)
mock_str = MagicMock(return_value='2.7.6')
mock_lst = MagicMock(return_value=['2.7.6'])
with patch.dict(pyenv.__salt__, {'pyenv.is_installed': mock_f, 'pyenv.uninstall_python': mock_t, 'pyenv.default': mock_str, 'pyenv.versions': mock_lst}):
comt = 'pyenv not installed, 2.7.6 not either'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(pyenv.absent(name), ret)
comt = 'Successfully removed python'
ret.update({'comment': comt, 'result': True, 'default': True, 'changes': {'2.7.6': 'Uninstalled'}})
self.assertDictEqual(pyenv.absent(name), ret)
|
'Test to install pyenv if not installed.'
| def test_install_pyenv(self):
| name = 'python-2.7.6'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
with patch.dict(pyenv.__opts__, {'test': True}):
comt = 'pyenv is set to be installed'
ret.update({'comment': comt})
self.assertDictEqual(pyenv.install_pyenv(name), ret)
with patch.dict(pyenv.__opts__, {'test': False}):
mock_t = MagicMock(return_value=True)
mock_str = MagicMock(return_value='2.7.6')
mock_lst = MagicMock(return_value=['2.7.6'])
with patch.dict(pyenv.__salt__, {'pyenv.install_python': mock_t, 'pyenv.default': mock_str, 'pyenv.versions': mock_lst}):
comt = 'Successfully installed python'
ret.update({'comment': comt, 'result': True, 'default': False, 'changes': {None: 'Installed'}})
self.assertDictEqual(pyenv.install_pyenv(name), ret)
|
'Test - latest_installed when an upgrade is available'
| def test_latest_installed_with_changes(self):
| installed = MagicMock(return_value=KERNEL_LIST[:(-1)])
upgrade = MagicMock(return_value=KERNEL_LIST[(-1)])
with patch.dict(kernelpkg.__salt__, {'kernelpkg.list_installed': installed}):
with patch.dict(kernelpkg.__salt__, {'kernelpkg.latest_available': upgrade}):
with patch.dict(kernelpkg.__opts__, {'test': False}):
kernelpkg.__salt__['kernelpkg.upgrade'].reset_mock()
ret = kernelpkg.latest_installed(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertIsInstance(ret['changes'], dict)
self.assertIsInstance(ret['comment'], str)
self.assert_called_once(kernelpkg.__salt__['kernelpkg.upgrade'])
with patch.dict(kernelpkg.__opts__, {'test': True}):
kernelpkg.__salt__['kernelpkg.upgrade'].reset_mock()
ret = kernelpkg.latest_installed(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertIsNone(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()
|
'Test - latest_installed when no upgrade is available'
| def test_latest_installed_at_latest(self):
| installed = MagicMock(return_value=KERNEL_LIST)
upgrade = MagicMock(return_value=KERNEL_LIST[(-1)])
with patch.dict(kernelpkg.__salt__, {'kernelpkg.list_installed': installed}):
with patch.dict(kernelpkg.__salt__, {'kernelpkg.latest_available': upgrade}):
with patch.dict(kernelpkg.__opts__, {'test': False}):
ret = kernelpkg.latest_installed(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()
with patch.dict(kernelpkg.__opts__, {'test': True}):
ret = kernelpkg.latest_installed(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()
|
'Test - latest_active when a new kernel is available'
| def test_latest_active_with_changes(self):
| reboot = MagicMock(return_value=True)
with patch.dict(kernelpkg.__salt__, {'kernelpkg.needs_reboot': reboot}):
with patch.dict(kernelpkg.__opts__, {'test': False}):
kernelpkg.__salt__['system.reboot'].reset_mock()
ret = kernelpkg.latest_active(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertIsInstance(ret['changes'], dict)
self.assertIsInstance(ret['comment'], str)
self.assert_called_once(kernelpkg.__salt__['system.reboot'])
with patch.dict(kernelpkg.__opts__, {'test': True}):
kernelpkg.__salt__['system.reboot'].reset_mock()
ret = kernelpkg.latest_active(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertIsNone(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['system.reboot'].assert_not_called()
|
'Test - latest_active when the newest kernel is already active'
| def test_latest_active_at_latest(self):
| reboot = MagicMock(return_value=False)
with patch.dict(kernelpkg.__salt__, {'kernelpkg.needs_reboot': reboot}):
with patch.dict(kernelpkg.__opts__, {'test': False}):
kernelpkg.__salt__['system.reboot'].reset_mock()
ret = kernelpkg.latest_active(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['system.reboot'].assert_not_called()
with patch.dict(kernelpkg.__opts__, {'test': True}):
kernelpkg.__salt__['system.reboot'].reset_mock()
ret = kernelpkg.latest_active(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
kernelpkg.__salt__['system.reboot'].assert_not_called()
|
'Test - latest_wait static results'
| def test_latest_wait(self):
| ret = kernelpkg.latest_wait(name=STATE_NAME)
self.assertEqual(ret['name'], STATE_NAME)
self.assertTrue(ret['result'])
self.assertDictEqual(ret['changes'], {})
self.assertIsInstance(ret['comment'], str)
|
'Test to enforce a nice structure on the configuration files.'
| def test_mod_init(self):
| name = 'salt'
mock = MagicMock(side_effect=[True, Exception])
with patch.dict(portage_config.__salt__, {'portage_config.enforce_nice_config': mock}):
self.assertTrue(portage_config.mod_init(name))
self.assertFalse(portage_config.mod_init(name))
|
'Test to enforce the given flags on the given package or ``DEPEND`` atom.'
| def test_flags(self):
| with patch('traceback.format_exc', MagicMock(return_value='SALTSTACK')):
name = 'salt'
ret = {'name': name, 'result': False, 'comment': 'SALTSTACK', 'changes': {}}
mock = MagicMock(side_effect=Exception('error'))
with patch.dict(portage_config.__salt__, {'portage_config.get_missing_flags': mock}):
self.assertDictEqual(portage_config.flags(name, use='openssl'), ret)
self.assertDictEqual(portage_config.flags(name, accept_keywords=True), ret)
self.assertDictEqual(portage_config.flags(name, env=True), ret)
self.assertDictEqual(portage_config.flags(name, license=True), ret)
self.assertDictEqual(portage_config.flags(name, properties=True), ret)
self.assertDictEqual(portage_config.flags(name, mask=True), ret)
self.assertDictEqual(portage_config.flags(name, unmask=True), ret)
ret.update({'comment': '', 'result': True})
self.assertDictEqual(portage_config.flags(name), ret)
|
'Test to ensure the autoscale group exists.'
| def test_present(self):
| name = 'myasg'
launch_config_name = 'mylc'
availability_zones = ['us-east-1a', 'us-east-1b']
min_size = 1
max_size = 1
ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[False, {'min_size': 2}, ['']])
with patch.dict(boto_asg.__salt__, {'boto_asg.get_config': mock}):
with patch.dict(boto_asg.__opts__, {'test': True}):
comt = 'Autoscale group set to be created.'
ret.update({'comment': comt})
with patch.dict(boto_asg.__salt__, {'config.option': MagicMock(return_value={})}):
self.assertDictEqual(boto_asg.present(name, launch_config_name, availability_zones, min_size, max_size), ret)
def magic_side_effect(value):
if isinstance(value, int):
if (value == 1):
return 4
return value
return ''
comt = 'Autoscale group set to be updated.'
ret.update({'comment': comt, 'result': None})
ret.update({'changes': {'new': {'min_size': 4}, 'old': {'min_size': 2}}})
utils_ordered_mock = MagicMock(side_effect=magic_side_effect)
with patch.dict(boto_asg.__salt__, {'config.option': MagicMock(return_value={})}):
with patch.dict(boto_asg.__utils__, {'boto3.ordered': utils_ordered_mock}):
call_ret = boto_asg.present(name, launch_config_name, availability_zones, min_size, max_size)
self.assertDictEqual(call_ret, ret)
with patch.dict(boto_asg.__salt__, {'config.option': MagicMock(return_value={})}):
with patch.dict(boto_asg.__utils__, {'boto3.ordered': MagicMock(return_value='')}):
comt = 'Autoscale group present. '
ret.update({'comment': comt, 'result': True})
ret.update({'changes': {}})
self.assertDictEqual(boto_asg.present(name, launch_config_name, availability_zones, min_size, max_size), ret)
|
'Test to ensure the named autoscale group is deleted.'
| def test_absent(self):
| name = 'myasg'
ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[True, False])
with patch.dict(boto_asg.__salt__, {'boto_asg.get_config': mock}):
with patch.dict(boto_asg.__opts__, {'test': True}):
comt = 'Autoscale group set to be deleted.'
ret.update({'comment': comt})
self.assertDictEqual(boto_asg.absent(name), ret)
comt = 'Autoscale group does not exist.'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(boto_asg.absent(name), ret)
|
'Test to ensure the RabbitMQ VHost exists.'
| def test_present(self):
| name = 'virtual_host'
ret = {'name': name, 'changes': {'new': 'virtual_host', 'old': ''}, 'result': None, 'comment': "Virtual Host 'virtual_host' will be created."}
mock = MagicMock(return_value=False)
with patch.dict(rabbitmq_vhost.__salt__, {'rabbitmq.vhost_exists': mock}):
with patch.dict(rabbitmq_vhost.__opts__, {'test': True}):
self.assertDictEqual(rabbitmq_vhost.present(name), ret)
|
'Test to ensure the named user is absent.'
| def test_absent(self):
| name = 'myqueue'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': "Virtual Host '{0}' is not present.".format(name)}
mock = MagicMock(return_value=False)
with patch.dict(rabbitmq_vhost.__salt__, {'rabbitmq.vhost_exists': mock}):
self.assertDictEqual(rabbitmq_vhost.absent(name), ret)
|
'Test to execute an arbitrary query on the specified database.'
| def test_run(self):
| name = 'query_id'
database = 'my_database'
query = 'SELECT * FROM table;'
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
mock_str = MagicMock(return_value='salt')
mock_none = MagicMock(return_value=None)
mock_dict = MagicMock(return_value={'salt': 'SALT'})
mock_lst = MagicMock(return_value=['grain'])
with patch.dict(mysql_query.__salt__, {'mysql.db_exists': mock_f}):
with patch.object(mysql_query, '_get_mysql_error', mock_str):
ret.update({'comment': 'salt', 'result': False})
self.assertDictEqual(mysql_query.run(name, database, query), ret)
with patch.object(mysql_query, '_get_mysql_error', mock_none):
comt = 'Database {0} is not present'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(mysql_query.run(name, database, query), ret)
with patch.dict(mysql_query.__salt__, {'mysql.db_exists': mock_t, 'grains.ls': mock_lst, 'grains.get': mock_dict, 'mysql.query': mock_str}):
comt = 'No execution needed. Grain grain already set'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(mysql_query.run(name, database, query, output='grain', grain='grain', overwrite=False), ret)
with patch.dict(mysql_query.__opts__, {'test': True}):
comt = 'Query would execute, storing result in grain: grain'
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(mysql_query.run(name, database, query, output='grain', grain='grain'), ret)
comt = 'Query would execute, storing result in grain: grain:salt'
ret.update({'comment': comt})
self.assertDictEqual(mysql_query.run(name, database, query, output='grain', grain='grain', key='salt'), ret)
comt = 'Query would execute, storing result in file: salt'
ret.update({'comment': comt})
self.assertDictEqual(mysql_query.run(name, database, query, output='salt', grain='grain'), ret)
comt = 'Query would execute, not storing result'
ret.update({'comment': comt})
self.assertDictEqual(mysql_query.run(name, database, query), ret)
comt = 'No execution needed. Grain grain:salt already set'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(mysql_query.run(name, database, query, output='grain', grain='grain', key='salt', overwrite=False), ret)
comt = "Error: output type 'grain' needs the grain parameter\n"
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(mysql_query.run(name, database, query, output='grain'), ret)
with patch.object(os.path, 'isfile', mock_t):
comt = 'No execution needed. File salt already set'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(mysql_query.run(name, database, query, output='salt', grain='grain', overwrite=False), ret)
with patch.dict(mysql_query.__opts__, {'test': False}):
ret.update({'comment': 'salt', 'changes': {'query': 'Executed'}})
self.assertDictEqual(mysql_query.run(name, database, query), ret)
|
'Test writing a default setting'
| def test_write(self):
| expected = {'changes': {'written': 'com.apple.CrashReporter DialogType is set to Server'}, 'comment': '', 'name': 'DialogType', 'result': True}
read_mock = MagicMock(return_value='Local')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('DialogType', 'com.apple.CrashReporter', 'Server')
read_mock.assert_called_once_with('com.apple.CrashReporter', 'DialogType', None)
write_mock.assert_called_once_with('com.apple.CrashReporter', 'DialogType', 'Server', 'string', None)
self.assertEqual(out, expected)
|
'Test writing a default setting that is already set'
| def test_write_set(self):
| expected = {'changes': {}, 'comment': 'com.apple.CrashReporter DialogType is already set to Server', 'name': 'DialogType', 'result': True}
read_mock = MagicMock(return_value='Server')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('DialogType', 'com.apple.CrashReporter', 'Server')
read_mock.assert_called_once_with('com.apple.CrashReporter', 'DialogType', None)
assert (not write_mock.called)
self.assertEqual(out, expected)
|
'Test writing a default setting with a boolean'
| def test_write_boolean(self):
| expected = {'changes': {'written': 'com.apple.something Key is set to True'}, 'comment': '', 'name': 'Key', 'result': True}
read_mock = MagicMock(return_value='0')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('Key', 'com.apple.something', True, vtype='boolean')
read_mock.assert_called_once_with('com.apple.something', 'Key', None)
write_mock.assert_called_once_with('com.apple.something', 'Key', True, 'boolean', None)
self.assertEqual(out, expected)
|
'Test writing a default setting with a boolean that is already set to the same value'
| def test_write_boolean_match(self):
| expected = {'changes': {}, 'comment': 'com.apple.something Key is already set to YES', 'name': 'Key', 'result': True}
read_mock = MagicMock(return_value='1')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('Key', 'com.apple.something', 'YES', vtype='boolean')
read_mock.assert_called_once_with('com.apple.something', 'Key', None)
assert (not write_mock.called)
self.assertEqual(out, expected)
|
'Test writing a default setting with a integer'
| def test_write_integer(self):
| expected = {'changes': {'written': 'com.apple.something Key is set to 1337'}, 'comment': '', 'name': 'Key', 'result': True}
read_mock = MagicMock(return_value='99')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('Key', 'com.apple.something', 1337, vtype='integer')
read_mock.assert_called_once_with('com.apple.something', 'Key', None)
write_mock.assert_called_once_with('com.apple.something', 'Key', 1337, 'integer', None)
self.assertEqual(out, expected)
|
'Test writing a default setting with a integer that is already set to the same value'
| def test_write_integer_match(self):
| expected = {'changes': {}, 'comment': 'com.apple.something Key is already set to 1337', 'name': 'Key', 'result': True}
read_mock = MagicMock(return_value='1337')
write_mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.read': read_mock, 'macdefaults.write': write_mock}):
out = macdefaults.write('Key', 'com.apple.something', 1337, vtype='integer')
read_mock.assert_called_once_with('com.apple.something', 'Key', None)
assert (not write_mock.called)
self.assertEqual(out, expected)
|
'Test ensuring non-existent defaults value is absent'
| def test_absent_already(self):
| expected = {'changes': {}, 'comment': 'com.apple.something Key is already absent', 'name': 'Key', 'result': True}
mock = MagicMock(return_value={'retcode': 1})
with patch.dict(macdefaults.__salt__, {'macdefaults.delete': mock}):
out = macdefaults.absent('Key', 'com.apple.something')
mock.assert_called_once_with('com.apple.something', 'Key', None)
self.assertEqual(out, expected)
|
'Test removing an existing value'
| def test_absent_deleting_existing(self):
| expected = {'changes': {'absent': 'com.apple.something Key is now absent'}, 'comment': '', 'name': 'Key', 'result': True}
mock = MagicMock(return_value={'retcode': 0})
with patch.dict(macdefaults.__salt__, {'macdefaults.delete': mock}):
out = macdefaults.absent('Key', 'com.apple.something')
mock.assert_called_once_with('com.apple.something', 'Key', None)
self.assertEqual(out, expected)
|
'Tests present on a trail that does not exist.'
| def test_present_when_trail_does_not_exist(self):
| self.conn.get_trail_status.side_effect = [not_found_error, status_ret]
self.conn.create_trail.return_value = trail_ret
self.conn.describe_trails.return_value = {'trailList': [trail_ret]}
with patch.dict(self.funcs, {'boto_iam.get_account_id': MagicMock(return_value='1234')}):
result = self.salt_states['boto_cloudtrail.present']('trail present', Name=trail_ret['Name'], S3BucketName=trail_ret['S3BucketName'])
self.assertTrue(result['result'])
self.assertEqual(result['changes']['new']['trail']['Name'], trail_ret['Name'])
|
'Tests absent on a trail that does not exist.'
| def test_absent_when_trail_does_not_exist(self):
| self.conn.get_trail_status.side_effect = not_found_error
result = self.salt_states['boto_cloudtrail.absent']('test', 'mytrail')
self.assertTrue(result['result'])
self.assertEqual(result['changes'], {})
|
'Tests present on a bucket that does not exist.'
| def test_present_when_bucket_does_not_exist(self):
| self.conn.head_bucket.side_effect = [not_found_error, None]
self.conn.list_buckets.return_value = deepcopy(list_ret)
self.conn.create_bucket.return_value = bucket_ret
for (key, value) in six.iteritems(config_ret):
getattr(self.conn, key).return_value = deepcopy(value)
with patch.dict(self.funcs, {'boto_iam.get_account_id': MagicMock(return_value='111111222222')}):
result = self.salt_states['boto_s3_bucket.present']('bucket present', Bucket='testbucket', **config_in)
self.assertTrue(result['result'])
self.assertEqual(result['changes']['new']['bucket']['Location'], config_ret['get_bucket_location'])
|
'Tests absent on a bucket that does not exist.'
| def test_absent_when_bucket_does_not_exist(self):
| self.conn.head_bucket.side_effect = [not_found_error, None]
result = self.salt_states['boto_s3_bucket.absent']('test', 'mybucket')
self.assertTrue(result['result'])
self.assertEqual(result['changes'], {})
|
'Test to ensure that the named service is present.'
| def test_present(self):
| name = 'lvsrs'
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
mock_check = MagicMock(side_effect=[True, True, True, False, True, False, True, False, False, False, False])
mock_edit = MagicMock(side_effect=[True, False])
mock_add = MagicMock(side_effect=[True, False])
with patch.dict(lvs_service.__salt__, {'lvs.check_service': mock_check, 'lvs.edit_service': mock_edit, 'lvs.add_service': mock_add}):
with patch.dict(lvs_service.__opts__, {'test': True}):
comt = 'LVS Service lvsrs is present'
ret.update({'comment': comt})
self.assertDictEqual(lvs_service.present(name), ret)
comt = 'LVS Service lvsrs is present but some options should update'
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(lvs_service.present(name), ret)
with patch.dict(lvs_service.__opts__, {'test': False}):
comt = 'LVS Service lvsrs has been updated'
ret.update({'comment': comt, 'result': True, 'changes': {'lvsrs': 'Update'}})
self.assertDictEqual(lvs_service.present(name), ret)
comt = 'LVS Service lvsrs update failed'
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(lvs_service.present(name), ret)
with patch.dict(lvs_service.__opts__, {'test': True}):
comt = 'LVS Service lvsrs is not present and needs to be created'
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(lvs_service.present(name), ret)
with patch.dict(lvs_service.__opts__, {'test': False}):
comt = 'LVS Service lvsrs has been created'
ret.update({'comment': comt, 'result': True, 'changes': {'lvsrs': 'Present'}})
self.assertDictEqual(lvs_service.present(name), ret)
comt = 'LVS Service lvsrs create failed(False)'
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(lvs_service.present(name), ret)
|
'Test to ensure the LVS Real Server in specified service is absent.'
| def test_absent(self):
| name = 'lvsrs'
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
mock_check = MagicMock(side_effect=[True, True, True, False])
mock_delete = MagicMock(side_effect=[True, False])
with patch.dict(lvs_service.__salt__, {'lvs.check_service': mock_check, 'lvs.delete_service': mock_delete}):
with patch.dict(lvs_service.__opts__, {'test': True}):
comt = 'LVS Service lvsrs is present and needs to be removed'
ret.update({'comment': comt})
self.assertDictEqual(lvs_service.absent(name), ret)
with patch.dict(lvs_service.__opts__, {'test': False}):
comt = 'LVS Service lvsrs has been removed'
ret.update({'comment': comt, 'result': True, 'changes': {'lvsrs': 'Absent'}})
self.assertDictEqual(lvs_service.absent(name), ret)
comt = 'LVS Service lvsrs removed failed(False)'
ret.update({'comment': comt, 'result': False, 'changes': {}})
self.assertDictEqual(lvs_service.absent(name), ret)
comt = 'LVS Service lvsrs is not present, so it cannot be removed'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(lvs_service.absent(name), ret)
|
'Test to ensure an Apache module is enabled.'
| def test_enabled(self):
| name = 'cgi'
ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[True, False, False])
mock_str = MagicMock(return_value={'Status': ['enabled']})
with patch.dict(apache_module.__salt__, {'apache.check_mod_enabled': mock, 'apache.a2enmod': mock_str}):
comt = '{0} already enabled.'.format(name)
ret.update({'comment': comt})
self.assertDictEqual(apache_module.enabled(name), ret)
comt = 'Apache module {0} is set to be enabled.'.format(name)
ret.update({'comment': comt, 'result': None, 'changes': {'new': 'cgi', 'old': None}})
with patch.dict(apache_module.__opts__, {'test': True}):
self.assertDictEqual(apache_module.enabled(name), ret)
comt = 'Failed to enable {0} Apache module'.format(name)
ret.update({'comment': comt, 'result': False, 'changes': {}})
with patch.dict(apache_module.__opts__, {'test': False}):
self.assertDictEqual(apache_module.enabled(name), ret)
|
'Test to ensure an Apache module is disabled.'
| def test_disabled(self):
| name = 'cgi'
ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[True, True, False])
mock_str = MagicMock(return_value={'Status': ['disabled']})
with patch.dict(apache_module.__salt__, {'apache.check_mod_enabled': mock, 'apache.a2dismod': mock_str}):
comt = 'Apache module {0} is set to be disabled.'.format(name)
ret.update({'comment': comt, 'changes': {'new': None, 'old': 'cgi'}})
with patch.dict(apache_module.__opts__, {'test': True}):
self.assertDictEqual(apache_module.disabled(name), ret)
comt = 'Failed to disable {0} Apache module'.format(name)
ret.update({'comment': comt, 'result': False, 'changes': {}})
with patch.dict(apache_module.__opts__, {'test': False}):
self.assertDictEqual(apache_module.disabled(name), ret)
comt = '{0} already disabled.'.format(name)
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(apache_module.disabled(name), ret)
|
'Test to ensure the IAM role exists.'
| def test_present(self):
| name = 'myelb'
listeners = [{'elb_port': 'ELBPORT', 'instance_port': 'PORT', 'elb_protocol': 'HTTPS', 'certificate': 'A'}]
alarms = {'MyAlarm': {'name': name, 'attributes': {'description': 'A'}}}
attrs = {'alarm_actions': ['arn:aws:sns:us-east-1:12345:myalarm'], 'insufficient_data_actions': [], 'ok_actions': ['arn:aws:sns:us-east-1:12345:myalarm']}
health_check = {'target:': 'HTTP:80/'}
avail_zones = ['us-east-1a', 'us-east-1c', 'us-east-1d']
cnames = [{'name': 'www.test.com', 'zone': 'test.com', 'ttl': 60}]
ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}
ret1 = copy.deepcopy(ret)
mock = MagicMock(return_value={})
mock_false_bool = MagicMock(return_value=False)
mock_true_bool = MagicMock(return_value=True)
mock_attributes = MagicMock(return_value=attrs)
mock_health_check = MagicMock(return_value=health_check)
with patch.dict(boto_elb.__salt__, {'config.option': mock, 'boto_elb.exists': mock_false_bool, 'boto_elb.create': mock_false_bool, 'pillar.get': MagicMock(return_value={})}):
with patch.dict(boto_elb.__opts__, {'test': False}):
ret = boto_elb.present(name, listeners, availability_zones=avail_zones)
self.assertTrue(boto_elb.__salt__['boto_elb.exists'].called)
self.assertTrue(boto_elb.__salt__['boto_elb.create'].called)
self.assertIn('Failed to create myelb ELB.', ret['comment'])
self.assertFalse(ret['result'])
def mock_config_option(*args, **kwargs):
if (args[0] == 'boto_elb_policies'):
return []
return {}
mock = MagicMock(return_value={})
with patch.dict(boto_elb.__salt__, {'config.option': MagicMock(side_effect=mock_config_option), 'boto_elb.exists': mock_false_bool, 'boto_elb.create': mock_true_bool, 'boto_elb.get_attributes': mock_attributes, 'boto_elb.get_health_check': mock_health_check, 'boto_elb.get_elb_config': MagicMock(side_effect=[mock, MagicMock()]), 'pillar.get': MagicMock(return_value={})}):
with patch.dict(boto_elb.__opts__, {'test': False}):
with patch.dict(boto_elb.__states__, {'boto_cloudwatch_alarm.present': MagicMock(return_value=ret1)}):
ret = boto_elb.present(name, listeners, availability_zones=avail_zones, health_check=health_check, alarms=alarms)
self.assertTrue(boto_elb.__salt__['boto_elb.exists'].called)
self.assertTrue(boto_elb.__salt__['boto_elb.create'].called)
self.assertTrue(boto_elb.__states__['boto_cloudwatch_alarm.present'].called)
self.assertFalse(boto_elb.__salt__['boto_elb.get_attributes'].called)
self.assertTrue(boto_elb.__salt__['boto_elb.get_health_check'].called)
self.assertIn('ELB myelb created.', ret['comment'])
self.assertTrue(ret['result'])
mock = MagicMock(return_value={})
mock_elb = MagicMock(return_value={'dns_name': 'myelb.amazon.com', 'policies': [], 'listeners': [], 'backends': []})
with patch.dict(boto_elb.__salt__, {'config.option': MagicMock(side_effect=mock_config_option), 'boto_elb.exists': mock_false_bool, 'boto_elb.create': mock_true_bool, 'boto_elb.get_attributes': mock_attributes, 'boto_elb.get_health_check': mock_health_check, 'boto_elb.get_elb_config': mock_elb, 'pillar.get': MagicMock(return_value={})}):
with patch.dict(boto_elb.__opts__, {'test': False}):
with patch.dict(boto_elb.__states__, {'boto_route53.present': MagicMock(return_value=ret1)}):
ret = boto_elb.present(name, listeners, availability_zones=avail_zones, health_check=health_check, cnames=cnames)
mock_changes = {'new': {'elb': 'myelb'}, 'old': {'elb': None}}
self.assertTrue(boto_elb.__states__['boto_route53.present'].called)
self.assertEqual(mock_changes, ret['changes'])
self.assertTrue(ret['result'])
|
'Test to add instance/s to load balancer'
| def test_register_instances(self):
| name = 'myelb'
instances = ['instance-id1', 'instance-id2']
ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''}
mock_bool = MagicMock(return_value=False)
with patch.dict(boto_elb.__salt__, {'boto_elb.exists': mock_bool}):
comt = 'Could not find lb {0}'.format(name)
ret.update({'comment': comt})
self.assertDictEqual(boto_elb.register_instances(name, instances), ret)
|
'Test to ensure the IAM role is deleted.'
| def test_absent(self):
| name = 'new_table'
ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[False, True])
with patch.dict(boto_elb.__salt__, {'boto_elb.exists': mock}):
comt = '{0} ELB does not exist.'.format(name)
ret.update({'comment': comt})
self.assertDictEqual(boto_elb.absent(name), ret)
with patch.dict(boto_elb.__opts__, {'test': True}):
comt = 'ELB {0} is set to be removed.'.format(name)
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(boto_elb.absent(name), ret)
|
'Test to execute update_packaging_site.'
| def test_update_packaging_site(self):
| name = 'http://192.168.0.2'
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value=True)
with patch.dict(pkgng.__salt__, {'pkgng.update_package_site': mock_t}):
self.assertDictEqual(pkgng.update_packaging_site(name), ret)
|
'Test to set debconf selections from a file or a template'
| def test_set_file(self):
| name = 'nullmailer'
source = 'salt://pathto/pkg.selections'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Context must be formed as a dict'
ret.update({'comment': comt})
self.assertDictEqual(debconfmod.set_file(name, source, context='salt'), ret)
comt = 'Defaults must be formed as a dict'
ret.update({'comment': comt})
self.assertDictEqual(debconfmod.set_file(name, source, defaults='salt'), ret)
with patch.dict(debconfmod.__opts__, {'test': True}):
comt = 'Debconf selections would have been set.'
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(debconfmod.set_file(name, source), ret)
with patch.dict(debconfmod.__opts__, {'test': False}):
mock = MagicMock(return_value=True)
with patch.dict(debconfmod.__salt__, {'debconf.set_file': mock}):
comt = 'Debconf selections were set.'
ret.update({'comment': comt, 'result': True})
self.assertDictEqual(debconfmod.set_file(name, source), ret)
|
'Test to set debconf selections'
| def test_set(self):
| name = 'nullmailer'
data = {'shared/mailname': {'type': 'string', 'value': 'server.domain.tld'}, 'nullmailer/relayhost': {'type': 'string', 'value': 'mail.domain.tld'}}
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
changes = {'nullmailer/relayhost': 'New value: mail.domain.tld', 'shared/mailname': 'New value: server.domain.tld'}
mock = MagicMock(return_value=None)
with patch.dict(debconfmod.__salt__, {'debconf.show': mock}):
with patch.dict(debconfmod.__opts__, {'test': True}):
ret.update({'changes': changes})
self.assertDictEqual(debconfmod.set(name, data), ret)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.