Commit Graph

41 Commits

Author SHA1 Message Date
Vsevolod Fedorov af9e03ec08 Rewrite YAML parser
Rewrite YAML parser, YAML objects and parameters expansion logic to
enable better control over expansion logic.
Broken backward compatilibity:
* More agressive parameter expansion. This may lead to parameters
  expanded in places where they were not expanded before.
* Top-level elements, which is not known to parser (such as 'job',
  'view', 'project' etc), are now lead to parse failures.
  Prepend them with underscore to be ignored by parser.
* Files included using '!include-raw:' elements and having formatting in
  it's path ('lazy-loaded' in previous implementation) are now expanded
  too.
  Use '!include-raw-escape:' for them instead.
  See changes in these tests for examples:
    tests/yamlparser/job_fixtures/lazy-load-jobs-multi001.yaml
    tests/yamlparser/job_fixtures/lazy-load-jobs-multi002.yaml
    tests/yamlparser/job_fixtures/lazy-load-jobs001.yaml
* Parameters with template value using itself were substituted as is.
  For example: "timer: '{timer}'" was expanded to "{timer}". Now it
  leads to recursive parameter error.
  See changes in this test for example:
    tests/yamlparser/job_fixtures/parameter_name_reuse_default.*
    ->
    tests/yamlparser/error_fixtures/parameter_name_reuse_default.*
* When job group includes a job which was never declared, it was just
  ignored. Now it fails: job is missing.
  See changes in this test for example:
    tests/yamlparser/job_fixtures/job_group_includes_missing_job.*
    ->
    tests/yamlparser/error_fixtures/job_group_includes_missing_job.*

Change-Id: Ief4e515f065a1b9e0f74fe06d7e94fa77d69f273
2023-02-28 20:16:57 +03:00
Thanh Ha 4d90c187a9 Auto-generated output from python-black
Please review the following patch containing the code changes in
the repo. This patch is a transition patch and is the auto-generated
output of the python-black tool.

Change-Id: I2d2de71da8a105fb62b561899ae78441ddab4032
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
2019-09-09 19:23:24 +01:00
Daniel Watkins 63c02a8092
Revert "Add support for rendering jinja template as yaml"
This reverts commit a9e12ed4a9.

Change-Id: I2bbb2cc167a4c2cd95ac6b376ebe83bcf7a263ad
2019-07-29 14:41:52 -04:00
Philip Roche a9e12ed4a9 Add support for rendering jinja template as yaml
This also adds support for using custom loaders in job definitions

not just job-templates and builders. I have also added unit tests for include-jinja2-as-yaml custom loader.

Example usage:

        - axis:
            type: user-defined
            name: VERSIONS
            values:
                !include-jinja2-as-yaml: versions.j2.yaml.inc

Where versions.j2.yaml.inc is

{% for possible_versions in configuration["possible_versions"] %}
- {{ possible_versions["versions"] }}
{% endfor -%}

Change-Id: I15a431d5a86b29d704efda8576965ade2b7dcd2f
2019-07-12 17:58:40 +01:00
Thanh Ha c5013b61d6
Ignore view update if not specified
Similar to job updates when passing a specific job name in the CLI,
views should also be ignored if they were not explicitly specified.

Change-Id: I77488b0af453964f77bc8d565d43f404327ef139
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
2019-04-10 10:13:42 +08:00
Thanh Ha c2f034ee0b
Remove random print
The random print statement does not provide any useful information
and spams the console output if a repo has many declared views with
uninteresting output.

Change-Id: I7f40730c753ec8f1145ba6144fe28bf97844b9e2
Signed-off-by: Thanh Ha <zxiiro@linux.com>
2018-11-13 18:03:18 +08:00
Sorin Sbarnea 4f7b6ee568
upgrade hacking module
- upgrades hacking to current version
- sorts new linting issues
- sorts bug with sys.reload on py3

Change-Id: I4a18abc93116667a2733e8aec619ac59ea73d630
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2018-06-19 18:04:37 +01:00
Vicky Chijwani 75d78b6540 Add retain_anchors config option.
If set to True, YAML anchors can be referenced across files, allowing jobs to be
composed from bits of YAML defined in separate files. False by default.

Story: 2000338
Task: 2547
Change-Id: I034ce3bce0030093cb8d4266dabbdb06d96306d6
2018-05-31 20:30:09 +05:30
Thanh Ha 418e7c628d Add support for view-templates
Allow views to also be configured via templates similar to
job-templates.

