Пример #1
0
    def test_filter_hubs_by_profile(self):
        pbm_client = mock.Mock()
        session = mock.Mock()
        session.pbm = pbm_client
        hubs = mock.Mock()
        profile_id = 'profile-0'

        pbm.filter_hubs_by_profile(session, hubs, profile_id)
        session.invoke_api.assert_called_once_with(
            pbm_client,
            'PbmQueryMatchingHub',
            pbm_client.service_content.placementSolver,
            hubsToSearch=hubs,
            profile=profile_id)
Пример #2
0
    def test_filter_hubs_by_profile(self):
        pbm_client = mock.Mock()
        session = mock.Mock()
        session.pbm = pbm_client
        hubs = mock.Mock()
        profile_id = 'profile-0'

        pbm.filter_hubs_by_profile(session, hubs, profile_id)
        session.invoke_api.assert_called_once_with(
            pbm_client,
            'PbmQueryMatchingHub',
            pbm_client.service_content.placementSolver,
            hubsToSearch=hubs,
            profile=profile_id)
Пример #3
0
 def test_filter_hubs_by_profile(self):
     pbm_client_factory = self.pbm.client.factory
     profile_id = pbm_client_factory.create('ns0:PbmProfileId')
     hub = pbm_client_factory.create('ns0:PbmPlacementHub')
     test_spec = self.spec.get("test_filter_hubs_by_profile")
     profile_id.uniqueId = test_spec.get("unique_id")
     datastore_list = test_spec.get("datastores")
     hubs = []
     for each_ds in datastore_list:
         hub.hubId = each_ds
         hub.hubType = "Datastore"
         hubs.append(hub)
     
     filtered_hubs = pbm.filter_hubs_by_profile(self.session, hubs, profile_id)
     self.assertIsNotNone(filtered_hubs)
Пример #4
0
def _filter_datastores_matching_storage_policy(session, data_stores,
                                               storage_policy):
    """Get datastores matching the given storage policy.

    :param data_stores: the list of retrieve result wrapped datastore objects
    :param storage_policy: the storage policy name
    :return the list of datastores conforming to the given storage policy
    """
    profile_id = pbm.get_profile_id_by_name(session, storage_policy)
    if profile_id:
        factory = session.pbm.client.factory
        ds_mors = [oc.obj for oc in data_stores.objects]
        hubs = pbm.convert_datastores_to_hubs(factory, ds_mors)
        matching_hubs = pbm.filter_hubs_by_profile(session, hubs, profile_id)
        if matching_hubs:
            matching_ds = pbm.filter_datastores_by_hubs(matching_hubs, ds_mors)
            object_contents = [
                oc for oc in data_stores.objects if oc.obj in matching_ds
            ]
            data_stores.objects = object_contents
            return data_stores
    LOG.error(_LE("Unable to retrieve storage policy with name %s"),
              storage_policy)
Пример #5
0
def _filter_datastores_matching_storage_policy(session, data_stores,
                                               storage_policy):
    """Get datastores matching the given storage policy.

    :param data_stores: the list of retrieve result wrapped datastore objects
    :param storage_policy: the storage policy name
    :return the list of datastores conforming to the given storage policy
    """
    profile_id = pbm.get_profile_id_by_name(session, storage_policy)
    if profile_id:
        factory = session.pbm.client.factory
        ds_mors = [oc.obj for oc in data_stores.objects]
        hubs = pbm.convert_datastores_to_hubs(factory, ds_mors)
        matching_hubs = pbm.filter_hubs_by_profile(session, hubs,
                                                   profile_id)
        if matching_hubs:
            matching_ds = pbm.filter_datastores_by_hubs(matching_hubs,
                                                        ds_mors)
            object_contents = [oc for oc in data_stores.objects
                               if oc.obj in matching_ds]
            data_stores.objects = object_contents
            return data_stores
    LOG.error(_LE("Unable to retrieve storage policy with name %s"),
              storage_policy)