コード例 #1
0
def test_apply_parameters(transport: str = "grpc"):
    client = CloudMemcacheClient(
        credentials=credentials.AnonymousCredentials(), transport=transport
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = cloud_memcache.ApplyParametersRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(
        type(client._transport.apply_parameters), "__call__"
    ) as call:
        # Designate an appropriate return value for the call.
        call.return_value = operations_pb2.Operation(name="operations/spam")

        response = client.apply_parameters(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls) == 1
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, future.Future)
コード例 #2
0
def test_apply_parameters_flattened_error():
    client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials())

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        client.apply_parameters(
            cloud_memcache.ApplyParametersRequest(),
            name="name_value",
            node_ids=["node_ids_value"],
            apply_all=True,
        )
コード例 #3
0
ファイル: client.py プロジェクト: vam-google/python-memcache
    def apply_parameters(
            self,
            request: cloud_memcache.ApplyParametersRequest = None,
            *,
            name: str = None,
            node_ids: Sequence[str] = None,
            apply_all: bool = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> operation.Operation:
        r"""ApplyParameters will update current set of Parameters
        to the set of specified nodes of the Memcached Instance.

        Args:
            request (:class:`~.cloud_memcache.ApplyParametersRequest`):
                The request object. Request for
                [ApplyParameters][google.cloud.memcache.v1beta2.CloudMemcache.ApplyParameters].
            name (:class:`str`):
                Required. Resource name of the
                Memcached instance for which parameter
                group updates should be applied.
                This corresponds to the ``name`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            node_ids (:class:`Sequence[str]`):
                Nodes to which we should apply the
                instance-level parameter group.
                This corresponds to the ``node_ids`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            apply_all (:class:`bool`):
                Whether to apply instance-level
                parameter group to all nodes. If set to
                true, will explicitly restrict users
                from specifying any nodes, and apply
                parameter group updates to all nodes
                within the instance.
                This corresponds to the ``apply_all`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.

            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            ~.operation.Operation:
                An object representing a long-running operation.

                The result type for the operation will be
                :class:``~.cloud_memcache.Instance``:

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        if request is not None and any([name, node_ids, apply_all]):
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = cloud_memcache.ApplyParametersRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.

        if name is not None:
            request.name = name
        if node_ids is not None:
            request.node_ids = node_ids
        if apply_all is not None:
            request.apply_all = apply_all

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method.wrap_method(
            self._transport.apply_parameters,
            default_timeout=None,
            client_info=_client_info,
        )

        # Send the request.
        response = rpc(request,
                       retry=retry,
                       timeout=timeout,
                       metadata=metadata)

        # Wrap the response in an operation future.
        response = operation.from_gapic(
            response,
            self._transport.operations_client,
            cloud_memcache.Instance,
            metadata_type=cloud_memcache.OperationMetadata,
        )

        # Done; return the response.
        return response
コード例 #4
0
    def apply_parameters(
            self,
            request: cloud_memcache.ApplyParametersRequest = None,
            *,
            name: str = None,
            node_ids: Sequence[str] = None,
            apply_all: bool = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> operation.Operation:
        r"""``ApplyParameters`` restarts the set of specified nodes in order
        to update them to the current set of parameters for the
        Memcached Instance.

        Args:
            request (google.cloud.memcache_v1beta2.types.ApplyParametersRequest):
                The request object. Request for
                [ApplyParameters][google.cloud.memcache.v1beta2.CloudMemcache.ApplyParameters].
            name (str):
                Required. Resource name of the
                Memcached instance for which parameter
                group updates should be applied.

                This corresponds to the ``name`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            node_ids (Sequence[str]):
                Nodes to which the instance-level
                parameter group is applied.

                This corresponds to the ``node_ids`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            apply_all (bool):
                Whether to apply instance-level parameter group to all
                nodes. If set to true, users are restricted from
                specifying individual nodes, and ``ApplyParameters``
                updates all nodes within the instance.

                This corresponds to the ``apply_all`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            google.api_core.operation.Operation:
                An object representing a long-running operation.

                The result type for the operation will be
                :class:`google.cloud.memcache_v1beta2.types.Instance` A
                Memorystore for Memcached instance

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([name, node_ids, apply_all])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        # Minor optimization to avoid making a copy if the user passes
        # in a cloud_memcache.ApplyParametersRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, cloud_memcache.ApplyParametersRequest):
            request = cloud_memcache.ApplyParametersRequest(request)
            # If we have keyword arguments corresponding to fields on the
            # request, apply these.
            if name is not None:
                request.name = name
            if node_ids is not None:
                request.node_ids = node_ids
            if apply_all is not None:
                request.apply_all = apply_all

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[
            self._transport.apply_parameters]

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("name", request.name), )), )

        # Send the request.
        response = rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # Wrap the response in an operation future.
        response = operation.from_gapic(
            response,
            self._transport.operations_client,
            cloud_memcache.Instance,
            metadata_type=cloud_memcache.OperationMetadata,
        )

        # Done; return the response.
        return response