예제 #1
0
    def test_described_objs(self):
        # create console
        # find agents
        # asynchronous query for all schema-based objects
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        for aname in ["agent1", "agent2"]:
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            #
            t_params = {
                QmfData.KEY_SCHEMA_ID: SchemaClassId("MyPackage", "MyClass")
            }
            query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT, t_params)
            #
            rc = self.console.do_query(agent, query, _reply_handle=aname)
            self.assertTrue(rc)

        # done.  Now wait for async responses

        count = 0
        while self.notifier.wait_for_work(3):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                count += 1
                self.assertTrue(wi.get_type() == WorkItem.QUERY_COMPLETE)
                self.assertTrue(wi.get_handle() == "agent1"
                                or wi.get_handle() == "agent2")
                reply = wi.get_params()
                self.assertTrue(len(reply) == 3)
                self.assertTrue(
                    isinstance(reply[0], qmf2.console.QmfConsoleData))
                self.assertTrue(reply[0].is_described())  # has schema
                self.console.release_workitem(wi)
                wi = self.console.get_next_workitem(timeout=0)

        self.assertTrue(count == 2)
        # @todo test if the console has learned the corresponding schemas....
        self.console.destroy(10)
예제 #2
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.timeout = 3
        self.broker_url = broker_url
        self.notifier = _testNotifier()
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaEventClass(_classId=SchemaClassId(
            "MyPackage", "MyClass", stype=SchemaClassId.TYPE_EVENT),
                                   _desc="A test event schema")
        # add properties
        _schema.add_property("prop-1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("prop-2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # Add schema to Agent
        self.schema = _schema
        self.agent.register_object_class(_schema)

        self.running = False
        self.ready = Event()
예제 #3
0
    def test_sync_periodic_publish_noncontinuous(self):
        # create console, find agent
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        # Change noncontinuous property on each publish,
        # should only see 1 publish per each update
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        # find an agent
        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent, query, "some-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)
        self.assertTrue(sp.get_duration() == 10)
        self.assertTrue(sp.get_publish_interval() == 2)

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        sid = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                self.assertTrue(wi.get_handle() == "some-handle")
                if r_count == 1:
                    # first indication - returns all matching objects
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 2)
                    for obj in reply:
                        self.assertTrue(isinstance(obj, QmfData))
                        self.assertTrue(obj.get_object_id() == "p1c1_key2"
                                        or obj.get_object_id() == "p1c1_key1")
                        sid = obj.get_schema_class_id()
                        self.assertTrue(isinstance(sid, SchemaClassId))
                        self.assertTrue(sid.get_package_name() == "package1")
                        self.assertTrue(sid.get_class_name() == "class1")

                else:
                    # verify publish of modified object only!
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    obj = reply[0]
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2")
                    self.assertTrue(obj.get_value("count2") == r_count - 1)
                    # fail test if we receive more than expected
                    self.assertTrue(r_count < 30)

                # now update the noncontinuous field of one of the objects!
                if r_count < 20:
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count2", r_count)

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect at least 1 publish per update
        self.assertTrue(r_count > 10)

        self.console.destroy(10)
