desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test for Suspend an instance'
| def test_suspend(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'suspend', MagicMock(return_value='A')):
self.assertTrue(nova.suspend('instance_id'))
|
'Test for Resume an instance'
| def test_resume(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'resume', MagicMock(return_value='A')):
self.assertTrue(nova.resume('instance_id'))
|
'Test for Lock an instance'
| def test_lock(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'lock', MagicMock(return_value='A')):
self.assertTrue(nova.lock('instance_id'))
|
'Test for Delete an instance'
| def test_delete(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'delete', MagicMock(return_value='A')):
self.assertTrue(nova.delete('instance_id'))
|
'Test for Return a list of available flavors (nova flavor-list)'
| def test_flavor_list(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'flavor_list', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_list())
|
'Test for Add a flavor to nova (nova flavor-create)'
| def test_flavor_create(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'flavor_create', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_create('name'))
|
'Test for Delete a flavor from nova by id (nova flavor-delete)'
| def test_flavor_delete(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'flavor_delete', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_delete('flavor_id'))
|
'Test for Return a list of available keypairs (nova keypair-list)'
| def test_keypair_list(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'keypair_list', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_list())
|
'Test for Add a keypair to nova (nova keypair-add)'
| def test_keypair_add(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'keypair_add', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_add('name'))
|
'Test for Add a keypair to nova (nova keypair-delete)'
| def test_keypair_delete(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'keypair_delete', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_delete('name'))
|
'Test for Return a list of available images
(nova images-list + nova image-show)'
| def test_image_list(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'image_list', MagicMock(return_value='A')):
self.assertTrue(nova.image_list())
|
'Test for Sets a key=value pair in the
metadata for an image (nova image-meta set)'
| def test_image_meta_set(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'image_meta_set', MagicMock(return_value='A')):
self.assertTrue(nova.image_meta_set())
|
'Test for Delete a key=value pair from the metadata for an image
(nova image-meta set)'
| def test_image_meta_delete(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'image_meta_delete', MagicMock(return_value='A')):
self.assertTrue(nova.image_meta_delete())
|
'Test for To maintain the feel of the nova command line,
this function simply calls
the server_list function.'
| def test_list_(self):
| with patch.object(nova, 'server_list', return_value=['A']):
self.assertEqual(nova.list_(), ['A'])
|
'Test for Return list of active servers'
| def test_server_list(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'server_list', MagicMock(return_value='A')):
self.assertTrue(nova.server_list())
|
'Test for To maintain the feel of the nova command line,
this function simply calls
the server_show function.'
| def test_show(self):
| with patch.object(nova, 'server_show', return_value=['A']):
self.assertEqual(nova.show('server_id'), ['A'])
|
'Test for Return detailed list of active servers'
| def test_server_list_detailed(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'server_list_detailed', MagicMock(return_value='A')):
self.assertTrue(nova.server_list_detailed())
|
'Test for Return detailed information for an active server'
| def test_server_show(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'server_show', MagicMock(return_value='A')):
self.assertTrue(nova.server_show('serv_id'))
|
'Test for Add a secgroup to nova (nova secgroup-create)'
| def test_secgroup_create(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'server_list_detailed', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_create('name', 'desc'))
|
'Test for Delete a secgroup to nova (nova secgroup-delete)'
| def test_secgroup_delete(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'secgroup_delete', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_delete('name'))
|
'Test for Return a list of available security groups (nova items-list)'
| def test_secgroup_list(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'secgroup_list', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_list())
|
'Test for Return information about a server'
| def test_server_by_name(self):
| self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth, 'server_by_name', MagicMock(return_value='A')):
self.assertTrue(nova.server_by_name('name'))
|
'Test if it shows global_settings'
| def test_global_settings(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Global Settings': {}})):
self.assertDictEqual(ilo.global_settings(), {'Global Settings': {}})
|
'Test if it configure the port HTTP should listen on'
| def test_set_http_port(self):
| with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'HTTP_PORT': {'VALUE': 80}}}):
self.assertTrue(ilo.set_http_port())
with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'HTTP_PORT': {'VALUE': 40}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Set HTTP Port': {}}):
self.assertDictEqual(ilo.set_http_port(), {'Set HTTP Port': {}})
|
'Test if it configure the port HTTPS should listen on'
| def test_set_https_port(self):
| with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'HTTP_PORT': {'VALUE': 443}}}):
self.assertTrue(ilo.set_https_port())
with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'HTTP_PORT': {'VALUE': 80}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Set HTTPS Port': {}}):
self.assertDictEqual(ilo.set_https_port(), {'Set HTTPS Port': {}})
|
'Test if it enable the SSH daemon'
| def test_enable_ssh(self):
| with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_STATUS': {'VALUE': 'Y'}}}):
self.assertTrue(ilo.enable_ssh())
with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_STATUS': {'VALUE': 'N'}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Enable SSH': {}}):
self.assertDictEqual(ilo.enable_ssh(), {'Enable SSH': {}})
|
'Test if it disable the SSH daemon'
| def test_disable_ssh(self):
| with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_STATUS': {'VALUE': 'N'}}}):
self.assertTrue(ilo.disable_ssh())
with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_STATUS': {'VALUE': 'Y'}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Disable SSH': {}}):
self.assertDictEqual(ilo.disable_ssh(), {'Disable SSH': {}})
|
'Test if it enable SSH on a user defined port'
| def test_set_ssh_port(self):
| with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_PORT': {'VALUE': 22}}}):
self.assertTrue(ilo.set_ssh_port())
with patch.object(ilo, 'global_settings', return_value={'Global Settings': {'SSH_PORT': {'VALUE': 20}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Configure SSH Port': {}}):
self.assertDictEqual(ilo.set_ssh_port(), {'Configure SSH Port': {}})
|
'Test if it configure SSH public keys for specific users'
| def test_set_ssh_key(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Import SSH Publickey': {}})):
self.assertDictEqual(ilo.set_ssh_key('ssh-rsa AAAAB3Nza Salt'), {'Import SSH Publickey': {}})
|
'Test if it delete a users SSH key from the ILO'
| def test_delete_ssh_key(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Delete user SSH key': {}})):
self.assertDictEqual(ilo.delete_ssh_key('Salt'), {'Delete user SSH key': {}})
|
'Test if it list all users'
| def test_list_users(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'All users': {}})):
self.assertDictEqual(ilo.list_users(), {'All users': {}})
|
'Test if it List all users in detail'
| def test_list_users_info(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'All users info': {}})):
self.assertDictEqual(ilo.list_users_info(), {'All users info': {}})
|
'Test if it create user'
| def test_create_user(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Create user': {}})):
self.assertDictEqual(ilo.create_user('Salt', 'secretagent', 'VIRTUAL_MEDIA_PRIV'), {'Create user': {}})
|
'Test if it delete a user'
| def test_delete_user(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Delete user': {}})):
self.assertDictEqual(ilo.delete_user('Salt'), {'Delete user': {}})
|
'Test if it returns local user information, excluding the password'
| def test_get_user(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'User Info': {}})):
self.assertDictEqual(ilo.get_user('Salt'), {'User Info': {}})
|
'Test if it change a username'
| def test_change_username(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Change username': {}})):
self.assertDictEqual(ilo.change_username('Salt', 'SALT'), {'Change username': {}})
|
'Test if it reset a users password'
| def test_change_password(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Change password': {}})):
self.assertDictEqual(ilo.change_password('Salt', 'saltpasswd'), {'Change password': {}})
|
'Test if it grab the current network settings'
| def test_network(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Network Settings': {}})):
self.assertDictEqual(ilo.network(), {'Network Settings': {}})
|
'Test if it configure Network Interface'
| def test_configure_network(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Configure_Network': {}})):
ret = {'Network Settings': {'IP_ADDRESS': {'VALUE': '10.0.0.10'}, 'SUBNET_MASK': {'VALUE': '255.255.255.0'}, 'GATEWAY_IP_ADDRESS': {'VALUE': '10.0.0.1'}}}
with patch.object(ilo, 'network', return_value=ret):
self.assertTrue(ilo.configure_network('10.0.0.10', '255.255.255.0', '10.0.0.1'))
with patch.object(ilo, 'network', return_value=ret):
with patch.object(ilo, '__execute_cmd', return_value={'Network Settings': {}}):
self.assertDictEqual(ilo.configure_network('10.0.0.100', '255.255.255.10', '10.0.0.10'), {'Network Settings': {}})
|
'Test if it enable DHCP'
| def test_enable_dhcp(self):
| with patch.object(ilo, 'network', return_value={'Network Settings': {'DHCP_ENABLE': {'VALUE': 'Y'}}}):
self.assertTrue(ilo.enable_dhcp())
with patch.object(ilo, 'network', return_value={'Network Settings': {'DHCP_ENABLE': {'VALUE': 'N'}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Enable DHCP': {}}):
self.assertDictEqual(ilo.enable_dhcp(), {'Enable DHCP': {}})
|
'Test if it disable DHCP'
| def test_disable_dhcp(self):
| with patch.object(ilo, 'network', return_value={'Network Settings': {'DHCP_ENABLE': {'VALUE': 'N'}}}):
self.assertTrue(ilo.disable_dhcp())
with patch.object(ilo, 'network', return_value={'Network Settings': {'DHCP_ENABLE': {'VALUE': 'Y'}}}):
with patch.object(ilo, '__execute_cmd', return_value={'Disable DHCP': {}}):
self.assertDictEqual(ilo.disable_dhcp(), {'Disable DHCP': {}})
|
'Test if it configure SNMP'
| def test_configure_snmp(self):
| with patch('salt.modules.ilo.__execute_cmd', MagicMock(return_value={'Configure SNMP': {}})):
self.assertDictEqual(ilo.configure_snmp('Salt'), {'Configure SNMP': {}})
|
'Test for Encodes a value with the specified encoder.'
| def test_hash(self):
| self.assertEqual(mod_random.hash('value')[0:4], 'ec2c')
self.assertRaises(SaltInvocationError, mod_random.hash, 'value', 'algorithm')
|
'Test for The value to be encoded.'
| def test_str_encode(self):
| self.assertRaises(SaltInvocationError, mod_random.str_encode, 'None', 'abc')
self.assertRaises(SaltInvocationError, mod_random.str_encode, None)
if six.PY2:
self.assertEqual(mod_random.str_encode('A'), 'QQ==\n')
else:
self.assertEqual(mod_random.str_encode('A'), 'QQ==')
|
'Test for Returns a random string of the specified length.'
| def test_get_str(self):
| with patch.object(salt.utils.pycrypto, 'secure_password', return_value='A'):
self.assertEqual(mod_random.get_str(), 'A')
|
'Test for Generates a salted hash suitable for /etc/shadow.'
| def test_shadow_hash(self):
| with patch.object(salt.utils.pycrypto, 'gen_hash', return_value='A'):
self.assertEqual(mod_random.shadow_hash(), 'A')
|
'Mock Com method'
| @staticmethod
def Com():
| return True
|
'Test if it return a list of the configured DNS servers
of the specified interface.'
| def test_get_dns_servers(self):
| with patch('salt.utils', Mockwinapi):
with patch('salt.utils.winapi.Com', MagicMock()):
with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]):
with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]):
self.assertListEqual(win_dns_client.get_dns_servers('Local Area Connection'), ['10.1.1.10'])
self.assertFalse(win_dns_client.get_dns_servers('Ethernet'))
|
'Test if it remove the DNS server from the network interface.'
| def test_rm_dns(self):
| with patch.dict(win_dns_client.__salt__, {'cmd.retcode': MagicMock(return_value=0)}):
self.assertTrue(win_dns_client.rm_dns('10.1.1.10'))
|
'Test if it add the DNS server to the network interface.'
| def test_add_dns(self):
| with patch('salt.utils.winapi.Com', MagicMock()):
with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]):
with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]):
self.assertFalse(win_dns_client.add_dns('10.1.1.10', 'Ethernet'))
self.assertTrue(win_dns_client.add_dns('10.1.1.10', 'Local Area Connection'))
with patch.object(win_dns_client, 'get_dns_servers', MagicMock(return_value=['10.1.1.10'])):
with patch.dict(win_dns_client.__salt__, {'cmd.retcode': MagicMock(return_value=0)}):
self.assertTrue(win_dns_client.add_dns('10.1.1.0', 'Local Area Connection'))
|
'Test if it configure the interface to get its
DNS servers from the DHCP server'
| def test_dns_dhcp(self):
| with patch.dict(win_dns_client.__salt__, {'cmd.retcode': MagicMock(return_value=0)}):
self.assertTrue(win_dns_client.dns_dhcp())
|
'Test if it get the type of DNS configuration (dhcp / static)'
| def test_get_dns_config(self):
| with patch('salt.utils.winapi.Com', MagicMock()):
with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]):
with patch.object(self.WMI, 'Win32_NetworkAdapterConfiguration', return_value=[Mockwmi()]):
self.assertTrue(win_dns_client.get_dns_config())
|
'List the active mounts.'
| def test_active(self):
| with patch.dict(mount.__grains__, {'os': 'FreeBSD', 'kernel': 'FreeBSD'}):
mock = MagicMock(return_value='A B C D,E,F,uid=user1,gid=grp1')
mock_user = MagicMock(return_value={'uid': '100'})
mock_group = MagicMock(return_value={'gid': '100'})
with patch.dict(mount.__salt__, {'cmd.run_stdout': mock, 'user.info': mock_user, 'group.info': mock_group}):
self.assertEqual(mount.active(), {'B': {'device': 'A', 'opts': ['D', 'E', 'F', 'uid=100', 'gid=100'], 'fstype': 'C'}})
with patch.dict(mount.__grains__, {'os': 'Solaris', 'kernel': 'SunOS'}):
mock = MagicMock(return_value='A * B * C D/E/F')
with patch.dict(mount.__salt__, {'cmd.run_stdout': mock}):
self.assertEqual(mount.active(), {'B': {'device': 'A', 'opts': ['D', 'E', 'F'], 'fstype': 'C'}})
with patch.dict(mount.__grains__, {'os': 'OpenBSD', 'kernel': 'OpenBSD'}):
mock = MagicMock(return_value={})
with patch.object(mount, '_active_mounts_openbsd', mock):
self.assertEqual(mount.active(), {})
with patch.dict(mount.__grains__, {'os': 'MacOS', 'kernel': 'Darwin'}):
mock = MagicMock(return_value={})
with patch.object(mount, '_active_mounts_darwin', mock):
self.assertEqual(mount.active(), {})
with patch.dict(mount.__grains__, {'os': 'MacOS', 'kernel': 'Darwin'}):
mock = MagicMock(return_value={})
with patch.object(mount, '_active_mountinfo', mock):
with patch.object(mount, '_active_mounts_darwin', mock):
self.assertEqual(mount.active(extended=True), {})
|
'List the content of the fstab'
| def test_fstab(self):
| mock = MagicMock(return_value=False)
with patch.object(os.path, 'isfile', mock):
self.assertEqual(mount.fstab(), {})
mock = MagicMock(return_value=True)
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(os.path, 'isfile', mock):
file_data = '\n'.join(['#', 'A B C D,E,F G H'])
with patch('salt.utils.files.fopen', mock_open(read_data=file_data), create=True) as m:
m.return_value.__iter__.return_value = file_data.splitlines()
self.assertEqual(mount.fstab(), {'B': {'device': 'A', 'dump': 'G', 'fstype': 'C', 'opts': ['D', 'E', 'F'], 'pass': 'H'}})
|
'List the content of the vfstab'
| def test_vfstab(self):
| mock = MagicMock(return_value=False)
with patch.object(os.path, 'isfile', mock):
self.assertEqual(mount.vfstab(), {})
mock = MagicMock(return_value=True)
with patch.dict(mount.__grains__, {'kernel': 'SunOS'}):
with patch.object(os.path, 'isfile', mock):
file_data = '\n'.join(['#', 'swap - /tmp tmpfs - yes size=2048m'])
with patch('salt.utils.files.fopen', mock_open(read_data=file_data), create=True) as m:
m.return_value.__iter__.return_value = file_data.splitlines()
self.assertEqual(mount.fstab(), {'/tmp': {'device': 'swap', 'device_fsck': '-', 'fstype': 'tmpfs', 'mount_at_boot': 'yes', 'opts': ['size=2048m'], 'pass_fsck': '-'}})
|
'Remove the mount point from the fstab'
| def test_rm_fstab(self):
| mock_fstab = MagicMock(return_value={})
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'fstab', mock_fstab):
with patch('salt.utils.files.fopen', mock_open()):
self.assertTrue(mount.rm_fstab('name', 'device'))
|
'Tests to verify that this mount is represented in the fstab,
change the mount to match the data passed, or add the mount
if it is not present.'
| def test_set_fstab(self):
| mock = MagicMock(return_value=False)
with patch.object(os.path, 'isfile', mock):
self.assertRaises(CommandExecutionError, mount.set_fstab, 'A', 'B', 'C')
mock = MagicMock(return_value=True)
mock_read = MagicMock(side_effect=OSError)
with patch.object(os.path, 'isfile', mock):
with patch.object(salt.utils.files, 'fopen', mock_read):
self.assertRaises(CommandExecutionError, mount.set_fstab, 'A', 'B', 'C')
mock = MagicMock(return_value=True)
with patch.object(os.path, 'isfile', mock):
with patch('salt.utils.files.fopen', mock_open(read_data=MOCK_SHELL_FILE)):
self.assertEqual(mount.set_fstab('A', 'B', 'C'), 'new')
|
'Remove the mount point from the auto_master'
| def test_rm_automaster(self):
| mock = MagicMock(return_value={})
with patch.object(mount, 'automaster', mock):
self.assertTrue(mount.rm_automaster('name', 'device'))
mock = MagicMock(return_value={'name': 'name'})
with patch.object(mount, 'fstab', mock):
self.assertTrue(mount.rm_automaster('name', 'device'))
|
'Verify that this mount is represented in the auto_salt, change the mount
to match the data passed, or add the mount if it is not present.'
| def test_set_automaster(self):
| mock = MagicMock(return_value=True)
with patch.object(os.path, 'isfile', mock):
self.assertRaises(CommandExecutionError, mount.set_automaster, 'A', 'B', 'C')
|
'Test the list the contents of the fstab'
| def test_automaster(self):
| self.assertDictEqual(mount.automaster(), {})
|
'Mount a device'
| def test_mount(self):
| with patch.dict(mount.__grains__, {'os': 'MacOS'}):
mock = MagicMock(return_value=True)
with patch.object(os.path, 'exists', mock):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'file.mkdir': None}):
mock = MagicMock(return_value={'retcode': True, 'stderr': True})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))
mock = MagicMock(return_value={'retcode': False, 'stderr': False})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.mount('name', 'device'))
|
'Attempt to remount a device, if the device is not already mounted, mount
is called'
| def test_remount(self):
| with patch.dict(mount.__grains__, {'os': 'MacOS'}):
mock = MagicMock(return_value=[])
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value=True)
with patch.object(mount, 'mount', mock):
self.assertTrue(mount.remount('name', 'device'))
|
'Attempt to unmount a device by specifying the directory it is
mounted on'
| def test_umount(self):
| mock = MagicMock(return_value={})
with patch.object(mount, 'active', mock):
self.assertEqual(mount.umount('name'), 'name does not have anything mounted')
mock = MagicMock(return_value={'name': 'name'})
with patch.object(mount, 'active', mock):
mock = MagicMock(return_value={'retcode': True, 'stderr': True})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.umount('name'))
mock = MagicMock(return_value={'retcode': False})
with patch.dict(mount.__salt__, {'cmd.run_all': mock}):
self.assertTrue(mount.umount('name'))
|
'Returns true if the command passed is a fuse mountable application'
| def test_is_fuse_exec(self):
| with patch.object(salt.utils.path, 'which', return_value=None):
self.assertFalse(mount.is_fuse_exec('cmd'))
def _ldd_side_effect(cmd, *args, **kwargs):
"\n Neither of these are full ldd output, but what is_fuse_exec is\n looking for is 'libfuse' in the ldd output, so these examples\n should be sufficient enough to test both the True and False cases.\n "
return {'ldd cmd1': textwrap.dedent(' linux-vdso.so.1 (0x00007ffeaf5fb000)\n libfuse3.so.3 => /usr/lib/libfuse3.so.3 (0x00007f91e66ac000)\n '), 'ldd cmd2': textwrap.dedent(' linux-vdso.so.1 (0x00007ffeaf5fb000)\n ')}[cmd]
which_mock = MagicMock(side_effect=(lambda x: x))
ldd_mock = MagicMock(side_effect=_ldd_side_effect)
with patch.object(salt.utils.path, 'which', which_mock):
with patch.dict(mount.__salt__, {'cmd.run': _ldd_side_effect}):
self.assertTrue(mount.is_fuse_exec('cmd1'))
self.assertFalse(mount.is_fuse_exec('cmd2'))
|
'Return a dict containing information on active swap'
| def test_swaps(self):
| file_data = '\n'.join(['Filename Type Size Used Priority', '/dev/sda1 partition 31249404 4100 -1'])
with patch.dict(mount.__grains__, {'os': '', 'kernel': ''}):
with patch('salt.utils.files.fopen', mock_open(read_data=file_data), create=True) as m:
m.return_value.__iter__.return_value = file_data.splitlines()
self.assertDictEqual(mount.swaps(), {'/dev/sda1': {'priority': '-1', 'size': '31249404', 'type': 'partition', 'used': '4100'}})
file_data = '\n'.join(['Device Size Used Unknown Unknown Priority', '/dev/sda1 31249404 4100 unknown unknown -1'])
mock = MagicMock(return_value=file_data)
with patch.dict(mount.__grains__, {'os': 'OpenBSD', 'kernel': 'OpenBSD'}):
with patch.dict(mount.__salt__, {'cmd.run_stdout': mock}):
self.assertDictEqual(mount.swaps(), {'/dev/sda1': {'priority': '-1', 'size': '31249404', 'type': 'partition', 'used': '4100'}})
|
'Activate a swap disk'
| def test_swapon(self):
| mock = MagicMock(return_value={'name': 'name'})
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
self.assertEqual(mount.swapon('name'), {'stats': 'name', 'new': False})
mock = MagicMock(return_value={})
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'cmd.run': mock}):
self.assertEqual(mount.swapon('name', False), {})
mock = MagicMock(side_effect=[{}, {'name': 'name'}])
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'cmd.run': mock}):
self.assertEqual(mount.swapon('name'), {'stats': 'name', 'new': True})
|
'Deactivate a named swap mount'
| def test_swapoff(self):
| mock = MagicMock(return_value={})
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
self.assertEqual(mount.swapoff('name'), None)
mock = MagicMock(return_value={'name': 'name'})
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
with patch.dict(mount.__grains__, {'os': 'test'}):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'cmd.run': mock}):
self.assertFalse(mount.swapoff('name'))
mock = MagicMock(side_effect=[{'name': 'name'}, {}])
with patch.dict(mount.__grains__, {'kernel': ''}):
with patch.object(mount, 'swaps', mock):
with patch.dict(mount.__grains__, {'os': 'test'}):
mock = MagicMock(return_value=None)
with patch.dict(mount.__salt__, {'cmd.run': mock}):
self.assertTrue(mount.swapoff('name'))
|
'Provide information if the path is mounted'
| def test_is_mounted(self):
| mock = MagicMock(return_value={})
with patch.object(mount, 'active', mock):
self.assertFalse(mount.is_mounted('name'))
mock = MagicMock(return_value={'name': 'name'})
with patch.object(mount, 'active', mock):
self.assertTrue(mount.is_mounted('name'))
|
'Test if it list the packages currently installed in a dict'
| def test_list_pkgs(self):
| cmdmock = MagicMock(return_value='A 1.0\nB 2.0')
sortmock = MagicMock()
stringifymock = MagicMock()
mock_ret = {'A': ['1.0'], 'B': ['2.0']}
with patch.dict(pacman.__salt__, {'cmd.run': cmdmock, 'pkg_resource.add_pkg': (lambda pkgs, name, version: pkgs.setdefault(name, []).append(version)), 'pkg_resource.sort_pkglist': sortmock, 'pkg_resource.stringify': stringifymock}):
self.assertDictEqual(pacman.list_pkgs(), mock_ret)
sortmock.assert_called_with(mock_ret)
stringifymock.assert_called_with(mock_ret)
|
'Test if it lists the packages currently installed in a dict'
| def test_list_pkgs_as_list(self):
| cmdmock = MagicMock(return_value='A 1.0\nB 2.0')
sortmock = MagicMock()
stringifymock = MagicMock()
mock_ret = {'A': ['1.0'], 'B': ['2.0']}
with patch.dict(pacman.__salt__, {'cmd.run': cmdmock, 'pkg_resource.add_pkg': (lambda pkgs, name, version: pkgs.setdefault(name, []).append(version)), 'pkg_resource.sort_pkglist': sortmock, 'pkg_resource.stringify': stringifymock}):
self.assertDictEqual(pacman.list_pkgs(True), mock_ret)
sortmock.assert_called_with(mock_ret)
self.assertTrue((stringifymock.call_count == 0))
|
'Test if it lists the available groups'
| def test_group_list(self):
| def cmdlist(cmd, **kwargs):
'\n Handle several different commands being run\n '
if (cmd == ['pacman', '-Sgg']):
return 'group-a pkg1\ngroup-a pkg2\ngroup-f pkg9\ngroup-c pkg3\ngroup-b pkg4'
elif (cmd == ['pacman', '-Qg']):
return 'group-a pkg1\ngroup-b pkg4'
else:
return 'Untested command ({0}, {1})!'.format(cmd, kwargs)
cmdmock = MagicMock(side_effect=cmdlist)
sortmock = MagicMock()
with patch.dict(pacman.__salt__, {'cmd.run': cmdmock, 'pkg_resource.sort_pkglist': sortmock}):
self.assertDictEqual(pacman.group_list(), {'available': ['group-c', 'group-f'], 'installed': ['group-b'], 'partially_installed': ['group-a']})
|
'Test if it shows the packages in a group'
| def test_group_info(self):
| def cmdlist(cmd, **kwargs):
'\n Handle several different commands being run\n '
if (cmd == ['pacman', '-Sgg', 'testgroup']):
return 'testgroup pkg1\ntestgroup pkg2'
else:
return 'Untested command ({0}, {1})!'.format(cmd, kwargs)
cmdmock = MagicMock(side_effect=cmdlist)
sortmock = MagicMock()
with patch.dict(pacman.__salt__, {'cmd.run': cmdmock, 'pkg_resource.sort_pkglist': sortmock}):
self.assertEqual(pacman.group_info('testgroup')['default'], ['pkg1', 'pkg2'])
|
'Test if it shows the difference between installed and target group contents'
| def test_group_diff(self):
| listmock = MagicMock(return_value={'A': ['1.0'], 'B': ['2.0']})
groupmock = MagicMock(return_value={'mandatory': [], 'optional': [], 'default': ['A', 'C'], 'conditional': []})
with patch.dict(pacman.__salt__, {'pkg.list_pkgs': listmock, 'pkg.group_info': groupmock}):
results = pacman.group_diff('testgroup')
self.assertEqual(results['default'], {'installed': ['A'], 'not installed': ['C']})
|
'Define common mock data for status.uptime tests'
| def _set_up_test_uptime(self):
| class MockData(object, ):
'\n Store mock data\n '
m = MockData()
m.now = 1477004312
m.ut = 1540154.0
m.idle = 3047777.32
m.ret = {'users': 3, 'seconds': 1540154, 'since_t': 1475464158, 'days': 17, 'since_iso': '2016-10-03T03:09:18', 'time': '19:49'}
return m
|
'Define common mock data for cmd.run_all for status.uptime on SunOS'
| def _set_up_test_uptime_sunos(self):
| class MockData(object, ):
'\n Store mock data\n '
m = MockData()
m.ret = {'retcode': 0, 'stdout': 'unix:0:system_misc:boot_time 1475464158'}
return m
|
'Test modules.status.uptime function for Linux'
| def test_uptime_linux(self):
| m = self._set_up_test_uptime()
with patch.multiple(salt.utils.platform, is_linux=MagicMock(return_value=True), is_sunos=MagicMock(return_value=False), is_darwin=MagicMock(return_value=False), is_freebsd=MagicMock(return_value=False), is_openbsd=MagicMock(return_value=False), is_netbsd=MagicMock(return_value=False)):
with patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value='1\n2\n3')}):
with patch('time.time', MagicMock(return_value=m.now)):
with patch('os.path.exists', MagicMock(return_value=True)):
proc_uptime = '{0} {1}'.format(m.ut, m.idle)
with patch('salt.utils.files.fopen', mock_open(read_data=proc_uptime)):
ret = status.uptime()
self.assertDictEqual(ret, m.ret)
with patch('os.path.exists', MagicMock(return_value=False)):
with self.assertRaises(CommandExecutionError):
status.uptime()
|
'Test modules.status.uptime function for SunOS'
| def test_uptime_sunos(self):
| m = self._set_up_test_uptime()
m2 = self._set_up_test_uptime_sunos()
with patch.multiple(salt.utils.platform, is_linux=MagicMock(return_value=False), is_sunos=MagicMock(return_value=True), is_darwin=MagicMock(return_value=False), is_freebsd=MagicMock(return_value=False), is_openbsd=MagicMock(return_value=False), is_netbsd=MagicMock(return_value=False)):
with patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value='1\n2\n3'), 'cmd.run_all': MagicMock(return_value=m2.ret)}):
with patch('time.time', MagicMock(return_value=m.now)):
ret = status.uptime()
self.assertDictEqual(ret, m.ret)
|
'Test modules.status.uptime function for macOS'
| def test_uptime_macos(self):
| m = self._set_up_test_uptime()
kern_boottime = '{{ sec = {0}, usec = {1:0<6} }} Mon Oct 03 03:09:18.23 2016'.format(*str((m.now - m.ut)).split('.'))
with patch.multiple(salt.utils.platform, is_linux=MagicMock(return_value=False), is_sunos=MagicMock(return_value=False), is_darwin=MagicMock(return_value=True), is_freebsd=MagicMock(return_value=False), is_openbsd=MagicMock(return_value=False), is_netbsd=MagicMock(return_value=False)):
with patch.dict(status.__salt__, {'cmd.run': MagicMock(return_value='1\n2\n3'), 'sysctl.get': MagicMock(return_value=kern_boottime)}):
with patch('time.time', MagicMock(return_value=m.now)):
ret = status.uptime()
self.assertDictEqual(ret, m.ret)
with patch.dict(status.__salt__, {'sysctl.get': MagicMock(return_value='')}):
with self.assertRaises(CommandExecutionError):
status.uptime()
|
'Test modules.status.uptime function for other platforms'
| def test_uptime_return_success_not_supported(self):
| with patch.multiple(salt.utils.platform, is_linux=MagicMock(return_value=False), is_sunos=MagicMock(return_value=False), is_darwin=MagicMock(return_value=False), is_freebsd=MagicMock(return_value=False), is_openbsd=MagicMock(return_value=False), is_netbsd=MagicMock(return_value=False)):
exc_mock = MagicMock(side_effect=CommandExecutionError)
with self.assertRaises(CommandExecutionError):
with patch.dict(status.__salt__, {'cmd.run': exc_mock}):
status.uptime()
|
'Test for Device-Mapper Multipath list'
| def test_multipath_list(self):
| mock = MagicMock(return_value='A')
with patch.dict(devmap.__salt__, {'cmd.run': mock}):
self.assertEqual(devmap.multipath_list(), ['A'])
|
'Test for Device-Mapper Multipath flush'
| def test_multipath_flush(self):
| mock = MagicMock(return_value=False)
with patch.object(os.path, 'exists', mock):
self.assertEqual(devmap.multipath_flush('device'), 'device does not exist')
mock = MagicMock(return_value=True)
with patch.object(os.path, 'exists', mock):
mock = MagicMock(return_value='A')
with patch.dict(devmap.__salt__, {'cmd.run': mock}):
self.assertEqual(devmap.multipath_flush('device'), ['A'])
|
'Test if return server version (``apachectl -v``)'
| def test_version(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='Server version: Apache/2.4.7')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.version(), 'Apache/2.4.7')
|
'Test if return server version (``apachectl -V``)'
| def test_fullversion(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='Server version: Apache/2.4.7')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.fullversion(), {'compiled_with': [], 'server_version': 'Apache/2.4.7'})
|
'Test if return list of static and shared modules'
| def test_modules(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='unixd_module (static)\n access_compat_module (shared)')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.modules(), {'shared': ['access_compat_module'], 'static': ['unixd_module']})
|
'Test if return list of modules compiled into the server'
| def test_servermods(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='core.c\nmod_so.c')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.servermods(), ['core.c', 'mod_so.c'])
|
'Test if return list of directives'
| def test_directives(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='Salt')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.directives(), {'Salt': ''})
|
'Test if it shows the virtualhost settings'
| def test_vhosts(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.vhosts(), {})
|
'Test if return no signal for httpd'
| def test_signal(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
mock = MagicMock(return_value='')
with patch.dict(apache.__salt__, {'cmd.run': mock}):
self.assertEqual(apache.signal(None), None)
|
'Test if return httpd signal to start, restart, or stop.'
| def test_signal_args(self):
| with patch('salt.modules.apache._detect_os', MagicMock(return_value='apachectl')):
ret = 'Command: "apachectl -k start" completed successfully!'
mock = MagicMock(return_value={'retcode': 1, 'stderr': '', 'stdout': ''})
with patch.dict(apache.__salt__, {'cmd.run_all': mock}):
self.assertEqual(apache.signal('start'), ret)
mock = MagicMock(return_value={'retcode': 1, 'stderr': 'Syntax OK', 'stdout': ''})
with patch.dict(apache.__salt__, {'cmd.run_all': mock}):
self.assertEqual(apache.signal('start'), 'Syntax OK')
mock = MagicMock(return_value={'retcode': 0, 'stderr': 'Syntax OK', 'stdout': ''})
with patch.dict(apache.__salt__, {'cmd.run_all': mock}):
self.assertEqual(apache.signal('start'), 'Syntax OK')
mock = MagicMock(return_value={'retcode': 1, 'stderr': '', 'stdout': 'Salt'})
with patch.dict(apache.__salt__, {'cmd.run_all': mock}):
self.assertEqual(apache.signal('start'), 'Salt')
|
'Test if it add HTTP user using the ``htpasswd`` command'
| def test_useradd(self):
| mock = MagicMock(return_value=True)
with patch.dict(apache.__salt__, {'webutil.useradd': mock}):
self.assertTrue(apache.useradd('htpasswd', 'salt', 'badpassword'))
|
'Test if it delete HTTP user using the ``htpasswd`` file'
| def test_userdel(self):
| mock = MagicMock(return_value=True)
with patch.dict(apache.__salt__, {'webutil.userdel': mock}):
self.assertTrue(apache.userdel('htpasswd', 'salt'))
|
'Test if return get information from the Apache server-status'
| def test_server_status(self):
| with patch('salt.modules.apache.server_status', MagicMock(return_value={})):
mock = MagicMock(return_value='')
with patch.dict(apache.__salt__, {'config.get': mock}):
self.assertEqual(apache.server_status(), {})
|
'Test if return get error from the Apache server-status'
| def test_server_status_error(self):
| mock = MagicMock(side_effect=URLError('error'))
with patch.object(apache, '_urlopen', mock):
mock = MagicMock(return_value='')
with patch.dict(apache.__salt__, {'config.get': mock}):
self.assertEqual(apache.server_status(), 'error')
|
'Test if it create VirtualHost configuration files'
| def test_config(self):
| with patch('salt.modules.apache._parse_config', MagicMock(return_value='Listen 22')):
with patch('salt.utils.files.fopen', mock_open()):
self.assertEqual(apache.config('/ports.conf', [{'Listen': '22'}]), 'Listen 22')
|
'Mock login_with_password method'
| @staticmethod
def login_with_password(xapi_login, xapi_password):
| return (xapi_login, xapi_password)
|
'Mock logout method'
| @staticmethod
def logout():
| return Mockxapi()
|
'Test to return a list of domain names on the minion'
| def test_list_domains(self):
| with patch.object(xapi, '_get_xapi_session', MagicMock()):
self.assertListEqual(xapi.list_domains(), [])
|
'Test to return detailed information about the vms'
| def test_vm_info(self):
| with patch.object(xapi, '_get_xapi_session', MagicMock()):
mock = MagicMock(return_value=False)
with patch.object(xapi, '_get_record_by_label', mock):
self.assertDictEqual(xapi.vm_info(True), {True: False})
|
'Test to return list of all the vms and their state.'
| def test_vm_state(self):
| with patch.object(xapi, '_get_xapi_session', MagicMock()):
mock = MagicMock(return_value={'power_state': '1'})
with patch.object(xapi, '_get_record_by_label', mock):
self.assertDictEqual(xapi.vm_state('salt'), {'salt': '1'})
self.assertDictEqual(xapi.vm_state(), {})
|
'Test to return info about the network interfaces of a named vm'
| def test_get_nics(self):
| ret = {'Stack': {'device': 'ETH0', 'mac': 'Stack', 'mtu': 1}}
with patch.object(xapi, '_get_xapi_session', MagicMock()):
mock = MagicMock(side_effect=[False, {'VIFs': 'salt'}])
with patch.object(xapi, '_get_record_by_label', mock):
self.assertFalse(xapi.get_nics('salt'))
mock = MagicMock(return_value={'MAC': 'Stack', 'device': 'ETH0', 'MTU': 1})
with patch.object(xapi, '_get_record', mock):
self.assertDictEqual(xapi.get_nics('salt'), ret)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.