This adds a new project key called "views" and parser type called
"view-template" allowing the user to add custom views.

Example:

- view-template:
    name: '{name}-template-{seq}'
    description: 'testing view templates feature'
    view-type: list
    regex: 'test-view-.*'

- project:
    name: 'test-view'
    views:
        - '{name}-template-{seq}'
    seq:
        - a
        - b
        - c

Change-Id: I6eb225f24bc3c7d790c7dcab6391735c579ac71a
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
2018-04-12 19:42:31 +01:00
Darragh Bailey 733906f01b Preserve template-name via escaping
Make use of an improved regex pattern matching to simply escape the
template name when passing into the params to allow the name be
preserved and used as input to other params.

This avoids needing to perform an additional branch test against all
variables being formatted.

Change-Id: I9c0ac8996d520b9acff3d29039c5c3d76f56d899
Depends-On: I8a74f9b4236ca7bcc72dd207fca23c2bf6a7c801
2018-02-09 14:59:41 +00:00
Zuul 5da4f97e23 Merge "Allow template-name in the global defaults" 2018-01-27 07:56:58 +00:00
Jan Hruban 28cab53d5d Allow template-name in the global defaults
Inject the template-name into parameters earlier, so it's possible to
use it in the global defaults. Mark the template name as 'verbatim' so
the interpolation is skipped by the formatter.

Change-Id: I5d98e32ed2bedaa6b536e61fbdec589f358f861f
2018-01-16 16:00:46 +01:00
Thanh Ha eddb40babd Revert "Move macro expansion into YamlParser."
This reverts commit e645ac2acf.

Change-Id: I56e8c8282669cbc9f963056f64e9caef8104b6bb
2018-01-01 10:54:10 -06:00
Darragh Bailey af9d984baa
Basic folder support
Allows specifying a folder attribute for each job generated, which in
turn is used when creating or uploading to place the job under the
requested folder.

The job name is expanded after defaults are applied, to support the
attribute being defined within a set of defaults applied to a number of
jobs.

This in turn allows for multiple jobs with the same basename to exist,
provided they are targeted at different folders.

Does not support creating the folders if they do not exist.

Change-Id: I8c2157c4c81087cc972a048d1b88d5f08ac65361
2017-10-23 13:29:21 -04:00
Wayne Warren e645ac2acf
Move macro expansion into YamlParser.
Introduce the registry.MacroRegistry class to handle:
 * registration of macro types via setuptools' entrypoints
 * registration of individual macros for lookup by component list type
 * expansion of macros references during YAML "parsing"

As a consequence there is a reduction in performance due to moving the
expansion of macros from inline with XML generation, to requiring
multiple passes over macro component lists.

This decrease in efficiency results in approx ~30-50% increase in unit
test time. Since this will allow for jobs to be expanded from
templates/macros in parallel with future changes, it is a reasonable
short term trade-off as the most computationally expensive task is
updating the definitions on the remote master

Change-Id: I292c6b1f8472370282205426cd8ceb847eb969bd
2017-08-24 10:14:26 -04:00
Jenkins 86e2ad2f07 Merge "Output additional info when exceptions occur" 2017-06-05 18:55:10 +00:00
Sorin Sbarnea 8a7d77c180 Removed some deprecation warnings and enabled py35 on tox.
Change-Id: Icc5b28c4636b542a10502b7b1d2d2dc2028cc166
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
2017-03-12 19:43:33 +00:00
Darragh Bailey 0f0f681069 Output additional info when exceptions occur
Problems occurring deep in the code frequently need to be caught and
additional information included in the error output to help debug
issues.

Change-Id: I5aee523a3cf9e1cb7573fa6fc5a06dc3888be1ef
2016-12-08 15:59:12 +00:00
Jenkins e47f9629bc Merge "Add view management functionality" 2016-11-10 16:35:23 +00:00
Thanh Ha 1deb3aff4c
Add view management functionality
- Adds the ability for JJB to work with views
- Views can be created, updated, and deleted.
- New modules for List view and Build Pipeline view are added
- New tests for testing the deletion of views

Example View configuration:

    - view:
        name: MyView
        view-type: list

