Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken ssh slow tests #59098

Merged
merged 7 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions salt/client/ssh/wrapper/cp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-
"""
Wrap the cp module allowing for managed ssh file transfers
"""
# Import Python libs
from __future__ import absolute_import, print_function

import logging
import os

# Import salt libs
import salt.client.ssh
import salt.utils.files
import salt.utils.stringutils
Expand Down Expand Up @@ -107,13 +103,13 @@ def _render_filenames(path, dest, saltenv, template):
if template not in salt.utils.templates.TEMPLATE_REGISTRY:
raise CommandExecutionError(
"Attempted to render file paths with unavailable engine "
"{0}".format(template)
"{}".format(template)
)

kwargs = {}
kwargs["salt"] = __salt__
kwargs["pillar"] = __pillar__
kwargs["grains"] = __grains__
kwargs["salt"] = __salt__.value()
kwargs["pillar"] = __pillar__.value()
kwargs["grains"] = __grains__.value()
kwargs["opts"] = __opts__
kwargs["saltenv"] = saltenv

Expand All @@ -133,7 +129,7 @@ def _render(contents):
if not data["result"]:
# Failed to render the template
raise CommandExecutionError(
"Failed to render file path with error: {0}".format(data["data"])
"Failed to render file path with error: {}".format(data["data"])
)
else:
return data["data"]
Expand Down
30 changes: 11 additions & 19 deletions salt/client/ssh/wrapper/grains.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
# -*- coding: utf-8 -*-
"""
Return/control aspects of the grains data
"""

from __future__ import absolute_import, print_function

import copy
import math
from collections.abc import Mapping

import salt.utils.data
import salt.utils.dictupdate
import salt.utils.json
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.exceptions import SaltException
from salt.ext import six

try:
# Python 3
from collections.abc import Mapping
except ImportError:
# We still allow Py2 import because this could be executed in a machine with Py2.
from collections import Mapping # pylint: disable=no-name-in-module


# Seed the grains dict so cython will build
__grains__ = {}
Expand All @@ -33,7 +23,7 @@ def _serial_sanitizer(instr):
"""
length = len(instr)
index = int(math.floor(length * 0.75))
return "{0}{1}".format(instr[:index], "X" * (length - index))
return "{}{}".format(instr[:index], "X" * (length - index))


_FQDN_SANITIZER = lambda x: "MINION.DOMAINNAME"
Expand Down Expand Up @@ -76,10 +66,12 @@ def get(key, default="", delimiter=DEFAULT_TARGET_DELIM, ordered=True):
salt '*' grains.get pkg:apache
"""
if ordered is True:
grains = __grains__
grains = __grains__.value()
else:
grains = salt.utils.json.loads(salt.utils.json.dumps(__grains__))
return salt.utils.data.traverse_dict_and_list(__grains__, key, default, delimiter)
grains = salt.utils.json.loads(salt.utils.json.dumps(__grains__.value()))
return salt.utils.data.traverse_dict_and_list(
__grains__.value(), key, default, delimiter
)


def has_value(key):
Expand Down Expand Up @@ -124,13 +116,13 @@ def items(sanitize=False):
salt '*' grains.items sanitize=True
"""
if salt.utils.data.is_true(sanitize):
out = dict(__grains__)
for key, func in six.iteritems(_SANITIZERS):
out = dict(__grains__.value())
for key, func in _SANITIZERS.items():
if key in out:
out[key] = func(out[key])
return out
else:
return __grains__
return __grains__.value()


def item(*args, **kwargs):
Expand All @@ -157,7 +149,7 @@ def item(*args, **kwargs):
except KeyError:
pass
if salt.utils.data.is_true(kwargs.get("sanitize")):
for arg, func in six.iteritems(_SANITIZERS):
for arg, func in _SANITIZERS.items():
if arg in ret:
ret[arg] = func(ret[arg])
return ret
Expand Down
21 changes: 12 additions & 9 deletions salt/client/ssh/wrapper/pillar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
"""
Extract the pillar data for this minion
"""
from __future__ import absolute_import, print_function

# Import salt libs
import salt.pillar
import salt.utils.data
import salt.utils.dictupdate
Expand Down Expand Up @@ -56,11 +53,15 @@ def get(key, default="", merge=False, delimiter=DEFAULT_TARGET_DELIM):
salt '*' pillar.get pkg:apache
"""
if merge:
ret = salt.utils.data.traverse_dict_and_list(__pillar__, key, {}, delimiter)
ret = salt.utils.data.traverse_dict_and_list(
__pillar__.value(), key, {}, delimiter
)
if isinstance(ret, Mapping) and isinstance(default, Mapping):
return salt.utils.dictupdate.update(default, ret)

