desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test to return the status for a service, returns the PID or an empty
string if the service is running or not, pass a signature to use to
find the service via ps'
| def test_status(self):
| with patch.dict(service.__salt__, {'status.pid': MagicMock(return_value=True)}):
self.assertTrue(service.status('name'))
|
'Test to restart the specified service'
| def test_reload_(self):
| with patch.object(os.path, 'join', return_value='A'):
with patch.dict(service.__salt__, {'service.run': MagicMock(return_value=True)}):
self.assertTrue(service.reload_('name'))
|
'Test to run the specified service'
| def test_run(self):
| with patch.object(os.path, 'join', return_value='A'):
with patch.dict(service.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(service.run('name', 'action'))
|
'Test to returns ``True`` if the specified service is available,
otherwise returns ``False``.'
| def test_available(self):
| with patch.object(service, 'get_all', return_value=['name', 'A']):
self.assertTrue(service.available('name'))
|
'Test to inverse of service.available.'
| def test_missing(self):
| with patch.object(service, 'get_all', return_value=['name1', 'A']):
self.assertTrue(service.missing('name'))
|
'Test to return a list of all available services'
| def test_get_all(self):
| with patch.object(os.path, 'isdir', side_effect=[False, True]):
self.assertEqual(service.get_all(), [])
with patch.object(os, 'listdir', return_value=['A', 'B']):
self.assertListEqual(service.get_all(), ['A', 'B'])
|
'If ssl options are present then check that they are parsed and returned'
| def test_returns_opts_if_specified(self):
| options = MagicMock(return_value={'cluster': ['192.168.50.10', '192.168.50.11', '192.168.50.12'], 'port': 9000, 'ssl_options': {'ca_certs': '/etc/ssl/certs/ca-bundle.trust.crt', 'ssl_version': 'PROTOCOL_TLSv1'}, 'username': 'cas_admin'})
with patch.dict(cassandra_cql.__salt__, {'config.option': options}):
self.assertEqual(cassandra_cql._get_ssl_opts(), {'ca_certs': '/etc/ssl/certs/ca-bundle.trust.crt', 'ssl_version': ssl.PROTOCOL_TLSv1})
|
'Check that the protocol version is imported only if it isvalid'
| def test_invalid_protocol_version(self):
| options = MagicMock(return_value={'cluster': ['192.168.50.10', '192.168.50.11', '192.168.50.12'], 'port': 9000, 'ssl_options': {'ca_certs': '/etc/ssl/certs/ca-bundle.trust.crt', 'ssl_version': 'Invalid'}, 'username': 'cas_admin'})
with patch.dict(cassandra_cql.__salt__, {'config.option': options}):
with self.assertRaises(CommandExecutionError):
cassandra_cql._get_ssl_opts()
|
'Check that it returns None when ssl opts aren\'t specified'
| def test_unspecified_opts(self):
| with patch.dict(cassandra_cql.__salt__, {'config.option': MagicMock(return_value={})}):
self.assertEqual(cassandra_cql._get_ssl_opts(), None)
|
'Test for delete a container, or delete an object from a container.'
| def test_delete(self):
| with patch.object(swift, '_auth', MagicMock()):
self.assertTrue(swift.delete('mycontainer'))
self.assertTrue(swift.delete('mycontainer', path='myfile.png'))
|
'Test for list the contents of a container,
or return an object from a container.'
| def test_get(self):
| with patch.object(swift, '_auth', MagicMock()):
self.assertTrue(swift.get())
self.assertTrue(swift.get('mycontainer'))
self.assertTrue(swift.get('mycontainer', path='myfile.png', return_bin=True))
self.assertTrue(swift.get('mycontainer', path='myfile.png', local_file='/tmp/myfile.png'))
self.assertFalse(swift.get('mycontainer', path='myfile.png'))
|
'Test for create a new container, or upload an object to a container.'
| def test_put(self):
| with patch.object(swift, '_auth', MagicMock()):
self.assertTrue(swift.put('mycontainer'))
self.assertTrue(swift.put('mycontainer', path='myfile.png', local_file='/tmp/myfile.png'))
self.assertFalse(swift.put('mycontainer', path='myfile.png'))
|
'Test installing a PKG file'
| def test_install(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run_all': mock}):
macpackage.install('/path/to/file.pkg')
mock.assert_called_once_with('installer -pkg /path/to/file.pkg -target LocalSystem', python_shell=False)
|
'Test installing a PKG file with a wildcard'
| def test_install_wildcard(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run_all': mock}):
macpackage.install('/path/to/*.pkg')
mock.assert_called_once_with('installer -pkg /path/to/*.pkg -target LocalSystem', python_shell=True)
|
'Test installing a PKG file with extra options'
| def test_install_with_extras(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run_all': mock}):
macpackage.install('/path/to/file.pkg', store=True, allow_untrusted=True)
mock.assert_called_once_with('installer -pkg /path/to/file.pkg -target LocalSystem -store -allowUntrusted', python_shell=False)
|
'Test installing an APP package'
| def test_install_app(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
macpackage.install_app('/path/to/file.app')
mock.assert_called_once_with('rsync -a --delete "/path/to/file.app/" "/Applications/file.app"')
|
'Test installing an APP package with a specific target'
| def test_install_app_specify_target(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
macpackage.install_app('/path/to/file.app', '/Applications/new.app')
mock.assert_called_once_with('rsync -a --delete "/path/to/file.app/" "/Applications/new.app"')
|
'Test installing an APP package with a specific target'
| def test_install_app_with_slash(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
macpackage.install_app('/path/to/file.app/')
mock.assert_called_once_with('rsync -a --delete "/path/to/file.app/" "/Applications/file.app"')
|
'Test Uninstalling an APP package with a specific target'
| def test_uninstall(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'file.remove': mock}):
macpackage.uninstall_app('/path/to/file.app')
mock.assert_called_once_with('/path/to/file.app')
|
'Test mounting an dmg file to a temporary location'
| def test_mount(self):
| cmd_mock = MagicMock()
temp_mock = MagicMock(return_value='dmg-ABCDEF')
with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock, 'temp.dir': temp_mock}):
macpackage.mount('/path/to/file.dmg')
temp_mock.assert_called_once_with(prefix='dmg-')
cmd_mock.assert_called_once_with('hdiutil attach -readonly -nobrowse -mountpoint dmg-ABCDEF "/path/to/file.dmg"')
|
'Test Unmounting an dmg file to a temporary location'
| def test_unmount(self):
| mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
macpackage.unmount('/path/to/file.dmg')
mock.assert_called_once_with('hdiutil detach "/path/to/file.dmg"')
|
'Test getting a list of the installed packages'
| def test_installed_pkgs(self):
| expected = ['com.apple.this', 'com.salt.that']
mock = MagicMock(return_value='com.apple.this\ncom.salt.that')
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage.installed_pkgs()
mock.assert_called_once_with('pkgutil --pkgs')
self.assertEqual(out, expected)
|
'Test getting a the id for a package'
| def test_get_pkg_id_with_files(self):
| with patch('salt.modules.mac_package._get_pkg_id_from_pkginfo') as pkg_id_pkginfo_mock:
expected = ['com.apple.this']
cmd_mock = MagicMock(side_effect=['/path/to/PackageInfo\n/path/to/some/other/fake/PackageInfo', '', ''])
pkg_id_pkginfo_mock.side_effect = [['com.apple.this'], []]
temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
remove_mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock, 'temp.dir': temp_mock, 'file.remove': remove_mock}):
out = macpackage.get_pkg_id('/path/to/file.pkg')
temp_mock.assert_called_once_with(prefix='pkg-')
cmd_calls = [call('xar -t -f /path/to/file.pkg | grep PackageInfo', python_shell=True, output_loglevel='quiet'), call('xar -x -f /path/to/file.pkg /path/to/PackageInfo /path/to/some/other/fake/PackageInfo', cwd='/tmp/dmg-ABCDEF', output_loglevel='quiet')]
cmd_mock.assert_has_calls(cmd_calls)
pkg_id_pkginfo_calls = [call('/path/to/PackageInfo'), call('/path/to/some/other/fake/PackageInfo')]
pkg_id_pkginfo_mock.assert_has_calls(pkg_id_pkginfo_calls)
remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')
self.assertEqual(out, expected)
|
'Test getting a the id for a package with a directory'
| def test_get_pkg_id_with_dir(self):
| with patch('salt.modules.mac_package._get_pkg_id_dir') as pkg_id_dir_mock:
expected = ['com.apple.this']
pkg_id_dir_mock.return_value = ['com.apple.this']
cmd_mock = MagicMock(return_value='Error opening /path/to/file.pkg')
temp_mock = MagicMock(return_value='/tmp/dmg-ABCDEF')
remove_mock = MagicMock()
with patch.dict(macpackage.__salt__, {'cmd.run': cmd_mock, 'temp.dir': temp_mock, 'file.remove': remove_mock}):
out = macpackage.get_pkg_id('/path/to/file.pkg')
temp_mock.assert_called_once_with(prefix='pkg-')
cmd_mock.assert_called_once_with('xar -t -f /path/to/file.pkg | grep PackageInfo', python_shell=True, output_loglevel='quiet')
pkg_id_dir_mock.assert_called_once_with('/path/to/file.pkg')
remove_mock.assert_called_once_with('/tmp/dmg-ABCDEF')
self.assertEqual(out, expected)
|
'Test getting the ids of a mpkg file'
| def test_get_mpkg_ids(self):
| with patch('salt.modules.mac_package.get_pkg_id') as get_pkg_id_mock:
expected = ['com.apple.this', 'com.salt.other']
mock = MagicMock(return_value='/tmp/dmg-X/file.pkg\n/tmp/dmg-X/other.pkg')
get_pkg_id_mock.side_effect = [['com.apple.this'], ['com.salt.other']]
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage.get_mpkg_ids('/path/to/file.mpkg')
mock.assert_called_once_with('find /path/to -name *.pkg', python_shell=True)
calls = [call('/tmp/dmg-X/file.pkg'), call('/tmp/dmg-X/other.pkg')]
get_pkg_id_mock.assert_has_calls(calls)
self.assertEqual(out, expected)
|
'Test getting a package id from pkginfo files'
| def test_get_pkg_id_from_pkginfo(self):
| expected = ['com.apple.this', 'com.apple.that']
mock = MagicMock(return_value='com.apple.this\ncom.apple.that')
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage._get_pkg_id_from_pkginfo('/tmp/dmg-X/PackageInfo')
cmd = 'cat /tmp/dmg-X/PackageInfo | grep -Eo \'identifier="[a-zA-Z.0-9\\-]*"\' | cut -c 13- | tr -d \'"\''
mock.assert_called_once_with(cmd, python_shell=True)
self.assertEqual(out, expected)
|
'Test getting a package id from pkginfo file when it doesn\'t exist'
| def test_get_pkg_id_from_pkginfo_no_file(self):
| expected = []
mock = MagicMock(return_value='No such file')
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage._get_pkg_id_from_pkginfo('/tmp/dmg-X/PackageInfo')
cmd = 'cat /tmp/dmg-X/PackageInfo | grep -Eo \'identifier="[a-zA-Z.0-9\\-]*"\' | cut -c 13- | tr -d \'"\''
mock.assert_called_once_with(cmd, python_shell=True)
self.assertEqual(out, expected)
|
'Test getting a package id from a directory'
| def test_get_pkg_id_dir(self):
| expected = ['com.apple.this']
mock = MagicMock(return_value='com.apple.this')
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage._get_pkg_id_dir('/tmp/dmg-X/')
cmd = '/usr/libexec/PlistBuddy -c "print :CFBundleIdentifier" /tmp/dmg-X/Contents/Info.plist'
mock.assert_called_once_with(cmd, python_shell=False)
self.assertEqual(out, expected)
|
'Test getting a package id from a directory with a wildcard'
| def test_get_pkg_id_dir_wildcard(self):
| expected = ['com.apple.this']
mock = MagicMock(return_value='com.apple.this')
with patch.dict(macpackage.__salt__, {'cmd.run': mock}):
out = macpackage._get_pkg_id_dir('/tmp/dmg-X/*.pkg/')
cmd = '/usr/libexec/PlistBuddy -c "print :CFBundleIdentifier" \'/tmp/dmg-X/*.pkg/Contents/Info.plist\''
mock.assert_called_once_with(cmd, python_shell=True)
self.assertEqual(out, expected)
|
'Test to get the lucene version that solr is using.'
| def test_lucene_version(self):
| with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False, False]):
tempdict = {'success': 'success', 'errors': 'errors', 'data': {'lucene': {'lucene-spec-version': 1}}}
with patch.object(solr, '_get_admin_info', side_effect=[tempdict, tempdict, {'success': None}]):
with patch.dict(solr.__salt__, {'config.option': MagicMock(return_value=['A'])}):
with patch.object(solr, '_update_return_dict', return_value={'A': 'a'}):
self.assertDictEqual(solr.lucene_version('c'), {'A': 'a'})
self.assertDictEqual(solr.lucene_version('c'), {'A': 'a'})
self.assertDictEqual(solr.lucene_version('c'), {'success': None})
|
'Test to get the solr version for the core specified'
| def test_version(self):
| with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False, False]):
tempdict = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': {'lucene': {'solr-spec-version': 1}}}
with patch.object(solr, '_get_admin_info', side_effect=[tempdict, tempdict]):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value=['A'])}):
with patch.object(solr, '_update_return_dict', return_value={'A': 'a'}):
self.assertDictEqual(solr.version(), {'A': 'a'})
self.assertDictEqual(solr.version(), {'A': 'a'})
with patch.object(solr, '_get_admin_info', return_value={'success': None}):
self.assertDictEqual(solr.version(), {'success': None})
|
'Test to search queries fast, but it is a very expensive operation.'
| def test_optimize(self):
| with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
tempdict = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': {'lucene': {'solr-spec-version': 1}}}
with patch.object(solr, '_format_url', return_value='A'):
with patch.dict(solr.__salt__, {'config.option': MagicMock(return_value=['A'])}):
with patch.object(solr, '_http_request', return_value=tempdict):
with patch.object(solr, '_update_return_dict', return_value={'A': 'a'}):
self.assertDictEqual(solr.optimize(), {'A': 'a'})
with patch.object(solr, '_http_request', return_value='A'):
self.assertEqual(solr.optimize(), 'A')
|
'Test to check on solr, makes sure solr can talk to the
indexes.'
| def test_ping(self):
| with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
tempdict = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': {'lucene': {'solr-spec-version': 1}}}
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value=['A'])}):
with patch.object(solr, '_get_admin_info', return_value=tempdict):
with patch.object(solr, '_update_return_dict', return_value={'A': 'a'}):
self.assertDictEqual(solr.ping(), {'A': 'a'})
with patch.object(solr, '_get_admin_info', return_value='A'):
self.assertEqual(solr.ping(), 'A')
|
'Test to check for errors, and determine if a slave
is replicating or not.'
| def test_is_replication_enabled(self):
| error = 'Only "slave" minions can run "is_replication_enabled"'
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_is_master', side_effect=[True, False]):
self.assertIsNone(solr.is_replication_enabled())
with patch.object(solr, '_get_none_or_value', return_value=None):
with patch.object(solr, '_check_for_cores', return_value=True):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='A')}):
with patch.object(solr, '_replication_request', return_value='A'):
self.assertDictEqual(solr.is_replication_enabled(), {'A': 'a', 'errors': [error], 'success': False})
|
'Test to verifies that the master and the slave versions are in sync by
comparing the index version.'
| def test_match_index_versions(self):
| err = 'solr.match_index_versions can only be called by "slave" minions'
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_is_master', side_effect=[True, False]):
self.assertIsNone(solr.match_index_versions())
with patch.object(solr, '_get_none_or_value', return_value=None):
with patch.object(solr, '_check_for_cores', return_value=True):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='A')}):
with patch.object(solr, '_replication_request', return_value='A'):
self.assertDictEqual(solr.match_index_versions(), {'A': 'a', 'errors': [err], 'success': False})
|
'Test to get the full replication details.'
| def test_replication_details(self):
| tempdict1 = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': 'data'}
tempdict2 = {'success': None, 'errors': 'errors', 'warnings': 'warnings', 'data': 'data'}
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', return_value=True):
with patch.object(solr, '_replication_request', side_effect=[tempdict2, tempdict1]):
self.assertDictEqual(solr.replication_details(), tempdict2)
with patch.object(solr, '_update_return_dict', return_value=tempdict1):
self.assertDictEqual(solr.replication_details(), tempdict1)
|
'Test to tell solr make a backup.'
| def test_backup(self):
| tempdict = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': 'data'}
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.dict(solr.__opts__, {'solr.backup_path': MagicMock(return_value='A'), 'solr.num_backups': MagicMock(return_value='B'), 'solr.cores': MagicMock(return_value=['A'])}):
with patch.object(os.path, 'sep', return_value='B'):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
with patch.object(solr, '_replication_request', return_value=tempdict):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value=['A'])}):
with patch.object(solr, '_update_return_dict', return_value='A'):
self.assertDictEqual(solr.backup(), {'A': 'a'})
self.assertDictEqual(solr.backup(), tempdict)
|
'Test to prevent the slaves from polling the master for updates.'
| def test_set_is_polling(self):
| tempdict = {'success': 'success', 'errors': 'errors', 'warnings': 'warnings', 'data': 'data'}
err = 'solr.set_is_polling can only be called by "slave" minions'
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_is_master', side_effect=[True, False, False]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, None, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
self.assertIsNone(solr.set_is_polling('p'))
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='A')}):
with patch.object(solr, '_update_return_dict', return_value=tempdict):
self.assertDictEqual(solr.set_is_polling('p'), {'A': 'a', 'errors': [err], 'success': False})
with patch.object(solr, '_replication_request', return_value='A'):
self.assertEqual(solr.set_is_polling('p'), 'A')
|
'Test to sets the master to ignore poll requests from the slaves.'
| def test_set_replication_enabled(self):
| with patch.object(solr, '_is_master', side_effect=[False, True, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, None, True, True, True]):
with patch.object(solr, '_get_return_dict', side_effect=[{'A': 'a'}, {}]):
with patch.object(solr, '_replication_request', return_value='A'):
self.assertDictEqual(solr.set_replication_enabled('s'), {'A': 'a'})
with patch.object(solr, '_check_for_cores', return_value=True):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='n')}):
self.assertEqual(solr.set_replication_enabled('s'), {})
self.assertEqual(solr.set_replication_enabled('s'), 'A')
self.assertEqual(solr.set_replication_enabled(False), 'A')
|
'Test to signals Apache Solr to start, stop, or restart.'
| def test_signal(self):
| self.assertEqual(solr.signal('signal'), 'signal is an invalid signal. Try: one of: start, stop, or restart')
|
'Test to load a new core from the same configuration as
an existing registered core.'
| def test_reload_core(self):
| error = ['solr.reload_core can only be called by "multi-core" minions']
with patch.object(solr, '_check_for_cores', side_effect=[False, True, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_format_url', return_value='A'):
with patch.object(solr, '_http_request', return_value='A'):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='n')}):
self.assertIsNone(solr.reload_core())
self.assertDictEqual(solr.reload_core(), {'A': 'a', 'errors': error, 'success': False})
self.assertEqual(solr.reload_core(), 'A')
|
'Test to get the status for a given core or all cores
if no core is specified'
| def test_core_status(self):
| error = ['solr.reload_core can only be called by "multi-core" minions']
with patch.object(solr, '_check_for_cores', side_effect=[False, True, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_format_url', return_value='A'):
with patch.object(solr, '_http_request', return_value='A'):
with patch.dict(solr.__opts__, {'solr.cores': MagicMock(return_value='n')}):
self.assertIsNone(solr.core_status())
self.assertDictEqual(solr.core_status(), {'A': 'a', 'errors': error, 'success': False})
self.assertEqual(solr.core_status(), 'A')
|
'Test to re-loads the handler config XML file.'
| def test_reload_import_config(self):
| with patch.object(solr, '_is_master', side_effect=[False, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, None, None, True, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
with patch.object(solr, '_format_url', return_value='A'):
with patch.object(solr, '_http_request', return_value='A'):
self.assertDictEqual(solr.reload_import_config('h'), {'A': 'a'})
self.assertDictEqual(solr.reload_import_config('h'), {'A': 'a'})
self.assertEqual(solr.reload_import_config('h'), 'A')
|
'Test to aborts an existing import command to the specified handler.'
| def test_abort_import(self):
| with patch.object(solr, '_is_master', side_effect=[False, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, None, None, True, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
with patch.object(solr, '_format_url', return_value='A'):
with patch.object(solr, '_http_request', return_value='A'):
self.assertDictEqual(solr.abort_import('h'), {'A': 'a'})
self.assertDictEqual(solr.abort_import('h'), {'A': 'a'})
self.assertEqual(solr.abort_import('h'), 'A')
|
'Test to submits an import command to the specified handler using
specified options.'
| def test_full_import(self):
| with patch('salt.modules.solr._format_url', MagicMock(return_value='A')):
with patch.object(solr, '_is_master', side_effect=[False, True, True, True, True, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True, True, True, True]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False, False, False, False]):
with patch.object(solr, '_pre_index_check', side_effect=[{'success': False}, {'success': True}, {'success': True}]):
with patch.object(solr, '_merge_options', side_effect=[{'clean': True}, {'clean': False}]):
with patch.object(solr, 'set_replication_enabled', return_value={'success': False}):
with patch.object(solr, '_http_request', return_value='A'):
self.assertDictEqual(solr.full_import('h'), {'A': 'a'})
self.assertDictEqual(solr.full_import('h'), {'A': 'a'})
self.assertDictEqual(solr.full_import('h'), {'success': False})
self.assertDictEqual(solr.full_import('h'), {'A': 'a'})
self.assertEqual(solr.full_import('h'), 'A')
|
'Test to submits an import command to the specified handler using
specified options.'
| def test_delta_import(self):
| with patch('salt.modules.solr._format_url', MagicMock(return_value='A')):
with patch.object(solr, '_is_master', side_effect=[False, True, True, True, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True, True, True, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_pre_index_check', side_effect=[{'success': False}, {'success': True}, {'success': True}, {'success': True}]):
with patch.object(solr, '_merge_options', side_effect=[{'clean': True}, {'clean': False}]):
with patch.object(solr, '_check_for_cores', side_effect=[True, False]):
with patch.object(solr, 'set_replication_enabled', return_value={'success': False}):
with patch.object(solr, '_http_request', return_value='A'):
self.assertDictEqual(solr.delta_import('h'), {'A': 'a'})
self.assertDictEqual(solr.delta_import('h'), {'success': False})
self.assertDictEqual(solr.delta_import('h'), {'A': 'a'})
self.assertEqual(solr.delta_import('h'), 'A')
|
'Test to submits an import command to the specified handler using
specified options.'
| def test_import_status(self):
| with patch.object(solr, '_is_master', side_effect=[False, True]):
with patch.object(solr, '_get_none_or_value', side_effect=[None, True]):
with patch.object(solr, '_get_return_dict', return_value={'A': 'a'}):
with patch.object(solr, '_format_url', return_value='A'):
with patch.object(solr, '_http_request', return_value='A'):
self.assertDictEqual(solr.import_status('h'), {'A': 'a'})
self.assertEqual(solr.import_status('h'), 'A')
|
'unit tests for disk.format'
| @skipIf((not salt.utils.path.which('sync')), 'sync not found')
@skipIf((not salt.utils.path.which('mkfs')), 'mkfs not found')
def test_format(self):
| device = '/dev/sdX1'
mock = MagicMock(return_value=0)
with patch.dict(disk.__salt__, {'cmd.retcode': mock}):
self.assertEqual(disk.format_(device), True)
|
'unit tests for disk.fstype'
| def test_fstype(self):
| device = '/dev/sdX1'
fs_type = 'ext4'
mock = MagicMock(return_value='FSTYPE\n{0}'.format(fs_type))
with patch.dict(disk.__grains__, {'kernel': 'Linux'}):
with patch.dict(disk.__salt__, {'cmd.run': mock}):
self.assertEqual(disk.fstype(device), fs_type)
|
'unit tests for disk.resize2fs'
| @skipIf((not salt.utils.path.which('resize2fs')), 'resize2fs not found')
def test_resize2fs(self):
| device = '/dev/sdX1'
mock = MagicMock()
with patch.dict(disk.__salt__, {'cmd.run_all': mock}):
disk.resize2fs(device)
mock.assert_called_once_with('resize2fs {0}'.format(device), python_shell=False)
|
'Test - Read a registry value from a subkey using Pythen 2 Strings or
Pythen 3 Bytes'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_read_reg_plain(self):
| if (not PY2):
self.skipTest(u'Invalid for Python Version 2')
subkey = 'Software\\Microsoft\\Windows NT\\CurrentVersion'
vname = 'PathName'
handle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey, 0, _winreg.KEY_ALL_ACCESS)
(current_vdata, dummy_current_vtype) = _winreg.QueryValueEx(handle, vname)
_winreg.CloseKey(handle)
test_vdata = win_mod_reg.read_value('HKEY_LOCAL_MACHINE', subkey, vname)['vdata']
self.assertEqual(test_vdata, current_vdata)
|
'Test - Read a registry value from a subkey using Pythen 2 Unicode
or Pythen 3 Str i.e. Unicode'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_read_reg_unicode(self):
| subkey = u'Software\\Microsoft\\Windows NT\\CurrentVersion'
vname = u'PathName'
handle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey, 0, _winreg.KEY_ALL_ACCESS)
(current_vdata, dummy_current_vtype) = _winreg.QueryValueEx(handle, vname)
_winreg.CloseKey(handle)
test_vdata = win_mod_reg.read_value(u'HKEY_LOCAL_MACHINE', subkey, vname)[u'vdata']
self.assertEqual(test_vdata, current_vdata)
|
'Test - Read list the keys under a subkey which does not exist.'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_list_keys_fail(self):
| subkey = u'ThisIsJunkItDoesNotExistIhope'
test_list = win_mod_reg.list_keys(u'HKEY_LOCAL_MACHINE', subkey)
test = (isinstance(test_list, tuple) and (not test_list[0]))
self.assertTrue(test)
|
'Test - Read list the keys under a subkey'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_list_keys(self):
| subkey = u'Software\\Microsoft\\Windows NT\\CurrentVersion'
test_list = win_mod_reg.list_keys(u'HKEY_LOCAL_MACHINE', subkey)
test = (len(test_list) > 5)
self.assertTrue(test)
|
'Test - List the values under a subkey which does not exist.'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_list_values_fail(self):
| subkey = u'ThisIsJunkItDoesNotExistIhope'
test_list = win_mod_reg.list_values(u'HKEY_LOCAL_MACHINE', subkey)
test = (isinstance(test_list, tuple) and (not test_list[0]))
self.assertTrue(test)
|
'Test - List the values under a subkey.'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_list_values(self):
| subkey = u'Software\\Microsoft\\Windows NT\\CurrentVersion'
test_list = win_mod_reg.list_values(u'HKEY_LOCAL_MACHINE', subkey)
test = (len(test_list) > 5)
self.assertTrue(test)
|
'Test - set a registry plain text subkey name to a unicode string value'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_set_value_unicode(self):
| vname = u'TestUniccodeString'
subkey = u'Software\\SaltStackTest'
test1_success = False
test2_success = False
test1_success = win_mod_reg.set_value(u'HKEY_LOCAL_MACHINE', subkey, vname, UNICODETEST_WITH_SIGNS)
if test1_success:
handle = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey, 0, _winreg.KEY_ALL_ACCESS)
(current_vdata, dummy_current_vtype) = _winreg.QueryValueEx(handle, vname)
_winreg.CloseKey(handle)
test2_success = (current_vdata == UNICODETEST_WITH_SIGNS)
self.assertTrue((test1_success and test2_success))
|
'Test - set a registry Unicode subkey name with unicode characters within
to a integer'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_set_value_unicode_key(self):
| test_success = win_mod_reg.set_value(u'HKEY_LOCAL_MACHINE', u'Software\\SaltStackTest', UNICODE_TEST_KEY, TIMEINT, u'REG_DWORD')
self.assertTrue(test_success)
|
'Test - Create Directly and Delete with salt a registry value'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_del_value(self):
| subkey = u'Software\\SaltStackTest'
vname = UNICODE_TEST_KEY_DEL
vdata = u'I will be deleted'
if PY2:
handle = _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, subkey.encode(u'mbcs'), 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname.encode(u'mbcs'), 0, _winreg.REG_SZ, vdata.encode(u'mbcs'))
else:
handle = _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, subkey, 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname, 0, _winreg.REG_SZ, vdata)
_winreg.CloseKey(handle)
test_success = win_mod_reg.delete_value(u'HKEY_LOCAL_MACHINE', subkey, vname)
self.assertTrue(test_success)
|
'Test - Create directly key/value pair and Delete recusivly with salt'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
def test_del_key_recursive_user(self):
| subkey = u'Software\\SaltStackTest'
vname = UNICODE_TEST_KEY_DEL
vdata = u'I will be deleted recursive'
if PY2:
handle = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, subkey.encode(u'mbcs'), 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname.encode(u'mbcs'), 0, _winreg.REG_SZ, vdata.encode(u'mbcs'))
else:
handle = _winreg.CreateKeyEx(_winreg.HKEY_CURRENT_USER, subkey, 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname, 0, _winreg.REG_SZ, vdata)
_winreg.CloseKey(handle)
test_success = win_mod_reg.delete_key_recursive(u'HKEY_CURRENT_USER', subkey)
self.assertTrue(test_success)
|
'This is a DESTRUCTIVE TEST it creates a new registry entry.
And then destroys the registry entry recusively , however it is completed in its own space
within the registry. We mark this as destructiveTest as it has the potential
to detroy a machine if salt reg code has a large error in it.'
| @skipIf((not sys.platform.startswith(u'win')), u'requires Windows OS')
@destructiveTest
def test_del_key_recursive_machine(self):
| subkey = u'Software\\SaltStackTest'
vname = UNICODE_TEST_KEY_DEL
vdata = u'I will be deleted recursive'
if PY2:
handle = _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, subkey.encode(u'mbcs'), 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname.encode(u'mbcs'), 0, _winreg.REG_SZ, vdata.encode(u'mbcs'))
else:
handle = _winreg.CreateKeyEx(_winreg.HKEY_LOCAL_MACHINE, subkey, 0, _winreg.KEY_ALL_ACCESS)
_winreg.SetValueEx(handle, vname, 0, _winreg.REG_SZ, vdata)
_winreg.CloseKey(handle)
test_success = win_mod_reg.delete_key_recursive(u'HKEY_LOCAL_MACHINE', subkey)
self.assertTrue(test_success)
|
'Test for Return version from firewall-cmd'
| def test_version(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=2):
self.assertEqual(firewalld.version(), 2)
|
'Test for Print default zone for connections and interfaces'
| def test_default_zone(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.default_zone(), 'A')
|
'Test for List everything added for or enabled in all zones'
| def test_list_zones(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=[]):
self.assertEqual(firewalld.default_zone(), [])
|
'Test for Print predefined zones'
| def test_get_zones(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.get_zones(), ['A'])
|
'Test for Print predefined services'
| def test_get_services(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.get_services(), ['A'])
|
'Test for Print predefined icmptypes'
| def test_get_icmp_types(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.get_icmp_types(), ['A'])
|
'Test for Add a new zone'
| def test_new_zone(self):
| with patch.object(firewalld, '__mgmt', return_value='success'):
mock = MagicMock(return_value='A')
with patch.object(firewalld, '__firewall_cmd', mock):
self.assertEqual(firewalld.new_zone('zone'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.new_zone('zone'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.new_zone('zone', False), 'A')
|
'Test for Delete an existing zone'
| def test_delete_zone(self):
| with patch.object(firewalld, '__mgmt', return_value='success'):
with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.delete_zone('zone'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.delete_zone('zone'), 'A')
mock = MagicMock(return_value='A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.delete_zone('zone', False), 'A')
|
'Test for Set default zone'
| def test_set_default_zone(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.set_default_zone('zone'), 'A')
|
'Test for Add a new service'
| def test_new_service(self):
| with patch.object(firewalld, '__mgmt', return_value='success'):
mock = MagicMock(return_value='A')
with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.new_service('zone'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.new_service('zone'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.new_service('zone', False), 'A')
|
'Test for Delete an existing service'
| def test_delete_service(self):
| with patch.object(firewalld, '__mgmt', return_value='success'):
mock = MagicMock(return_value='A')
with patch.object(firewalld, '__firewall_cmd', return_value='A'):
self.assertEqual(firewalld.delete_service('name'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.delete_service('name'), 'A')
with patch.object(firewalld, '__mgmt', return_value='A'):
self.assertEqual(firewalld.delete_service('name', False), 'A')
|
'Test for List everything added for or enabled in a zone'
| def test_list_all(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=''):
self.assertEqual(firewalld.list_all(), {})
|
'Test for List services added for zone as a space separated list.'
| def test_list_services(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=''):
self.assertEqual(firewalld.list_services(), [])
|
'Test for Add a service for zone'
| def test_add_service(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=''):
self.assertEqual(firewalld.add_service('name'), '')
|
'Test for Remove a service from zone'
| def test_remove_service(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=''):
self.assertEqual(firewalld.remove_service('name'), '')
|
'Test for adding masquerade'
| def test_add_masquerade(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.add_masquerade('name'), 'success')
|
'Test for removing masquerade'
| def test_remove_masquerade(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.remove_masquerade('name'), 'success')
|
'Test adding a port to a specific zone'
| def test_add_port(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.add_port('zone', '80/tcp'), 'success')
|
'Test removing a port from a specific zone'
| def test_remove_port(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.remove_port('zone', '80/tcp'), 'success')
|
'Test listing ports within a zone'
| def test_list_ports(self):
| ret = '22/tcp 53/udp 53/tcp'
exp = ['22/tcp', '53/udp', '53/tcp']
with patch.object(firewalld, '__firewall_cmd', return_value=ret):
self.assertEqual(firewalld.list_ports('zone'), exp)
|
'Test adding port forwarding on a zone'
| def test_add_port_fwd(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.add_port_fwd('zone', '22', '2222', 'tcp'), 'success')
|
'Test removing port forwarding on a zone'
| def test_remove_port_fwd(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.remove_port_fwd('zone', '22', '2222', 'tcp'), 'success')
|
'Test listing all port forwarding for a zone'
| def test_list_port_fwd(self):
| ret = 'port=23:proto=tcp:toport=8080:toaddr=\nport=80:proto=tcp:toport=443:toaddr='
exp = [{'Destination address': '', 'Destination port': '8080', 'Protocol': 'tcp', 'Source port': '23'}, {'Destination address': '', 'Destination port': '443', 'Protocol': 'tcp', 'Source port': '80'}]
with patch.object(firewalld, '__firewall_cmd', return_value=ret):
self.assertEqual(firewalld.list_port_fwd('zone'), exp)
|
'Test ICMP block'
| def test_block_icmp(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
with patch.object(firewalld, 'get_icmp_types', return_value='echo-reply'):
self.assertEqual(firewalld.block_icmp('zone', 'echo-reply'), 'success')
with patch.object(firewalld, '__firewall_cmd'):
self.assertFalse(firewalld.block_icmp('zone', 'echo-reply'))
|
'Test ICMP allow'
| def test_allow_icmp(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
with patch.object(firewalld, 'get_icmp_types', return_value='echo-reply'):
self.assertEqual(firewalld.allow_icmp('zone', 'echo-reply'), 'success')
with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertFalse(firewalld.allow_icmp('zone', 'echo-reply'))
|
'Test ICMP block list'
| def test_list_icmp_block(self):
| ret = 'echo-reply echo-request'
exp = ['echo-reply', 'echo-request']
with patch.object(firewalld, '__firewall_cmd', return_value=ret):
self.assertEqual(firewalld.list_icmp_block('zone'), exp)
|
'Test listing rich rules bound to a zone'
| def test_get_rich_rules(self):
| with patch.object(firewalld, '__firewall_cmd', return_value=''):
self.assertEqual(firewalld.get_rich_rules('zone'), [])
|
'Test adding a rich rule to a zone'
| def test_add_rich_rule(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.add_rich_rule('zone', 'rule family="ipv4" source address="1.2.3.4" accept'), 'success')
|
'Test removing a rich rule to a zone'
| def test_remove_rich_rule(self):
| with patch.object(firewalld, '__firewall_cmd', return_value='success'):
self.assertEqual(firewalld.remove_rich_rule('zone', 'rule family="ipv4" source address="1.2.3.4" accept'), 'success')
|
'Tests LVM version info from lvm version'
| def test_version(self):
| mock = MagicMock(return_value=' LVM version: 2.02.168(2) (2016-11-30)\n Library version: 1.03.01 (2016-11-30)\n Driver version: 4.35.0\n')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
self.assertEqual(linux_lvm.version(), '2.02.168(2) (2016-11-30)')
|
'Tests all version info from lvm version'
| def test_fullversion(self):
| mock = MagicMock(return_value=' LVM version: 2.02.168(2) (2016-11-30)\n Library version: 1.03.01 (2016-11-30)\n Driver version: 4.35.0\n')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
self.assertDictEqual(linux_lvm.fullversion(), {'LVM version': '2.02.168(2) (2016-11-30)', 'Library version': '1.03.01 (2016-11-30)', 'Driver version': '4.35.0'})
|
'Tests information about the physical volume(s)'
| def test_pvdisplay(self):
| mock = MagicMock(return_value={'retcode': 1})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.pvdisplay(), {})
mock = MagicMock(return_value={'retcode': 0, 'stdout': 'A:B:C:D:E:F:G:H:I:J:K'})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.pvdisplay(), {'A': {'Allocated Physical Extents': 'K', 'Current Logical Volumes Here': 'G', 'Free Physical Extents': 'J', 'Internal Physical Volume Number': 'D', 'Physical Extent Size (kB)': 'H', 'Physical Volume (not) Allocatable': 'F', 'Physical Volume Device': 'A', 'Physical Volume Size (kB)': 'C', 'Physical Volume Status': 'E', 'Total Physical Extents': 'I', 'Volume Group Name': 'B'}})
mockpath = MagicMock(return_value='Z')
with patch.object(os.path, 'realpath', mockpath):
self.assertDictEqual(linux_lvm.pvdisplay(real=True), {'Z': {'Allocated Physical Extents': 'K', 'Current Logical Volumes Here': 'G', 'Free Physical Extents': 'J', 'Internal Physical Volume Number': 'D', 'Physical Extent Size (kB)': 'H', 'Physical Volume (not) Allocatable': 'F', 'Physical Volume Device': 'A', 'Physical Volume Size (kB)': 'C', 'Physical Volume Status': 'E', 'Real Physical Volume Device': 'Z', 'Total Physical Extents': 'I', 'Volume Group Name': 'B'}})
|
'Tests information about the volume group(s)'
| def test_vgdisplay(self):
| mock = MagicMock(return_value={'retcode': 1})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.vgdisplay(), {})
mock = MagicMock(return_value={'retcode': 0, 'stdout': 'A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q'})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.vgdisplay(), {'A': {'Actual Physical Volumes': 'K', 'Allocated Physical Extents': 'O', 'Current Logical Volumes': 'F', 'Current Physical Volumes': 'J', 'Free Physical Extents': 'P', 'Internal Volume Group Number': 'D', 'Maximum Logical Volume Size': 'H', 'Maximum Logical Volumes': 'E', 'Maximum Physical Volumes': 'I', 'Open Logical Volumes': 'G', 'Physical Extent Size (kB)': 'M', 'Total Physical Extents': 'N', 'UUID': 'Q', 'Volume Group Access': 'B', 'Volume Group Name': 'A', 'Volume Group Size (kB)': 'L', 'Volume Group Status': 'C'}})
|
'Return information about the logical volume(s)'
| def test_lvdisplay(self):
| mock = MagicMock(return_value={'retcode': 1})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.lvdisplay(), {})
mock = MagicMock(return_value={'retcode': 0, 'stdout': 'A:B:C:D:E:F:G:H:I:J:K:L:M'})
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(linux_lvm.lvdisplay(), {'A': {'Allocated Logical Extents': 'I', 'Allocation Policy': 'J', 'Current Logical Extents Associated': 'H', 'Internal Logical Volume Number': 'E', 'Logical Volume Access': 'C', 'Logical Volume Name': 'A', 'Logical Volume Size': 'G', 'Logical Volume Status': 'D', 'Major Device Number': 'L', 'Minor Device Number': 'M', 'Open Logical Volumes': 'F', 'Read Ahead Sectors': 'K', 'Volume Group Name': 'B'}})
|
'Tests for set a physical device to be used as an LVM physical volume'
| def test_pvcreate(self):
| self.assertEqual(linux_lvm.pvcreate(''), 'Error: at least one device is required')
self.assertRaises(CommandExecutionError, linux_lvm.pvcreate, 'A')
pvdisplay = MagicMock(side_effect=[False, True])
with patch('salt.modules.linux_lvm.pvdisplay', pvdisplay):
with patch.object(os.path, 'exists', return_value=True):
ret = {'stdout': 'saltines', 'stderr': 'cheese', 'retcode': 0, 'pid': '1337'}
mock = MagicMock(return_value=ret)
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000), True)
|
'Test a scenario when all the submitted devices are already LVM PVs.'
| def test_pvcreate_existing_pvs(self):
| pvdisplay = MagicMock(return_value=True)
with patch('salt.modules.linux_lvm.pvdisplay', pvdisplay):
with patch.object(os.path, 'exists', return_value=True):
ret = {'stdout': 'saltines', 'stderr': 'cheese', 'retcode': 0, 'pid': '1337'}
cmd_mock = MagicMock(return_value=ret)
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': cmd_mock}):
self.assertEqual(linux_lvm.pvcreate('A', metadatasize=1000), True)
self.assertTrue((cmd_mock.call_count == 0))
|
'Tests for remove a physical device being used as an LVM physical volume'
| def test_pvremove(self):
| pvdisplay = MagicMock(return_value=False)
with patch('salt.modules.linux_lvm.pvdisplay', pvdisplay):
self.assertRaises(CommandExecutionError, linux_lvm.pvremove, 'A', override=False)
pvdisplay = MagicMock(return_value=False)
with patch('salt.modules.linux_lvm.pvdisplay', pvdisplay):
mock = MagicMock(return_value=True)
with patch.dict(linux_lvm.__salt__, {'lvm.pvdisplay': mock}):
ret = {'stdout': 'saltines', 'stderr': 'cheese', 'retcode': 0, 'pid': '1337'}
mock = MagicMock(return_value=ret)
with patch.dict(linux_lvm.__salt__, {'cmd.run_all': mock}):
self.assertEqual(linux_lvm.pvremove('A'), True)
|
'Tests create an LVM volume group'
| def test_vgcreate(self):
| self.assertEqual(linux_lvm.vgcreate('', ''), 'Error: vgname and device(s) are both required')
mock = MagicMock(return_value='A\nB')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
with patch.object(linux_lvm, 'vgdisplay', return_value={}):
self.assertDictEqual(linux_lvm.vgcreate('A', 'B'), {'Output from vgcreate': 'A'})
|
'Tests add physical volumes to an LVM volume group'
| def test_vgextend(self):
| self.assertEqual(linux_lvm.vgextend('', ''), 'Error: vgname and device(s) are both required')
mock = MagicMock(return_value='A\nB')
with patch.dict(linux_lvm.__salt__, {'cmd.run': mock}):
with patch.object(linux_lvm, 'vgdisplay', return_value={}):
self.assertDictEqual(linux_lvm.vgextend('A', 'B'), {'Output from vgextend': 'A'})
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.