Skip to content
Snippets Groups Projects
Commit d276d1cb authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-333: CommClient.connect now does not return, but raises an exception upon...

L2SS-333: CommClient.connect now does not return, but raises an exception upon failure. This replaces using 'return True' and raising an exception.
parent 3c81de67
Branches
Tags
1 merge request!95L2SS-333: Improve CommClient.connect signature
...@@ -21,9 +21,10 @@ class CommClient(Thread): ...@@ -21,9 +21,10 @@ class CommClient(Thread):
def connect(self): def connect(self):
""" """
Function used to connect to the client. Function used to connect to the client.
Throws an Exception if the connection cannot be established.
""" """
self.connected = True self.connected = True
return True
def disconnect(self): def disconnect(self):
""" """
......
...@@ -47,11 +47,7 @@ class OPCUAConnection(CommClient): ...@@ -47,11 +47,7 @@ class OPCUAConnection(CommClient):
self.client = Client(address, timeout) self.client = Client(address, timeout)
# Explicitly connect # Explicitly connect
if not self.connect(): self.connect()
# hardware or infra is down -- needs fixing first
fault_func()
return
# determine namespace used # determine namespace used
try: try:
...@@ -79,13 +75,13 @@ class OPCUAConnection(CommClient): ...@@ -79,13 +75,13 @@ class OPCUAConnection(CommClient):
try: try:
self.streams.debug_stream("Connecting to server %s", self._servername()) self.streams.debug_stream("Connecting to server %s", self._servername())
self.client.connect() self.client.connect()
self.connected = True
self.streams.debug_stream("Connected to %s. Initialising.", self._servername()) self.streams.debug_stream("Connected to %s. Initialising.", self._servername())
return True
except socket.error as e: except socket.error as e:
self.streams.error_stream("Could not connect to server %s: %s", self._servername(), 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 raise Exception("Could not connect to server %s", self._servername()) from e
super().connect()
def check_nodes(self): def check_nodes(self):
""" """
function purely for debugging/development only. Simply lists all top level nodes and the nodes below that function purely for debugging/development only. Simply lists all top level nodes and the nodes below that
......
...@@ -36,10 +36,7 @@ class StatisticsClient(CommClient): ...@@ -36,10 +36,7 @@ class StatisticsClient(CommClient):
super().__init__(fault_func, streams, try_interval) super().__init__(fault_func, streams, try_interval)
# Explicitly connect # Explicitly connect
if not self.connect(): self.connect()
# hardware or infra is down -- needs fixing first
fault_func()
return
def queue_fill_percentage(self): def queue_fill_percentage(self):
try: try:
...@@ -57,7 +54,7 @@ class StatisticsClient(CommClient): ...@@ -57,7 +54,7 @@ class StatisticsClient(CommClient):
self.udp = UDPReceiver(self.host, self.port, self.queue, self.poll_timeout) self.udp = UDPReceiver(self.host, self.port, self.queue, self.poll_timeout)
self.statistics = self.statistics_collector_class(self.queue) self.statistics = self.statistics_collector_class(self.queue)
return super().connect() super().connect()
def ping(self): def ping(self):
if not self.statistics.is_alive(): if not self.statistics.is_alive():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment