Ema has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/344659 )
Change subject: bgp: log with util.log instead of printing to stdout
......................................................................
bgp: log with util.log instead of printing to stdout
Change-Id: Ib8508b2ab33c5eca2affefe028968b0d1033dd8f
---
M pybal/bgp.py
1 file changed, 31 insertions(+), 46 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/debs/pybal
refs/changes/59/344659/1
diff --git a/pybal/bgp.py b/pybal/bgp.py
index 47d21c4..e5d66bc 100644
--- a/pybal/bgp.py
+++ b/pybal/bgp.py
@@ -17,8 +17,10 @@
from zope.interface import implements, Interface
# Twisted imports
-from twisted import copyright
-from twisted.internet import reactor, protocol, base, interfaces, error, defer
+from twisted.internet import reactor, protocol, interfaces, error, defer
+
+# Pybal imports
+from .util import log
# Constants
VERSION = 4
@@ -970,7 +972,7 @@
def __setattr__(self, name, value):
if name == 'state' and value != getattr(self, name):
- print "State is now:", stateDescr[value]
+ log.info("State is now: %s" % stateDescr[value], system="bgp")
super(FSM, self).__setattr__(name, value)
def manualStart(self):
@@ -1102,8 +1104,7 @@
elif self.state == ST_OPENCONFIRM:
# State OpenConfirm, events 19, 20
- # DEBUG
- print "Running collision detection"
+ log.info("Running collision detection", system="bgp")
# Perform collision detection
self.protocol.collisionDetect()
@@ -1228,8 +1229,7 @@
(event 23)
"""
- # DEBUG
- print "Collided, closing."
+ log.info("Collided, closing.", system="bgp")
if self.state == ST_IDLE:
return
@@ -1244,8 +1244,7 @@
assert(self.delayOpen)
- # DEBUG
- print "Delay Open event"
+ log.info("Delay Open event", system="bgp")
if self.state == ST_CONNECT:
# State Connect, event 12
@@ -1368,8 +1367,7 @@
# Set transport socket options
self.transport.setTcpNoDelay(True)
- # DEBUG
- print "Connection established"
+ log.info("Connection established", system="bgp")
# Set the local BGP id from the local IP address if it's not set
if self.factory.bgpId is None:
@@ -1392,8 +1390,7 @@
self.factory.connectionClosed(self)
return
- # DEBUG
- print "Connection lost:", reason.getErrorMessage()
+ log.info("Connection lost: %s" % reason.getErrorMessage(),
system="bgp")
try:
self.fsm.connectionFailed()
@@ -1422,19 +1419,17 @@
def sendOpen(self):
"""Sends a BGP Open message to the peer"""
- # DEBUG
- print "Sending Open"
+ log.info("Sending Open", system="bgp")
self.transport.write(self.constructOpen())
def sendUpdate(self, withdrawnPrefixes, attributes, nlri):
"""Sends a BGP Update message to the peer"""
- # DEBUG
- print "Sending Update"
- print "Withdrawing:", withdrawnPrefixes
- print "Attributes:", attributes
- print "NLRI:", nlri
+ log.info("Sending Update", system="bgp")
+ log.info("Withdrawing: %s" % withdrawnPrefixes, system="bgp")
+ log.info("Attributes: %s" % attributes, system="bgp")
+ log.info("NLRI: %s" % nlri, system="bgp")
self.transport.write(self.constructUpdate(withdrawnPrefixes,
attributes, nlri))
self.fsm.updateSent()
@@ -1641,9 +1636,8 @@
def openReceived(self, version, ASN, holdTime, bgpId):
"""Called when a BGP Open message was received."""
- # DEBUG
- print "OPEN: version:", version, "ASN:", ASN, "hold time:", \
- holdTime, "id:", bgpId
+ log.info("OPEN: version: %s ASN: %s hold time: %s id: %s" %
+ (version, ASN, holdTime, bgpId), system="bgp")
self.peerId = bgpId
self.bgpPeering.setPeerId(bgpId)
@@ -1677,9 +1671,8 @@
def notificationReceived(self, error, suberror, data=''):
"""Called when a BGP Notification message was received.
"""
-
- # DEBUG
- print "NOTIFICATION:", error, suberror, [ord(d) for d in data]
+ log.info("NOTIFICATION: %s %s %s" % (
+ error, suberror, [ord(d) for d in data]), system="bgp")
self.fsm.notificationReceived(error, suberror)
@@ -1693,8 +1686,8 @@
# Derived times
self.fsm.keepAliveTime = self.fsm.holdTime / 3
- # DEBUG
- print "Hold time:", self.fsm.holdTime, "Keepalive time:",
self.fsm.keepAliveTime
+ log.info("Hold time: %s Keepalive time: %s" % (
+ self.fsm.holdTime, self.fsm.keepAliveTime), system="bgp")
def collisionDetect(self):
"""Performs collision detection. Outsources to factory class
BGPPeering."""
@@ -1831,8 +1824,7 @@
pass
def clientConnectionLost(self, connector, reason):
- # DEBUG
- print "Client connection lost:", reason.getErrorMessage()
+ log.info("Client connection lost: %s" % reason.getErrorMessage(),
system="bgp")
class BGPServerFactory(BGPFactory):
"""Class managing the server (listening) side of the BGP
@@ -1848,9 +1840,7 @@
"""Builds a BGPProtocol instance by finding an appropriate
BGPPeering factory instance to hand over to.
"""
-
- # DEBUG
- print "Connection received from", addr.host
+ log.info("Connection received from %s" % addr.host, system="bgp")
try:
bgpPeering = self.peers[addr.host]
@@ -1879,8 +1869,7 @@
def buildProtocol(self, addr):
"""Builds a BGP protocol instance"""
-
- print "Building a new BGP protocol instance"
+ log.info("Building a new BGP protocol instance", system="bgp")
p = BGPFactory.buildProtocol(self, addr)
if p is not None:
@@ -1922,9 +1911,7 @@
def clientConnectionFailed(self, connector, reason):
"""Called when the outgoing connection failed."""
-
- # DEBUG
- print "Client connection failed:", reason.getErrorMessage()
+ log.info("Client connection failed: %s" % reason.getErrorMessage(),
system="bgp")
# There is no protocol instance yet at this point.
# Catch a possible NotificationException
@@ -1978,7 +1965,7 @@
Called by FSM or Protocol when the BGP connection has been closed.
"""
- print "Connection closed"
+ log.info("Connection closed", system="bgp")
if protocol is not None:
# Connection succeeded previously, protocol exists
@@ -2033,7 +2020,7 @@
def protocolError(self, failure):
failure.trap(BGPException)
- print "BGP exception", failure
+ log.error("BGP exception: %s" % failure)
e = failure.check(NotificationSent)
try:
@@ -2041,9 +2028,9 @@
failure.raiseException()
except NotificationSent, e:
if (e.error, e.suberror) == (ERR_MSG_UPDATE,
ERR_MSG_UPDATE_ATTR_FLAGS):
- print "exception on flags:", BGP.parseEncodedAttributes(e.data)
+ log.error("exception on flags: %s" %
BGP.parseEncodedAttributes(e.data))
else:
- print e.error, e.suberror, e.data
+ log.error("%s %s %s" % (e.error, e.suberror, e.data))
# FIXME: error handling
@@ -2110,9 +2097,7 @@
"""Initiates a TCP connection to the peer. Should only be called from
BGPPeering or FSM, otherwise use manualStart() instead.
"""
-
- # DEBUG
- print "(Re)connect to", self.peerAddr
+ log.info("(Re)connect to %s" % self.peerAddr, system="bgp")
if self.fsm.state != ST_ESTABLISHED:
reactor.connectTCP(self.peerAddr, PORT, self)
@@ -2299,4 +2284,4 @@
if (len(withdrawals) + len(advertisements) > 0
) or (MPReachNLRIAttribute in attributes
) or (MPUnreachNLRIAttribute in attributes):
- self.estabProtocol.sendUpdate([w.prefix for w in withdrawals],
attributes, [a.prefix for a in advertisements])
\ No newline at end of file
+ self.estabProtocol.sendUpdate([w.prefix for w in withdrawals],
attributes, [a.prefix for a in advertisements])
--
To view, visit https://gerrit.wikimedia.org/r/344659
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8508b2ab33c5eca2affefe028968b0d1033dd8f
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: 1.13
Gerrit-Owner: Ema <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits