mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #20210 from rallytime/bp-20171
Backport #20171 to 2014.7
This commit is contained in:
commit
8598559bfd
@ -867,6 +867,7 @@ ARGS = {9}\n'''.format(self.minion_config,
|
||||
# RSTR was found in stdout but not stderr - which means there
|
||||
# is a SHIM command for the master.
|
||||
shim_command = re.split(r'\r?\n', stdout, 1)[0].strip()
|
||||
log.debug('SHIM retcode({0}) and command: {1}'.format(retcode, shim_command))
|
||||
if 'deploy' == shim_command and retcode == salt.exitcodes.EX_THIN_DEPLOY:
|
||||
self.deploy()
|
||||
stdout, stderr, retcode = self.shim_cmd(cmd_str)
|
||||
|
@ -25,14 +25,24 @@ EX_MOD_DEPLOY = 13
|
||||
|
||||
|
||||
class OBJ(object):
|
||||
"""An empty class for holding instance attribute values."""
|
||||
pass
|
||||
|
||||
|
||||
OPTIONS = None
|
||||
ARGS = None
|
||||
# The below line is where OPTIONS can be redefined with internal options
|
||||
# (rather than cli arguments) when the shim is bundled by
|
||||
# client.ssh.Single._cmd_str()
|
||||
# pylint: disable=block-comment-should-start-with-'# '
|
||||
#%%OPTS
|
||||
|
||||
|
||||
def need_deployment():
|
||||
"""
|
||||
Salt thin needs to be deployed - prep the target directory and emit the
|
||||
delimeter and exit code that signals a required deployment.
|
||||
"""
|
||||
if os.path.exists(OPTIONS.saltdir):
|
||||
shutil.rmtree(OPTIONS.saltdir)
|
||||
old_umask = os.umask(0077)
|
||||
@ -51,8 +61,8 @@ def need_deployment():
|
||||
sudo_gid = os.environ.get('SUDO_GID')
|
||||
if sudo_gid:
|
||||
os.chown(OPTIONS.saltdir, -1, int(sudo_gid))
|
||||
st = os.stat(OPTIONS.saltdir)
|
||||
os.chmod(OPTIONS.saltdir, st.st_mode | stat.S_IWGRP | stat.S_IRGRP | stat.S_IXGRP)
|
||||
stt = os.stat(OPTIONS.saltdir)
|
||||
os.chmod(OPTIONS.saltdir, stt.st_mode | stat.S_IWGRP | stat.S_IRGRP | stat.S_IXGRP)
|
||||
|
||||
# Delimeter emitted on stdout *only* to indicate shim message to master.
|
||||
sys.stdout.write("{0}\ndeploy\n".format(OPTIONS.delimiter))
|
||||
@ -61,6 +71,7 @@ def need_deployment():
|
||||
|
||||
# Adapted from salt.utils.get_hash()
|
||||
def get_hash(path, form='sha1', chunk_size=4096):
|
||||
"""Generate a hash digest string for a file."""
|
||||
try:
|
||||
hash_type = getattr(hashlib, form)
|
||||
except AttributeError:
|
||||
@ -74,6 +85,7 @@ def get_hash(path, form='sha1', chunk_size=4096):
|
||||
|
||||
|
||||
def unpack_thin(thin_path):
|
||||
"""Unpack the Salt thin archive."""
|
||||
tfile = tarfile.TarFile.gzopen(thin_path)
|
||||
tfile.extractall(path=OPTIONS.saltdir)
|
||||
tfile.close()
|
||||
@ -81,11 +93,13 @@ def unpack_thin(thin_path):
|
||||
|
||||
|
||||
def need_ext():
|
||||
"""Signal that external modules need to be deployed."""
|
||||
sys.stdout.write("{0}\next_mods\n".format(OPTIONS.delimiter))
|
||||
sys.exit(EX_MOD_DEPLOY)
|
||||
|
||||
|
||||
def unpack_ext(ext_path):
|
||||
"""Unpack the external modules."""
|
||||
modcache = os.path.join(
|
||||
OPTIONS.saltdir,
|
||||
'running_data',
|
||||
@ -103,7 +117,8 @@ def unpack_ext(ext_path):
|
||||
shutil.move(ver_path, ver_dst)
|
||||
|
||||
|
||||
def main(argv):
|
||||
def main(argv): # pylint: disable=W0613
|
||||
"""Main program body"""
|
||||
thin_path = os.path.join(OPTIONS.saltdir, THIN_ARCHIVE)
|
||||
if os.path.isfile(thin_path):
|
||||
if OPTIONS.checksum != get_hash(thin_path, OPTIONS.hashfunc):
|
||||
@ -119,17 +134,28 @@ def main(argv):
|
||||
need_deployment()
|
||||
|
||||
if not os.path.isdir(OPTIONS.saltdir):
|
||||
sys.stderr.write('ERROR: salt path "{0}" exists but is not a directory\n'.format(OPTIONS.saltdir))
|
||||
sys.stderr.write(
|
||||
'ERROR: salt path "{0}" exists but is'
|
||||
' not a directory\n'.format(OPTIONS.saltdir)
|
||||
)
|
||||
sys.exit(os.EX_CANTCREAT)
|
||||
|
||||
version_path = os.path.join(OPTIONS.saltdir, 'version')
|
||||
if not os.path.exists(version_path) or not os.path.isfile(version_path):
|
||||
sys.stderr.write('WARNING: Unable to locate current thin version.\n')
|
||||
sys.stderr.write(
|
||||
'WARNING: Unable to locate current thin '
|
||||
' version: {0}.\n'.format(version_path)
|
||||
)
|
||||
need_deployment()
|
||||
with open(version_path, 'r') as vpo:
|
||||
cur_version = vpo.readline().strip()
|
||||
if cur_version != OPTIONS.version:
|
||||
sys.stderr.write('WARNING: current thin version is not up-to-date.\n')
|
||||
sys.stderr.write(
|
||||
'WARNING: current thin version {0}'
|
||||
' is not up-to-date with {1}.\n'.format(
|
||||
cur_version, OPTIONS.version
|
||||
)
|
||||
)
|
||||
need_deployment()
|
||||
# Salt thin exists and is up-to-date - fall through and use it
|
||||
|
||||
@ -179,7 +205,7 @@ def main(argv):
|
||||
sys.stderr.flush()
|
||||
if OPTIONS.tty:
|
||||
import subprocess
|
||||
stdout, stderr = subprocess.Popen(salt_argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
stdout, _ = subprocess.Popen(salt_argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
sys.stdout.write(stdout)
|
||||
sys.stdout.flush()
|
||||
if OPTIONS.wipe:
|
||||
|
Loading…
Reference in New Issue
Block a user