ignore nodes already scheduled for re-imaging in outdated check (#341)

If a node is already scheduled to be reimaged/deleted, we should not bother checking if it's outdated.
This commit is contained in:
bmc-msft
2020-11-30 12:36:15 -05:00
committed by GitHub
parent 2391d927f7
commit 30cc5d4778
2 changed files with 13 additions and 1 deletions

View File

@ -46,6 +46,7 @@ from .updates import queue_update
A = TypeVar("A", bound="ORMMixin") A = TypeVar("A", bound="ORMMixin")
QUERY_VALUE_TYPES = Union[ QUERY_VALUE_TYPES = Union[
List[bool],
List[int], List[int],
List[str], List[str],
List[UUID], List[UUID],
@ -135,6 +136,12 @@ def build_filters(
field_name = field field_name = field
parts: Optional[List[str]] = None parts: Optional[List[str]] = None
if isinstance(values[0], bool):
parts = []
for x in values:
if not isinstance(x, bool):
raise TypeError("unexpected type")
parts.append("%s eq %s" % (field_name, str(x).lower))
if isinstance(values[0], int): if isinstance(values[0], int):
parts = [] parts = []
for x in values: for x in values:

View File

@ -99,6 +99,7 @@ class Node(BASE_NODE, ORMMixin):
scaleset_id: Optional[UUID] = None, scaleset_id: Optional[UUID] = None,
states: Optional[List[NodeState]] = None, states: Optional[List[NodeState]] = None,
pool_name: Optional[str] = None, pool_name: Optional[str] = None,
exclude_update_scheduled: bool = False,
) -> List["Node"]: ) -> List["Node"]:
query: QueryFilter = {} query: QueryFilter = {}
if scaleset_id: if scaleset_id:
@ -108,6 +109,10 @@ class Node(BASE_NODE, ORMMixin):
if pool_name: if pool_name:
query["pool_name"] = [pool_name] query["pool_name"] = [pool_name]
if exclude_update_scheduled:
query["reimage_requested"] = [False]
query["delete_requested"] = [False]
# azure table query always return false when the column does not exist # azure table query always return false when the column does not exist
# We write the query this way to allow us to get the nodes where the # We write the query this way to allow us to get the nodes where the
# version is not defined as well as the nodes with a mismatched version # version is not defined as well as the nodes with a mismatched version
@ -116,7 +121,7 @@ class Node(BASE_NODE, ORMMixin):
@classmethod @classmethod
def mark_outdated_nodes(cls) -> None: def mark_outdated_nodes(cls) -> None:
outdated = cls.search_outdated() outdated = cls.search_outdated(exclude_update_scheduled=True)
for node in outdated: for node in outdated:
logging.info( logging.info(
"node is outdated: %s - node_version:%s api_version:%s", "node is outdated: %s - node_version:%s api_version:%s",