Merge branch '2019.2' into merge-2019.2

This commit is contained in:
Megan Wilhite 2019-02-19 11:02:29 -05:00 committed by GitHub
commit b46eac3ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 8 deletions

View File

@ -56,7 +56,7 @@ def _parse_image_meta(image=None, detail=False):
if image and 'Error' in image:
ret = image
elif image:
elif image and 'manifest' in image:
name = image['manifest']['name']
version = image['manifest']['version']
os = image['manifest']['os']
@ -164,6 +164,8 @@ def docker_to_uuid(uuid):
if _is_docker_uuid(uuid):
images = list_installed(verbose=True)
for image_uuid in images:
if 'name' not in images[image_uuid]:
continue
if images[image_uuid]['name'] == uuid:
return image_uuid
return None

View File

@ -320,6 +320,20 @@ def _get_supported_py_config(tops, extended_cfg):
return salt.utils.stringutils.to_bytes(os.linesep.join(pymap))
def _get_thintar_prefix(tarname):
'''
Make sure thintar temporary name is concurrent and secure.
:param tarname: name of the chosen tarball
:return: prefixed tarname
'''
tfd, tmp_tarname = tempfile.mkstemp(dir=os.path.dirname(tarname), prefix=".thin-",
suffix="." + os.path.basename(tarname).split(".", 1)[-1])
os.close(tfd)
return tmp_tarname
def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods='',
python2_bin='python2', python3_bin='python3', absonly=True,
compress='gzip', extended_cfg=None):
@ -438,10 +452,11 @@ def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods='',
with salt.utils.files.fopen(pymap_cfg, 'wb') as fp_:
fp_.write(_get_supported_py_config(tops=tops_py_version_mapping, extended_cfg=extended_cfg))
tmp_thintar = _get_thintar_prefix(thintar)
if compress == 'gzip':
tfp = tarfile.open(thintar, 'w:gz', dereference=True)
tfp = tarfile.open(tmp_thintar, 'w:gz', dereference=True)
elif compress == 'zip':
tfp = zipfile.ZipFile(thintar, 'w', compression=zlib and zipfile.ZIP_DEFLATED or zipfile.ZIP_STORED)
tfp = zipfile.ZipFile(tmp_thintar, 'w', compression=zlib and zipfile.ZIP_DEFLATED or zipfile.ZIP_STORED)
tfp.add = tfp.write
try: # cwd may not exist if it was removed but salt was run from it
@ -541,6 +556,8 @@ def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods='',
os.chdir(start_dir)
tfp.close()
shutil.move(tmp_thintar, thintar)
return thintar

View File

@ -443,7 +443,8 @@ class SSHThinTestCase(TestCase):
@patch('salt.utils.thin.zipfile', MagicMock())
@patch('salt.utils.thin.os.getcwd', MagicMock())
@patch('salt.utils.thin.os.chdir', MagicMock())
@patch('salt.utils.thin.tempfile', MagicMock())
@patch('salt.utils.thin.tempfile.mkdtemp', MagicMock())
@patch('salt.utils.thin.tempfile.mkstemp', MagicMock(return_value=(3, ".temporary")))
@patch('salt.utils.thin.shutil', MagicMock())
@patch('salt.utils.thin._six.PY3', True)
@patch('salt.utils.thin._six.PY2', False)
@ -482,7 +483,9 @@ class SSHThinTestCase(TestCase):
@patch('salt.utils.thin.zipfile', MagicMock())
@patch('salt.utils.thin.os.getcwd', MagicMock())
@patch('salt.utils.thin.os.chdir', MagicMock())
@patch('salt.utils.thin.tempfile', MagicMock(mkdtemp=MagicMock(return_value='')))
@patch('salt.utils.thin.os.close', MagicMock())
@patch('salt.utils.thin.tempfile.mkdtemp', MagicMock(return_value=''))
@patch('salt.utils.thin.tempfile.mkstemp', MagicMock(return_value=(3, ".temporary")))
@patch('salt.utils.thin.shutil', MagicMock())
@patch('salt.utils.thin._six.PY3', True)
@patch('salt.utils.thin._six.PY2', False)
@ -496,7 +499,7 @@ class SSHThinTestCase(TestCase):
'''
thin.gen_thin('')
arc_name, arc_mode = thin.tarfile.method_calls[0][1]
self.assertEqual(arc_name, os.path.join('thin', 'thin.tgz'))
self.assertEqual(arc_name, ".temporary")
self.assertEqual(arc_mode, 'w:gz')
for idx, fname in enumerate(['version', '.thin-gen-py-version', 'salt-call', 'supported-versions']):
name = thin.tarfile.open().method_calls[idx + 4][1][0]
@ -524,7 +527,9 @@ class SSHThinTestCase(TestCase):
@patch('salt.utils.thin.zipfile', MagicMock())
@patch('salt.utils.thin.os.getcwd', MagicMock())
@patch('salt.utils.thin.os.chdir', MagicMock())
@patch('salt.utils.thin.tempfile', MagicMock())
@patch('salt.utils.thin.os.close', MagicMock())
@patch('salt.utils.thin.tempfile.mkdtemp', MagicMock(return_value=''))
@patch('salt.utils.thin.tempfile.mkstemp', MagicMock(return_value=(3, ".temporary")))
@patch('salt.utils.thin.shutil', MagicMock())
@patch('salt.utils.thin._six.PY3', True)
@patch('salt.utils.thin._six.PY2', False)
@ -574,7 +579,9 @@ class SSHThinTestCase(TestCase):
@patch('salt.utils.thin.zipfile', MagicMock())
@patch('salt.utils.thin.os.getcwd', MagicMock())
@patch('salt.utils.thin.os.chdir', MagicMock())
@patch('salt.utils.thin.tempfile', MagicMock(mkdtemp=MagicMock(return_value='')))
@patch('salt.utils.thin.os.close', MagicMock())
@patch('salt.utils.thin.tempfile.mkdtemp', MagicMock(return_value=''))
@patch('salt.utils.thin.tempfile.mkstemp', MagicMock(return_value=(3, ".temporary")))
@patch('salt.utils.thin.shutil', MagicMock())
@patch('salt.utils.thin._six.PY3', True)
@patch('salt.utils.thin._six.PY2', False)