コード例 #1
0
    def test_get_datastores(self, mkdir_mock):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        vim_client.get_all_datastores.return_value = self.get_datastore_mock([
            # name, url, type, local
            ["datastore1", "/vmfs/volumes/id-1", "VMFS", True],
            ["datastore2", "/vmfs/volumes/id-2", "VMFS", False],
            ["datastore3", "/vmfs/volumes/id-3", "NFS", None],
            ["datastore4", "/vmfs/volumes/id-4", "NFSV41", None],
            ["datastore5", "/vmfs/volumes/id-5", "vsan", None],
            ["datastore6", "/vmfs/volumes/id-6", "VFFS", None],
        ])

        hypervisor.vim_client = vim_client

        ds_list = [
            "datastore1", "datastore2", "datastore3", "datastore4",
            "datastore5", "datastore6"
        ]
        image_ds = [{"name": "datastore2", "used_for_vms": False}]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list, image_ds)

        expected_call_args = []
        for ds in ds_list:
            for folder in [
                    DISK_FOLDER_NAME, VM_FOLDER_NAME, IMAGE_FOLDER_NAME,
                    TMP_IMAGE_FOLDER_NAME
            ]:
                expected_call_args.append('/vmfs/volumes/%s/%s' % (ds, folder))
        called_args = [c[0][0] for c in mkdir_mock.call_args_list]
        assert_that(called_args, contains_inanyorder(*expected_call_args))

        assert_that(
            ds_manager.get_datastore_ids(),
            contains_inanyorder("id-1", "id-2", "id-3", "id-4", "id-5",
                                "id-6"))

        assert_that(
            ds_manager.vm_datastores(),
            contains_inanyorder("id-1", "id-3", "id-4", "id-5", "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(
            datastores,
            contains_inanyorder(
                Datastore("id-1",
                          "datastore1",
                          type=DSType.LOCAL_VMFS,
                          tags=set([LOCAL_VMFS_TAG])),
                Datastore("id-2",
                          "datastore2",
                          type=DSType.SHARED_VMFS,
                          tags=set([SHARED_VMFS_TAG])),
                Datastore("id-3",
                          "datastore3",
                          type=DSType.NFS_3,
                          tags=set([NFS_TAG])),
                Datastore("id-4",
                          "datastore4",
                          type=DSType.NFS_41,
                          tags=set([NFS_TAG])),
                Datastore("id-5", "datastore5", type=DSType.VSAN, tags=set()),
                Datastore("id-6", "datastore6", type=DSType.OTHER,
                          tags=set())))

        assert_that(ds_manager.image_datastores(), is_(["id-2"]))
        assert_that(ds_manager.datastore_type("id-1"), is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"), is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"), is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"), is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"), is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"), is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))