return salt.utils.data.traverse_dict_and_list(__pillar__, key, default, delimiter)
return salt.utils.data.traverse_dict_and_list(
__pillar__.value(), key, default, delimiter
)


def item(*args):
Expand Down Expand Up @@ -104,7 +105,7 @@ def raw(key=None):
if key:
ret = __pillar__.get(key, {})
else:
ret = __pillar__
ret = __pillar__.value()

return ret

Expand All @@ -127,13 +128,15 @@ def keys(key, delimiter=DEFAULT_TARGET_DELIM):

salt '*' pillar.keys web:sites
"""
ret = salt.utils.data.traverse_dict_and_list(__pillar__, key, KeyError, delimiter)
ret = salt.utils.data.traverse_dict_and_list(
__pillar__.value(), key, KeyError, delimiter
)

if ret is KeyError:
raise KeyError("Pillar key not found: {0}".format(key))
raise KeyError("Pillar key not found: {}".format(key))

if not isinstance(ret, dict):
raise ValueError("Pillar value in key {0} is not a dict".format(key))
raise ValueError("Pillar value in key {} is not a dict".format(key))

return ret.keys()

Expand Down
60 changes: 33 additions & 27 deletions salt/client/ssh/wrapper/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def _ssh_state(chunks, st_kwargs, kwargs, test=False):
)
# Create the tar containing the state pkg and relevant files.
trans_tar = salt.client.ssh.state.prep_trans_tar(
__context__["fileclient"], chunks, file_refs, __pillar__, st_kwargs["id_"]
__context__["fileclient"],
chunks,
file_refs,
__pillar__.value(),
st_kwargs["id_"],
)
trans_tar_sum = salt.utils.hashutils.get_hash(trans_tar, __opts__["hash_type"])
cmd = "state.pkg {}/salt_state.tgz test={} pkg_sum={} hash_type={}".format(
Expand Down Expand Up @@ -98,7 +102,7 @@ def _check_pillar(kwargs, pillar=None):
"""
if kwargs.get("force"):
return True
pillar_dict = pillar if pillar is not None else __pillar__
pillar_dict = pillar if pillar is not None else __pillar__.value()
if "_errors" in pillar_dict:
return False
return True
Expand Down Expand Up @@ -168,15 +172,17 @@ def sls(mods, saltenv="base", test=None, exclude=None, **kwargs):
Create the seed file for a state.sls run
"""
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
__pillar__.update(kwargs.get("pillar", {}))
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__.value(), __context__["fileclient"]
)
st_.push_active()
mods = _parse_mods(mods)
high_data, errors = st_.render_highstate({saltenv: mods}, context=__context__)
high_data, errors = st_.render_highstate(
{saltenv: mods}, context=__context__.value()
)
if exclude:
if isinstance(exclude, str):
exclude = exclude.split(",")
Expand Down Expand Up @@ -213,7 +219,7 @@ def sls(mods, saltenv="base", test=None, exclude=None, **kwargs):
__context__["fileclient"],
chunks,
file_refs,
__pillar__,
__pillar__.value(),
st_kwargs["id_"],
roster_grains,
)
Expand Down Expand Up @@ -331,10 +337,10 @@ def low(data, **kwargs):
salt '*' state.low '{"state": "pkg", "fun": "installed", "name": "vi"}'
"""
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
chunks = [data]
st_ = salt.client.ssh.state.SSHHighState(
__opts__, __pillar__, __salt__, __context__["fileclient"]
__opts__, __pillar__.value(), __salt__.value(), __context__["fileclient"]
)
for chunk in chunks:
chunk["__id__"] = chunk["name"] if not chunk.get("__id__") else chunk["__id__"]
Expand All @@ -355,7 +361,7 @@ def low(data, **kwargs):
__context__["fileclient"],
chunks,
file_refs,
__pillar__,
__pillar__.value(),
st_kwargs["id_"],
roster_grains,
)
Expand Down Expand Up @@ -418,10 +424,10 @@ def high(data, **kwargs):
"""
__pillar__.update(kwargs.get("pillar", {}))
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__.value(), __context__["fileclient"]
)
st_.push_active()
chunks = st_.state.compile_high_data(data)
Expand All @@ -441,7 +447,7 @@ def high(data, **kwargs):
__context__["fileclient"],
chunks,
file_refs,
__pillar__,
__pillar__.value(),
st_kwargs["id_"],
roster_grains,
)
Expand Down Expand Up @@ -654,10 +660,10 @@ def highstate(test=None, **kwargs):
"""
__pillar__.update(kwargs.get("pillar", {}))
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__.value(), __context__["fileclient"]
)
st_.push_active()
chunks = st_.compile_low_chunks()
Expand All @@ -682,7 +688,7 @@ def highstate(test=None, **kwargs):
__context__["fileclient"],
chunks,
file_refs,
__pillar__,
__pillar__.value(),
st_kwargs["id_"],
roster_grains,
)
Expand Down Expand Up @@ -731,7 +737,7 @@ def top(topfn, test=None, **kwargs):
"""
__pillar__.update(kwargs.get("pillar", {}))
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
if salt.utils.args.test_mode(test=test, **kwargs):
opts["test"] = True
Expand Down Expand Up @@ -804,7 +810,7 @@ def show_highstate(**kwargs):

salt '*' state.show_highstate
"""
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
Expand All @@ -825,10 +831,10 @@ def show_lowstate(**kwargs):

