check_port_listening: workaround for sheband limitation, reduce to a single file
The whole code is small enough and having the template in a separate file only made editing more annoying.
... | ... | @@ -26,24 +26,34 @@ |
# | ||
############################################################################## | ||
from slapos.recipe.librecipe import GenericBaseRecipe | ||
from zc.buildout.easy_install import _safe_arg, script_header | ||
import sys | ||
template = script_header + r""" | ||
|
||
# BEWARE: This file is operated by slapgrid | ||
# BEWARE: It will be overwritten automatically | ||
import socket | ||
import sys | ||
addr = "%(hostname)s", %(port)s | ||
try: | ||
socket.create_connection(addr).close() | ||
except (socket.error, socket.timeout): | ||
sys.stderr.write("%%s on %%s isn't listening\n" %% addr) | ||
sys.exit(127) | ||
""" | ||
class Recipe(GenericBaseRecipe): | ||
""" | ||
Check listening port promise | ||
""" | ||
def install(self): | ||
config = dict( | ||
hostname=self.options['hostname'], | ||
port=self.options['port'], | ||
python_path=sys.executable, | ||
) | ||
vnc_promise = self.createExecutable( | ||
self.options['path'], | ||
self.substituteTemplate( | ||
self.getTemplateFilename('socket_connection_attempt.py.in'), | ||
config)) | ||
promise = self.createExecutable(self.options['path'], template % { | ||
'python': _safe_arg(sys.executable), | ||
'hostname': self.options['hostname'], | ||
'port': self.options['port'], | ||
}) | ||
return [vnc_promise] | ||
return [promise] |