mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Pep compliance, I hope
This commit is contained in:
parent
63eebebdfb
commit
61e84c03ae
2 changed files with 466 additions and 172 deletions
|
@ -9107,7 +9107,7 @@ def list_tag_categories(server=None, username=None, password=None,
|
|||
categories = None
|
||||
if client:
|
||||
categories = client.tagging.Category.list()
|
||||
return {"Categories": categories}
|
||||
return {'Categories': categories}
|
||||
|
||||
|
||||
@depends(HAS_PYVMOMI, HAS_VSPHERE_SDK)
|
||||
|
@ -9296,8 +9296,8 @@ def list_attached_tags(object_id,
|
|||
attached_tags = client.tagging.TagAssociation.list_attached_tags(
|
||||
dynamic_id)
|
||||
except vsphere_errors:
|
||||
log.warning('Unable to list attached tags. Check user privileges '
|
||||
'and object_id (must be a string).')
|
||||
log.warning('Unable to list attached tags. Check user privileges'
|
||||
' and object_id (must be a string).')
|
||||
return {'Attached tags': attached_tags}
|
||||
|
||||
|
||||
|
@ -9548,8 +9548,8 @@ def delete_tag(tag_id,
|
|||
try:
|
||||
tag_deleted = client.tagging.Tag.delete(tag_id)
|
||||
except vsphere_errors:
|
||||
log.warning('Unable to delete category. Check user privileges '
|
||||
'and that category exists.')
|
||||
log.warning('Unable to delete category. Check user privileges'
|
||||
' and that category exists.')
|
||||
return {'Tag deleted': tag_deleted}
|
||||
|
||||
|
||||
|
|
|
@ -32,12 +32,14 @@ from tests.support.mock import (
|
|||
# Import Third Party Libs
|
||||
try:
|
||||
from pyVmomi import vim, vmodl # pylint: disable=unused-import
|
||||
|
||||
HAS_PYVMOMI = True
|
||||
except ImportError:
|
||||
HAS_PYVMOMI = False
|
||||
|
||||
try:
|
||||
from com.vmware.vapi.std_client import DynamicID
|
||||
|
||||
HAS_VSPHERE_SDK = True
|
||||
except ImportError:
|
||||
HAS_VSPHERE_SDK = False
|
||||
|
@ -57,6 +59,7 @@ class VsphereTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Unit TestCase for the salt.modules.vsphere module.
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {vsphere: {'__virtual__': MagicMock(return_value='vsphere')}}
|
||||
|
||||
|
@ -578,6 +581,7 @@ class GetProxyTypeTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.get_proxy_type
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {vsphere: {'__virtual__': MagicMock(return_value='vsphere')}}
|
||||
|
||||
|
@ -592,6 +596,7 @@ class SupportsProxiesTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.supports_proxies decorator
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {vsphere: {'__virtual__': MagicMock(return_value='vsphere')}}
|
||||
|
||||
|
@ -623,6 +628,7 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere._get_proxy_connection_details
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {vsphere: {'__virtual__': MagicMock(return_value='vsphere')}}
|
||||
|
||||
|
@ -684,7 +690,7 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value='esxi')):
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'esxi.get_details':
|
||||
MagicMock(return_value=self.esxi_host_details)}):
|
||||
MagicMock(return_value=self.esxi_host_details)}):
|
||||
ret = vsphere._get_proxy_connection_details()
|
||||
self.assertEqual(('fake_host', 'fake_username', 'fake_password',
|
||||
'fake_protocol', 'fake_port', 'fake_mechanism',
|
||||
|
@ -695,7 +701,7 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value='esxdatacenter')):
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'esxdatacenter.get_details': MagicMock(
|
||||
return_value=self.esxdatacenter_details)}):
|
||||
return_value=self.esxdatacenter_details)}):
|
||||
ret = vsphere._get_proxy_connection_details()
|
||||
self.assertEqual(('fake_vcenter', 'fake_username', 'fake_password',
|
||||
'fake_protocol', 'fake_port', 'fake_mechanism',
|
||||
|
@ -706,7 +712,7 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value='esxcluster')):
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'esxcluster.get_details': MagicMock(
|
||||
return_value=self.esxcluster_details)}):
|
||||
return_value=self.esxcluster_details)}):
|
||||
ret = vsphere._get_proxy_connection_details()
|
||||
self.assertEqual(('fake_vcenter', 'fake_username', 'fake_password',
|
||||
'fake_protocol', 'fake_port', 'fake_mechanism',
|
||||
|
@ -717,8 +723,8 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value='esxi')):
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'esxi.get_details':
|
||||
MagicMock(
|
||||
return_value=self.esxi_vcenter_details)}):
|
||||
MagicMock(
|
||||
return_value=self.esxi_vcenter_details)}):
|
||||
ret = vsphere._get_proxy_connection_details()
|
||||
self.assertEqual(('fake_vcenter', 'fake_username', 'fake_password',
|
||||
'fake_protocol', 'fake_port', 'fake_mechanism',
|
||||
|
@ -729,7 +735,7 @@ class _GetProxyConnectionDetailsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value='vcenter')):
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': MagicMock(
|
||||
return_value=self.vcenter_details)}):
|
||||
return_value=self.vcenter_details)}):
|
||||
ret = vsphere._get_proxy_connection_details()
|
||||
self.assertEqual(('fake_vcenter', 'fake_username', 'fake_password',
|
||||
'fake_protocol', 'fake_port', 'fake_mechanism',
|
||||
|
@ -749,6 +755,7 @@ class GetsServiceInstanceViaProxyTestCase(TestCase, LoaderModuleMockMixin):
|
|||
Tests for salt.modules.vsphere.gets_service_instance_via_proxy
|
||||
decorator
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
patcher = patch('salt.utils.vmware.get_service_instance', MagicMock())
|
||||
patcher.start()
|
||||
|
@ -919,6 +926,7 @@ class GetServiceInstanceViaProxyTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.get_service_instance_via_proxy
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
patcher = patch('salt.utils.vmware.get_service_instance', MagicMock())
|
||||
patcher.start()
|
||||
|
@ -961,6 +969,7 @@ class DisconnectTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.disconnect
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
self.mock_si = MagicMock()
|
||||
self.addCleanup(delattr, self, 'mock_si')
|
||||
|
@ -997,6 +1006,7 @@ class TestVcenterConnectionTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.test_vcenter_connection
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
self.mock_si = MagicMock()
|
||||
self.addCleanup(delattr, self, 'mock_si')
|
||||
|
@ -1072,6 +1082,7 @@ class ListDatacentersViaProxyTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.list_datacenters_via_proxy
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
self.mock_si = MagicMock()
|
||||
self.addCleanup(delattr, self, 'mock_si')
|
||||
|
@ -1157,6 +1168,7 @@ class CreateDatacenterTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.create_datacenter
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
self.mock_si = MagicMock()
|
||||
self.addCleanup(delattr, self, 'mock_si')
|
||||
|
@ -1207,6 +1219,7 @@ class EraseDiskPartitionsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.erase_disk_partitions
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1295,6 +1308,7 @@ class RemoveDatastoreTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.remove_datastore
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1384,6 +1398,7 @@ class RemoveDiskgroupTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.remove_diskgroup
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1479,6 +1494,7 @@ class RemoveCapacityFromDiskgroupTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.remove_capacity_from_diskgroup
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1646,6 +1662,7 @@ class ListClusterTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.list_cluster
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1684,7 +1701,7 @@ class ListClusterTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# Patch __salt__ dunder
|
||||
patcher = patch.dict(vsphere.__salt__,
|
||||
{'esxcluster.get_details':
|
||||
MagicMock(return_value={'cluster': 'cl'})})
|
||||
MagicMock(return_value={'cluster': 'cl'})})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
|
@ -1737,6 +1754,7 @@ class RenameDatastoreTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere.rename_datastore
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1819,6 +1837,7 @@ class _GetProxyTargetTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
Tests for salt.modules.vsphere._get_proxy_target
|
||||
'''
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
vsphere: {
|
||||
|
@ -1914,7 +1933,6 @@ class _GetProxyTargetTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
||||
|
||||
'''
|
||||
Tests for:
|
||||
- salt.modules.vsphere.create_tag_category
|
||||
|
@ -1945,79 +1963,115 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
# Function attributes
|
||||
func_attrs = {
|
||||
key: None for key in [
|
||||
'category_id', 'object_id', 'tag_id', 'name', 'description', 'cardinality']
|
||||
'category_id', 'object_id', 'tag_id', 'name',
|
||||
'description', 'cardinality']
|
||||
}
|
||||
|
||||
# Expected returns
|
||||
create_tag_category = {
|
||||
'Category created':
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
}
|
||||
|
||||
create_tag = {
|
||||
'Tag created':
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
}
|
||||
|
||||
delete_tag_category = {
|
||||
'Category deleted':
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
}
|
||||
|
||||
delete_tag = {
|
||||
'Tag deleted':
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
}
|
||||
|
||||
list_tag_categories_return = [
|
||||
'urn:vmomi:InventoryServiceCategory:b13f4959-a3f3-48d0-8080-15bb586b4355:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:f4d41f02-c317-422d-9013-dcbebfcd54ad:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:2db5b00b-f211-4bba-ba42-e2658ebbb283:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:cd847c3c-687c-4bd9-8e5a-0eb536f0a01d:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:d51c24f9-cffb-4ce0-af56-7f18b6e649af:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'b13f4959-a3f3-48d0-8080-15bb586b4355:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'f4d41f02-c317-422d-9013-dcbebfcd54ad:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'2db5b00b-f211-4bba-ba42-e2658ebbb283:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'cd847c3c-687c-4bd9-8e5a-0eb536f0a01d:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'd51c24f9-cffb-4ce0-af56-7f18b6e649af:GLOBAL'
|
||||
]
|
||||
|
||||
list_tags_return = [
|
||||
'urn:vmomi:InventoryServiceTag:a584a83b-3015-45ad-8057-a3630613052f:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:db08019c-15de-4bbf-be46-d81aaf8d25c0:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:b55ecc77-f4a5-49f8-ab52-38865467cfbe:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:f009ab1b-e1b5-4c40-b8f7-951d9d716b39:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:102bb4c5-9b76-4d6c-882a-76a91ee3edcc:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:71d30f2d-bb23-48e1-995f-630adfb0dc89:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'a584a83b-3015-45ad-8057-a3630613052f:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'db08019c-15de-4bbf-be46-d81aaf8d25c0:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'b55ecc77-f4a5-49f8-ab52-38865467cfbe:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'f009ab1b-e1b5-4c40-b8f7-951d9d716b39:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'102bb4c5-9b76-4d6c-882a-76a91ee3edcc:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'71d30f2d-bb23-48e1-995f-630adfb0dc89:GLOBAL'
|
||||
]
|
||||
|
||||
list_attached_tags_return = [
|
||||
'urn:vmomi:InventoryServiceTag:b55ecc77-f4a5-49f8-ab52-38865467cfbe:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'b55ecc77-f4a5-49f8-ab52-38865467cfbe:GLOBAL',
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
]
|
||||
|
||||
list_create_category_return = [
|
||||
'urn:vmomi:InventoryServiceCategory:0af54c2d-e8cd-4248-931e-2f5807d8c477:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'0af54c2d-e8cd-4248-931e-2f5807d8c477:GLOBAL'
|
||||
]
|
||||
|
||||
list_create_tag_return = [
|
||||
'urn:vmomi:InventoryServiceCategory:0af54c2d-e8cd-4248-931e-2f5807d8c477:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceCategory:'
|
||||
'0af54c2d-e8cd-4248-931e-2f5807d8c477:GLOBAL'
|
||||
]
|
||||
|
||||
attach_tags_return = {
|
||||
'Tag attached':
|
||||
'urn:vmomi:InventoryServiceTag:bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
'urn:vmomi:InventoryServiceTag:'
|
||||
'bb0350b4-85db-46b0-a726-e7c5989fc857:GLOBAL'
|
||||
}
|
||||
|
||||
def test_create_tag_category_client_none(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=None) as get_vsphere_client:
|
||||
|
||||
ret = vsphere.create_tag_category(self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.create_tag_category(
|
||||
self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
|
@ -2033,17 +2087,35 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
tagging=Mock(
|
||||
Category=Mock(
|
||||
CreateSpec=Mock(return_value=Mock()),
|
||||
create=Mock(return_value=self.create_tag_category['Category']))))
|
||||
create=Mock(
|
||||
return_value=self.create_tag_category[
|
||||
'Category created']))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
ret = vsphere.create_tag_category(self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.create_tag_category(
|
||||
self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
|
@ -2056,16 +2128,30 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details},
|
||||
clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=None) as get_vsphere_client:
|
||||
|
||||
ret = vsphere.create_tag(self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
)as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.create_tag(
|
||||
self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
|
@ -2081,19 +2167,34 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
tagging=Mock(
|
||||
Tag=Mock(
|
||||
CreateSpec=Mock(return_value=Mock()),
|
||||
create=Mock(return_value=self.create_tag['Tag']))))
|
||||
create=Mock(return_value=self.create_tag[
|
||||
'Tag created']))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details},
|
||||
clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
|
||||
ret = vsphere.create_tag(self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
)as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.create_tag(
|
||||
self.func_attrs['name'],
|
||||
self.func_attrs['description'],
|
||||
self.func_attrs['cardinality'])
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
|
@ -2105,20 +2206,34 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
|
||||
ret = vsphere.delete_tag_category(self.func_attrs['category_id'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag_category(
|
||||
self.func_attrs['category_id'])
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, None)
|
||||
self.assertEqual(ret, {'Category deleted': None})
|
||||
|
||||
def test_delete_tag_category_client(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
@ -2127,15 +2242,32 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
Category=Mock(
|
||||
delete=Mock(return_value=self.delete_tag_category['Successfully deleted category']))))
|
||||
delete=Mock(return_value=self.delete_tag_category[
|
||||
'Category deleted']))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag_category(self.func_attrs['category_id'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag_category(
|
||||
self.func_attrs['category_id'])
|
||||
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
|
@ -2148,14 +2280,27 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
|
||||
ret = vsphere.delete_tag(self.func_attrs['tag_id'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag(
|
||||
self.func_attrs['tag_id'])
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
|
@ -2170,15 +2315,32 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
Tag=Mock(
|
||||
delete=Mock(return_value=self.delete_tag['Successfully deleted tag']))))
|
||||
delete=Mock(return_value=self.delete_tag[
|
||||
'Tag deleted']))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag(self.func_attrs['tag_id'])
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.delete_tag(
|
||||
self.func_attrs['tag_id'])
|
||||
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
|
@ -2191,13 +2353,26 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.list_tag_categories()
|
||||
# Check function calls and return data
|
||||
get_proxy_type.assert_called_once()
|
||||
|
@ -2213,33 +2388,64 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
Category=Mock(
|
||||
list=Mock(return_value=self.list_tag_categories_return))))
|
||||
list=Mock(return_value=self.list_tag_categories_return
|
||||
))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
ret = vsphere.list_tag_categories()
|
||||
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, {'Categories': self.list_tag_categories_return})
|
||||
self.assertEqual(
|
||||
ret, {'Categories':
|
||||
self.list_tag_categories_return})
|
||||
|
||||
def test_list_tags_client_none(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
# Check function calls and return
|
||||
ret = vsphere.list_tags()
|
||||
get_proxy_type.assert_called_once()
|
||||
|
@ -2255,42 +2461,73 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
Tag=Mock(
|
||||
list=Mock(return_value=self.list_tags_return))))
|
||||
list=Mock(return_value=self.list_tags_return
|
||||
))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
# Check function calls and return
|
||||
ret = vsphere.list_tags()
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, {'Tags': self.list_tags_return})
|
||||
self.assertEqual(ret,
|
||||
{'Tags': self.list_tags_return})
|
||||
|
||||
def test_list_attached_tags_client_none(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
with patch.object(vsphere, 'DynamicID') as dynamic_id:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
with patch.object(vsphere,
|
||||
'DynamicID'
|
||||
) as dynamic_id:
|
||||
# Check function calls and return
|
||||
ret = vsphere.list_attached_tags('object_id')
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, None)
|
||||
self.assertEqual(ret, {'Attached tags': None})
|
||||
|
||||
def test_list_attached_tags_client(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
@ -2299,42 +2536,78 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
TagAssociation=Mock(
|
||||
list_attached_tags=Mock(return_value=self.list_attached_tags_return))))
|
||||
list_attached_tags=Mock(
|
||||
return_value=self.list_attached_tags_return
|
||||
))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
with patch.object(vsphere, 'DynamicID') as dynamic_id:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
with patch.object(vsphere,
|
||||
'DynamicID'
|
||||
) as dynamic_id:
|
||||
# Check function calls and return
|
||||
ret = vsphere.list_attached_tags(self.func_attrs['object_id'])
|
||||
ret = vsphere.list_attached_tags(
|
||||
self.func_attrs['object_id'])
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, {'Attached tags': self.list_attached_tags_return})
|
||||
self.assertEqual(
|
||||
ret, {'Attached tags':
|
||||
self.list_attached_tags_return})
|
||||
|
||||
def test_attach_tags_client_none(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client',
|
||||
return_value=None) as get_vsphere_client:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=None
|
||||
) as get_vsphere_client:
|
||||
# Check function calls and return
|
||||
ret = vsphere.attach_tag(object_id=self.func_attrs['object_id'], tag_id=self.func_attrs['tag_id'])
|
||||
ret = vsphere.attach_tag(
|
||||
object_id=self.func_attrs['object_id'],
|
||||
tag_id=self.func_attrs['tag_id'])
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, {'Tag attached': False})
|
||||
self.assertEqual(ret, {'Tag attached': None})
|
||||
|
||||
def test_attach_tags_client(self):
|
||||
get_details = MagicMock(return_value=self.details)
|
||||
|
@ -2343,20 +2616,41 @@ class TestVSphereTagging(TestCase, LoaderModuleMockMixin):
|
|||
mock_client = Mock(
|
||||
tagging=Mock(
|
||||
TagAssociation=Mock(
|
||||
attach=Mock(return_value=self.list_attached_tags_return))))
|
||||
attach=Mock(return_value=self.list_attached_tags_return
|
||||
))))
|
||||
|
||||
# Start patching each external API return with Mock Objects
|
||||
with patch.object(vsphere, 'get_proxy_type', return_value='vcenter') as get_proxy_type:
|
||||
with patch.object(vsphere, '_get_proxy_connection_details', return_value=[]) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware, 'get_service_instance', return_value=None) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__, {'vcenter.get_details': get_details}, clear=True) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware, 'get_vsphere_client', return_value=mock_client) as get_vsphere_client:
|
||||
with patch.object(vsphere, 'DynamicID') as dynamic_id:
|
||||
|
||||
with patch.object(vsphere,
|
||||
'get_proxy_type',
|
||||
return_value='vcenter'
|
||||
) as get_proxy_type:
|
||||
with patch.object(vsphere,
|
||||
'_get_proxy_connection_details',
|
||||
return_value=[]
|
||||
) as get_proxy_connection:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_service_instance',
|
||||
return_value=None
|
||||
) as get_service_instance:
|
||||
with patch.dict(vsphere.__salt__,
|
||||
{'vcenter.get_details': get_details},
|
||||
clear=True
|
||||
) as get_vcenter_details:
|
||||
with patch.object(salt.utils.vmware,
|
||||
'get_vsphere_client',
|
||||
return_value=mock_client
|
||||
) as get_vsphere_client:
|
||||
with patch.object(vsphere,
|
||||
'DynamicID'
|
||||
) as dynamic_id:
|
||||
# Check function calls and return
|
||||
ret = vsphere.attach_tag(object_id=self.func_attrs['object_id'], tag_id=self.func_attrs['tag_id'])
|
||||
ret = vsphere.attach_tag(
|
||||
object_id=self.func_attrs['object_id'],
|
||||
tag_id=self.func_attrs['tag_id'])
|
||||
get_proxy_type.assert_called_once()
|
||||
get_proxy_connection.assert_called_once()
|
||||
get_service_instance.assert_called_once()
|
||||
get_vsphere_client.assert_called_once()
|
||||
self.assertEqual(ret, {'Tag attached': True})
|
||||
self.assertEqual(
|
||||
ret, {'Tag attached':
|
||||
self.list_attached_tags_return})
|
||||
|
|
Loading…
Add table
Reference in a new issue