Change-Id: Idb29a4407bcc14593e10a4d951036cb04e8e6c27
Co-Authored-By: Brandon Leonard <brandon.leonard@rackspace.com>
Co-Authored-By: Joao Vale <jpvale@gmail.com>
Co-Authored-By: Lucas Dutra Nunes <ldnunes@ossystems.com.br>
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
2016-10-14 09:14:21 -04:00
Darragh Bailey 64537f5125 Improve logger output for expanding templates
Output the variable inputs used that trigger an error when expanding
template names to the error logger channel in a sensible format.

Ensures that when indented variable inputs for templates result in
exceptions when expanding a template name, that the project, template
name and variables that failed to be iterated over are outputted in a
log error message along with the original set of inputs from the
project definition to make it easier for end users to find where the
error has been made in a JJB definition.

Add code to allow dumping of variables stored in OrderedDict
transparently to match the input format used in JJB definitions and
hide the implementation detail of using OrderedDict to be within the
localyaml library.

Change-Id: I660bb0ca3b109e1a861948d6a867f185047b90ae
2016-09-14 15:15:04 +01:00
Wayne Warren 8ffb11a4bf Be explicit about objects exported by modules.
Change-Id: Iaea087c6c3a024922034423a8d56571184f33b7c
2016-08-20 00:34:35 -07:00
Wayne Warren c80e3bc5e9
Cleanup various deprecation warnings.
Change-Id: Iec16a5965d62bebb50d3e7307ab93c59304a9ab6
2016-08-20 01:24:49 -04:00
Wayne Warren aaae83c623
Factor XmlJobGenerator out of YamlParser.
Separate XML generation from Yaml parsing/interpreting. The goal here
is to allow different sources to provide data for XML generation,
including external API users writing job definitions in pure Python or
JJB developers who would like to work on alternative Yaml parsing code
since the current YamlParser has very likely reached the limits of
what can be reasonably done with one giant expandYaml procedure.

Change-Id: I9da848acac7e944c0e07286b7399b2e1956a58a5
2016-08-18 22:42:24 -04:00
Wayne Warren ae1fb60f16
Disentangle YamlParser and ModuleRegistry classes
Create the ModuleRegistry anywhere other than inside the YamlParser
class. This will make it slightly easier to factor a XmlGenerator out
of YamlParser, but I also want to work toward eliminating the circular
references between YamlParser and ModuleRegistry which have been
making it difficult to understand overall program flow.

This commit also replaces all YamlParser instances being passed to
Jenkins job config generating functions with a ModuleRegistry. Mostly
it seems like the parser was only needed to call the ModuleRegistry's
'dispatch' method which to be honest I don't fully understand. This is
where the circular references mentioned in previously come in...it
seems like the "dispatch" function needs access to the (mostly) raw
data contained by the parser, so it took that as a parameter.

The need for the YamlParser's job data can be satisfied by assigning
it to a property on the ModuleRegistry object before Yaml expansion or
XML generation begins; by doing this, we allow the ModuleRegistry to
avoid referencing the parser.

Change-Id: I4b571299b81e708540392ad963163fe092acf1d9
2016-08-18 22:42:24 -04:00
Wayne Warren f9b3c4e6a7 Remove YamlParser references from JJB modules.
Change-Id: Ia9ca686c4040fd27890dbce99fda3db3e99a1102
2016-08-05 09:01:30 -07:00
Wayne Warren f85cf31826 Don't expose YamlParser methods unnecessarily.
Change-Id: I81ef41c2b411850b3535387115e0e379e2efc038
2016-08-05 08:56:35 -07:00
Wayne Warren c569dc02d3 Move load_files method to YamlParser from Builder.
This is the first step in removing jenkins_modules.parser.YamlParser
references from jenkins_jobs.builder.Builder entirely, necessary
because load_files is actually a YamlParser behavior, not a Builder
behavior.

Change-Id: I1cad99b4cdb44af25ba398837f7f328cfcbd5bbb
2016-07-22 17:33:53 +01:00
Wayne Warren 0da11b51c5 Use JJBConfig in ModuleRegistry.
Remove reference to ConfigParser object in ModuleRegistry. Instead:
* make use of JJBConfig.get_module_config to grab settings for Hipchat
  Notifier Plugin
* make use of JJBConfig.yamlparser['allow_empty_variables'] rather
  than repeating ConfigParser logic moved out of the YamlParser into
  JJBConfig in an earlier commit.

