Commit Graph

11 Commits

Author SHA1 Message Date
Vsevolod Fedorov 60e8395c62 Add source location and context to error messages
Change-Id: I2e955c01b71a195bb6ff8ba2bb6f3a64cb3e1f58
2023-04-04 13:35:42 +03:00
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
Vsevolod Fedorov f4d64f9f66 Move tests to pytest
Pytest makes each scenario into individual selectable test.
To be able to run each scenario separately is very useful for development.

Change-Id: I4b1c990a1fd839ce327cd7faa27159a9b9632fed
2022-12-20 10:44:43 +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 df84460f7b Refactor duplicated code in xml_config.py
The view generation code was largely a copy/paste of the job generation
code.  This refactors that shared code in to a super-class that both
code paths can share.

(This has the side effect of improving the error message when an
incorrect project-type is specified; that improvement was previously
only applied to views.)

Change-Id: I1316162b885267c5e21793e59c2c3f7b95d5ce3b
2018-06-20 15:41:35 -04: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
Daniel Watkins e6d6c276d1 Give an explicit error message when unsupported view type used
When specifying a view type that isn't supported by any modules (such as
"list-view" instead of "list"), this ensures that the user is guided
towards something correct.

This changes the error message in this case from:

AttributeError: 'NoneType' object has no attribute 'name'

to:

jenkins_jobs.errors.JenkinsJobsException: Unrecognized view type: list-view (supported types are: list, pipeline)

Change-Id: I0ee800db1c9c8aeecffcf11f1e86c03ba0590da8
2017-10-06 14:24:48 -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
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
Darragh Bailey b36474bfae Enable and fix xml_config tests
Insert missing __init__.py to ensure xml_config tests run and update
call to `expandYaml` to handle multiple item return.

Change-Id: I8e409126556196f09a348d98a39ae9ca16245860
2016-11-21 13:56:33 +00:00
Darragh Bailey a5bd11ed18 Raise exception on unrecognized project type
Change-Id: I3a9355333dfc7c3f51cd970d0c12deff24223e68
Story: 2000575
2016-09-14 18:02:16 +01:00