Skip to content

Commit

Permalink
Added ping testing of routers
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfzc committed Apr 15, 2015
1 parent 4224404 commit b69d7e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
35 changes: 12 additions & 23 deletions examples/normalizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,24 @@ This example version of a Normalizer will connect to a defined set of routers. I

There are a number of todos, the most signficiant is that I would like to return the ordered command output including commands that occur more than once (e.g. write mem).

Here is a first execution against a set of three routers, one of which requires normalization and one of which is offline.
Here is the result of two executions against a set of three routers, one of which requires normalization and one of which is offline.

```
johnf@pstanadm1:~/TriggerTest$ ./TriggerReactorlessNormalize.py
Error in getRouterDetails for device r3
Traceback (most recent call last):
Failure: twisted.internet.error.ConnectError: An error occurred while connecting: 113: No route to host.
In validateRouterDetails
Processing result set for device r1
Processing result set for device r2
In initiateRouterNormalization
Ping testing 3 devices (r1 r2 r3)
Not processing device r3, failed to responded to ping
Processing responsive 2 devices (r1 r2)
Validating router details
Queueing routers for normalization
Will normalize router r1
Need to normalize ACL on router r1
Need to normalize ACL
Job state is True
Device r1
```

And a second execution with the configurations normalized.

```
johnf@pstanadm1:~/TriggerTest$ ./TriggerReactorlessNormalize.py
Error in getRouterDetails for device r3
Traceback (most recent call last):
Failure: twisted.internet.error.ConnectError: An error occurred while connecting: 113: No route to host.
In validateRouterDetails
Processing result set for device r1
Processing result set for device r2
In initiateRouterNormalization
Ping testing 3 devices (r1 r2 r3)
Not processing device r3, failed to responded to ping
Processing responsive 2 devices (r1 r2)
Validating router details
Queueing routers for normalization
No devices need to be normalized
```
23 changes: 18 additions & 5 deletions examples/normalizer/TriggerReactorlessNormalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trigger.cmds import ReactorlessCommando
from twisted.python import log
from twisted.internet import defer, task, reactor
import os
import re
import sys
import time
Expand All @@ -24,11 +25,11 @@ def errback(self, failure, device):
print "Error in getRouterDetails for device {}\n{}".format(device,failure.getTraceback())

def validateRouterDetails(result):
print "In validateRouterDetails"
print "Validating router details"
devicesToCorrect = []

for device, results in result.items():
print "Processing result set for device {}".format(device)
# print "Processing result set for device {}".format(device)
routers[device].normalize["trigger_acl"] = True
for line in results["show run | i ip access-list"].splitlines():
line=line.strip()
Expand All @@ -53,14 +54,14 @@ def validateRouterDetails(result):
return devicesToCorrect or None

def initiateRouterNormalization(devices):
print "In initiateRouterNormalization"
print "Queueing routers for normalization"
# log.startLogging(sys.stdout, setStdout=False)
if devices is not None:
deferreds = []
for device in devices:
print "Will normalize router {} ".format(device)
if routers[device].normalize["trigger_acl"]:
print "Need to normalize ACL on router {}".format(device)
print "Need to normalize ACL".format(device)
routers[device].commando = ReactorlessCommando([device],commands=routers[device].commands)
deferreds.append(routers[device].commando.run())
return defer.DeferredList(deferreds)
Expand All @@ -79,14 +80,26 @@ def stop_reactor(result):
if __name__ == '__main__':
nd = NetDevices()
device_list = ['r1', 'r2', 'r3']
up_device_list = []
routers={}

print "Ping testing {} devices ({})".format(len(device_list)," ".join(device_list))

for device in device_list:
response = os.system("ping -c 2 {} >/dev/null 2>&1".format(device))
if response == 0:
up_device_list.append(device)
else:
print "Not processing device {}, failed to responded to ping".format(device)

print "Processing responsive {} devices ({})".format(len(up_device_list)," ".join(up_device_list))

for device in up_device_list:
routers[device]=Router(device)

# log.startLogging(sys.stdout, setStdout=False)

d = getRouterDetails(device_list).run()
d = getRouterDetails(up_device_list).run()
d.addCallback(validateRouterDetails)
d.addCallback(initiateRouterNormalization)
d.addBoth(stop_reactor)
Expand Down

0 comments on commit b69d7e5

Please sign in to comment.