Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
respdiff
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
18
Issues
18
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
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
Knot projects
respdiff
Commits
5aff589a
Commit
5aff589a
authored
May 25, 2018
by
Tomas Krizek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nitpicks
parent
65b48167
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
10 deletions
+18
-10
respdiff/dbhelper.py
respdiff/dbhelper.py
+8
-6
respdiff/histogram.py
respdiff/histogram.py
+4
-0
respdiff/msgdiff.py
respdiff/msgdiff.py
+5
-3
tests/test_dbhelper.py
tests/test_dbhelper.py
+1
-1
No files found.
respdiff/dbhelper.py
View file @
5aff589a
from
abc
import
ABC
from
contextlib
import
contextmanager
import
logging
import
os
import
struct
import
sys
...
...
@@ -160,6 +159,8 @@ class DNSReply:
def
__eq__
(
self
,
other
)
->
bool
:
if
self
.
timeout
and
other
.
timeout
:
return
True
# float equality comparison: use 10^-7 tolerance since it's less than available
# resoltuion from the time_int integer value (which is 10^-6)
return
self
.
wire
==
other
.
wire
and
\
abs
(
self
.
time
-
other
.
time
)
<
10
**
-
7
...
...
@@ -169,13 +170,14 @@ class DNSReply:
return
self
.
TIMEOUT_INT
value
=
round
(
self
.
time
*
(
10
**
6
))
if
value
>
self
.
TIMEOUT_INT
:
raise
ValueError
(
'Maximum time value exceeded'
)
raise
ValueError
(
'Maximum time value exceeded: (value: "{}", max: {})'
.
format
(
value
,
self
.
TIMEOUT_INT
))
return
value
@
property
def
binary
(
self
)
->
bytes
:
length
=
len
(
self
.
wire
)
assert
length
<
2
**
(
self
.
SIZEOF_SHORT
*
8
),
'Maximum wire format length exceeded'
return
struct
.
pack
(
'<I'
,
self
.
time_int
)
+
struct
.
pack
(
'<H'
,
length
)
+
self
.
wire
@
classmethod
...
...
@@ -215,10 +217,12 @@ class DNSRepliesFactory:
reply
,
buff
=
DNSReply
.
from_binary
(
buff
)
replies
[
server
]
=
reply
if
buff
:
logging
.
warning
(
'Trailing data in buffer'
)
raise
ValueError
(
'Trailing data in buffer'
)
return
replies
def
serialize
(
self
,
replies
:
Mapping
[
ResolverID
,
DNSReply
])
->
bytes
:
if
len
(
replies
)
>
len
(
self
.
servers
):
raise
ValueError
(
'Extra unexpected data to serialize!'
)
data
=
[]
for
server
in
self
.
servers
:
try
:
...
...
@@ -227,8 +231,6 @@ class DNSRepliesFactory:
raise
ValueError
(
'Missing reply for server "{}"!'
.
format
(
server
))
else
:
data
.
append
(
reply
.
binary
)
if
len
(
replies
)
>
len
(
self
.
servers
):
raise
ValueError
(
'Extra unexpected data to serialize!'
)
return
b
''
.
join
(
data
)
...
...
respdiff/histogram.py
View file @
5aff589a
#!/usr/bin/env python3
# NOTE: Due to a weird bug, numpy is detected as a 3rd party module, while lmdb
# is not and pylint complains about wrong-import-order.
# Since these checks have to be disabled for matplotlib imports anyway, they
# were moved a bit higher up to avoid the issue.
# pylint: disable=wrong-import-order,wrong-import-position
import
argparse
import
logging
...
...
respdiff/msgdiff.py
View file @
5aff589a
...
...
@@ -259,7 +259,8 @@ def export_json(filename: str, report: DiffReport):
for
field
,
mismatch
in
diff
.
items
():
report
.
target_disagreements
.
add_mismatch
(
field
,
mismatch
,
qid
)
# it doesn't make sense to use existing report.json
# NOTE: msgdiff is the first tool in the toolchain to generate report.json
# thus it doesn't make sense to re-use existing report.json file
if
os
.
path
.
exists
(
filename
):
backup_filename
=
filename
+
'.bak'
os
.
rename
(
filename
,
backup_filename
)
...
...
@@ -321,9 +322,10 @@ def main():
qid_stream
=
lmdb
.
key_stream
(
LMDB
.
ANSWERS
)
dnsreplies_factory
=
DNSRepliesFactory
(
servers
)
func
=
partial
(
compare_lmdb_wrapper
,
criteria
,
target
,
dnsreplies_factory
)
compare_func
=
partial
(
compare_lmdb_wrapper
,
criteria
,
target
,
dnsreplies_factory
)
with
pool
.
Pool
()
as
p
:
for
_
in
p
.
imap_unordered
(
func
,
qid_stream
,
chunksize
=
10
):
for
_
in
p
.
imap_unordered
(
compare_
func
,
qid_stream
,
chunksize
=
10
):
pass
export_json
(
datafile
,
report
)
...
...
tests/test_dbhelper.py
View file @
5aff589a
...
...
@@ -46,7 +46,7 @@ def test_dns_reply_time_int(time, time_int):
assert
reply
.
time_int
==
time_int
DR_TIMEOUT
=
DNSReply
(
None
,
None
)
DR_TIMEOUT
=
DNSReply
(
None
)
DR_TIMEOUT_BIN
=
b
'
\xff\xff\xff\xff\x00\x00
'
DR_EMPTY_0
=
DNSReply
(
b
''
)
DR_EMPTY_0_BIN
=
b
'
\x00\x00\x00\x00\x00\x00
'
...
...
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