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_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_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_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_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_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_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)
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")