From e712d9fee2a04cdf9945fcbf6692911a36a77272 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 31 Jul 2013 11:40:11 -0700 Subject: [PATCH] Test that custom functions are live-reloaded Change-Id: Ie9cc0869729f3304b281e1700912f43d7e3ac70d --- ...unctions_live_reconfiguration_functions.py | 2 ++ ...layout-live-reconfiguration-functions.yaml | 34 +++++++++++++++++++ tests/test_scheduler.py | 30 ++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/fixtures/custom_functions_live_reconfiguration_functions.py create mode 100644 tests/fixtures/layout-live-reconfiguration-functions.yaml diff --git a/tests/fixtures/custom_functions_live_reconfiguration_functions.py b/tests/fixtures/custom_functions_live_reconfiguration_functions.py new file mode 100644 index 0000000000..d8e06f4305 --- /dev/null +++ b/tests/fixtures/custom_functions_live_reconfiguration_functions.py @@ -0,0 +1,2 @@ +def select_debian_node(item, params): + params['ZUUL_NODE'] = 'wheezy' diff --git a/tests/fixtures/layout-live-reconfiguration-functions.yaml b/tests/fixtures/layout-live-reconfiguration-functions.yaml new file mode 100644 index 0000000000..f477a1250e --- /dev/null +++ b/tests/fixtures/layout-live-reconfiguration-functions.yaml @@ -0,0 +1,34 @@ +includes: + - python-file: custom_functions_live_reconfiguration_functions.py + +pipelines: + - name: gate + manager: DependentPipelineManager + failure-message: Build failed. For information on how to proceed, see http://wiki.example.org/Test_Failures + trigger: + gerrit: + - event: comment-added + approval: + - approved: 1 + success: + verified: 2 + submit: true + failure: + verified: -2 + start: + verified: 0 + precedence: high + +jobs: + - name: ^.*-merge$ + failure-message: Unable to merge change + hold-following-changes: true + - name: node-project-test1 + parameter-function: select_debian_node + +projects: + - name: org/node-project + gate: + - node-project-merge: + - node-project-test1 + - node-project-test2 diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index faace9d3ca..48baaeff97 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -2467,6 +2467,36 @@ class TestScheduler(testtools.TestCase): self.assertEqual(A.data['status'], 'MERGED') self.assertEqual(A.reported, 2) + def test_live_reconfiguration_functions(self): + "Test live reconfiguration with a custom function" + self.worker.registerFunction('build:node-project-test1:debian') + self.worker.registerFunction('build:node-project-test1:wheezy') + A = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'A') + A.addApproval('CRVW', 2) + self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) + self.waitUntilSettled() + + self.assertIsNone(self.getJobFromHistory('node-project-merge').node) + self.assertEqual(self.getJobFromHistory('node-project-test1').node, + 'debian') + self.assertIsNone(self.getJobFromHistory('node-project-test2').node) + + self.config.set('zuul', 'layout_config', + 'tests/fixtures/layout-live-' + 'reconfiguration-functions.yaml') + self.sched.reconfigure(self.config) + self.worker.build_history = [] + + B = self.fake_gerrit.addFakeChange('org/node-project', 'master', 'B') + B.addApproval('CRVW', 2) + self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) + self.waitUntilSettled() + + self.assertIsNone(self.getJobFromHistory('node-project-merge').node) + self.assertEqual(self.getJobFromHistory('node-project-test1').node, + 'wheezy') + self.assertIsNone(self.getJobFromHistory('node-project-test2').node) + def test_delayed_repo_init(self): self.config.set('zuul', 'layout_config', 'tests/fixtures/layout-delayed-repo-init.yaml')