desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test that renderers have: - __salt__ # Execution functions (i.e. __salt__[\'test.echo\'](\'foo\')) - __grains__ # Grains (i.e. __grains__[\'os\']) - __pillar__ # Pillar data (i.e. __pillar__[\'foo\']) - __opts__ # Minion configuration options - __context__ # Context dict shared amongst all modules of the same ...
def test_renderers(self):
self._verify_globals(salt.loader.render(self.master_opts, {}))
'Test to verifies that the specified SSH key is present for the specified user.'
def test_present(self):
name = 'sshkeys' user = 'root' source = 'salt://ssh_keys/id_rsa.pub' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(return_value='exists') mock_data = MagicMock(side_effect=['replace', 'new']) with patch.dict(ssh_auth.__salt__, {'ssh.check_key': mock, 'ss...
'Test to verifies that the specified SSH key is absent.'
def test_absent(self):
name = 'sshkeys' user = 'root' source = 'salt://ssh_keys/id_rsa.pub' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(side_effect=['User authorized keys file not present', 'Key removed']) mock_up = MagicMock(side_effect=['update', 'updated']) ...
'Test to spin up a single instance on a cloud provider, using salt-cloud.'
def test_present(self):
name = 'mycloud' cloud_provider = 'my_cloud_provider' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False]) mock_bool = MagicMock(side_effect=[True, False, False]) mock_dict = MagicMock(return_value={'cloud': 'saltcloud'}) with patch.d...
'Test to ensure that no instances with the specified names exist.'
def test_absent(self):
name = 'mycloud' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False]) mock_bool = MagicMock(side_effect=[False, True, True]) mock_dict = MagicMock(return_value={'cloud': 'saltcloud'}) with patch.dict(cloud.__salt__, {'cmd.retcode': mock, ...
'Test to create a single instance on a cloud provider, using a salt-cloud profile.'
def test_profile(self):
name = 'mycloud' profile = 'myprofile' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False]) mock_dict = MagicMock(side_effect=[{'cloud': 'saltcloud'}, {'Not Actioned': True}, {'Not Actioned': True}, {'Not Found': True, 'Not Action...
'Test to check that a block volume exists.'
def test_volume_present(self):
name = 'mycloud' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=name) mock_lst = MagicMock(side_effect=[[name], [], []]) with patch.dict(cloud.__salt__, {'cloud.volume_list': mock_lst, 'cloud.volume_create': mock}): with patch.object(salt.ut...
'Test to check that a block volume exists.'
def test_volume_absent(self):
name = 'mycloud' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=False) mock_lst = MagicMock(side_effect=[[], [name], [name]]) with patch.dict(cloud.__salt__, {'cloud.volume_list': mock_lst, 'cloud.volume_delete': mock}): with patch.object(sa...
'Test to check if a block volume is attached.'
def test_volume_attached(self):
name = 'mycloud' server_name = 'mycloud_server' disk_name = 'trogdor' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=False) mock_dict = MagicMock(side_effect=[{name: {'name': disk_name, 'attachments': True}}, {}, {name: {'name': disk_name, 'atta...
'Test to check if a block volume is detached.'
def test_volume_detached(self):
name = 'mycloud' server_name = 'mycloud_server' disk_name = 'trogdor' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(return_value=False) mock_dict = MagicMock(side_effect=[{name: {'name': disk_name, 'attachments': False}}, {}, {name: {'name': disk_name, 'att...
'tests present on a thing type that does not exist.'
def test_present_when_thing_type_does_not_exist(self):
self.conn.describe_thing_type.side_effect = [not_found_error, thing_type_ret] self.conn.create_thing_type.return_value = create_thing_type_ret result = self.salt_states['boto_iot.thing_type_present']('thing type present', thingTypeName=thing_type_name, thingTypeDescription=thing_type_desc, searchableA...
'Tests absent on a thing type does not exist'
def test_absent_when_thing_type_does_not_exist(self):
self.conn.describe_thing_type.side_effect = not_found_error result = self.salt_states['boto_iot.thing_type_absent']('test', 'mythingtype', **conn_parameters) self.assertTrue(result['result']) self.assertEqual(result['changes'], {})
'Tests absent on a thing type'
def test_absent_when_thing_type_exists(self):
self.conn.describe_thing_type.return_value = deprecated_thing_type_ret result = self.salt_states['boto_iot.thing_type_absent']('test', thing_type_name, **conn_parameters) self.assertTrue(result['result']) self.assertEqual(result['changes']['new']['thing_type'], None) self.assertTrue((self.conn.depre...
'Tests present on a policy that does not exist.'
def test_present_when_policy_does_not_exist(self):
self.conn.get_policy.side_effect = [not_found_error, policy_ret] self.conn.create_policy.return_value = policy_ret result = self.salt_states['boto_iot.policy_present']('policy present', policyName=policy_ret['policyName'], policyDocument=policy_ret['policyDocument']) self.assertTrue(result['result'])...
'Tests absent on a policy that does not exist.'
def test_absent_when_policy_does_not_exist(self):
self.conn.get_policy.side_effect = not_found_error result = self.salt_states['boto_iot.policy_absent']('test', 'mypolicy') self.assertTrue(result['result']) self.assertEqual(result['changes'], {})
'Tests attached on a policy that is not attached.'
def test_attached_when_policy_not_attached(self):
self.conn.list_principal_policies.return_value = {'policies': []} result = self.salt_states['boto_iot.policy_attached']('test', 'myfunc', principal) self.assertTrue(result['result']) self.assertTrue(result['changes']['new']['attached'])
'Tests attached on a policy that is attached.'
def test_attached_when_policy_attached(self):
self.conn.list_principal_policies.return_value = {'policies': [policy_ret]} result = self.salt_states['boto_iot.policy_attached']('test', policy_ret['policyName'], principal) self.assertTrue(result['result']) self.assertEqual(result['changes'], {})
'Tests attached on a policy that is attached.'
def test_attached_with_failure(self):
self.conn.list_principal_policies.return_value = {'policies': []} self.conn.attach_principal_policy.side_effect = ClientError(error_content, 'attach_principal_policy') result = self.salt_states['boto_iot.policy_attached']('test', policy_ret['policyName'], principal) self.assertFalse(result['result']) ...
'Tests detached on a policy that is not detached.'
def test_detached_when_policy_not_detached(self):
self.conn.list_principal_policies.return_value = {'policies': [policy_ret]} result = self.salt_states['boto_iot.policy_detached']('test', policy_ret['policyName'], principal) self.assertTrue(result['result']) log.warning(result) self.assertFalse(result['changes']['new']['attached'])
'Tests detached on a policy that is detached.'
def test_detached_when_policy_detached(self):
self.conn.list_principal_policies.return_value = {'policies': []} result = self.salt_states['boto_iot.policy_detached']('test', policy_ret['policyName'], principal) self.assertTrue(result['result']) self.assertEqual(result['changes'], {})
'Tests detached on a policy that is detached.'
def test_detached_with_failure(self):
self.conn.list_principal_policies.return_value = {'policies': [policy_ret]} self.conn.detach_principal_policy.side_effect = ClientError(error_content, 'detach_principal_policy') result = self.salt_states['boto_iot.policy_detached']('test', policy_ret['policyName'], principal) self.assertFalse(result['re...
'Tests present on a topic_rule that does not exist.'
def test_present_when_topic_rule_does_not_exist(self):
self.conn.get_topic_rule.side_effect = [topic_rule_not_found_error, {'rule': topic_rule_ret}] self.conn.create_topic_rule.return_value = {'created': True} result = self.salt_states['boto_iot.topic_rule_present']('topic rule present', ruleName=topic_rule_ret['ruleName'], sql=topic_rule_ret['sql'], desc...
'Tests absent on a topic rule that does not exist.'
def test_absent_when_topic_rule_does_not_exist(self):
self.conn.get_topic_rule.side_effect = topic_rule_not_found_error result = self.salt_states['boto_iot.topic_rule_absent']('test', 'myrule') self.assertTrue(result['result']) self.assertEqual(result['changes'], {})
'Test to ensure that the cluster admin or database user is present.'
def test_present(self):
name = 'salt' passwd = 'salt' ret = {'name': name, 'result': False, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[False, False, False, True]) mock_t = MagicMock(side_effect=[True, False]) mock_f = MagicMock(return_value=False) with patch.dict(influxdb08_user.__salt__, {'influxd...
'Test to ensure that the named cluster admin or database user is absent.'
def test_absent(self):
name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=[True, True, True, False]) mock_t = MagicMock(side_effect=[True, False]) with patch.dict(influxdb08_user.__salt__, {'influxdb08.user_exists': mock, 'influxdb08.user_remove': mock_t}): ...
'Checkout or update the working directory to the latest revision from the remote repository.'
def test_latest(self):
mock = MagicMock(return_value=True) with patch.object(svn, '_fail', mock): self.assertTrue(svn.latest('salt')) mock = MagicMock(side_effect=[True, False, False, False]) with patch.object(os.path, 'exists', mock): mock = MagicMock(return_value=False) with patch.object(os.path, 'is...
'Test to export a file or directory from an SVN repository'
def test_export(self):
mock = MagicMock(return_value=True) with patch.object(svn, '_fail', mock): self.assertTrue(svn.export('salt')) mock = MagicMock(side_effect=[True, False, False, False]) with patch.object(os.path, 'exists', mock): mock = MagicMock(return_value=False) with patch.object(os.path, 'is...
'Test to determine if the working directory has been changed.'
def test_dirty(self):
mock = MagicMock(return_value=True) with patch.object(svn, '_fail', mock): self.assertTrue(svn.dirty('salt', 'c://salt'))
'Test to ensure that the named database is present with the specified properties.'
def test_present(self):
name = 'frank' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock_t = MagicMock(return_value=True) mock = MagicMock(return_value={name: {}}) with patch.dict(postgres_database.__salt__, {'postgres.db_list': mock, 'postgres.db_alter': mock_t}): comt = 'Database {0} ...
'Test to ensure that the named database 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_database.__salt__, {'postgres.db_exists': mock, 'postgres.db_remove': mock_t}): with patch.dict(...
'Test to ensure the SQS queue exists.'
def test_exists(self):
name = 'myqueue' region = 'eu-west-1' ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[False, True]) with patch.dict(aws_sqs.__salt__, {'aws_sqs.queue_exists': mock}): comt = 'AWS SQS queue {0} is set to be created'.form...
'Test to remove the named SQS queue if it exists.'
def test_absent(self):
name = 'myqueue' region = 'eu-west-1' ret = {'name': name, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False]) with patch.dict(aws_sqs.__salt__, {'aws_sqs.queue_exists': mock}): comt = 'AWS SQS queue {0} is set to be removed'.form...
'Test to set package in \'hold\' state, meaning it will not be upgraded.'
def test_held(self):
name = 'tmux' ret = {'name': name, 'result': False, 'changes': {}, 'comment': 'Package {0} does not have a state'.format(name)} mock = MagicMock(return_value=False) with patch.dict(aptpkg.__salt__, {'pkg.get_selections': mock}): self.assertDictEqual(aptpkg.held(name), ret)
'Test to create an event on the PagerDuty service.'
def test_create_event(self):
name = 'This is a server warning message' details = 'This is a much more detailed message' service_key = '9abcd123456789efabcde362783cdbaf' profile = 'my-pagerduty-account' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(pagerdu...
'Test to ensure that the named sysctl value is set in memory and persisted to the named configuration file.'
def test_present(self):
name = 'net.ipv4.conf.all.rp_filter' value = '1' config = '/etc/sysctl.conf' comment = 'Sysctl option {0} might be changed, we failed to check config file at {1}. The file is either unreadable, or missing.'.format(name, config) ret = {'name...
'Test if it returns True when specified package is not installed'
def test_removed_not_installed(self):
mock = MagicMock(return_value={'underscore': {}}) with patch.dict(bower.__salt__, {'bower.list': mock}): ret = bower.removed('jquery', '/path/to/project') expected = {'name': 'jquery', 'result': True, 'comment': "Package 'jquery' is not installed", 'changes': {}} self.assertE...
'Test if returns False when list packages fails'
def test_removed_with_error(self):
mock = MagicMock(side_effect=CommandExecutionError) with patch.dict(bower.__salt__, {'bower.list': mock}): ret = bower.removed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result': False, 'comment': "Error removing 'underscore': ", 'changes': {}} self.ass...
'Test if it returns True when specified package is installed and uninstall succeeds'
def test_removed_existing(self):
mock_list = MagicMock(return_value={'underscore': {}}) mock_uninstall = MagicMock(return_value=True) with patch.dict(bower.__salt__, {'bower.list': mock_list, 'bower.uninstall': mock_uninstall}): ret = bower.removed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result'...
'Test if it returns False when specified package is installed and uninstall fails'
def test_removed_existing_with_error(self):
mock_list = MagicMock(return_value={'underscore': {}}) mock_uninstall = MagicMock(side_effect=CommandExecutionError) with patch.dict(bower.__salt__, {'bower.list': mock_list, 'bower.uninstall': mock_uninstall}): ret = bower.removed('underscore', '/path/to/project') expected = {'name': 'under...
'Test if it return False when install packages fails'
def test_bootstrap_with_error(self):
mock = MagicMock(side_effect=CommandExecutionError) with patch.dict(bower.__salt__, {'bower.install': mock}): ret = bower.bootstrap('/path/to/project') expected = {'name': '/path/to/project', 'result': False, 'comment': "Error bootstrapping '/path/to/project': ", 'changes': {}} ...
'Test if it returns True when there is nothing to install'
def test_bootstrap_not_needed(self):
mock = MagicMock(return_value=False) with patch.dict(bower.__salt__, {'bower.install': mock}): ret = bower.bootstrap('/path/to/project') expected = {'name': '/path/to/project', 'result': True, 'comment': 'Directory is already bootstrapped', 'changes': {}} self.assertEqual(ret, e...
'Test if it returns True when install packages succeeds'
def test_bootstrap_success(self):
mock = MagicMock(return_value=True) with patch.dict(bower.__salt__, {'bower.install': mock}): ret = bower.bootstrap('/path/to/project') expected = {'name': '/path/to/project', 'result': True, 'comment': 'Directory was successfully bootstrapped', 'changes': {'/path/to/project': 'Bootstra...
'Test if it returns False when list packages fails'
def test_installed_with_error(self):
mock = MagicMock(side_effect=CommandExecutionError) with patch.dict(bower.__salt__, {'bower.list': mock}): ret = bower.installed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result': False, 'comment': "Error looking up 'underscore': ", 'changes': {}} s...
'Test if it returns True when there is nothing to install'
def test_installed_not_needed(self):
mock = MagicMock(return_value={'underscore': {'pkgMeta': {'version': '1.7.0'}}, 'jquery': {'pkgMeta': {'version': '2.0.0'}}}) with patch.dict(bower.__salt__, {'bower.list': mock}): ret = bower.installed('test', '/path/to/project', ['underscore', 'jquery#2.0.0']) expected = {'name': 'test', 'resu...
'Test if it returns False when install packages fails (exception)'
def test_installed_new_with_exc(self):
mock_list = MagicMock(return_value={}) mock_install = MagicMock(side_effect=CommandExecutionError) with patch.dict(bower.__salt__, {'bower.list': mock_list, 'bower.install': mock_install}): ret = bower.installed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result': Fa...
'Test if returns False when install packages fails (bower error)'
def test_installed_new_with_error(self):
mock_list = MagicMock(return_value={}) mock_install = MagicMock(return_value=False) with patch.dict(bower.__salt__, {'bower.list': mock_list, 'bower.install': mock_install}): ret = bower.installed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result': False, 'comment':...
'Test if it returns True when install succeeds'
def test_installed_success(self):
mock_list = MagicMock(return_value={}) mock_install = MagicMock(return_value=True) with patch.dict(bower.__salt__, {'bower.list': mock_list, 'bower.install': mock_install}): ret = bower.installed('underscore', '/path/to/project') expected = {'name': 'underscore', 'result': True, 'comment': "...
'Test to verify that the correct versions of composer dependencies are present.'
def test_installed(self):
name = 'CURL' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} mock = MagicMock(return_value=True) with patch.dict(composer.__salt__, {'composer.did_composer_install': mock}): comt = 'Composer already installed this directory' ret.update({'comment': comt}) ...
'Test to composer update the directory to ensure we have the latest versions of all project dependencies.'
def test_update(self):
name = 'CURL' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} changes = {'new': 'composer install/update will be run in CURL', 'old': 'composer install has not yet been run in CURL'} mock = MagicMock(return_value=True) with patch.dict(comp...
'Test to send an event to the Salt Master'
def test_send(self):
with patch.dict(event.__opts__, {'test': True}): self.assertDictEqual(event.send('salt'), {'changes': {'data': None, 'tag': 'salt'}, 'comment': 'Event would have been fired', 'name': 'salt', 'result': None}) with patch.dict(event.__opts__, {'test': False}): mock = MagicMock(return_va...
'Test to fire an event on the Salt master'
def test_wait(self):
self.assertDictEqual(event.wait('salt'), {'changes': {}, 'comment': '', 'name': 'salt', 'result': True})
'Test to ensures that the named host is present with the given ip'
def test_present(self):
ret = {'changes': {}, 'comment': 'Host salt (127.0.0.1) already present', 'name': 'salt', 'result': True} mock = MagicMock(return_value=True) with patch.dict(host.__salt__, {'hosts.has_pair': mock}): self.assertDictEqual(host.present('salt', '127.0.0.1'), ret)
'Test to ensure that the named host is absent'
def test_absent(self):
ret = {'changes': {}, 'comment': 'Host salt (127.0.0.1) already absent', 'name': 'salt', 'result': True} mock = MagicMock(return_value=False) with patch.dict(host.__salt__, {'hosts.has_pair': mock}): self.assertDictEqual(host.absent('salt', '127.0.0.1'), ret)
'Test only() when the state hasn\'t changed'
def test_only_already(self):
expected = {'name': '127.0.1.1', 'changes': {}, 'result': True, 'comment': 'IP address 127.0.1.1 already set to "foo.bar"'} mock1 = MagicMock(return_value=['foo.bar']) with patch.dict(host.__salt__, {'hosts.get_alias': mock1}): mock2 = MagicMock(return_value=True) with patc...
'Test only() when state would change, but it\'s a dry run'
def test_only_dryrun(self):
expected = {'name': '127.0.1.1', 'changes': {}, 'result': None, 'comment': 'Would change 127.0.1.1 from "foo.bar" to "foo.bar foo"'} mock1 = MagicMock(return_value=['foo.bar']) with patch.dict(host.__salt__, {'hosts.get_alias': mock1}): mock2 = MagicMock(return_value=True) ...
'Test only() when state change fails'
def test_only_fail(self):
expected = {'name': '127.0.1.1', 'changes': {}, 'result': False, 'comment': ('hosts.set_host failed to change 127.0.1.1' + ' from "foo.bar" to "foo.bar foo"')} mock = MagicMock(return_value=['foo.bar']) with patch.dict(host.__salt__, {'hosts.get_alias': mock}): mock = Magi...
'Test only() when state successfully changes'
def test_only_success(self):
expected = {'name': '127.0.1.1', 'changes': {'127.0.1.1': {'old': 'foo.bar', 'new': 'foo.bar foo'}}, 'result': True, 'comment': ('successfully changed 127.0.1.1' + ' from "foo.bar" to "foo.bar foo"')} mock = MagicMock(return_value=['foo.bar']) with patch.dict(host.__salt__, {'hosts.g...
'Test to enforce that the WAR will be deployed and started in the context path it will make use of WAR versions'
def test_war_deployed(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock_start = MagicMock(return_value='saltstack') mock_undeploy = MagicMock(side_effect=['FAIL', 'saltstack']) mock_deploy = MagicMock(return_value='deploy') mock_ls = MagicMock(side_effect=[{'salt': {'version': 'jenkins-1.20.4', 'm...
'Tests that going from versions to no versions and back work, as well as not overwriting a WAR without version with another without version.'
def test_war_deployed_no_version(self):
ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock_deploy = MagicMock(return_value='deploy') mock_undeploy = MagicMock(return_value='SUCCESS') mock_ls_version = MagicMock(return_value={'salt': {'version': '1.2.4', 'mode': 'running'}}) mock_ls_no_version = MagicMock(return_valu...
'Test to wait for the tomcat manager to load'
def test_wait(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': 'tomcat manager is ready'} mock = MagicMock(return_value=True) with patch.dict(tomcat.__salt__, {'tomcat.status': mock, 'tomcat.extract_war_version': tomcatmod.extract_war_version}): self.assertDictEqual(tomcat.wait('salt'), r...
'Test to the tomcat watcher function.'
def test_mod_watch(self):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': 'True'} mock = MagicMock(return_value='True') with patch.dict(tomcat.__salt__, {'tomcat.reload': mock, 'tomcat.extract_war_version': tomcatmod.extract_war_version}): ret.update({'changes': {'salt': False}}) self.assertDictEqua...
'Test to enforce that the WAR will be un-deployed from the server'
def test_undeployed(self):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': 'True'} mock = MagicMock(side_effect=[False, True, True, True, True]) mock1 = MagicMock(side_effect=[{'salt': {'a': 1}}, {'salt': {'version': 1}}, {'salt': {'version': 1}}, {'salt': {'version': 1}}]) mock2 = MagicMock(side_effect=['FAIL',...
'Test to ensure the SNS topic exists.'
def test_present(self):
name = 'test.example.com.' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False, False]) mock_bool = MagicMock(return_value=False) with patch.dict(boto_sns.__salt__, {'boto_sns.exists': mock, 'boto_sns.create': mock_bool}): comt = 'AWS ...
'Test to ensure the named sns topic is deleted.'
def test_absent(self):
name = 'test.example.com.' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} self.maxDiff = None exists_mock = MagicMock(side_effect=[False, True, True, True, True, True, True]) with patch.dict(boto_sns.__salt__, {'boto_sns.exists': exists_mock}): comt = 'AWS SNS topic...
'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_server.__salt__, {'lvs.check_server': mock_check, 'lvs.delete_server': mock_delete}):...
'Test to send a message to a Slack channel.'
def test_post_message(self):
name = 'slack-message' channel = '#general' from_name = 'SuperAdmin' message = 'This state was executed successfully.' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} with patch.dict(slack.__opts__, {'test': True}): comt = 'The following message is...
'Test to make sure that a pecl extension is installed.'
def test_installed(self):
name = 'mongo' ver = '1.0.1' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock_lst = MagicMock(return_value={name: 'stable'}) mock_t = MagicMock(return_value=True) with patch.dict(pecl.__salt__, {'pecl.list': mock_lst, 'pecl.install': mock_t}): comt = 'Pecl exten...
'Test to make sure that a pecl extension is not installed.'
def test_removed(self):
name = 'mongo' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock_lst = MagicMock(side_effect=[{}, {name: 'stable'}, {name: 'stable'}]) mock_t = MagicMock(return_value=True) with patch.dict(pecl.__salt__, {'pecl.list': mock_lst, 'pecl.uninstall': mock_t}): comt = 'Pecl ...
'Test to ensure an Apache site is enabled.'
def test_enabled(self):
name = 'saltstack.com' 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_site.__salt__, {'apache.check_site_enabled': mock, 'apache.a2ensite': mock_st...
'Test to ensure an Apache site is disabled.'
def test_disabled(self):
name = 'saltstack.com' 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_site.__salt__, {'apache.check_site_enabled': mock, 'apache.a2dissite': mock_s...
'Test to ensures that the artifact from artifactory exists at given location.'
def test_downloaded(self):
name = 'jboss' arti_url = 'http://artifactory.intranet.example.com/artifactory' artifact = {'artifactory_url': arti_url, 'artifact_id': 'module', 'repository': 'libs-release-local', 'packaging': 'jar', 'group_id': 'com.company.module', 'classifier': 'sources', 'version': '1.0'} ret = {'name': name, 'res...
'Test to verify the chain is exist.'
def test_chain_present(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[True, False, False]) with patch.dict(nftables.__salt__, {'nftables.check_chain': mock}): ret.update({'comment': 'nftables salt chain is already exist in filter table for i...
'Test to verify the chain is absent.'
def test_chain_absent(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=[False, True]) with patch.dict(nftables.__salt__, {'nftables.check_chain': mock}): ret.update({'comment': 'nftables salt chain is already absent in filter table for ipv4'})...
'Test to append a rule to a chain'
def test_append(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(return_value=[]) with patch.object(nftables, '_STATE_INTERNAL_KEYWORDS', mock): mock = MagicMock(return_value='a') with patch.dict(nftables.__salt__, {'nftables.build_rule': mock}): mock = Magic...
'Test to insert a rule into a chain'
def test_insert(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(return_value=[]) with patch.object(nftables, '_STATE_INTERNAL_KEYWORDS', mock): mock = MagicMock(return_value='a') with patch.dict(nftables.__salt__, {'nftables.build_rule': mock}): mock = Magic...
'Test to delete a rule to a chain'
def test_delete(self):
ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=[]) with patch.object(nftables, '_STATE_INTERNAL_KEYWORDS', mock): mock = MagicMock(return_value='a') with patch.dict(nftables.__salt__, {'nftables.build_rule': mock}): mock = Magic...
'Test to flush current nftables state'
def test_flush(self):
ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(return_value=[]) with patch.object(nftables, '_STATE_INTERNAL_KEYWORDS', mock): mock = MagicMock(side_effect=[False, True, True, True]) with patch.dict(nftables.__salt__, {'nftables.check_table': mock}): ...
'Test to ensure that the named user is present with the specified properties'
def test_present(self):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''} mock_false = MagicMock(return_value=False) mock_empty_list = MagicMock(return_value=[]) with patch.dict(user.__grains__, {'kernel': 'Linux'}): with patch.dict(user.__salt__, {'group.info': mock_false, 'user.info': mock_empty_l...
'Test to ensure that the named user is absent'
def test_absent(self):
ret = {'name': 'salt', 'changes': {}, 'result': None, 'comment': ''} mock = MagicMock(side_effect=[True, True, False]) mock1 = MagicMock(return_value=False) with patch.dict(user.__salt__, {'user.info': mock, 'user.delete': mock1, 'group.info': mock1}): with patch.dict(user.__opts__, {'test': Tru...
'test alias.present has target already'
def test_present_has_target(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Alias {0} already present'.format(name), 'changes': {}, 'name': name, 'result': True} has_target = MagicMock(return_value=True) with patch.dict(alias.__salt__, {'aliases.has_target': has_target}): self.assertEqual(al...
'test alias.present has\'t got target yet test mode'
def test_present_has_not_target_test(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Alias {0} -> {1} is set to be added'.format(name, target), 'changes': {}, 'name': name, 'result': None} has_target = MagicMock(return_value=False) with patch.dict(alias.__salt__, {'aliases.has_target': has_tar...
'test alias.present set target'
def test_present_set_target(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Set email alias {0} -> {1}'.format(name, target), 'changes': {'alias': name}, 'name': name, 'result': True} has_target = MagicMock(return_value=False) set_target = MagicMock(return_value=True) with patch.dict(alias...
'test alias.present set target failure'
def test_present_set_target_failed(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Failed to set alias {0} -> {1}'.format(name, target), 'changes': {}, 'name': name, 'result': False} has_target = MagicMock(return_value=False) set_target = MagicMock(return_value=False) with patch.dict(alias.__s...
'test alias.absent already gone'
def test_absent_already_gone(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Alias {0} already absent'.format(name), 'changes': {}, 'name': name, 'result': True} get_target = MagicMock(return_value=False) with patch.dict(alias.__salt__, {'aliases.get_target': get_target}): self.assertEqual(al...
'test alias.absent already gone test mode'
def test_absent_not_gone_test(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Alias {0} is set to be removed'.format(name), 'changes': {}, 'name': name, 'result': None} get_target = MagicMock(return_value=True) with patch.dict(alias.__salt__, {'aliases.get_target': get_target}): with ...
'test alias.absent remove alias'
def test_absent_rm_alias(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Removed alias {0}'.format(name), 'changes': {'alias': name}, 'name': name, 'result': True} get_target = MagicMock(return_value=True) rm_alias = MagicMock(return_value=True) with patch.dict(alias.__salt__, {'aliases.get_targ...
'test alias.absent remove alias failure'
def test_absent_rm_alias_failed(self):
name = 'saltdude' target = 'dude@saltstack.com' ret = {'comment': 'Failed to remove alias {0}'.format(name), 'changes': {}, 'name': name, 'result': False} get_target = MagicMock(return_value=True) rm_alias = MagicMock(return_value=False) with patch.dict(alias.__salt__, {'aliases.get_...
'Test to configure the DNS server list in the specified interface'
def test_dns_exists(self):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''} with patch.dict(win_dns_client.__opts__, {'test': False}): ret.update({'changes': {'Servers Added': [], 'Servers Removed': [], 'Servers Reordered': []}, 'comment': 'servers entry is not a list !'}) s...
'Test to configure the DNS server list from DHCP Server'
def test_dns_dhcp(self):
ret = {'name': 'salt', 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(side_effect=['dhcp', 'salt', 'salt']) with patch.dict(win_dns_client.__salt__, {'win_dns_client.get_dns_config': mock}): ret.update({'comment': 'Local Area Connection already configured with DNS ...
'Test to configure the global primary DNS suffix of a DHCP client.'
def test_primary_suffix(self):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''} ret.update({'comment': "'updates' must be a boolean value"}) self.assertDictEqual(win_dns_client.primary_suffix('salt', updates='a'), ret) mock = MagicMock(side_effect=[{'vdata': 'a'}, {'vdata': False}, {'vdata': 'b'}, ...
'Test to ensure the IAM role exists.'
def test_present(self):
name = 'myrole' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} _desc_role = {'create_date': '2015-02-11T19:47:14Z', 'role_id': 'HIUHBIUBIBNKJNBKJ', 'assume_role_policy_document': {'Version': '2008-10-17', 'Statement': [{'Action': 'sts:AssumeRole', 'Principal': {'Service': 'ec2.amazonaws...
'Test to ensure the IAM role is deleted.'
def test_absent(self):
name = 'myrole' ret = {'name': name, 'result': False, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[['mypolicy'], ['mypolicy'], False, True, False, False, True, False, False, False, True]) mock_bool = MagicMock(return_value=False) mock_lst = MagicMock(return_value=[]) with patch.di...
'Test to verify that a device is mounted.'
def test_mounted(self):
name = '/mnt/sdb' device = '/dev/sdb5' fstype = 'xfs' name2 = '/mnt/cifs' device2 = '//SERVER/SHARE/' fstype2 = 'cifs' opts2 = ['noowners'] superopts2 = ['uid=510', 'gid=100', 'username=cifsuser', 'domain=cifsdomain'] ret = {'name': name, 'result': False, 'comment': '', 'changes': {}...
'Test to activates a swap device.'
def test_swap(self):
name = '/mnt/sdb' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock = MagicMock(side_effect=['present', 'new', 'change', 'bad config']) mock_f = MagicMock(return_value=False) mock_swp = MagicMock(return_value=[name]) mock_fs = MagicMock(return_value={'none': {'device': n...
'Test to verify that a device is not mounted'
def test_unmounted(self):
name = '/mnt/sdb' device = '/dev/sdb5' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} mock_f = MagicMock(return_value=False) mock_dev = MagicMock(return_value={name: {'device': device}}) mock_fs = MagicMock(return_value={name: {'device': name}}) mock_mnt = MagicMock(side_...
'Test the mounted watcher, called to invoke the watch command.'
def test_mod_watch(self):
name = '/mnt/sdb' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} comt = 'Watch not supported in unmount at this time' ret.update({'comment': comt}) self.assertDictEqual(mount.mod_watch(name, sfun='unmount'), ret)
'Try and create a record that already exists'
def test_present_record_exists(self):
result = libcloud_dns.record_present('www', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result)
'Try and create a record that already exists'
def test_present_record_does_not_exist(self):
result = libcloud_dns.record_present('mail', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result)
'Try and deny a record that already exists'
def test_absent_record_exists(self):
result = libcloud_dns.record_absent('www', 'test.com', 'A', '127.0.0.1', 'test') self.assertTrue(result)