From ba2b563aad68a00fd5798708546f4c110a402a07 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 25 Nov 2015 12:30:13 -0800 Subject: [PATCH] Upgrading Bigtable package to use gRPC beta. --- gcloud/bigtable/_helpers.py | 2 +- gcloud/bigtable/client.py | 26 ++++++++++++-------------- gcloud/bigtable/test_client.py | 23 ++++++----------------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/gcloud/bigtable/_helpers.py b/gcloud/bigtable/_helpers.py index 4c1683880841..9a0c08984d6e 100644 --- a/gcloud/bigtable/_helpers.py +++ b/gcloud/bigtable/_helpers.py @@ -82,7 +82,7 @@ def make_stub(client, stub_factory, host, port): :type port: int :param port: The port for the service. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: The stub object used to make gRPC requests to a given API. """ custom_metadata_transformer = MetadataTransformer(client) diff --git a/gcloud/bigtable/client.py b/gcloud/bigtable/client.py index 59eb0596d294..4fdf598d8bee 100644 --- a/gcloud/bigtable/client.py +++ b/gcloud/bigtable/client.py @@ -207,7 +207,7 @@ def project_name(self): def _data_stub(self): """Getter for the gRPC stub used for the Data API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. :raises: :class:`ValueError ` if the current client has not been :meth:`start`-ed. @@ -220,7 +220,7 @@ def _data_stub(self): def _cluster_stub(self): """Getter for the gRPC stub used for the Cluster Admin API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. :raises: :class:`ValueError ` if the current client is not an admin client or if it has not been @@ -236,7 +236,7 @@ def _cluster_stub(self): def _operations_stub(self): """Getter for the gRPC stub used for the Operations API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. :raises: :class:`ValueError ` if the current client is not an admin client or if it has not been @@ -252,7 +252,7 @@ def _operations_stub(self): def _table_stub(self): """Getter for the gRPC stub used for the Table Admin API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. :raises: :class:`ValueError ` if the current client is not an admin client or if it has not been @@ -267,7 +267,7 @@ def _table_stub(self): def _make_data_stub(self): """Creates gRPC stub to make requests to the Data API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. """ return make_stub(self, DATA_STUB_FACTORY, @@ -276,7 +276,7 @@ def _make_data_stub(self): def _make_cluster_stub(self): """Creates gRPC stub to make requests to the Cluster Admin API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. """ return make_stub(self, CLUSTER_STUB_FACTORY, @@ -288,7 +288,7 @@ def _make_operations_stub(self): These are for long-running operations of the Cluster Admin API, hence the host and port matching. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. """ return make_stub(self, OPERATIONS_STUB_FACTORY, @@ -297,7 +297,7 @@ def _make_operations_stub(self): def _make_table_stub(self): """Creates gRPC stub to make requests to the Table Admin API. - :rtype: :class:`grpc.early_adopter.implementations._Stub` + :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: A gRPC stub object. """ return make_stub(self, TABLE_STUB_FACTORY, @@ -388,10 +388,9 @@ def list_zones(self): zones is not in ``OK`` state. """ request_pb = messages_pb2.ListZonesRequest(name=self.project_name) - response = self._cluster_stub.ListZones.async(request_pb, - self.timeout_seconds) # We expect a `.messages_pb2.ListZonesResponse` - list_zones_response = response.result() + list_zones_response = self._cluster_stub.ListZones( + request_pb, self.timeout_seconds) result = [] for zone in list_zones_response.zones: @@ -410,10 +409,9 @@ def list_clusters(self): zones in the request). """ request_pb = messages_pb2.ListClustersRequest(name=self.project_name) - response = self._cluster_stub.ListClusters.async(request_pb, - self.timeout_seconds) # We expect a `.messages_pb2.ListClustersResponse` - list_clusters_response = response.result() + list_clusters_response = self._cluster_stub.ListClusters( + request_pb, self.timeout_seconds) failed_zones = [zone.display_name for zone in list_clusters_response.failed_zones] diff --git a/gcloud/bigtable/test_client.py b/gcloud/bigtable/test_client.py index c2e12bd601ad..7420ee599556 100644 --- a/gcloud/bigtable/test_client.py +++ b/gcloud/bigtable/test_client.py @@ -651,30 +651,19 @@ def __getattr__(self, name): class _MethodMock(object): - """Mock for :class:`grpc.framework.alpha._reexport._UnaryUnarySyncAsync`. + """Mock for API method attached to a gRPC stub. - May need to be callable and needs to (in our use) have an - ``async`` method. + In the beta implementation, these are of type. + :class:`grpc.framework.crust.implementations._UnaryUnaryMultiCallable` """ def __init__(self, name, factory): self._name = name self._factory = factory - def async(self, *args, **kwargs): - """Async method meant to mock a gRPC stub request.""" + def __call__(self, *args, **kwargs): + """Sync method meant to mock a gRPC stub request.""" self._factory.method_calls.append((self._name, args, kwargs)) curr_result, self._factory.results = (self._factory.results[0], self._factory.results[1:]) - return _AsyncResult(curr_result) - - -class _AsyncResult(object): - """Result returned from a ``_MethodMock.async`` call.""" - - def __init__(self, result): - self._result = result - - def result(self): - """Result method on an asyc object.""" - return self._result + return curr_result