Repository: qpid-cpp
Updated Branches:
  refs/heads/master 7ca027022 -> 550b62723


QPID-7432: Make python management tools work over AMQP 1.0

Two bugs in qpid_messaging found and fixed, required for qpidtoollibs to work:

- incorrect encoding of python Unicode strings, assumed default-encoding=UTF8.
- bug in Message.content decoding an empty list or map body.

With those fixes, the existing qpidtoollibs works with AMQP 1.0 if you use a
qpid_messaging.Connection instead of a qpid.messaging.Connection.

qpid_messaging implements the same API as qpid.messaging, but using SWIG over
the C++ codec which supports AMQP 1.0. An existing tool can be updated to prefer
qpid_messaging as follows:

    try:
        from qpid_messaging import Connection
    except:
        from qpid.messaging import Connection

Or if you don't care about qpid.messaging you can simply import qpid_messaging.

NOTE: qpid-route does NOT work on AMQP1.0, as it is based on an older client.
Raise a new issue if that also needs to be ported to qpidtoollibs for 1.0 
support.


Project: http://git-wip-us.apache.org/repos/asf/qpid-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-cpp/commit/550b6272
Tree: http://git-wip-us.apache.org/repos/asf/qpid-cpp/tree/550b6272
Diff: http://git-wip-us.apache.org/repos/asf/qpid-cpp/diff/550b6272

Branch: refs/heads/master
Commit: 550b62723bb6b80035961c93c05de4cbd0ab170e
Parents: 7ca0270
Author: Alan Conway <acon...@redhat.com>
Authored: Wed Sep 21 15:54:08 2016 -0400
Committer: Alan Conway <acon...@redhat.com>
Committed: Wed Sep 21 16:23:47 2016 -0400

----------------------------------------------------------------------
 bindings/qpid/python/qpid_messaging.i  |  3 ++-
 include/qpid/swig_python_typemaps.i    |  5 ++++-
 management/python/bin/qpid-config      |  9 +++++---
 management/python/bin/qpid-ha          |  6 ++++--
 management/python/bin/qpid-printevents | 10 +++++----
 management/python/bin/qpid-receive     |  5 ++++-
 management/python/bin/qpid-send        |  8 +++++---
 management/python/bin/qpid-stat        |  6 +++++-
 management/python/test.sh              | 32 +++++++++++++++++++++++++++++
 9 files changed, 68 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/bindings/qpid/python/qpid_messaging.i
----------------------------------------------------------------------
diff --git a/bindings/qpid/python/qpid_messaging.i 
b/bindings/qpid/python/qpid_messaging.i
index 513cc53..688b7ea 100644
--- a/bindings/qpid/python/qpid_messaging.i
+++ b/bindings/qpid/python/qpid_messaging.i
@@ -468,13 +468,14 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError)
 
          def _get_content(self) :
              obj = self.getContentObject()
-             if obj:
+             if obj is not None:
                  return obj
              if self.content_type == "amqp/list" :
                  return decodeList(self)
              if self.content_type == "amqp/map" :
                  return decodeMap(self)
              return self.getContent()
+
          def _set_content(self, content) :
              if isinstance(content, str) :
                  self.setContent(content)

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/include/qpid/swig_python_typemaps.i
----------------------------------------------------------------------
diff --git a/include/qpid/swig_python_typemaps.i 
b/include/qpid/swig_python_typemaps.i
index a27782d..5bad619 100644
--- a/include/qpid/swig_python_typemaps.i
+++ b/include/qpid/swig_python_typemaps.i
@@ -69,7 +69,10 @@ typedef int Py_ssize_t;
         if (PyInt_Check(value))    return 
qpid::types::Variant(int64_t(PyLong_AS_LONG(value)));
         if (PyString_Check(value)) return 
qpid::types::Variant(std::string(PyBytes_AS_STRING(value)));
         if (PyUnicode_Check(value)) {
-            qpid::types::Variant v(std::string(PyUnicode_AS_DATA(value)));
+            PyObject* utf8 = PyUnicode_AsUTF8String(value);
+            std::string s(PyBytes_AS_STRING(utf8));
+            Py_XDECREF(utf8);
+            qpid::types::Variant v(s);
             v.setEncoding("utf8");
             return v;
         }

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-config
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-config 
b/management/python/bin/qpid-config
index 3d4bb60..793b15a 100755
--- a/management/python/bin/qpid-config
+++ b/management/python/bin/qpid-config
@@ -28,9 +28,12 @@ import locale
 home = os.environ.get("QPID_TOOLS_HOME", 
os.path.normpath("/usr/share/qpid-tools"))
 sys.path.append(os.path.join(home, "python"))
 