예제 #4
0
    def test_async_cancel(self):
        # create console
        # find one agent
        # async subscribe to changes to any object in package1/class1
        # cancel after first data indication
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        rc = self.console.create_subscription(agent,
                                              query,
                                              "my-handle",
                                              _blocking=False)
        self.assertTrue(rc)

        r_count = 0
        sp = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                if wi.get_type() == WorkItem.SUBSCRIBE_RESPONSE:
                    self.assertTrue(wi.get_handle() == "my-handle")
                    sp = wi.get_params()
                    self.assertTrue(
                        isinstance(sp, qmf2.console.SubscribeParams))
                    self.assertTrue(sp.succeeded())
                    self.assertTrue(sp.get_error() == None)
                else:
                    self.assertTrue(
                        wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                    # sp better be set up by now!
                    self.assertTrue(
                        isinstance(sp, qmf2.console.SubscribeParams))
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    self.assertTrue(isinstance(reply[0], QmfData))
                    self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                    sid = reply[0].get_schema_class_id()
                    self.assertTrue(isinstance(sid, SchemaClassId))
                    self.assertTrue(sid.get_package_name() == "package1")
                    self.assertTrue(sid.get_class_name() == "class1")
                    self.assertTrue(wi.get_handle() == "my-handle")

                    # count1 is continuous, touching it will force a
                    # publish on the interval
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count1", r_count)

                if r_count == 3:
                    self.console.cancel_subscription(sp.get_subscription_id())

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect cancel after 3 replies
        self.assertTrue(r_count == 3)

        self.console.destroy(10)
예제 #5
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_duration=10,
                           default_duration=7,
                           min_duration=5,
                           min_interval=1,
                           default_interval=2)

        # Management Database
        # - two different schema packages,
        # - two classes within one schema package
        # - multiple objects per schema package+class
        # - two "undescribed" objects

        # "package1/class1"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class1"),
                                    _desc="A test data schema - one",
                                    _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))

        # note: count1 is continuous, count2 is not
        count1_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=True)
        _schema.add_property("count1", count1_prop)
        count2_prop = SchemaProperty.create(qmfTypes.TYPE_UINT32,
                                            continuous=False)
        _schema.add_property("count2", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key1"},
                            _schema=_schema)
        _obj.set_value("count1", 0)
        _obj.set_value("count2", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p1c1_key2"},
                            _schema=_schema)
        _obj.set_value("count1", 9)
        _obj.set_value("count2", 10)
        self.agent.add_object(_obj)

        # "package1/class2"

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "package1", "class2"),
                                    _desc="A test data schema - two",
                                    _object_id_names=["name"])
        # add properties
        _schema.add_property("name", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("string1", SchemaProperty(qmfTypes.TYPE_LSTR))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name1"},
                            _schema=_schema)
        _obj.set_value("string1", "a data string")
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"name": "p1c2_name2"},
                            _schema=_schema)
        _obj.set_value("string1", "another data string")
        self.agent.add_object(_obj)

        # "package2/class1"

        _schema = SchemaObjectClass(
            _classId=SchemaClassId("package2", "class1"),
            _desc="A test data schema - second package",
            _object_id_names=["key"])

        _schema.add_property("key", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("counter", SchemaProperty(qmfTypes.TYPE_UINT32))

        self.agent.register_object_class(_schema)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key1"},
                            _schema=_schema)
        _obj.set_value("counter", 0)
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent,
                            _values={"key": "p2c1_key2"},
                            _schema=_schema)
        _obj.set_value("counter", 2112)
        self.agent.add_object(_obj)

        # add two "unstructured" objects to the Agent

        _obj = QmfAgentData(self.agent, _object_id="undesc-1")
        _obj.set_value("field1", "a value")
        _obj.set_value("field2", 2)
        _obj.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj.set_value("field4", ["a", "list", "value"])
        self.agent.add_object(_obj)

        _obj = QmfAgentData(self.agent, _object_id="undesc-2")
        _obj.set_value("key-1", "a value")
        _obj.set_value("key-2", 2)
        self.agent.add_object(_obj)

        self.running = False
        self.ready = Event()
예제 #6
0
    def test_sync_refresh(self):
        # create console
        # find one agent
        # subscribe to changes to any object in package1/class1
        # after 3 data indications, refresh
        # verify > 5 more data indications received
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent, query, "my-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)

        # refresh after three subscribe indications, count all
        # indications to verify refresh worked
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() == "my-handle")

                # count1 is continuous, touching it will force a
                # publish on the interval
                self.assertTrue(sid is not None)
                test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                self.assertTrue(test_obj is not None)
                test_obj.set_value("count1", r_count)

                self.console.release_workitem(wi)

                if r_count == 3:
                    rp = self.console.refresh_subscription(
                        sp.get_subscription_id())
                    self.assertTrue(rp)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 5 publish per subscription, more if refreshed
        self.assertTrue(r_count > 5)

        self.console.destroy(10)
예제 #7
0
    def test_sync_by_obj_id_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match object "p2c1_key2" in schema package2/class1
        sid = SchemaClassId.create("package2", "class1")
        query = QmfQuery.create_id_object("p2c1_key2", sid)

        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent, query, index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for all subscriptions to expire (2x interval w/o
        # indications)
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p2c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package2")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
예제 #8
0
    def test_sync_by_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent, query, index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)
            self.assertTrue(sp.get_duration() == 10)
            self.assertTrue(sp.get_publish_interval() == 2)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 2)
                for obj in reply:
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2"
                                    or obj.get_object_id() == "p1c1_key1")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")

                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
예제 #9
0
    def test_end(self):
        print("!!! end test")


