Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
PYCBC-412: update SDK to provide diagnostics/ping support
Motivation ---------- The libcouchbase SDK has evolved in how it provides diagnostics pertinent to the health of the cluster. Python SDK must be updated to reflect these changes. Modifications ------------- - Renamed Bucket.get_health to Bucket.ping (to match lcb_ping3) from libcouchbase, to better represent the abstraction level provided. Users will have to build their own heuristics that interpret the information returned from ping. - Exposed the lcb_diag function as Bucket.diag, providing activity information, connection status per node, as well as API/version information from the client. Results ------- Client now successfully passes through the diag and ping result structures, as validated by the schema listed in "couchbase.tests.cases.diag_t". Change-Id: I15909dca1c12d8e79f9f76bc3419f53ec5424b1a Reviewed-on: http://review.couchbase.org/87160 Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com> Tested-by: Ellis Breen <ellis.breen@couchbase.com>
- Loading branch information
Showing
9 changed files
with
269 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ CouchbaseMock.jar | |
/.pydevproject | ||
/cmake-build-debug/ | ||
/make.sh | ||
html | ||
latex | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# | ||
# Copyright 2017, Couchbase, Inc. | ||
# All Rights Reserved | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License") | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from unittest import SkipTest | ||
|
||
from couchbase.tests.base import ConnectionTestCase | ||
import jsonschema | ||
import re | ||
|
||
# For Python 2/3 compatibility | ||
try: | ||
basestring | ||
except NameError: | ||
basestring = str | ||
|
||
service_schema = {"type": "object", | ||
"properties": {"details": {"type": "string"}, | ||
"latency": {"anyOf": [{"type": "number"}, {"type": "string"}]}, | ||
"server": {"type": "string"}, | ||
"status": {"type": "number"} | ||
}, | ||
"required": ["details", "latency", "server", "status"]} | ||
|
||
any_of_required_services_schema = {"type": "array", | ||
"items": service_schema} | ||
|
||
|
||
def gen_schema_for_services_with_required_entry(name): | ||
return {"type": "object", | ||
"properties": {name: any_of_required_services_schema}, | ||
"required": [name] | ||
} | ||
|
||
|
||
any_of_required_services_schema = {"anyOf": | ||
[gen_schema_for_services_with_required_entry(name) for name in ["n1ql", "views", "fts", "kv"]] | ||
} | ||
|
||
ping_schema = {"anyOf": [{ | ||
"type": "object", | ||
"properties": { | ||
"services": any_of_required_services_schema | ||
}, | ||
"required": ["services"] | ||
}]} | ||
|
||
server_and_port_schema = {"type": "string", | ||
"pattern": "([0-9]{1,3}\.){3,3}[0-9]{1,3}:[0-9]+"} | ||
connection_status_schema = {"type": "string", | ||
"pattern": "connected"} | ||
config_schema = {"type": "array", | ||
"items": {"type": "object", | ||
"properties": { | ||
"id": {"type": "string"}, | ||
"last_activity_us": {"type": "number"}, | ||
"local": server_and_port_schema, | ||
"remote": server_and_port_schema, | ||
"status": connection_status_schema | ||
}}} | ||
|
||
python_id="PYCBC" | ||
|
||
client_id_schema = {"type": "string", | ||
"pattern": "^0x[a-f0-9]+/"+python_id} | ||
|
||
three_part_ver_num = "([0-9]+\.)+[0-9]+" | ||
|
||
sdk_schema = {"type": "string", | ||
"pattern": "libcouchbase" + | ||
re.escape("/") + three_part_ver_num + "_[0-9]+_(.*?)" + | ||
re.escape(python_id + "/") + | ||
three_part_ver_num + "\.[^\s]*"} | ||
|
||
|
||
diagnostics_schema = {"type": "object", | ||
"properties": { | ||
"config": config_schema, | ||
"id": client_id_schema, | ||
"sdk": sdk_schema, | ||
"version": {"type": "number"} | ||
|
||
}} | ||
|
||
|
||
class DiagnosticsTests(ConnectionTestCase): | ||
|
||
def setUp(self): | ||
super(DiagnosticsTests, self).setUp() | ||
|
||
def test_ping(self): | ||
result = self.cb.ping() | ||
jsonschema.validate(result, any_of_required_services_schema) | ||
|
||
def test_diagnostics(self): | ||
|
||
if self.is_mock: | ||
raise SkipTest() | ||
result = self.cb.diagnostics() | ||
|
||
jsonschema.validate(result, diagnostics_schema) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.