From acbadee709aabf368368ae9ce503164650daa46d Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 18 Sep 2019 17:59:17 -0700 Subject: [PATCH 1/3] Porting PR #49634 to 2019.2.1 --- salt/client/ssh/wrapper/state.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/salt/client/ssh/wrapper/state.py b/salt/client/ssh/wrapper/state.py index b4272e4b55b4..3f1cead4b169 100644 --- a/salt/client/ssh/wrapper/state.py +++ b/salt/client/ssh/wrapper/state.py @@ -167,6 +167,16 @@ def _cleanup_slsmod_high_data(high_data): stateconf_data['slsmod'] = None +def _parse_mods(mods): + ''' + Parse modules. + ''' + if isinstance(mods, six.string_types): + mods = [item.strip() for item in mods.split(',') if item.strip()] + + return mods + + def sls(mods, saltenv='base', test=None, exclude=None, **kwargs): ''' Create the seed file for a state.sls run @@ -181,8 +191,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs): __salt__, __context__['fileclient']) st_.push_active() - if isinstance(mods, six.string_types): - mods = mods.split(',') + mods = _parse_mods(mods) high_data, errors = st_.render_highstate({saltenv: mods}) if exclude: if isinstance(exclude, six.string_types): @@ -922,8 +931,7 @@ def sls_id(id_, mods, test=None, queue=False, **kwargs): err += __pillar__['_errors'] return err - if isinstance(mods, six.string_types): - split_mods = mods.split(',') + split_mods = _parse_mods(mods) st_.push_active() high_, errors = st_.render_highstate({opts['saltenv']: split_mods}) errors += st_.state.verify_high(high_) @@ -980,8 +988,7 @@ def show_sls(mods, saltenv='base', test=None, **kwargs): __salt__, __context__['fileclient']) st_.push_active() - if isinstance(mods, six.string_types): - mods = mods.split(',') + mods = _parse_mods(mods) high_data, errors = st_.render_highstate({saltenv: mods}) high_data, ext_errors = st_.state.reconcile_extend(high_data) errors += ext_errors @@ -1025,8 +1032,7 @@ def show_low_sls(mods, saltenv='base', test=None, **kwargs): __salt__, __context__['fileclient']) st_.push_active() - if isinstance(mods, six.string_types): - mods = mods.split(',') + mods = _parse_mods(mods) high_data, errors = st_.render_highstate({saltenv: mods}) high_data, ext_errors = st_.state.reconcile_extend(high_data) errors += ext_errors From 7078d7a179e853f9fc922c1c95a6823597b8cfba Mon Sep 17 00:00:00 2001 From: Robert Baker Date: Thu, 21 Nov 2019 14:03:19 -0700 Subject: [PATCH 2/3] added test for _parse_mods in state.py --- tests/unit/client/ssh/__init__.py | 1 + tests/unit/client/ssh/wrapper/__init__.py | 1 + tests/unit/client/ssh/wrapper/test_state.py | 24 +++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/unit/client/ssh/__init__.py create mode 100644 tests/unit/client/ssh/wrapper/__init__.py create mode 100644 tests/unit/client/ssh/wrapper/test_state.py diff --git a/tests/unit/client/ssh/__init__.py b/tests/unit/client/ssh/__init__.py new file mode 100644 index 000000000000..40a96afc6ff0 --- /dev/null +++ b/tests/unit/client/ssh/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/unit/client/ssh/wrapper/__init__.py b/tests/unit/client/ssh/wrapper/__init__.py new file mode 100644 index 000000000000..40a96afc6ff0 --- /dev/null +++ b/tests/unit/client/ssh/wrapper/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/unit/client/ssh/wrapper/test_state.py b/tests/unit/client/ssh/wrapper/test_state.py new file mode 100644 index 000000000000..9a902a11636f --- /dev/null +++ b/tests/unit/client/ssh/wrapper/test_state.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +''' + :codeauthor: :email:`saltybob Date: Thu, 5 Dec 2019 17:37:59 -0700 Subject: [PATCH 3/3] Fix linter error --- tests/unit/client/ssh/wrapper/test_state.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/client/ssh/wrapper/test_state.py b/tests/unit/client/ssh/wrapper/test_state.py index 9a902a11636f..a57b68e15055 100644 --- a/tests/unit/client/ssh/wrapper/test_state.py +++ b/tests/unit/client/ssh/wrapper/test_state.py @@ -2,6 +2,7 @@ ''' :codeauthor: :email:`saltybob