Add VirtualInterface.destroy()

This adds a destroy() method for VirtualInterface which has not been
required before but is now.

Change-Id: Ie00f52153a816049f8efcc9aa8071371ce0b7e5a
Related-Bug: #1602357
This commit is contained in:
Dan Smith 2016-07-12 14:39:30 -07:00
parent 29f82ad191
commit ae9c58792c
6 changed files with 52 additions and 2 deletions

View File

@ -687,6 +687,11 @@ def virtual_interface_delete_by_instance(context, instance_id):
return IMPL.virtual_interface_delete_by_instance(context, instance_id)
def virtual_interface_delete(context, id):
"""Delete virtual interface by id."""
return IMPL.virtual_interface_delete(context, id)
def virtual_interface_get_all(context):
"""Gets all virtual interfaces from the table."""
return IMPL.virtual_interface_get_all(context)

View File

@ -1640,6 +1640,18 @@ def virtual_interface_delete_by_instance(context, instance_uuid):
soft_delete()
@require_context
@pick_context_manager_writer
def virtual_interface_delete(context, id):
"""Delete virtual interface records.
:param id: id of the interface
"""
_virtual_interface_query(context).\
filter_by(id=id).\
soft_delete()
@require_context
@pick_context_manager_reader
def virtual_interface_get_all(context):

View File

@ -29,7 +29,8 @@ class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: Add tag field
# Version 1.2: Adding a save method
VERSION = '1.2'
# Version 1.3: Added destroy() method
VERSION = '1.3'
fields = {
'id': fields.IntegerField(),
@ -109,6 +110,10 @@ class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
def delete_by_instance_uuid(cls, context, instance_uuid):
db.virtual_interface_delete_by_instance(context, instance_uuid)
@base.remotable
def destroy(self):
db.virtual_interface_delete(self._context, self.id)
@base.NovaObjectRegistry.register
class VirtualInterfaceList(base.ObjectListBase, base.NovaObject):

View File

@ -6540,6 +6540,20 @@ class VirtualInterfaceTestCase(test.TestCase, ModelsObjectComparatorMixin):
self.assertEqual(len(real_vifs1), 0)
self.assertEqual(len(real_vifs2), 1)
def test_virtual_interface_delete(self):
values = [dict(address='fake1'), dict(address='fake2'),
dict(address='fake3')]
vifs = []
for vals in values:
vifs.append(self._create_virt_interface(
dict(vals, instance_uuid=self.instance_uuid)))
db.virtual_interface_delete(self.ctxt, vifs[0]['id'])
real_vifs = db.virtual_interface_get_by_instance(self.ctxt,
self.instance_uuid)
self.assertEqual(2, len(real_vifs))
def test_virtual_interface_get_all(self):
inst_uuid2 = db.instance_create(self.ctxt, {})['uuid']
values = [dict(address='fake1'), dict(address='fake2'),

View File

@ -1200,7 +1200,7 @@ object_data = {
'VirtCPUFeature': '1.0-3310718d8c72309259a6e39bdefe83ee',
'VirtCPUModel': '1.0-6a5cc9f322729fc70ddc6733bacd57d3',
'VirtCPUTopology': '1.0-fc694de72e20298f7c6bab1083fd4563',
'VirtualInterface': '1.2-25730967393678bd4da092b98694f971',
'VirtualInterface': '1.3-efd3ca8ebcc5ce65fff5a25f31754c54',
'VirtualInterfaceList': '1.0-9750e2074437b3077e46359102779fc6',
'VolumeUsage': '1.0-6c8190c46ce1469bb3286a1f21c2e475',
'XenapiLiveMigrateData': '1.0-5f982bec68f066e194cd9ce53a24ac4c',

View File

@ -124,6 +124,20 @@ class _TestVirtualInterface(object):
'fake-uuid')
delete.assert_called_with(self.context, 'fake-uuid')
def test_destroy(self):
vif = vif_obj.VirtualInterface(context=self.context)
vif.address = '00:00:00:00:00:00'
vif.network_id = 123
vif.instance_uuid = uuids.instance_uuid
vif.uuid = uuids.vif_uuid
vif.tag = 'foo'
vif.create()
vif = vif_obj.VirtualInterface.get_by_id(self.context, vif.id)
vif.destroy()
self.assertIsNone(vif_obj.VirtualInterface.get_by_id(self.context,
vif.id))
def test_obj_make_compatible_pre_1_1(self):
vif = vif_obj.VirtualInterface(context=self.context)
vif.address = '00:00:00:00:00:00'