def test_w_explicit_serve_nodes(self): from gcloud.bigtable._generated import (instance_pb2 as data_v2_pb2) from gcloud.bigtable._generated import (bigtable_instance_admin_pb2 as messages_v2_pb) from gcloud.bigtable.instance import Instance DISPLAY_NAME = u'DISPLAY_NAME' SERVE_NODES = 5 client = _Client(self.PROJECT) instance = Instance(self.INSTANCE_ID, client, self.LOCATION_ID, display_name=DISPLAY_NAME, serve_nodes=SERVE_NODES) request_pb = self._callFUT(instance) self.assertTrue( isinstance(request_pb, messages_v2_pb.CreateInstanceRequest)) self.assertEqual(request_pb.instance_id, self.INSTANCE_ID) self.assertEqual(request_pb.parent, 'projects/' + self.PROJECT) self.assertTrue(isinstance(request_pb.instance, data_v2_pb2.Instance)) self.assertEqual(request_pb.instance.display_name, DISPLAY_NAME) # An instance must also define a same-named cluster cluster = request_pb.clusters[self.INSTANCE_ID] self.assertTrue(isinstance(cluster, data_v2_pb2.Cluster)) self.assertEqual(cluster.location, self.LOCATION_NAME) self.assertEqual(cluster.serve_nodes, SERVE_NODES)
def test_w_defaults(self): from gcloud.bigtable.cluster import DEFAULT_SERVE_NODES from gcloud.bigtable._generated import (instance_pb2 as data_v2_pb2) from gcloud.bigtable._generated import (bigtable_instance_admin_pb2 as messages_v2_pb) from gcloud.bigtable.instance import Instance client = _Client(self.PROJECT) instance = Instance(self.INSTANCE_ID, client, self.LOCATION_ID) request_pb = self._callFUT(instance) self.assertTrue( isinstance(request_pb, messages_v2_pb.CreateInstanceRequest)) self.assertEqual(request_pb.instance_id, self.INSTANCE_ID) self.assertEqual(request_pb.parent, self.PARENT) self.assertTrue(isinstance(request_pb.instance, data_v2_pb2.Instance)) self.assertEqual(request_pb.instance.name, u'') self.assertEqual(request_pb.instance.display_name, self.INSTANCE_ID) # An instance must also define a same-named cluster cluster = request_pb.clusters[self.INSTANCE_ID] self.assertTrue(isinstance(cluster, data_v2_pb2.Cluster)) self.assertEqual(cluster.name, self.CLUSTER_NAME) self.assertEqual(cluster.location, self.LOCATION_NAME) self.assertEqual(cluster.serve_nodes, DEFAULT_SERVE_NODES)
def instance(self, instance_id, location=_EXISTING_INSTANCE_LOCATION_ID, display_name=None, serve_nodes=DEFAULT_SERVE_NODES): """Factory to create a instance associated with this client. :type instance_id: str :param instance_id: The ID of the instance. :type location: string :param location: location name, in form ``projects/<project>/locations/<location>``; used to set up the instance's cluster. :type display_name: str :param display_name: (Optional) The display name for the instance in the Cloud Console UI. (Must be between 4 and 30 characters.) If this value is not set in the constructor, will fall back to the instance ID. :type serve_nodes: int :param serve_nodes: (Optional) The number of nodes in the instance's cluster; used to set up the instance's cluster. :rtype: :class:`.Instance` :returns: an instance owned by this client. """ return Instance(instance_id, self, location, display_name=display_name, serve_nodes=serve_nodes)
def list_instances(self): """List instances owned by the project. :rtype: tuple :returns: A pair of results, the first is a list of :class:`.Instance` objects returned and the second is a list of strings (the failed locations in the request). """ request_pb = bigtable_instance_admin_pb2.ListInstancesRequest( parent=self.project_name) response = self._instance_stub.ListInstances(request_pb) instances = [Instance.from_pb(instance_pb, self) for instance_pb in response.instances] return instances, response.failed_locations
def list_instances(self): """List instances owned by the project. :rtype: tuple :returns: A pair of results, the first is a list of :class:`.Instance` objects returned and the second is a list of strings (the failed locations in the request). """ request_pb = instance_admin_v2_pb2.ListInstancesRequest( parent=self.project_name) response = self._instance_stub.ListInstances( request_pb, self.timeout_seconds) instances = [Instance.from_pb(instance_pb, self) for instance_pb in response.instances] return instances, response.failed_locations
def _finished_helper(self, done): from google.longrunning import operations_pb2 from gcloud.bigtable._testing import _FakeStub from gcloud.bigtable.instance import Instance PROJECT = 'PROJECT' INSTANCE_ID = 'instance-id' TIMEOUT_SECONDS = 1 client = _Client(PROJECT, timeout_seconds=TIMEOUT_SECONDS) instance = Instance(INSTANCE_ID, client, self.LOCATION_ID) operation = self._makeOne(self.OP_TYPE, self.OP_ID, self.BEGIN, self.LOCATION_ID, instance=instance) # Create request_pb op_name = ('operations/projects/' + PROJECT + '/instances/' + INSTANCE_ID + '/locations/' + self.LOCATION_ID + '/operations/%d' % (self.OP_ID, )) request_pb = operations_pb2.GetOperationRequest(name=op_name) # Create response_pb response_pb = operations_pb2.Operation(done=done) # Patch the stub used by the API method. client._operations_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = done # Perform the method and check the result. result = operation.finished() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'GetOperation', (request_pb, TIMEOUT_SECONDS), {}, )]) if done: self.assertTrue(operation._complete) else: self.assertFalse(operation._complete)