Commit ecc3101b authored by Morten Knutsen's avatar Morten Knutsen

neighbors.py: Add support for noop execution.

This will ease testing in preperation for router upgrade.
parent a0c0e84c
......@@ -38,7 +38,7 @@ def unicast_mac(mac):
class NeighborCache(object):
def __init__(self, ssl_cert, ssl_key, cacert, interface, routers):
def __init__(self, ssl_cert, ssl_key, cacert, interface, routers, noop):
self.etcd_client = etcd_connect('localhost', ssl_cert, ssl_key, cacert)
self.caches = ({}, {}, {})
self.ifindex = ifindex(interface)
......@@ -70,7 +70,11 @@ class NeighborCache(object):
else:
log.info("%s changed address from %s to %s",
mac, old_address, ipaddr)
neighbors.remove_pair(self.etcd_client, mac, old_address, addrtype)
if not self.noop:
neighbors.remove_pair(self.etcd_client, mac, old_address, addrtype)
else:
log.info("Would have removed pair (%s: %s)", mac, old_address)
orig_mac = neighbors.get_mac_from_ipaddress(self.etcd_client, ipaddr, addrtype)
if orig_mac is not None:
......@@ -80,7 +84,10 @@ class NeighborCache(object):
return
else:
log.info("New host %s: %s", mac, ipaddr)
neighbors.add_pair(self.etcd_client, mac, ipaddr, addrtype)
if not self.noop:
neighbors.add_pair(self.etcd_client, mac, ipaddr, addrtype)
else:
log.info("Would have added pair (%s: %s)", mac, ipaddr)
def process_event(self, np):
if np['event'] == 'RTM_NEWNEIGH':
......@@ -122,7 +129,7 @@ def main(args):
logging.info("Process starting")
cache = NeighborCache(args.cert, args.key, args.cacert, args.interface, args.routers)
cache = NeighborCache(args.cert, args.key, args.cacert, args.interface, args.routers, args.noop)
cache.run()
......@@ -149,7 +156,8 @@ def parse_args():
parser.add_argument('--routers',
help="Comma-separated list of routers to ignore when monitoring",
nargs="*", required=True)
parser.add_argument('--noop', action="store_true",
help="Don't actually update anything, just tell what would have been done")
return parser.parse_args()
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment