16 Commits

Author SHA1 Message Date
Darragh Bailey
4573b3a25d Refactor base test classes inheritance for reuse
Refactor base test class inheritance to allow for BaseTest class to be
reused without needing to also import the TestCase class everywhere in
order to avoid having the common test function executed on base classes.

This makes it easier to build base testing classes and then simplifies
the subclassing of these for actual tests.

Change-Id: I89809e8082469f814f245db4a9ab7658aac8a405
2016-09-14 14:58:57 +01:00
Wayne Warren
e9a295b1fb Move CacheStorage to its own module.
And rename it to JobCache. The word "Cache" already implies "Storage"
so it makes more sense to name it after the things that it
stores...Jobs!

Change-Id: If7a7a56e8f6a3637f62e285eaa7ba989f67002dc
2016-09-02 08:58:09 -07:00
Wayne Warren
2cf11f014c Use JJBConfig for arg/config initialization.
* Create jenkins_jobs.config module with JJBConfig class.
* Move DEFAULT_CONF from jenkins_jobs.cmd into jenkins_jobs.config
* Move configuration initialization into JJBConfig
* Create method, "do_magical_things" to handle arbitration between
  config file and arguments as well as setting default values for
  config file settings if it doesn't contain the expected keys.
* Move JenkinsJobs.create_parser into its own module,
  jenkins_jobs.cli.parser, it can be used to provide default settings
  in the JJBConfig class when an argparse namespace object is not
  provided; this is primarily necessary because most of the original
  configuration initialization code relies on this being a namespace
  object (simple descendant of the object class).

At this point JJBConfig isn't much more than an object-oriented
version of the way configuration handling happened previously. Its
current form, however, is more amenable to the ultimate goal of the
2.0 refactorings--namely, being able to pass a single config object
around rather than breaking it up into apparently arbitrary settings
necessary to instantiate the Builder class and its delegate objects.

Change-Id: Ic0147e1dccbe620aaaba039a434e7cea6c670054
2016-07-19 18:57:34 +01:00
Wayne
fc73cedb45 Introduce modular implementation of subcommands.
This commit intentionally introduces a number of important API
breakages. Specifically, the jenkins_jobs.cmd module has been pared
down to some of its most difficult-to-refactor elements.

* Create jenkins_jobs.cli.entry.JenkinsJobs class to organize command
  line parsing and execution.
* Remove references to ConfigParser object in test code, hidden as an
  implementation detail of JenkinsJobs command line parsing. This will
  be necessary in the next stage of JJB 2.0 code which will be to
  create a JJBConfig object that handles logic and presentation of
  configuration from various sources--defaults, command line
  arguments, configuration file, and maybe environment variables in
  the future.
* Remove references to Namespace object produced by argparse module.
  Required rewrite of multipath & recursive path tests with a new
  MatchesDir testtools Matcher class that validates the expected
  output for a run of JJB against a given set of yamldirs with the
  specified command line arguments.
* Use stevedore to dynamically load subcommand parsers.
* Move configuration loading/testing to its own test file. Also fix
  the global vs home directory JJB config file test.

Change-Id: If62280418ba7319c313033ab387af4284237747e
2016-07-08 09:55:44 -07:00
Darragh Bailey
8805a34c0f Reorder imports to match hacking guidelines
Ensure that the imports follow the standard OpenStack hacking
guidelines.

Change-Id: Iaa4326aef118ddfd807dd006934f1d9ca80a1cfa
2015-12-23 15:23:42 -08:00
Darragh Bailey
9bfbffa559 Capture logs with FakeLogging Fixture
Capture logs to attach them on exceptions to simplify the debugging of
errors in tests when they occur.

Change-Id: I5c1b5c306aba37789a8d41eabf65e0ac628af838
2015-09-30 16:25:22 +01:00
Darragh Bailey
5b16aa9c55 Test update command with --delete-old option
Add simple test to ensure the update command results in update_job()
being called as expected and a complex scenario to test that when only
some jobs are updated, that passing --delete-old option to update will
only remove those managed jobs no longer listed and cannot include jobs
that were skipped previously.

Additionally this has been tested with the problem commit for adding
parallel thread usage and after adjusting the names of the functions
mocked to align with the rename demonstrated the bug encountered by
applying commit 7100a7f225e60936f23d24c757c1b14c9b136ec4.

Change-Id: I9c8a0bf86be2e67e012a3cf2a46530fd2622712b
2015-06-28 14:53:31 +01:00
Jeremy Stanley
fbd432a0ad Use mock in a Python 3.4 compatible way
Related to https://code.google.com/p/mock/issues/detail?id=234

Change-Id: I85549fdba7b9cb575850a12d52e1ffb0d2dba8c0
2015-01-29 23:07:53 +00:00
Wayne
288af951b5 Reorganize tests/cmd
This commit reorganizes the 'cmd' tests by subcommand.

Previously the multipath test was using an actual fixture directory
which actually made the fixtures directory somewhat unusable by other
tests since with an upcoming change (get_plugins_version) fixtures
directories may also contain YAML that doesn't contain JJB data.

Change-Id: I4c3866e1e0769512b40e1790e40affedb13953a2
2014-12-01 18:31:58 -08:00
Khai Do
4ce214b288 add test for globbed parameters feature
add a test to verify commmand processing of the globbed parameters
feature to delete jobs.

Change-Id: Ib13a2c644388ac65cb1af5728019912d6452d852
2014-11-14 18:26:45 +00:00
Khai Do
b7ff37ca5d fix delete job command and add tests
change I126751e3 introduced recursive file definition feature however it broke
the ability to delete jobs.  This changes fixes it and adds a few tests for it.

This was the error when trying to delete a job:

(py27)~/jenkins-job-builder$ jenkins-jobs --conf jenkins_jobs.ini delete myjob
INFO:root:Deleting jobs in [myjob]
Traceback (most recent call last):
  File "/jenkins-job-builder/.tox/py27/bin/jenkins-jobs", line 10, in <module>
    sys.exit(main())
  File "/jenkins-job-builder/jenkins_jobs/cmd.py", line 122, in main
    execute(options, config)
  File "/jenkins-job-builder/jenkins_jobs/cmd.py", line 207, in execute
    builder.delete_job(job, options.path)
  File "/jenkins-job-builder/jenkins_jobs/builder.py", line 611, in delete_job
    self.load_files(fn)
  File "/jenkins-job-builder/jenkins_jobs/builder.py", line 576, in load_files
    if os.path.isdir(path):
  File "/jenkins-job-builder/.tox/py27/lib/python2.7/genericpath.py", line 41,
    in isdir st = os.stat(s)
TypeError: coercing to Unicode: need string or buffer, NoneType found

Closes-Bug: #1349634
Change-Id: Ib87fa497d80ba33470c049f875658a3878afb664
2014-10-23 18:55:21 -07:00
Wayne
f0e53d34a1 Accept list of paths in 'path' arg.
This adds the behavior of splitting the path positional argument on colons then
processing each resulting string the same way that the path was being processed
previous to this commit.

* Adds a unit test to validate correct `path` parsing.
* Adds a unit test to validate correct `path` parsing in the recursive case.
* Documents the new behavior.

Change-Id: I0f465e02077569352cd276a8366ead5bab0eb117
2014-10-17 07:58:59 -07:00
Marc Abramowitz
64e217f885 Make JJB python 3 compatible
Convert to use idioms that work for both python 3 and python 2.6+ and
ensure that a suitable version of dependencies is included for python 3
compatibility.

Update python-jenkins to 0.3.4 as the earliest version that supports
python 3 without any known regressions. Add an extra parser check for
missing 'command' due to changes in how argparse works under python 3.

To access the first element of a dict in both python 2 and 3,
'next(iter(dict.items()))' is used as the standard idiom to replace
'dict.items()[0]' as 'items()' returns an iterator in python 3 which
cannot be indexed. Using 'next(iter(..))' allows for both lists and
iterators to be passed in without unnecessary conversion of iterators to
lists which would be true of 'list(dict.items())[0]'.

Original change which was reverted due to breaking use of job-groups is
If4b35e2ceee8239379700e22eb79a3eaa04d6f0f. This replaces the previous
conversion of 'dict.items()[0]' to 'dict.popitem()', which would result
in removing a job-group when first called, thus defeating the benefit of
being able to reference the group mulitple times. This usage has been
replaced with 'next(iter(dict.items()))' as a non-modifying alternative
that still avoids creating unnecessary copies of data while working for
all supported versions of python.

Change-Id: I37e3b67c043dadddb54e16ee584bde3f79e6a770
2014-10-06 15:24:16 +01:00
David Caro
a70126cd94 Added recursive option
Now you can organize your yaml files into subdirectories and apply them
all just passing --recursive option or adding the proper configuration
file option.

In adding support for multiple paths the Builder.load_files method was
reworked to be backward compatible with individual paths or file-like
objects, while also now handling being passed a list of paths or
file-like objects to be parsed.

Change-Id: I126751e347622716c592c6ed1a57b8acb7bf79a4
2014-08-29 18:41:14 +01:00
Darragh Bailey
1eb343616f Allow test command to use conf files
It should be possible to run the `test` command with a custom config.
This allows examination of the XML outputted where config settings can
change the outputted XML. Otherwise any non-default config values will
only be used when running the `update` comand.

Add a simple test to confirm that the custom url that is unlikely to
ever be a valid default value is returned when the command is set to
`test` and a custom config is specified.

Change-Id: I193e83314a35943406bff5b182f20693edd640ba
2014-07-09 15:57:00 +00:00
Khai Do
1df929c58a tests for JJB command processing
Add a few tests for JJB command processing.  This is just to get
started I'm hoping more will come.

Change-Id: Iff964af025f6a3d7ba4acd91b1e0242285a11bc3
2014-07-09 08:55:10 -07:00