← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1258065] Re: The implementation of utils.str2dict fails to convert a dict with more than 2 elements

 

** Changed in: neutron
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1258065

Title:
  The implementation of utils.str2dict fails to convert a dict with more
  than 2 elements

Status in OpenStack Neutron (virtual network service):
  Fix Released

Bug description:
  from neutron.common import utils
  print utils.str2dict('inside_addr=10.0.1.2,inside_port=22,outside_addr=172.16.0.1,outside_port=2222,protocol=tcp')

  returns 
  {'inside_addr': '10.0.1.2', 'inside_port': '22,outside_addr=172.16.0.1,outside_port=2222,protocol=tcp'}

  expected value should be

  {'outside_port': '2222', 'inside_addr': '10.0.1.2', 'protocol': 'tcp',
  'inside_port': '22', 'outside_addr': '172.16.0.1'}

  The reason is that in the third line of the implementation below,
  string.split(',', 1) only splits out two key-value pairs.

  quote from neutron/common/utils.py:181:

  def str2dict(string):
      res_dict = {}
      for keyvalue in string.split(',', 1):
          (key, value) = keyvalue.split('=', 1)
          res_dict[key] = value
      return res_dict

  a quick fix might be remove ",1" from string.split. But it turns out
  that str2dict/dict2str may also fail when input values containing
  characters like '=' or ','. A better fix might be using json
  encode/decode to deal with it.

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1258065/+subscriptions


References