Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Bigtable Cluster.copy(). #1266

Merged
merged 1 commit into from
Dec 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):

This comment was marked as spam.

return (other.project == self.project and
other.project_name == self.project_name and
other.timeout_seconds == self.timeout_seconds)