salt '*' state.show_lowstate
"""
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__, __context__["fileclient"]
)
st_.push_active()
chunks = st_.compile_low_chunks()
Expand Down Expand Up @@ -883,7 +889,7 @@ def sls_id(id_, mods, test=None, queue=False, **kwargs):
opts["saltenv"] = "base"

st_ = salt.client.ssh.state.SSHHighState(
__opts__, __pillar__, __salt__, __context__["fileclient"]
__opts__, __pillar__.value(), __salt__, __context__["fileclient"]
)

if not _check_pillar(kwargs, st_.opts["pillar"]):
Expand Down Expand Up @@ -934,14 +940,14 @@ def show_sls(mods, saltenv="base", test=None, **kwargs):
salt '*' state.show_sls core,edit.vim dev
"""
__pillar__.update(kwargs.get("pillar", {}))
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
if salt.utils.args.test_mode(test=test, **kwargs):
opts["test"] = True
else:
opts["test"] = __opts__.get("test", None)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__, __context__["fileclient"]
)
st_.push_active()
mods = _parse_mods(mods)
Expand Down Expand Up @@ -975,15 +981,15 @@ def show_low_sls(mods, saltenv="base", test=None, **kwargs):
salt '*' state.show_sls core,edit.vim dev
"""
__pillar__.update(kwargs.get("pillar", {}))
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()

opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
if salt.utils.args.test_mode(test=test, **kwargs):
opts["test"] = True
else:
opts["test"] = __opts__.get("test", None)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__, __context__["fileclient"]
)
st_.push_active()
mods = _parse_mods(mods)
Expand Down Expand Up @@ -1017,7 +1023,7 @@ def show_top(**kwargs):
__opts__["grains"] = __grains__
opts = salt.utils.state.get_sls_opts(__opts__, **kwargs)
st_ = salt.client.ssh.state.SSHHighState(
opts, __pillar__, __salt__, __context__["fileclient"]
opts, __pillar__.value(), __salt__, __context__["fileclient"]
)
top_data = st_.get_top()
errors = []
Expand Down Expand Up @@ -1048,7 +1054,7 @@ def single(fun, name, test=None, **kwargs):

"""
st_kwargs = __salt__.kwargs
__opts__["grains"] = __grains__
__opts__["grains"] = __grains__.value()

# state.fun -> [state, fun]
comps = fun.split(".")
Expand Down Expand Up @@ -1099,7 +1105,7 @@ def single(fun, name, test=None, **kwargs):
__context__["fileclient"],
chunks,
file_refs,
__pillar__,
__pillar__.value(),
st_kwargs["id_"],
roster_grains,
)
Expand Down
Loading