From f2e6df7448f8e63aa4b05652bfa2ddb92f878832 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sun, 21 May 2023 10:42:09 +0200 Subject: [PATCH] Implement test.ping Wait for minions to respond to test.ping before attempting a state.apply. Signed-off-by: Georg Pfuetzenreuter --- scullery.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scullery.py b/scullery.py index 3c19048..2ccaef3 100755 --- a/scullery.py +++ b/scullery.py @@ -141,11 +141,21 @@ def vagrant_sshconfig(outfile): with open(outfile, 'w') as fh: fh.write(ssh_config) -def runapply(state, target): +def _saltcmd(target): if target == 'local': saltcmd = 'salt-call --local' else: - saltcmd = 'salt {}'.format(target) + saltcmd = 'salt -t10 {}'.format(target) + return saltcmd + +def runping(target): + saltcmd = _saltcmd(target) + sshout = v.ssh(command='sudo {} test.ping'.format(saltcmd)) + log.info('\n{}\n'.format(str(sshout))) + return sshout + +def runapply(state, target): + saltcmd = _saltcmd(target) sshout = v.ssh(command='sudo {} state.apply {}'.format(saltcmd, state)) log.info('\n{}\n'.format(str(sshout))) @@ -241,6 +251,11 @@ def main_interactive(): log.debug('state.apply requested') if masters is not None: target = 'scullery-*' + count = 0 + while not runping(target): + if count == 5: + _abort('Unable to reach minions') + count += 1 else: target = 'local' runapply(testconf['apply'], target)