From 15f7c4dd7936a34151b748a4ddbf7cdc2bdb87f0 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Mon, 5 Mar 2012 21:04:04 +0000 Subject: NO-JIRA - Cleaned up qpidtoollibs 1) Fixed the update() method to work on all object types 2) Shortened the path needed in import statements 3) Updated the connection-stats test to use qpidtoollibs git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1297230 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/ha_tests.py | 2 +- qpid/python/qpid/testlib.py | 4 +- .../src/py/qpid_tests/broker_0_10/management.py | 19 +++++++++- qpid/tools/src/py/qpid-config | 2 +- qpid/tools/src/py/qpid-stat | 4 +- qpid/tools/src/py/qpidtoollibs/__init__.py | 4 ++ qpid/tools/src/py/qpidtoollibs/broker.py | 44 +++++++++++----------- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/qpid/cpp/src/tests/ha_tests.py b/qpid/cpp/src/tests/ha_tests.py index 18f47b17c5..0ab876ecab 100755 --- a/qpid/cpp/src/tests/ha_tests.py +++ b/qpid/cpp/src/tests/ha_tests.py @@ -24,7 +24,7 @@ from qpid.datatypes import uuid4 from brokertest import * from threading import Thread, Lock, Condition from logging import getLogger, WARN, ERROR, DEBUG -from qpidtoollibs.broker import BrokerAgent +from qpidtoollibs import BrokerAgent log = getLogger("qpid.ha-tests") diff --git a/qpid/python/qpid/testlib.py b/qpid/python/qpid/testlib.py index d9feb6b484..f9796982f5 100644 --- a/qpid/python/qpid/testlib.py +++ b/qpid/python/qpid/testlib.py @@ -30,7 +30,7 @@ from qpid.harness import Skipped from qpid.exceptions import VersionError import qpid.messaging -import qpidtoollibs.broker +from qpidtoollibs import BrokerAgent class TestBase(unittest.TestCase): """Base class for Qpid test cases. @@ -203,7 +203,7 @@ class TestBase010(unittest.TestCase): if 'broker_conn' not in self.__dict__: self.broker_conn = qpid.messaging.Connection(str(self.broker)) self.broker_conn.open() - self.broker_access = qpidtoollibs.broker.BrokerAgent(self.broker_conn) + self.broker_access = BrokerAgent(self.broker_conn) def connect(self, host=None, port=None): url = self.broker diff --git a/qpid/tests/src/py/qpid_tests/broker_0_10/management.py b/qpid/tests/src/py/qpid_tests/broker_0_10/management.py index 867210b11d..a17a945e29 100644 --- a/qpid/tests/src/py/qpid_tests/broker_0_10/management.py +++ b/qpid/tests/src/py/qpid_tests/broker_0_10/management.py @@ -24,8 +24,17 @@ from threading import Condition from time import sleep import qmf.console import qpid.messaging +from qpidtoollibs import BrokerAgent class ManagementTest (TestBase010): + + def setup_access(self): + if 'broker_agent' not in self.__dict__: + self.conn2 = qpid.messaging.Connection(self.broker) + self.conn2.open() + self.broker_agent = BrokerAgent(self.conn2) + return self.broker_agent + """ Tests for the management hooks """ @@ -559,12 +568,18 @@ class ManagementTest (TestBase010): """ Test message in/out stats for connection """ - self.startQmf() + agent = self.setup_access() conn = self.connect() session = conn.session("stats-session") #using qmf find named session and the corresponding connection: - conn_qmf = self.qmf.getObjects(_class="session", name="stats-session")[0]._connectionRef_ + conn_qmf = None + sessions = agent.getAllSessions() + for s in sessions: + if s.name == "stats-session": + conn_qmf = agent.getConnection(s.connectionRef) + + assert(conn_qmf) #send a message to a queue session.queue_declare(queue="stats-q", exclusive=True, auto_delete=True) diff --git a/qpid/tools/src/py/qpid-config b/qpid/tools/src/py/qpid-config index 367fd0574e..fb0f34f72e 100755 --- a/qpid/tools/src/py/qpid-config +++ b/qpid/tools/src/py/qpid-config @@ -29,7 +29,7 @@ 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 -from qpidtoollibs.broker import BrokerAgent +from qpidtoollibs import BrokerAgent usage = """ Usage: qpid-config [OPTIONS] diff --git a/qpid/tools/src/py/qpid-stat b/qpid/tools/src/py/qpid-stat index 17e4120f60..5a816baf6e 100755 --- a/qpid/tools/src/py/qpid-stat +++ b/qpid/tools/src/py/qpid-stat @@ -30,8 +30,8 @@ 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")) -from qpidtoollibs.broker import BrokerAgent -from qpidtoollibs.disp import Display, Header, Sorter, YN, Commas, TimeLong +from qpidtoollibs import BrokerAgent +from qpidtoollibs import Display, Header, Sorter, YN, Commas, TimeLong class Config: diff --git a/qpid/tools/src/py/qpidtoollibs/__init__.py b/qpid/tools/src/py/qpidtoollibs/__init__.py index 31d5a2ef58..2815bac22f 100644 --- a/qpid/tools/src/py/qpidtoollibs/__init__.py +++ b/qpid/tools/src/py/qpidtoollibs/__init__.py @@ -16,3 +16,7 @@ # specific language governing permissions and limitations # under the License. # + +from qpidtoollibs.broker import * +from qpidtoollibs.disp import * + diff --git a/qpid/tools/src/py/qpidtoollibs/broker.py b/qpid/tools/src/py/qpidtoollibs/broker.py index 98c1bfaa32..c2340de9dd 100644 --- a/qpid/tools/src/py/qpidtoollibs/broker.py +++ b/qpid/tools/src/py/qpidtoollibs/broker.py @@ -95,9 +95,8 @@ class BrokerAgent(object): self.sess.acknowledge() return items - def _doNameQuery(self, class_name, object_name, package_name='org.apache.qpid.broker'): - query = {'_what' : 'OBJECT', - '_object_id' : {'_object_name' : "%s:%s:%s" % (package_name, class_name, object_name)}} + def _doNameQuery(self, object_id): + query = {'_what' : 'OBJECT', '_object_id' : {'_object_name' : object_id}} correlator = self._sendRequest('_query_request', query) response = self.reply_rx.fetch(10) if response.properties['qmf.opcode'] != '_query_response': @@ -123,13 +122,18 @@ class BrokerAgent(object): objs.append(cls(self, item)) return objs - def _getBrokerObject(self, cls, name): - obj = self._doNameQuery(cls.__name__.lower(), name) + def _getBrokerObject(self, cls, oid): + obj = self._doNameQuery(oid) if obj: return cls(self, obj) return None def _getSingleObject(self, cls): + # + # getAllBrokerObjects is used instead of getBrokerObject(Broker, 'amqp-broker') because + # of a bug that used to be in the broker whereby by-name queries did not return the + # object timestamps. + # objects = self._getAllBrokerObjects(cls) if objects: return objects[0] return None @@ -138,11 +142,6 @@ class BrokerAgent(object): """ Get the Broker object that contains broker-scope statistics and operations. """ - # - # getAllBrokerObjects is used instead of getBrokerObject(Broker, 'amqp-broker') because - # of a bug that used to be in the broker whereby by-name queries did not return the - # object timestamps. - # return self._getSingleObject(Broker) @@ -155,32 +154,32 @@ class BrokerAgent(object): def getAllConnections(self): return self._getAllBrokerObjects(Connection) - def getConnection(self, name): - return self._getBrokerObject(Connection, name) + def getConnection(self, oid): + return self._getBrokerObject(Connection, "org.apache.qpid.broker:connection:%s" % oid) def getAllSessions(self): return self._getAllBrokerObjects(Session) - def getSession(self, name): - return self._getBrokerObject(Session, name) + def getSession(self, oid): + return self._getBrokerObject(Session, "org.apache.qpid.broker:session:%s" % oid) def getAllSubscriptions(self): return self._getAllBrokerObjects(Subscription) - def getSubscription(self, name): - return self._getBrokerObject(Subscription, name) + def getSubscription(self, oid): + return self._getBrokerObject(Subscription, "org.apache.qpid.broker:subscription:%s" % oid) def getAllExchanges(self): return self._getAllBrokerObjects(Exchange) def getExchange(self, name): - return self._getBrokerObject(Exchange, name) + return self._getBrokerObject(Exchange, "org.apache.qpid.broker:exchange:%s" % name) def getAllQueues(self): return self._getAllBrokerObjects(Queue) def getQueue(self, name): - return self._getBrokerObject(Queue, name) + return self._getBrokerObject(Queue, "org.apache.qpid.broker:queue:%s" % name) def getAllBindings(self): return self._getAllBrokerObjects(Binding) @@ -277,9 +276,9 @@ class BrokerAgent(object): """Delete an object of the specified type""" pass - def query(self, _type, name): + def query(self, _type, oid): """Query the current state of an object""" - return self._getBrokerObject(self, _type, name) + return self._getBrokerObject(self, _type, oid) class BrokerObject(object): @@ -302,6 +301,9 @@ class BrokerObject(object): return full_name[colon+1:] return value + def getObjectId(self): + return self.content['_object_id']['_object_name'] + def getAttributes(self): return self.values @@ -318,7 +320,7 @@ class BrokerObject(object): """ Reload the property values from the agent. """ - refreshed = self.broker._getBrokerObject(self.__class__, self.name) + refreshed = self.broker._getBrokerObject(self.__class__, self.getObjectId()) if refreshed: self.content = refreshed.content self.values = self.content['_values'] -- cgit v1.2.1