Update get_arg_list_as_str to skip func params
This patch updates inspect_utils.get_arg_list_as_str so that it skips handling parameters that can't be JSON serialized. One example of this would be a function parameter (func=time.sleep). Some of the OpenStack clients have functions that would be useful to expose by simply relying on the default settings for these parameters. Change-Id: Id1cc8e79db3001ffec5066b2e81ec2e5119e875a Closes-bug: #1584366
This commit is contained in:
parent
b9dafd1e1a
commit
7712cc3138
@ -12,6 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from mistral.actions import std_actions
|
from mistral.actions import std_actions
|
||||||
from mistral.tests.unit import base
|
from mistral.tests.unit import base
|
||||||
from mistral.utils import inspect_utils as i_u
|
from mistral.utils import inspect_utils as i_u
|
||||||
@ -37,3 +39,11 @@ class InspectUtilsTest(base.BaseTest):
|
|||||||
parameters_str = i_u.get_arg_list_as_str(clazz.__init__)
|
parameters_str = i_u.get_arg_list_as_str(clazz.__init__)
|
||||||
|
|
||||||
self.assertEqual("wf_ex, task_spec, ctx", parameters_str)
|
self.assertEqual("wf_ex, task_spec, ctx", parameters_str)
|
||||||
|
|
||||||
|
def test_get_parameters_str_with_function_parameter(self):
|
||||||
|
|
||||||
|
def test_func(foo, bar=None, test_func=time.sleep):
|
||||||
|
pass
|
||||||
|
|
||||||
|
parameters_str = i_u.get_arg_list_as_str(test_func)
|
||||||
|
self.assertEqual("foo, bar=null", parameters_str)
|
||||||
|
@ -66,12 +66,15 @@ def get_arg_list_as_str(func):
|
|||||||
|
|
||||||
for index, default in enumerate(args):
|
for index, default in enumerate(args):
|
||||||
if index >= diff_args_defs:
|
if index >= diff_args_defs:
|
||||||
arg_str_list.append(
|
try:
|
||||||
"%s=%s" % (
|
arg_str_list.append(
|
||||||
args[index],
|
"%s=%s" % (
|
||||||
json.dumps(defs[index - diff_args_defs])
|
args[index],
|
||||||
|
json.dumps(defs[index - diff_args_defs])
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except TypeError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
arg_str_list.append("%s" % args[index])
|
arg_str_list.append("%s" % args[index])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user