Skip to content

Commit

Permalink
Persist only non-string values in bindings with json encoding in cont…
Browse files Browse the repository at this point in the history
…rail.

This way the string checks for vnic_type in backend (vnc_cfg_types.py)
don't have to check for json-encoded values.

Change-Id: I516c890f6540a263b93bc870e42fff1feee09636
Closes-Bug: 1590971
(cherry picked from commit fb27702)
  • Loading branch information
Hampapur Ajay committed Jun 14, 2016
1 parent c750811 commit 6806c2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py
Expand Up @@ -1829,15 +1829,18 @@ def _port_neutron_to_vnc(self, port_q, net_obj, oper):
# pick binding keys from neutron repr and persist as kvp elements
# that are string/string(k/v).
# it is assumed allowing/denying oper*key is done at neutron-server.
vmi_binding_kvps = dict((k.replace('binding:',''), v)
for k,v in port_q.items() if k.startswith('binding:'))
for k,v in vmi_binding_kvps.items():
if isinstance(v, basestring):
continue
vmi_binding_kvps[k] = json.dumps(v)

if oper == CREATE:
vmi_binding_kvps = dict((k.replace('binding:',''), json.dumps(v))
for k,v in port_q.items() if k.startswith('binding:'))
port_obj.set_virtual_machine_interface_bindings(
KeyValuePairs([KeyValuePair(k,v)
for k,v in vmi_binding_kvps.items()]))
elif oper == UPDATE:
vmi_binding_kvps = dict((k.replace('binding:',''), json.dumps(v))
for k,v in port_q.items() if k.startswith('binding:'))
for k,v in vmi_binding_kvps.items():
port_obj.add_virtual_machine_interface_bindings(
KeyValuePair(key=k, value=v))
Expand Down Expand Up @@ -2027,9 +2030,8 @@ def _port_vnc_to_neutron(self, port_obj, port_req_memo=None):
for kvp in kvps:
try:
port_q_dict['binding:'+kvp.key] = json.loads(kvp.value)
except ValueError:
# upgrade case, earlier version might have saved it
# in non-json format OR vif_details/vif_type/vnic_type
except (ValueError, TypeError):
# native string case, so not stored as json
port_q_dict['binding:'+kvp.key] = kvp.value

# 1. upgrade case, port created before bindings prop was
Expand Down
4 changes: 3 additions & 1 deletion src/config/vnc_openstack/vnc_openstack/tests/test_basic.py
Expand Up @@ -276,11 +276,13 @@ def test_port_bindings(self):
'roles': ''}
data = {'resource':{'network_id': vn_obj.uuid,
'tenant_id': proj_uuid,
'binding:profile': {'foo': 'bar'}}}
'binding:profile': {'foo': 'bar'},
'binding:host_id': 'somehost'}}
body = {'context': context, 'data': data}
resp = self._api_svr_app.post_json('/neutron/port', body)
port_dict = json.loads(resp.text)
self.assertTrue(isinstance(port_dict['binding:profile'], dict))
self.assertTrue(isinstance(port_dict['binding:host_id'], basestring))
# end test_port_bindings
# end class TestBasic

Expand Down

0 comments on commit 6806c2f

Please sign in to comment.