desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Tests for configure syslog remote logging, by default syslog will
automatically be enabled if a server is specified. However,
if you want to disable syslog you will need to specify a server
followed by False'
| def test_syslog(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.syslog('server'))
mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.syslog('server', False))
|
'Test to Enable/Disable email alerts'
| def test_email_alerts(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.email_alerts(True))
mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.email_alerts(False))
|
'Test for list all DRAC users'
| def test_list_users(self):
| mock = MagicMock(return_value={'retcode': 0, 'stdout': 'cfgUserAdminUserName=value'})
with patch.dict(drac.__salt__, {'cmd.run_all': mock}):
self.assertEqual(drac.list_users(), {'value': {'index': 16}})
|
'Tests to delete a user'
| def test_delete_user(self):
| mock = MagicMock(return_value='ABC')
with patch.object(drac, '__execute_cmd', mock):
self.assertEqual(drac.delete_user('username', 1), 'ABC')
self.assertFalse(drac.delete_user('username', False))
|
'Tests to change users password'
| def test_change_password(self):
| mock = MagicMock(return_value='ABC')
with patch.object(drac, '__execute_cmd', mock):
self.assertEqual(drac.change_password('username', 'password', 1), 'ABC')
self.assertFalse(drac.change_password('username', 'password', False), False)
|
'Tests to create user accounts'
| def test_create_user(self):
| self.assertFalse(drac.create_user('username', 'password', 'permissions', {'username': None}))
mock = MagicMock(return_value=False)
with patch.object(drac, '__execute_cmd', mock):
mock = MagicMock(return_value=None)
with patch.object(drac, 'delete_user', mock):
self.assertFalse(drac.create_user('username', 'password', 'permissions', {'username1': {'index': 1}}))
mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
mock = MagicMock(return_value=False)
with patch.object(drac, 'set_permissions', mock):
mock = MagicMock(return_value=None)
with patch.object(drac, 'delete_user', mock):
self.assertFalse(drac.create_user('username', 'password', 'permissions', {'username1': {'index': 1}}))
mock = MagicMock(return_value=True)
with patch.object(drac, 'set_permissions', mock):
mock = MagicMock(return_value=False)
with patch.object(drac, 'change_password', mock):
mock = MagicMock(return_value=None)
with patch.object(drac, 'delete_user', mock):
self.assertFalse(drac.create_user('username', 'password', 'permissions', {'username1': {'index': 1}}))
mock = MagicMock(side_effect=[True, False])
with patch.object(drac, '__execute_cmd', mock):
mock = MagicMock(return_value=True)
with patch.object(drac, 'set_permissions', mock):
mock = MagicMock(return_value=True)
with patch.object(drac, 'change_password', mock):
mock = MagicMock(return_value=None)
with patch.object(drac, 'delete_user', mock):
self.assertFalse(drac.create_user('username', 'password', 'permissions', {'username1': {'index': 1}}))
mock = MagicMock(side_effect=[True, True])
with patch.object(drac, '__execute_cmd', mock):
mock = MagicMock(return_value=True)
with patch.object(drac, 'set_permissions', mock):
mock = MagicMock(return_value=True)
with patch.object(drac, 'change_password', mock):
mock = MagicMock(return_value=None)
with patch.object(drac, 'delete_user', mock):
self.assertTrue(drac.create_user('username', 'password', 'permissions', {'username1': {'index': 1}}))
|
'Test to configure users permissions'
| def test_set_permissions(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.set_permissions('username', 'A,B,C', 1))
|
'Test to configure SNMP community string'
| def test_set_snmp(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.set_snmp('username'))
|
'Test to configure Network'
| def test_set_network(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.set_network('ip', 'netmask', 'gateway'))
|
'Tests for issues a power-cycle operation on the managed server.
This action is similar to pressing the power button on the system\'s
front panel to power down and then power up the system.'
| def test_server_reboot(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.server_reboot())
|
'Tests for powers down the managed server.'
| def test_server_poweroff(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.server_poweroff())
|
'Tests for powers up the managed server.'
| def test_server_poweron(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.server_poweron())
|
'Tests for performs a reset (reboot) operation on the managed server.'
| def test_server_hardreset(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.server_hardreset())
|
'Tests to configure server to PXE perform a one off PXE boot'
| def test_server_pxe(self):
| mock = MagicMock(return_value=True)
with patch.object(drac, '__execute_cmd', mock):
self.assertTrue(drac.server_pxe())
mock = MagicMock(side_effect=[True, False])
with patch.object(drac, '__execute_cmd', mock):
self.assertFalse(drac.server_pxe())
mock = MagicMock(return_value=False)
with patch.object(drac, '__execute_cmd', mock):
self.assertFalse(drac.server_pxe())
|
'Tests return a list of all available kernel modules'
| def test_available(self):
| with patch('salt.modules.kmod.available', MagicMock(return_value=['kvm'])):
self.assertEqual(['kvm'], kmod.available())
|
'Tests if the specified kernel module is available'
| def test_check_available(self):
| with patch('salt.modules.kmod.available', MagicMock(return_value=['kvm'])):
self.assertTrue(kmod.check_available('kvm'))
|
'Tests return information about currently loaded modules'
| def test_lsmod(self):
| mock_ret = [{'size': 100, 'module': None, 'depcount': 10, 'deps': None}]
with patch('salt.modules.kmod.lsmod', MagicMock(return_value=mock_ret)):
mock_cmd = MagicMock(return_value=1)
with patch.dict(kmod.__salt__, {'cmd.run': mock_cmd}):
self.assertListEqual(mock_ret, kmod.lsmod())
|
'Tests return a list of the loaded module names'
| @skipIf((not os.path.isfile('/etc/modules')), '/etc/modules not present')
def test_mod_list(self):
| with patch('salt.modules.kmod._get_modules_conf', MagicMock(return_value='/etc/modules')):
with patch('salt.modules.kmod._strip_module_name', MagicMock(return_value='lp')):
self.assertListEqual(['lp'], kmod.mod_list(True))
mock_ret = [{'size': 100, 'module': None, 'depcount': 10, 'deps': None}]
with patch('salt.modules.kmod.lsmod', MagicMock(return_value=mock_ret)):
self.assertListEqual([None], kmod.mod_list(False))
|
'Tests to loads specified kernel module.'
| def test_load(self):
| mod = 'cheese'
err_msg = 'Module too moldy, refusing to load'
mock_persist = MagicMock(return_value=set([mod]))
mock_lsmod = MagicMock(return_value=[{'size': 100, 'module': None, 'depcount': 10, 'deps': None}])
mock_run_all_0 = MagicMock(return_value={'retcode': 0})
mock_run_all_1 = MagicMock(return_value={'retcode': 1, 'stderr': err_msg})
with patch('salt.modules.kmod._set_persistent_module', mock_persist):
with patch('salt.modules.kmod.lsmod', mock_lsmod):
with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_0}):
self.assertEqual([mod], kmod.load(mod, True))
with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_1}):
self.assertEqual('Error loading module {0}: {1}'.format(mod, err_msg), kmod.load(mod))
|
'Tests if specified kernel module is loaded.'
| def test_is_loaded(self):
| with patch('salt.modules.kmod.mod_list', MagicMock(return_value=set(['lp']))):
self.assertTrue(kmod.is_loaded('lp'))
|
'Tests to remove the specified kernel module'
| def test_remove(self):
| mod = 'cheese'
err_msg = 'Cannot find module: it has been eaten'
mock_persist = MagicMock(return_value=set([mod]))
mock_lsmod = MagicMock(return_value=[{'size': 100, 'module': None, 'depcount': 10, 'deps': None}])
mock_run_all_0 = MagicMock(return_value={'retcode': 0})
mock_run_all_1 = MagicMock(return_value={'retcode': 1, 'stderr': err_msg})
with patch('salt.modules.kmod._remove_persistent_module', mock_persist):
with patch('salt.modules.kmod.lsmod', mock_lsmod):
with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_0}):
self.assertEqual([mod], kmod.remove(mod, True))
self.assertEqual([], kmod.remove(mod))
with patch.dict(kmod.__salt__, {'cmd.run_all': mock_run_all_1}):
self.assertEqual('Error removing module {0}: {1}'.format(mod, err_msg), kmod.remove(mod, True))
|
'Test if it return version from iptables --version'
| def test_version(self):
| mock = MagicMock(return_value='iptables v1.4.21')
with patch.dict(iptables.__salt__, {'cmd.run': mock}):
self.assertEqual(iptables.version(), 'v1.4.21')
|
'Test if it build a well-formatted iptables rule based on kwargs.'
| def test_build_rule(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
self.assertEqual(iptables.build_rule(), '')
self.assertEqual(iptables.build_rule(name='ignored', state='ignored'), '', 'build_rule should ignore name and state')
self.assertEqual(iptables.build_rule(**{'if': '!eth0'}), '! -i eth0')
self.assertEqual(iptables.build_rule(**{'if': 'not eth0'}), '! -i eth0')
self.assertEqual(iptables.build_rule(dports=[80, 443], proto='tcp'), '-p tcp -m multiport --dports 80,443')
self.assertEqual(iptables.build_rule(dports='80,443', proto='tcp'), '-p tcp -m multiport --dports 80,443')
self.assertEqual(iptables.build_rule(dports=['!80', 443], proto='tcp'), '-p tcp -m multiport ! --dports 80,443')
self.assertEqual(iptables.build_rule(dports='!80,443', proto='tcp'), '-p tcp -m multiport ! --dports 80,443')
self.assertEqual(iptables.build_rule(sports=[80, 443], proto='tcp'), '-p tcp -m multiport --sports 80,443')
self.assertEqual(iptables.build_rule(sports='80,443', proto='tcp'), '-p tcp -m multiport --sports 80,443')
self.assertEqual(iptables.build_rule('filter', 'INPUT', command='I', position='3', full=True, dports='proto', jump='ACCEPT'), 'Error: proto must be specified')
self.assertEqual(iptables.build_rule('filter', 'INPUT', command='I', position='3', full=True, sports='proto', jump='ACCEPT'), 'Error: proto must be specified')
self.assertEqual(iptables.build_rule('', 'INPUT', command='I', position='3', full='True', match='state', jump='ACCEPT'), 'Error: Table needs to be specified')
self.assertEqual(iptables.build_rule('filter', '', command='I', position='3', full='True', match='state', jump='ACCEPT'), 'Error: Chain needs to be specified')
self.assertEqual(iptables.build_rule('filter', 'INPUT', command='', position='3', full='True', match='state', jump='ACCEPT'), 'Error: Command needs to be specified')
self.assertEqual(iptables.build_rule(jump='REDIRECT', **{'to-port': 8080}), '--jump REDIRECT --to-port 8080')
self.assertEqual(iptables.build_rule(jump='LOG', **{'log-prefix': 'long prefix'}), '--jump LOG --log-prefix "long prefix"')
self.assertEqual(iptables.build_rule(jump='LOG', **{'log-prefix': 'spam: '}), '--jump LOG --log-prefix "spam: "')
self.assertEqual(iptables.build_rule(jump='CLUSTERIP', **{'new': ''}), '--jump CLUSTERIP --new')
self.assertEqual(iptables.build_rule(jump='CT', **{'notrack': None}), '--jump CT --notrack')
self.assertEqual(iptables.build_rule(**{'match-set': 'src flag1,flag2'}), '-m set --match-set src flag1,flag2')
match_sets = ['src1 flag1', 'src2 flag2,flag3']
self.assertEqual(iptables.build_rule(**{'match-set': match_sets}), '-m set --match-set src1 flag1 -m set --match-set src2 flag2,flag3')
self.assertEqual(iptables.build_rule(**{'match-set': '!src flag'}), '-m set ! --match-set src flag')
match_sets = ['src1 flag', 'not src2 flag2']
self.assertEqual(iptables.build_rule(**{'match-set': match_sets}), '-m set --match-set src1 flag -m set ! --match-set src2 flag2')
self.assertEqual(iptables.build_rule(**{'match': 'recent', 'name_': 'SSH'}), '-m recent --name SSH')
self.assertEqual(iptables.build_rule(**{'match': 'recent', 'update': None}), '-m recent --update')
ret = '/sbin/iptables --wait -t salt -I INPUT 3 -m state --jump ACCEPT'
with patch.object(iptables, '_iptables_cmd', MagicMock(return_value='/sbin/iptables')):
self.assertEqual(iptables.build_rule('salt', 'INPUT', command='I', position='3', full='True', match='state', jump='ACCEPT'), ret)
|
'Test if it return a data structure of the rules in the conf file'
| def test_get_saved_rules(self):
| mock = MagicMock(return_value=False)
with patch.object(iptables, '_parse_conf', mock):
self.assertFalse(iptables.get_saved_rules())
mock.assert_called_with(conf_file=None, family='ipv4')
|
'Test if it return a data structure of the current, in-memory rules'
| def test_get_rules(self):
| mock = MagicMock(return_value=False)
with patch.object(iptables, '_parse_conf', mock):
self.assertFalse(iptables.get_rules())
mock.assert_called_with(in_mem=True, family='ipv4')
|
'Test if it return the current policy for the specified table/chain'
| def test_get_saved_policy(self):
| self.assertEqual(iptables.get_saved_policy(table='filter', chain=None, conf_file=None, family='ipv4'), 'Error: Chain needs to be specified')
with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy': True}}})):
self.assertTrue(iptables.get_saved_policy(table='filter', chain='INPUT', conf_file=None, family='ipv4'))
with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy1': True}}})):
self.assertIsNone(iptables.get_saved_policy(table='filter', chain='INPUT', conf_file=None, family='ipv4'))
|
'Test if it return the current policy for the specified table/chain'
| def test_get_policy(self):
| self.assertEqual(iptables.get_policy(table='filter', chain=None, family='ipv4'), 'Error: Chain needs to be specified')
with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy': True}}})):
self.assertTrue(iptables.get_policy(table='filter', chain='INPUT', family='ipv4'))
with patch.object(iptables, '_parse_conf', MagicMock(return_value={'filter': {'INPUT': {'policy1': True}}})):
self.assertIsNone(iptables.get_policy(table='filter', chain='INPUT', family='ipv4'))
|
'Test if it set the current policy for the specified table/chain'
| def test_set_policy(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
self.assertEqual(iptables.set_policy(table='filter', chain=None, policy=None, family='ipv4'), 'Error: Chain needs to be specified')
self.assertEqual(iptables.set_policy(table='filter', chain='INPUT', policy=None, family='ipv4'), 'Error: Policy needs to be specified')
mock = MagicMock(return_value=True)
with patch.dict(iptables.__salt__, {'cmd.run': mock}):
self.assertTrue(iptables.set_policy(table='filter', chain='INPUT', policy='ACCEPT', family='ipv4'))
|
'Test if it save the current in-memory rules to disk'
| def test_save(self):
| with patch('salt.modules.iptables._conf', MagicMock(return_value=False)):
with patch('os.path.isdir', MagicMock(return_value=True)):
mock = MagicMock(return_value=True)
with patch.dict(iptables.__salt__, {'cmd.run': mock, 'file.write': mock, 'config.option': MagicMock(return_value=[])}):
self.assertTrue(iptables.save(filename='/xyz', family='ipv4'))
|
'Test if it check for the existence of a rule in the table and chain'
| def test_check(self):
| self.assertEqual(iptables.check(table='filter', chain=None, rule=None, family='ipv4'), 'Error: Chain needs to be specified')
self.assertEqual(iptables.check(table='filter', chain='INPUT', rule=None, family='ipv4'), 'Error: Rule needs to be specified')
mock_rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT'
mock_chain = 'INPUT'
mock_uuid = 31337
mock_cmd = MagicMock(return_value='-A {0}\n-A {1}'.format(mock_chain, hex(mock_uuid)))
mock_has = MagicMock(return_value=True)
mock_not = MagicMock(return_value=False)
with patch.object(iptables, '_has_option', mock_not):
with patch.object(uuid, 'getnode', MagicMock(return_value=mock_uuid)):
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.check(table='filter', chain=mock_chain, rule=mock_rule, family='ipv4'))
mock_cmd = MagicMock(return_value='')
with patch.object(iptables, '_has_option', mock_not):
with patch.object(uuid, 'getnode', MagicMock(return_value=mock_uuid)):
with patch.dict(iptables.__salt__, {'cmd.run': MagicMock(return_value='')}):
self.assertFalse(iptables.check(table='filter', chain=mock_chain, rule=mock_rule, family='ipv4'))
with patch.object(iptables, '_has_option', mock_has):
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.check(table='filter', chain='INPUT', rule=mock_rule, family='ipv4'))
mock_cmd = MagicMock(return_value='-A 0x4d2')
mock_uuid = MagicMock(return_value=1234)
with patch.object(iptables, '_has_option', mock_has):
with patch.object(uuid, 'getnode', mock_uuid):
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.check(table='filter', chain='0x4d2', rule=mock_rule, family='ipv4'))
|
'Test if it check for the existence of a chain in the table'
| def test_check_chain(self):
| self.assertEqual(iptables.check_chain(table='filter', chain=None, family='ipv4'), 'Error: Chain needs to be specified')
mock_cmd = MagicMock(return_value='')
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertFalse(iptables.check_chain(table='filter', chain='INPUT', family='ipv4'))
|
'Test if it create new custom chain to the specified table.'
| def test_new_chain(self):
| self.assertEqual(iptables.new_chain(table='filter', chain=None, family='ipv4'), 'Error: Chain needs to be specified')
mock_cmd = MagicMock(return_value='')
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.new_chain(table='filter', chain='INPUT', family='ipv4'))
|
'Test if it delete custom chain to the specified table.'
| def test_delete_chain(self):
| self.assertEqual(iptables.delete_chain(table='filter', chain=None, family='ipv4'), 'Error: Chain needs to be specified')
mock_cmd = MagicMock(return_value='')
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.delete_chain(table='filter', chain='INPUT', family='ipv4'))
|
'Test if it append a rule to the specified table/chain.'
| def test_append(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
with patch.object(iptables, 'check', MagicMock(return_value=False)):
self.assertEqual(iptables.append(table='filter', chain=None, rule=None, family='ipv4'), 'Error: Chain needs to be specified')
self.assertEqual(iptables.append(table='filter', chain='INPUT', rule=None, family='ipv4'), 'Error: Rule needs to be specified')
_rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT'
mock = MagicMock(side_effect=['', 'SALT'])
with patch.dict(iptables.__salt__, {'cmd.run': mock}):
self.assertTrue(iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4'))
self.assertFalse(iptables.append(table='filter', chain='INPUT', rule=_rule, family='ipv4'))
|
'Test if it insert a rule into the specified table/chain,
at the specified position.'
| def test_insert(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
with patch.object(iptables, 'check', MagicMock(return_value=False)):
self.assertEqual(iptables.insert(table='filter', chain=None, position=None, rule=None, family='ipv4'), 'Error: Chain needs to be specified')
pos_err = 'Error: Position needs to be specified or use append (-A)'
self.assertEqual(iptables.insert(table='filter', chain='INPUT', position=None, rule=None, family='ipv4'), pos_err)
self.assertEqual(iptables.insert(table='filter', chain='INPUT', position=3, rule=None, family='ipv4'), 'Error: Rule needs to be specified')
_rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT'
mock = MagicMock(return_value=True)
with patch.dict(iptables.__salt__, {'cmd.run': mock}):
self.assertTrue(iptables.insert(table='filter', chain='INPUT', position=3, rule=_rule, family='ipv4'))
|
'Test if it delete a rule from the specified table/chain'
| def test_delete(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
_rule = 'm state --state RELATED,ESTABLISHED -j ACCEPT'
self.assertEqual(iptables.delete(table='filter', chain=None, position=3, rule=_rule, family='ipv4'), 'Error: Only specify a position or a rule, not both')
mock = MagicMock(return_value=True)
with patch.dict(iptables.__salt__, {'cmd.run': mock}):
self.assertTrue(iptables.delete(table='filter', chain='INPUT', position=3, rule='', family='ipv4'))
|
'Test if it flush the chain in the specified table,
flush all chains in the specified table if not specified chain.'
| def test_flush(self):
| with patch.object(iptables, '_has_option', MagicMock(return_value=True)):
mock_cmd = MagicMock(return_value=True)
with patch.dict(iptables.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(iptables.flush(table='filter', chain='INPUT', family='ipv4'))
|
'Test for Add a virtual service.'
| def test_add_service(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.add_service(), 'stderr')
|
'Test for Edit the virtual service.'
| def test_edit_service(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.edit_service(), 'stderr')
|
'Test for Delete the virtual service.'
| def test_delete_service(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.delete_service(), 'stderr')
|
'Test for Add a real server to a virtual service.'
| def test_add_server(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.add_server(), 'stderr')
|
'Test for Edit a real server to a virtual service.'
| def test_edit_server(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.edit_server(), 'stderr')
|
'Test for Delete the realserver from the virtual service.'
| def test_delete_server(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.delete_server(), 'stderr')
|
'Test for Clear the virtual server table'
| def test_clear(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.clear(), 'stderr')
|
'Test for Get the virtual server rules'
| def test_get_rules(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.dict(lvs.__salt__, {'cmd.run': MagicMock(return_value='A')}):
self.assertEqual(lvs.get_rules(), 'A')
|
'Test for List the virtual server table'
| def test_list_(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.list_('p', 's'), 'stderr')
|
'Test for Zero the packet, byte and rate counters in a
service or all services.'
| def test_zero(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
self.assertEqual(lvs.zero('p', 's'), 'stderr')
|
'Test for Check the virtual service exists.'
| def test_check_service(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
with patch.object(lvs, 'get_rules', return_value='C'):
self.assertEqual(lvs.check_service('p', 's'), 'Error: service not exists')
|
'Test for Check the real server exists in the specified service.'
| def test_check_server(self):
| with patch.object(lvs, '__detect_os', return_value='C'):
with patch.object(lvs, '_build_cmd', return_value='B'):
with patch.dict(lvs.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 'ret', 'stderr': 'stderr'})}):
with patch.object(lvs, 'get_rules', return_value='C'):
self.assertEqual(lvs.check_server('p', 's'), 'Error: server not exists')
|
'Test if the specific Site symlink is enabled.'
| def test_check_site_enabled(self):
| with patch('os.path.islink', MagicMock(return_value=True)):
self.assertTrue(deb_apache.check_site_enabled('saltstack.com'))
|
'Test if the specific Site symlink is enabled.'
| def test_check_site_enabled_default(self):
| with patch('os.path.islink', MagicMock(side_effect=[False, True])):
self.assertTrue(deb_apache.check_site_enabled('default'))
|
'Test if the specific Site symlink is enabled.'
| def test_check_site_enabled_false(self):
| with patch('os.path.islink', MagicMock(return_value=False)):
self.assertFalse(deb_apache.check_site_enabled('saltstack.com'))
|
'Test if it runs a2ensite for the given site.'
| def test_a2ensite_notfound(self):
| mock = MagicMock(return_value=1)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2ensite('saltstack.com'), {'Name': 'Apache2 Enable Site', 'Site': 'saltstack.com', 'Status': 'Site saltstack.com Not found'})
|
'Test if it runs a2ensite for the given site.'
| def test_a2ensite_enabled(self):
| mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2ensite('saltstack.com'), {'Name': 'Apache2 Enable Site', 'Site': 'saltstack.com', 'Status': 'Site saltstack.com enabled'})
|
'Test if it runs a2ensite for the given site.'
| def test_a2ensite(self):
| mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2ensite('saltstack.com'), {'Name': 'Apache2 Enable Site', 'Site': 'saltstack.com', 'Status': 2})
|
'Test if it runs a2ensite for the given site.'
| def test_a2ensite_exception(self):
| mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2ensite('saltstack.com')), 'error')
|
'Test if it runs a2dissite for the given site.'
| def test_a2dissite_notfound(self):
| mock = MagicMock(return_value=256)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dissite('saltstack.com'), {'Name': 'Apache2 Disable Site', 'Site': 'saltstack.com', 'Status': 'Site saltstack.com Not found'})
|
'Test if it runs a2dissite for the given site.'
| def test_a2dissite_disabled(self):
| mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dissite('saltstack.com'), {'Name': 'Apache2 Disable Site', 'Site': 'saltstack.com', 'Status': 'Site saltstack.com disabled'})
|
'Test if it runs a2dissite for the given site.'
| def test_a2dissite(self):
| mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dissite('saltstack.com'), {'Name': 'Apache2 Disable Site', 'Site': 'saltstack.com', 'Status': 2})
|
'Test if it runs a2dissite for the given site.'
| def test_a2dissite_exception(self):
| mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2dissite('saltstack.com')), 'error')
|
'Test if the specific mod symlink is enabled.'
| def test_check_mod_enabled(self):
| with patch('os.path.islink', MagicMock(return_value=True)):
self.assertTrue(deb_apache.check_mod_enabled('status.conf'))
|
'Test if the specific mod symlink is enabled.'
| def test_check_mod_enabled_false(self):
| with patch('os.path.islink', MagicMock(return_value=False)):
self.assertFalse(deb_apache.check_mod_enabled('status.conf'))
|
'Test if it runs a2enmod for the given module.'
| def test_a2enmod_notfound(self):
| mock = MagicMock(return_value=1)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enmod('vhost_alias'), {'Name': 'Apache2 Enable Mod', 'Mod': 'vhost_alias', 'Status': 'Mod vhost_alias Not found'})
|
'Test if it runs a2enmod for the given module.'
| def test_a2enmod_enabled(self):
| mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enmod('vhost_alias'), {'Name': 'Apache2 Enable Mod', 'Mod': 'vhost_alias', 'Status': 'Mod vhost_alias enabled'})
|
'Test if it runs a2enmod for the given module.'
| def test_a2enmod(self):
| mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enmod('vhost_alias'), {'Name': 'Apache2 Enable Mod', 'Mod': 'vhost_alias', 'Status': 2})
|
'Test if it runs a2enmod for the given module.'
| def test_a2enmod_exception(self):
| mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2enmod('vhost_alias')), 'error')
|
'Test if it runs a2dismod for the given module.'
| def test_a2dismod_notfound(self):
| mock = MagicMock(return_value=256)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dismod('vhost_alias'), {'Name': 'Apache2 Disable Mod', 'Mod': 'vhost_alias', 'Status': 'Mod vhost_alias Not found'})
|
'Test if it runs a2dismod for the given module.'
| def test_a2dismod_disabled(self):
| mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dismod('vhost_alias'), {'Name': 'Apache2 Disable Mod', 'Mod': 'vhost_alias', 'Status': 'Mod vhost_alias disabled'})
|
'Test if it runs a2dismod for the given module.'
| def test_a2dismod(self):
| mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2dismod('vhost_alias'), {'Name': 'Apache2 Disable Mod', 'Mod': 'vhost_alias', 'Status': 2})
|
'Test if it runs a2dismod for the given module.'
| def test_a2dismod_exception(self):
| mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2dismod('vhost_alias')), 'error')
|
'Test if the specific conf symlink is enabled.'
| def test_check_conf_enabled(self):
| with patch('os.path.islink', MagicMock(return_value=True)):
self.assertTrue(deb_apache.check_conf_enabled('security.conf'))
|
'Test if the specific conf symlink is enabled.'
| def test_check_conf_enabled_false(self):
| with patch('os.path.islink', MagicMock(return_value=False)):
self.assertFalse(deb_apache.check_conf_enabled('security.conf'))
|
'Test if it runs a2enconf for the given conf.'
| def test_a2enconf_notfound(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2enconf')):
mock = MagicMock(return_value=1)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enconf('security'), {'Name': 'Apache2 Enable Conf', 'Conf': 'security', 'Status': 'Conf security Not found'})
|
'Test if it runs a2enconf for the given conf.'
| def test_a2enconf_enabled(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2enconf')):
mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enconf('security'), {'Name': 'Apache2 Enable Conf', 'Conf': 'security', 'Status': 'Conf security enabled'})
|
'Test if it runs a2enconf for the given conf.'
| def test_a2enconf(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2enconf')):
mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2enconf('security'), {'Name': 'Apache2 Enable Conf', 'Conf': 'security', 'Status': 2})
|
'Test if it runs a2enconf for the given conf.'
| def test_a2enconf_exception(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2enconf')):
mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2enconf('security')), 'error')
|
'Test if it runs a2disconf for the given conf.'
| def test_a2disconf_notfound(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2disconf')):
mock = MagicMock(return_value=256)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2disconf('security'), {'Name': 'Apache2 Disable Conf', 'Conf': 'security', 'Status': 'Conf security Not found'})
|
'Test if it runs a2disconf for the given conf.'
| def test_a2disconf_disabled(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2disconf')):
mock = MagicMock(return_value=0)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2disconf('security'), {'Name': 'Apache2 Disable Conf', 'Conf': 'security', 'Status': 'Conf security disabled'})
|
'Test if it runs a2disconf for the given conf.'
| def test_a2disconf(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2disconf')):
mock = MagicMock(return_value=2)
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(deb_apache.a2disconf('security'), {'Name': 'Apache2 Disable Conf', 'Conf': 'security', 'Status': 2})
|
'Test if it runs a2disconf for the given conf.'
| def test_a2disconf_exception(self):
| with patch('salt.utils.path.which', MagicMock(return_value='a2disconf')):
mock = MagicMock(side_effect=Exception('error'))
with patch.dict(deb_apache.__salt__, {'cmd.retcode': mock}):
self.assertEqual(str(deb_apache.a2disconf('security')), 'error')
|
'Test if it determine which packages own the currently running services.'
| def test_running_service_owners(self):
| err1 = 'The module for the package manager on this system does not support looking up which package(s) owns which file(s)'
err2 = 'The file module on this system does not support looking up open files on the system'
ret = {'Error': {'Unsupported File Module': '{0}'.format(err2), 'Unsupported Package Manager': '{0}'.format(err1)}}
self.assertDictEqual(introspect.running_service_owners(), ret)
mock = MagicMock(return_value={})
with patch.dict(introspect.__salt__, {'pkg.owner': mock, 'file.open_files': mock, 'service.execs': mock}):
self.assertDictEqual(introspect.running_service_owners(), {})
|
'Test if it return which packages own each of the services
that are currently enabled.'
| def test_enabled_service_owners(self):
| err1 = 'The module for the package manager on this system does not support looking up which package(s) owns which file(s)'
err2 = 'The module for the service manager on this system does not support showing descriptive service data'
ret = {'Error': {'Unsupported Service Manager': '{0}'.format(err2), 'Unsupported Package Manager': '{0}'.format(err1)}}
self.assertDictEqual(introspect.enabled_service_owners(), ret)
mock = MagicMock(return_value={})
with patch.dict(introspect.__salt__, {'pkg.owner': mock, 'service.show': mock, 'service.get_enabled': mock}):
self.assertDictEqual(introspect.enabled_service_owners(), {})
|
'Test if it return running and enabled services in a highstate structure.'
| def test_service_highstate(self):
| with patch('salt.modules.introspect.running_service_owners', MagicMock(return_value={})):
with patch('salt.modules.introspect.enabled_service_owners', MagicMock(return_value={})):
self.assertDictEqual(introspect.service_highstate(), {})
|
'Mock gen_token method'
| def gen_token(self, tok):
| self.tok = tok
return 'salt_tok'
|
'Mock factory method'
| def factory(self, tok):
| self.tok = tok
return Channel()
|
'Mock send method'
| def send(self, load):
| self.load = load
if (self.flag == 1):
raise SaltReqTimeoutError
return True
|
'Test if it publish a command from the minion out to other minions.'
| def test_publish(self):
| self.assertDictEqual(publish.publish('os:Fedora', 'publish.salt'), {})
|
'Test if it return the full data about the publication'
| def test_full_data(self):
| self.assertDictEqual(publish.publish('*', 'publish.salt'), {})
|
'Test if it execute a runner on the master and return the data
from the runner function'
| def test_runner(self):
| ret = 'No access to master. If using salt-call with --local, please remove.'
self.assertEqual(publish.runner('manage.down'), ret)
mock = MagicMock(return_value=True)
mock_id = MagicMock(return_value='salt_id')
with patch.dict(publish.__opts__, {'master_uri': mock, 'id': mock_id}):
Channel.flag = 0
self.assertTrue(publish.runner('manage.down'))
Channel.flag = 1
self.assertEqual(publish.runner('manage.down'), "'manage.down' runner publish timed out")
|
'Test to make sure that we correctly get the current proxy info
on macOS'
| def test_get_http_proxy_macos(self):
| mock = MagicMock(return_value='Enabled: Yes\nServer: 192.168.0.1\nPort: 3128\nAuthenticated Proxy Enabled: 0')
expected = {'enabled': True, 'server': '192.168.0.1', 'port': '3128'}
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.get_http_proxy()
mock.assert_called_once_with('networksetup -getwebproxy Ethernet')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly get the current proxy info
on macOS'
| def test_get_https_proxy_macos(self):
| mock = MagicMock(return_value='Enabled: Yes\nServer: 192.168.0.1\nPort: 3128\nAuthenticated Proxy Enabled: 0')
expected = {'enabled': True, 'server': '192.168.0.1', 'port': '3128'}
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.get_https_proxy()
mock.assert_called_once_with('networksetup -getsecurewebproxy Ethernet')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly get the current proxy info
on macOS'
| def test_get_ftp_proxy_macos(self):
| mock = MagicMock(return_value='Enabled: Yes\nServer: 192.168.0.1\nPort: 3128\nAuthenticated Proxy Enabled: 0')
expected = {'enabled': True, 'server': '192.168.0.1', 'port': '3128'}
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.get_ftp_proxy()
mock.assert_called_once_with('networksetup -getftpproxy Ethernet')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly return when theres no proxy set'
| def test_get_http_proxy_macos_none(self):
| mock = MagicMock(return_value='Enabled: No\nServer:\nPort: 0\nAuthenticated Proxy Enabled: 0')
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.get_http_proxy()
mock.assert_called_once_with('networksetup -getwebproxy Ethernet')
self.assertEqual({}, out)
|
'Test to make sure that we correctly set the proxy info
on macOS'
| def test_set_http_proxy_macos(self):
| mock = MagicMock()
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.set_http_proxy('192.168.0.1', 3128, 'frank', 'badpassw0rd', bypass_hosts='.moo.com,.salt.com')
mock.assert_called_once_with('networksetup -setwebproxy Ethernet 192.168.0.1 3128 On frank badpassw0rd')
self.assertTrue(out)
|
'Test to make sure that we correctly set the proxy info
on macOS'
| def test_set_https_proxy_macos(self):
| mock = MagicMock()
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.set_https_proxy('192.168.0.1', 3128, 'frank', 'passw0rd', bypass_hosts='.moo.com,.salt.com')
mock.assert_called_once_with('networksetup -setsecurewebproxy Ethernet 192.168.0.1 3128 On frank passw0rd')
self.assertTrue(out)
|
'Test to make sure that we correctly set the proxy info
on macOS'
| def test_set_ftp_proxy_macos(self):
| mock = MagicMock()
with patch.dict(proxy.__salt__, {'cmd.run': mock}):
out = proxy.set_ftp_proxy('192.168.0.1', 3128, 'frank', 'badpassw0rd', bypass_hosts='.moo.com,.salt.com')
mock.assert_called_once_with('networksetup -setftpproxy Ethernet 192.168.0.1 3128 On frank badpassw0rd')
self.assertTrue(out)
|
'Test to make sure that we correctly get the current proxy info
on Windows'
| def test_get_http_proxy_windows(self):
| with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.1', 'port': '3128'}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_http_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly get the current proxy info
on Windows'
| def test_get_https_proxy_windows(self):
| with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.2', 'port': '3128'}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_https_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly get the current proxy info
on Windows'
| def test_get_ftp_proxy_windows(self):
| with patch.dict(proxy.__grains__, {'os': 'Windows'}):
result = {'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}
mock = MagicMock(return_value=result)
expected = {'server': '192.168.0.3', 'port': '3128'}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_ftp_proxy()
mock.assert_called_once_with('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer')
self.assertEqual(expected, out)
|
'Test to make sure that we correctly get the current proxy info
on Windows'
| def test_get_all_proxies_windows(self):
| with patch.dict(proxy.__grains__, {'os': 'Windows'}):
results = [{'vdata': 'http=192.168.0.1:3128;https=192.168.0.2:3128;ftp=192.168.0.3:3128'}, {'vdata': 1}]
mock = MagicMock(side_effect=results)
expected = {'enabled': True, 'http': {'server': '192.168.0.1', 'port': '3128'}, 'https': {'server': '192.168.0.2', 'port': '3128'}, 'ftp': {'server': '192.168.0.3', 'port': '3128'}}
with patch.dict(proxy.__salt__, {'reg.read_value': mock}):
out = proxy.get_proxy_win()
calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable')]
mock.assert_has_calls(calls)
self.assertEqual(expected, out)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.