コード例 #2
0
    def test_get_datastores(self, mkdir_mock):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        vim_client.get_all_datastores.return_value = self.get_datastore_mock([
            # name, url, type, local
            ["datastore1", "/vmfs/volumes/id-1", "VMFS", True],
            ["datastore2", "/vmfs/volumes/id-2", "VMFS", False],
            ["datastore3", "/vmfs/volumes/id-3", "NFS", None],
            ["datastore4", "/vmfs/volumes/id-4", "NFSV41", None],
            ["datastore5", "/vmfs/volumes/id-5", "vsan", None],
            ["datastore6", "/vmfs/volumes/id-6", "VFFS", None],
        ])

        hypervisor.vim_client = vim_client

        ds_list = ["datastore1", "datastore2", "datastore3",
                   "datastore4", "datastore5", "datastore6"]
        image_ds = [{"name": "datastore2", "used_for_vms": False}]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list, image_ds)

        expected_call_args = []
        for ds in ds_list:
            for folder in [DISK_FOLDER_NAME, VM_FOLDER_NAME, IMAGE_FOLDER_NAME,
                           TMP_IMAGE_FOLDER_NAME]:
                expected_call_args.append('/vmfs/volumes/%s/%s' % (ds, folder))
        called_args = [c[0][0] for c in mkdir_mock.call_args_list]
        assert_that(called_args, contains_inanyorder(*expected_call_args))

        assert_that(ds_manager.get_datastore_ids(),
                    contains_inanyorder("id-1", "id-2", "id-3", "id-4",
                                        "id-5", "id-6"))

        assert_that(ds_manager.vm_datastores(),
                    contains_inanyorder("id-1", "id-3", "id-4", "id-5",
                                        "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(datastores, contains_inanyorder(
            Datastore("id-1", "datastore1", type=DSType.LOCAL_VMFS,
                      tags=set([LOCAL_VMFS_TAG])),
            Datastore("id-2", "datastore2", type=DSType.SHARED_VMFS,
                      tags=set([SHARED_VMFS_TAG])),
            Datastore("id-3", "datastore3", type=DSType.NFS_3,
                      tags=set([NFS_TAG])),
            Datastore("id-4", "datastore4", type=DSType.NFS_41,
                      tags=set([NFS_TAG])),
            Datastore("id-5", "datastore5", type=DSType.VSAN, tags=set()),
            Datastore("id-6", "datastore6", type=DSType.OTHER, tags=set())))

        assert_that(ds_manager.image_datastores(), is_(["id-2"]))
        assert_that(ds_manager.datastore_type("id-1"),
                    is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"),
                    is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"),
                    is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"),
                    is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"),
                    is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"),
                    is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))
コード例 #3
0
    def test_get_datastores(self, mkdir_mock):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        dstags = MagicMock()
        dstags.get.return_value = []
        common.services.register(ServiceName.DATASTORE_TAGS, dstags)

        vim_client.get_datastore.side_effect = self._get_datastore
        hypervisor.vim_client = vim_client

        ds_list = [
            "datastore1", "datastore2", "datastore3", "datastore4",
            "datastore5", "datastore6"
        ]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list,
                                         set(["datastore2"]))

        expected_call_args = []
        for ds in ds_list:
            for folder in [
                    DISK_FOLDER_NAME, VM_FOLDER_NAME, IMAGE_FOLDER_NAME,
                    TMP_IMAGE_FOLDER_NAME
            ]:
                expected_call_args.append('/vmfs/volumes/%s/%s' % (ds, folder))
        called_args = [c[0][0] for c in mkdir_mock.call_args_list]
        assert_that(called_args, equal_to(expected_call_args))

        assert_that(ds_manager.get_datastore_ids(), has_length(6))
        assert_that(
            ds_manager.get_datastore_ids(),
            contains_inanyorder("id-1", "id-2", "id-3", "id-4", "id-5",
                                "id-6"))

        assert_that(ds_manager.vm_datastores(), has_length(5))
        assert_that(
            ds_manager.vm_datastores(),
            contains_inanyorder("id-1", "id-3", "id-4", "id-5", "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(
            datastores[0],
            is_(
                Datastore("id-1",
                          "datastore1",
                          type=DSType.LOCAL_VMFS,
                          tags=[LOCAL_VMFS_TAG])))
        assert_that(
            datastores[1],
            is_(
                Datastore("id-2",
                          "datastore2",
                          type=DSType.SHARED_VMFS,
                          tags=[SHARED_VMFS_TAG])))
        assert_that(
            datastores[2],
            is_(
                Datastore("id-3",
                          "datastore3",
                          type=DSType.NFS_3,
                          tags=[NFS_TAG])))
        assert_that(
            datastores[3],
            is_(
                Datastore("id-4",
                          "datastore4",
                          type=DSType.NFS_41,
                          tags=[NFS_TAG])))
        assert_that(
            datastores[4],
            is_(Datastore("id-5", "datastore5", type=DSType.VSAN, tags=[])))
        assert_that(
            datastores[5],
            is_(Datastore("id-6", "datastore6", type=DSType.OTHER, tags=[])))

        assert_that(ds_manager.image_datastores(), is_(set(["id-2"])))
        assert_that(ds_manager.datastore_type("id-1"), is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"), is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"), is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"), is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"), is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"), is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))
