Skip to content

Commit

Permalink
MAINT: Refactor test into own static method
Browse files Browse the repository at this point in the history
Slim down the override by moving checks into their own private static method
without changing the implementation.
  • Loading branch information
DavidFair committed Dec 4, 2024
1 parent 8a8cfcf commit 8849346
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import logging
from dataclasses import dataclass
from typing import Dict, Optional
from typing import Dict, Optional, Union

from mashumaro import DataClassDictMixin
from mashumaro.config import BaseConfig
Expand Down Expand Up @@ -58,20 +58,27 @@ def override_from_vm_meta(self, vm_meta: Dict[str, str]):
if alias not in vm_meta:
continue

if not vm_meta[alias]:
logger.warning(
"Empty value found for metadata property: '%s'",
alias,
)
continue

user_val = vm_meta[alias].lower().strip()
if user_val in _INVALID_VALUES:
if not self._is_metadata_val_valid(vm_meta[alias]):
logger.warning(
"Invalid metadata value '%s' found for metadata property '%s', skipping",
user_val,
vm_meta[alias],
alias,
)
continue

setattr(self, attr, vm_meta[alias])

@staticmethod
def _is_metadata_val_valid(val: Union[str, None]) -> bool:
"""
Tests if an individual metadata value is sane, i.e.
a str which is not null, or a blocked value.
If this is valid, it returns true
"""
if not val:
return False

user_val = val.lower().strip()
if user_val in _INVALID_VALUES:
return False
return True

0 comments on commit 8849346

Please sign in to comment.