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.succ...
'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.succ...
'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, 'c...
'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_stat...
'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_stat...
'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, 'ch...
'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_...
'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(mon...
'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_effec...
'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])...
'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, CommandExecutio...
'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, CommandExecution...
'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_te...
'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(s...
'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(s...
'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_e...
'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 = Magi...
'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_crea...
'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__ = {'docke...
'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...
'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.disconn...
'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):...
'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}): ...
'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 pa...
'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() w...
'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_presen...
'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_abse...
'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(l...
'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(nam...
'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...
'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...
'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(n...
'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_b...
'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.functi...
'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 ' ...
'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.assertDictE...
'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...
'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, ...
'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 ...
'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': 'sal...
'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 s...
'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', '...
'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, ...
'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._...
'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...
'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...
'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.updat...
'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 alread...
'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.'}) ...
'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(xa...
'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(xa...
'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() ...
'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...
'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 = Ma...
'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 = '\nerr...
'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...
'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....
'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.dic...
'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) ...
'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) w...
'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 p...
'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...
'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 - 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.as...
'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.a...
'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_f...
'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...
'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...
'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...
'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.ab...
'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 = MagicMo...
'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__, {'macdefaul...
'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__, {'macdefault...
'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, 'ma...
'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, 'macde...
'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, 'm...
'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, 'm...
'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') ...
'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.somethin...
'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_...
'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.fu...
'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 pat...
'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...
'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}): ...
'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}): ...
'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_acti...
'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...
'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}) ...
'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) ...
'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...