-from qpid.messaging import Connection, ConnectionError
-from qpidtoollibs import BrokerAgent
-from qpidtoollibs import Display, Header
+try:
+    from qpid_messaging import Connection, ConnectionError
+except:
+    from qpid.messaging import Connection, ConnectionError
+
+from qpidtoollibs import BrokerAgent, Display, Header
 
 usage = """
 Usage:  qpid-config [OPTIONS]

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-ha
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-ha b/management/python/bin/qpid-ha
index 1c07658..88116ca 100755
--- a/management/python/bin/qpid-ha
+++ b/management/python/bin/qpid-ha
@@ -20,8 +20,10 @@
 #
 
 import optparse, sys, time, os, re, math
-from qpid.messaging import Connection
-from qpid.messaging import Message as QpidMessage
+try:
+    from qpid_messaging import Connection
+except:
+    from qpid.messaging import Connection
 from qpid.util import URL
 from qpidtoollibs.broker import BrokerAgent
 from qpidtoollibs.config import parse_qpidd_conf

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-printevents
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-printevents 
b/management/python/bin/qpid-printevents
index f702ca9..7181fc9 100755
--- a/management/python/bin/qpid-printevents
+++ b/management/python/bin/qpid-printevents
@@ -25,8 +25,10 @@ import sys
 from optparse       import IndentedHelpFormatter
 from time           import time, strftime, gmtime, sleep
 from threading      import Lock, Condition, Thread
-from qpid.messaging import Connection
-import qpid.messaging.exceptions
+try:
+  from qpid_messaging import Connection, exceptions
+except:
+  from qpid.messaging import Connection, exceptions
 
 home = os.environ.get("QPID_TOOLS_HOME", 
os.path.normpath("/usr/share/qpid-tools"))
 sys.path.append(os.path.join(home, "python"))
@@ -85,9 +87,9 @@ class EventReceiver(Thread):
             event = self.helper.event(msg)
             self.printer.pr(event.__repr__())
             sess.acknowledge()
-          except qpid.messaging.exceptions.Empty:
+          except exceptions.Empty:
             pass
-        
+
       except Exception, e:
         if isOpen:
           self.printer.pr(strftime("%c", gmtime(time())) + " NOTIC 
qpid-printevents:brokerDisconnected broker=%s" % self.url)

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-receive
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-receive 
b/management/python/bin/qpid-receive
index f14df27..a055b4f 100755
--- a/management/python/bin/qpid-receive
+++ b/management/python/bin/qpid-receive
@@ -20,7 +20,10 @@
 
 import optparse, sys, time
 import statistics
-from qpid.messaging import *
+try:
+    from qpid_messaging import *
+except:
+    from qpid.messaging import *
 
 SECOND = 1000
 TIME_SEC = 1000000000

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-send
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-send b/management/python/bin/qpid-send
index b0105e4..2268541 100755
--- a/management/python/bin/qpid-send
+++ b/management/python/bin/qpid-send
@@ -18,9 +18,11 @@
 # under the License.
 #
 
-import optparse, random, os, time, uuid
-from qpid.messaging import *
-import statistics
+import optparse, random, os, time, uuid, statistics
+try:
+    from qpid_messaging import *
+except:
+    from qpid.messaging import *
 
 EOS = "eos"
 SN = "sn"

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/bin/qpid-stat
----------------------------------------------------------------------
diff --git a/management/python/bin/qpid-stat b/management/python/bin/qpid-stat
index 1780c4a..1bff8ad 100755
--- a/management/python/bin/qpid-stat
+++ b/management/python/bin/qpid-stat
@@ -25,7 +25,11 @@ import sys
 import locale
 import socket
 import re
-from qpid.messaging import Connection
+
+try:
+    from qpid_messaging import Connection
+except:
+    from qpid.messaging import Connection
 
 home = os.environ.get("QPID_TOOLS_HOME", 
os.path.normpath("/usr/share/qpid-tools"))
 sys.path.append(os.path.join(home, "python"))

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/550b6272/management/python/test.sh
----------------------------------------------------------------------
diff --git a/management/python/test.sh b/management/python/test.sh
new file mode 100755
index 0000000..2bb8a03
--- /dev/null
+++ b/management/python/test.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# Smoke test the management tools with AMQP 1.0 protocol
+
+set -e -x
+
+DIR=$(mktemp -d)
+PORT=$(qpidd -dp0 --ha-queue-replication=yes  --auth=no --protocols=amqp1.0 
--data-dir $DIR)
+trap "qpidd -qp $PORT; rm -rf $DIR" EXIT
+
+qpid-config -b localhost:$PORT add queue test-foo
+qpid-stat -b localhost:$PORT -q | grep test-foo
+
+qpid-config -b localhost:$PORT add exchange topic test-ex
+qpid-stat -b localhost:$PORT -e | grep test-ex
+
+qpid-config -b localhost:$PORT add queue test-bar
+qpid-config -b localhost:$PORT del queue test-bar
+{ qpid-stat -b localhost:$PORT -q | grep test-bar; } && { echo not deleted; 
exit 1; }
+
+qpid-stat -b localhost:$PORT -m | grep malloc_arena
+qpid-stat -b localhost:$PORT -g | grep queue-depth
+qpid-stat -b localhost:$PORT -c | grep Connections
+qpid-stat -b localhost:$PORT -u | grep Subscriptions
+
+qpid-ha -b localhost:$PORT query | grep standalone
+qpid-ha -b localhost:$PORT status | grep standalone
+
+qpid-send -b localhost:$PORT -a test-foo --content-string hello
+qpid-receive -b localhost:$PORT -a test-foo | grep hello
+
+echo PASS
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to