From d2839c7bfa96e014fba9d0bb6c7ac423d30e2c43 Mon Sep 17 00:00:00 2001 From: Ganesh Murthy Date: Mon, 15 Jan 2018 14:09:49 -0500 Subject: [PATCH] DISPATCH-907 - Added code to qdmanage to handle integer types --- tests/system_tests_qdmanage.py | 13 +++++++++++++ tools/qdmanage | 25 ++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py index d2ac3640d7..9c73db6e85 100644 --- a/tests/system_tests_qdmanage.py +++ b/tests/system_tests_qdmanage.py @@ -250,6 +250,13 @@ def test_check_address_name(self): self.assertEqual(output[1]['pattern'], "a/*/b/#/c") self.assertTrue('prefix' not in output[1]) + def test_create_address(self): + long_type = 'org.apache.qpid.dispatch.router.config.address' + create_command = 'CREATE --type=' + long_type + ' pattern="a.b.#" ingressPhase=5 egressPhase=6' + output = json.loads(self.run_qdmanage(create_command)) + self.assertEqual(output['egressPhase'], 6) + self.assertEqual(output['ingressPhase'], 5) + def test_check_link_route_name(self): long_type = 'org.apache.qpid.dispatch.router.config.linkRoute' query_command = 'QUERY --type=' + long_type @@ -272,6 +279,12 @@ def test_check_auto_link_name(self): self.assertEqual(output[0]['dir'], "out") self.assertEqual(output[0]['addr'], "mnop") + def test_create_auto_link_with_phase(self): + long_type = 'org.apache.qpid.dispatch.router.config.autoLink' + create_command = 'CREATE --type=' + long_type + ' addr=xyz containerId=id1 dir=out phase=2' + output = json.loads(self.run_qdmanage(create_command)) + self.assertEqual(output['phase'], 2) + def test_specify_container_id_connection_auto_link(self): long_type = 'org.apache.qpid.dispatch.router.config.autoLink' create_command = 'CREATE --type=' + long_type + ' addr=abc containerId=id1 connection=conn1 dir=out' diff --git a/tools/qdmanage b/tools/qdmanage index a534eb6944..33c1756ad0 100755 --- a/tools/qdmanage +++ b/tools/qdmanage @@ -26,18 +26,29 @@ from collections import Mapping, Sequence from optparse import OptionGroup from qpid_dispatch_internal.tools.command import OptionParser, Option, UsageError, connection_options, check_args, \ main, opts_ssl_domain, opts_url, opts_sasl +from qpid_dispatch_internal.management.qdrouter import QdSchema -def attr_split(attrstr): +INTEGER_TYPE = "integer" + +def attr_split(attrstr, qd_schema, type): """Split an attribute string of the form name=value or name to indicate None""" nv = attrstr.split("=", 1) - if len(nv) == 1: return [nv[0], None] + if len(nv) == 1: + return [nv[0], None] else: - if nv[1] == "true": nv[1] = True - if nv[1] == "false": nv[1] = False + if nv[1] == "true": + nv[1] = True + elif nv[1] == "false": + nv[1] = False + elif type and qd_schema.entity_type(type) and qd_schema.entity_type(type).attribute(nv[0]).type == INTEGER_TYPE: + nv[1] = int(nv[1]) + return nv + class QdManage(): def __init__(self): + self.qd_schema = QdSchema() self.prefix = 'org.apache.qpid.dispatch.' self.operations = ['QUERY', 'CREATE', 'READ', 'UPDATE', 'DELETE', 'GET-TYPES', 'GET-OPERATIONS', 'GET-ATTRIBUTES', 'GET-ANNOTATIONS', @@ -149,7 +160,7 @@ class QdManage(): def create(self): """create [ATTR=VALUE...] Create a new entity.""" if self.args: - self.opts.attributes = dict(attr_split(arg) for arg in self.args) + self.opts.attributes = dict(attr_split(arg, self.qd_schema, self.opts.type) for arg in self.args) self.call_bulk(lambda attrs: self.call_node('create', 'type', 'name', attributes=attrs)) def read(self): @@ -160,7 +171,7 @@ class QdManage(): def update(self): """update [ATTR=VALUE...] Update an entity.""" if self.args: - self.opts.attributes = dict(attr_split(arg) for arg in self.args) + self.opts.attributes = dict(attr_split(arg, self.qd_schema, self.opts.type) for arg in self.args) self.call_bulk( lambda attrs: self.call_node('update', 'type', 'name', 'identity', attributes=attrs)) @@ -204,7 +215,7 @@ class QdManage(): def operation(self, operation): """operation [ATTR=VALUE...] Call custom operation with ATTR=VALUE as request properties. Use --body and --properties if specified.""" - properties = dict(attr_split(arg) for arg in self.args or []) + properties = dict(attr_split(arg, self.qd_schema, self.opts.type) for arg in self.args or []) if self.opts.properties: properties.update(self.json_arg(self.opts.properties)) body = None