Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pim_dm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
pim_dm
Commits
e38ffa98
Commit
e38ffa98
authored
Feb 20, 2018
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix quagga end blocking & server log classes
parent
f5fb3c58
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
197 additions
and
0 deletions
+197
-0
emulation/client2/root/ServerLog.py
emulation/client2/root/ServerLog.py
+106
-0
emulation/client2/root/TestAssert.py
emulation/client2/root/TestAssert.py
+80
-0
emulation/router1.startup
emulation/router1.startup
+1
-0
emulation/router2.startup
emulation/router2.startup
+2
-0
emulation/router3.startup
emulation/router3.startup
+2
-0
emulation/router4.startup
emulation/router4.startup
+2
-0
emulation/router5.startup
emulation/router5.startup
+2
-0
emulation/router6.startup
emulation/router6.startup
+2
-0
No files found.
emulation/client2/root/ServerLog.py
0 → 100644
View file @
e38ffa98
import
pickle
import
logging
import
logging.handlers
import
socketserver
import
struct
from
TestAssert
import
Test1
,
Test2
import
sys
from
threading
import
Lock
class
LogRecordStreamHandler
(
socketserver
.
StreamRequestHandler
):
"""Handler for a streaming logging request.
This basically logs the record using whatever logging policy is
configured locally.
"""
currentTest
=
Test1
()
nextTests
=
[
Test2
()]
lock
=
Lock
()
main
=
None
def
handle
(
self
):
"""
Handle multiple requests - each expected to be a 4-byte length,
followed by the LogRecord in pickle format. Logs the record
according to whatever policy is configured locally.
"""
logging
.
FileHandler
(
'server.log'
).
setLevel
(
logging
.
DEBUG
)
while
True
:
chunk
=
self
.
connection
.
recv
(
4
)
if
len
(
chunk
)
<
4
:
break
slen
=
struct
.
unpack
(
'>L'
,
chunk
)[
0
]
chunk
=
self
.
connection
.
recv
(
slen
)
while
len
(
chunk
)
<
slen
:
chunk
=
chunk
+
self
.
connection
.
recv
(
slen
-
len
(
chunk
))
obj
=
self
.
unPickle
(
chunk
)
record
=
logging
.
makeLogRecord
(
obj
)
self
.
handleLogRecord
(
record
)
def
unPickle
(
self
,
data
):
return
pickle
.
loads
(
data
)
def
handleLogRecord
(
self
,
record
):
# if a name is specified, we use the named logger rather than the one
# implied by the record.
if
self
.
server
.
logname
is
not
None
:
name
=
self
.
server
.
logname
else
:
name
=
record
.
name
logger
=
logging
.
getLogger
(
name
)
logger
.
addFilter
(
logging
.
Filter
(
'pim'
))
# N.B. EVERY record gets logged. This is because Logger.handle
# is normally called AFTER logger-level filtering. If you want
# to do filtering, do it at the client end to save wasting
# cycles and network bandwidth!
#if record.routername == "R2":
logger
.
handle
(
record
)
with
LogRecordStreamHandler
.
lock
:
if
LogRecordStreamHandler
.
currentTest
and
record
.
routername
in
[
"R2"
,
"R3"
,
"R4"
,
"R5"
,
"R6"
]
and
record
.
name
in
(
"pim.KernelEntry.DownstreamInterface.Assert"
,
"pim.KernelEntry.UpstreamInterface.Assert"
)
and
LogRecordStreamHandler
.
currentTest
.
test
(
record
):
if
len
(
LogRecordStreamHandler
.
nextTests
)
>
0
:
LogRecordStreamHandler
.
currentTest
=
LogRecordStreamHandler
.
nextTests
.
pop
(
0
)
if
LogRecordStreamHandler
.
currentTest
is
None
:
LogRecordStreamHandler
.
main
.
abort
=
1
class
LogRecordSocketReceiver
(
socketserver
.
ThreadingTCPServer
):
"""
Simple TCP socket-based logging receiver suitable for testing.
"""
allow_reuse_address
=
True
def
__init__
(
self
,
host
=
'10.5.5.100'
,
port
=
logging
.
handlers
.
DEFAULT_TCP_LOGGING_PORT
,
handler
=
LogRecordStreamHandler
):
handler
.
main
=
self
socketserver
.
ThreadingTCPServer
.
__init__
(
self
,
(
host
,
port
),
handler
)
self
.
abort
=
0
self
.
timeout
=
1
self
.
logname
=
None
def
serve_until_stopped
(
self
):
import
select
abort
=
0
while
not
abort
:
rd
,
wr
,
ex
=
select
.
select
([
self
.
socket
.
fileno
()],
[],
[],
self
.
timeout
)
if
rd
:
self
.
handle_request
()
abort
=
self
.
abort
def
main
():
logging
.
basicConfig
(
format
=
'%(relativeCreated)5d %(name)-50s %(levelname)-8s %(tree)-35s %(vif)-2s %(routername)-2s %(message)s'
,
)
#filename='example.log')
tcpserver
=
LogRecordSocketReceiver
()
print
(
'About to start TCP server...'
)
tcpserver
.
serve_until_stopped
()
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
emulation/client2/root/TestAssert.py
0 → 100644
View file @
e38ffa98
import
logging
class
ContextFilter
(
logging
.
Filter
):
"""
This is a filter which injects contextual information into the log.
Rather than use actual contextual information, we just use random
data in this demo.
"""
def
__init__
(
self
,
tree
,
router_name
):
super
().
__init__
()
def
filter
(
self
,
record
):
return
record
.
routername
in
[
"R2"
,
"R3"
,
"R4"
,
"R5"
,
"R6"
]
class
Test1
(
logging
.
Filter
):
expectedState
=
{
"R2"
:
"L"
,
"R3"
:
"L"
,
"R4"
:
"W"
,
"R5"
:
"L"
,
"R6"
:
"L"
,
}
Success
=
{
"R2"
:
False
,
"R3"
:
False
,
"R4"
:
False
,
"R5"
:
False
,
"R6"
:
False
,
}
def
__init__
(
self
):
print
(
"Test1: No info about (10.1.1.100,224.12.12.12)"
)
print
(
"Expected: R4 WINNER"
)
super
().
__init__
()
def
test
(
self
,
record
):
if
record
.
routername
not
in
self
.
expectedState
:
return
False
if
record
.
msg
==
self
.
expectedState
.
get
(
record
.
routername
):
self
.
Success
[
record
.
routername
]
=
True
if
sum
(
self
.
Success
.
values
())
==
len
(
self
.
Success
):
# tudo certo
print
(
"Test1 Success"
)
return
True
return
False
class
Test2
(
logging
.
Filter
):
expectedState
=
{
"R2"
:
"L"
,
"R3"
:
"W"
,
"R5"
:
"L"
,
"R6"
:
"L"
,
}
Success
=
{
"R2"
:
False
,
"R3"
:
False
,
"R5"
:
False
,
"R6"
:
False
,
}
def
__init__
(
self
):
print
(
"Test2: Kill assert winner"
)
print
(
"Expected: R3 WINNER"
)
super
().
__init__
()
def
test
(
self
,
record
):
if
record
.
routername
not
in
self
.
expectedState
:
return
False
if
record
.
msg
==
self
.
expectedState
.
get
(
record
.
routername
):
self
.
Success
[
record
.
routername
]
=
True
if
sum
(
self
.
Success
.
values
())
==
len
(
self
.
Success
):
# tudo certo
print
(
"Test2 Success"
)
return
True
return
False
emulation/router1.startup
View file @
e38ffa98
...
...
@@ -16,4 +16,5 @@ iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -o eth4 -j MASQUERADE
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
emulation/router2.startup
View file @
e38ffa98
...
...
@@ -20,3 +20,5 @@ done
# install python
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
emulation/router3.startup
View file @
e38ffa98
...
...
@@ -20,3 +20,5 @@ done
# install python
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
emulation/router4.startup
View file @
e38ffa98
...
...
@@ -21,3 +21,5 @@ done
# install python
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
emulation/router5.startup
View file @
e38ffa98
...
...
@@ -20,3 +20,5 @@ done
# install python
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
emulation/router6.startup
View file @
e38ffa98
...
...
@@ -20,3 +20,5 @@ done
# install python
#apt-get update && apt-get --assume-yes install python3 python3-pip
echo VTYSH_PAGER=more > /etc/environment
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment