Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FUSS
fuss-manager
Commits
6cd1c7ad
Commit
6cd1c7ad
authored
Aug 19, 2020
by
Elena Grandi
Browse files
Fix loading of machine data when the timestamp is earlier than the current state
parent
0a722e07
Changes
2
Hide whitespace changes
Inline
Side-by-side
manager/stores.py
View file @
6cd1c7ad
...
...
@@ -127,15 +127,19 @@ class Machine:
(old value, new value).
"""
changes
=
{}
if
self
.
last_seen
<
evt
.
timestamp
:
changes
[
"last_seen"
]
=
(
self
.
last_seen
,
evt
.
timestamp
)
self
.
last_seen
=
evt
.
timestamp
else
:
# If the event has an older timestamp than the machine,
# ignore it
return
{}
if
evt
.
ip
is
not
None
and
self
.
ip
!=
evt
.
ip
:
changes
[
"ip"
]
=
(
self
.
ip
,
evt
.
ip
)
self
.
ip
=
evt
.
ip
if
evt
.
name
is
not
None
and
self
.
name
!=
evt
.
name
:
changes
[
"name"
]
=
(
self
.
name
,
evt
.
name
)
self
.
name
=
evt
.
name
if
self
.
last_seen
<
evt
.
timestamp
:
changes
[
"last_seen"
]
=
(
self
.
last_seen
,
evt
.
timestamp
)
self
.
last_seen
=
evt
.
timestamp
if
evt
.
registered
is
not
None
and
self
.
registered
!=
evt
.
registered
:
changes
[
"registered"
]
=
(
self
.
registered
,
evt
.
registered
)
self
.
registered
=
evt
.
registered
...
...
tests/test_store.py
View file @
6cd1c7ad
...
...
@@ -228,13 +228,21 @@ class TestMockMachineStore(AsyncTestCase):
@
gen_test
async
def
test_add_machine_earlier_timestamp
(
self
):
mac
=
self
.
machine
[
'mac'
]
gathered
=
await
self
.
post_host_seen
(
mac
=
mac
,
timestamp
=
100
)
gathered
=
await
self
.
post_host_seen
(
mac
=
mac
,
timestamp
=
100
,
ip
=
self
.
machine
[
'ip'
])
self
.
assertIsInstance
(
gathered
[
0
],
events
.
HostSeenEvent
)
self
.
assertIsInstance
(
gathered
[
1
],
events
.
HostNewEvent
)
self
.
assertEqual
(
self
.
store
.
machines
[
mac
].
last_seen
,
100
)
# HostSeen with an earlier timestamp generates no changes
gathered
=
await
self
.
post_host_seen
(
mac
=
mac
,
timestamp
=
80
)
# HostSeen with an earlier timestamp generates no changes, even
# if the ip has changed
gathered
=
await
self
.
post_host_seen
(
mac
=
mac
,
timestamp
=
80
,
ip
=
'192.168.6.101'
)
self
.
assertNotEqual
(
self
.
machine
[
'ip'
],
'192.168.6.101'
)
self
.
assertIsInstance
(
gathered
[
0
],
events
.
HostSeenEvent
)
self
.
assertEqual
(
len
(
gathered
),
1
)
self
.
assertIn
(
mac
,
self
.
store
.
machines
)
...
...
@@ -248,7 +256,7 @@ class TestMockMachineStore(AsyncTestCase):
self
.
assertIsInstance
(
gathered
[
1
],
events
.
HostNewEvent
)
self
.
assertEqual
(
self
.
store
.
machines
[
mac
].
last_seen
,
100
)
# HostSeen with a
n earli
er timestamp generates no changes
# HostSeen with a
lat
er timestamp generates no changes
gathered
=
await
self
.
post_host_seen
(
mac
=
mac
,
timestamp
=
200
)
self
.
assertIsInstance
(
gathered
[
0
],
events
.
HostSeenEvent
)
self
.
assertIsInstance
(
gathered
[
1
],
events
.
HostChangedEvent
)
...
...
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