~pieq/checkbox/add-30suspend-1reboot-cycles-support

« back to all changes in this revision

Viewing changes to plainbox/plainbox/impl/unit/test_job.py

  • Committer: Zygmunt Krynicki
  • Date: 2015-09-25 07:28:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4028.
  • Revision ID: zygmunt.krynicki@canonical.com-20150925072831-6l14ydn1ghivt7de
plainbox: add support for 'after' constraint

This patch adds the 'after' ordering constraint. It is exactly the same
as 'depends' but unlike it, it will not inhibit a job from running if
the other job runs but fails (or crashes). It is especially useful for
enforcing the order on a pair of jobs where the job that runs second can
collect the log files or the system state after the execution of the
first job.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
578
578
            issue_list, self.unit_cls.Meta.fields.depends,
579
579
            Problem.bad_reference, Severity.error, message)
580
580
 
 
581
    def test_after__untranslatable(self):
 
582
        issue_list = self.unit_cls({
 
583
            '_after': 'after'
 
584
        }, provider=self.provider).check()
 
585
        self.assertIssueFound(
 
586
            issue_list, self.unit_cls.Meta.fields.after,
 
587
            Problem.unexpected_i18n, Severity.warning)
 
588
 
 
589
    def test_after__refers_to_other_units(self):
 
590
        unit = self.unit_cls({
 
591
            'after': 'some-unit'
 
592
        }, provider=self.provider)
 
593
        message = "field 'after', unit 'ns::some-unit' is not available"
 
594
        self.provider.unit_list = [unit]
 
595
        context = UnitValidationContext([self.provider])
 
596
        issue_list = unit.check(context=context)
 
597
        self.assertIssueFound(
 
598
            issue_list, self.unit_cls.Meta.fields.after,
 
599
            Problem.bad_reference, Severity.error, message)
 
600
 
 
601
    def test_after__refers_to_other_jobs(self):
 
602
        other_unit = UnitWithId({
 
603
            'id': 'some-unit'
 
604
        }, provider=self.provider)
 
605
        unit = self.unit_cls({
 
606
            'after': 'some-unit'
 
607
        }, provider=self.provider)
 
608
        message = "field 'after', the referenced unit is not a job"
 
609
        self.provider.unit_list = [unit, other_unit]
 
610
        context = UnitValidationContext([self.provider])
 
611
        issue_list = unit.check(context=context)
 
612
        self.assertIssueFound(
 
613
            issue_list, self.unit_cls.Meta.fields.after,
 
614
            Problem.bad_reference, Severity.error, message)
 
615
 
581
616
    def test_requires__untranslatable(self):
582
617
        issue_list = self.unit_cls({
583
618
            '_requires': 'requires'