desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Mock of getWeight method'
| def getWeight(self, server, backend, weight=0):
| self.backend = backend
self.server = server
self.weight = weight
return 'server weight'
|
'Mock of showFrontends method'
| @staticmethod
def showFrontends():
| return 'frontend-alpha\nfrontend-beta\nfrontend-gamma'
|
'Mock of showBackends method'
| @staticmethod
def showBackends():
| return 'backend-alpha\nbackend-beta\nbackend-gamma'
|
'Mock of sendCmd method'
| def sendCmd(self, ha_cmd, objectify=False):
| self.ha_cmd = ha_cmd
self.objectify = objectify
return ha_cmd
|
'Test list_servers'
| def test_list_servers(self):
| self.assertTrue(haproxyconn.list_servers('mysql'))
|
'Test enable_server'
| def test_enable_server(self):
| self.assertTrue(haproxyconn.enable_server('web1.salt.com', 'www'))
|
'Test disable_server'
| def test_disable_server(self):
| self.assertTrue(haproxyconn.disable_server('db1.salt.com', 'mysql'))
|
'Test get the weight of a server'
| def test_get_weight(self):
| self.assertTrue(haproxyconn.get_weight('db1.salt.com', 'mysql'))
|
'Test setting the weight of a given server'
| def test_set_weight(self):
| self.assertTrue(haproxyconn.set_weight('db1.salt.com', 'mysql', weight=11))
|
'Test print all frontends received from the HAProxy socket'
| def test_show_frontends(self):
| self.assertTrue(haproxyconn.show_frontends())
|
'Test listing all frontends'
| def test_list_frontends(self):
| self.assertEqual(sorted(haproxyconn.list_frontends()), sorted(['frontend-alpha', 'frontend-beta', 'frontend-gamma']))
|
'Test print all backends received from the HAProxy socket'
| def test_show_backends(self):
| self.assertTrue(haproxyconn.show_backends())
|
'Test listing of all backends'
| def test_list_backends(self):
| self.assertEqual(sorted(haproxyconn.list_backends()), sorted(['backend-alpha', 'backend-beta', 'backend-gamma']))
|
'Test get_backend and compare returned value'
| def test_get_backend(self):
| expected_data = {'server01': {'status': 'UP', 'weight': 1, 'bin': 22, 'bout': 12}, 'server02': {'status': 'MAINT', 'weight': 2, 'bin': 0, 'bout': 0}}
self.assertDictEqual(haproxyconn.get_backend('test'), expected_data)
|
'Test a successful wait for state'
| def test_wait_state_true(self):
| self.assertTrue(haproxyconn.wait_state('test', 'server01'))
|
'Test a failed wait for state, with a timeout of 0'
| def test_wait_state_false(self):
| self.assertFalse(haproxyconn.wait_state('test', 'server02', 'up', 0))
|
'Test for List configured exports'
| def test_list_exports(self):
| file_d = '\n'.join(['A B1(23'])
with patch('salt.utils.files.fopen', mock_open(read_data=file_d), create=True) as mfi:
mfi.return_value.__iter__.return_value = file_d.splitlines()
self.assertDictEqual(nfs3.list_exports(), {'A': [{'hosts': ['B1'], 'options': ['23']}]})
|
'Test for Remove an export'
| def test_del_export(self):
| with patch.object(nfs3, 'list_exports', return_value={'A': [{'hosts': ['B1'], 'options': ['23']}]}):
with patch.object(nfs3, '_write_exports', return_value=None):
self.assertDictEqual(nfs3.del_export(path='A'), {})
|
'Test for pillar.get(key=..., default=..., merge=True)
Do not update the ``default`` value when using ``merge=True``.
See: https://github.com/saltstack/salt/issues/38558'
| def test_pillar_get_default_merge_regression_38558(self):
| with patch.dict(pillarmod.__pillar__, {'l1': {'l2': {'l3': 42}}}):
res = pillarmod.get(key='l1')
self.assertEqual({'l2': {'l3': 42}}, res)
default = {'l2': {'l3': 43}}
res = pillarmod.get(key='l1', default=default)
self.assertEqual({'l2': {'l3': 42}}, res)
self.assertEqual({'l2': {'l3': 43}}, default)
res = pillarmod.get(key='l1', default=default, merge=True)
self.assertEqual({'l2': {'l3': 42}}, res)
self.assertEqual({'l2': {'l3': 43}}, default)
|
'Confirm that we do not raise an exception if default is None and
merge=True.
See https://github.com/saltstack/salt/issues/39062 for more info.'
| def test_pillar_get_default_merge_regression_39062(self):
| with patch.dict(pillarmod.__pillar__, {'foo': 'bar'}):
self.assertEqual(pillarmod.get(key='foo', default=None, merge=True), 'bar')
|
'Test if it enables RDP the service on the server'
| def test_enable(self):
| mock = MagicMock(return_value=True)
with patch.dict(rdp.__salt__, {'cmd.run': mock}):
with patch('salt.modules.rdp._parse_return_code_powershell', MagicMock(return_value=0)):
self.assertTrue(rdp.enable())
|
'Test if it disables RDP the service on the server'
| def test_disable(self):
| mock = MagicMock(return_value=True)
with patch.dict(rdp.__salt__, {'cmd.run': mock}):
with patch('salt.modules.rdp._parse_return_code_powershell', MagicMock(return_value=0)):
self.assertTrue(rdp.disable())
|
'Test if it shows rdp is enabled on the server'
| def test_status(self):
| mock = MagicMock(return_value='1')
with patch.dict(rdp.__salt__, {'cmd.run': mock}):
self.assertTrue(rdp.status())
|
'This tests git.list_worktrees'
| def test_list_worktrees(self):
| def _build_worktree_output(path):
"\n Build 'git worktree list' output for a given path\n "
return 'worktree {0}\nHEAD {1}\n{2}\n'.format(path, WORKTREE_INFO[path]['HEAD'], ('branch {0}'.format(WORKTREE_INFO[path]['branch']) if (WORKTREE_INFO[path]['branch'] != 'detached') else 'detached'))
_cmd_run_values = {'git worktree list --porcelain': '\n'.join([_build_worktree_output(x) for x in WORKTREE_INFO]), 'git --version': 'git version 2.7.0'}
for path in WORKTREE_INFO:
if (WORKTREE_INFO[path]['branch'] != 'detached'):
continue
key = ('git tag --points-at ' + WORKTREE_INFO[path]['HEAD'])
_cmd_run_values[key] = '\n'.join(WORKTREE_INFO[path].get('tags', []))
def _cmd_run_side_effect(key, **kwargs):
return {'stdout': _cmd_run_values[' '.join(key)], 'stderr': '', 'retcode': 0, 'pid': 12345}
def _isdir_side_effect(key):
return (not WORKTREE_INFO[key].get('stale', False))
worktree_ret = copy.deepcopy(WORKTREE_INFO)
for key in worktree_ret:
ptr = worktree_ret.get(key)
ptr['detached'] = (ptr['branch'] == 'detached')
ptr['branch'] = (None if ptr['detached'] else ptr['branch'].replace('refs/heads/', '', 1))
cmd_run_mock = MagicMock(side_effect=_cmd_run_side_effect)
isdir_mock = MagicMock(side_effect=_isdir_side_effect)
with patch.dict(git_mod.__salt__, {'cmd.run_all': cmd_run_mock}):
with patch.object(os.path, 'isdir', isdir_mock):
self.maxDiff = None
self.assertEqual(git_mod.list_worktrees(WORKTREE_ROOT, all=True, stale=False), worktree_ret)
self.assertEqual(git_mod.list_worktrees(WORKTREE_ROOT, all=False, stale=False), dict([(x, worktree_ret[x]) for x in WORKTREE_INFO if (not WORKTREE_INFO[x].get('stale', False))]))
self.assertEqual(git_mod.list_worktrees(WORKTREE_ROOT, all=False, stale=True), dict([(x, worktree_ret[x]) for x in WORKTREE_INFO if WORKTREE_INFO[x].get('stale', False)]))
|
'Test for Show parsed configuration'
| def test_show_conf(self):
| with patch.object(logadm, '_parse_conf', return_value=True):
self.assertTrue(logadm.show_conf('conf_file'))
|
'Test for Set up pattern for logging.'
| def test_rotate(self):
| with patch.dict(logadm.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 1, 'stderr': 'stderr'})}):
self.assertEqual(logadm.rotate('name'), {'Output': 'stderr', 'Error': 'Failed in adding log'})
with patch.dict(logadm.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0, 'stderr': 'stderr'})}):
self.assertEqual(logadm.rotate('name'), {'Result': 'Success'})
|
'Test for Remove log pattern from logadm'
| def test_remove(self):
| with patch.dict(logadm.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 1, 'stderr': 'stderr'})}):
self.assertEqual(logadm.remove('name'), {'Output': 'stderr', 'Error': 'Failure in removing log. Possibly already removed?'})
with patch.dict(logadm.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0, 'stderr': 'stderr'})}):
self.assertEqual(logadm.remove('name'), {'Result': 'Success'})
|
'Test to halt a running system'
| def test_halt(self):
| with patch.dict(system.__salt__, {'cmd.run': MagicMock(return_value='A')}):
self.assertEqual(system.halt(), 'A')
|
'Test to change the system runlevel on sysV compatible systems'
| def test_init(self):
| with patch.dict(system.__salt__, {'cmd.run': MagicMock(return_value='A')}):
self.assertEqual(system.init('r'), 'A')
|
'Test to poweroff a running system'
| def test_poweroff(self):
| with patch.dict(system.__salt__, {'cmd.run': MagicMock(return_value='A')}):
self.assertEqual(system.poweroff(), 'A')
|
'Test to reboot the system with shutdown -r'
| def test_reboot(self):
| cmd_mock = MagicMock(return_value='A')
with patch.dict(system.__salt__, {'cmd.run': cmd_mock}):
self.assertEqual(system.reboot(), 'A')
cmd_mock.assert_called_with(['shutdown', '-r', 'now'], python_shell=False)
|
'Test to reboot the system using shutdown -r with a delay'
| def test_reboot_with_delay(self):
| cmd_mock = MagicMock(return_value='A')
with patch.dict(system.__salt__, {'cmd.run': cmd_mock}):
self.assertEqual(system.reboot(at_time=5), 'A')
cmd_mock.assert_called_with(['shutdown', '-r', '5'], python_shell=False)
|
'Test to shutdown a running system'
| def test_shutdown(self):
| with patch.dict(system.__salt__, {'cmd.run': MagicMock(return_value='A')}):
self.assertEqual(system.shutdown(), 'A')
|
'test multiple pip mirrors. This test only works with pip < 7.0.0'
| def test_issue5940_install_multiple_pip_mirrors(self):
| with patch.object(pip, 'version', MagicMock(return_value='1.4')):
mirrors = ['http://g.pypi.python.org', 'http://c.pypi.python.org', 'http://pypi.crate.io']
expected = ['pip', 'install', '--use-mirrors']
for item in mirrors:
expected.extend(['--mirrors', item])
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
pip.install(mirrors=mirrors)
mock.assert_called_once_with(expected, saltenv='base', runas=None, use_vt=False, python_shell=False)
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
pip.install(mirrors=','.join(mirrors))
mock.assert_called_once_with(expected, saltenv='base', runas=None, use_vt=False, python_shell=False)
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
pip.install(mirrors=mirrors[0])
mock.assert_called_once_with(['pip', 'install', '--use-mirrors', '--mirrors', mirrors[0]], saltenv='base', runas=None, use_vt=False, python_shell=False)
|
'Tests describing identity pool when the pool\'s name exists'
| def test_that_when_describing_a_named_identity_pool_and_pool_exists_the_describe_identity_pool_method_returns_pools_properties(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
self.conn.describe_identity_pool.side_effect = self._describe_identity_pool_side_effect
result = boto_cognitoidentity.describe_identity_pools(IdentityPoolName=first_pool_name, **conn_parameters)
self.assertEqual(result.get('identity_pools'), [first_pool_ret, third_pool_ret])
|
'Tests describing identity pool when the given pool\'s id exists'
| def test_that_when_describing_a_identity_pool_by_its_id_and_pool_exists_the_desribe_identity_pool_method_returns_pools_properties(self):
| self.conn.describe_identity_pool.return_value = third_pool_ret
result = boto_cognitoidentity.describe_identity_pools(IdentityPoolName='', IdentityPoolId=third_pool_id, **conn_parameters)
self.assertEqual(result.get('identity_pools'), [third_pool_ret])
self.assertTrue((self.conn.list_identity_pools.call_count == 0))
|
'Tests describing identity pool when the pool\'s name doesn\'t exist'
| def test_that_when_describing_a_named_identity_pool_and_pool_does_not_exist_the_describe_identity_pool_method_returns_none(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
self.conn.describe_identity_pool.return_value = first_pool_ret
result = boto_cognitoidentity.describe_identity_pools(IdentityPoolName='no_such_pool', **conn_parameters)
self.assertEqual(result.get('identity_pools', 'no such key'), None)
|
'Tests describing identity pool returns error when there is an exception to boto3 calls'
| def test_that_when_describing_a_named_identity_pool_and_error_thrown_the_describe_identity_pool_method_returns_error(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
self.conn.describe_identity_pool.side_effect = ClientError(error_content, 'error on describe identity pool')
result = boto_cognitoidentity.describe_identity_pools(IdentityPoolName=first_pool_name, **conn_parameters)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('error on describe identity pool'))
|
'Tests the positive case where create identity pool succeeds'
| def test_that_when_create_identity_pool_the_create_identity_pool_method_returns_created_identity_pool(self):
| return_val = default_pool_ret.copy()
return_val.pop('DeveloperProviderName', None)
self.conn.create_identity_pool.return_value = return_val
result = boto_cognitoidentity.create_identity_pool(IdentityPoolName='default_pool_name', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('created'))
self.assertEqual(len(mock_calls), 1)
self.assertEqual(mock_calls[0][0], 'create_identity_pool')
self.assertNotIn('DeveloperProviderName', mock_calls[0][2])
|
'Tests the negative case where create identity pool has a boto3 client error'
| def test_that_when_create_identity_pool_and_error_thrown_the_create_identity_pool_method_returns_error(self):
| self.conn.create_identity_pool.side_effect = ClientError(error_content, 'create_identity_pool')
result = boto_cognitoidentity.create_identity_pool(IdentityPoolName='default_pool_name', **conn_parameters)
self.assertIs(result.get('created'), False)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('create_identity_pool'))
|
'Tests that given 2 matching pool ids, the operation returns deleted status of true and
count 2'
| def test_that_when_delete_identity_pools_with_multiple_matching_pool_names_the_delete_identity_pools_methos_returns_true_and_deleted_count(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
self.conn.delete_identity_pool.return_value = None
result = boto_cognitoidentity.delete_identity_pools(IdentityPoolName=first_pool_name, **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('deleted'))
self.assertEqual(result.get('count'), 2)
self.assertEqual(len(mock_calls), 3)
self.assertEqual(mock_calls[1][0], 'delete_identity_pool')
self.assertEqual(mock_calls[2][0], 'delete_identity_pool')
self.assertEqual(mock_calls[1][2].get('IdentityPoolId'), first_pool_id)
self.assertEqual(mock_calls[2][2].get('IdentityPoolId'), third_pool_id)
|
'Tests that the given pool name does not exist, the operation returns deleted status of false
and count 0'
| def test_that_when_delete_identity_pools_with_no_matching_pool_names_the_delete_identity_pools_method_returns_false(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
result = boto_cognitoidentity.delete_identity_pools(IdentityPoolName='no_such_pool_name', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('deleted'), False)
self.assertEqual(result.get('count'), 0)
self.assertEqual(len(mock_calls), 1)
|
'Tests that the delete_identity_pool method throws an exception'
| def test_that_when_delete_identity_pools_and_error_thrown_the_delete_identity_pools_method_returns_false_and_the_error(self):
| self.conn.delete_identity_pool.side_effect = ClientError(error_content, 'delete_identity_pool')
result = boto_cognitoidentity.delete_identity_pools(IdentityPoolName=first_pool_name, IdentityPoolId='no_such_pool_id', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('deleted'), False)
self.assertIs(result.get('count'), None)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('delete_identity_pool'))
self.assertEqual(len(mock_calls), 1)
|
'Tests that the given 2 pool id\'s matching the given pool name, the results are
passed through as a list of identity_pool_roles'
| def test_that_when_get_identity_pool_roles_with_matching_pool_names_the_get_identity_pool_roles_method_returns_pools_role_properties(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
self.conn.get_identity_pool_roles.side_effect = self._get_identity_pool_roles_side_effect
result = boto_cognitoidentity.get_identity_pool_roles(IdentityPoolName=first_pool_name, **conn_parameters)
id_pool_roles = result.get('identity_pool_roles')
self.assertIsNot(id_pool_roles, None)
self.assertEqual(result.get('error', 'key_should_not_be_there'), 'key_should_not_be_there')
self.assertEqual(len(id_pool_roles), 2)
self.assertEqual(id_pool_roles[0], first_pool_role_ret)
self.assertEqual(id_pool_roles[1], third_pool_role_ret)
|
'Tests that the given no pool id\'s matching the given pool name, the results returned is
None and get_identity_pool_roles should never be called'
| def test_that_when_get_identity_pool_roles_with_no_matching_pool_names_the_get_identity_pool_roles_method_returns_none(self):
| self.conn.list_identity_pools.return_value = identity_pools_ret
result = boto_cognitoidentity.get_identity_pool_roles(IdentityPoolName='no_such_pool_name', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('identity_pool_roles', 'key_should_be_there'), None)
self.assertEqual(len(mock_calls), 1)
self.assertEqual(result.get('error', 'key_should_not_be_there'), 'key_should_not_be_there')
|
'Tests that given an invalid pool id, we properly handle error generated from get_identity_pool_roles'
| def test_that_when_get_identity_pool_roles_and_error_thrown_due_to_invalid_pool_id_the_get_identity_pool_roles_method_returns_error(self):
| self.conn.get_identity_pool_roles.side_effect = ClientError(error_content, 'get_identity_pool_roles')
result = boto_cognitoidentity.get_identity_pool_roles(IdentityPoolName='', IdentityPoolId='no_such_pool_id', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertEqual(result.get('error', {}).get('message'), error_message.format('get_identity_pool_roles'))
self.assertEqual(len(mock_calls), 1)
|
'Tests that given an invalid pool id, we properly handle error generated from set_identity_pool_roles'
| def test_that_when_set_identity_pool_roles_with_invalid_pool_id_the_set_identity_pool_roles_method_returns_set_false_and_error(self):
| self.conn.set_identity_pool_roles.side_effect = ClientError(error_content, 'set_identity_pool_roles')
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='no_such_pool_id', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('set'), False)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('set_identity_pool_roles'))
self.assertEqual(len(mock_calls), 1)
|
'Tests that given a valid pool id, and no other roles given, the role for the pool is cleared.'
| def test_that_when_set_identity_pool_roles_with_no_roles_specified_the_set_identity_pool_roles_method_unset_the_roles(self):
| self.conn.set_identity_pool_roles.return_value = None
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('set'))
self.assertEqual(len(mock_calls), 1)
self.assertEqual(mock_calls[0][2].get('Roles'), {})
|
'Tests that given a valid pool id, and only other given role is the AuthenticatedRole, the auth role for the
pool is set and unauth role is cleared.'
| def test_that_when_set_identity_pool_roles_with_only_auth_role_specified_the_set_identity_pool_roles_method_only_set_the_auth_role(self):
| self.conn.set_identity_pool_roles.return_value = None
with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_auth_role_arn'})}):
expected_roles = dict(authenticated='my_auth_role_arn')
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='my_auth_role', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('set'))
self.assertEqual(len(mock_calls), 1)
self.assertEqual(mock_calls[0][2].get('Roles'), expected_roles)
|
'Tests that given a valid pool id, and only other given role is the UnauthenticatedRole, the unauth role for the
pool is set and the auth role is cleared.'
| def test_that_when_set_identity_pool_roles_with_only_unauth_role_specified_the_set_identity_pool_roles_method_only_set_the_unauth_role(self):
| self.conn.set_identity_pool_roles.return_value = None
with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_unauth_role_arn'})}):
expected_roles = dict(unauthenticated='my_unauth_role_arn')
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', UnauthenticatedRole='my_unauth_role', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('set'))
self.assertEqual(len(mock_calls), 1)
self.assertEqual(mock_calls[0][2].get('Roles'), expected_roles)
|
'Tests setting of both roles to valid given roles'
| def test_that_when_set_identity_pool_roles_with_both_roles_specified_the_set_identity_pool_role_method_set_both_roles(self):
| self.conn.set_identity_pool_roles.return_value = None
with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_unauth_role_arn'})}):
expected_roles = dict(authenticated='arn:aws:iam:my_auth_role', unauthenticated='my_unauth_role_arn')
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='arn:aws:iam:my_auth_role', UnauthenticatedRole='my_unauth_role', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertTrue(result.get('set'))
self.assertEqual(len(mock_calls), 1)
self.assertEqual(mock_calls[0][2].get('Roles'), expected_roles)
|
'Tests error handling for invalid auth role'
| def test_that_when_set_identity_pool_roles_given_invalid_auth_role_the_set_identity_pool_method_returns_set_false_and_error(self):
| with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value=False)}):
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='no_such_auth_role', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('set'), False)
self.assertIn('no_such_auth_role', result.get('error', ''))
self.assertEqual(len(mock_calls), 0)
|
'Tests error handling for invalid unauth role'
| def test_that_when_set_identity_pool_roles_given_invalid_unauth_role_the_set_identity_pool_method_returns_set_false_and_error(self):
| with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value=False)}):
result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='arn:aws:iam:my_auth_role', UnauthenticatedRole='no_such_unauth_role', **conn_parameters)
mock_calls = self.conn.mock_calls
self.assertIs(result.get('set'), False)
self.assertIn('no_such_unauth_role', result.get('error', ''))
self.assertEqual(len(mock_calls), 0)
|
'Tests error handling for invalid pool id'
| def test_that_when_update_identity_pool_given_invalid_pool_id_the_update_identity_pool_method_returns_updated_false_and_error(self):
| self.conn.describe_identity_pool.side_effect = ClientError(error_content, 'error on describe identity pool with pool id')
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId='no_such_pool_id', **conn_parameters)
self.assertIs(result.get('updated'), False)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('error on describe identity pool with pool id'))
|
'Tests the base case of calling update_identity_pool with only the pool id, verify
that the passed parameters into boto3 update_identity_pool has at least all the
expected required parameters in IdentityPoolId, IdentityPoolName and AllowUnauthenticatedIdentities'
| def test_that_when_update_identity_pool_given_only_valid_pool_id_the_update_identity_pool_method_returns_udpated_identity(self):
| self.conn.describe_identity_pool.return_value = second_pool_ret
self.conn.update_identity_pool.return_value = second_pool_ret
expected_params = second_pool_ret
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=second_pool_id, **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), second_pool_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests successful update of a pool\'s name'
| def test_that_when_update_identity_pool_given_valid_pool_id_and_pool_name_the_update_identity_pool_method_returns_updated_identity_pool(self):
| self.conn.describe_identity_pool.return_value = second_pool_ret
second_pool_updated_ret = second_pool_ret.copy()
second_pool_updated_ret['IdentityPoolName'] = second_pool_name_updated
self.conn.update_identity_pool.return_value = second_pool_updated_ret
expected_params = second_pool_updated_ret
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=second_pool_id, IdentityPoolName=second_pool_name_updated, **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), second_pool_updated_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests the request parameters to boto3 update_identity_pool\'s AllowUnauthenticatedIdentities is {}'
| def test_that_when_update_identity_pool_given_empty_dictionary_for_supported_login_providers_the_update_identity_pool_method_is_called_with_proper_request_params(self):
| self.conn.describe_identity_pool.return_value = first_pool_ret
first_pool_updated_ret = first_pool_ret.copy()
first_pool_updated_ret.pop('SupportedLoginProviders')
self.conn.update_identity_pool.return_value = first_pool_updated_ret
expected_params = first_pool_ret.copy()
expected_params['SupportedLoginProviders'] = {}
expected_params.pop('DeveloperProviderName')
expected_params.pop('OpenIdConnectProviderARNs')
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=first_pool_id, SupportedLoginProviders={}, **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), first_pool_updated_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests the request parameters to boto3 update_identity_pool\'s OpenIdConnectProviderARNs is []'
| def test_that_when_update_identity_pool_given_empty_list_for_openid_connect_provider_arns_the_update_identity_pool_method_is_called_with_proper_request_params(self):
| self.conn.describe_identity_pool.return_value = first_pool_ret
first_pool_updated_ret = first_pool_ret.copy()
first_pool_updated_ret.pop('OpenIdConnectProviderARNs')
self.conn.update_identity_pool.return_value = first_pool_updated_ret
expected_params = first_pool_ret.copy()
expected_params.pop('SupportedLoginProviders')
expected_params.pop('DeveloperProviderName')
expected_params['OpenIdConnectProviderARNs'] = []
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=first_pool_id, OpenIdConnectProviderARNs=[], **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), first_pool_updated_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests the request parameters do not include \'DeveloperProviderName\' if this was previously set
for the given pool id'
| def test_that_when_update_identity_pool_given_developer_provider_name_when_developer_provider_name_was_set_previously_the_udpate_identity_pool_method_is_called_without_developer_provider_name_param(self):
| self.conn.describe_identity_pool.return_value = first_pool_ret
self.conn.update_identity_pool.return_value = first_pool_ret
expected_params = first_pool_ret.copy()
expected_params.pop('SupportedLoginProviders')
expected_params.pop('DeveloperProviderName')
expected_params.pop('OpenIdConnectProviderARNs')
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=first_pool_id, DeveloperProviderName='this should not change', **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), first_pool_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests the request parameters include \'DeveloperProviderName\' when the pool did not have this
property set previously.'
| def test_that_when_update_identity_pool_given_developer_provider_name_is_included_in_the_params_when_associated_for_the_first_time(self):
| self.conn.describe_identity_pool.return_value = second_pool_ret
second_pool_updated_ret = second_pool_ret.copy()
second_pool_updated_ret['DeveloperProviderName'] = 'added_developer_provider'
self.conn.update_identity_pool.return_value = second_pool_updated_ret
expected_params = second_pool_updated_ret.copy()
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=second_pool_id, DeveloperProviderName='added_developer_provider', **conn_parameters)
self.assertTrue(result.get('updated'))
self.assertEqual(result.get('identity_pool'), second_pool_updated_ret)
self.conn.update_identity_pool.assert_called_with(**expected_params)
|
'Tests the error handling of exception generated by boto3 update_identity_pool'
| def test_that_the_update_identity_pool_method_handles_exception_from_boto3(self):
| self.conn.describe_identity_pool.return_value = second_pool_ret
second_pool_updated_ret = second_pool_ret.copy()
second_pool_updated_ret['DeveloperProviderName'] = 'added_developer_provider'
self.conn.update_identity_pool.side_effect = ClientError(error_content, 'update_identity_pool')
result = boto_cognitoidentity.update_identity_pool(IdentityPoolId=second_pool_id, DeveloperProviderName='added_developer_provider', **conn_parameters)
self.assertIs(result.get('updated'), False)
self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_identity_pool'))
|
'Test the list_ function for older tuned-adm (v2.4.1)
as shipped with CentOS-6'
| def test_v_241(self):
| tuned_list = 'Available profiles:\n- throughput-performance\n- virtual-guest\n- latency-performance\n- laptop-battery-powersave\n- laptop-ac-powersave\n- virtual-host\n- desktop-powersave\n- server-powersave\n- spindown-disk\n- sap\n- enterprise-storage\n- default\nCurrent active profile: throughput-performance'
mock_cmd = MagicMock(return_value=tuned_list)
with patch.dict(tuned.__salt__, {'cmd.run': mock_cmd}):
self.assertEqual(tuned.list_(), ['throughput-performance', 'virtual-guest', 'latency-performance', 'laptop-battery-powersave', 'laptop-ac-powersave', 'virtual-host', 'desktop-powersave', 'server-powersave', 'spindown-disk', 'sap', 'enterprise-storage', 'default'])
|
'Test the list_ function for newer tuned-adm (v2.7.1)
as shipped with CentOS-7'
| def test_v_271(self):
| tuned_list = 'Available profiles:\n- balanced - General non-specialized tuned profile\n- desktop - Optmize for the desktop use-case\n- latency-performance - Optimize for deterministic performance\n- network-latency - Optimize for deterministic performance\n- network-throughput - Optimize for streaming network throughput.\n- powersave - Optimize for low power-consumption\n- throughput-performance - Broadly applicable tuning that provides--\n- virtual-guest - Optimize for running inside a virtual-guest.\n- virtual-host - Optimize for running KVM guests\nCurrent active profile: virtual-guest\n'
mock_cmd = MagicMock(return_value=tuned_list)
with patch.dict(tuned.__salt__, {'cmd.run': mock_cmd}):
self.assertEqual(tuned.list_(), ['balanced', 'desktop', 'latency-performance', 'network-latency', 'network-throughput', 'powersave', 'throughput-performance', 'virtual-guest', 'virtual-host'])
|
'New behavior, identifier will get track of the managed lines!'
| def test__need_changes_new(self):
| with patch('salt.modules.cron.raw_cron', new=MagicMock(side_effect=get_crontab)):
with patch('salt.modules.cron._write_cron_lines', new=MagicMock(side_effect=write_crontab)):
set_crontab((L + '# SALT_CRON_IDENTIFIER:booh\n* * * * * ls\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='ls', comment=None, identifier=None)
c1 = get_crontab()
set_crontab((L + '* * * * * ls\n'))
self.assertEqual(c1, '# Lines below here are managed by Salt, do not edit\n# SALT_CRON_IDENTIFIER:booh\n* * * * * ls\n* * * * * ls')
set_crontab((L + '# SALT_CRON_IDENTIFIER:bar\n* * * * * ls\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='ls', comment=None, identifier='bar')
c5 = get_crontab()
set_crontab((L + '* * * * * ls\n'))
self.assertEqual(c5, '# Lines below here are managed by Salt, do not edit\n# SALT_CRON_IDENTIFIER:bar\n* * * * * ls\n')
set_crontab((L + '# SALT_CRON_IDENTIFIER:bar\n* * * * * ls\n'))
cron.set_job(user='root', minute='1', hour='2', daymonth='3', month='4', dayweek='5', cmd='foo', comment='moo', identifier='bar')
c6 = get_crontab()
self.assertEqual(c6, '# Lines below here are managed by Salt, do not edit\n# moo SALT_CRON_IDENTIFIER:bar\n1 2 3 4 5 foo')
|
'old behavior; ID has no special action
- If an id is found, it will be added as a new crontab
even if there is a cmd that looks like this one
- no comment, delete the cmd and readd it
- comment: idem'
| def test__need_changes_old(self):
| with patch('salt.modules.cron.raw_cron', new=MagicMock(side_effect=get_crontab)):
with patch('salt.modules.cron._write_cron_lines', new=MagicMock(side_effect=write_crontab)):
set_crontab((L + '* * * * * ls\n\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='ls', comment=None, identifier=cron.SALT_CRON_NO_IDENTIFIER)
c1 = get_crontab()
set_crontab((L + '* * * * * ls\n'))
self.assertEqual(c1, '# Lines below here are managed by Salt, do not edit\n* * * * * ls\n\n')
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='ls', comment='foo', identifier=cron.SALT_CRON_NO_IDENTIFIER)
c2 = get_crontab()
self.assertEqual(c2, '# Lines below here are managed by Salt, do not edit\n# foo\n* * * * * ls')
set_crontab((L + '* * * * * ls\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='lsa', comment='foo', identifier='bar')
c3 = get_crontab()
self.assertEqual(c3, '# Lines below here are managed by Salt, do not edit\n* * * * * ls\n# foo SALT_CRON_IDENTIFIER:bar\n* * * * * lsa')
set_crontab((L + '* * * * * ls\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='foo', comment='foo', identifier='bar')
c4 = get_crontab()
self.assertEqual(c4, '# Lines below here are managed by Salt, do not edit\n* * * * * ls\n# foo SALT_CRON_IDENTIFIER:bar\n* * * * * foo')
set_crontab((L + '* * * * * ls\n'))
cron.set_job(user='root', minute='*', hour='*', daymonth='*', month='*', dayweek='*', cmd='ls', comment='foo', identifier='bbar')
c4 = get_crontab()
self.assertEqual(c4, '# Lines below here are managed by Salt, do not edit\n# foo SALT_CRON_IDENTIFIER:bbar\n* * * * * ls')
|
'handle multi old style crontabs
https://github.com/saltstack/salt/issues/10959'
| def test__issue10959(self):
| with patch('salt.modules.cron.raw_cron', new=MagicMock(side_effect=get_crontab)):
with patch('salt.modules.cron._write_cron_lines', new=MagicMock(side_effect=write_crontab)):
set_crontab('# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * samecmd\n* * * * * otheridcmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n0 * * * * samecmd1\n1 * * * * samecmd1\n0 * * * * otheridcmd1\n1 * * * * otheridcmd1\n# SALT_CRON_IDENTIFIER:1\n0 * * * * otheridcmd1\n# SALT_CRON_IDENTIFIER:2\n0 * * * * otheridcmd1\n')
crons1 = cron.list_tab('root')
self.assertEqual(crons1, {'crons': [{'cmd': 'ls', 'comment': 'uoo', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'too', 'comment': 'uuoo', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'zoo', 'comment': 'uuuoo', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'yoo', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'xoo', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'samecmd', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'samecmd', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '*', 'month': '*', 'commented': False}, {'cmd': 'samecmd1', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'NO ID SET', 'minute': '0', 'month': '*', 'commented': False}, {'cmd': 'samecmd1', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '1', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd1', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '0', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd1', 'comment': None, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': None, 'minute': '1', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd1', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': '1', 'minute': '0', 'month': '*', 'commented': False}, {'cmd': 'otheridcmd1', 'comment': '', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': '2', 'minute': '0', 'month': '*', 'commented': False}], 'env': [], 'pre': [], 'special': []})
inc_tests = ['# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n0 * * * * samecmd1', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n1 * * * * samecmd1', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n1 * * * * samecmd1\n0 * * * * otheridcmd1', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n1 * * * * samecmd1\n1 * * * * otheridcmd1', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n1 * * * * samecmd1\n# SALT_CRON_IDENTIFIER:1\n0 * * * * otheridcmd1', '# Lines below here are managed by Salt, do not edit\n# uoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * ls\n# uuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * too\n# uuuoo SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * zoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * yoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * xoo\n# SALT_CRON_IDENTIFIER:NO ID SET\n* * * * * samecmd\n* * * * * otheridcmd\n# SALT_CRON_IDENTIFIER:NO ID SET\n1 * * * * samecmd1\n# SALT_CRON_IDENTIFIER:1\n0 * * * * otheridcmd1\n# SALT_CRON_IDENTIFIER:2\n0 * * * * otheridcmd1']
set_crontab('')
for (idx, cr) in enumerate(crons1['crons']):
cron.set_job('root', **cr)
self.assertEqual(get_crontab(), inc_tests[idx], "idx {0}\n'{1}'\n != \n'{2}'\n\n\n'{1}' != '{2}'".format(idx, get_crontab(), inc_tests[idx]))
|
'handle commented cron jobs
https://github.com/saltstack/salt/issues/29082'
| def test_list_tab_commented_cron_jobs(self):
| with patch('salt.modules.cron.raw_cron', MagicMock(side_effect=get_crontab)):
with patch('salt.modules.cron._write_cron_lines', MagicMock(side_effect=write_crontab)):
set_crontab('# An unmanaged commented cron job\n#0 * * * * /bin/true\n# Lines below here are managed by Salt, do not edit\n# cron_1 SALT_CRON_IDENTIFIER:cron_1\n#DISABLED#0 * * * * my_cmd_1\n# cron_2 SALT_CRON_IDENTIFIER:cron_2\n#DISABLED#* * * * * my_cmd_2\n# cron_3 SALT_CRON_IDENTIFIER:cron_3\n#DISABLED#but it is a comment line#DISABLED#0 * * * * my_cmd_3\n# cron_4 SALT_CRON_IDENTIFIER:cron_4\n0 * * * * my_cmd_4\n')
crons1 = cron.list_tab('root')
self.assertEqual(crons1, {'crons': [{'cmd': 'my_cmd_1', 'comment': 'cron_1', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'cron_1', 'minute': '0', 'month': '*', 'commented': True}, {'cmd': 'my_cmd_2', 'comment': 'cron_2', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'cron_2', 'minute': '*', 'month': '*', 'commented': True}, {'cmd': 'line#DISABLED#0 * * * * my_cmd_3', 'comment': 'cron_3', 'daymonth': 'is', 'dayweek': 'comment', 'hour': 'it', 'identifier': 'cron_3', 'minute': 'but', 'month': 'a', 'commented': True}, {'cmd': 'my_cmd_4', 'comment': 'cron_4', 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'cron_4', 'minute': '0', 'month': '*', 'commented': False}], 'env': [], 'pre': ['# An unmanaged commented cron job', '#0 * * * * /bin/true'], 'special': []})
|
'Issue #38449'
| def test_cron_extra_spaces(self):
| with patch.dict(cron.__grains__, {'os': None}):
with patch('salt.modules.cron.raw_cron', MagicMock(return_value=STUB_CRON_SPACES)):
ret = cron.list_tab('root')
eret = {'crons': [{'cmd': 'echo "must be double spaced"', 'comment': '', 'commented': False, 'daymonth': '*', 'dayweek': '*', 'hour': '*', 'identifier': 'echo "must be double spaced"', 'minute': '11', 'month': '*'}], 'env': [{'name': 'TEST_VAR', 'value': '"a string with plenty of spaces"'}], 'pre': [''], 'special': []}
self.assertEqual(eret, ret)
|
'Assert that write_cron_file() is called with the correct cron command and user: RedHat
- If instance running uid matches crontab user uid, runas STUB_USER without -u flag.'
| def test_write_cron_file_root_rh(self):
| with patch.dict(cron.__grains__, {'os_family': 'RedHat'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', new=MagicMock(return_value=True)):
cron.write_cron_file(STUB_USER, STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file() is called with the correct cron command and user: RedHat
- If instance running with uid that doesn\'t match crontab user uid, run with -u flag'
| def test_write_cron_file_foo_rh(self):
| with patch.dict(cron.__grains__, {'os_family': 'RedHat'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file('foo', STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab -u foo /tmp', python_shell=False)
|
'Assert that write_cron_file() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_write_cron_file_root_sol(self):
| with patch.dict(cron.__grains__, {'os_family': 'RedHat'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.write_cron_file(STUB_USER, STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_write_cron_file_foo_sol(self):
| with patch.dict(cron.__grains__, {'os_family': 'Solaris'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file('foo', STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab /tmp', runas='foo', python_shell=False)
|
'Assert that write_cron_file() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_write_cron_file_root_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.write_cron_file(STUB_USER, STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_write_cron_file_foo_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.retcode': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file('foo', STUB_PATH)
cron.__salt__['cmd.retcode'].assert_called_with('crontab /tmp', runas='foo', python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: RedHat
- If instance running uid matches crontab user uid, runas STUB_USER without -u flag.'
| def test_write_cr_file_v_root_rh(self):
| with patch.dict(cron.__grains__, {'os_family': 'Redhat'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.write_cron_file_verbose(STUB_USER, STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: RedHat
- If instance running with uid that doesn\'t match crontab user uid, run with -u flag'
| def test_write_cr_file_v_foo_rh(self):
| with patch.dict(cron.__grains__, {'os_family': 'Redhat'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file_verbose('foo', STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab -u foo /tmp', python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_write_cr_file_v_root_sol(self):
| with patch.dict(cron.__grains__, {'os_family': 'Solaris'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.write_cron_file_verbose(STUB_USER, STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_write_cr_file_v_foo_sol(self):
| with patch.dict(cron.__grains__, {'os_family': 'Solaris'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file_verbose('foo', STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab /tmp', runas='foo', python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_write_cr_file_v_root_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.write_cron_file_verbose(STUB_USER, STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab /tmp', runas=STUB_USER, python_shell=False)
|
'Assert that write_cron_file_verbose() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_write_cr_file_v_foo_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.run_all': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.write_cron_file_verbose('foo', STUB_PATH)
cron.__salt__['cmd.run_all'].assert_called_with('crontab /tmp', runas='foo', python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: RedHat
- If instance running uid matches crontab user uid, runas STUB_USER without -u flag.'
| def test_raw_cron_root_redhat(self):
| with patch.dict(cron.__grains__, {'os_family': 'Redhat'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -l', runas=STUB_USER, rstrip=False, python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: RedHat
- If instance running with uid that doesn\'t match crontab user uid, run with -u flag'
| def test_raw_cron_foo_redhat(self):
| with patch.dict(cron.__grains__, {'os_family': 'Redhat'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -u root -l', rstrip=False, python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_raw_cron_root_solaris(self):
| with patch.dict(cron.__grains__, {'os_family': 'Solaris'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -l', runas=STUB_USER, rstrip=False, python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: Solaris
- Solaris should always run without a -u flag'
| def test_raw_cron_foo_solaris(self):
| with patch.dict(cron.__grains__, {'os_family': 'Solaris'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -l', runas=STUB_USER, rstrip=False, python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_raw_cron_root_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=True)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -l', runas=STUB_USER, rstrip=False, python_shell=False)
|
'Assert that raw_cron() is called with the correct cron command and user: AIX
- AIX should always run without a -u flag'
| def test_raw_cron_foo_aix(self):
| with patch.dict(cron.__grains__, {'os_family': 'AIX'}):
with patch.dict(cron.__salt__, {'cmd.run_stdout': MagicMock()}):
with patch('salt.modules.cron._check_instance_uid_match', MagicMock(return_value=False)):
cron.raw_cron(STUB_USER)
cron.__salt__['cmd.run_stdout'].assert_called_with('crontab -l', runas=STUB_USER, rstrip=False, python_shell=False)
|
'Assert that if the new var is \'random\' and old is \'* that we return True'
| def test__needs_change_random(self):
| self.assertTrue(cron._needs_change('*', 'random'))
|
'Passes if a user is added to crontab command'
| def test__get_cron_cmdstr_user(self):
| self.assertEqual('crontab -u root /tmp', cron._get_cron_cmdstr(STUB_PATH, STUB_USER))
|
'Passes if a match is found on all elements. Note the conversions to strings here!
:return:'
| def test__date_time_match(self):
| self.assertTrue(cron._date_time_match(STUB_CRON_TIMESTAMP, minute=STUB_CRON_TIMESTAMP['minute'], hour=STUB_CRON_TIMESTAMP['hour'], daymonth=STUB_CRON_TIMESTAMP['daymonth'], dayweek=STUB_CRON_TIMESTAMP['dayweek']))
|
'Mock bgrewriteaof method'
| @staticmethod
def bgrewriteaof():
| return 'A'
|
'Mock bgsave method'
| @staticmethod
def bgsave():
| return 'A'
|
'Mock config_get method'
| def config_get(self, pattern):
| self.pattern = pattern
return 'A'
|
'Mock config_set method'
| def config_set(self, name, value):
| self.name = name
self.value = value
return 'A'
|
'Mock dbsize method'
| @staticmethod
def dbsize():
| return 'A'
|
'Mock delete method'
| @staticmethod
def delete():
| return 'A'
|
'Mock exists method'
| def exists(self, key):
| self.key = key
return 'A'
|
'Mock expire method'
| def expire(self, key, seconds):
| self.key = key
self.seconds = seconds
return 'A'
|
'Mock expireat method'
| def expireat(self, key, timestamp):
| self.key = key
self.timestamp = timestamp
return 'A'
|
'Mock flushall method'
| @staticmethod
def flushall():
| return 'A'
|
'Mock flushdb method'
| @staticmethod
def flushdb():
| return 'A'
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.