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',...
'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...
'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'...
'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...
'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', re...
'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_valu...
'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_va...
'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_v...
'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()]): s...
'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', 'Ether...
'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__, {...
'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(['#', ...
'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(...
'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 pa...
'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={'retco...
'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...
'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\...
'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.__it...
'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__, {'ke...
'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 ...
'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)), 'pk...
'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)), 'pk...
'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 ...
'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' ...
'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('tes...
'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, 'da...
'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=Fal...
'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=Fa...
'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...
'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...
'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') ...
'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': 'Apac...
'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 ...
'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}): ...
'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')) ...