← Back to team overview

openstack team mailing list archive

Virtaul Interface create error

 

Hi, guys.

I found a bug about generate VIF Mac address. This is written this url
https://bugs.launchpad.net/nova/+bug/1062097

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('test@xxxxxxxx
','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. I think this is a bug.

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()
---------------------------------------------------------------------------------------------------------------