add_network_ipam doesn't work correctly for update

Bug #1381082 reported by Jacek Świderski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenContrail
New
Undecided
Hampapur Ajay

Bug Description

Part of generated method add_network_ipam responsible for updating attr (and since its generated there might be more problems like this) doesn't work :

(...)
# if ref already exists, update any attr with it
for ref in refs:
    if ref['to'] == ref_obj.get_fq_name():
        ref = {'to':ref_obj.get_fq_name(), 'attr':ref_data}
        if ref_obj.uuid:
            ref['uuid'] = ref_obj.uuid
        return
(...)

this code doesn't modify refs list in any way - it remains the same because it only changes what ref "points to" and not refs content - like this :

>>> a = ["aaa","bbb"]
>>> a
['aaa', 'bbb']
>>> for item in a:
... item = "ccc"
...
>>> a
['aaa', 'bbb']

Tags: api config
Revision history for this message
Pedro Marques (5-roque) wrote :

Jacek,
Can you please provide a working example of this problem ?

i.e. from the API client generate a subnet as an attribute to a specific IPAM; then generate a modification.

My understanding is that modifying the subnet prefix is possible today and that we do have tests for that.

Changed in opencontrail:
status: New → Invalid
assignee: nobody → Hampapur Ajay (hajay)
status: Invalid → Incomplete
Revision history for this message
Jacek Świderski (jacek-swiderski) wrote :

Here's the example:

>>> from vnc_api.vnc_api import *
>>> vnc = VncApi("admin",'contrail123',"admin","127.0.0.1","8082","/")
>>> vnc.network_ipams_list()
{u'network-ipams': [{u'href': u'http://127.0.0.1:8082/network-ipam/f9b58449-f9bc-4134-a2b1-a1a00582f404', u'fq_name': [u'default-domain', u'default-project', u'default-network-ipam'], u'uuid': u'f9b58449-f9bc-4134-a2b1-a1a00582f404'}]}
>>> ipam = vnc.network_ipam_read(id="f9b58449-f9bc-4134-a2b1-a1a00582f404")
>>> vn_blue_obj = VirtualNetwork('vn')
>>> vn_obj = VirtualNetwork('vn')
>>> vn_obj.add_network_ipam(ipam,VnSubnetsType([IpamSubnetType(subnet = SubnetType('10.1.1.0', 24)),IpamSubnetType(subnet = SubnetType('190.1.1.0', 24))]))
>>> vnc.virtual_network_create(vn_obj)
// now network has 2 subnets attached - 10.1.1.0/24 and 190.1.1.0/24 - http://pastebin.com/zRUWUzVu
>>> vn_obj = vnc.virtual_network_read(id='6317af36-c9f6-4ff0-b82f-5ab3b7045563')
>>> vn_obj.add_network_ipam(ipam,VnSubnetsType([IpamSubnetType(subnet = SubnetType('30.1.1.0', 12)),IpamSubnetType(subnet = SubnetType('19.1.1.0', 18))]))
>>> vnc.virtual_network_update(vn_obj)
u'{"virtual-network": {"href": "http://127.0.0.1:8082/virtual-network/6317af36-c9f6-4ff0-b82f-5ab3b7045563", "uuid": "6317af36-c9f6-4ff0-b82f-5ab3b7045563"}}'
// after update network has the same subnets as before update - only modification date changed - http://pastebin.com/A5eKv8nm

note - there is no explicit documentation about it being expected behavior but comment in method suggests that if we add already existing IPAM with new attr (VnSubnetsType) it should be updated to newly passed value - if that's not the case I would be thankful for clarification.

Changed in opencontrail:
status: Incomplete → New
Revision history for this message
Pedro Marques (5-roque) wrote :

Jacek,
I believe that the API expects you do do:
    - del_network_ipam(ipam)
    - add_network_ipam(ipam, <new value>)

In order to replace the existing value.

The code that is being used by the neutron plugin is:
https://github.com/Juniper/contrail-controller/blob/master/src/config/vnc_openstack/vnc_openstack/neutron_plugin_db.py

method: subnet_create.
Look at line 2286: If there is an existing link between the virtual-network and the IPAM object the code is modifying the list of subnets associated with the link before doing the update.

I agree that the API is not very clear in this case. Ajay, please chime in.

tags: added: api config
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.