summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2015-02-22 08:20:35 +0000
committerKeith Wall <kwall@apache.org>2015-02-22 08:20:35 +0000
commit8052b6623c44580994cae37a49386162da977d96 (patch)
tree159f9e53c0894872e923b2be2cdd0c7446531db5 /python
parentfd1ce0efdf06a40b323d68f19d2c0d4540a35174 (diff)
downloadqpid-python-8052b6623c44580994cae37a49386162da977d96.tar.gz
QPID-6405: [Python Client] Retreive package version number from pkg_resources and report to the peer at connection time using version/qpid.client_version connection property
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1661459 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python')
-rw-r--r--python/qpid/client.py2
-rw-r--r--python/qpid/tests/util.py22
-rw-r--r--python/qpid/util.py13
3 files changed, 25 insertions, 12 deletions
diff --git a/python/qpid/client.py b/python/qpid/client.py
index b0ce5d9009..fbec7ccc7d 100644
--- a/python/qpid/client.py
+++ b/python/qpid/client.py
@@ -89,7 +89,7 @@ class Client:
self.password = password
self.locale = locale
self.tune_params = tune_params
- self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties)
+ self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties, version_property_key="version")
self.sasl_options = sasl_options
self.socket = connect(self.host, self.port, connection_options)
self.conn = Connection(self.socket, self.spec)
diff --git a/python/qpid/tests/util.py b/python/qpid/tests/util.py
index 9777443720..4e901218c2 100644
--- a/python/qpid/tests/util.py
+++ b/python/qpid/tests/util.py
@@ -21,26 +21,32 @@ from qpid.util import get_client_properties_with_defaults
class UtilTest (TestCase):
- def test_get_spec_recommended_client_properties(self):
- client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
+ def test_default_client_properties_08091(self):
+ client_properties = get_client_properties_with_defaults(version_property_key="version")
self.assertTrue("product" in client_properties)
self.assertTrue("version" in client_properties)
self.assertTrue("platform" in client_properties)
- def test_get_client_properties_with_provided_value(self):
+ def test_default_client_properties_010(self):
+ client_properties = get_client_properties_with_defaults(version_property_key="qpid.client_version")
+ self.assertTrue("product" in client_properties)
+ self.assertTrue("qpid.client_version" in client_properties)
+ self.assertTrue("platform" in client_properties)
+
+ def test_client_properties_with_provided_value(self):
client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"})
self.assertTrue("product" in client_properties)
self.assertTrue("mykey" in client_properties)
self.assertEqual("myvalue", client_properties["mykey"])
- def test_get_client_properties_with_no_provided_values(self):
+ def test_client_properties_with_provided_value_that_overrides_default(self):
+ client_properties = get_client_properties_with_defaults(provided_client_properties={"product":"myproduct"})
+ self.assertEqual("myproduct", client_properties["product"])
+
+ def test_client_properties_with_no_provided_values(self):
client_properties = get_client_properties_with_defaults(provided_client_properties=None)
self.assertTrue("product" in client_properties)
client_properties = get_client_properties_with_defaults()
self.assertTrue("product" in client_properties)
- def test_get_client_properties_with_provided_value_that_overrides_default(self):
- client_properties = get_client_properties_with_defaults(provided_client_properties={"version":"myversion"})
- self.assertEqual("myversion", client_properties["version"])
-
diff --git a/python/qpid/util.py b/python/qpid/util.py
index 37d999b771..fb343b536a 100644
--- a/python/qpid/util.py
+++ b/python/qpid/util.py
@@ -17,7 +17,7 @@
# under the License.
#
-import os, socket, time, textwrap, re, sys
+import os, socket, time, textwrap, re, sys, pkg_resources
try:
from ssl import wrap_socket as ssl
@@ -42,15 +42,22 @@ except ImportError:
def close(self):
self.sock.close()
-def get_client_properties_with_defaults(provided_client_properties={}):
+def get_client_properties_with_defaults(provided_client_properties={}, version_property_key="qpid.client_version"):
ppid = 0
+ version = "unidentified"
try:
ppid = os.getppid()
except:
pass
+ try:
+ pkg = pkg_resources.require("qpid-python")
+ version = pkg[0].version if pkg and pkg[0] and pkg[0].version else version
+ except:
+ pass
+
client_properties = {"product": "qpid python client",
- "version": "development",
+ version_property_key : version,
"platform": os.name,
"qpid.client_process": os.path.basename(sys.argv and sys.argv[0] or ''),
"qpid.client_pid": os.getpid(),