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

Impossible to use RunnerClient in custom runner #44905

Closed
kiemlicz opened this issue Dec 10, 2017 · 4 comments
Closed

Impossible to use RunnerClient in custom runner #44905

kiemlicz opened this issue Dec 10, 2017 · 4 comments
Labels
Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged
Milestone

Comments

@kiemlicz
Copy link
Contributor

Description of Issue/Question

I have custom runner module that I start from Reactor System
In this custom module I would like to execute runner function e.g. like so:

import salt.runner


def no_jobs_running(minion):
    opts = __opts__.copy()
    r = salt.runner.RunnerClient(opts)
    o = r.cmd("jobs.active")

    if not o:
        __jid_event__.fire_event({'data': {}}, 'progress')

Unfortunately this ends with strange error:

Exception occurred in runner travis_stop.no_jobs_running: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/client/mixins.py", line 382, in _low
    data['return'] = self.functions[fun](*args, **kwargs)
  File "/srv/salt_ext/runners/travis_stop.py", line 12, in no_jobs_running
    __jid_event__.fire_event({'data': {}}, 'progress')
ReferenceError: weakly-referenced object no longer exists

Could anyone explain what does this mean and how to fix this?
Is it legal to use RunnerCilent from runner module?

Setup

Just create runner module from aforementioned snipped and configure:

runner_dirs:
  - /srv/ext/runners

Put module under /srv/ext/runners

Steps to Reproduce Issue

salt-run travis_stop.no_jobs_running minion1

Versions Report

Salt Version:
           Salt: 2017.7.2
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: 2.0.0
      gitpython: 2.1.1
          ioflo: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Nov 24 2017, 17:33:09)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.1
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1
 
System Versions:
           dist: debian 9.2 
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 4.11.0-1-amd64
         system: Linux
        version: debian 9.2 
 
@gtmanfred
Copy link
Contributor

Why do you need a runner client inside of a runner module?

All other runner modules are loaded into the __salt__ dunder inside the runners.

https://github.com/saltstack/salt/blob/2017.7/salt/loader.py#L837

@kiemlicz
Copy link
Contributor Author

I know that (most likely) I don't need to
Since I got this error I wanted to get the most out of it.

My use case:
I want to stop master once all N minions completes their work

I thought that I use reactor to run some function checking if there are any jobs.active
If no: publish event that everything is completed

Following other solution to my use case: is it possible to invoke runner within jinja template?

{% set output = runner['manage.status']('jobs.active') %}
# or
{% set output = salt['saltutil.runner']('jobs.active') %}

So that I will parse output in sls file beforehand?

@gtmanfred
Copy link
Contributor

in the orchestration sls files you would use the saltutil.runner If you want to be able to trigger a runner from a minion that is not running on the salt master, you would need to use publish.runner

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.publish.html#salt.modules.publish.runner

@garethgreenaway garethgreenaway added this to the Blocked milestone Dec 11, 2017
@garethgreenaway garethgreenaway added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label Dec 11, 2017
@kiemlicz
Copy link
Contributor Author

Ok,
It is fairly simple to just do sth like:
{% set jobs = salt.saltutil.runner("jobs.list_jobs").items()|map(attribute=1)|selectattr("Function", "equalto", "state.highstate")|list %}
I believe that my stacktrace has something to do with the fact that second Runner was spawned and somehow affected global scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged
Projects
None yet
Development

No branches or pull requests

3 participants