summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-02-28 11:10:51 +0000
committerGerrit Code Review <review@openstack.org>2019-02-28 11:10:51 +0000
commitf4793a1df47507ec7c445f84952c0b87b1547298 (patch)
treeaa4793640495671f1fc32000a044c43b3ff265ff
parent62e0c131908298a36689b045638d04de35ebaac7 (diff)
parent8e09a758cf953bc7fdc9f46c70465b671d7cbd1e (diff)
Merge "Request child nodes of paused jobs at higher priority"
-rw-r--r--tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml17
-rw-r--r--tests/fixtures/config/job-pause-priority/git/org_project/README1
-rw-r--r--tests/fixtures/config/job-pause-priority/git/org_project/playbooks/compile.yaml7
-rw-r--r--tests/fixtures/config/job-pause-priority/git/org_project/playbooks/test.yaml2
-rw-r--r--tests/fixtures/config/job-pause-priority/git/org_project/zuul.yaml23
-rw-r--r--tests/fixtures/config/job-pause-priority/main.yaml7
-rw-r--r--tests/unit/test_v3.py38
-rw-r--r--zuul/model.py11
8 files changed, 104 insertions, 2 deletions
diff --git a/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml b/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml
new file mode 100644
index 0000000..a07342e
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/git/common-config/zuul.yaml
@@ -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
diff --git a/tests/fixtures/config/job-pause-priority/git/org_project/README b/tests/fixtures/config/job-pause-priority/git/org_project/README
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/git/org_project/README
@@ -0,0 +1 @@
test
diff --git a/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/compile.yaml b/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/compile.yaml
new file mode 100644
index 0000000..9d6f2da
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/compile.yaml
@@ -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
diff --git a/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/test.yaml b/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/test.yaml
new file mode 100644
index 0000000..f679dce
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/git/org_project/playbooks/test.yaml
@@ -0,0 +1,2 @@
1- hosts: all
2 tasks: []
diff --git a/tests/fixtures/config/job-pause-priority/git/org_project/zuul.yaml b/tests/fixtures/config/job-pause-priority/git/org_project/zuul.yaml
new file mode 100644
index 0000000..854b083
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/git/org_project/zuul.yaml
@@ -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
diff --git a/tests/fixtures/config/job-pause-priority/main.yaml b/tests/fixtures/config/job-pause-priority/main.yaml
new file mode 100644
index 0000000..a213015
--- /dev/null
+++ b/tests/fixtures/config/job-pause-priority/main.yaml
@@ -0,0 +1,7 @@
1- tenant:
2 name: tenant-one
3 source:
4 gerrit:
5 config-projects:
6 - common-config
7 - org/project
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 7c45a02..955a344 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -31,6 +31,7 @@ from tests.base import (
31 ZuulDBTestCase, 31 ZuulDBTestCase,
32 FIXTURE_DIR, 32 FIXTURE_DIR,
33 simple_layout, 33 simple_layout,
34 iterate_timeout,
34) 35)
35 36
36 37
@@ -4637,7 +4638,7 @@ class TestJobPause(AnsibleZuulTestCase):
4637 self.executor_server.verbose = True 4638 self.executor_server.verbose = True
4638 4639
4639 # Second node request should fail 4640 # Second node request should fail
4640 fail = {'_oid': '200-0000000001'} 4641 fail = {'_oid': '199-0000000001'}
4641 self.fake_nodepool.addFailRequest(fail) 4642 self.fake_nodepool.addFailRequest(fail)
4642 4643
4643 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A') 4644 A = self.fake_gerrit.addFakeChange('org/project2', 'master', 'A')
@@ -5101,3 +5102,38 @@ class TestForceMergeMissingTemplate(ZuulTestCase):
5101 self.assertHistory([ 5102 self.assertHistory([
5102 dict(name='other-job', result='SUCCESS', changes='2,1'), 5103 dict(name='other-job', result='SUCCESS', changes='2,1'),
5103 ]) 5104 ])
5105
5106
5107class 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()
diff --git a/zuul/model.py b/zuul/model.py
index 89a6e5c..7d84927 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -723,11 +723,20 @@ class NodeRequest(object):
723 723
724 @property 724 @property
725 def priority(self): 725 def priority(self):
726 precedence_adjustment = 0
726 if self.build_set: 727 if self.build_set:
727 precedence = self.build_set.item.pipeline.precedence 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 else: 736 else:
729 precedence = PRECEDENCE_NORMAL 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 @property 741 @property
733 def fulfilled(self): 742 def fulfilled(self):