コード例 #4
0
    def test_get_datastores(self, mkdir_mock):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        dstags = MagicMock()
        dstags.get.return_value = []
        common.services.register(ServiceName.DATASTORE_TAGS, dstags)

        vim_client.get_datastore.side_effect = self._get_datastore
        hypervisor.vim_client = vim_client

        ds_list = ["datastore1", "datastore2", "datastore3",
                   "datastore4", "datastore5", "datastore6"]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list,
                                         set(["datastore2"]))

        expected_call_args = []
        for ds in ds_list:
            for folder in [DISK_FOLDER_NAME, VM_FOLDER_NAME, IMAGE_FOLDER_NAME,
                           TMP_IMAGE_FOLDER_NAME]:
                expected_call_args.append('/vmfs/volumes/%s/%s' % (ds, folder))
        called_args = [c[0][0] for c in mkdir_mock.call_args_list]
        assert_that(called_args, equal_to(expected_call_args))

        assert_that(ds_manager.get_datastore_ids(), has_length(6))
        assert_that(ds_manager.get_datastore_ids(),
                    contains_inanyorder("id-1", "id-2", "id-3", "id-4",
                                        "id-5", "id-6"))

        assert_that(ds_manager.vm_datastores(), has_length(5))
        assert_that(ds_manager.vm_datastores(),
                    contains_inanyorder("id-1", "id-3", "id-4", "id-5",
                                        "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(datastores[0], is_(Datastore("id-1", "datastore1",
                                                 type=DSType.LOCAL_VMFS,
                                                 tags=[LOCAL_VMFS_TAG])))
        assert_that(datastores[1], is_(Datastore("id-2", "datastore2",
                                                 type=DSType.SHARED_VMFS,
                                                 tags=[SHARED_VMFS_TAG])))
        assert_that(datastores[2], is_(Datastore("id-3", "datastore3",
                                                 type=DSType.NFS_3,
                                                 tags=[NFS_TAG])))
        assert_that(datastores[3], is_(Datastore("id-4", "datastore4",
                                                 type=DSType.NFS_41,
                                                 tags=[NFS_TAG])))
        assert_that(datastores[4], is_(Datastore("id-5", "datastore5",
                                                 type=DSType.VSAN,
                                                 tags=[])))
        assert_that(datastores[5], is_(Datastore("id-6", "datastore6",
                                                 type=DSType.OTHER,
                                                 tags=[])))

        assert_that(ds_manager.image_datastores(), is_(set(["id-2"])))
        assert_that(ds_manager.datastore_type("id-1"),
                    is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"),
                    is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"),
                    is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"),
                    is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"),
                    is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"),
                    is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))
コード例 #5
0
    def test_get_datastores(self):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        vim_client.get_all_datastores.return_value = self.get_datastore_mock([
            # name, url, type, local
            ["datastore1", "/vmfs/volumes/id-1", "VMFS", True],
            ["datastore2", "/vmfs/volumes/id-2", "VMFS", False],
            ["datastore3", "/vmfs/volumes/id-3", "NFS", None],
            ["datastore4", "/vmfs/volumes/id-4", "NFSV41", None],
            ["datastore5", "/vmfs/volumes/id-5", "vsan", None],
            ["datastore6", "/vmfs/volumes/id-6", "VFFS", None],
        ])

        hypervisor.vim_client = vim_client

        ds_list = [
            "datastore1", "datastore2", "datastore3", "datastore4",
            "datastore5", "datastore6"
        ]
        image_ds = [{"name": "datastore2", "used_for_vms": False}]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list, image_ds)

        assert_that(
            ds_manager.get_datastore_ids(),
            contains_inanyorder("id-1", "id-2", "id-3", "id-4", "id-5",
                                "id-6"))

        assert_that(
            ds_manager.vm_datastores(),
            contains_inanyorder("id-1", "id-3", "id-4", "id-5", "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(
            datastores,
            contains_inanyorder(
                Datastore("id-1",
                          "datastore1",
                          type=DSType.LOCAL_VMFS,
                          tags=set([LOCAL_VMFS_TAG])),
                Datastore("id-2",
                          "datastore2",
                          type=DSType.SHARED_VMFS,
                          tags=set([SHARED_VMFS_TAG])),
                Datastore("id-3",
                          "datastore3",
                          type=DSType.NFS_3,
                          tags=set([NFS_TAG])),
                Datastore("id-4",
                          "datastore4",
                          type=DSType.NFS_41,
                          tags=set([NFS_TAG])),
                Datastore("id-5",
                          "datastore5",
                          type=DSType.VSAN,
                          tags=set([VSAN_TAG])),
                Datastore("id-6", "datastore6", type=DSType.OTHER,
                          tags=set())))

        assert_that(ds_manager.image_datastores(), is_(["id-2"]))
        assert_that(ds_manager.datastore_type("id-1"), is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"), is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"), is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"), is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"), is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"), is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))
