def test_update_parameters_flattened(): client = CloudMemcacheClient(credentials=credentials.AnonymousCredentials()) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client._transport.update_parameters), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = client.update_parameters( name="name_value", update_mask=field_mask.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] assert args[0].name == "name_value" assert args[0].update_mask == field_mask.FieldMask(paths=["paths_value"]) assert args[0].parameters == cloud_memcache.MemcacheParameters(id="id_value")
def update_parameters( self, update_mask: Union[Dict, FieldMask], parameters: Union[Dict, cloud_memcache.MemcacheParameters], project_id: str, location: str, instance_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ): """ Updates the defined Memcached Parameters for an existing Instance. This method only stages the parameters, it must be followed by apply_parameters to apply the parameters to nodes of the Memcached Instance. :param update_mask: Required. Mask of fields to update. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.protobuf.field_mask_pb2.FieldMask` Union[Dict, google.protobuf.field_mask_pb2.FieldMask] :param parameters: The parameters to apply to the instance. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.memcache_v1beta2.types.cloud_memcache.MemcacheParameters` :param location: The location of the Cloud Memorystore instance (for example europe-west1) :param instance_id: The logical name of the Memcached instance in the customer project. :param project_id: Project ID of the project that contains the instance. If set to None or missing, the default project_id from the Google Cloud connection is used. :param retry: A retry object used to retry requests. If ``None`` is specified, requests will not be retried. :param timeout: The amount of time, in seconds, to wait for the request to complete. Note that if ``retry`` is specified, the timeout applies to each individual attempt. :param metadata: Additional metadata that is provided to the method. """ client = self.get_conn() metadata = metadata or () if isinstance(parameters, dict): parameters = cloud_memcache.MemcacheParameters(parameters) elif not isinstance(parameters, cloud_memcache.MemcacheParameters): raise AirflowException( "instance is not instance of MemcacheParameters type or python dict" ) name = CloudMemcacheClient.instance_path(project_id, location, instance_id) self.log.info("Staging update to instance: %s", instance_id) result = client.update_parameters( name=name, update_mask=update_mask, parameters=parameters, retry=retry, timeout=timeout, metadata=metadata, ) result.result() self.log.info("Update staged for instance: %s", instance_id)
def test_update_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.update_parameters( cloud_memcache.UpdateParametersRequest(), name="name_value", update_mask=field_mask.FieldMask(paths=["paths_value"]), parameters=cloud_memcache.MemcacheParameters(id="id_value"), )