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

Port 54653 to master and add a test #55403

Merged
merged 4 commits into from
Dec 11, 2019
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
22 changes: 14 additions & 8 deletions salt/client/ssh/wrapper/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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_)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/client/ssh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
1 change: 1 addition & 0 deletions tests/unit/client/ssh/wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
25 changes: 25 additions & 0 deletions tests/unit/client/ssh/wrapper/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`saltybob <bbaker@saltstack.com`
'''
from __future__ import absolute_import

# Import python libs

# Import Salt Testing libs
from tests.support.unit import TestCase

# Import Salt libs
from salt.client.ssh.wrapper import state


class StateTests(TestCase):
def test_parse_mods(self):
'''
Test _parse_mods
'''
expected = ['a', 'b', 'c', 'd', 'e', 'f']
mods = 'a,b, c, d,e ,f '

actual = state._parse_mods(mods)
self.assertEqual(expected, actual)