Skip to content

Commit f5dd3bc

Browse files
committed
Node: One more fixup after refactoring
We had the true/false signs mixed up in checking for a live connection in case of IOS/IOSXE devices and that screwed up the connectivity to those devices. Furthermore, if the user supplies a device type, we need to switch to it first as the device might require privilege escalation and if we don't switch first, we'll never manage to connect to the device. Signed-off-by: Dinesh Dutt <[email protected]>
1 parent c422c87 commit f5dd3bc

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

suzieq/poller/worker/nodes/node.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,32 @@ async def initialize(self, **kwargs) -> TNode:
159159

160160
self._init_service_queue()
161161

162+
devtype = kwargs.get("devtype", None)
163+
if devtype:
164+
self._set_devtype(devtype, '')
165+
self.logger.warning(
166+
f'{devtype} supplied for {self.address}:{self.port}')
167+
162168
if self.transport == "ssh":
163169
self.port = self.port or 22
164170
await self._init_ssh(init_dev_data=False)
165171
elif self.transport == "https":
166172
self.port = self.port or 443
167-
168-
devtype = kwargs.get("devtype", None)
169-
if devtype:
170-
self._set_devtype(devtype, '')
171-
if self.transport == 'https':
173+
if self.devtype:
174+
# Checking devtype to ensure we didn't get a REST transport
175+
# without also providing the device type.
172176
await self._init_rest()
173-
self.logger.warning(
174-
f'{devtype} supplied for {self.address}:{self.port}')
175-
elif self.transport != 'ssh':
176-
self.logger.error(
177-
'devtype MUST be specified in inventory file if transport'
178-
f'is not ssh for {self.address}')
179-
return self
180-
elif self.is_connected:
181-
# So we have a connection, lets figure out if we know what
182-
# to do with this device
183-
await self._detect_node_type()
177+
178+
if not devtype:
179+
if self.transport != 'ssh':
180+
self.logger.error(
181+
'devtype MUST be specified in inventory file if transport'
182+
f'is not ssh for {self.address}')
183+
return self
184+
elif self.is_connected:
185+
# So we have a connection, lets figure out if we know what
186+
# to do with this device
187+
await self._detect_node_type()
184188

185189
# Now we know the dev type, fetch the data we need about the
186190
# device to get cracking
@@ -1434,7 +1438,7 @@ async def _init_ssh(self, init_dev_data=True,
14341438
# Don't release rel lock here
14351439
await super()._init_ssh(init_dev_data=False, use_lock=False)
14361440

1437-
if not self.is_connected:
1441+
if self.is_connected:
14381442
self.logger.info(
14391443
f'Reconnect succeeded via SSH for {self.hostname}')
14401444
break
@@ -1454,7 +1458,7 @@ async def _init_ssh(self, init_dev_data=True,
14541458

14551459
output = await self.wait_for_prompt()
14561460
if output.strip().endswith('>'):
1457-
if not self._handle_privilege_escalation():
1461+
if await self._handle_privilege_escalation() == -1:
14581462
await self._close_connection()
14591463
self._conn = None
14601464
self._stdin = None

0 commit comments

Comments
 (0)