mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Added tests for salt.modules.vsphere.remove_diskgroup
This commit is contained in:
parent
4e0755de20
commit
ec2637db44
1 changed files with 92 additions and 0 deletions
|
@ -1346,6 +1346,98 @@ class RemoveDatastoreTestCase(TestCase, LoaderModuleMockMixin):
|
|||
self.assertTrue(res)
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class RemoveDiskgroupTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''Tests for salt.modules.vsphere.remove_diskgroup'''
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
'__virtual__': MagicMock(return_value='vsphere'),
|
||||
'_get_proxy_connection_details': MagicMock(),
|
||||
'__proxy__': {'esxi.get_details': MagicMock(
|
||||
return_value={'esxi_host': 'fake_host'})}
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
attrs = (('mock_si', MagicMock()),
|
||||
('mock_host', MagicMock()),
|
||||
('mock_diskgroup', MagicMock()))
|
||||
for attr, mock_obj in attrs:
|
||||
setattr(self, attr, mock_obj)
|
||||
self.addCleanup(delattr, self, attr)
|
||||
|
||||
patches = (
|
||||
('salt.utils.vmware.get_service_instance',
|
||||
MagicMock(return_value=self.mock_si)),
|
||||
('salt.modules.vsphere.get_proxy_type',
|
||||
MagicMock(return_value='esxi')),
|
||||
('salt.modules.vsphere._get_proxy_target',
|
||||
MagicMock(return_value=self.mock_host)),
|
||||
('salt.utils.vmware.get_diskgroups',
|
||||
MagicMock(return_value=[self.mock_diskgroup])),
|
||||
('salt.utils.vsan.remove_diskgroup', MagicMock()))
|
||||
for module, mock_obj in patches:
|
||||
patcher = patch(module, mock_obj)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_supported_proxes(self):
|
||||
supported_proxies = ['esxi']
|
||||
for proxy_type in supported_proxies:
|
||||
with patch('salt.modules.vsphere.get_proxy_type',
|
||||
MagicMock(return_value=proxy_type)):
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
|
||||
def test__get_proxy_target_call(self):
|
||||
mock__get_proxy_target = MagicMock(return_value=self.mock_host)
|
||||
with patch('salt.modules.vsphere._get_proxy_target',
|
||||
mock__get_proxy_target):
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
mock__get_proxy_target.assert_called_once_with(self.mock_si)
|
||||
|
||||
def test_get_disk_groups(self):
|
||||
mock_get_diskgroups = MagicMock(return_value=[self.mock_diskgroup])
|
||||
with patch('salt.utils.vmware.get_diskgroups',
|
||||
mock_get_diskgroups):
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
mock_get_diskgroups.assert_called_once_with(
|
||||
self.mock_host, cache_disk_ids=['fake_disk_id'])
|
||||
|
||||
def test_disk_group_not_found_safety_checks_set(self):
|
||||
with patch('salt.utils.vmware.get_diskgroups',
|
||||
MagicMock(return_value=[])):
|
||||
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
self.assertEqual('No diskgroup with cache disk id '
|
||||
'\'fake_disk_id\' was found in ESXi host '
|
||||
'\'fake_host\'',
|
||||
excinfo.exception.strerror)
|
||||
|
||||
def test_remove_disk_group(self):
|
||||
mock_remove_diskgroup = MagicMock(return_value=None)
|
||||
with patch('salt.utils.vsan.remove_diskgroup',
|
||||
mock_remove_diskgroup):
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
mock_remove_diskgroup.assert_called_once_with(
|
||||
self.mock_si, self.mock_host, self.mock_diskgroup,
|
||||
data_accessibility=True)
|
||||
|
||||
def test_remove_disk_group_data_accessibility_false(self):
|
||||
mock_remove_diskgroup = MagicMock(return_value=None)
|
||||
with patch('salt.utils.vsan.remove_diskgroup',
|
||||
mock_remove_diskgroup):
|
||||
vsphere.remove_diskgroup(cache_disk_id='fake_disk_id',
|
||||
data_accessibility=False)
|
||||
mock_remove_diskgroup.assert_called_once_with(
|
||||
self.mock_si, self.mock_host, self.mock_diskgroup,
|
||||
data_accessibility=False)
|
||||
|
||||
def test_success_output(self):
|
||||
res = vsphere.remove_diskgroup(cache_disk_id='fake_disk_id')
|
||||
self.assertTrue(res)
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class ListClusterTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''Tests for salt.modules.vsphere.list_cluster'''
|
||||
|
|
Loading…
Add table
Reference in a new issue