#
# An example agent application
#

if __name__ == '__main__':
    _notifier = ExampleNotifier()
    _agent = Agent("qmf.testAgent", _notifier=_notifier)

    # Dynamically construct a class schema

    _schema = SchemaObjectClass(_classId=SchemaClassId("MyPackage", "MyClass"),
                                _desc="A test data schema",
                                _object_id_names=["index1", "index2"])
    # add properties
    _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
    _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

    # these two properties are statistics
    _schema.add_property("query_count", SchemaProperty(qmfTypes.TYPE_UINT32))
    _schema.add_property("method_call_count",
                         SchemaProperty(qmfTypes.TYPE_UINT32))

    # These two properties can be set via the method call
    _schema.add_property("set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
    _schema.add_property("set_int", SchemaProperty(qmfTypes.TYPE_UINT32))
예제 #10
0
파일: subscriptions.py 프로젝트: ncdc/qpid
    def test_sync_periodic_publish_noncontinuous(self):
        # create console, find agent
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        # Change noncontinuous property on each publish,
        # should only see 1 publish per each update 
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        # find an agent
        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent,
                                              query,
                                              "some-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)
        self.assertTrue(sp.get_duration() == 10)
        self.assertTrue(sp.get_publish_interval() == 2)

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        sid = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                self.assertTrue(wi.get_handle() == "some-handle")
                if r_count == 1:
                    # first indication - returns all matching objects
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 2)
                    for obj in reply:
                        self.assertTrue(isinstance(obj, QmfData))
                        self.assertTrue(obj.get_object_id() == "p1c1_key2" or
                                        obj.get_object_id() == "p1c1_key1")
                        sid = obj.get_schema_class_id()
                        self.assertTrue(isinstance(sid, SchemaClassId))
                        self.assertTrue(sid.get_package_name() == "package1")
                        self.assertTrue(sid.get_class_name() == "class1")

                else:
                    # verify publish of modified object only!
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    obj = reply[0]
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2")
                    self.assertTrue(obj.get_value("count2") == r_count - 1)
                    # fail test if we receive more than expected
                    self.assertTrue(r_count < 30)


                # now update the noncontinuous field of one of the objects!
                if r_count < 20:
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count2", r_count)

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect at least 1 publish per update
        self.assertTrue(r_count > 10)

        self.console.destroy(10)
예제 #11
0
파일: subscriptions.py 프로젝트: ncdc/qpid
    def test_async_cancel(self):
        # create console
        # find one agent
        # async subscribe to changes to any object in package1/class1
        # cancel after first data indication
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        rc = self.console.create_subscription(agent,
                                              query,
                                              "my-handle",
                                              _blocking=False)
        self.assertTrue(rc)

        r_count = 0
        sp = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                if wi.get_type() == WorkItem.SUBSCRIBE_RESPONSE:
                    self.assertTrue(wi.get_handle() == "my-handle")
                    sp = wi.get_params()
                    self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
                    self.assertTrue(sp.succeeded())
                    self.assertTrue(sp.get_error() == None)
                else:
                    self.assertTrue(wi.get_type() ==
                                    WorkItem.SUBSCRIBE_INDICATION)
                    # sp better be set up by now!
                    self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    self.assertTrue(isinstance(reply[0], QmfData))
                    self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                    sid = reply[0].get_schema_class_id()
                    self.assertTrue(isinstance(sid, SchemaClassId))
                    self.assertTrue(sid.get_package_name() == "package1")
                    self.assertTrue(sid.get_class_name() == "class1")
                    self.assertTrue(wi.get_handle() == "my-handle")

                    # count1 is continuous, touching it will force a
                    # publish on the interval
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count1", r_count)

                if r_count == 3:
                    self.console.cancel_subscription(sp.get_subscription_id())

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect cancel after 3 replies
        self.assertTrue(r_count == 3)

        self.console.destroy(10)
예제 #12
0
파일: subscriptions.py 프로젝트: ncdc/qpid
    def test_sync_refresh(self):
        # create console
        # find one agent
        # subscribe to changes to any object in package1/class1
        # after 3 data indications, refresh
        # verify > 5 more data indications received
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent,
                                              query,
                                              "my-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)

        # refresh after three subscribe indications, count all
        # indications to verify refresh worked
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() == "my-handle")

                # count1 is continuous, touching it will force a
                # publish on the interval
                self.assertTrue(sid is not None)
                test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                self.assertTrue(test_obj is not None)
                test_obj.set_value("count1", r_count)

                self.console.release_workitem(wi)

                if r_count == 3:
                    rp = self.console.refresh_subscription(sp.get_subscription_id())
                    self.assertTrue(rp)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 5 publish per subscription, more if refreshed
        self.assertTrue(r_count > 5)

        self.console.destroy(10)