コード例 #6
0
    def test_get_datastores(self):
        """ Test esx datastore manager with different datastore types.
        Verify the datastore types are correctly parsed and all the
        datastores are populated.
        """
        hypervisor = MagicMock()
        vim_client = MagicMock()

        vim_client.get_all_datastores.return_value = self.get_datastore_mock([
            # name, url, type, local
            ["datastore1", "/vmfs/volumes/id-1", "VMFS", True],
            ["datastore2", "/vmfs/volumes/id-2", "VMFS", False],
            ["datastore3", "/vmfs/volumes/id-3", "NFS", None],
            ["datastore4", "/vmfs/volumes/id-4", "NFSV41", None],
            ["datastore5", "/vmfs/volumes/id-5", "vsan", None],
            ["datastore6", "/vmfs/volumes/id-6", "VFFS", None],
        ])

        hypervisor.vim_client = vim_client

        ds_list = ["datastore1", "datastore2", "datastore3",
                   "datastore4", "datastore5", "datastore6"]
        image_ds = [{"name": "datastore2", "used_for_vms": False}]
        ds_manager = EsxDatastoreManager(hypervisor, ds_list, image_ds)

        assert_that(ds_manager.get_datastore_ids(),
                    contains_inanyorder("id-1", "id-2", "id-3", "id-4",
                                        "id-5", "id-6"))

        assert_that(ds_manager.vm_datastores(),
                    contains_inanyorder("id-1", "id-3", "id-4", "id-5",
                                        "id-6"))

        datastores = ds_manager.get_datastores()
        assert_that(datastores, contains_inanyorder(
            Datastore("id-1", "datastore1", type=DSType.LOCAL_VMFS,
                      tags=set([LOCAL_VMFS_TAG])),
            Datastore("id-2", "datastore2", type=DSType.SHARED_VMFS,
                      tags=set([SHARED_VMFS_TAG])),
            Datastore("id-3", "datastore3", type=DSType.NFS_3,
                      tags=set([NFS_TAG])),
            Datastore("id-4", "datastore4", type=DSType.NFS_41,
                      tags=set([NFS_TAG])),
            Datastore("id-5", "datastore5", type=DSType.VSAN, tags=set([VSAN_TAG])),
            Datastore("id-6", "datastore6", type=DSType.OTHER, tags=set())))

        assert_that(ds_manager.image_datastores(), is_(["id-2"]))
        assert_that(ds_manager.datastore_type("id-1"),
                    is_(DSType.LOCAL_VMFS))
        assert_that(ds_manager.datastore_type("id-2"),
                    is_(DSType.SHARED_VMFS))
        assert_that(ds_manager.datastore_type("id-3"),
                    is_(DSType.NFS_3))
        assert_that(ds_manager.datastore_type("id-4"),
                    is_(DSType.NFS_41))
        assert_that(ds_manager.datastore_type("id-5"),
                    is_(DSType.VSAN))
        assert_that(ds_manager.datastore_type("id-6"),
                    is_(DSType.OTHER))

        # test normalize
        assert_that(ds_manager.normalize("id-1"), is_("id-1"))
        assert_that(ds_manager.normalize("datastore1"), is_("id-1"))