SatelliteQE / broker

The infrastructure middleman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`broker execute` leads to `UnboundLocalError`

jarovo opened this issue · comments

(venv) ➜  broker git:(thp) ✗ broker execute
Traceback (most recent call last):
  File "/home/jhenner/work/sat/broker/venv/bin/broker", line 33, in <module>
    sys.exit(load_entry_point('broker', 'console_scripts', 'broker')())
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/jhenner/work/sat/broker/venv/lib64/python3.9/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/jhenner/work/sat/broker/broker/commands.py", line 302, in execute
    result = broker_inst.execute()
  File "/home/jhenner/work/sat/broker/broker/broker.py", line 135, in execute
    logger.info(f"Using provider {provider.__name__} for execution")
UnboundLocalError: local variable 'provider' referenced before assignment

This is probably because of the self._provider_actions.items() is empty. The pattern used there:

        for action, arg in self._provider_actions.items():
            provider, method = PROVIDER_ACTIONS[action]
        logger.info(f"Using provider {provider.__name__} for execution")
        return self._act(provider, method)

Is quite suspicious. Is it really meant to use the last action defined in the _provider actions? Why we should iterate over all of them?

I see the pattern repeated many times in the broker.py. This violates DRY principle and I think it can be done better, but I don't yet understand the design.

This is not happening when executing:
broker execute --workflow some_workflow test_action

This should initially be handled at the cli level, don't execute if there is nothing to execute.

fixed by #108