当前位置: 首页>>代码示例>>Python>>正文


Python VimClient.get_nfc_ticket_by_ds_name方法代码示例

本文整理汇总了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)
开发者ID:cartlhd,项目名称:photon-controller,代码行数:17,代码来源:test_vim_client.py

示例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."""
开发者ID:tomzhang,项目名称:photon-controller,代码行数:70,代码来源:test_vim_client.py


注:本文中的host.hypervisor.esx.vim_client.VimClient.get_nfc_ticket_by_ds_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。