diff --git a/doc/source/installation.rst b/doc/source/installation.rst index abc022992..f2ba12812 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -11,6 +11,25 @@ systems, including Jenkins. If you use Puppet, you can use the __ https://github.com/openstack-infra/config/tree/master/modules/jenkins +Documentation +------------- + +Documentation have been included and are in the 'doc' folder. To generate docs +locally execute the command:: + + tox -e venv -- python setup.py build_sphinx + +Unit Tests +---------- + +Unit tests have been included and are in the 'tests' folder. We recently +started including unit tests as examples in our documentation so to keep the +examples up to date it is very important that we include a unit tests for +every module. You can run the unit tests by execute the command:: + + tox -epy27 + +*Note - view tox.ini to run test on other versions of python Configuration File ------------------ @@ -54,15 +73,18 @@ Usage ^^^^^ .. program-output:: jenkins-jobs --help -Testing -^^^^^^^ -Once you have a configuration defined, you can test it with:: +Testing JJB +^^^^^^^^^^^ +Once you have a configuration defined, you can test the job builder by running:: jenkins-jobs test /path/to/config -o /path/to/output That will write XML files to the output directory for all of the jobs -defined in the configuration directory. When you're satisfied, you -can run:: +defined in the configuration directory. + +Updating Jenkins +^^^^^^^^^^^^^^^^ +When you're satisfied with the generated xml from the test, you can run:: jenkins-jobs update /path/to/config diff --git a/jenkins_jobs/modules/notifications.py b/jenkins_jobs/modules/notifications.py index bb03c7cf9..d208930bc 100644 --- a/jenkins_jobs/modules/notifications.py +++ b/jenkins_jobs/modules/notifications.py @@ -49,7 +49,7 @@ def http_endpoint(parser, xml_parent, data): notifications: - http: - url: http://example.com/jenkins_endpoint + url: http://example.com/jenkins_endpoint """ endpoint_element = XML.SubElement(xml_parent, 'com.tikal.hudson.plugins.notification.' diff --git a/tests/builders/__init__.py b/tests/builders/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/builders/fixtures/trigger-builds001.xml b/tests/builders/fixtures/trigger-builds001.xml new file mode 100644 index 000000000..5afabc731 --- /dev/null +++ b/tests/builders/fixtures/trigger-builds001.xml @@ -0,0 +1,37 @@ + + + + + + + + + FOO="bar" + + + build_started + ALWAYS + false + false + + + FAILURE + 2 + RED + + + UNSTABLE + 1 + Yellow + + + FAILURE + 2 + RED + + + + + + + diff --git a/tests/builders/fixtures/trigger-builds001.yaml b/tests/builders/fixtures/trigger-builds001.yaml new file mode 100644 index 000000000..92cc2fd71 --- /dev/null +++ b/tests/builders/fixtures/trigger-builds001.yaml @@ -0,0 +1,6 @@ +builders: + - trigger-builds: + - project: "build_started" + predefined-parameters: + FOO="bar" + block: true \ No newline at end of file diff --git a/tests/builders/test_builders.py b/tests/builders/test_builders.py new file mode 100644 index 000000000..fa5115bf5 --- /dev/null +++ b/tests/builders/test_builders.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testtools import TestCase +from testscenarios.testcase import TestWithScenarios +from jenkins_jobs.modules import builders +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleBuilders(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = builders.Builders diff --git a/tests/general/test_general.py b/tests/general/test_general.py index 6ff848458..17c31c2ee 100644 --- a/tests/general/test_general.py +++ b/tests/general/test_general.py @@ -1,3 +1,20 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + import os from testtools import TestCase from testscenarios.testcase import TestWithScenarios diff --git a/tests/notifications/__init__.py b/tests/notifications/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/notifications/fixtures/http-endpoint001.xml b/tests/notifications/fixtures/http-endpoint001.xml new file mode 100644 index 000000000..cc3ddc18e --- /dev/null +++ b/tests/notifications/fixtures/http-endpoint001.xml @@ -0,0 +1,13 @@ + + + + + + + HTTP + http://example.com/jenkins_endpoint + + + + + diff --git a/tests/notifications/fixtures/http-endpoint001.yaml b/tests/notifications/fixtures/http-endpoint001.yaml new file mode 100644 index 000000000..8c14e54fe --- /dev/null +++ b/tests/notifications/fixtures/http-endpoint001.yaml @@ -0,0 +1,3 @@ +notifications: + - http: + url: http://example.com/jenkins_endpoint \ No newline at end of file diff --git a/tests/notifications/test_notifications.py b/tests/notifications/test_notifications.py new file mode 100644 index 000000000..13fd32e44 --- /dev/null +++ b/tests/notifications/test_notifications.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testtools import TestCase +from testscenarios.testcase import TestWithScenarios +from jenkins_jobs.modules import notifications +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleNotifications(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = notifications.Notifications diff --git a/tests/parameters/__init__.py b/tests/parameters/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/parameters/fixtures/dynamic-choice-param001.xml b/tests/parameters/fixtures/dynamic-choice-param001.xml new file mode 100644 index 000000000..7220a733a --- /dev/null +++ b/tests/parameters/fixtures/dynamic-choice-param001.xml @@ -0,0 +1,26 @@ + + + + + + + OPTIONS + Available options + <__remote>false + <__script>['optionA', 'optionB'] + <__localBaseDirectory serialization="custom"> + + + /var/lib/jenkins/dynamic_parameter/classpath + + true + + + <__remoteBaseDirectory>dynamic_parameter_classpath + <__classPath/> + false + + + + + diff --git a/tests/parameters/fixtures/dynamic-choice-param001.yaml b/tests/parameters/fixtures/dynamic-choice-param001.yaml new file mode 100644 index 000000000..25ae90fd0 --- /dev/null +++ b/tests/parameters/fixtures/dynamic-choice-param001.yaml @@ -0,0 +1,7 @@ +parameters: + - dynamic-choice: + name: OPTIONS + description: "Available options" + script: "['optionA', 'optionB']" + remote: false + read-only: false \ No newline at end of file diff --git a/tests/parameters/test_parameters.py b/tests/parameters/test_parameters.py new file mode 100644 index 000000000..11ff0f0e4 --- /dev/null +++ b/tests/parameters/test_parameters.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testscenarios.testcase import TestWithScenarios +from testtools import TestCase +from jenkins_jobs.modules import parameters +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleParameters(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = parameters.Parameters diff --git a/tests/properties/__init__.py b/tests/properties/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/properties/fixtures/throttle001.xml b/tests/properties/fixtures/throttle001.xml new file mode 100644 index 000000000..de321a371 --- /dev/null +++ b/tests/properties/fixtures/throttle001.xml @@ -0,0 +1,16 @@ + + + + + 0 + 4 + true + + cat1 + cat2 + + + 1 + + + diff --git a/tests/properties/fixtures/throttle001.yaml b/tests/properties/fixtures/throttle001.yaml new file mode 100644 index 000000000..1fb6a063f --- /dev/null +++ b/tests/properties/fixtures/throttle001.yaml @@ -0,0 +1,6 @@ +properties: + - throttle: + max-total: 4 + categories: + - cat1 + - cat2 diff --git a/tests/properties/test_properties.py b/tests/properties/test_properties.py new file mode 100644 index 000000000..f601601aa --- /dev/null +++ b/tests/properties/test_properties.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testtools import TestCase +from testscenarios.testcase import TestWithScenarios +from jenkins_jobs.modules import properties +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleProperties(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = properties.Properties diff --git a/tests/publishers/test_publishers.py b/tests/publishers/test_publishers.py index 67fdc2ba2..f35a9a789 100644 --- a/tests/publishers/test_publishers.py +++ b/tests/publishers/test_publishers.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Joint copyright: # - Copyright 2012,2013 Wikimedia Foundation # - Copyright 2012,2013 Antoine "hashar" Musso @@ -24,7 +22,7 @@ from jenkins_jobs.modules import publishers from tests.base import get_scenarios, BaseTestCase -class TestCaseModulePublisher(TestWithScenarios, TestCase, BaseTestCase): +class TestCaseModulePublishers(TestWithScenarios, TestCase, BaseTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') scenarios = get_scenarios(fixtures_path) klass = publishers.Publishers diff --git a/tests/scm/fixtures/repo001.xml b/tests/scm/fixtures/repo001.xml new file mode 100644 index 000000000..bed34c01b --- /dev/null +++ b/tests/scm/fixtures/repo001.xml @@ -0,0 +1,15 @@ + + + + https://example.com/project/ + stable + repo.xml + drivers + build + https://internal.net/projects/repo + ~/git/project/ + 3 + false + false + + diff --git a/tests/scm/fixtures/repo001.yaml b/tests/scm/fixtures/repo001.yaml new file mode 100644 index 000000000..40df65a7b --- /dev/null +++ b/tests/scm/fixtures/repo001.yaml @@ -0,0 +1,12 @@ +scm: + - repo: + manifest-url: https://example.com/project/ + manifest-branch: stable + manifest-file: repo.xml + manifest-group: drivers + destination-dir: build + repo-url: https://internal.net/projects/repo + mirror-dir: ~/git/project/ + jobs: 3 + current-branch: false + quiet: false diff --git a/tests/scm/test_scm.py b/tests/scm/test_scm.py index f9eecef25..8125e83f1 100644 --- a/tests/scm/test_scm.py +++ b/tests/scm/test_scm.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Joint copyright: # - Copyright 2012,2013 Wikimedia Foundation # - Copyright 2012,2013 Antoine "hashar" Musso @@ -18,13 +16,13 @@ # under the License. import os -from testscenarios.testcase import TestWithScenarios from testtools import TestCase +from testscenarios.testcase import TestWithScenarios from jenkins_jobs.modules import scm from tests.base import get_scenarios, BaseTestCase -class TestCaseModuleScm(TestWithScenarios, TestCase, BaseTestCase): +class TestCaseModuleSCM(TestWithScenarios, TestCase, BaseTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') scenarios = get_scenarios(fixtures_path) klass = scm.SCM diff --git a/tests/triggers/__init__.py b/tests/triggers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/triggers/fixtures/gerrit001.xml b/tests/triggers/fixtures/gerrit001.xml new file mode 100644 index 000000000..53fadaaef --- /dev/null +++ b/tests/triggers/fixtures/gerrit001.xml @@ -0,0 +1,48 @@ + + + + + + + + PLAIN + test-project + + + ANT + ** + + + + + ANT + subdirectory/** + + + + + + true + true + true + true + + false + false + false + True + http://myhost/mytrigger + + + APRV + 1 + + + + + + + + + + diff --git a/tests/triggers/fixtures/gerrit001.yaml b/tests/triggers/fixtures/gerrit001.yaml new file mode 100644 index 000000000..e93c4b030 --- /dev/null +++ b/tests/triggers/fixtures/gerrit001.yaml @@ -0,0 +1,23 @@ +triggers: + - gerrit: + trigger-on-comment-added-event: true + trigger-approval-category: 'APRV' + trigger-approval-value: 1 + projects: + - project-compare-type: 'PLAIN' + project-pattern: 'test-project' + branch-compare-type: 'ANT' + branch-pattern: '**' + file-paths: + - compare-type: ANT + pattern: subdirectory/** + skip-vote: + successful: true + failed: true + unstable: true + notbuilt: true + silent: false + escape-quotes: false + no-name-and-email: false + dynamic-trigger-enabled: true + dynamic-trigger-url: http://myhost/mytrigger \ No newline at end of file diff --git a/tests/triggers/test_triggers.py b/tests/triggers/test_triggers.py new file mode 100644 index 000000000..553e67d5e --- /dev/null +++ b/tests/triggers/test_triggers.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testtools import TestCase +from testscenarios.testcase import TestWithScenarios +from jenkins_jobs.modules import triggers +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleTriggers(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = triggers.Triggers diff --git a/tests/wrappers/__init__.py b/tests/wrappers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/wrappers/fixtures/env-file001.xml b/tests/wrappers/fixtures/env-file001.xml new file mode 100644 index 000000000..d6cb26a56 --- /dev/null +++ b/tests/wrappers/fixtures/env-file001.xml @@ -0,0 +1,8 @@ + + + + + /tmp/foo.txt + + + diff --git a/tests/wrappers/fixtures/env-file001.yaml b/tests/wrappers/fixtures/env-file001.yaml new file mode 100644 index 000000000..a2cb11583 --- /dev/null +++ b/tests/wrappers/fixtures/env-file001.yaml @@ -0,0 +1,3 @@ +wrappers: + - env-file: + properties-file: /tmp/foo.txt diff --git a/tests/wrappers/test_wrappers.py b/tests/wrappers/test_wrappers.py new file mode 100644 index 000000000..5312fd389 --- /dev/null +++ b/tests/wrappers/test_wrappers.py @@ -0,0 +1,28 @@ +# Joint copyright: +# - Copyright 2012,2013 Wikimedia Foundation +# - Copyright 2012,2013 Antoine "hashar" Musso +# - Copyright 2013 Arnaud Fabre +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +from testtools import TestCase +from testscenarios.testcase import TestWithScenarios +from jenkins_jobs.modules import wrappers +from tests.base import get_scenarios, BaseTestCase + + +class TestCaseModuleWrappers(TestWithScenarios, TestCase, BaseTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = get_scenarios(fixtures_path) + klass = wrappers.Wrappers