mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-16 11:58:09 +00:00
Fixing VMSS Re-Image 7-Day Timer (#1616)
* Fixing VMSS Re-Image 7-Day Timer * Updating use of TimeStamp to created_at * Renaming. * Updating field name. * Removing test chagne. * Updating query to work if init_at entry does not exist yet. * Changing timer for testing. * Adding field comment. * Formatting models.py * Fixing where save is called. * Adidng logging. * Removing logging. Ready for merge. * Update src/pytypes/onefuzztypes/models.py Co-authored-by: Joe Ranweiler <joe@lemma.co> * Formatting. * Updating datetime. * Testing after datetime change. * Removing test. Co-authored-by: nharper285 <nharper285@gmail.com> Co-authored-by: Joe Ranweiler <joe@lemma.co>
This commit is contained in:
committed by
GitHub
parent
f374801d35
commit
6100191aaf
@ -3,6 +3,7 @@
|
|||||||
# Copyright (c) Microsoft Corporation.
|
# Copyright (c) Microsoft Corporation.
|
||||||
# Licensed under the MIT License.
|
# Licensed under the MIT License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional, cast
|
from typing import Optional, cast
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
@ -75,7 +76,9 @@ def on_state_update(
|
|||||||
# they send 'init' with reimage_requested, it's because the node was reimaged
|
# they send 'init' with reimage_requested, it's because the node was reimaged
|
||||||
# successfully.
|
# successfully.
|
||||||
node.reimage_requested = False
|
node.reimage_requested = False
|
||||||
|
node.initialized_at = datetime.datetime.now(datetime.timezone.utc)
|
||||||
node.set_state(state)
|
node.set_state(state)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
logging.info("node state update: %s from:%s to:%s", machine_id, node.state, state)
|
logging.info("node state update: %s from:%s to:%s", machine_id, node.state, state)
|
||||||
|
@ -35,7 +35,7 @@ from ..versions import is_minimum_version
|
|||||||
from .shrink_queue import ShrinkQueue
|
from .shrink_queue import ShrinkQueue
|
||||||
|
|
||||||
NODE_EXPIRATION_TIME: datetime.timedelta = datetime.timedelta(hours=1)
|
NODE_EXPIRATION_TIME: datetime.timedelta = datetime.timedelta(hours=1)
|
||||||
NODE_REIMAGE_TIME: datetime.timedelta = datetime.timedelta(days=7)
|
NODE_REIMAGE_TIME: datetime.timedelta = datetime.timedelta(days=6)
|
||||||
|
|
||||||
# Future work:
|
# Future work:
|
||||||
#
|
#
|
||||||
@ -367,8 +367,8 @@ class Node(BASE_NODE, ORMMixin):
|
|||||||
def is_too_old(self) -> bool:
|
def is_too_old(self) -> bool:
|
||||||
return (
|
return (
|
||||||
self.scaleset_id is not None
|
self.scaleset_id is not None
|
||||||
and self.timestamp is not None
|
and self.initialized_at is not None
|
||||||
and self.timestamp
|
and self.initialized_at
|
||||||
< datetime.datetime.now(datetime.timezone.utc) - NODE_REIMAGE_TIME
|
< datetime.datetime.now(datetime.timezone.utc) - NODE_REIMAGE_TIME
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -453,15 +453,18 @@ class Node(BASE_NODE, ORMMixin):
|
|||||||
reasonably up-to-date with OS patches without disrupting running
|
reasonably up-to-date with OS patches without disrupting running
|
||||||
fuzzing tasks with patch reboot cycles.
|
fuzzing tasks with patch reboot cycles.
|
||||||
"""
|
"""
|
||||||
time_filter = "Timestamp lt datetime'%s'" % (
|
time_filter = "not (initialized_at ge datetime'%s')" % (
|
||||||
(datetime.datetime.utcnow() - NODE_REIMAGE_TIME).isoformat()
|
(
|
||||||
|
datetime.datetime.now(datetime.timezone.utc) - NODE_REIMAGE_TIME
|
||||||
|
).isoformat()
|
||||||
)
|
)
|
||||||
for node in cls.search(
|
reimage_nodes = cls.search(
|
||||||
query={
|
query={
|
||||||
"scaleset_id": [scaleset_id],
|
"scaleset_id": [scaleset_id],
|
||||||
},
|
},
|
||||||
raw_unchecked_filter=time_filter,
|
raw_unchecked_filter=time_filter,
|
||||||
):
|
)
|
||||||
|
for node in reimage_nodes:
|
||||||
if node.debug_keep_node:
|
if node.debug_keep_node:
|
||||||
logging.info(
|
logging.info(
|
||||||
"removing debug_keep_node for expired node. "
|
"removing debug_keep_node for expired node. "
|
||||||
|
@ -568,6 +568,9 @@ class NodeCommandEnvelope(BaseModel):
|
|||||||
|
|
||||||
class Node(BaseModel):
|
class Node(BaseModel):
|
||||||
timestamp: Optional[datetime] = Field(alias="Timestamp")
|
timestamp: Optional[datetime] = Field(alias="Timestamp")
|
||||||
|
|
||||||
|
# Set only once, when a node is initialized.
|
||||||
|
initialized_at: Optional[datetime]
|
||||||
pool_name: PoolName
|
pool_name: PoolName
|
||||||
pool_id: Optional[UUID]
|
pool_id: Optional[UUID]
|
||||||
machine_id: UUID
|
machine_id: UUID
|
||||||
|
Reference in New Issue
Block a user