From 56934d9d28758ac67a7bec72c49a448da5b6873f Mon Sep 17 00:00:00 2001 From: Plamen Dimitrov Date: Thu, 14 Nov 2024 00:06:59 +0200 Subject: [PATCH] Provide remote Pyro5 compatibility for multiple remote objects The Pyro5.nameserver resp. Pyro4.naming are name servers that are used for resolving names of remote objects (for easier access than long hashes which are the unique default identifiers for these objects). With this change we will use the correct name server if we have Pyro4 installed locally and Pyro4 installed remotely and resp. Pyro5 installed locally and Pyro5 installed remotely. Before this change we would make something like Pyro4/Pyro5 locally work with Pyro4 remotely. Note that the current usage is more standard (expecting the same version) and is not a regression in functionality since many of the Pyro5 versions already have incompatible protocol with the latest (but no longer worked on) Pyro4 versions. Sharing multiple remote objects at the same time is a more rarely used case that we now cover with Pyro5 support as well. The method we recommend remains in retrieving multiple remote objects one by one using single remote object getter and this one remains more manual and still requires some control file implementation. The changes this builds upon are 8f4c5cc where we provide compatibility between Pyro5 and Pyro4. The reason we went for this was to introduce the minimal amount of changes to the various remote door functionality until everything is better tested over the longer term. The idea was and still is to "tread lightly". Signed-off-by: Plamen Dimitrov --- aexpect/remote_door.py | 5 ++++- tests/test_remote_door.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aexpect/remote_door.py b/aexpect/remote_door.py index c89bb55..22bd3a2 100644 --- a/aexpect/remote_door.py +++ b/aexpect/remote_door.py @@ -77,6 +77,7 @@ from Pyro5 import server # noinspection PyPackageRequirements from Pyro5 import nameserver + NS_MODULE = "Pyro5.nameserver" except ImportError: # noinspection PyPackageRequirements,PyUnresolvedReferences import Pyro4 @@ -92,10 +93,12 @@ def __init__(self): # noinspection PyPackageRequirements from Pyro4 import naming as nameserver nameserver.start_ns = nameserver.startNS + NS_MODULE = "Pyro4.naming" except ImportError: logging.warning("Remote object backend (Pyro4) not found, some functionality" " of the remote door will not be available") + NS_MODULE = "" # NOTE: disable aexpect importing on the remote side if not available as the # remote door can run code remotely without the requirement for the aexpect @@ -848,7 +851,7 @@ def share_remote_objects(session, control_path, host="localhost", port=9090, # setup remote objects server LOG.info("Starting nameserver for the remote objects") - cmd = f"python -m Pyro4.naming -n {host} -p {port}" + cmd = f"python -m {NS_MODULE} -n {host} -p {port}" session.cmd("START " + cmd if os_type == "windows" else cmd + " &") LOG.info("Starting the server daemon for the remote objects") diff --git a/tests/test_remote_door.py b/tests/test_remote_door.py index 61f656e..9970bba 100644 --- a/tests/test_remote_door.py +++ b/tests/test_remote_door.py @@ -217,6 +217,7 @@ def test_share_remote_objects(self): """Test that a remote object can be shared properly and remotely.""" self.session = mock.MagicMock(name='session') self.session.client = "ssh" + remote_door.NS_MODULE = "pyro.name.server" control_file = os.path.join(remote_door.REMOTE_CONTROL_DIR, "tmpxxxxxxxx.control") @@ -234,7 +235,7 @@ def test_share_remote_objects(self): else: self.assertEqual(self.session.cmd.call_count, 1) command = self.session.cmd.call_args[0][0] - self.assertEqual("python -m Pyro4.naming -n testhost -p 4242 &", command) + self.assertEqual(f"python -m {remote_door.NS_MODULE} -n testhost -p 4242 &", command) def test_import_remote_exceptions(self): """Test that selected remote exceptions are properly imported and deserialized."""