Skip to content

Fix the 'configuration._' not defined error when not provide '_' parameter.

Boxiang Sun requested to merge Daetalus/slapos:jstestnode into master

There will be an error when we don't provide _ in webrunner. The instance-parameter:configuration is something like '''!py!{'full_address_list': [], '_': '{}'}'''

This commit process it by these steps:

  1. Remove the !py prefix by str[4:].
  2. Use double quotes replace single quotes within the str.
  3. Get the dict {'full_address_list': [], '_': '{}'}
  4. Get the value of the '_' key, in this case, it is a string "{}". Use json to convert it to a dict {}.

Notes:

  • Use eval or ast.literal_eval can do it in 1 or 2 steps. But it is unsafe and can not process json string which contains true, false, etc.
  • The test suite was passed in here with this commit: Daetalus/slapos@6e15fa38 . The commit includes in here contains some formatting.

Please let me know if there has trouble to hardcode the str[4:] or there has corner case that I didn't cover.

Merge request reports