Fix ssh mux socket file error.

ssh ControlPath socket file needs to be unique for each host.
To avoid using ssh ControlPath option placeholders move socket file
to host's temp directory. Since each host has unique temp
directory then, although file name for socket file is fixed, its path
is unique.
This commit is contained in:
Darko Poljak 2016-07-23 16:13:59 +02:00
commit 6f28fc2db2
9 changed files with 221 additions and 160 deletions

View file

@ -29,7 +29,6 @@ import subprocess
import shutil
import logging
import tempfile
import hashlib
import cdist
import cdist.message
@ -48,40 +47,25 @@ class Local(object):
"""
def __init__(self,
target_host,
base_root_path,
host_dir_name,
exec_path=sys.argv[0],
initial_manifest=None,
base_path=None,
add_conf_dirs=None):
self.target_host = target_host
self._init_log()
# FIXME: stopped: create base that does not require moving later
if base_path:
base_path_parent = base_path
else:
base_path_parent = tempfile.mkdtemp()
# TODO: the below atexit hook nukes any debug info we would have
# if cdist exits with error.
# import atexit
# atexit.register(lambda: shutil.rmtree(base_path_parent))
self.hostdir = self._hostdir()
self.log.info("Calculated temp dir for target \"{}\" is "
"\"{}\"".format(self.target_host, self.hostdir))
self.base_path = os.path.join(base_path_parent, self.hostdir)
self._init_permissions()
self.mkdir(self.base_path)
# FIXME: as well
self._init_cache_dir(None)
self.hostdir = host_dir_name
self.base_path = os.path.join(base_root_path, "data")
self.exec_path = exec_path
self.custom_initial_manifest = initial_manifest
self._add_conf_dirs = add_conf_dirs
self._init_log()
self._init_permissions()
self.mkdir(self.base_path)
# FIXME: create dir that does not require moving later
self._init_cache_dir(None)
self._init_paths()
self._init_object_marker()
self._init_conf_dirs()
@ -98,12 +82,6 @@ class Local(object):
else:
return None
def _hostdir(self):
# Do not assume target_host is anything that can be used as a
# directory name.
# Instead use a hash, which is known to work as directory name.
return hashlib.md5(self.target_host.encode('utf-8')).hexdigest()
def _init_log(self):
self.log = logging.getLogger(self.target_host)