Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python code is not allowed: Sub() if there's dash in resource id while template job uses template-filter #1223

Open
baconYao opened this issue May 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@baconYao
Copy link
Contributor

baconYao commented May 3, 2024

Bug Description

The plainbox.impl.resource.CodeNotAllowed: this kind of python code is not allowed: Sub() exception be thrown while a template job use template-filter to filter a resource job whose id has dash.

$ checkbox.checkbox-cli run com.canonical.certification::try-resource-dash

$PROVIDERPATH is defined, so following provider sources are ignored ['/home/baconyao/.local/share/plainbox-providers-1', '/var/tmp/checkbox-providers-develop'] 
Using sideloaded provider: checkbox-provider-base, version 4.0.0.dev254 from /var/tmp/checkbox-providers/base
Skipped file: /var/tmp/checkbox-providers/base/units/stress/suspend_cycles_reboot.md
Undeclared exception CodeNotAllowed raised from use_job_result
Undeclared exception CodeNotAllowed raised from bootstrap
Traceback (most recent call last):
  File "/snap/checkbox22/current/bin/checkbox-cli", line 8, in <module>
    sys.exit(main())
  File "/snap/checkbox22/current/lib/python3.10/site-packages/checkbox_ng/launcher/checkbox_cli.py", line 166, in main
    return subcmd.invoked(ctx)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/checkbox_ng/launcher/subcommands.py", line 1122, in invoked
    self.just_run_test_plan(selection[0])
  File "/snap/checkbox22/current/lib/python3.10/site-packages/checkbox_ng/launcher/subcommands.py", line 1147, in just_run_test_plan
    self.sa.bootstrap()
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/decorators.py", line 153, in wrapper
    raise exc
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/decorators.py", line 145, in wrapper
    return func(*args, **kwargs)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/session/assistant.py", line 822, in bootstrap
    self.use_job_result(job.id, rb.get_result())
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/decorators.py", line 153, in wrapper
    raise exc
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/decorators.py", line 145, in wrapper
    return func(*args, **kwargs)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/session/assistant.py", line 1591, in use_job_result
    self._context.state.update_job_result(job, result)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/session/state.py", line 995, in update_job_result
    job.controller.observe_result(
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/ctrl.py", line 385, in observe_result
    self._process_resource_result(
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/ctrl.py", line 398, in _process_resource_result
    self._instantiate_templates(
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/ctrl.py", line 438, in _instantiate_templates
    for new_unit in unit.instantiate_all(
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/unit/template.py", line 437, in instantiate_all
    if self.should_instantiate(resource):
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/unit/template.py", line 548, in should_instantiate
    program = self.get_filter_program()
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/unit/template.py", line 393, in get_filter_program
    self._filter_program = ResourceProgram(
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 218, in __init__
    ResourceExpression(line, implicit_namespace, imports)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 545, in __init__
    self._resource_alias_list = self._analyze(text)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 739, in _analyze
    visitor.visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 471, in generic_visit
    return super(ResourceNodeVisitor, self).generic_visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 426, in generic_visit
    self.visit(item)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 471, in generic_visit
    return super(ResourceNodeVisitor, self).generic_visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 471, in generic_visit
    return super(ResourceNodeVisitor, self).generic_visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 471, in generic_visit
    return super(ResourceNodeVisitor, self).generic_visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 471, in generic_visit
    return super(ResourceNodeVisitor, self).generic_visit(node)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 428, in generic_visit
    self.visit(value)
  File "/snap/checkbox22/current/usr/lib/python3.10/ast.py", line 418, in visit
    return visitor(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 470, in generic_visit
    self._check_node(node)
  File "/snap/checkbox22/current/lib/python3.10/site-packages/plainbox/impl/resource.py", line 481, in _check_node
    raise CodeNotAllowed(node)
plainbox.impl.resource.CodeNotAllowed: this kind of python code is not allowed: Sub()

To Reproduce

Reproducible by the follow code

id: try-resource-dash
unit: test plan
_name: Try resource dash
_description: Test
bootstrap_include:
    demo-dash-resource
include:
    demo/demo_dash_success

id: demo-dash-resource
_summary: Try resource id has dash
_description: Problem occurs while resource id has dash
estimated_duration: 0.02
category_id: com.canonical.plainbox::info
plugin: resource
command:
    echo "key: 123"
    echo ""
    echo "key: 456"
    echo ""
    echo ""

unit: template
template-engine: jinja2
template-resource: demo-dash-resource
template-unit: job
template-filter: demo-dash-resource.key == "456"
template-id: demo/demo_dash_success
id: demo/go_{{ key }}
_summary: Try demo-dash-resource
plugin: shell
category_id: com.canonical.plainbox::info
estimated_duration: 1s
command:
    echo "Success with 'demo-dash-resource' resource job"

Environment

OS: Class and UC
Checkbox Version:

checkbox                        4.0.0-dev254                6779   latest/beta      ce-certification-qa  classic
checkbox22                      4.0.0-dev254                918    latest/beta      ce-certification-qa  -

Relevant log output

### Unable to reproduce this issue without the template-filter

id: try-resource-dash
unit: test plan
_name: Try resource dash
_description: Test
bootstrap_include:
    demo-dash-resource
include:
    demo/demo_dash_success

id: demo-dash-resource
_summary: Try resource id has dash
_description: Problem occurs while resource id has dash
estimated_duration: 0.02
category_id: com.canonical.plainbox::info
plugin: resource
command:
    echo "key: 123"
    echo ""
    echo "key: 456"
    echo ""
    echo ""

unit: template
template-engine: jinja2
template-resource: demo-dash-resource
template-unit: job
template-id: demo/demo_dash_success
id: demo/go_{{ key }}
_summary: Try demo-dash-resource
plugin: shell
category_id: com.canonical.plainbox::info
estimated_duration: 1s
command:
    echo "Success with 'demo-dash-resource' resource job"


```bash
checkbox.checkbox-cli run com.canonical.certification::try-resource-dash               1 ✘  13:20:42 
$PROVIDERPATH is defined, so following provider sources are ignored ['/home/baconyao/.local/share/plainbox-providers-1', '/var/tmp/checkbox-providers-develop'] 
Using sideloaded provider: checkbox-provider-base, version 4.0.0.dev254 from /var/tmp/checkbox-providers/base
Skipped file: /var/tmp/checkbox-providers/base/units/stress/suspend_cycles_reboot.md
=========================[ Running Selected Test Plan ]=========================
==============[ Running job 1 / 2. Estimated time left: 0:00:02 ]===============
---------------------------[ Try demo-dash-resource ]---------------------------
ID: com.canonical.certification::demo/go_123
Category: com.canonical.plainbox::info
... 8< -------------------------------------------------------------------------
Success with 'demo-dash-resource' resource job
------------------------------------------------------------------------- >8 ---
Outcome: job passed
==============[ Running job 2 / 2. Estimated time left: 0:00:01 ]===============
---------------------------[ Try demo-dash-resource ]---------------------------
ID: com.canonical.certification::demo/go_456
Category: com.canonical.plainbox::info
... 8< -------------------------------------------------------------------------
Success with 'demo-dash-resource' resource job
------------------------------------------------------------------------- >8 ---
Outcome: job passed
Finalizing session that hasn't been submitted anywhere: checkbox-run-2024-05-03T05.20.48
==================================[ Results ]===================================
 ☑ : Try demo-dash-resource
 ☑ : Try demo-dash-resource


### Additional context

_No response_
@baconYao baconYao added the bug Something isn't working label May 3, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CHECKBOX-1434.

This message was autogenerated

@baconYao baconYao changed the title Python code is not allowed: Sub() if there's dash in resource id while template job use template-filter Python code is not allowed: Sub() if there's dash in resource id while template job uses template-filter May 3, 2024
@baconYao
Copy link
Contributor Author

baconYao commented May 3, 2024

Unable to reproduce this issue if resource id uses underscore

id: try-resource-underscore
unit: test plan
_name: Try resource dash
_description: Test
bootstrap_include:
    demo_dash_resource
include:
    demo/demo_dash_success

id: demo_dash_resource
_summary: Try resource id has dash
_description: Problem occurs while resource id has dash
estimated_duration: 0.02
category_id: com.canonical.plainbox::info
plugin: resource
command:
    echo "key: 123"
    echo ""
    echo "key: 456"
    echo ""
    echo ""

unit: template
template-engine: jinja2
template-resource: demo_dash_resource
template-unit: job
template-filter: demo_dash_resource.key == "456"
template-id: demo/demo_dash_success
id: demo/go_{{ key }}
_summary: Try demo_dash_resource
plugin: shell
category_id: com.canonical.plainbox::info
estimated_duration: 1s
command:
    echo "Success with 'demo-dash-resource' resource job"

Result

checkbox.checkbox-cli run com.canonical.certification::try-resource-underscore    1 ✘  5s  13:38:45 
$PROVIDERPATH is defined, so following provider sources are ignored ['/home/baconyao/.local/share/plainbox-providers-1', '/var/tmp/checkbox-providers-develop'] 
Using sideloaded provider: checkbox-provider-base, version 4.0.0.dev254 from /var/tmp/checkbox-providers/base
Skipped file: /var/tmp/checkbox-providers/base/units/stress/suspend_cycles_reboot.md
=========================[ Running Selected Test Plan ]=========================
==============[ Running job 1 / 1. Estimated time left: 0:00:01 ]===============
---------------------------[ Try demo_dash_resource ]---------------------------
ID: com.canonical.certification::demo/go_456
Category: com.canonical.plainbox::info
... 8< -------------------------------------------------------------------------
Success with 'demo-dash-resource' resource job
------------------------------------------------------------------------- >8 ---
Outcome: job passed
Finalizing session that hasn't been submitted anywhere: checkbox-run-2024-05-03T05.39.36
==================================[ Results ]===================================
 ☑ : Try demo_dash_resource

@baconYao
Copy link
Contributor Author

baconYao commented May 3, 2024

According to the Checkbox Document, the id should only contain character in [a-z0-9/-] only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant