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

Custom scripts fail at failing #169

Closed
jtishey opened this issue Oct 28, 2021 · 3 comments
Closed

Custom scripts fail at failing #169

jtishey opened this issue Oct 28, 2021 · 3 comments

Comments

@jtishey
Copy link

jtishey commented Oct 28, 2021

It seems like when a script runs into an exception, it gets caught by s_exec in netpalm/backend/plugins/calls/scriptrunner/script.py and returns the exception string to the script_exec function, which then has no way to know it failed. This makes scripts always be reported as successful. Would it be better to either remove the try/except in s_exec or maybe have it re-raise the exception or something? Am I just missing something here?

Modified "hello_world" script to fail and raise an exception:

def run(**kwargs):
        args = kwargs.get("kwargs")
        world = args.get("hello")
        return non_existent_world

Current result:

<...>
   "task_status": "finished",
    "task_result": {},
    "task_errors": []
  }

Modified scriptrunner/script.py function:

    def s_exec(self):
        module = importlib.import_module(self.script_name)
        runscrp = getattr(module, "run")
        res = runscrp(kwargs=self.arg)
        return res

Result with modified s_exec():

<...>
    "task_status": "failed",
    "task_result": null,
    "task_errors": [
      "name 'non_existent_world' is not defined"
    ]
@tbotnz
Copy link
Owner

tbotnz commented Oct 29, 2021

@jtishey thanks for raising this, yes you are correct. Would you like to PR?

Tbot

@jtishey
Copy link
Author

jtishey commented Oct 29, 2021

OK cool. Yeah, I'll open a PR for this. Thanks!

jtishey pushed a commit to jtishey/netpalm that referenced this issue Oct 29, 2021
jtishey pushed a commit to jtishey/netpalm that referenced this issue Oct 29, 2021
@jtishey
Copy link
Author

jtishey commented Oct 29, 2021

PR #170 submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants