diff --git a/devices/clients/comms_client.py b/devices/clients/comms_client.py index 6e44e6d2d088ed49b3f2a4e7f65796e297444601..31dfc99ce4092d8f1025bfe3b10fc8a9c561ebe8 100644 --- a/devices/clients/comms_client.py +++ b/devices/clients/comms_client.py @@ -63,9 +63,10 @@ class CommClient(AbstractCommClient, Thread): def connect(self): """ Function used to connect to the client. + + Throws an Exception if the connection cannot be established. """ self.connected = True - return True def disconnect(self): """ @@ -74,22 +75,15 @@ class CommClient(AbstractCommClient, Thread): self.connected = False def run(self): - - # Explicitly connect - if not self.connect(): - # hardware or infra is down -- needs fixing first - self.fault_func() - return - self.stopping = False while not self.stopping: - # keep trying to connect if not self.connected: - if self.connect(): - pass - else: - # we retry only once, to catch exotic network issues. if the infra or hardware is down, - # our device cannot help, and must be reinitialised after the infra or hardware is fixed. + # we (re)try only once, to catch exotic network issues. if the infra or hardware is down, + # our device cannot help, and must be reinitialised after the infra or hardware is fixed. + try: + self.connect() + except Exception as e: + self.streams.error_stream("Fault condition in communication detected.", e) self.fault_func() return diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py index fb8d252927b2831c50af7ee60e6e7c6d8fba4cf2..bf68edd19318648f1c8313f349a63671000382c7 100644 --- a/devices/clients/opcua_client.py +++ b/devices/clients/opcua_client.py @@ -59,7 +59,6 @@ class OPCUAConnection(AsyncCommClient): try: await self.client.connect() - self.connected = True except (socket.error, IOError, OSError) as e: raise IOError(f"Could not connect to OPC-UA server {self._servername()}") from e diff --git a/devices/test/clients/test_client.py b/devices/test/clients/test_client.py index 039974a1e34ae1a0c9779fd29c2c87f545bc38b7..7e002c3ad28a531b0ba16f12a22e782d4ba3bb01 100644 --- a/devices/test/clients/test_client.py +++ b/devices/test/clients/test_client.py @@ -22,10 +22,7 @@ class test_client(CommClient): super().__init__(fault_func, streams, try_interval) # Explicitly connect - if not self.connect(): - # hardware or infra is down -- needs fixing first - fault_func() - return + self.connect() def connect(self): """ @@ -34,7 +31,6 @@ class test_client(CommClient): self.streams.debug_stream("the example client doesn't actually connect to anything silly") self.connected = True # set connected to true - return True # if succesfull, return true. otherwise return false def disconnect(self): self.connected = False # always force a reconnect, regardless of a successful disconnect diff --git a/devices/test/common/test_lofar_logging.py b/devices/test/common/test_lofar_logging.py index 98222563f33167e62db9385090e1738aa29b6b24..c1030b28f3b9b7861e6eec9d25b4ca6ef22a0c22 100644 --- a/devices/test/common/test_lofar_logging.py +++ b/devices/test/common/test_lofar_logging.py @@ -14,6 +14,7 @@ from common import lofar_logging import logging from tango.server import Device from tango import device_server +from tango.test_context import DeviceTestContext from test import base @@ -82,11 +83,15 @@ class TestLofarLogging(base.TestCase): logger.info("test") with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream: - # logs in the constructor already - mydevice = MyDevice(None, "MyDeviceName") + with DeviceTestContext(MyDevice) as mydevice: + self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device") - self.assertEqual(mydevice, self.memory_handler.records[0].tango_device, msg="configure_logging did not detect active Tango device") - self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device") + # Lookup our "test" logline among f.e. the debug messages output by Tango + test_record = [record for record in self.memory_handler.records if record.msg == "test"] + + # Tango uses slightly different class representations of MyDevice, so + # we can't compare them direclty. Just verify we're talking about the same thing. + self.assertEqual(str(mydevice), str(test_record[0].tango_device), msg="configure_logging did not detect active Tango device") def test_log_exceptions(self): diff --git a/docker-compose/.env b/docker-compose/.env index 85ebd21e4cfc0392b1f3f4452f22c861f1d304fe..00b12b0fcb55b351ebf9e56b37ae2c1f0fc6f4a9 100644 --- a/docker-compose/.env +++ b/docker-compose/.env @@ -8,7 +8,7 @@ TANGO_CPP_VERSION=9.3.5 TANGO_DB_VERSION=10.4.11 TANGO_DSCONFIG_VERSION=1.5.1 TANGO_HDBPP_VIEWER_VERSION=2021-05-28 -TANGO_ITANGO_VERSION=9.3.5 +TANGO_ITANGO_VERSION=9.3.7 TANGO_JAVA_VERSION=9.3.4 TANGO_POGO_VERSION=9.6.32 TANGO_REST_VERSION=1.14.2