Commit dad1f246 authored by Marco Mariani's avatar Marco Mariani

simpler, more robust PBS promise

parent 9cc71e98
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
# #
############################################################################## ##############################################################################
from hashlib import sha512 import hashlib
import inspect
import json import json
import os import os
import signal import signal
...@@ -43,33 +42,14 @@ from slapos import slap as slapmodule ...@@ -43,33 +42,14 @@ from slapos import slap as slapmodule
def promise(args): def promise(args):
def failed_ssh(partition, ssh): def failed_ssh():
sys.stderr.write("SSH Connection failed\n") sys.stderr.write("SSH Connection failed\n")
try: partition = slap.registerComputerPartition(args['computer_id'],
ssh.terminate() args['partition_id'])
except:
pass
partition.bang("SSH Connection failed. rdiff-backup is unusable.") partition.bang("SSH Connection failed. rdiff-backup is unusable.")
def sigterm_handler(signum, frame): def sigterm_handler(signum, frame):
# Walk up in the stack to get promise local failed_ssh()
# variables
ssh = None
for upper_frame in inspect.getouterframes(frame):
# Use promise.func_name insteand of 'promise' in order to be
# detected by editor if promise func name change.
# Else, it's hard to debug this kind of error.
if upper_frame[3] == promise.func_name:
try:
partition = upper_frame[0].f_locals['partition']
ssh = upper_frame[0].f_locals['ssh']
except KeyError:
raise SystemExit("SIGTERM Send too soon.")
break
# If ever promise function wasn't found in the stack.
if ssh is None:
raise SystemExit
failed_ssh(partition, ssh)
signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGTERM, sigterm_handler)
...@@ -78,9 +58,6 @@ def promise(args): ...@@ -78,9 +58,6 @@ def promise(args):
key_file=args.get('key_file'), key_file=args.get('key_file'),
cert_file=args.get('cert_file')) cert_file=args.get('cert_file'))
partition = slap.registerComputerPartition(args['computer_id'],
args['partition_id'])
ssh = subprocess.Popen([args['ssh_client'], '%(user)s@%(host)s/%(port)s' % args], ssh = subprocess.Popen([args['ssh_client'], '%(user)s@%(host)s/%(port)s' % args],
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=open(os.devnull, 'w'), stdout=open(os.devnull, 'w'),
...@@ -97,7 +74,8 @@ def promise(args): ...@@ -97,7 +74,8 @@ def promise(args):
if ssh.poll() is None: if ssh.poll() is None:
return 1 return 1
if ssh.returncode != 0: if ssh.returncode != 0:
failed_ssh(partition, ssh) ssh.terminate()
failed_ssh()
return ssh.returncode return ssh.returncode
...@@ -112,8 +90,8 @@ class Recipe(GenericSlapRecipe, Notify, Callback): ...@@ -112,8 +90,8 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
url = '' url = ''
# We assume that thanks to sha512 there's no collisions # We assume that thanks to sha512 there's no collisions
url_hash = sha512(url).hexdigest() url_hash = hashlib.sha512(url).hexdigest()
name_hash = sha512(entry['name']).hexdigest() name_hash = hashlib.sha512(entry['name']).hexdigest()
promise_path = os.path.join(self.options['promises-directory'], promise_path = os.path.join(self.options['promises-directory'],
url_hash) url_hash)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment