mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge branch 'develop' into boto_lc
This commit is contained in:
commit
995e9cb608
4
.github/stale.yml
vendored
4
.github/stale.yml
vendored
@ -1,8 +1,8 @@
|
|||||||
# Probot Stale configuration file
|
# Probot Stale configuration file
|
||||||
|
|
||||||
# Number of days of inactivity before an issue becomes stale
|
# Number of days of inactivity before an issue becomes stale
|
||||||
# 1000 is approximately 2 years and 9 months
|
# 975 is approximately 2 years and 8 months
|
||||||
daysUntilStale: 1000
|
daysUntilStale: 975
|
||||||
|
|
||||||
# Number of days of inactivity before a stale issue is closed
|
# Number of days of inactivity before a stale issue is closed
|
||||||
daysUntilClose: 7
|
daysUntilClose: 7
|
||||||
|
@ -325,7 +325,7 @@ The following example works on UNIX-like operating systems:
|
|||||||
|
|
||||||
.. code-block:: jinja
|
.. code-block:: jinja
|
||||||
|
|
||||||
{%- if grains['os'] != 'Windows' %
|
{%- if grains['os'] != 'Windows' %}
|
||||||
Restart Salt Minion:
|
Restart Salt Minion:
|
||||||
cmd.run:
|
cmd.run:
|
||||||
- name: 'salt-call --local service.restart salt-minion'
|
- name: 'salt-call --local service.restart salt-minion'
|
||||||
|
@ -67,7 +67,7 @@ _su_cmd() {
|
|||||||
|
|
||||||
|
|
||||||
_get_pid() {
|
_get_pid() {
|
||||||
netstat $NS_NOTRIM -ap --protocol=unix 2>$ERROR_TO_DEVNULL \
|
netstat -n $NS_NOTRIM -ap --protocol=unix 2>$ERROR_TO_DEVNULL \
|
||||||
| sed -r -e "\|\s${SOCK_DIR}/minion_event_${MINION_ID_HASH}_pub\.ipc$|"'!d; s|/.*||; s/.*\s//;' \
|
| sed -r -e "\|\s${SOCK_DIR}/minion_event_${MINION_ID_HASH}_pub\.ipc$|"'!d; s|/.*||; s/.*\s//;' \
|
||||||
| uniq
|
| uniq
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ start() {
|
|||||||
printf "\nPROCESSES:\n" >&2
|
printf "\nPROCESSES:\n" >&2
|
||||||
ps wwwaxu | grep '[s]alt-minion' >&2
|
ps wwwaxu | grep '[s]alt-minion' >&2
|
||||||
printf "\nSOCKETS:\n" >&2
|
printf "\nSOCKETS:\n" >&2
|
||||||
netstat $NS_NOTRIM -ap --protocol=unix | grep 'salt.*minion' >&2
|
netstat -n $NS_NOTRIM -ap --protocol=unix | grep 'salt.*minion' >&2
|
||||||
printf "\nLOG_FILE:\n" >&2
|
printf "\nLOG_FILE:\n" >&2
|
||||||
tail -n 20 "$LOG_FILE" >&2
|
tail -n 20 "$LOG_FILE" >&2
|
||||||
printf "\nENVIRONMENT:\n" >&2
|
printf "\nENVIRONMENT:\n" >&2
|
||||||
|
@ -659,11 +659,12 @@ def list_subnets(call=None, kwargs=None): # pylint: disable=unused-argument
|
|||||||
for subnet in subnets:
|
for subnet in subnets:
|
||||||
ret[subnet.name] = make_safe(subnet)
|
ret[subnet.name] = make_safe(subnet)
|
||||||
ret[subnet.name]['ip_configurations'] = {}
|
ret[subnet.name]['ip_configurations'] = {}
|
||||||
for ip_ in subnet.ip_configurations:
|
if subnet.ip_configurations:
|
||||||
comps = ip_.id.split('/')
|
for ip_ in subnet.ip_configurations:
|
||||||
name = comps[-1]
|
comps = ip_.id.split('/')
|
||||||
ret[subnet.name]['ip_configurations'][name] = make_safe(ip_)
|
name = comps[-1]
|
||||||
ret[subnet.name]['ip_configurations'][name]['subnet'] = subnet.name
|
ret[subnet.name]['ip_configurations'][name] = make_safe(ip_)
|
||||||
|
ret[subnet.name]['ip_configurations'][name]['subnet'] = subnet.name
|
||||||
ret[subnet.name]['resource_group'] = kwargs['resource_group']
|
ret[subnet.name]['resource_group'] = kwargs['resource_group']
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -749,12 +749,13 @@ def list_nodes(full=False, call=None):
|
|||||||
log.error('Invalid response when listing Joyent nodes: {0}'.format(result[1]))
|
log.error('Invalid response when listing Joyent nodes: {0}'.format(result[1]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
result = query(command='my/machines', location=DEFAULT_LOCATION,
|
location = get_location()
|
||||||
|
result = query(command='my/machines', location=location,
|
||||||
method='GET')
|
method='GET')
|
||||||
nodes = result[1]
|
nodes = result[1]
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if 'name' in node:
|
if 'name' in node:
|
||||||
node['location'] = DEFAULT_LOCATION
|
node['location'] = location
|
||||||
ret[node['name']] = reformat_node(item=node, full=full)
|
ret[node['name']] = reformat_node(item=node, full=full)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -265,6 +265,11 @@ def update():
|
|||||||
os.unlink(lk_fn)
|
os.unlink(lk_fn)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
hash_cachedir = os.path.join(__opts__['cachedir'], 'azurefs', 'hashes')
|
||||||
|
shutil.rmtree(hash_cachedir)
|
||||||
|
except Exception:
|
||||||
|
log.exception('Problem occurred trying to invalidate hash cach for azurefs')
|
||||||
|
|
||||||
|
|
||||||
def file_hash(load, fnd):
|
def file_hash(load, fnd):
|
||||||
|
@ -970,7 +970,7 @@ class Minion(MinionBase):
|
|||||||
# Flag meaning minion has finished initialization including first connect to the master.
|
# Flag meaning minion has finished initialization including first connect to the master.
|
||||||
# True means the Minion is fully functional and ready to handle events.
|
# True means the Minion is fully functional and ready to handle events.
|
||||||
self.ready = False
|
self.ready = False
|
||||||
self.jid_queue = jid_queue
|
self.jid_queue = jid_queue or []
|
||||||
|
|
||||||
if io_loop is None:
|
if io_loop is None:
|
||||||
if HAS_ZMQ:
|
if HAS_ZMQ:
|
||||||
|
@ -4358,7 +4358,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
|
|||||||
is_dir = os.path.isdir(name)
|
is_dir = os.path.isdir(name)
|
||||||
if not salt.utils.platform.is_windows() and not is_dir and lsattr_cmd:
|
if not salt.utils.platform.is_windows() and not is_dir and lsattr_cmd:
|
||||||
# List attributes on file
|
# List attributes on file
|
||||||
perms['lattrs'] = ''.join(lsattr(name)[name])
|
perms['lattrs'] = ''.join(lsattr(name).get('name', ''))
|
||||||
# Remove attributes on file so changes can be enforced.
|
# Remove attributes on file so changes can be enforced.
|
||||||
if perms['lattrs']:
|
if perms['lattrs']:
|
||||||
chattr(name, operator='remove', attributes=perms['lattrs'])
|
chattr(name, operator='remove', attributes=perms['lattrs'])
|
||||||
|
@ -5672,7 +5672,6 @@ def remove_datastore(datastore, service_instance=None):
|
|||||||
'''
|
'''
|
||||||
log.trace('Removing datastore \'{0}\''.format(datastore))
|
log.trace('Removing datastore \'{0}\''.format(datastore))
|
||||||
target = _get_proxy_target(service_instance)
|
target = _get_proxy_target(service_instance)
|
||||||
taget_name = target.name
|
|
||||||
datastores = salt.utils.vmware.get_datastores(
|
datastores = salt.utils.vmware.get_datastores(
|
||||||
service_instance,
|
service_instance,
|
||||||
reference=target,
|
reference=target,
|
||||||
@ -6340,7 +6339,7 @@ def remove_capacity_from_diskgroup(cache_disk_id, capacity_disk_ids,
|
|||||||
'capacity_ids': capacity_disk_ids}]},
|
'capacity_ids': capacity_disk_ids}]},
|
||||||
schema)
|
schema)
|
||||||
except jsonschema.exceptions.ValidationError as exc:
|
except jsonschema.exceptions.ValidationError as exc:
|
||||||
raise ArgumentValueError(exc)
|
raise ArgumentValueError(str(exc))
|
||||||
host_ref = _get_proxy_target(service_instance)
|
host_ref = _get_proxy_target(service_instance)
|
||||||
hostname = __proxy__['esxi.get_details']()['esxi_host']
|
hostname = __proxy__['esxi.get_details']()['esxi_host']
|
||||||
disks = salt.utils.vmware.get_disks(host_ref, disk_ids=capacity_disk_ids)
|
disks = salt.utils.vmware.get_disks(host_ref, disk_ids=capacity_disk_ids)
|
||||||
@ -6390,7 +6389,6 @@ def remove_diskgroup(cache_disk_id, data_accessibility=True,
|
|||||||
salt '*' vsphere.remove_diskgroup cache_disk_id='naa.000000000000001'
|
salt '*' vsphere.remove_diskgroup cache_disk_id='naa.000000000000001'
|
||||||
'''
|
'''
|
||||||
log.trace('Validating diskgroup input')
|
log.trace('Validating diskgroup input')
|
||||||
schema = DiskGroupsDiskIdSchema.serialize()
|
|
||||||
host_ref = _get_proxy_target(service_instance)
|
host_ref = _get_proxy_target(service_instance)
|
||||||
hostname = __proxy__['esxi.get_details']()['esxi_host']
|
hostname = __proxy__['esxi.get_details']()['esxi_host']
|
||||||
diskgroups = \
|
diskgroups = \
|
||||||
|
@ -265,9 +265,12 @@ def get_load(jid):
|
|||||||
except couchbase.exceptions.NotFoundError:
|
except couchbase.exceptions.NotFoundError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
ret = jid_doc.value['load']
|
ret = {}
|
||||||
if 'minions' in jid_doc.value:
|
try:
|
||||||
|
ret = jid_doc.value['load']
|
||||||
ret['Minions'] = jid_doc.value['minions']
|
ret['Minions'] = jid_doc.value['minions']
|
||||||
|
except KeyError as e:
|
||||||
|
log.error(e)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -1173,6 +1173,437 @@ class CreateDatacenterTestCase(TestCase, LoaderModuleMockMixin):
|
|||||||
self.assertEqual(res, {'create_datacenter': True})
|
self.assertEqual(res, {'create_datacenter': True})
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
class EraseDiskPartitionsTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
'''Tests for salt.modules.vsphere.erase_disk_partitions'''
|
||||||
|
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()))
|
||||||
|
for attr, mock_obj in attrs:
|
||||||
|
setattr(self, attr, mock_obj)
|
||||||
|
self.addCleanup(delattr, self, attr)
|
||||||
|
attrs = (('mock_proxy_target', MagicMock(return_value=self.mock_host)),
|
||||||
|
('mock_erase_disk_partitions', 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.erase_disk_partitions',
|
||||||
|
self.mock_erase_disk_partitions))
|
||||||
|
for module, mock_obj in patches:
|
||||||
|
patcher = patch(module, mock_obj)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_supported_proxies(self):
|
||||||
|
supported_proxies = ['esxi']
|
||||||
|
for proxy_type in supported_proxies:
|
||||||
|
with patch('salt.modules.vsphere.get_proxy_type',
|
||||||
|
MagicMock(return_value=proxy_type)):
|
||||||
|
vsphere.erase_disk_partitions(disk_id='fake_disk')
|
||||||
|
|
||||||
|
def test_no_disk_id_or_scsi_address(self):
|
||||||
|
with self.assertRaises(ArgumentValueError) as excinfo:
|
||||||
|
vsphere.erase_disk_partitions()
|
||||||
|
self.assertEqual('Either \'disk_id\' or \'scsi_address\' needs to '
|
||||||
|
'be specified', excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_get_proxy_target(self):
|
||||||
|
mock_test_proxy_target = MagicMock()
|
||||||
|
with patch('salt.modules.vsphere._get_proxy_target',
|
||||||
|
mock_test_proxy_target):
|
||||||
|
vsphere.erase_disk_partitions(disk_id='fake_disk')
|
||||||
|
mock_test_proxy_target.assert_called_once_with(self.mock_si)
|
||||||
|
|
||||||
|
def test_scsi_address_not_found(self):
|
||||||
|
mock = MagicMock(return_value={'bad_scsi_address': 'bad_disk_id'})
|
||||||
|
with patch('salt.utils.vmware.get_scsi_address_to_lun_map', mock):
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsphere.erase_disk_partitions(scsi_address='fake_scsi_address')
|
||||||
|
self.assertEqual('Scsi lun with address \'fake_scsi_address\' was '
|
||||||
|
'not found on host \'fake_host\'',
|
||||||
|
excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_scsi_address_to_disk_id_map(self):
|
||||||
|
mock_disk_id = MagicMock(canonicalName='fake_scsi_disk_id')
|
||||||
|
mock_get_scsi_addr_to_lun = \
|
||||||
|
MagicMock(return_value={'fake_scsi_address': mock_disk_id})
|
||||||
|
with patch('salt.utils.vmware.get_scsi_address_to_lun_map',
|
||||||
|
mock_get_scsi_addr_to_lun):
|
||||||
|
vsphere.erase_disk_partitions(scsi_address='fake_scsi_address')
|
||||||
|
mock_get_scsi_addr_to_lun.assert_called_once_with(self.mock_host)
|
||||||
|
self.mock_erase_disk_partitions.assert_called_once_with(
|
||||||
|
self.mock_si, self.mock_host, 'fake_scsi_disk_id',
|
||||||
|
hostname='fake_host')
|
||||||
|
|
||||||
|
def test_erase_disk_partitions(self):
|
||||||
|
vsphere.erase_disk_partitions(disk_id='fake_disk_id')
|
||||||
|
self.mock_erase_disk_partitions.assert_called_once_with(
|
||||||
|
self.mock_si, self.mock_host, 'fake_disk_id', hostname='fake_host')
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
class RemoveDatastoreTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
'''Tests for salt.modules.vsphere.remove_datastore'''
|
||||||
|
def setup_loader_modules(self):
|
||||||
|
return {
|
||||||
|
vsphere: {
|
||||||
|
'__virtual__': MagicMock(return_value='vsphere'),
|
||||||
|
'_get_proxy_connection_details': MagicMock(),
|
||||||
|
'get_proxy_type': MagicMock(return_value='esxdatacenter'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
attrs = (('mock_si', MagicMock()),
|
||||||
|
('mock_target', MagicMock()),
|
||||||
|
('mock_ds', 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='esxdatacenter')),
|
||||||
|
('salt.modules.vsphere._get_proxy_target',
|
||||||
|
MagicMock(return_value=self.mock_target)),
|
||||||
|
('salt.utils.vmware.get_datastores',
|
||||||
|
MagicMock(return_value=[self.mock_ds])),
|
||||||
|
('salt.utils.vmware.remove_datastore', 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', 'esxcluster', 'esxdatacenter']
|
||||||
|
for proxy_type in supported_proxies:
|
||||||
|
with patch('salt.modules.vsphere.get_proxy_type',
|
||||||
|
MagicMock(return_value=proxy_type)):
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds_name')
|
||||||
|
|
||||||
|
def test__get_proxy_target_call(self):
|
||||||
|
mock__get_proxy_target = MagicMock(return_value=self.mock_target)
|
||||||
|
with patch('salt.modules.vsphere._get_proxy_target',
|
||||||
|
mock__get_proxy_target):
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds_name')
|
||||||
|
mock__get_proxy_target.assert_called_once_with(self.mock_si)
|
||||||
|
|
||||||
|
def test_get_datastores_call(self):
|
||||||
|
mock_get_datastores = MagicMock()
|
||||||
|
with patch('salt.utils.vmware.get_datastores',
|
||||||
|
mock_get_datastores):
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds')
|
||||||
|
mock_get_datastores.assert_called_once_with(
|
||||||
|
self.mock_si, reference=self.mock_target,
|
||||||
|
datastore_names=['fake_ds'])
|
||||||
|
|
||||||
|
def test_datastore_not_found(self):
|
||||||
|
with patch('salt.utils.vmware.get_datastores',
|
||||||
|
MagicMock(return_value=[])):
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds')
|
||||||
|
self.assertEqual('Datastore \'fake_ds\' was not found',
|
||||||
|
excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_multiple_datastores_found(self):
|
||||||
|
with patch('salt.utils.vmware.get_datastores',
|
||||||
|
MagicMock(return_value=[MagicMock(), MagicMock()])):
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds')
|
||||||
|
self.assertEqual('Multiple datastores \'fake_ds\' were found',
|
||||||
|
excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_remove_datastore_call(self):
|
||||||
|
mock_remove_datastore = MagicMock()
|
||||||
|
with patch('salt.utils.vmware.remove_datastore',
|
||||||
|
mock_remove_datastore):
|
||||||
|
vsphere.remove_datastore(datastore='fake_ds')
|
||||||
|
mock_remove_datastore.assert_called_once_with(
|
||||||
|
self.mock_si, self.mock_ds)
|
||||||
|
|
||||||
|
def test_success_output(self):
|
||||||
|
res = vsphere.remove_datastore(datastore='fake_ds')
|
||||||
|
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)
|
||||||
|
@skipIf(not vsphere.HAS_JSONSCHEMA, 'The \'jsonschema\' library is missing')
|
||||||
|
class RemoveCapacityFromDiskgroupTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
'''Tests for salt.modules.vsphere.remove_capacity_from_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_schema', MagicMock()),
|
||||||
|
('mock_host', MagicMock()),
|
||||||
|
('mock_disk1', MagicMock(canonicalName='fake_disk1')),
|
||||||
|
('mock_disk2', MagicMock(canonicalName='fake_disk2')),
|
||||||
|
('mock_disk3', MagicMock(canonicalName='fake_disk3')),
|
||||||
|
('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.DiskGroupsDiskIdSchema.serialize',
|
||||||
|
MagicMock(return_value=self.mock_schema)),
|
||||||
|
('salt.modules.vsphere.jsonschema.validate', MagicMock()),
|
||||||
|
('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_disks',
|
||||||
|
MagicMock(return_value=[self.mock_disk1, self.mock_disk2,
|
||||||
|
self.mock_disk3])),
|
||||||
|
('salt.utils.vmware.get_diskgroups',
|
||||||
|
MagicMock(return_value=[self.mock_diskgroup])),
|
||||||
|
('salt.utils.vsan.remove_capacity_from_diskgroup', MagicMock()))
|
||||||
|
for module, mock_obj in patches:
|
||||||
|
patcher = patch(module, mock_obj)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_validate(self):
|
||||||
|
mock_schema_validate = MagicMock()
|
||||||
|
with patch('salt.modules.vsphere.jsonschema.validate',
|
||||||
|
mock_schema_validate):
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
mock_schema_validate.assert_called_once_with(
|
||||||
|
{'diskgroups': [{'cache_id': 'fake_cache_disk_id',
|
||||||
|
'capacity_ids': ['fake_disk1',
|
||||||
|
'fake_disk2']}]},
|
||||||
|
self.mock_schema)
|
||||||
|
|
||||||
|
def test_invalid_schema_validation(self):
|
||||||
|
mock_schema_validate = MagicMock(
|
||||||
|
side_effect=vsphere.jsonschema.exceptions.ValidationError('err'))
|
||||||
|
with patch('salt.modules.vsphere.jsonschema.validate',
|
||||||
|
mock_schema_validate):
|
||||||
|
with self.assertRaises(ArgumentValueError) as excinfo:
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
self.assertEqual('err', excinfo.exception.strerror)
|
||||||
|
|
||||||
|
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_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
|
||||||
|
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_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
mock__get_proxy_target.assert_called_once_with(self.mock_si)
|
||||||
|
|
||||||
|
def test_get_disks(self):
|
||||||
|
mock_get_disks = MagicMock(
|
||||||
|
return_value=[self.mock_disk1, self.mock_disk2, self.mock_disk3])
|
||||||
|
with patch('salt.utils.vmware.get_disks', mock_get_disks):
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
mock_get_disks.assert_called_once_with(
|
||||||
|
self.mock_host, disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
|
||||||
|
def test_disk_not_found_safety_checks_set(self):
|
||||||
|
mock_get_disks = MagicMock(
|
||||||
|
return_value=[self.mock_disk1, self.mock_disk2, self.mock_disk3])
|
||||||
|
with patch('salt.utils.vmware.get_disks', mock_get_disks):
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk4'],
|
||||||
|
safety_checks=True)
|
||||||
|
self.assertEqual('No disk with id \'fake_disk4\' was found '
|
||||||
|
'in ESXi host \'fake_host\'',
|
||||||
|
excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_get_diskgroups(self):
|
||||||
|
mock_get_diskgroups = MagicMock(return_value=[self.mock_diskgroup])
|
||||||
|
with patch('salt.utils.vmware.get_diskgroups',
|
||||||
|
mock_get_diskgroups):
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
mock_get_diskgroups.assert_called_once_with(
|
||||||
|
self.mock_host, cache_disk_ids=['fake_cache_disk_id'])
|
||||||
|
|
||||||
|
def test_diskgroup_not_found(self):
|
||||||
|
with patch('salt.utils.vmware.get_diskgroups',
|
||||||
|
MagicMock(return_value=[])):
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
self.assertEqual('No diskgroup with cache disk id '
|
||||||
|
'\'fake_cache_disk_id\' was found in ESXi host '
|
||||||
|
'\'fake_host\'',
|
||||||
|
excinfo.exception.strerror)
|
||||||
|
|
||||||
|
def test_remove_capacity_from_diskgroup(self):
|
||||||
|
mock_remove_capacity_from_diskgroup = MagicMock()
|
||||||
|
with patch('salt.utils.vsan.remove_capacity_from_diskgroup',
|
||||||
|
mock_remove_capacity_from_diskgroup):
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
mock_remove_capacity_from_diskgroup.assert_called_once_with(
|
||||||
|
self.mock_si, self.mock_host, self.mock_diskgroup,
|
||||||
|
capacity_disks=[self.mock_disk1, self.mock_disk2],
|
||||||
|
data_evacuation=True)
|
||||||
|
|
||||||
|
def test_remove_capacity_from_diskgroup_data_evacuation_false(self):
|
||||||
|
mock_remove_capacity_from_diskgroup = MagicMock()
|
||||||
|
with patch('salt.utils.vsan.remove_capacity_from_diskgroup',
|
||||||
|
mock_remove_capacity_from_diskgroup):
|
||||||
|
vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'],
|
||||||
|
data_evacuation=False)
|
||||||
|
mock_remove_capacity_from_diskgroup.assert_called_once_with(
|
||||||
|
self.mock_si, self.mock_host, self.mock_diskgroup,
|
||||||
|
capacity_disks=[self.mock_disk1, self.mock_disk2],
|
||||||
|
data_evacuation=False)
|
||||||
|
|
||||||
|
def test_success_output(self):
|
||||||
|
res = vsphere.remove_capacity_from_diskgroup(
|
||||||
|
cache_disk_id='fake_cache_disk_id',
|
||||||
|
capacity_disk_ids=['fake_disk1', 'fake_disk2'])
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
class ListClusterTestCase(TestCase, LoaderModuleMockMixin):
|
class ListClusterTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
'''Tests for salt.modules.vsphere.list_cluster'''
|
'''Tests for salt.modules.vsphere.list_cluster'''
|
||||||
|
@ -16,7 +16,8 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock, \
|
|||||||
PropertyMock
|
PropertyMock
|
||||||
|
|
||||||
# Import Salt libraries
|
# Import Salt libraries
|
||||||
from salt.exceptions import VMwareApiError, VMwareRuntimeError
|
from salt.exceptions import VMwareApiError, VMwareRuntimeError, \
|
||||||
|
VMwareObjectRetrievalError
|
||||||
from salt.utils import vsan
|
from salt.utils import vsan
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -137,6 +138,651 @@ class GetVsanClusterConfigSystemTestCase(TestCase, LoaderModuleMockMixin):
|
|||||||
self.assertEqual(ret, self.mock_ret)
|
self.assertEqual(ret, self.mock_ret)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'pyvsan\' bindings are missing')
|
||||||
|
class GetVsanDiskManagementSystemTestCase(TestCase, LoaderModuleMockMixin):
|
||||||
|
'''Tests for salt.utils.vsan.get_vsan_disk_management_system'''
|
||||||
|
def setup_loader_modules(self):
|
||||||
|
return {vsan: {
|
||||||
|
'__virtual__': MagicMock(return_value='vsan'),
|
||||||
|
'sys': MagicMock(),
|
||||||
|
'ssl': MagicMock()}}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_ret = MagicMock()
|
||||||
|
patches = (('salt.utils.vsan.vsanapiutils.GetVsanVcMos',
|
||||||
|
MagicMock(
|
||||||
|
return_value={'vsan-disk-management-system':
|
||||||
|
self.mock_ret})),)
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
type(vsan.sys).version_info = PropertyMock(return_value=(2, 7, 9))
|
||||||
|
self.mock_context = MagicMock()
|
||||||
|
self.mock_create_default_context = \
|
||||||
|
MagicMock(return_value=self.mock_context)
|
||||||
|
vsan.ssl.create_default_context = self.mock_create_default_context
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
for attr in ('mock_si', 'mock_ret', 'mock_context',
|
||||||
|
'mock_create_default_context'):
|
||||||
|
delattr(self, attr)
|
||||||
|
|
||||||
|
def test_ssl_default_context_loaded(self):
|
||||||
|
vsan.get_vsan_disk_management_system(self.mock_si)
|
||||||
|
self.mock_create_default_context.assert_called_once_with()
|
||||||
|
self.assertFalse(self.mock_context.check_hostname)
|
||||||
|
self.assertEqual(self.mock_context.verify_mode, vsan.ssl.CERT_NONE)
|
||||||
|
|
||||||
|
def test_ssl_default_context_not_loaded(self):
|
||||||
|
type(vsan.sys).version_info = PropertyMock(return_value=(2, 7, 8))
|
||||||
|
vsan.get_vsan_disk_management_system(self.mock_si)
|
||||||
|
self.assertEqual(self.mock_create_default_context.call_count, 0)
|
||||||
|
|
||||||
|
def test_GetVsanVcMos_call(self):
|
||||||
|
mock_get_vsan_vc_mos = MagicMock()
|
||||||
|
with patch('salt.utils.vsan.vsanapiutils.GetVsanVcMos',
|
||||||
|
mock_get_vsan_vc_mos):
|
||||||
|
vsan.get_vsan_disk_management_system(self.mock_si)
|
||||||
|
mock_get_vsan_vc_mos.assert_called_once_with(self.mock_si._stub,
|
||||||
|
context=self.mock_context)
|
||||||
|
|
||||||
|
def test_return(self):
|
||||||
|
ret = vsan.get_vsan_disk_management_system(self.mock_si)
|
||||||
|
self.assertEqual(ret, self.mock_ret)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
class GetHostVsanSystemTestCase(TestCase):
|
||||||
|
'''Tests for salt.utils.vsan.get_host_vsan_system'''
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_host_ref = MagicMock()
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_traversal_spec = MagicMock()
|
||||||
|
self.mock_vsan_system = MagicMock()
|
||||||
|
patches = (
|
||||||
|
('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')),
|
||||||
|
('salt.utils.vsan.vmodl.query.PropertyCollector.TraversalSpec',
|
||||||
|
MagicMock(return_value=self.mock_traversal_spec)),
|
||||||
|
('salt.utils.vmware.get_mors_with_properties',
|
||||||
|
MagicMock(return_value=self.mock_traversal_spec)),
|
||||||
|
('salt.utils.vmware.get_mors_with_properties',
|
||||||
|
MagicMock(return_value=[{'object': self.mock_vsan_system}])))
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_get_hostname(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
mock_get_managed_object_name):
|
||||||
|
vsan.get_host_vsan_system(self.mock_si, self.mock_host_ref)
|
||||||
|
mock_get_managed_object_name.assert_called_once_with(
|
||||||
|
self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_hostname_argument(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')):
|
||||||
|
vsan.get_host_vsan_system(self.mock_si,
|
||||||
|
self.mock_host_ref,
|
||||||
|
hostname='passedin_hostname')
|
||||||
|
self.assertEqual(mock_get_managed_object_name.call_count, 0)
|
||||||
|
|
||||||
|
def test_traversal_spec(self):
|
||||||
|
mock_traversal_spec = MagicMock(return_value=self.mock_traversal_spec)
|
||||||
|
with patch(
|
||||||
|
'salt.utils.vmware.vmodl.query.PropertyCollector.TraversalSpec',
|
||||||
|
mock_traversal_spec):
|
||||||
|
|
||||||
|
vsan.get_host_vsan_system(self.mock_si, self.mock_host_ref)
|
||||||
|
mock_traversal_spec.assert_called_once_with(
|
||||||
|
path='configManager.vsanSystem',
|
||||||
|
type=vim.HostSystem,
|
||||||
|
skip=False)
|
||||||
|
|
||||||
|
def test_get_mors_with_properties(self):
|
||||||
|
mock_get_mors = \
|
||||||
|
MagicMock(return_value=[{'object': self.mock_vsan_system}])
|
||||||
|
with patch('salt.utils.vmware.get_mors_with_properties',
|
||||||
|
mock_get_mors):
|
||||||
|
vsan.get_host_vsan_system(self.mock_si, self.mock_host_ref)
|
||||||
|
mock_get_mors.assert_called_once_with(
|
||||||
|
self.mock_si,
|
||||||
|
vim.HostVsanSystem,
|
||||||
|
property_list=['config.enabled'],
|
||||||
|
container_ref=self.mock_host_ref,
|
||||||
|
traversal_spec=self.mock_traversal_spec)
|
||||||
|
|
||||||
|
def test_empty_mors_result(self):
|
||||||
|
mock_get_mors = MagicMock(return_value=None)
|
||||||
|
with patch('salt.utils.vmware.get_mors_with_properties',
|
||||||
|
mock_get_mors):
|
||||||
|
|
||||||
|
with self.assertRaises(VMwareObjectRetrievalError) as excinfo:
|
||||||
|
vsan.get_host_vsan_system(self.mock_si, self.mock_host_ref)
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Host\'s \'fake_hostname\' VSAN system was '
|
||||||
|
'not retrieved')
|
||||||
|
|
||||||
|
def test_valid_mors_result(self):
|
||||||
|
res = vsan.get_host_vsan_system(self.mock_si, self.mock_host_ref)
|
||||||
|
self.assertEqual(res, self.mock_vsan_system)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
class CreateDiskgroupTestCase(TestCase):
|
||||||
|
'''Tests for salt.utils.vsan.create_diskgroup'''
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_task = MagicMock()
|
||||||
|
self.mock_initialise_disk_mapping = \
|
||||||
|
MagicMock(return_value=self.mock_task)
|
||||||
|
self.mock_vsan_disk_mgmt_system = MagicMock(
|
||||||
|
InitializeDiskMappings=self.mock_initialise_disk_mapping)
|
||||||
|
self.mock_host_ref = MagicMock()
|
||||||
|
self.mock_cache_disk = MagicMock()
|
||||||
|
self.mock_cap_disk1 = MagicMock()
|
||||||
|
self.mock_cap_disk2 = MagicMock()
|
||||||
|
self.mock_spec = MagicMock()
|
||||||
|
patches = (
|
||||||
|
('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')),
|
||||||
|
('salt.utils.vsan.vim.VimVsanHostDiskMappingCreationSpec',
|
||||||
|
MagicMock(return_value=self.mock_spec)),
|
||||||
|
('salt.utils.vsan._wait_for_tasks', MagicMock()))
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_get_hostname(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
mock_get_managed_object_name):
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock_get_managed_object_name.assert_called_once_with(
|
||||||
|
self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_vsan_spec_all_flash(self):
|
||||||
|
self.mock_cap_disk1.ssd = True
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.capacityDisks, [self.mock_cap_disk1,
|
||||||
|
self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.cacheDisks, [self.mock_cache_disk])
|
||||||
|
self.assertEqual(self.mock_spec.creationType, 'allFlash')
|
||||||
|
self.assertEqual(self.mock_spec.host, self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_vsan_spec_hybrid(self):
|
||||||
|
self.mock_cap_disk1.ssd = False
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_cap_disk1.ssd = False
|
||||||
|
self.assertEqual(self.mock_spec.creationType, 'hybrid')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping(self):
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_initialise_disk_mapping.assert_called_once_with(
|
||||||
|
self.mock_spec)
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_no_permission(self):
|
||||||
|
err = vim.fault.NoPermission()
|
||||||
|
err.privilegeId = 'Fake privilege'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Not enough permissions. Required privilege: '
|
||||||
|
'Fake privilege')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_vim_fault(self):
|
||||||
|
err = vim.fault.VimFault()
|
||||||
|
err.msg = 'vim_fault'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'vim_fault')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_method_not_found(self):
|
||||||
|
err = vmodl.fault.MethodNotFound()
|
||||||
|
err.method = 'fake_method'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Method \'fake_method\' not found')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_runtime_fault(self):
|
||||||
|
err = vmodl.RuntimeFault()
|
||||||
|
err.msg = 'runtime_fault'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'runtime_fault')
|
||||||
|
|
||||||
|
def test__wait_for_tasks(self):
|
||||||
|
mock___wait_for_tasks = MagicMock()
|
||||||
|
with patch('salt.utils.vsan._wait_for_tasks',
|
||||||
|
mock___wait_for_tasks):
|
||||||
|
vsan.create_diskgroup(self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock___wait_for_tasks.assert_called_once_with(
|
||||||
|
[self.mock_task], self.mock_si)
|
||||||
|
|
||||||
|
def test_result(self):
|
||||||
|
res = vsan.create_diskgroup(self.mock_si,
|
||||||
|
self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_cache_disk,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
class AddCapacityToDiskGroupTestCase(TestCase):
|
||||||
|
'''Tests for salt.utils.vsan.add_capacity_to_diskgroup'''
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_task = MagicMock()
|
||||||
|
self.mock_initialise_disk_mapping = \
|
||||||
|
MagicMock(return_value=self.mock_task)
|
||||||
|
self.mock_vsan_disk_mgmt_system = MagicMock(
|
||||||
|
InitializeDiskMappings=self.mock_initialise_disk_mapping)
|
||||||
|
self.mock_host_ref = MagicMock()
|
||||||
|
self.mock_cache_disk = MagicMock()
|
||||||
|
self.mock_diskgroup = MagicMock(ssd=self.mock_cache_disk)
|
||||||
|
self.mock_cap_disk1 = MagicMock()
|
||||||
|
self.mock_cap_disk2 = MagicMock()
|
||||||
|
self.mock_spec = MagicMock()
|
||||||
|
patches = (
|
||||||
|
('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')),
|
||||||
|
('salt.utils.vsan.vim.VimVsanHostDiskMappingCreationSpec',
|
||||||
|
MagicMock(return_value=self.mock_spec)),
|
||||||
|
('salt.utils.vsan._wait_for_tasks', MagicMock()))
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_get_hostname(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
mock_get_managed_object_name):
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock_get_managed_object_name.assert_called_once_with(
|
||||||
|
self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_vsan_spec_all_flash(self):
|
||||||
|
self.mock_cap_disk1.ssd = True
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.capacityDisks, [self.mock_cap_disk1,
|
||||||
|
self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.cacheDisks, [self.mock_cache_disk])
|
||||||
|
self.assertEqual(self.mock_spec.creationType, 'allFlash')
|
||||||
|
self.assertEqual(self.mock_spec.host, self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_vsan_spec_hybrid(self):
|
||||||
|
self.mock_cap_disk1.ssd = False
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_cap_disk1.ssd = False
|
||||||
|
self.assertEqual(self.mock_spec.creationType, 'hybrid')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping(self):
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_initialise_disk_mapping.assert_called_once_with(
|
||||||
|
self.mock_spec)
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_no_permission(self):
|
||||||
|
err = vim.fault.NoPermission()
|
||||||
|
err.privilegeId = 'Fake privilege'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Not enough permissions. Required privilege: '
|
||||||
|
'Fake privilege')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_vim_fault(self):
|
||||||
|
err = vim.fault.VimFault()
|
||||||
|
err.msg = 'vim_fault'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'vim_fault')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_method_not_found(self):
|
||||||
|
err = vmodl.fault.MethodNotFound()
|
||||||
|
err.method = 'fake_method'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Method \'fake_method\' not found')
|
||||||
|
|
||||||
|
def test_initialize_disk_mapping_raise_runtime_fault(self):
|
||||||
|
err = vmodl.RuntimeFault()
|
||||||
|
err.msg = 'runtime_fault'
|
||||||
|
self.mock_vsan_disk_mgmt_system.InitializeDiskMappings = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'runtime_fault')
|
||||||
|
|
||||||
|
def test__wait_for_tasks(self):
|
||||||
|
mock___wait_for_tasks = MagicMock()
|
||||||
|
with patch('salt.utils.vsan._wait_for_tasks',
|
||||||
|
mock___wait_for_tasks):
|
||||||
|
vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock___wait_for_tasks.assert_called_once_with(
|
||||||
|
[self.mock_task], self.mock_si)
|
||||||
|
|
||||||
|
def test_result(self):
|
||||||
|
res = vsan.add_capacity_to_diskgroup(
|
||||||
|
self.mock_si, self.mock_vsan_disk_mgmt_system,
|
||||||
|
self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
class RemoveCapacityFromDiskGroup(TestCase):
|
||||||
|
'''Tests for salt.utils.vsan.remove_capacity_from_diskgroup'''
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_task = MagicMock()
|
||||||
|
self.mock_remove_disk = \
|
||||||
|
MagicMock(return_value=self.mock_task)
|
||||||
|
self.mock_host_vsan_system = MagicMock(
|
||||||
|
RemoveDisk_Task=self.mock_remove_disk)
|
||||||
|
self.mock_host_ref = MagicMock()
|
||||||
|
self.mock_cache_disk = MagicMock()
|
||||||
|
self.mock_diskgroup = MagicMock(ssd=self.mock_cache_disk)
|
||||||
|
self.mock_cap_disk1 = MagicMock()
|
||||||
|
self.mock_cap_disk2 = MagicMock()
|
||||||
|
self.mock_spec = MagicMock()
|
||||||
|
patches = (
|
||||||
|
('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')),
|
||||||
|
('salt.utils.vsan.get_host_vsan_system',
|
||||||
|
MagicMock(return_value=self.mock_host_vsan_system)),
|
||||||
|
('salt.utils.vsan.vim.HostMaintenanceSpec',
|
||||||
|
MagicMock(return_value=self.mock_spec)),
|
||||||
|
('salt.utils.vsan.vim.VsanHostDecommissionMode', MagicMock()),
|
||||||
|
('salt.utils.vmware.wait_for_task', MagicMock()))
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_get_hostname(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
mock_get_managed_object_name):
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock_get_managed_object_name.assert_called_once_with(
|
||||||
|
self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_maintenance_mode_evacuate_all_data(self):
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.vsanMode.objectAction,
|
||||||
|
vim.VsanHostDecommissionModeObjectAction.evacuateAllData)
|
||||||
|
|
||||||
|
def test_maintenance_mode_no_action(self):
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2],
|
||||||
|
data_evacuation=False)
|
||||||
|
self.assertEqual(self.mock_spec.vsanMode.objectAction,
|
||||||
|
vim.VsanHostDecommissionModeObjectAction.noAction)
|
||||||
|
|
||||||
|
def test_remove_disk(self):
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_remove_disk.assert_called_once_with(
|
||||||
|
disk=[self.mock_cap_disk1, self.mock_cap_disk2],
|
||||||
|
maintenanceSpec=self.mock_spec)
|
||||||
|
|
||||||
|
def test_remove_disk_raise_no_permission(self):
|
||||||
|
err = vim.fault.NoPermission()
|
||||||
|
err.privilegeId = 'Fake privilege'
|
||||||
|
self.mock_host_vsan_system.RemoveDisk_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Not enough permissions. Required privilege: '
|
||||||
|
'Fake privilege')
|
||||||
|
|
||||||
|
def test_remove_disk_raise_vim_fault(self):
|
||||||
|
err = vim.fault.VimFault()
|
||||||
|
err.msg = 'vim_fault'
|
||||||
|
self.mock_host_vsan_system.RemoveDisk_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'vim_fault')
|
||||||
|
|
||||||
|
def test_remove_disk_raise_runtime_fault(self):
|
||||||
|
err = vmodl.RuntimeFault()
|
||||||
|
err.msg = 'runtime_fault'
|
||||||
|
self.mock_host_vsan_system.RemoveDisk_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'runtime_fault')
|
||||||
|
|
||||||
|
def test_wait_for_tasks(self):
|
||||||
|
mock_wait_for_task = MagicMock()
|
||||||
|
with patch('salt.utils.vmware.wait_for_task',
|
||||||
|
mock_wait_for_task):
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
mock_wait_for_task.assert_called_once_with(
|
||||||
|
self.mock_task, 'fake_hostname', 'remove_capacity')
|
||||||
|
|
||||||
|
def test_result(self):
|
||||||
|
res = vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
class RemoveDiskgroup(TestCase):
|
||||||
|
'''Tests for salt.utils.vsan.remove_diskgroup'''
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_si = MagicMock()
|
||||||
|
self.mock_task = MagicMock()
|
||||||
|
self.mock_remove_disk_mapping = \
|
||||||
|
MagicMock(return_value=self.mock_task)
|
||||||
|
self.mock_host_vsan_system = MagicMock(
|
||||||
|
RemoveDiskMapping_Task=self.mock_remove_disk_mapping)
|
||||||
|
self.mock_host_ref = MagicMock()
|
||||||
|
self.mock_cache_disk = MagicMock()
|
||||||
|
self.mock_diskgroup = MagicMock(ssd=self.mock_cache_disk)
|
||||||
|
self.mock_cap_disk1 = MagicMock()
|
||||||
|
self.mock_cap_disk2 = MagicMock()
|
||||||
|
self.mock_spec = MagicMock()
|
||||||
|
patches = (
|
||||||
|
('salt.utils.vmware.get_managed_object_name',
|
||||||
|
MagicMock(return_value='fake_hostname')),
|
||||||
|
('salt.utils.vsan.get_host_vsan_system',
|
||||||
|
MagicMock(return_value=self.mock_host_vsan_system)),
|
||||||
|
('salt.utils.vsan.vim.HostMaintenanceSpec',
|
||||||
|
MagicMock(return_value=self.mock_spec)),
|
||||||
|
('salt.utils.vsan.vim.VsanHostDecommissionMode', MagicMock()),
|
||||||
|
('salt.utils.vmware.wait_for_task', MagicMock()))
|
||||||
|
for mod, mock in patches:
|
||||||
|
patcher = patch(mod, mock)
|
||||||
|
patcher.start()
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
def test_get_hostname(self):
|
||||||
|
mock_get_managed_object_name = MagicMock(return_value='fake_hostname')
|
||||||
|
with patch('salt.utils.vmware.get_managed_object_name',
|
||||||
|
mock_get_managed_object_name):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
mock_get_managed_object_name.assert_called_once_with(
|
||||||
|
self.mock_host_ref)
|
||||||
|
|
||||||
|
def test_maintenance_mode_evacuate_all_data(self):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.assertEqual(self.mock_spec.vsanMode.objectAction,
|
||||||
|
vim.VsanHostDecommissionModeObjectAction.evacuateAllData)
|
||||||
|
|
||||||
|
def test_maintenance_mode_no_action(self):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2],
|
||||||
|
data_evacuation=False)
|
||||||
|
self.assertEqual(self.mock_spec.vsanMode.objectAction,
|
||||||
|
vim.VsanHostDecommissionModeObjectAction.noAction)
|
||||||
|
|
||||||
|
def test_remove_disk_mapping(self):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
vsan.remove_capacity_from_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup,
|
||||||
|
[self.mock_cap_disk1, self.mock_cap_disk2])
|
||||||
|
self.mock_remove_disk_mapping.assert_called_once_with(
|
||||||
|
mapping=[self.mock_diskgroup],
|
||||||
|
maintenanceSpec=self.mock_spec)
|
||||||
|
|
||||||
|
def test_remove_disk_mapping_raise_no_permission(self):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
err = vim.fault.NoPermission()
|
||||||
|
err.privilegeId = 'Fake privilege'
|
||||||
|
self.mock_host_vsan_system.RemoveDiskMapping_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
self.assertEqual(excinfo.exception.strerror,
|
||||||
|
'Not enough permissions. Required privilege: '
|
||||||
|
'Fake privilege')
|
||||||
|
|
||||||
|
def test_remove_disk_mapping_raise_vim_fault(self):
|
||||||
|
err = vim.fault.VimFault()
|
||||||
|
err.msg = 'vim_fault'
|
||||||
|
self.mock_host_vsan_system.RemoveDiskMapping_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareApiError) as excinfo:
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'vim_fault')
|
||||||
|
|
||||||
|
def test_remove_disk_mapping_raise_runtime_fault(self):
|
||||||
|
err = vmodl.RuntimeFault()
|
||||||
|
err.msg = 'runtime_fault'
|
||||||
|
self.mock_host_vsan_system.RemoveDiskMapping_Task = \
|
||||||
|
MagicMock(side_effect=err)
|
||||||
|
with self.assertRaises(VMwareRuntimeError) as excinfo:
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
self.assertEqual(excinfo.exception.strerror, 'runtime_fault')
|
||||||
|
|
||||||
|
def test_wait_for_tasks(self):
|
||||||
|
mock_wait_for_task = MagicMock()
|
||||||
|
with patch('salt.utils.vmware.wait_for_task',
|
||||||
|
mock_wait_for_task):
|
||||||
|
vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
mock_wait_for_task.assert_called_once_with(
|
||||||
|
self.mock_task, 'fake_hostname', 'remove_diskgroup')
|
||||||
|
|
||||||
|
def test_result(self):
|
||||||
|
res = vsan.remove_diskgroup(
|
||||||
|
self.mock_si, self.mock_host_ref, self.mock_diskgroup)
|
||||||
|
self.assertTrue(res)
|
||||||
|
|
||||||
|
|
||||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
@skipIf(not HAS_PYVMOMI, 'The \'pyvmomi\' library is missing')
|
||||||
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
@skipIf(not HAS_PYVSAN, 'The \'vsan\' ext library is missing')
|
||||||
|
Loading…
Reference in New Issue
Block a user