Browse Source

Merge "Request child nodes of paused jobs at higher priority"

tags/3.6.0
Zuul 2 months ago
parent
commit
f4793a1df4

+ 17
- 0
tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml View File

@@ -0,0 +1,17 @@
1
+- pipeline:
2
+    name: check
3
+    manager: independent
4
+    post-review: true
5
+    trigger:
6
+      gerrit:
7
+        - event: patchset-created
8
+    success:
9
+      gerrit:
10
+        Verified: 1
11
+    failure:
12
+      gerrit:
13
+        Verified: -1
14
+
15
+- job:
16
+    name: base
17
+    parent: null

+ 1
- 0
tests/fixtures/config/job-pause-priority/git/org_project/README View File

@@ -0,0 +1 @@
1
+test

+ 7
- 0
tests/fixtures/config/job-pause-priority/git/org_project/playbooks/compile.yaml View File

@@ -0,0 +1,7 @@
1
+- hosts: all
2
+  tasks:
3
+    - name: Pause and let child run
4
+      zuul_return:
5
+        data:
6
+          zuul:
7
+            pause: true

+ 2
- 0
tests/fixtures/config/job-pause-priority/git/org_project/playbooks/test.yaml View File

@@ -0,0 +1,2 @@
1
+- hosts: all
2
+  tasks: []

+ 23
- 0
tests/fixtures/config/job-pause-priority/git/org_project/zuul.yaml View File

@@ -0,0 +1,23 @@
1
+- job:
2
+    name: compile
3
+    run: playbooks/compile.yaml
4
+    nodeset:
5
+      nodes:
6
+        - name: compile_node
7
+          label: compile_label
8
+
9
+- job:
10
+    name: test
11
+    run: playbooks/test.yaml
12
+    nodeset:
13
+      nodes:
14
+        - name: test_node
15
+          label: test_label
16
+
17
+- project:
18
+    check:
19
+      jobs:
20
+        - compile
21
+        - test:
22
+            dependencies:
23
+              - compile

+ 7
- 0
tests/fixtures/config/job-pause-priority/main.yaml View File

@@ -0,0 +1,7 @@
1
+- tenant:
2
+    name: tenant-one
3
+    source:
4
+      gerrit:
5
+        config-projects:
6
+          - common-config
7
+          - org/project

+ 37
- 1
tests/unit/test_v3.py View File

@@ -31,6 +31,7 @@ from tests.base import (
31 31
     ZuulDBTestCase,
32 32
     FIXTURE_DIR,
33 33
     simple_layout,
34
+    iterate_timeout,
34 35
 )
35 36
 
36 37
 
@@ -4637,7 +4638,7 @@ class TestJobPause(AnsibleZuulTestCase):
4637 4638
         self.executor_server.verbose = True
4638 4639
 
4639 4640
         # Second node request should fail
4640
-        fail = {'_oid': '200-0000000001'}
4641
+        fail = {'_oid': '199-0000000001'}
4641 4642
         self.fake_nodepool.addFailRequest(fail)
4642 4643
 
4643 4644
         A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
@@ -5101,3 +5102,38 @@ class TestForceMergeMissingTemplate(ZuulTestCase):
5101 5102
         self.assertHistory([
5102 5103
             dict(name='other-job', result='SUCCESS', changes='2,1'),
5103 5104
         ])
5105
+
5106
+
5107
+class TestJobPausePriority(AnsibleZuulTestCase):
5108
+    tenant_config_file = 'config/job-pause-priority/main.yaml'
5109
+
5110
+    def test_paused_job_priority(self):
5111
+        "Test that nodes for children of paused jobs have a higher priority"
5112
+
5113
+        self.fake_nodepool.pause()
5114
+        self.executor_server.hold_jobs_in_build = True
5115
+
5116
+        A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
5117
+        self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
5118
+        self.waitUntilSettled()
5119
+
5120
+        reqs = self.fake_nodepool.getNodeRequests()
5121
+        self.assertEqual(len(reqs), 1)
5122
+        self.assertEqual(reqs[0]['_oid'], '200-0000000000')
5123
+
5124
+        self.fake_nodepool.unpause()
5125
+        self.waitUntilSettled()
5126
+        self.fake_nodepool.pause()
5127
+        self.executor_server.hold_jobs_in_build = False
5128
+        self.executor_server.release()
5129
+
5130
+        for x in iterate_timeout(60, 'paused job'):
5131
+            reqs = self.fake_nodepool.getNodeRequests()
5132
+            if reqs:
5133
+                break
5134
+
5135
+        self.assertEqual(len(reqs), 1)
5136
+        self.assertEqual(reqs[0]['_oid'], '199-0000000001')
5137
+
5138
+        self.fake_nodepool.unpause()
5139
+        self.waitUntilSettled()

+ 10
- 1
zuul/model.py View File

@@ -723,11 +723,20 @@ class NodeRequest(object):
723 723
 
724 724
     @property
725 725
     def priority(self):
726
+        precedence_adjustment = 0
726 727
         if self.build_set:
727 728
             precedence = self.build_set.item.pipeline.precedence
729
+            job_graph = self.build_set.item.job_graph
730
+            if job_graph:
731
+                for parent in job_graph.getParentJobsRecursively(
732
+                    self.job.name):
733
+                    build = self.build_set.getBuild(parent.name)
734
+                    if build.paused:
735
+                        precedence_adjustment = -1
728 736
         else:
729 737
             precedence = PRECEDENCE_NORMAL
730
-        return PRIORITY_MAP[precedence]
738
+        initial_precedence = PRIORITY_MAP[precedence]
739
+        return max(0, initial_precedence + precedence_adjustment)
731 740
 
732 741
     @property
733 742
     def fulfilled(self):

Loading…
Cancel
Save