Change-Id: Icb7ef514826005545e48af993335ce120f973b0d
2016-07-22 17:33:30 +01:00
Wayne Warren 4f04de1f9a Use JJBConfig in YamlParser.
This commit sees JJBConfig start to take the form it ought to have,
namely using attributes to represent different logical sections of
configuration that target specific subsystems of JJB.

It also moves ConfigParser data retrieval from
jenkins_jobs.modules.helpers.get_value_from_yaml_or_config_file() to
jenkins_jobs.config.JJBConfig.get_module_config()

TODO: Add JJBConfig tests to validate the behavior of JJBConfig in
specific circumstances.

Change-Id: I053d165559f5325a2f40b239117a86e6d0f3ef37
2016-07-22 17:33:25 +01:00
Jenkins 5d14a621a0 Merge "Allow id's for different templates to follow same naming" 2016-04-21 23:13:59 +00:00
David Caro d4fa9d7b23 Added possibility to exclude project combinations
Change-Id: I40603f041d33a27d08bf6912b7d9d885a95278fd
Signed-off-by: David Caro <dcaroest@redhat.com>
2016-03-12 17:51:01 +00:00
Darragh Bailey 398e28b3c3 Allow id's for different templates to follow same naming
It is useful to allow templates that can have different settings for
slightly different jobs while still following the same naming scheme.
Additionally this allows for shorter and more descriptive names to be
used without the confusion of the variable placeholders, and for the
resulting job names from the templates to be altered without needing to
update all references.

Change-Id: Idc3517b44873210a33f988ebff449ea2ed567054
2016-02-20 18:20:51 +00: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
Jenkins daf8be4480 Merge "Debug message leads to (n*m) log growth." 2015-12-03 04:59:49 +00:00
James E. Blair 7ef05f7373 Add template-name as a variable that can be used in a template
In complex configurations it may be useful to have a template
print out its name so that a given job can be easily traced to
its definition.

Change-Id: I1cfed9c27a58b45ba48aeed04839bfc8f54a831e
2015-11-24 07:47:26 -08:00
Wayne Warren 43cfc27360 Debug message leads to (n*m) log growth.
Where n = number of variables in scope for a particular job template instance.
and   m = number of job template instance.

Let's imagine for a large set of jobs with n = 100 and m = 50

This debug message makes it difficult to scan through JJB output looking for
signficant debug messages and does not provide a clear value.

It is trivially easy to know which variables are and which are not included in a
job-template's name by simply reading it.

Change-Id: I745e26ac6062277fc477cb1ca70cf2809f5806e3
2015-11-17 16:03:28 -08:00
Darragh Bailey b023d7e23f Wrap file objects with codecs to handle unicode
Ensure file objects including stdin/stdout objects are wrapped using
codecs to handle unicode translation to the selected encoding for
input/output.

Add tests to simulate different encodings for input/output and
consequently fix the reading of input from stdin. Include test to
trigger failure to encode a unicode valid character using 'ascii'
encoding.

Change-Id: I9a5c4c96d131873db0000377729b8b0a45aa470d
2015-10-09 10:48:01 -07:00
Darragh Bailey 0e74bddb56 Replace open() with io.open() and force 'utf-8'
Use io.open() to allow reading and writing of files in 'utf-8' format
irrespective of the terminal encoding selected.

Change-Id: Ie952617a34c0719efc59a7729d698beafaa477b0
2015-07-25 14:16:12 -07:00
Richard Pijnenburg b56e8812c7 Adding tests surrounding handling of defaults values
waynr fixed a bug but explained in concat_defaults002
This bug happens when some values are specified in an other defaults
namespace then global.
This causes JJB to fail that its unable to find the required keys
becasue these were not merged correctly

Change-Id: Id0df24ba7cf8281389c2ed7af7ee716047d0e4a5
2015-05-27 18:24:54 +02:00
Wayne 4a8b93b8c2 Remove YamlParser from jenkins_jobs.builder
The goal of this patch is simply to move some classes out of
jenkins_jobs.builder into more appropriately-named modules. This started with
simply moving YamlParser into jenkins_jobs.parser but led to other moves in
order to avoid cyclic imports since YamlParser uses other classes previously
defined in jenkins_jobs.builder.

That said, this patch doesn't intend to address all of the clutter in
jenkins_jobs.builder, mostly just what is necessary to get started working on
YamlParser independent of other classes in that module.

Change-Id: Ie88bf683e495033eb0b670fe29c256a70282735f
2015-04-22 11:59:07 -07:00