mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #30049 from rallytime/esxi-unit-tests
Add some more unit tests for the vsphere execution module
This commit is contained in:
commit
bad6daca93
2 changed files with 187 additions and 4 deletions
|
@ -807,7 +807,8 @@ def reset_syslog_config(host,
|
|||
port. Default port is ``443``.
|
||||
|
||||
syslog_config
|
||||
List of parameters to reset, or 'all' to reset everything.
|
||||
List of parameters to reset, provided as a comma-delimited string, or 'all' to
|
||||
reset all syslog configuration parameters. Required.
|
||||
|
||||
esxi_hosts
|
||||
If ``host`` is a vCenter host, then use esxi_hosts to execute this function
|
||||
|
@ -831,6 +832,10 @@ def reset_syslog_config(host,
|
|||
salt '*' vsphere.reset_syslog_config my.vcenter.location root bad-password \
|
||||
syslog_config='logdir,loghost' esxi_hosts='[esxi-1.host.com, esxi-2.host.com]'
|
||||
'''
|
||||
if not syslog_config:
|
||||
raise CommandExecutionError('The \'reset_syslog_config\' function requires a '
|
||||
'\'syslog_config\' setting.')
|
||||
|
||||
valid_resets = ['logdir', 'loghost', 'default-rotate',
|
||||
'default-size', 'default-timeout', 'logdir-unique']
|
||||
cmd = 'system syslog config set --reset='
|
||||
|
@ -3268,8 +3273,8 @@ def _get_service_manager(host_reference):
|
|||
def _get_vsan_eligible_disks(service_instance, host, host_names):
|
||||
'''
|
||||
Helper function that returns a dictionary of host_name keys with either a list of eligible
|
||||
disks that can be added to VSAN or either and 'Error' message or a message saying no
|
||||
eligible disks were found. Possible keys/values look like so:
|
||||
disks that can be added to VSAN or either an 'Error' message or a message saying no
|
||||
eligible disks were found. Possible keys/values look like:
|
||||
|
||||
return = {'host_1': {'Error': 'VSAN System Config Manager is unset ...'},
|
||||
'host_2': {'Eligible': 'The host xxx does not have any VSAN eligible disks.'},
|
||||
|
@ -3328,6 +3333,9 @@ def _reset_syslog_config_params(host, username, password, cmd, resets, valid_res
|
|||
ret_dict = {}
|
||||
all_success = True
|
||||
|
||||
if not isinstance(resets, list):
|
||||
resets = [resets]
|
||||
|
||||
for reset_param in resets:
|
||||
if reset_param in valid_resets:
|
||||
ret = salt.utils.vmware.esxcli(host, username, password, cmd + reset_param,
|
||||
|
|
|
@ -348,6 +348,181 @@ class VsphereTestCase(TestCase):
|
|||
'foo',
|
||||
firewall=True))
|
||||
|
||||
# Tests for get_syslog_config function
|
||||
|
||||
def test_get_syslog_config_esxi_hosts_not_list(self):
|
||||
'''
|
||||
Tests CommandExecutionError is raised when esxi_hosts is provided,
|
||||
but is not a list.
|
||||
'''
|
||||
self.assertRaises(CommandExecutionError,
|
||||
vsphere.get_syslog_config,
|
||||
HOST, USER, PASSWORD, esxi_hosts='foo')
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_get_syslog_config_host_list_bad_retcode(self):
|
||||
'''
|
||||
Tests error message returned with list of esxi_hosts.
|
||||
'''
|
||||
host_1 = 'host_1.foo.com'
|
||||
self.assertEqual({host_1: {'message': ERROR, 'success': False}},
|
||||
vsphere.get_syslog_config(HOST, USER, PASSWORD, esxi_hosts=[host_1]))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_get_syslog_config_host_list_success(self):
|
||||
'''
|
||||
Tests successful function return when an esxi_host is provided.
|
||||
'''
|
||||
host_1 = 'host_1.foo.com'
|
||||
self.assertEqual({host_1: {'success': True}},
|
||||
vsphere.get_syslog_config(HOST, USER, PASSWORD, esxi_hosts=[host_1]))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_get_syslog_config_bad_retcode(self):
|
||||
'''
|
||||
Tests error message given for a single ESXi host.
|
||||
'''
|
||||
self.assertEqual({HOST: {'message': ERROR, 'success': False}},
|
||||
vsphere.get_syslog_config(HOST, USER, PASSWORD))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_get_syslog_config_success(self):
|
||||
'''
|
||||
Tests successful function return for a single ESXi host.
|
||||
'''
|
||||
self.assertEqual({HOST: {'success': True}},
|
||||
vsphere.get_syslog_config(HOST, USER, PASSWORD))
|
||||
|
||||
# Tests for reset_syslog_config function
|
||||
|
||||
def test_reset_syslog_config_no_syslog_config(self):
|
||||
'''
|
||||
Tests CommandExecutionError is raised when a syslog_config parameter is missing.
|
||||
'''
|
||||
self.assertRaises(CommandExecutionError,
|
||||
vsphere.reset_syslog_config,
|
||||
HOST, USER, PASSWORD)
|
||||
|
||||
def test_reset_syslog_config_esxi_hosts_not_list(self):
|
||||
'''
|
||||
Tests CommandExecutionError is raised when esxi_hosts is provided,
|
||||
but is not a list.
|
||||
'''
|
||||
self.assertRaises(CommandExecutionError,
|
||||
vsphere.reset_syslog_config,
|
||||
HOST, USER, PASSWORD, syslog_config='test', esxi_hosts='foo')
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={}))
|
||||
def test_reset_syslog_config_invalid_config_param(self):
|
||||
'''
|
||||
Tests error message returned when an invalid syslog_config parameter is provided.
|
||||
'''
|
||||
error = 'Invalid syslog configuration parameter'
|
||||
self.assertEqual({HOST: {'success': False, 'test': {'message': error, 'success': False}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='test'))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_reset_syslog_config_host_list_bad_retcode(self):
|
||||
'''
|
||||
Tests error message returned with list of esxi_hosts.
|
||||
'''
|
||||
host_1 = 'host_1.foo.com'
|
||||
self.assertEqual({host_1: {'success': False, 'logdir': {'message': ERROR, 'success': False}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='logdir',
|
||||
esxi_hosts=[host_1]))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_reset_syslog_config_host_list_success(self):
|
||||
'''
|
||||
Tests successful function return when an esxi_host is provided.
|
||||
'''
|
||||
host_1 = 'host_1.foo.com'
|
||||
self.assertEqual({host_1: {'success': True, 'loghost': {'success': True}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='loghost',
|
||||
esxi_hosts=[host_1]))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_reset_syslog_config_bad_retcode(self):
|
||||
'''
|
||||
Tests error message given for a single ESXi host.
|
||||
'''
|
||||
self.assertEqual({HOST: {'success': False, 'logdir-unique': {'message': ERROR, 'success': False}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='logdir-unique'))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_reset_syslog_config_success(self):
|
||||
'''
|
||||
Tests successful function return for a single ESXi host.
|
||||
'''
|
||||
self.assertEqual({HOST: {'success': True, 'default-rotate': {'success': True}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='default-rotate'))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_reset_syslog_config_success_multiple_configs(self):
|
||||
'''
|
||||
Tests successful function return for a single ESXi host when passing in multiple syslog_config values.
|
||||
'''
|
||||
self.assertEqual({HOST: {'success': True,
|
||||
'default-size': {'success': True},
|
||||
'default-timeout': {'success': True}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='default-size,default-timeout'))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0, 'stdout': ''}))
|
||||
def test_reset_syslog_config_success_all_configs(self):
|
||||
'''
|
||||
Tests successful function return for a single ESXi host when passing in multiple syslog_config values.
|
||||
'''
|
||||
self.assertEqual({HOST: {'success': True,
|
||||
'logdir': {'success': True},
|
||||
'loghost': {'success': True},
|
||||
'default-rotate': {'success': True},
|
||||
'default-size': {'success': True},
|
||||
'default-timeout': {'success': True},
|
||||
'logdir-unique': {'success': True}}},
|
||||
vsphere.reset_syslog_config(HOST, USER, PASSWORD,
|
||||
syslog_config='all'))
|
||||
|
||||
# Tests for _reset_syslog_config_params function
|
||||
|
||||
def test_reset_syslog_config_params_no_valid_reset(self):
|
||||
'''
|
||||
Tests function returns False when an invalid syslog config is passed.
|
||||
'''
|
||||
valid_resets = ['hello', 'world']
|
||||
config = 'foo'
|
||||
ret = {'success': False, config: {'success': False, 'message': 'Invalid syslog configuration parameter'}}
|
||||
self.assertEqual(ret, vsphere._reset_syslog_config_params(HOST, USER, PASSWORD,
|
||||
'cmd', config, valid_resets))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_reset_syslog_config_params_error(self):
|
||||
'''
|
||||
Tests function returns False when the esxxli function returns an unsuccessful retcode.
|
||||
'''
|
||||
valid_resets = ['hello', 'world']
|
||||
error_dict = {'success': False, 'message': ERROR}
|
||||
ret = {'success': False, 'hello': error_dict, 'world': error_dict}
|
||||
self.assertDictEqual(ret, vsphere._reset_syslog_config_params(HOST, USER, PASSWORD,
|
||||
'cmd', valid_resets, valid_resets))
|
||||
|
||||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 0}))
|
||||
def test_reset_syslog_config_params_success(self):
|
||||
'''
|
||||
Tests function returns True when the esxxli function returns a successful retcode.
|
||||
'''
|
||||
valid_resets = ['hello', 'world']
|
||||
ret = {'success': True, 'hello': {'success': True}, 'world': {'success': True}}
|
||||
self.assertDictEqual(ret, vsphere._reset_syslog_config_params(HOST, USER, PASSWORD,
|
||||
'cmd', valid_resets, valid_resets))
|
||||
|
||||
# Tests for _set_syslog_config_helper function
|
||||
|
||||
def test_set_syslog_config_helper_no_valid_reset(self):
|
||||
'''
|
||||
Tests function returns False when an invalid syslog config is passed.
|
||||
|
@ -359,7 +534,7 @@ class VsphereTestCase(TestCase):
|
|||
@patch('salt.utils.vmware.esxcli', MagicMock(return_value={'retcode': 1, 'stdout': ERROR}))
|
||||
def test_set_syslog_config_helper_bad_retcode(self):
|
||||
'''
|
||||
Tests function returns False when the esxcli function returns a unsuccessful retcode.
|
||||
Tests function returns False when the esxcli function returns an unsuccessful retcode.
|
||||
'''
|
||||
config = 'default-rotate'
|
||||
self.assertEqual({config: {'success': False, 'message': ERROR}},
|
||||
|
|
Loading…
Add table
Reference in a new issue