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

Feature Request : Add synchronous refreshing methods to saltutil #20590

Open
JeremieCharest opened this issue Feb 11, 2015 · 14 comments · May be fixed by #61386
Open

Feature Request : Add synchronous refreshing methods to saltutil #20590

JeremieCharest opened this issue Feb 11, 2015 · 14 comments · May be fixed by #61386
Labels
Feature new functionality including changes to functionality and code refactors, etc.
Milestone

Comments

@JeremieCharest
Copy link

Is it possible to add a sync method/parameter for ­­­saltutil:refresh_pillar, saltutil:refresh_grains and all others "refresh_xxx"? Currently the documentation doesn't mention the fact that they are async methods. That create us several mysterious bugs.

salt/saltutil.py

def refresh_pillar():
    try:
        ret = __salt__['event.fire']({}, 'pillar_refresh')
    except KeyError:
        log.error('Event module not available. Module refresh failed.')
        ret = False  # Effectively a no-op, since we can't really return without an event system
    return ret

We were having a few sls that modified pillars, refreshed them and worked on the "updated" values inside modules :

refresh_pillar:
  file.append:
    - name: /srv/salt/base/pillar/dummy.sls
    - text: |
        dummy:
          testProps: {{ [1, 45, 666, 9999, 24234, 45345345] | random }}
    - require:
      - file: write_dummy_pillar
  module.run:
    - name: saltutil.refresh_pillar
    - require:
      - file: refresh_pillar

# this module will print the previous pillar value, not the new one
broken_state_due_to_async_refresh:
  module.run:
    - name: print_pillar.test
    - require:
      - module: refresh_pillar

Do you know a workaround that we could use to obtain real updated values?

@cachedout
Copy link
Contributor

This is an issue that does tend to bite people. I think that one approach here might be to make this pseduo-syncrhronous. Instead of blocking the entire minion during a refresh (which is why it's async to begin with), we could setup a poller inside the refresh call that spins until the refresh is complete before returning. We may need to add some singaling to the loader to facilitate this. It's going to require some further discussion and planning but I do agree this is an issue that needs to be resolved.

@cachedout cachedout added the Feature new functionality including changes to functionality and code refactors, etc. label Feb 11, 2015
@cachedout cachedout added this to the Approved milestone Feb 11, 2015
@JeremieCharest
Copy link
Author

I tried to hack my way around that but I had difficulties to make the minion event listening working. I started from the http://docs.saltstack.com/en/latest/topics/event/index.html doc.

salt-call frima_saltutil.refresh_pillar

Exception AttributeError: "'MinionEvent' object has no attribute 'cpub'" in <bound method MinionEvent.__del__ of <salt.utils.event.MinionEvent object at 0x4838c10>> ignored
Passed invalid arguments: __init__() got an unexpected keyword argument 'ioflo_realtime'

frima_saltutil.py

import salt.utils.event

def refresh_pillar():
    minion_event = salt.utils.event.MinionEvent(**__opts__)

    __salt__['saltutil.refresh_pillar']()

    for job_event in minion_event.iter_events(tag='salt/job'):
        if job_event["data"]["func"] == "saltutil.refresh_pillar":
            return job_event["data"]["success"] or False

    return False
@cachedout
Copy link
Contributor

It looks like we will be slating this feature for 2015.5, due out in mid-May.

@eliasp
Copy link
Contributor

eliasp commented Feb 11, 2015

This could be the reason for #19417 to happen. No wait, in #19417 saltutil.sync_all is called after fileserver.update - most likely something else then.

@JeremieCharest
Copy link
Author

I link #10304 for the event system exception

@stale
Copy link

stale bot commented Oct 14, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Oct 14, 2017
@stale stale bot closed this as completed Oct 21, 2017
@Oloremo
Copy link
Contributor

Oloremo commented Feb 28, 2019

I really wish synchronous sync will be implemented. I struggling with async races with Salt.

@Oloremo
Copy link
Contributor

Oloremo commented Feb 28, 2019

@Ch3LL any chance to ressurect this request? Having a synchronous option to these modules will open many great possibilities and remove many race conditions like "I did pillars_refresh - can I already start things or they're not refreshed yet?" And so on

@Oloremo
Copy link
Contributor

Oloremo commented Feb 28, 2019

KInda related: #50105

@Ch3LL Ch3LL reopened this May 14, 2019
@stale
Copy link

stale bot commented May 14, 2019

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label May 14, 2019
@Ch3LL
Copy link
Contributor

Ch3LL commented May 14, 2019

as you pointed out in that issue this functionality has been added to refreshing modules and pillar, but would be nice to add it across refreshing all different kinds of modules.

@stale
Copy link

stale bot commented Jan 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 8, 2020
@Oloremo
Copy link
Contributor

Oloremo commented Jan 8, 2020

not stale

@stale
Copy link

stale bot commented Jan 8, 2020

Thank you for updating this issue. It is no longer marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature new functionality including changes to functionality and code refactors, etc.
5 participants