예제 #13
0
파일: subscriptions.py 프로젝트: ncdc/qpid
    def test_sync_by_obj_id_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match object "p2c1_key2" in schema package2/class1
        sid = SchemaClassId.create("package2", "class1")
        query = QmfQuery.create_id_object("p2c1_key2", sid)

        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent,
                                                  query,
                                                  index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for all subscriptions to expire (2x interval w/o
        # indications)
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p2c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package2")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
예제 #14
0
파일: subscriptions.py 프로젝트: ncdc/qpid
    def test_sync_by_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent,
                                                  query,
                                                  index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)
            self.assertTrue(sp.get_duration() == 10)
            self.assertTrue(sp.get_publish_interval() == 2)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 2)
                for obj in reply:
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2" or
                                    obj.get_object_id() == "p1c1_key1")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")

                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
예제 #15
0
    def test_wildcard_schema_id(self):
        # create console
        # find all agents
        # synchronous query for all described objects by:
        #    oid & wildcard schema_id
        #    wildcard schema_id
        # verify known object ids are returned
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

        wild_schema_id = SchemaClassId("package1", "class1")
        objs = self.console.get_objects(_schema_id=wild_schema_id, _timeout=5)
        self.assertTrue(len(objs) == (self.agent_count * 2))
        for obj in objs:
            self.assertTrue(
                obj.get_schema_class_id().get_package_name() == "package1")
            self.assertTrue(
                obj.get_schema_class_id().get_class_name() == "class1")

        wild_schema_id = SchemaClassId("package1", "class2")
        objs = self.console.get_objects(_schema_id=wild_schema_id, _timeout=5)
        self.assertTrue(len(objs) == self.agent_count)
        for obj in objs:
            self.assertTrue(
                obj.get_schema_class_id().get_package_name() == "package1")
            self.assertTrue(
                obj.get_schema_class_id().get_class_name() == "class2")
            self.assertTrue(obj.get_object_id() == "p1c2_name1")

        wild_schema_id = SchemaClassId("package2", "class1")
        objs = self.console.get_objects(_schema_id=wild_schema_id, _timeout=5)
        self.assertTrue(len(objs) == (self.agent_count * 2))
        for obj in objs:
            self.assertTrue(
                obj.get_schema_class_id().get_package_name() == "package2")
            self.assertTrue(
                obj.get_schema_class_id().get_class_name() == "class1")

        wild_schema_id = SchemaClassId("package1", "class1")
        objs = self.console.get_objects(_schema_id=wild_schema_id,
                                        _object_id="p1c1_key2",
                                        _timeout=5)
        self.assertTrue(len(objs) == self.agent_count)
        for obj in objs:
            self.assertTrue(
                obj.get_schema_class_id().get_package_name() == "package1")
            self.assertTrue(
                obj.get_schema_class_id().get_class_name() == "class1")
            self.assertTrue(obj.get_object_id() == "p1c1_key2")

        # should fail
        objs = self.console.get_objects(_schema_id=wild_schema_id,
                                        _object_id="does not exist",
                                        _timeout=5)
        self.assertTrue(objs == None)

        wild_schema_id = SchemaClassId("package2", "class1")
        objs = self.console.get_objects(_schema_id=wild_schema_id,
                                        _object_id="p2c1_key2",
                                        _timeout=5)
        self.assertTrue(len(objs) == self.agent_count)
        for obj in objs:
            self.assertTrue(
                obj.get_schema_class_id().get_package_name() == "package2")
            self.assertTrue(
                obj.get_schema_class_id().get_class_name() == "class1")
            self.assertTrue(obj.get_object_id() == "p2c1_key2")

        # should fail
        wild_schema_id = SchemaClassId("package1", "bad-class")
        objs = self.console.get_objects(_schema_id=wild_schema_id,
                                        _object_id="p1c1_key2",
                                        _timeout=5)
        self.assertTrue(objs == None)

        self.console.destroy(10)
