Permalink
Browse files

added RESTful Bucket Flush to close PYCBC-40

Change-Id: I8e354a6a57bfd15b2b22aadf508e1afd25ede58b
Reviewed-on: http://review.couchbase.org/20389
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Benjamin Young <benjamin@couchbase.com>
  • Loading branch information...
1 parent 0127688 commit 82430fefac2fa09baaf5b167784797e5c5ea229d @BigBlueHat BigBlueHat committed with Benjamin Young Aug 31, 2012
Showing with 30 additions and 2 deletions.
  1. +17 −1 couchbase/client.py
  2. +1 −0 couchbase/rest_client.py
  3. +12 −1 couchbase/tests/test_client.py
View
@@ -28,6 +28,7 @@
from couchbase.logger import logger
from couchbase.rest_client import RestConnection
from couchbase.couchbaseclient import CouchbaseClient
+from couchbase.exception import BucketUnavailableException
log = logger("client")
@@ -192,7 +193,8 @@ def __init__(self, name, server):
self.name = name
rest = server._rest()
- self.password = rest.get_bucket(self.name).saslPassword
+ self.info = rest.get_bucket(self.name)
+ self.password = self.info.saslPassword
ip, port, rest_username, rest_password = server._rest_info()
formatter_uri = "http://%s:%s/pools/default"
@@ -347,6 +349,20 @@ def design_docs(self):
return ddocs
+ def flush(self):
+ """RESTful Bucket flushing - will destory all the data in a bucket."""
+ ip, port, rest_username, rest_password = self.server._rest_info()
+ api = ''.join(["http://{0}:{1}".format(ip, port),
+ self.info.controllers['flush']])
+ response = requests.post(api, auth=(rest_username, rest_password))
+
+ if response.status_code is 503:
+ raise Exception("Only buckets of type 'memcached' support flush.")
+ elif response.status_code is 404:
+ raise BucketUnavailableException
+ elif response.status_code is 200:
+ return True
+
class DesignDoc(object):
"""Object representation of a Couchbase Server Design Document--the thing
View
@@ -1051,6 +1051,7 @@ def parse_get_bucket_json(self, parsed):
bucket.port = parsed['proxyPort']
bucket.authType = parsed["authType"]
bucket.saslPassword = parsed["saslPassword"]
+ bucket.controllers = parsed['controllers']
bucket.nodes = list()
if 'vBucketServerMap' in parsed:
vBucketServerMap = parsed['vBucketServerMap']
@@ -375,6 +375,17 @@ def test_design_doc_creation_via_setitem(self):
rest = self.client.server._rest()
rest.delete_design_doc(self.client.name, 'testing_setitem')
+ @attr(cbv="2.0.0")
+ def test_flush(self):
+ """Test RESTful bucket flushing"""
+ server = self.client.server
+ rest = server._rest()
+ rest.create_bucket('memcached', bucketType='memcached')
+ # TODO: look into making wait_for_node_status() work...
+ time.sleep(5)
+ self.assertTrue(self.cb['memcached'].flush())
+ rest.delete_bucket('memcached')
+
class DesignDocTest(Base):
def setUp(self):
@@ -399,7 +410,7 @@ def setUp(self):
}
}
self.rest.create_design_doc(self.client.name, 'test_ddoc',
- json.dumps(self.ddoc))
+ json.dumps(self.ddoc))
self.design_docs = self.client.design_docs()
def tearDown(self):

0 comments on commit 82430fe

Please sign in to comment.