Commit 81ca71cb authored by Julien Muchembled's avatar Julien Muchembled

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.
parent f6aa1348
......@@ -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]
#!%(python_path)s
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
import socket
import sys
hostname = "%(hostname)s"
port = %(port)s
try:
s = socket.create_connection((hostname, port))
s.close()
except (socket.error, socket.timeout):
sys.stderr.write("%(port)s on %(hostname)s isn't listening\n")
sys.exit(127)
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