Esempio n. 1
0
    def reload(self):
        """Reload the metadata for this cluster."""
        request_pb = messages_pb2.GetClusterRequest(name=self.name)
        # We expect a `._generated.bigtable_cluster_data_pb2.Cluster`.
        cluster_pb = self._client._cluster_stub.GetCluster(
            request_pb, self._client.timeout_seconds)

        # NOTE: _update_from_pb does not check that the project, zone and
        #       cluster ID on the response match the request.
        self._update_from_pb(cluster_pb)
Esempio n. 2
0
    def test_reload(self):
        from gcloud.bigtable._generated import (bigtable_cluster_data_pb2 as
                                                data_pb2)
        from gcloud.bigtable._generated import (
            bigtable_cluster_service_messages_pb2 as messages_pb2)
        from gcloud.bigtable._testing import _FakeStub
        from gcloud.bigtable.cluster import DEFAULT_SERVE_NODES

        project = 'PROJECT'
        zone = 'zone'
        cluster_id = 'cluster-id'
        timeout_seconds = 123

        client = _Client(project, timeout_seconds=timeout_seconds)
        cluster = self._makeOne(zone, cluster_id, client)

        # Create request_pb
        cluster_name = ('projects/' + project + '/zones/' + zone +
                        '/clusters/' + cluster_id)
        request_pb = messages_pb2.GetClusterRequest(name=cluster_name)

        # Create response_pb
        serve_nodes = 31
        display_name = u'hey-hi-hello'
        response_pb = data_pb2.Cluster(
            display_name=display_name,
            serve_nodes=serve_nodes,
        )

        # Patch the stub used by the API method.
        client._cluster_stub = stub = _FakeStub(response_pb)

        # Create expected_result.
        expected_result = None  # reload() has no return value.

        # Check Cluster optional config values before.
        self.assertEqual(cluster.serve_nodes, DEFAULT_SERVE_NODES)
        self.assertEqual(cluster.display_name, cluster_id)

        # Perform the method and check the result.
        result = cluster.reload()
        self.assertEqual(result, expected_result)
        self.assertEqual(stub.method_calls, [(
            'GetCluster',
            (request_pb, timeout_seconds),
            {},
        )])

        # Check Cluster optional config values before.
        self.assertEqual(cluster.serve_nodes, serve_nodes)
        self.assertEqual(cluster.display_name, display_name)