Skip to content
Snippets Groups Projects

update a4f for compatibility with Donnie/Oniro4OpenHarmony

Open Alberto Pianon requested to merge ap/donnie into master
@@ -17,8 +17,8 @@ class BBLayer(BaseModel):
def __init__(
self,
layer_path: str,
remote: Optional[str] = None,
revision: Optional[str] = None
remote: Optional[str] = None,
revision: Optional[str] = None
):
self.layer_path = layer_path
self.remote = remote
@@ -194,11 +194,11 @@ class PackageContainer(DictModel):
# generated in different local builds, but
# it doesn't matter here
],
exclude_regex_paths=[
r"root.package.files.files\[\d+\].sha256", # bin file checksums may depend on build host, adding this to ease migration to a new gitlab runner
r"root.package.files.files\[\d+\].size", # bin file sizes may depend on build host, adding this to ease migration to a new gitlab runner
r"root.package.chk_sum", # (as a consequence, we should ignore also package checksum)
]
exclude_regex_paths=[
r"root.package.files.files\[\d+\].sha256", # bin file checksums may depend on build host, adding this to ease migration to a new gitlab runner
r"root.package.files.files\[\d+\].size", # bin file sizes may depend on build host, adding this to ease migration to a new gitlab runner
r"root.package.chk_sum", # (as a consequence, we should ignore also package checksum)
]
)
if diff:
raise ModelError(
@@ -263,8 +263,8 @@ class RecipeMetaData(BaseModel):
class CveProduct(BaseModel):
def __init__(
self,
product: str,
cvesInRecord: str
product: str,
cvesInRecord: str
) -> None:
self.product = product
self.cvesInRecord = cvesInRecord
@@ -291,8 +291,8 @@ class CveIssue(BaseModel):
class RecipeCveMetaData(BaseModel):
def __init__(
self,
products: Optional[List[CveProduct]] = None,
issue: Optional[List[CveIssue]] = None,
products: Optional[List[CveProduct]] = None,
issue: Optional[List[CveIssue]] = None,
# FIXME backwards compatibility, remove in next version:
cve_version: Optional[str] = None,
cve_version_suffix: Optional[str] = None,
@@ -321,6 +321,60 @@ class Recipe(BaseModel):
self.layer = layer
self.chk_sum = chk_sum
class Anomaly(BaseModel):
def __init__(
self,
id: str,
severity: str,
type: str,
type_description: str,
comment: str,
source_package_id: str,
tags: List[str]
):
self.id = id
self.severity = severity
self.type = type
self.type_description = type_description
self.comment = comment
self.source_package_id = source_package_id
self.tags = tags
_TAnomalyContainer = TypeVar('_TAnomalyContainer', bound='AnomalyContainer')
class AnomalyContainer(DictModel):
subclass = Anomaly
@staticmethod
def merge(
old: Dict[str, _TAnomalyContainer],
new: Dict[str, _TAnomalyContainer]
) -> Dict[str, _TAnomalyContainer]:
res = {}
ids = set(list(old) + list(new))
for id in ids:
if id in new and id in old:
logger.debug(f"anomaly {id} found in new and old, merging")
diff = DeepDiff(
old[id],
new[id],
ignore_order=True,
exclude_paths=[ 'root.tags' ]
)
if diff:
raise ModelError(
f"can't merge anomaly {id}, because some fields"
f" mismatch, diff is: {diff}"
)
res[id] = deepcopy(new[id])
res[id].tags = list(set(old[id].tags + new[id].tags))
elif id in new and id not in old:
logger.debug(f"{id} found in new")
res[id] = new[id]
elif id not in new and id in old:
logger.debug(f"{id} found in old")
res[id] = old[id]
return res
_TContainer = TypeVar('_TContainer', bound='Container')
class Container(BaseModel):
@@ -329,10 +383,12 @@ class Container(BaseModel):
self,
recipe: Optional[Recipe] = None,
tags: Optional[List[str]] = None,
anomalies: Optional[Dict[str, Anomaly]] = None,
packages: Optional[Dict[str, PackageWithTags]] = None
) -> None:
self.recipe = Recipe.decode(recipe)
self.tags = tags
self.anomalies = AnomalyContainer.decode(anomalies)
self.packages = PackageContainer.decode(packages)
@staticmethod
@@ -358,10 +414,11 @@ class Container(BaseModel):
# (M): expected diffs that we want to merge
# (I): expected diffs that we can safely ignore (we keep the newer value)
# (U): undesirable diffs that however "happen", even if the recipe version and revision stay the same;
# we ignore them to avoid complications (we keep the newer value)
# we ignore them to avoid complications (we keep the newer value)
exclude_paths=[
"root.tags", # (M)
"root.packages", # (M)
"root.anomalies", # (M)
"root.recipe.metadata.description", # (U)
"root.recipe.metadata.homepage", # (U)
"root.recipe.metadata.summary", # (U)
@@ -391,6 +448,10 @@ class Container(BaseModel):
old[id].packages,
new[id].packages
)
res[id].anomalies = AnomalyContainer.merge(
old[id].anomalies,
new[id].anomalies
)
res[id].recipe.metadata = RecipeMetaData.merge(
old[id].recipe.metadata,
new[id].recipe.metadata
@@ -442,7 +503,7 @@ class TinfoilHatModel(DictModel):
return res
# FIXME: All merge methods here are based on one assumption:
# that the "new" tinfoilhat file is really newer than the "old"
# one, and that it containes more updated info than the "old" one.
# We should add some field ('project manifest commit date'?)
# tinfoilhat.json in order to check this
# that the "new" tinfoilhat file is really newer than the "old"
# one, and that it containes more updated info than the "old" one.
# We should add some field ('project manifest commit date'?)
# tinfoilhat.json in order to check this
Loading