8000 #4804 Handle action parameters of type array correctly by winem · Pull Request #4861 · StackStorm/st2 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#4804 Handle action parameters of type array correctly #4861

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

Merged
merged 19 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ce0b448
- match for argument_type 'array' instead of 'list' to be compliant w…
winem Feb 11, 2020
4a45fe8
Merge branch 'master' into fix/4804-serialize-array-in-parameters
winem Feb 11, 2020
6d62e02
check the parameter type for 'array' and 'list' and not just array
winem Feb 11, 2020
1cc6cfe
Merge branch 'fix/4804-serialize-array-in-parameters' of pgithub.com:…
winem Feb 11, 2020
f262b1a
remove spaces between the square brackets and array values to pass li…
winem Feb 13, 2020
25558aa
add unit tests for action parameter type array
winem Feb 13, 2020
18a8828
fix failing assert on unit tests
winem Feb 14, 2020
d74a2e1
fix last unit test
winem Feb 14, 2020
5c6e560
Merge branch 'master' into fix/4804-serialize-array-in-parameters
blag Feb 21, 2020
3d4568e
Merge remote-tracking branch 'upstream/master' into fix/4804-serializ…
winem F 8000 eb 22, 2020
79282a7
add changelog entry for the 4861 fixing array passing to shell runner…
winem Feb 22, 2020
234332e
add full name to changelog entry for 4861
winem Feb 22, 2020
0725178
Merge branch 'master' into fix/4804-serialize-array-in-parameters
blag Feb 25, 2020
b29f1bd
add test for arrays and lists with different types of values
winem Apr 4, 2020
184ee37
Merge branch 'fix/4804-serialize-array-in-parameters' of pgithub.com:…
winem Apr 4, 2020
8aaa076
add a 2nd complex number as string to the array being passed to the a…
winem Apr 4, 2020
27055a6
Merge branch 'master' into fix/4804-serialize-array-in-parameters
winem Apr 4, 2020
621d23d
Update st2common/tests/unit/test_action_db_utils.py to fix flake8 issues
armab Apr 6, 2020
d2785a9
Merge branch 'master' into fix/4804-serialize-array-in-parameters
armab Apr 6, 2020
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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ Changed

Fixed
~~~~~
* Fix the passing of arrays to shell scripts where the arrays where not detected as such by the
st2 action_db utility. This caused arrays to be passed as Python lists serialized into a string.

Reported by @kingsleyadam #4804 and contributed by Marcel Weinberg (@winem) #4861
* Fix ssh zombies when using ProxyCommand from ssh config #4881 [Eric Edgar]
* Fix rbac with execution view where the rbac is unable to verify the pack or uid of the execution
because it was not returned from the action execution db. This would result in an internal server
Expand Down
4 changes: 2 additions & 2 deletions st2common/st2common/util/action_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ def serialize_positional_argument(argument_type, argument_value):
argument_value = '1' if bool(argument_value) else '0'
else:
argument_value = ''
elif argument_type == 'list':
elif argument_type in ['array', 'list']:
# Lists are serialized a comma delimited string (foo,bar,baz)
argument_value = ','.join(argument_value) if argument_value else ''
argument_value = ','.join(map(str, argument_value)) if argument_value else ''
elif argument_type == 'object':
# Objects are serialized as JSON
argument_value = json.dumps(argument_value) if argument_value else ''
Expand Down
36 changes: 32 additions & 4 deletions st2common/tests/unit/test_action_db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_get_args(self):
'runnerint': 555
}
pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db)
self.assertListEqual(pos_args, ['20', '', 'foo', '', '', '', ''],
self.assertListEqual(pos_args, ['20', '', 'foo', '', '', '', '', ''],
'Positional args not parsed correctly.')
self.assertNotIn('actionint', named_args)
self.assertNotIn('actionstr', named_args)
Expand All @@ -340,6 +340,7 @@ def test_get_args(self):
'actionfloat': 1.5,
'actionstr': 'string value',
'actionbool': True,
'actionarray': ['foo', 'bar', 'baz', 'qux'],
'actionlist': ['foo', 'bar', 'baz'],
'actionobject': {'a': 1, 'b': '2'},
}
Expand All @@ -348,6 +349,7 @@ def test_get_args(self):
'1.5',
'string value',
'1',
'foo,bar,baz,qux',
'foo,bar,baz',
'{"a": 1, "b": "2"}',
''
Expand All @@ -361,6 +363,7 @@ def test_get_args(self):
'actionfloat': 1.5,
'actionstr': 'string value',
'actionbool': False,
'actionarray': [],
'actionlist': [],
'actionobject': {'a': 1, 'b': '2'},
}
Expand All @@ -370,6 +373,7 @@ def test_get_args(self):
'string value',
'0',
'',
'',
'{"a": 1, "b": "2"}',
''
]
Expand All @@ -383,6 +387,7 @@ def test_get_args(self):
'actionfloat': None,
'actionstr': None,
'actionbool': None,
'actionarray': None,
'actionlist': None,
'actionobject': None,
}
Expand All @@ -393,6 +398,7 @@ def test_get_args(self):
'',
'',
'',
'',
''
]
pos_args, _ = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db)
Expand All @@ -412,10 +418,31 @@ def test_get_args(self):
'',
'',
'',
'',
''
]
pos_args, named_args = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db)
self.assertListEqual(pos_args, expected_pos_args, 'Positional args not parsed correctly.')

# Test arrays and lists with values of different types
params = {
'actionarray': [None, False, 1, 4.2e1, '1e3', 'foo'],
'actionlist': [None, False, 1, 73e-2, '1e2', 'bar']
}
expected_pos_args = [
'',
'',
'',
'',
'None,False,1,42.0,1e3,foo',
'None,False,1,0.73,1e2,bar',
'',
''
]
pos_args, _ = action_db_utils.get_args(params, ActionDBUtilsTestCase.action_db)
self.assertListEqual(pos_args, expected_pos_args,
'Positional args not parsed / serialized correctly.')

self.assertNotIn('actionint', named_args)
self.assertNotIn('actionstr', named_args)
self.assertEqual(named_args.get('runnerint'), 555)
Expand Down Expand Up @@ -463,9 +490,10 @@ def setup_action_models(cls):
'actionfloat': {'type': 'float', 'required': False, 'position': 1},
'actionstr': {'type': 'string', 'required': True, 'position': 2},
'actionbool': {'type': 'boolean', 'required': False, 'position': 3},
'actionlist': {'type': 'list', 'required': False, 'position': 4},
'actionobject': {'type': 'object', 'required': False, 'position': 5},
'actionnull': {'type': 'null', 'required': False, 'position': 6},
'actionarray': {'type': 'array', 'required': False, 'position': 4},
'actionlist': {'type': 'list', 'required': False, 'position': 5},
'actionobject': {'type': 'object', 'required': False, 'position': 6},
'actionnull': {'type': 'null', 'required': False, 'position': 7},

'runnerdummy': {'type': 'string', 'default': 'actiondummy'}
}
Expand Down
0