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
6b99c6d1
Commit
6b99c6d1
authored
Feb 21, 2018
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added 1 test & consider interface name in tests
parent
e38ffa98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
59 deletions
+89
-59
emulation/client2/root/ServerLog.py
emulation/client2/root/ServerLog.py
+20
-11
emulation/client2/root/TestAssert.py
emulation/client2/root/TestAssert.py
+69
-48
No files found.
emulation/client2/root/ServerLog.py
View file @
6b99c6d1
...
...
@@ -3,19 +3,24 @@ import logging
import
logging.handlers
import
socketserver
import
struct
from
TestAssert
import
Test1
,
Test2
import
sys
from
TestAssert
import
Test1
,
Test2
,
Test3
from
threading
import
Lock
class
CustomFilter
(
logging
.
Filter
):
def
filter
(
self
,
record
):
return
record
.
name
in
(
"pim.KernelEntry.DownstreamInterface.Assert"
,
"pim.KernelEntry.UpstreamInterface.Assert"
,
"pim.KernelInterface"
)
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
()]
currentTest
.
print_test
()
nextTests
=
[
Test2
(),
Test3
()]
lock
=
Lock
()
main
=
None
...
...
@@ -25,7 +30,7 @@ class LogRecordStreamHandler(socketserver.StreamRequestHandler):
followed by the LogRecord in pickle format. Logs the record
according to whatever policy is configured locally.
"""
logging
.
FileHandler
(
'server.log'
).
setLevel
(
logging
.
DEBUG
)
#
logging.FileHandler('server.log').setLevel(logging.DEBUG)
while
True
:
chunk
=
self
.
connection
.
recv
(
4
)
if
len
(
chunk
)
<
4
:
...
...
@@ -49,7 +54,7 @@ class LogRecordStreamHandler(socketserver.StreamRequestHandler):
else
:
name
=
record
.
name
logger
=
logging
.
getLogger
(
name
)
logger
.
addFilter
(
logging
.
Filter
(
'pim'
))
logger
.
addFilter
(
CustomFilter
(
))
# 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
...
...
@@ -60,8 +65,10 @@ class LogRecordStreamHandler(socketserver.StreamRequestHandler):
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
LogRecordStreamHandler
.
currentTest
.
print_test
()
else
:
LogRecordStreamHandler
.
currentTest
=
None
LogRecordStreamHandler
.
main
.
abort
=
True
...
...
@@ -73,7 +80,7 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
allow_reuse_address
=
True
def
__init__
(
self
,
host
=
'
10.5.5.100
'
,
def
__init__
(
self
,
host
=
'
localhost
'
,
port
=
logging
.
handlers
.
DEFAULT_TCP_LOGGING_PORT
,
handler
=
LogRecordStreamHandler
):
handler
.
main
=
self
...
...
@@ -93,14 +100,16 @@ class LogRecordSocketReceiver(socketserver.ThreadingTCPServer):
self
.
handle_request
()
abort
=
self
.
abort
def
main
():
logging
.
basicConfig
(
format
=
'%(
relativeCreated)5d %(name)-50s %(levelname)-8s %(tree)-35s %(vif)-2
s %(routername)-2s %(message)s'
,
format
=
'%(
name)-50s %(levelname)-8s %(tree)-35s %(vif)-2s %(interfacename)-5
s %(routername)-2s %(message)s'
,
)
#filename='example.log')
tcpserver
=
LogRecordSocketReceiver
()
tcpserver
=
LogRecordSocketReceiver
(
host
=
'10.5.5.100'
)
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
View file @
6b99c6d1
import
logging
from
abc
import
ABCMeta
class
ContextFilter
(
logging
.
Filter
):
"""
...
...
@@ -7,74 +8,94 @@ class ContextFilter(logging.Filter):
Rather than use actual contextual information, we just use random
data in this demo.
"""
def
__init__
(
self
,
tree
,
router_name
):
def
__init__
(
self
):
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
,
}
class
Test
():
__metaclass__
=
ABCMeta
def
__init__
(
self
):
print
(
"Test1: No info about (10.1.1.100,224.12.12.12)"
)
print
(
"Expected: R4 WINNER"
)
s
uper
().
__init__
()
def
__init__
(
self
,
testName
,
expectedState
,
success
):
self
.
testName
=
testName
self
.
expectedState
=
expectedState
s
elf
.
success
=
success
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
if
record
.
msg
==
self
.
expectedState
.
get
(
record
.
routername
).
get
(
record
.
interfacename
):
self
.
success
[
record
.
routername
][
record
.
interfacename
]
=
True
for
interface_test
in
self
.
success
.
values
():
if
False
in
interface_test
.
values
():
return
False
print
(
'
\
x1b
[1;32;40m'
+
self
.
testName
+
' Success'
+
'
\
x1b
[0m'
)
return
True
class
Test1
(
Test
):
def
__init__
(
self
):
expectedState
=
{
"R2"
:
{
"eth1"
:
"L"
},
"R3"
:
{
"eth1"
:
"L"
},
"R4"
:
{
"eth1"
:
"W"
},
"R5"
:
{
"eth0"
:
"L"
},
"R6"
:
{
"eth0"
:
"L"
},
}
success
=
{
"R2"
:
{
"eth1"
:
False
},
"R3"
:
{
"eth1"
:
False
},
"R4"
:
{
"eth1"
:
False
},
"R5"
:
{
"eth0"
:
False
},
"R6"
:
{
"eth0"
:
False
},
}
super
().
__init__
(
"Test1"
,
expectedState
,
success
)
def
print_test
(
self
):
print
(
"Test1: No info about (10.1.1.100,224.12.12.12)"
)
print
(
"Expected: R4 WINNER"
)
class
Test2
(
logging
.
Filter
):
expectedState
=
{
"R2"
:
"L"
,
"R3"
:
"W"
,
"R5"
:
"L"
,
"R6"
:
"L"
,
}
Success
=
{
"R2"
:
False
,
"R3"
:
False
,
"R5"
:
False
,
"R6"
:
False
,
}
class
Test2
(
Test
):
def
__init__
(
self
):
expectedState
=
{
"R2"
:
{
"eth1"
:
"L"
},
"R3"
:
{
"eth1"
:
"W"
},
"R5"
:
{
"eth0"
:
"L"
},
"R6"
:
{
"eth0"
:
"L"
},
}
success
=
{
"R2"
:
{
"eth1"
:
False
},
"R3"
:
{
"eth1"
:
False
},
"R5"
:
{
"eth0"
:
False
},
"R6"
:
{
"eth0"
:
False
},
}
super
().
__init__
(
"Test2"
,
expectedState
,
success
)
def
print_test
(
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
class
Test3
(
Test
):
def
__init__
(
self
):
expectedState
=
{
"R2"
:
{
"eth1"
:
"NI"
},
"R3"
:
{
"eth1"
:
"NI"
},
}
success
=
{
"R2"
:
{
"eth1"
:
False
},
"R3"
:
{
"eth1"
:
False
},
}
super
().
__init__
(
"Test3"
,
expectedState
,
success
)
def
print_test
(
self
):
print
(
"Test3: CouldAssert of AssertWinner(R3) -> False"
)
print
(
"Expected: everyone NI"
)
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