From d276d1cb585a63ee043bf950ad3357dcfd2ac3c2 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Thu, 12 Aug 2021 16:27:36 +0200 Subject: [PATCH] L2SS-333: CommClient.connect now does not return, but raises an exception upon failure. This replaces using 'return True' and raising an exception. --- devices/clients/comms_client.py | 3 ++- devices/clients/opcua_client.py | 10 +++------- devices/clients/statistics_client.py | 7 ++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/devices/clients/comms_client.py b/devices/clients/comms_client.py index 011e1e621..6aa52ae42 100644 --- a/devices/clients/comms_client.py +++ b/devices/clients/comms_client.py @@ -21,9 +21,10 @@ class CommClient(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): """ diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py index dc85a6f4f..e1aa0a87c 100644 --- a/devices/clients/opcua_client.py +++ b/devices/clients/opcua_client.py @@ -47,11 +47,7 @@ class OPCUAConnection(CommClient): self.client = Client(address, timeout) # Explicitly connect - if not self.connect(): - # hardware or infra is down -- needs fixing first - fault_func() - return - + self.connect() # determine namespace used try: @@ -79,13 +75,13 @@ class OPCUAConnection(CommClient): try: self.streams.debug_stream("Connecting to server %s", self._servername()) self.client.connect() - self.connected = True self.streams.debug_stream("Connected to %s. Initialising.", self._servername()) - return True except socket.error as e: self.streams.error_stream("Could not connect to server %s: %s", self._servername(), e) raise Exception("Could not connect to server %s", self._servername()) from e + super().connect() + def check_nodes(self): """ function purely for debugging/development only. Simply lists all top level nodes and the nodes below that diff --git a/devices/clients/statistics_client.py b/devices/clients/statistics_client.py index 5d45ac472..b66971b77 100644 --- a/devices/clients/statistics_client.py +++ b/devices/clients/statistics_client.py @@ -36,10 +36,7 @@ class StatisticsClient(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 queue_fill_percentage(self): try: @@ -57,7 +54,7 @@ class StatisticsClient(CommClient): self.udp = UDPReceiver(self.host, self.port, self.queue, self.poll_timeout) self.statistics = self.statistics_collector_class(self.queue) - return super().connect() + super().connect() def ping(self): if not self.statistics.is_alive(): -- GitLab