Skip to content

Commit

Permalink
Implementing Bigtable Cluster.copy().
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Dec 4, 2015
1 parent f575283 commit 796e122
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
15 changes: 15 additions & 0 deletions gcloud/bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ def from_pb(cls, cluster_pb, client):
result._update_from_pb(cluster_pb)
return result

def copy(self):
"""Make a copy of this cluster.
Copies the local data stored as simple types but does not copy the
current state of any operations with the Cloud Bigtable API. Also
copies the client attached to this instance.
:rtype: :class:`.Cluster`
:returns: A copy of the current cluster.
"""
new_client = self._client.copy()
return self.__class__(self.zone, self.cluster_id, new_client,
display_name=self.display_name,
serve_nodes=self.serve_nodes)

@property
def name(self):
"""Cluster name used in requests.
Expand Down
31 changes: 30 additions & 1 deletion gcloud/bigtable/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ def test_constructor_non_default(self):
self.assertEqual(cluster.serve_nodes, serve_nodes)
self.assertTrue(cluster._client is client)

def test_copy(self):
project = 'PROJECT'
zone = 'zone'
cluster_id = 'cluster-id'
display_name = 'display_name'
serve_nodes = 8

client = _Client(project)
cluster = self._makeOne(zone, cluster_id, client,
display_name=display_name,
serve_nodes=serve_nodes)
new_cluster = cluster.copy()

# Make sure the client copy succeeded.
self.assertFalse(new_cluster._client is client)
self.assertEqual(new_cluster._client, client)
# Make sure the client got copied to a new instance.
self.assertFalse(cluster is new_cluster)
self.assertEqual(cluster, new_cluster)

def test_table_factory(self):
from gcloud.bigtable.table import Table

Expand Down Expand Up @@ -80,7 +100,7 @@ def test_from_pb_success(self):
cluster_pb = data_pb2.Cluster(
name=cluster_name,
display_name=cluster_id,
serve_nodes=3,
serve_nodes=331,
)

klass = self._getTargetClass()
Expand Down Expand Up @@ -363,3 +383,12 @@ def __init__(self, project, timeout_seconds=None):
self.project = project
self.project_name = 'projects/' + self.project
self.timeout_seconds = timeout_seconds

def copy(self):
from copy import deepcopy
return deepcopy(self)

def __eq__(self, other):
return (other.project == self.project and
other.project_name == self.project_name and
other.timeout_seconds == self.timeout_seconds)

0 comments on commit 796e122

Please sign in to comment.