本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient._find_by_inventory_path方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient._find_by_inventory_path方法的具体用法?Python VimClient._find_by_inventory_path怎么用?Python VimClient._find_by_inventory_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient._find_by_inventory_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_nfc_ticket
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import _find_by_inventory_path [as 别名]
def test_get_nfc_ticket(self, connect_mock):
vim_client = VimClient(auto_sync=False)
vim_client._find_by_inventory_path = MagicMock(return_value=None)
self.assertRaises(DatastoreNotFound, vim_client.get_nfc_ticket_by_ds_name, "no_exist")
ds_mock = MagicMock()
vim_client._find_by_inventory_path = MagicMock(return_value=ds_mock)
nfc_service = MagicMock()
type(vim).NfcService = MagicMock()
type(vim).NfcService.return_value = nfc_service
vim_client._si = MagicMock()
vim_client.get_nfc_ticket_by_ds_name("existing_ds")
nfc_service.FileManagement.assert_called_once_with(ds_mock)
示例2: TestVimClient
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import _find_by_inventory_path [as 别名]
#.........这里部分代码省略.........
retry = 0
while update_mock.call_count < 5 and retry < 10:
time.sleep(0.2)
retry += 1
assert_that(retry, is_not(10), "VimClient._poll_updates is not called repeatedly")
vim_client.disconnect()
assert_that(disconnect_mock.called, is_(True))
@patch("pysdk.host.GetHostSystem")
@patch("pysdk.connect.Connect")
def test_vim_client_errback(self, connect_mock, host_mock):
callback = MagicMock()
vim_client = VimClient(auto_sync=False, errback=callback)
vim_client.connect_userpwd("esx.local", "root", "password")
host_mock.side_effect = vim.fault.NotAuthenticated
vim_client.host_system
callback.assert_called_once()
host_mock.side_effect = vim.fault.HostConnectFault
vim_client.host_system
assert_that(callback.call_count, is_(2))
host_mock.side_effect = vim.fault.InvalidLogin
vim_client.host_system
assert_that(callback.call_count, is_(3))
host_mock.side_effect = AcquireCredentialsException
vim_client.host_system
assert_that(callback.call_count, is_(4))
@patch("pysdk.connect.Connect")
def test_get_nfc_ticket(self, connect_mock):
vim_client = VimClient(auto_sync=False)
vim_client._find_by_inventory_path = MagicMock(return_value=None)
self.assertRaises(DatastoreNotFound, vim_client.get_nfc_ticket_by_ds_name, "no_exist")
ds_mock = MagicMock()
vim_client._find_by_inventory_path = MagicMock(return_value=ds_mock)
nfc_service = MagicMock()
type(vim).NfcService = MagicMock()
type(vim).NfcService.return_value = nfc_service
vim_client._si = MagicMock()
vim_client.get_nfc_ticket_by_ds_name("existing_ds")
nfc_service.FileManagement.assert_called_once_with(ds_mock)
def test_inventory_path(self):
"""Check that convert to inventory path correctly."""
tests = [
{"path": (), "val": "ha-datacenter"},
{"path": ("network", None), "val": "ha-datacenter/network"},
{"path": ("vm",), "val": "ha-datacenter/vm"},
{"path": ("vm", "Cent/OS"), "val": "ha-datacenter/vm/Cent%2fOS"},
]
for test in tests:
self.vim_client._find_by_inventory_path(*test["path"])
self.vim_client._content.searchIndex.FindByInventoryPath.assert_called_once_with(test["val"])
self.vim_client._content.searchIndex.FindByInventoryPath.reset_mock()
def test_get_vm_not_found(self):
"""Test that if the vm isn't found we throw an exception."""
self.vim_client._find_by_inventory_path = MagicMock(return_value=None)
# assertRaisesRegexp is only supported in 2.7
self.assertRaises(Exception, self.vim_client.get_vm, "vm_id")