virtual interface create error

Bug #1062097 reported by Jay Lee
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Invalid
Low
Unassigned

Bug Description

I saw instance creation failed when nova-network attempted create duplicated MAC address for vif.
In nova code, there are exception code exists but It looks doesn't catch exception Integrity error.

This is my test code.

#!/usr/bin/python
from nova import utils
from nova import flags
import nova.context
import sys
from nova import db

def main(sys):
    context = nova.context.RequestContext('<email address hidden>','prj-test',True,False)
    vif = {'address': '02:16:3e:63:c9:39',
               'instance_id': 1,
               'network_id': 1,
               'uuid': str(utils.gen_uuid())}

    db.virtual_interface_create(context, vif)

if __name__ == '__main__':
    utils.default_flagfile()
    FLAGS = flags.FLAGS(sys.argv)

'02:16:3e:63:c9:39' is already exists db table. So I expected exception.VirtualInterfaceCreateException() because In db/sqlalchemy/api.py,

 @require_context
 def virtual_interface_create(context, values):
     """Create a new virtual interface record in teh database.

     :param values: = dict containing column values
     """
     try:
         vif_ref = models.VirtualInterface()
        vif_ref.update(values)
         vif_ref.save()
     except IntegrityError:
        raise exception.VirtualInterfaceCreateException()

     return vif_ref

But next error is occured when I tested.
Traceback (most recent call last):
  File "./test_create_vif.sh", line 23, in <module>
    main(sys)
  File "./test_create_vif.sh", line 17, in main
    db.virtual_interface_create(context, vif)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/api.py", line 448, in virtual_interface_create
    return IMPL.virtual_interface_create(context, values)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/sqlalchemy/api.py", line 120, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/sqlalchemy/api.py", line 1002, in virtual_interface_create
    vif_ref.save()
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/sqlalchemy/models.py", line 59, in save
    session.flush()
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/exception.py", line 98, in _wrap
    raise DBError(e)
nova.exception.DBError: (IntegrityError) (1062, "Duplicate entry '02:16:3e:63:c9:39' for key 'address'") 'INSERT INTO virtual_interfaces (created_at, updated_at, deleted_at, deleted, address, network_id, instance_id, uuid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)' (datetime.datetime(2012, 10, 5, 8, 7, 30, 868674), None, None, 0, '02:16:3e:63:c9:39', 1, 1, '9452abe3-3fea-4706-94e3-876753e8bcb1')

For this reason, When VIF's mac address is duplicated, maybe instance creation is failed.

When Instance is created, below code is executed.

nova/network/manager.py

    def add_virtual_interface(self, context, instance_uuid, network_id):
        vif = {'address': utils.generate_mac_address(),
               'instance_uuid': instance_uuid,
               'network_id': network_id,
               'uuid': str(utils.gen_uuid())}
        # try FLAG times to create a vif record with a unique mac_address
        for i in xrange(FLAGS.create_unique_mac_address_attempts):
            try:
                return self.db.virtual_interface_create(context, vif)
            except exception.VirtualInterfaceCreateException:
                vif['address'] = utils.generate_mac_address()
        else:
            self.db.virtual_interface_delete_by_instance(context,
                                                         instance_uuid)
            raise exception.VirtualInterfaceMacAddressException()

Revision history for this message
Jay Lee (hyangii) wrote :

When I modify exception.py, exception.VirtualInterfaceMacAddressException() is occured.

From:
def wrap_db_error(f):
    def _wrap(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except UnicodeEncodeError:
            raise InvalidUnicodeParameter()
        except Exception, e:
            LOG.exception(_('DB exception wrapped.'))
            raise DBError(e)
    _wrap.func_name = f.func_name
    return _wrap

To:
def wrap_db_error(f):
    def _wrap(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except UnicodeEncodeError:
            raise InvalidUnicodeParameter()
        except Exception, e:
            LOG.exception(_('DB exception wrapped.'))
            raise e
    _wrap.func_name = f.func_name
    return _wrap

This is error trace when changed code.
Traceback (most recent call last):
  File "./test_create_vif.sh", line 23, in <module>
    main(sys)
  File "./test_create_vif.sh", line 17, in main
    db.virtual_interface_create(context, vif)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/api.py", line 448, in virtual_interface_create
    return IMPL.virtual_interface_create(context, values)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/sqlalchemy/api.py", line 120, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/nova-2012.1-py2.7.egg/nova/db/sqlalchemy/api.py", line 1004, in virtual_interface_create
    raise exception.VirtualInterfaceCreateException()
nova.exception.VirtualInterfaceCreateException: Virtual Interface creation failed

Jay Lee (hyangii)
security vulnerability: no → yes
security vulnerability: yes → no
Jay Lee (hyangii)
Changed in nova:
assignee: nobody → Jay Lee (hyangii)
status: New → Confirmed
Thierry Carrez (ttx)
Changed in nova:
status: Confirmed → New
Revision history for this message
Chuck Short (zulcss) wrote :

this is obviously not being worked on.

Changed in nova:
assignee: Jay Lee (hyangii) → nobody
Revision history for this message
Vish Ishaya (vishvananda) wrote :

This should be handled by the unique keys blueprint

Changed in nova:
status: New → Triaged
importance: Undecided → Low
Changed in nova:
assignee: nobody → Boris Pavlovic (boris-42)
Revision history for this message
Sean Dague (sdague) wrote :

Going to assume the unique keys blueprint addressed this

Changed in nova:
assignee: Boris Pavlovic (boris-42) → nobody
status: Triaged → Invalid
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.