本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient.get_nfc_ticket_by_ds_name方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient.get_nfc_ticket_by_ds_name方法的具体用法?Python VimClient.get_nfc_ticket_by_ds_name怎么用?Python VimClient.get_nfc_ticket_by_ds_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient.get_nfc_ticket_by_ds_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_nfc_ticket
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_nfc_ticket_by_ds_name [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 get_nfc_ticket_by_ds_name [as 别名]
#.........这里部分代码省略.........
@patch("pysdk.host.GetHostSystem")
def test_datastore_name_to_path(self, host_system):
"""Test that we get the correct path for the name we use."""
expected_path = "datastore1path"
mount_name_mock = MagicMock(name="mount_name_mock")
mount_name_mock.volume.name = "datastore1"
mount_name_mock.mountInfo.path = expected_path
mount = MagicMock(name="mount")
mount.config.fileSystemVolume.mountInfo = [mount_name_mock]
host_system.return_value = mount
path = self.vim_client.datastore_name_to_path("datastore1")
assert_that(path, equal_to(expected_path))
@patch("pysdk.host.GetHostSystem")
def test_datastore_name_to_path_not_exist(self, host_system):
"""Test that we get None if the datastore name we're looking for does
not exist."""
expected_path = "datastore1path"
mount_name_mock = MagicMock(name="mount_name_mock")
mount_name_mock.GetVolume().GetName.return_value = "datastore1"
mount_name_mock.GetMountInfo().GetPath.return_value = expected_path
mount = MagicMock(name="mount")
mount.GetConfig().GetFileSystemVolume().GetMountInfo.return_value = (
[mount_name_mock])
host_system.return_value = mount
path = self.vim_client.datastore_name_to_path("datastore_doesnt_exist")
assert_that(path, none())
def test_get_nfc_ticket(self):
self.vim_client.get_datastore = MagicMock(return_value=None)
self.assertRaises(DatastoreNotFound,
self.vim_client.get_nfc_ticket_by_ds_name,
"no_exist")
ds_mock = MagicMock()
self.vim_client.get_datastore = MagicMock(return_value=ds_mock)
type(self.vim_client).nfc_service = MagicMock()
self.vim_client.get_nfc_ticket_by_ds_name("existing_ds")
self.vim_client.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:
result = self.vim_client.inventory_path(*test["path"])
assert_that(result, equal_to(test["val"]))
def test_get_vm_power_state(self):
"""Check that we return the expected power state."""
vm_mock = MagicMock(name="vm_mock")
vm_mock.runtime.powerState = "poweredoff"
assert_that(self.vim_client.get_vm_power_state(vm_mock),
equal_to("poweredoff"))
def test_get_vm_not_found(self):
"""Test that if the vm isn't found we throw an exception."""