def test_all_objects(self): # create console # find agents # synchronous query for all objects by schema_id 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: agent = self.console.find_agent(agent_app.agent.get_name(), timeout=3) self.assertTrue(agent and agent.get_name() == agent_app.agent.get_name()) # get a list of all schema_ids query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == _SCHEMAS_PER_AGENT) for sid in sid_list: query = QmfQuery.create_wildcard_object(sid) obj_list = self.console.do_query(agent, query) self.assertTrue(obj_list and len(obj_list) == _OBJS_PER_AGENT) for obj in obj_list: self.assertTrue(isinstance(obj, qmf2.console.QmfConsoleData)) self.console.destroy(10)
def test_all_objects(self): # create console # find agents # synchronous query for all objects by schema_id 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: agent = self.console.find_agent(agent_app.agent.get_name(), timeout=3) self.assertTrue(agent and agent.get_name() == agent_app.agent.get_name()) # get a list of all schema_ids query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == _SCHEMAS_PER_AGENT) for sid in sid_list: query = QmfQuery.create_wildcard_object(sid) obj_list = self.console.do_query(agent, query) self.assertTrue(obj_list and len(obj_list) == _OBJS_PER_AGENT) for obj in obj_list: self.assertTrue( isinstance(obj, qmf2.console.QmfConsoleData)) self.console.destroy(10)
def test_described_obj(self): # create console # find agents # synchronous query for all objects in schema # method call on each object 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) i_count = 0 for aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT, _target_params=t_params) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: cookie = "cookie-" + str(i_count) i_count += 1 mr = obj.invoke_method( "set_meth", {"arg_int": -99, "arg_str": "Now set!", "cookie": cookie}, _reply_handle=cookie, _timeout=3) self.assertTrue(mr) # done, now wait for async responses r_count = 0 while self.notifier.wait_for_work(3): wi = self.console.get_next_workitem(timeout=0) while wi is not None: r_count += 1 self.assertTrue(wi.get_type() == WorkItem.METHOD_RESPONSE) reply = wi.get_params() self.assertTrue(isinstance(reply, qmf2.console.MethodResult)) self.assertTrue(reply.succeeded()) self.assertTrue(reply.get_argument("cookie") == wi.get_handle()) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(r_count == i_count) self.console.destroy(10)
def test_predicate_match_integer(self): # create console # find agents # synchronous query for all objects with a value named # "index1" which is < or equal to various values 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) # Query the unmanaged (no schema) objects # == 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.EQ, "index1", 50]]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) self.assertTrue(obj_list[0].has_value("index1")) self.assertTrue(obj_list[0].get_value("index1") == 50) # <= 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.LE, "index1", 50]]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 3) for obj in obj_list: self.assertTrue(obj.has_value("index1")) self.assertTrue(obj.get_value("index1") <= 50) # > 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.GT, "index1", 50]]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) for obj in obj_list: self.assertTrue(obj.has_value("index1")) self.assertTrue(obj.get_value("index1") > 50) self.console.destroy(10)
def test_predicate_match_integer(self): # create console # find agents # synchronous query for all objects with a value named # "index1" which is < or equal to various values 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) # Query the unmanaged (no schema) objects # == 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [ QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.EQ, "index1", 50] ]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) self.assertTrue(obj_list[0].has_value("index1")) self.assertTrue(obj_list[0].get_value("index1") == 50) # <= 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [ QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.LE, "index1", 50] ]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 3) for obj in obj_list: self.assertTrue(obj.has_value("index1")) self.assertTrue(obj.get_value("index1") <= 50) # > 50 query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [ QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "index1"]], [QmfQuery.GT, "index1", 50] ]) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) for obj in obj_list: self.assertTrue(obj.has_value("index1")) self.assertTrue(obj.get_value("index1") > 50) self.console.destroy(10)
def test_all_oids(self): # create console # find agents # synchronous query for all schemas # synchronous query for all objects per schema # 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 aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) # first, find objects per schema query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT_ID, _target_params=t_params) oid_list = self.console.do_query(agent, query) self.assertTrue(isinstance(oid_list, type([])), "Unexpected return type") self.assertTrue(len(oid_list) == 3, "Wrong count") self.assertTrue('100a name' in oid_list) self.assertTrue('99another name' in oid_list) self.assertTrue('50my name' in oid_list) self.assertTrue('01545' not in oid_list) # now, find all unmanaged objects (no schema) query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT_ID) oid_list = self.console.do_query(agent, query) self.assertTrue(isinstance(oid_list, type([])), "Unexpected return type") self.assertTrue(len(oid_list) == 4, "Wrong count") self.assertTrue('100a name' not in oid_list) self.assertTrue('99another name' not in oid_list) self.assertTrue('01545' in oid_list) self.assertTrue('01544' in oid_list) self.assertTrue('01543' in oid_list) self.assertTrue('01546' in oid_list) self.console.destroy(10)
def test_direct_oids(self): # create console # find agents # synchronous query for each objects # verify objects and schemas are correct 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) # first, find objects per schema query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for oid in ['100a name', '99another name']: query = QmfQuery.create_id_object(oid, sid_list[0]) obj_list = self.console.do_query(agent, query) self.assertTrue(isinstance(obj_list, type([])), "Unexpected return type") self.assertTrue(len(obj_list) == 1) obj = obj_list[0] self.assertTrue(isinstance(obj, QmfData)) self.assertTrue(obj.get_object_id() == oid) self.assertTrue(obj.get_schema_class_id() == sid_list[0]) schema_id = obj.get_schema_class_id() self.assertTrue(isinstance(schema_id, SchemaClassId)) self.assertTrue(obj.is_described()) # now find schema-less objects for oid in ['01545']: query = QmfQuery.create_id_object(oid) obj_list = self.console.do_query(agent, query) self.assertTrue(isinstance(obj_list, type([])), "Unexpected return type") self.assertTrue(len(obj_list) == 1) obj = obj_list[0] self.assertTrue(isinstance(obj, QmfData)) self.assertTrue(obj.get_object_id() == oid) self.assertFalse(obj.is_described()) self.console.destroy(10)
def test_bad_method_no_schema(self): # create console # find agents # synchronous query for all objects with no schema # invalid method call on each object # - should throw a ValueError 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) for obj in obj_list: self.assertTrue(obj.get_schema_class_id() == None) mr = obj.invoke_method("unknown_meth", { "arg1": -99, "arg2": "Now set!" }, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertFalse(mr.succeeded()) self.assertTrue(isinstance(mr.get_exception(), QmfData)) self.console.destroy(10)
def test_managed_obj(self): # create console # find agents # synchronous query for a managed object # method call on each object 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) query = QmfQuery.create_id(QmfQuery.TARGET_OBJECT, "01545") obj_list = self.console.do_query(agent, query) self.assertTrue(isinstance(obj_list, type([]))) self.assertTrue(len(obj_list) == 1) obj = obj_list[0] mr = obj.invoke_method("a_method", { "arg1": 1, "arg2": "Now set!", "arg3": 1966 }, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertTrue(mr.succeeded()) self.assertTrue(mr.get_argument("code") == 0) # @todo refresh and verify changes self.console.destroy(10)
def test_predicate_schema_id(self): # create console # find agents # synchronous query for all schema by package name 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) query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA, [QmfQuery.EQ, SchemaClassId.KEY_PACKAGE, [QmfQuery.QUOTE, "MyPackage"]]) schema_list = self.console.do_query(agent, query) self.assertTrue(len(schema_list)) for schema in schema_list: self.assertTrue(schema.get_class_id().get_package_name() == "MyPackage") self.console.destroy(10)
def test_all_schema(self): # create console # find agents # synchronous query for all schemas 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: agent = self.console.find_agent(agent_app.agent.get_name(), timeout=3) self.assertTrue(agent and agent.get_name() == agent_app.agent.get_name()) # get a list of all schema_ids query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA) schema_list = self.console.do_query(agent, query) self.assertTrue(schema_list and len(schema_list) == _SCHEMAS_PER_AGENT) for schema in schema_list: self.assertTrue(isinstance(schema, SchemaObjectClass)) self.console.destroy(10)
def test_managed_obj(self): # create console # find agents # synchronous query for a managed object # method call on each object 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) query = QmfQuery.create_id(QmfQuery.TARGET_OBJECT, "01545") obj_list = self.console.do_query(agent, query) self.assertTrue(isinstance(obj_list, type([]))) self.assertTrue(len(obj_list) == 1) obj = obj_list[0] mr = obj.invoke_method("a_method", {"arg1": 1, "arg2": "Now set!", "arg3": 1966}, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertTrue(mr.succeeded()) self.assertTrue(mr.get_argument("code") == 0) # @todo refresh and verify changes self.console.destroy(10)
def test_all_schema_id(self): # create console # find agents # synchronous query for all schemas_ids 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: agent = self.console.find_agent(agent_app.agent.get_name(), timeout=3) self.assertTrue(agent and agent.get_name() == agent_app.agent.get_name()) # get a list of all schema_ids query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == _SCHEMAS_PER_AGENT) for sid in sid_list: self.assertTrue(isinstance(sid, SchemaClassId)) self.assertTrue(sid.get_package_name() == "MyPackage") self.assertTrue( sid.get_class_name().split('-')[0] == "MyClass") self.console.destroy(10)
def test_all_schema_id(self): # create console # find agents # synchronous query for all schemas_ids 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: agent = self.console.find_agent(agent_app.agent.get_name(), timeout=3) self.assertTrue(agent and agent.get_name() == agent_app.agent.get_name()) # get a list of all schema_ids query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == _SCHEMAS_PER_AGENT) for sid in sid_list: self.assertTrue(isinstance(sid, SchemaClassId)) self.assertTrue(sid.get_package_name() == "MyPackage") self.assertTrue(sid.get_class_name().split('-')[0] == "MyClass") self.console.destroy(10)
def test_bad_method_no_schema(self): # create console # find agents # synchronous query for all objects with no schema # invalid method call on each object # - should throw a ValueError 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 1) for obj in obj_list: self.assertTrue(obj.get_schema_class_id() == None) mr = obj.invoke_method("unknown_meth", {"arg1": -99, "arg2": "Now set!"}, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertFalse(mr.succeeded()) self.assertTrue(isinstance(mr.get_exception(), QmfData)) self.console.destroy(10)
def test_predicate_schema_id(self): # create console # find agents # synchronous query for all schema by package name 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) query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA, [ QmfQuery.EQ, SchemaClassId.KEY_PACKAGE, [QmfQuery.QUOTE, "MyPackage"] ]) schema_list = self.console.do_query(agent, query) self.assertTrue(len(schema_list)) for schema in schema_list: self.assertTrue( schema.get_class_id().get_package_name() == "MyPackage") self.console.destroy(10)
def test_described_obj(self): # create console # find agents # synchronous query for all objects in schema # method call on each object 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT, _target_params=t_params) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: mr = obj.invoke_method("set_meth", { "arg_int": -99, "arg_str": "Now set!" }, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertTrue(mr.succeeded()) self.assertTrue(mr.get_argument("code") == 0) self.assertTrue(obj.get_value("method_call_count") == 0) self.assertTrue(obj.get_value("set_string") == "UNSET") self.assertTrue(obj.get_value("set_int") == 0) obj.refresh() self.assertTrue(obj.get_value("method_call_count") == 1) self.assertTrue(obj.get_value("set_string") == "Now set!") self.assertTrue(obj.get_value("set_int") == -99) self.console.destroy(10)
def test_bad_method_schema(self): # create console # find agents # synchronous query for all objects with schema # invalid method call on each object # - should throw a ValueError - NOT YET. 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.TRUE], _target_params=t_params) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: mr = obj.invoke_method("unknown_method", { "arg1": -99, "arg2": "Now set!" }, _timeout=3) # self.failUnlessRaises(ValueError, # obj.invoke_method, # "unknown_meth", # {"arg1": -99, "arg2": "Now set!"}, # _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertFalse(mr.succeeded()) self.assertTrue(isinstance(mr.get_exception(), QmfData)) self.console.destroy(10)
def test_predicate_match_string(self): # create console # find agents # synchronous query for all objects with a value named # set_string which is < or equal to "UNSET" 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) # get the schema id for MyPackage:MyClass schema query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA_ID, [ QmfQuery.AND, [ QmfQuery.EQ, SchemaClassId.KEY_PACKAGE, [QmfQuery.QUOTE, "MyPackage"] ], [ QmfQuery.EQ, SchemaClassId.KEY_CLASS, [QmfQuery.QUOTE, "MyClass"] ] ]) sid_list = self.console.do_query(agent, query) self.assertTrue(len(sid_list) == 1) query = QmfQuery.create_predicate( QmfQuery.TARGET_OBJECT, [ QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "set_string"]], [QmfQuery.EQ, "set_string", [QmfQuery.QUOTE, "UNSET"]] ], _target_params={QmfData.KEY_SCHEMA_ID: sid_list[0]}) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: self.assertTrue(obj.has_value("set_string")) self.assertTrue(obj.get_value("set_string") == "UNSET") self.console.destroy(10)
def test_query_expiration(self): # create console # find agents # kill the agents # send async query # wait for & verify expiration self.notifier = _testNotifier() self.console = qmf2.console.Console(notifier=self.notifier, agent_timeout=30) self.conn = qpid.messaging.Connection(self.broker) self.conn.open() self.console.add_connection(self.conn) # find the agents agents = [] for aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) agents.append(agent) # now nuke the agents from orbit. It's the only way to be sure. self.agent1.stop_app() self.agent1 = None self.agent2.stop_app() self.agent2 = None # now send queries to agents that no longer exist for agent in agents: query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA) rc = self.console.do_query(agent, query, _reply_handle=agent.get_name(), _timeout=2) self.assertTrue(rc) # done. Now wait for async responses due to timeouts 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) == 0) # empty self.console.release_workitem(wi) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(count == 2) self.console.destroy(10)
def test_all_schemas(self): # create console # find agents # asynchronous query for all schemas 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) # test internal state using non-api calls: # no schemas present yet self.assertTrue(len(self.console._schema_cache) == 0) # end test for aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) # send queries query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA) 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) == 1) self.assertTrue( isinstance(reply[0], qmf2.common.SchemaObjectClass)) self.assertTrue( reply[0].get_class_id().get_package_name() == "MyPackage") self.assertTrue( reply[0].get_class_id().get_class_name() == "MyClass") self.console.release_workitem(wi) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(count == 2) # test internal state using non-api calls: # schema has been learned self.assertTrue(len(self.console._schema_cache) == 1) # end test self.console.destroy(10)
def test_described_obj(self): # create console # find agents # synchronous query for all objects in schema # method call on each object 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT, _target_params=t_params) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: mr = obj.invoke_method("set_meth", {"arg_int": -99, "arg_str": "Now set!"}, _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertTrue(mr.succeeded()) self.assertTrue(mr.get_argument("code") == 0) self.assertTrue(obj.get_value("method_call_count") == 0) self.assertTrue(obj.get_value("set_string") == "UNSET") self.assertTrue(obj.get_value("set_int") == 0) obj.refresh() self.assertTrue(obj.get_value("method_call_count") == 1) self.assertTrue(obj.get_value("set_string") == "Now set!") self.assertTrue(obj.get_value("set_int") == -99) self.console.destroy(10)
def test_managed_obj(self): # create console # find agents # synchronous query for a managed object # method call on each object 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) i_count = 0 for aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) query = QmfQuery.create_id(QmfQuery.TARGET_OBJECT, "01545") obj_list = self.console.do_query(agent, query) self.assertTrue(isinstance(obj_list, type([]))) self.assertTrue(len(obj_list) == 1) obj = obj_list[0] cookie = "cookie-" + str(i_count) i_count += 1 mr = obj.invoke_method("a_method", {"arg1": 1, "arg2": "Now set!", "arg3": 1966, "cookie": cookie}, _reply_handle=cookie, _timeout=3) self.assertTrue(mr) # done, now wait for async responses r_count = 0 while self.notifier.wait_for_work(3): wi = self.console.get_next_workitem(timeout=0) while wi is not None: r_count += 1 self.assertTrue(wi.get_type() == WorkItem.METHOD_RESPONSE) reply = wi.get_params() self.assertTrue(isinstance(reply, qmf2.console.MethodResult)) self.assertTrue(reply.succeeded()) self.assertTrue(reply.get_argument("cookie") == wi.get_handle()) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(r_count == i_count) self.console.destroy(10)
def test_bad_method_schema(self): # create console # find agents # synchronous query for all objects with schema # invalid method call on each object # - should throw a ValueError - NOT YET. 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA_ID) sid_list = self.console.do_query(agent, query) self.assertTrue(sid_list and len(sid_list) == 1) for sid in sid_list: t_params = {QmfData.KEY_SCHEMA_ID: sid} query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.TRUE], _target_params=t_params) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: mr = obj.invoke_method("unknown_method", {"arg1": -99, "arg2": "Now set!"}, _timeout=3) # self.failUnlessRaises(ValueError, # obj.invoke_method, # "unknown_meth", # {"arg1": -99, "arg2": "Now set!"}, # _timeout=3) self.assertTrue(isinstance(mr, qmf2.console.MethodResult)) self.assertFalse(mr.succeeded()) self.assertTrue(isinstance(mr.get_exception(), QmfData)) self.console.destroy(10)
def test_all_schemas(self): # create console # find agents # asynchronous query for all schemas 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) # test internal state using non-api calls: # no schemas present yet self.assertTrue(len(self.console._schema_cache) == 0) # end test for aname in ["agent1", "agent2"]: agent = self.console.find_agent(aname, timeout=3) self.assertTrue(agent and agent.get_name() == aname) # send queries query = QmfQuery.create_wildcard(QmfQuery.TARGET_SCHEMA) 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) == 1) self.assertTrue(isinstance(reply[0], qmf2.common.SchemaObjectClass)) self.assertTrue(reply[0].get_class_id().get_package_name() == "MyPackage") self.assertTrue(reply[0].get_class_id().get_class_name() == "MyClass") self.console.release_workitem(wi) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(count == 2) # test internal state using non-api calls: # schema has been learned self.assertTrue(len(self.console._schema_cache) == 1) # end test self.console.destroy(10)
def test_predicate_match_string(self): # create console # find agents # synchronous query for all objects with a value named # set_string which is < or equal to "UNSET" 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) # get the schema id for MyPackage:MyClass schema query = QmfQuery.create_predicate(QmfQuery.TARGET_SCHEMA_ID, [QmfQuery.AND, [QmfQuery.EQ, SchemaClassId.KEY_PACKAGE, [QmfQuery.QUOTE, "MyPackage"]], [QmfQuery.EQ, SchemaClassId.KEY_CLASS, [QmfQuery.QUOTE, "MyClass"]]]) sid_list = self.console.do_query(agent, query) self.assertTrue(len(sid_list) == 1) query = QmfQuery.create_predicate(QmfQuery.TARGET_OBJECT, [QmfQuery.AND, [QmfQuery.EXISTS, [QmfQuery.QUOTE, "set_string"]], [QmfQuery.EQ, "set_string", [QmfQuery.QUOTE, "UNSET"]]], _target_params={QmfData.KEY_SCHEMA_ID: sid_list[0]}) obj_list = self.console.do_query(agent, query) self.assertTrue(len(obj_list) == 2) for obj in obj_list: self.assertTrue(obj.has_value("set_string")) self.assertTrue(obj.get_value("set_string") == "UNSET") self.console.destroy(10)
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)
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)
def test_packages(self): # create console # find agents # synchronous query all package names 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) query = QmfQuery.create_wildcard(QmfQuery.TARGET_PACKAGES) package_list = self.console.do_query(agent, query) self.assertTrue(len(package_list) == 1) self.assertTrue('MyPackage' in package_list) self.console.destroy(10)
def test_undescribed_objs(self): # create console # find agents # asynchronous query for all non-schema 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) # send queries query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT) 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) == 4) self.assertTrue( isinstance(reply[0], qmf2.console.QmfConsoleData)) self.assertFalse(reply[0].is_described()) # no schema self.console.release_workitem(wi) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(count == 2) self.console.destroy(10)
def test_undescribed_objs(self): # create console # find agents # asynchronous query for all non-schema 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) # send queries query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT) 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) == 4) self.assertTrue(isinstance(reply[0], qmf2.console.QmfConsoleData)) self.assertFalse(reply[0].is_described()) # no schema self.console.release_workitem(wi) wi = self.console.get_next_workitem(timeout=0) self.assertTrue(count == 2) self.console.destroy(10)
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)
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)
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)
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)
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)
print("Starting Connection") _c = Connection("localhost") _c.connect() print("Starting Console") _notifier = ExampleNotifier() _myConsole = Console(notifier=_notifier) _myConsole.addConnection(_c) # Allow discovery only for the agent named "qmf.testAgent" # @todo: replace "manual" query construction with # a formal class-based Query API _query = QmfQuery.create_predicate( QmfQuery.TARGET_AGENT, QmfQueryPredicate( {QmfQuery.CMP_EQ: [QmfQuery.KEY_AGENT_NAME, "qmf.testAgent"]})) _myConsole.enable_agent_discovery(_query) _done = False while not _done: # try: _notifier.waitForWork() _wi = _myConsole.get_next_workitem(timeout=0) while _wi: print("!!! work item received %d:%s" % (_wi.get_type(), str(_wi.get_params()))) if _wi.get_type() == _wi.AGENT_ADDED: _agent = _wi.get_params().get("agent")
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)
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)