예제 #16
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat)

        # Dynamically construct a management database

        _schema = SchemaObjectClass(_classId=SchemaClassId(
            "MyPackage", "MyClass"),
                                    _desc="A test data schema",
                                    _object_id_names=["index1", "index2"])
        # add properties
        _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
        _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

        # these two properties are statistics
        _schema.add_property("query_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))
        _schema.add_property("method_call_count",
                             SchemaProperty(qmfTypes.TYPE_UINT32))

        # These two properties can be set via the method call
        _schema.add_property("set_string", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_property("set_int", SchemaProperty(qmfTypes.TYPE_UINT32))

        # add method
        _meth = SchemaMethod(_desc="Method to set string and int in object.")
        _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
        _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
        _schema.add_method("set_meth", _meth)

        # Add schema to Agent

        self.agent.register_object_class(_schema)

        # instantiate managed data objects matching the schema

        _obj1 = QmfAgentData(self.agent,
                             _schema=_schema,
                             _values={
                                 "index1": 100,
                                 "index2": "a name"
                             })
        _obj1.set_value("set_string", "UNSET")
        _obj1.set_value("set_int", 0)
        _obj1.set_value("query_count", 0)
        _obj1.set_value("method_call_count", 0)
        self.agent.add_object(_obj1)

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 99,
                             "index2": "another name",
                             "set_string": "UNSET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        self.agent.add_object(
            QmfAgentData(self.agent,
                         _schema=_schema,
                         _values={
                             "index1": 50,
                             "index2": "my name",
                             "set_string": "SET",
                             "set_int": 0,
                             "query_count": 0,
                             "method_call_count": 0
                         }))

        # add an "unstructured" object to the Agent
        _obj2 = QmfAgentData(self.agent, _object_id="01545")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 2)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 50)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01546")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 3)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 51)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01544")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 49)
        self.agent.add_object(_obj2)

        _obj2 = QmfAgentData(self.agent, _object_id="01543")
        _obj2.set_value("field1", "a value")
        _obj2.set_value("field2", 4)
        _obj2.set_value("field3", {"a": 1, "map": 2, "value": 3})
        _obj2.set_value("field4", ["a", "list", "value"])
        _obj2.set_value("index1", 48)
        self.agent.add_object(_obj2)

        self.running = False
        self.ready = Event()
예제 #17
0
    def __init__(self, name, broker_url, heartbeat):
        Thread.__init__(self)
        self.schema_count = _SCHEMAS_PER_AGENT
        self.obj_count = _OBJS_PER_AGENT
        self.notifier = _testNotifier()
        self.broker_url = broker_url
        self.agent = Agent(name,
                           _notifier=self.notifier,
                           heartbeat_interval=heartbeat,
                           max_msg_size=_MAX_OBJS_PER_MSG)

        # Dynamically construct a management database
        for i in range(self.schema_count):
            _schema = SchemaObjectClass(_classId=SchemaClassId(
                "MyPackage", "MyClass-" + str(i)),
                                        _desc="A test data schema",
                                        _object_id_names=["index1", "index2"])
            # add properties
            _schema.add_property("index1", SchemaProperty(qmfTypes.TYPE_UINT8))
            _schema.add_property("index2", SchemaProperty(qmfTypes.TYPE_LSTR))

            # these two properties are statistics
            _schema.add_property("query_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))
            _schema.add_property("method_call_count",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # These two properties can be set via the method call
            _schema.add_property("set_string",
                                 SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_property("set_int",
                                 SchemaProperty(qmfTypes.TYPE_UINT32))

            # add method
            _meth = SchemaMethod(
                _desc="Method to set string and int in object.")
            _meth.add_argument("arg_int", SchemaProperty(qmfTypes.TYPE_UINT32))
            _meth.add_argument("arg_str", SchemaProperty(qmfTypes.TYPE_LSTR))
            _schema.add_method("set_meth", _meth)

            # Add schema to Agent

            self.agent.register_object_class(_schema)

            # instantiate managed data objects matching the schema

            for j in range(self.obj_count):

                self.agent.add_object(
                    QmfAgentData(self.agent,
                                 _schema=_schema,
                                 _values={
                                     "index1": j,
                                     "index2": "name-" + str(j),
                                     "set_string": "UNSET",
                                     "set_int": 0,
                                     "query_count": 0,
                                     "method_call_count": 0
                                 }))

        self.running = False
        self.ready = Event()