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.assert...
'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'], ('b...
'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, 's...
'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': M...
'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 = Mag...
'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')...
'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_...
'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'), Non...
'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.assertE...
'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.assertTru...
'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'),...
'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')) sel...
'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...
'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')...
'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_r...
'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.assertEq...
'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', {})...
'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(...
'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...
'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(Ide...
'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_rol...
'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 = ...
'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...
'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_...
'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.assertEq...
'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')) ...
'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 ...
'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['Suppor...
'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('...
'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('OpenIdConnectProvid...
'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_r...
'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...
'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 ...
'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 deskto...
'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', ...
'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...
'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_IDE...
'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 ...
'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, 'daymon...
'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.__...
'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__[...
'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...
'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__...
'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__[...
'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__['cm...
'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) cro...
'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._...
'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) cr...
'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....
'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._...
'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.__sa...
'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_std...
'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_st...
'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_st...
'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_s...
'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 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_stdou...
'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'