65598582f5
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=179
236 lines
9.3 KiB
Diff
236 lines
9.3 KiB
Diff
From 85464ec6c34fceee3379d268745c3294d27e7fb4 Mon Sep 17 00:00:00 2001
|
|
From: Steve Kowalik <steven@wedontsleep.org>
|
|
Date: Mon, 17 Feb 2020 15:34:00 +1100
|
|
Subject: [PATCH] Apply patch from upstream to support Python 3.8
|
|
|
|
Apply saltstack/salt#56031 to support Python 3.8, which removed a
|
|
deprecated module and changed some behaviour. Add a {Build,}Requires on
|
|
python-distro, since it is now required.
|
|
---
|
|
pkg/suse/salt.spec | 2 ++
|
|
salt/renderers/stateconf.py | 49 ++++++++++++++++---------------------
|
|
2 files changed, 23 insertions(+), 28 deletions(-)
|
|
|
|
diff --git a/pkg/suse/salt.spec b/pkg/suse/salt.spec
|
|
index a17d2381ce..0df9d6c283 100644
|
|
--- a/pkg/suse/salt.spec
|
|
+++ b/pkg/suse/salt.spec
|
|
@@ -62,6 +62,7 @@ BuildRequires: python-psutil
|
|
BuildRequires: python-requests >= 1.0.0
|
|
BuildRequires: python-tornado >= 4.2.1
|
|
BuildRequires: python-yaml
|
|
+BuildRequires: python-distro
|
|
# requirements/opt.txt (not all)
|
|
# BuildRequires: python-MySQL-python
|
|
# BuildRequires: python-timelib
|
|
@@ -112,6 +113,7 @@ Requires: python-psutil
|
|
Requires: python-requests >= 1.0.0
|
|
Requires: python-tornado >= 4.2.1
|
|
Requires: python-yaml
|
|
+Requires: python-distro
|
|
%if 0%{?suse_version}
|
|
# requirements/opt.txt (not all)
|
|
Recommends: python-MySQL-python
|
|
diff --git a/salt/renderers/stateconf.py b/salt/renderers/stateconf.py
|
|
index 298ae28338..f0527d51d7 100644
|
|
--- a/salt/renderers/stateconf.py
|
|
+++ b/salt/renderers/stateconf.py
|
|
@@ -1,4 +1,3 @@
|
|
-# -*- coding: utf-8 -*-
|
|
"""
|
|
A flexible renderer that takes a templating engine and a data format
|
|
|
|
@@ -26,8 +25,6 @@ A flexible renderer that takes a templating engine and a data format
|
|
# - apache: >= 0.1.0
|
|
#
|
|
|
|
-# Import python libs
|
|
-from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
import copy
|
|
import getopt
|
|
@@ -36,12 +33,9 @@ import os
|
|
import re
|
|
from itertools import chain
|
|
|
|
-# Import salt libs
|
|
import salt.utils.files
|
|
import salt.utils.stringutils
|
|
from salt.exceptions import SaltRenderError
|
|
-
|
|
-# Import 3rd-party libs
|
|
from salt.ext import six
|
|
from salt.ext.six.moves import StringIO # pylint: disable=import-error
|
|
|
|
@@ -135,7 +129,7 @@ def render(input, saltenv="base", sls="", argline="", **kws):
|
|
sid = has_names_decls(data)
|
|
if sid:
|
|
raise SaltRenderError(
|
|
- "'names' declaration(found in state id: {0}) is "
|
|
+ "'names' declaration(found in state id: {}) is "
|
|
"not supported with implicitly ordered states! You "
|
|
"should generate the states in a template for-loop "
|
|
"instead.".format(sid)
|
|
@@ -203,11 +197,11 @@ def render(input, saltenv="base", sls="", argline="", **kws):
|
|
name, rt_argline = (args[1] + " ").split(" ", 1)
|
|
render_template = renderers[name] # e.g., the mako renderer
|
|
except KeyError as err:
|
|
- raise SaltRenderError("Renderer: {0} is not available!".format(err))
|
|
+ raise SaltRenderError("Renderer: {} is not available!".format(err))
|
|
except IndexError:
|
|
raise INVALID_USAGE_ERROR
|
|
|
|
- if isinstance(input, six.string_types):
|
|
+ if isinstance(input, str):
|
|
with salt.utils.files.fopen(input, "r") as ifile:
|
|
sls_templ = salt.utils.stringutils.to_unicode(ifile.read())
|
|
else: # assume file-like
|
|
@@ -227,7 +221,7 @@ def render(input, saltenv="base", sls="", argline="", **kws):
|
|
prefix = sls + "::"
|
|
tmplctx = {
|
|
k[len(prefix) :] if k.startswith(prefix) else k: v
|
|
- for k, v in six.iteritems(tmplctx)
|
|
+ for k, v in tmplctx.items()
|
|
}
|
|
else:
|
|
tmplctx = {}
|
|
@@ -262,8 +256,8 @@ def rewrite_single_shorthand_state_decl(data): # pylint: disable=C0103
|
|
state_id_decl:
|
|
state.func: []
|
|
"""
|
|
- for sid, states in six.iteritems(data):
|
|
- if isinstance(states, six.string_types):
|
|
+ for sid, states in data.items():
|
|
+ if isinstance(states, str):
|
|
data[sid] = {states: []}
|
|
|
|
|
|
@@ -328,7 +322,7 @@ def nvlist(thelist, names=None):
|
|
for nvitem in thelist:
|
|
if isinstance(nvitem, dict):
|
|
# then nvitem is a name-value item(a dict) of the list.
|
|
- name, value = next(six.iteritems(nvitem))
|
|
+ name, value = next(iter(nvitem.items()))
|
|
if names is None or name in names:
|
|
yield nvitem, name, value
|
|
|
|
@@ -349,17 +343,16 @@ def nvlist2(thelist, names=None):
|
|
|
|
"""
|
|
for _, _, value in nvlist(thelist, names):
|
|
- for each in nvlist(value):
|
|
- yield each
|
|
+ yield from nvlist(value)
|
|
|
|
|
|
def statelist(states_dict, sid_excludes=frozenset(["include", "exclude"])):
|
|
- for sid, states in six.iteritems(states_dict):
|
|
+ for sid, states in states_dict.items():
|
|
if sid.startswith("__"):
|
|
continue
|
|
if sid in sid_excludes:
|
|
continue
|
|
- for sname, args in six.iteritems(states):
|
|
+ for sname, args in states.items():
|
|
if sname.startswith("__"):
|
|
continue
|
|
yield sid, states, sname, args
|
|
@@ -401,11 +394,11 @@ def rename_state_ids(data, sls, is_extend=False):
|
|
newsid = _local_to_abs_sid(sid, sls)
|
|
if newsid in data:
|
|
raise SaltRenderError(
|
|
- "Can't rename state id({0}) into {1} because the later "
|
|
+ "Can't rename state id({}) into {} because the later "
|
|
"already exists!".format(sid, newsid)
|
|
)
|
|
# add a '- name: sid' to those states without '- name'.
|
|
- for sname, args in six.iteritems(data[sid]):
|
|
+ for sname, args in data[sid].items():
|
|
if state_name(sname) == STATE_NAME:
|
|
continue
|
|
for arg in args:
|
|
@@ -430,7 +423,7 @@ EXTENDED_REQUIRE_IN = {}
|
|
# explicit require_in/watch_in/listen_in/onchanges_in/onfail_in can only contain states after it
|
|
def add_implicit_requires(data):
|
|
def T(sid, state): # pylint: disable=C0103
|
|
- return "{0}:{1}".format(sid, state_name(state))
|
|
+ return "{}:{}".format(sid, state_name(state))
|
|
|
|
states_before = set()
|
|
states_after = set()
|
|
@@ -462,7 +455,7 @@ def add_implicit_requires(data):
|
|
for _, rstate, rsid in reqs:
|
|
if T(rsid, rstate) in states_after:
|
|
raise SaltRenderError(
|
|
- "State({0}) can't require/watch/listen/onchanges/onfail a state({1}) defined "
|
|
+ "State({}) can't require/watch/listen/onchanges/onfail a state({}) defined "
|
|
"after it!".format(tag, T(rsid, rstate))
|
|
)
|
|
|
|
@@ -472,7 +465,7 @@ def add_implicit_requires(data):
|
|
for _, rstate, rsid in reqs:
|
|
if T(rsid, rstate) in states_before:
|
|
raise SaltRenderError(
|
|
- "State({0}) can't require_in/watch_in/listen_in/onchanges_in/onfail_in a state({1}) "
|
|
+ "State({}) can't require_in/watch_in/listen_in/onchanges_in/onfail_in a state({}) "
|
|
"defined before it!".format(tag, T(rsid, rstate))
|
|
)
|
|
|
|
@@ -492,7 +485,7 @@ def add_start_state(data, sls):
|
|
start_sid = __opts__["stateconf_start_state"]
|
|
if start_sid in data:
|
|
raise SaltRenderError(
|
|
- "Can't generate start state({0})! The same state id already "
|
|
+ "Can't generate start state({})! The same state id already "
|
|
"exists!".format(start_sid)
|
|
)
|
|
if not data:
|
|
@@ -502,14 +495,14 @@ def add_start_state(data, sls):
|
|
# no __sls__, or it's the first state whose id declaration has a
|
|
# __sls__ == sls.
|
|
non_sids = ("include", "exclude", "extend")
|
|
- for sid, states in six.iteritems(data):
|
|
+ for sid, states in data.items():
|
|
if sid in non_sids or sid.startswith("__"):
|
|
continue
|
|
if "__sls__" not in states or states["__sls__"] == sls:
|
|
break
|
|
else:
|
|
raise SaltRenderError("Can't determine the first state in the sls file!")
|
|
- reqin = {state_name(next(six.iterkeys(data[sid]))): sid}
|
|
+ reqin = {state_name(next(iter(data[sid].keys()))): sid}
|
|
data[start_sid] = {STATE_FUNC: [{"require_in": [reqin]}]}
|
|
|
|
|
|
@@ -517,7 +510,7 @@ def add_goal_state(data):
|
|
goal_sid = __opts__["stateconf_goal_state"]
|
|
if goal_sid in data:
|
|
raise SaltRenderError(
|
|
- "Can't generate goal state({0})! The same state id already "
|
|
+ "Can't generate goal state({})! The same state id already "
|
|
"exists!".format(goal_sid)
|
|
)
|
|
else:
|
|
@@ -561,7 +554,7 @@ STATE_CONF_EXT = {} # stateconf.set under extend: ...
|
|
|
|
|
|
def extract_state_confs(data, is_extend=False):
|
|
- for state_id, state_dict in six.iteritems(data):
|
|
+ for state_id, state_dict in data.items():
|
|
if state_id == "extend" and not is_extend:
|
|
extract_state_confs(state_dict, True)
|
|
continue
|
|
@@ -578,7 +571,7 @@ def extract_state_confs(data, is_extend=False):
|
|
for sdk in state_dict[key]:
|
|
if not isinstance(sdk, dict):
|
|
continue
|
|
- key, val = next(six.iteritems(sdk))
|
|
+ key, val = next(iter(sdk.items()))
|
|
conf[key] = val
|
|
|
|
if not is_extend and state_id in STATE_CONF_EXT:
|
|
--
|
|
2.29.2
|
|
|
|
|