This is an automated email from the ASF dual-hosted git repository. jdanek pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit bdd4fd4c0712815348c8e3619ec8cdd03ece1072 Author: Kenneth Giusti <kgiu...@redhat.com> AuthorDate: Thu Mar 10 21:33:43 2022 +0100 Fixes #155: avoid unnecessary Tester() instance in QdManager --- tests/system_test.py | 41 +++++++++++++++++----------------- tests/system_tests_autolinks.py | 18 +++++++-------- tests/system_tests_core_client.py | 2 +- tests/system_tests_edge_router.py | 12 +++++----- tests/system_tests_http.py | 4 ++-- tests/system_tests_link_routes.py | 14 ++++++------ tests/system_tests_log_level_update.py | 14 ++++++------ tests/system_tests_one_router.py | 14 ++++++------ tests/system_tests_open_properties.py | 8 +++---- tests/system_tests_qdmanage.py | 2 +- tests/system_tests_sasl_plain.py | 6 ++--- 11 files changed, 67 insertions(+), 68 deletions(-) diff --git a/tests/system_test.py b/tests/system_test.py index f3968b56..bb01b090 100755 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -1177,38 +1177,37 @@ class QdManager: A means to invoke qdmanage during a testcase """ - def __init__(self, tester=None, address=None, timeout=TIMEOUT, - router_id=None, - edge_router_id=None): + def __init__(self, address: Optional[str] = None, + timeout: Optional[float] = TIMEOUT, + router_id: Optional[str] = None, + edge_router_id: Optional[str] = None) -> None: # 'tester' - can be 'self' when called in a test, # or an instance any class derived from Process (like Qdrouterd) - self._tester = tester or Tester(None) self._timeout = timeout self._address = address self.router_id = router_id self.edge_router_id = edge_router_id - self.router = [] + self.router: List[str] = [] if self.router_id: self.router = self.router + ['--router', self.router_id] elif self.edge_router_id: self.router = self.router + ['--edge-router', self.edge_router_id] - def __call__(self, cmd, address=None, input=None, expect=Process.EXIT_OK, - timeout=None): - assert address or self._address, "address missing" - p = self._tester.popen( - ['qdmanage'] + cmd.split(' ') - + self.router + ['--bus', address or self._address, - '--indent=-1', - '--timeout', str(timeout or self._timeout)], - stdin=PIPE, stdout=PIPE, stderr=STDOUT, expect=expect, - universal_newlines=True) - out = p.communicate(input)[0] - try: - p.teardown() - except Exception as e: - raise Exception("%s\n%s" % (e, out)) - return out + def __call__(self, cmd: str, + address: Optional[str] = None, + input: Optional[str] = None, + timeout: Optional[float] = None) -> str: + addr = address or self._address + assert addr, "address missing" + with subprocess.Popen(['qdmanage'] + cmd.split(' ') + self.router + + ['--bus', addr, '--indent=-1', '--timeout', + str(timeout or self._timeout)], stdin=PIPE, + stdout=PIPE, stderr=STDOUT, + universal_newlines=True) as p: + rc = p.communicate(input) + if p.returncode != 0: + raise Exception("%s %s" % rc) + return rc[0] def create(self, long_type, kwargs): cmd = "CREATE --type=%s" % long_type diff --git a/tests/system_tests_autolinks.py b/tests/system_tests_autolinks.py index 33679e44..e3a2e8a8 100644 --- a/tests/system_tests_autolinks.py +++ b/tests/system_tests_autolinks.py @@ -124,7 +124,7 @@ class NameCollisionTest(TestCase): al_long_type = 'org.apache.qpid.dispatch.router.config.autoLink' addr_long_type = 'org.apache.qpid.dispatch.router.config.address' lr_long_type = 'org.apache.qpid.dispatch.router.config.linkRoute' - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: mgmt.create(al_long_type, args) @@ -137,7 +137,7 @@ class NameCollisionTest(TestCase): args = {"name": "linkRoute", "prefix": "linkRoute", "connection": "broker", "dir": "in"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: mgmt.create(lr_long_type, args) @@ -148,7 +148,7 @@ class NameCollisionTest(TestCase): args = {"name": "address", "prefix": "address.1", "waypoint": "yes"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: mgmt.create(addr_long_type, args) @@ -166,41 +166,41 @@ class NameCollisionTest(TestCase): # sure that is ok args = {"name": "autoLink", "prefix": "linkRoute", "connection": "broker", "dir": "in"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(lr_long_type, args) # insert a linkRoute with the name of an existing addr config and make # sure that is ok args = {"name": "address", "prefix": "linkRoute", "connection": "broker", "dir": "in"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(lr_long_type, args) # insert an autoLink with the name of an existing linkRoute and make # sure that is ok args = {"name": "linkRoute", "address": "autoLink1", "connection": "broker", "dir": "in"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(al_long_type, args) # insert an autoLink with the name of an existing address and make # sure that is ok args = {"name": "address", "address": "autoLink1", "connection": "broker", "dir": "in"} al_long_type = 'org.apache.qpid.dispatch.router.config.autoLink' - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(al_long_type, args) # insert an address with the name of an existing autoLink and make # sure that is ok args = {"name": "autoLink", "prefix": "address.2", "waypoint": "yes"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(addr_long_type, args) # insert an autoLink with the name of an existing linkRoute and make # sure that is ok args = {"name": "linkRoute", "prefix": "address.3", "waypoint": "yes"} - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) mgmt.create(addr_long_type, args) diff --git a/tests/system_tests_core_client.py b/tests/system_tests_core_client.py index 8e0bf36a..b2edf260 100644 --- a/tests/system_tests_core_client.py +++ b/tests/system_tests_core_client.py @@ -78,7 +78,7 @@ class CoreClientAPITest(TestCase): self.assertTrue(ts.accepted) def test_call_timeout(self): - qm = QdManager(self, self.router.addresses[0]) + qm = QdManager(self.router.addresses[0]) ts = TestCallTimeout(self.router.addresses[0], qm) ts.run() self.assertEqual("TIMED OUT!", ts.error) diff --git a/tests/system_tests_edge_router.py b/tests/system_tests_edge_router.py index 97f1f5eb..213dafc7 100644 --- a/tests/system_tests_edge_router.py +++ b/tests/system_tests_edge_router.py @@ -1394,7 +1394,7 @@ class RouterTest(TestCase): def test_71_qdmanage_edge_router_option(self): # Makes a connection to an interior router INT.A and runs qdstat # asking for all connections of an edge router EA1 - mgmt = QdManager(self, address=self.routers[0].addresses[0], + mgmt = QdManager(address=self.routers[0].addresses[0], edge_router_id='EA1') conn_found = False outs = mgmt.query('org.apache.qpid.dispatch.connection') @@ -1406,7 +1406,7 @@ class RouterTest(TestCase): # Makes a connection to an edge router and runs qdstat # asking for all connections of an edge router EA1 - mgmt = QdManager(self, address=self.routers[2].addresses[0], + mgmt = QdManager(address=self.routers[2].addresses[0], edge_router_id='EA1') conn_found = False outs = mgmt.query('org.apache.qpid.dispatch.connection') @@ -1421,7 +1421,7 @@ class RouterTest(TestCase): # asking for all connections of an edge router EA1. The interior # router INT.B is connected to edge router EA1 indirectly via # interior router INT.A - mgmt = QdManager(self, address=self.routers[1].addresses[0], + mgmt = QdManager(address=self.routers[1].addresses[0], edge_router_id='EA1') conn_found = False outs = mgmt.query('org.apache.qpid.dispatch.connection') @@ -1483,7 +1483,7 @@ class RouterTest(TestCase): # EA1 and EA2 and is also connected to another interior router INT.B # We will connect to edge router EA1 (which has an edge # uplink to INT.A) and query for connections on INT.A - mgmt = QdManager(self, address=self.routers[2].addresses[0], + mgmt = QdManager(address=self.routers[2].addresses[0], router_id='INT.A') outs = mgmt.query('org.apache.qpid.dispatch.connection') ea1_conn_found = False @@ -1503,7 +1503,7 @@ class RouterTest(TestCase): # EA1 via INT.A # We will connect to edge router EA1 (which has an edge # uplink to INT.A) and query for connections on INT.B - mgmt = QdManager(self, address=self.routers[2].addresses[0], + mgmt = QdManager(address=self.routers[2].addresses[0], router_id='INT.B') outs = mgmt.query('org.apache.qpid.dispatch.connection') eb1_conn_found = False @@ -1741,7 +1741,7 @@ class LinkRouteProxyTest(TestCase): """ query existing links and verify they are set up as expected """ - mgmt = QdManager(self, address=router) + mgmt = QdManager(address=router) # fetch all the connections cl = mgmt.query('org.apache.qpid.dispatch.connection') # map them by their identity diff --git a/tests/system_tests_http.py b/tests/system_tests_http.py index 4d03ee26..130d948d 100644 --- a/tests/system_tests_http.py +++ b/tests/system_tests_http.py @@ -139,7 +139,7 @@ class RouterTestHttp(TestCase): # Delete the listener on port http_delete_listen_port_1 long_type = 'org.apache.qpid.dispatch.listener' - mgmt = QdManager(self, address=address()) + mgmt = QdManager(address=address()) if self.skip_delete_http_listener_test: # You are not allowed to delete a http:yes listener @@ -339,7 +339,7 @@ class RouterTestHttp(TestCase): if not self.skip_delete_http_listener_test: # Delete the listener with name 'delete-me' long_type = 'org.apache.qpid.dispatch.listener' - mgmt = QdManager(self, address=address()) + mgmt = QdManager(address=address()) mgmt.delete(long_type, name=name) # Make sure that the listener got deleted. diff --git a/tests/system_tests_link_routes.py b/tests/system_tests_link_routes.py index eb8c884b..59f68e24 100644 --- a/tests/system_tests_link_routes.py +++ b/tests/system_tests_link_routes.py @@ -2233,8 +2233,8 @@ class ConnectionLinkRouteTest(TestCase): fs.delete_config() # eventually the addresses will be un-published - mgmt_A = QdManager(self, address=self.QDR_A.addresses[0]) - mgmt_B = QdManager(self, address=self.QDR_B.addresses[0]) + mgmt_A = QdManager(address=self.QDR_A.addresses[0]) + mgmt_B = QdManager(address=self.QDR_B.addresses[0]) deadline = time() + TIMEOUT while (self._get_address(mgmt_A, "flea.*") or self._get_address(mgmt_B, "flea.*")): @@ -2246,8 +2246,8 @@ class ConnectionLinkRouteTest(TestCase): # simple forwarding tests with auto delete def test_send_receive(self): COUNT = 5 - mgmt_A = QdManager(self, address=self.QDR_A.addresses[0]) - mgmt_B = QdManager(self, address=self.QDR_B.addresses[0]) + mgmt_A = QdManager(address=self.QDR_A.addresses[0]) + mgmt_B = QdManager(address=self.QDR_B.addresses[0]) # connect broker to A route-container fs = ConnLinkRouteService(self.QDR_A.addresses[1], container_id="FakeService", @@ -2302,8 +2302,8 @@ class ConnectionLinkRouteTest(TestCase): # are removed so the link route addresses must be gone fs.join() - mgmt_A = QdManager(self, address=self.QDR_A.addresses[0]) - mgmt_B = QdManager(self, address=self.QDR_B.addresses[0]) + mgmt_A = QdManager(address=self.QDR_A.addresses[0]) + mgmt_B = QdManager(address=self.QDR_B.addresses[0]) deadline = time() + TIMEOUT while (self._get_address(mgmt_A, "flea.*") or self._get_address(mgmt_B, "flea.*")): @@ -2580,7 +2580,7 @@ class Dispatch1428(TestCase): # Now that the qdmanage has run, query the link routes and make sure that their "operStatus" is "active" before # running any of the tests. long_type = 'org.apache.qpid.dispatch.router.config.linkRoute' - qd_manager = QdManager(self, address=self.routers[1].addresses[0]) + qd_manager = QdManager(address=self.routers[1].addresses[0]) for i in range(5): all_link_routes_activated = True diff --git a/tests/system_tests_log_level_update.py b/tests/system_tests_log_level_update.py index e291d019..42a46903 100644 --- a/tests/system_tests_log_level_update.py +++ b/tests/system_tests_log_level_update.py @@ -156,7 +156,7 @@ class LogModuleProtocolTest(TestCase): def test_turn_on_protocol_trace(self): hello_world_0 = "Hello World_0!" - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) blocking_connection = BlockingConnection(self.address) TEST_ADDR = "moduletest0" @@ -267,7 +267,7 @@ class EnableConnectionLevelInterRouterTraceTest(TestCase): return num_transfers def test_inter_router_protocol_trace(self): - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) # The router already has trace logging turned on for all connections. # Get the connection id of the inter-router connection @@ -332,7 +332,7 @@ class EnableConnectionLevelProtocolTraceTest(TestCase): cls.address = cls.router.addresses[0] def test_enable_protocol_trace_on_non_existent_connection(self): - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) bad_request = False @@ -346,7 +346,7 @@ class EnableConnectionLevelProtocolTraceTest(TestCase): self.assertTrue(bad_request) def test_single_connection_protocol_trace(self): - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) # Turn off trace logging on all connections. qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, @@ -452,7 +452,7 @@ class LogLevelUpdateTest(TestCase): hello_world_2 = "Hello World_2!" hello_world_3 = "Hello World_3!" hello_world_4 = "Hello World_4!" - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) blocking_connection = BlockingConnection(self.address) TEST_ADDR = "apachetest1" @@ -532,7 +532,7 @@ class LogLevelUpdateTest(TestCase): # Step 1. Turn off trace logging for module DEFAULT and enable trace logging # for the PROTOCOL module and make sure it works. - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) # Set log level to info+ on the DEFAULT module qd_manager.update("org.apache.qpid.dispatch.log", {"enable": "info+"}, name="log/DEFAULT") # Set log level to trace+ on the PROTOCOL module @@ -615,7 +615,7 @@ class RouterCoreModuleLogTest(TestCase): blocking_sender.send(msg) received_message = blocking_receiver.receive() self.assertEqual(TEST_MSG_BODY, received_message.body) - qd_manager = QdManager(self, self.address) + qd_manager = QdManager(self.address) logs = qd_manager.get_log() router_core_found = False diff --git a/tests/system_tests_one_router.py b/tests/system_tests_one_router.py index 299e1eda..25ec109b 100644 --- a/tests/system_tests_one_router.py +++ b/tests/system_tests_one_router.py @@ -58,7 +58,7 @@ class StandaloneRouterQdManageTest(TestCase): but never an inter-router connector. Inter router connectors are allowed only with interior routers. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.connector", @@ -77,7 +77,7 @@ class StandaloneRouterQdManageTest(TestCase): Since this is a standalone router, other routers (interior or edge routers) cannot connect to this router. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.listener", @@ -97,7 +97,7 @@ class StandaloneRouterQdManageTest(TestCase): Since this is a standalone router, other routers (interior or edge routers) cannot connect to this router. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.listener", @@ -130,7 +130,7 @@ class EdgeRouterQdManageTest(TestCase): but never an inter-router connector. Inter router connectors are allowed only with interior routers. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.connector", @@ -149,7 +149,7 @@ class EdgeRouterQdManageTest(TestCase): an edge router can connect to another edge router and that is not allowed. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.listener", @@ -169,7 +169,7 @@ class EdgeRouterQdManageTest(TestCase): an edge router can connect to another edge router and that is not allowed. """ - mgmt = QdManager(self, address=self.router.addresses[0]) + mgmt = QdManager(address=self.router.addresses[0]) test_pass = False try: out = mgmt.create("org.apache.qpid.dispatch.listener", @@ -3589,7 +3589,7 @@ class OneRouterUnavailableCoordinatorTest(TestCase): # condition=:"qd:no-route-to-dest", description="No route to the destination node" COORDINATOR = "$coordinator" long_type = 'org.apache.qpid.dispatch.router.config.linkRoute' - qd_manager = QdManager(self, address=self.address) + qd_manager = QdManager(address=self.address) args = {"prefix": COORDINATOR, "connection": "broker", "dir": "in"} qd_manager.create(long_type, args) link_route_created = False diff --git a/tests/system_tests_open_properties.py b/tests/system_tests_open_properties.py index 3e9979d2..e64671d4 100644 --- a/tests/system_tests_open_properties.py +++ b/tests/system_tests_open_properties.py @@ -265,10 +265,10 @@ class OpenPropertiesQdManageTest(TestCase): op}) cmd = "CREATE --type=org.apache.qpid.dispatch.%s --stdin" % client_class.entity - output = QdManager(tester=self)(cmd=cmd, - address=router.addresses[0], - input=input, - timeout=TIMEOUT) + output = QdManager()(cmd=cmd, + address=router.addresses[0], + input=input, + timeout=TIMEOUT) rc = json.loads(output) self.assertIn("openProperties", rc) self.assertEqual(op, rc["openProperties"]) diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py index f86f5029..f51c4dc4 100644 --- a/tests/system_tests_qdmanage.py +++ b/tests/system_tests_qdmanage.py @@ -597,7 +597,7 @@ class QdmanageTest(TestCase): def test_worker_threads(self): long_type = 'org.apache.qpid.dispatch.router' - qd_manager = QdManager(self, address=self.address()) + qd_manager = QdManager(address=self.address()) output = qd_manager.query('org.apache.qpid.dispatch.router') self.assertEqual(output[0]['workerThreads'], 4) diff --git a/tests/system_tests_sasl_plain.py b/tests/system_tests_sasl_plain.py index af5edc6b..a2378792 100644 --- a/tests/system_tests_sasl_plain.py +++ b/tests/system_tests_sasl_plain.py @@ -126,7 +126,7 @@ class RouterTestPlainSaslFailure(RouterTestPlainSaslCommon): def test_inter_router_sasl_fail(self): passed = False long_type = 'org.apache.qpid.dispatch.connection' - qd_manager = QdManager(self, address=self.routers[1].addresses[0]) + qd_manager = QdManager(address=self.routers[1].addresses[0]) connections = qd_manager.query(long_type) for connection in connections: if connection['role'] == 'inter-router': @@ -136,7 +136,7 @@ class RouterTestPlainSaslFailure(RouterTestPlainSaslCommon): # There was no inter-router connection established. self.assertFalse(passed) - qd_manager = QdManager(self, address=self.routers[1].addresses[0]) + qd_manager = QdManager(address=self.routers[1].addresses[0]) logs = qd_manager.get_log() sasl_failed = False @@ -223,7 +223,7 @@ class RouterTestPlainSaslFailureUsingLiteral(RouterTestPlainSaslCommon): passed = False long_type = 'org.apache.qpid.dispatch.connection' - qd_manager = QdManager(self, address=self.routers[1].addresses[0]) + qd_manager = QdManager(address=self.routers[1].addresses[0]) connections = qd_manager.query(long_type) for connection in connections: --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org