Merge ~sylvain-pineau/checkbox-ng:fail_valiadtion_on_missing_nested_parts into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Work in progress
Proposed branch: ~sylvain-pineau/checkbox-ng:fail_valiadtion_on_missing_nested_parts
Merge into: checkbox-ng:master
Diff against target: 130 lines (+40/-10)
1 file modified
plainbox/impl/unit/testplan.py (+40/-10)
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+412142@code.launchpad.net

Description of the change

This patch makes manage.py validate failing if one of the nested part is not found. The current behavior is just logging warnings.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Does not play nicely with the sru provider and the missing pts testplan

Unmerged commits

44188d7... by Sylvain Pineau

Change: nested parts not found are now failing validation

test plan ids not found while performing a validation in context are now
causing the ./manage.py validate command to fail.
(instead of just logging warnings).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/plainbox/impl/unit/testplan.py b/plainbox/impl/unit/testplan.py
index 96b5c9a..f209ae9 100644
--- a/plainbox/impl/unit/testplan.py
+++ b/plainbox/impl/unit/testplan.py
@@ -129,6 +129,26 @@ class NoBaseIncludeValidator(FieldValidatorBase):
129 raise NotImplementedError129 raise NotImplementedError
130130
131131
132class NestedPartReferenceValidator(FieldValidatorBase):
133 """
134 Validator that checks if nested parts identifiers are valid test plans
135
136 """
137
138 def check_in_context(self, parent, unit, field, context):
139 id_map = context.compute_shared(
140 "field_value_map[id]", compute_value_map, context, 'id')
141 value_list, problems = unit.get_nested_part()
142 for unit_id in problems:
143 if unit_id not in id_map:
144 yield parent.error(
145 unit, field, Problem.bad_reference,
146 self.message or _(
147 "test plan {!a} is not available"
148 ).format(unit_id))
149 continue
150
151
132class TestPlanUnit(UnitWithId):152class TestPlanUnit(UnitWithId):
133 """153 """
134 Test plan class154 Test plan class
@@ -279,7 +299,8 @@ class TestPlanUnit(UnitWithId):
279 "unable to parse bootstrap_include: %s"), node.msg)299 "unable to parse bootstrap_include: %s"), node.msg)
280300
281 V().visit(WordList.parse(self.bootstrap_include))301 V().visit(WordList.parse(self.bootstrap_include))
282 for tp_unit in self.get_nested_part():302 tp_units, problems = self.get_nested_part()
303 for tp_unit in tp_units:
283 job_ids.extend(tp_unit.get_bootstrap_job_ids())304 job_ids.extend(tp_unit.get_bootstrap_job_ids())
284 return job_ids305 return job_ids
285306
@@ -287,6 +308,7 @@ class TestPlanUnit(UnitWithId):
287 def get_nested_part(self):308 def get_nested_part(self):
288 """Compute and return a set of test plan ids from nested_part field."""309 """Compute and return a set of test plan ids from nested_part field."""
289 nested_parts = []310 nested_parts = []
311 problems = []
290 if self.nested_part is not None:312 if self.nested_part is not None:
291 from plainbox.impl.session import SessionManager313 from plainbox.impl.session import SessionManager
292 with SessionManager.get_throwaway_manager(self.provider_list) as m:314 with SessionManager.get_throwaway_manager(self.provider_list) as m:
@@ -307,9 +329,8 @@ class TestPlanUnit(UnitWithId):
307 try:329 try:
308 nested_parts.append(context.get_unit(tp_id, 'test plan'))330 nested_parts.append(context.get_unit(tp_id, 'test plan'))
309 except KeyError:331 except KeyError:
310 logger.warning(_(332 problems.append(tp_id)
311 "unable to find nested part: %s"), tp_id)333 return nested_parts, problems
312 return nested_parts
313334
314 @instance_method_lru_cache(maxsize=None)335 @instance_method_lru_cache(maxsize=None)
315 def get_qualifier(self):336 def get_qualifier(self):
@@ -324,7 +345,8 @@ class TestPlanUnit(UnitWithId):
324 qual_list.extend(self._gen_qualifiers('include', self.include, True))345 qual_list.extend(self._gen_qualifiers('include', self.include, True))
325 qual_list.extend(self._gen_qualifiers('exclude', self.exclude, False))346 qual_list.extend(self._gen_qualifiers('exclude', self.exclude, False))
326 qual_list.extend([self.get_bootstrap_qualifier(excluding=True)])347 qual_list.extend([self.get_bootstrap_qualifier(excluding=True)])
327 for tp_unit in self.get_nested_part():348 tp_units, problems = self.get_nested_part()
349 for tp_unit in tp_units:
328 qual_list.extend([tp_unit.get_qualifier()])350 qual_list.extend([tp_unit.get_qualifier()])
329 return CompositeQualifier(qual_list)351 return CompositeQualifier(qual_list)
330352
@@ -340,7 +362,8 @@ class TestPlanUnit(UnitWithId):
340 qual_list = []362 qual_list = []
341 qual_list.extend(363 qual_list.extend(
342 self._gen_qualifiers('include', self.mandatory_include, True))364 self._gen_qualifiers('include', self.mandatory_include, True))
343 for tp_unit in self.get_nested_part():365 tp_units, problems = self.get_nested_part()
366 for tp_unit in tp_units:
344 qual_list.extend([tp_unit.get_mandatory_qualifier()])367 qual_list.extend([tp_unit.get_mandatory_qualifier()])
345 return CompositeQualifier(qual_list)368 return CompositeQualifier(qual_list)
346369
@@ -356,7 +379,8 @@ class TestPlanUnit(UnitWithId):
356 qual_list = [FieldQualifier(379 qual_list = [FieldQualifier(
357 'id', OperatorMatcher(operator.eq, target_id), field_origin,380 'id', OperatorMatcher(operator.eq, target_id), field_origin,
358 not excluding) for target_id in self.get_bootstrap_job_ids()]381 not excluding) for target_id in self.get_bootstrap_job_ids()]
359 for tp_unit in self.get_nested_part():382 tp_units, problems = self.get_nested_part()
383 for tp_unit in tp_units:
360 qual_list.extend([tp_unit.get_bootstrap_qualifier(excluding)])384 qual_list.extend([tp_unit.get_bootstrap_qualifier(excluding)])
361 return CompositeQualifier(qual_list)385 return CompositeQualifier(qual_list)
362386
@@ -577,6 +601,9 @@ class TestPlanUnit(UnitWithId):
577 fields.mandatory_include: [601 fields.mandatory_include: [
578 NoBaseIncludeValidator(),602 NoBaseIncludeValidator(),
579 ],603 ],
604 fields.nested_part: [
605 NestedPartReferenceValidator(),
606 ],
580 fields.bootstrap_include: [607 fields.bootstrap_include: [
581 concrete_validators.untranslatable,608 concrete_validators.untranslatable,
582 NoBaseIncludeValidator(),609 NoBaseIncludeValidator(),
@@ -784,7 +811,8 @@ PatternMatcher('^job-[x-z]$'), inclusive=False)])
784 override_list.append((pattern, 'category_id', category_id))811 override_list.append((pattern, 'category_id', category_id))
785812
786 V().visit(OverrideFieldList.parse(testplan.category_overrides))813 V().visit(OverrideFieldList.parse(testplan.category_overrides))
787 for tp_unit in testplan.get_nested_part():814 tp_units, problems = testplan.get_nested_part()
815 for tp_unit in tp_units:
788 override_list.extend(self._get_category_overrides(tp_unit))816 override_list.extend(self._get_category_overrides(tp_unit))
789 return override_list817 return override_list
790818
@@ -813,7 +841,8 @@ PatternMatcher('^job-[x-z]$'), inclusive=False)])
813841
814 V().visit(OverrideFieldList.parse(842 V().visit(OverrideFieldList.parse(
815 testplan.certification_status_overrides))843 testplan.certification_status_overrides))
816 for tp_unit in testplan.get_nested_part():844 tp_units, problems = testplan.get_nested_part()
845 for tp_unit in tp_units:
817 override_list.extend(self._get_blocker_status_overrides(tp_unit))846 override_list.extend(self._get_blocker_status_overrides(tp_unit))
818 return override_list847 return override_list
819848
@@ -843,6 +872,7 @@ PatternMatcher('^job-[x-z]$'), inclusive=False)])
843 override_list.append((pattern, field_value_list))872 override_list.append((pattern, field_value_list))
844873
845 V().visit(IncludeStmtList.parse(testplan.include))874 V().visit(IncludeStmtList.parse(testplan.include))
846 for tp_unit in testplan.get_nested_part():875 tp_units, problems = testplan.get_nested_part()
876 for tp_unit in tp_units:
847 override_list.extend(self._get_inline_overrides(tp_unit))877 override_list.extend(self._get_inline_overrides(tp_unit))
848 return override_list878 return override_list

Subscribers

People subscribed via source and target branches