def process_snapd_timer():
    """
    Set the snapd refresh timer on the leader so all cluster members
    (present and future) will refresh near the same time.

    :return: None
    """
    # Get the current snapd refresh timer; we know layer-snap has set this
    # when the 'snap.refresh.set' flag is present.
    timer = snap.get(snapname="core",
                     key="refresh.timer").decode("utf-8").strip()
    if not timer:
        # The core snap timer is empty. This likely means a subordinate timer
        # reset ours. Try to set it back to a previously leader-set value,
        # falling back to config if needed. Luckily, this should only happen
        # during subordinate install, so this should remain stable afterward.
        timer = leader_get("snapd_refresh") or hookenv.config("snapd_refresh")
        snap.set_refresh_timer(timer)

        # Ensure we have the timer known by snapd (it may differ from config).
        timer = snap.get(snapname="core",
                         key="refresh.timer").decode("utf-8").strip()

    # The first time through, data_changed will be true. Subsequent calls
    # should only update leader data if something changed.
    if data_changed("snapd_refresh", timer):
        hookenv.log("setting leader snapd_refresh timer to: {}".format(timer))
        leader_set({"snapd_refresh": timer})
示例#2
0
def set_snapd_timer():
    ''' Set the snapd refresh.timer on non-leader cluster members. '''
    # NB: This method should only be run when 'snap.refresh.set' is present.
    # Layer-snap will always set a core refresh.timer, which may not be the
    # same as our leader. Gating with 'snap.refresh.set' ensures layer-snap
    # has finished and we are free to set our config to the leader's timer.
    timer = leader_get('snapd_refresh') or ''  # None will cause error
    log('setting snapd_refresh timer to: {}'.format(timer))
    snap.set_refresh_timer(timer)
示例#3
0
def change_snapd_refresh():
    """Set the system refresh.timer option"""
    ensure_snapd_min_version("2.31")
    timer = hookenv.config()["snapd_refresh"]
    was_set = reactive.is_flag_set("snap.refresh.was-set")
    if timer or was_set:
        snap.set_refresh_timer(timer)
    reactive.toggle_flag("snap.refresh.was-set", timer)
    reactive.set_flag("snap.refresh.set")
def set_snapd_timer():
    """
    Set the snapd refresh.timer on non-leader cluster members.

    :return: None
    """
    # NB: This method should only be run when 'snap.refresh.set' is present.
    # Layer-snap will always set a core refresh.timer, which may not be the
    # same as our leader. Gating with 'snap.refresh.set' ensures layer-snap
    # has finished and we are free to set our config to the leader's timer.
    timer = leader_get("snapd_refresh") or ""  # None will error
    hookenv.log("setting snapd_refresh timer to: {}".format(timer))
    snap.set_refresh_timer(timer)
def process_snapd_timer():
    ''' Set the snapd refresh timer on the leader so all cluster members
    (present and future) will refresh near the same time. '''
    # Get the current snapd refresh timer; we know layer-snap has set this
    # when the 'snap.refresh.set' flag is present.
    timer = snap.get(snapname='core', key='refresh.timer').decode('utf-8')
    if not timer:
        # A subordinate wiped out our value, so we need to force it to be set
        # again. Luckily, the subordinate should only wipe it out once, on
        # first install, so this should remain stable afterward.
        snap.set_refresh_timer(hookenv.config('snapd_refresh'))
        timer = snap.get(snapname='core', key='refresh.timer').decode('utf-8')

    # The first time through, data_changed will be true. Subsequent calls
    # should only update leader data if something changed.
    if data_changed('snapd_refresh', timer):
        hookenv.log('setting leader snapd_refresh timer to: {}'.format(timer))
        leadership.leader_set({'snapd_refresh': timer})
示例#6
0
def change_snapd_refresh():
    """Set the system refresh.timer option"""
    ensure_snapd_min_version('2.31')
    timer = hookenv.config()['snapd_refresh']
    snap.set_refresh_timer(timer)
    reactive.set_flag('snap.refresh.set')