Eli Mesika has uploaded a new change for review.

Change subject: upgrade from 3.0.7 to SI24.4 fail(#879918)
......................................................................

upgrade from 3.0.7 to SI24.4 fail(#879918)

upgrade from 3.0.7 to SI24.4 fails: ERROR: insert or update on table vm_device 
violates foreign key constraint fk_vm_device_vm _static

This bug is a result of missing FK between vmt_guid in vm_interface and
vm_guid in vm_static.
This cause junk interface left in vm_interface when a template that
has interfaces is removed.
Since in upgrade from 3.0 to 3.1 we added the vm_device table, there is
an attempt to insert those junk interfaces to vm_device that fails on
the FK constraint between vm_device and vm_static.

This patch fix the bug by:
1) Fixing the upgrade script to cleanup those junk interfaces before an
attempt to insert it to vm_device is done.
2) Adds the missing FK between vm_interface and vm_static to prevent
junk data in future.

Change-Id: Iaf4af7908566b5d16e39ea5167c6d6dffc5884db
Signed-off-by: Eli Mesika <emes...@redhat.com>
---
M backend/manager/dbscripts/upgrade/03_01_0440_vm_device_upgrade_data.sql
A 
backend/manager/dbscripts/upgrade/03_02_0020_add_fk_vm_interface_vm_static_template.sql
2 files changed, 9 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/62/9462/1

diff --git 
a/backend/manager/dbscripts/upgrade/03_01_0440_vm_device_upgrade_data.sql 
b/backend/manager/dbscripts/upgrade/03_01_0440_vm_device_upgrade_data.sql
index 1be2ae4..34c1dfa 100644
--- a/backend/manager/dbscripts/upgrade/03_01_0440_vm_device_upgrade_data.sql
+++ b/backend/manager/dbscripts/upgrade/03_01_0440_vm_device_upgrade_data.sql
@@ -159,6 +159,13 @@
        select id, vm_guid, 'interface', 'bridge', '', null, '', true, true, 
false  from vm_interface
        where vm_guid IS NOT NULL;
 
+       -- removing junk in vm_interface resulted from a missing constraint
+       -- between vmt_quid in vm_interface and vm_guid in vm_static
+       -- To prevent that in future, this constraint is added in a
+       -- seeparate upgrade script.
+       delete from vm_interface
+       where vmt_guid not in (select vm_guid from vm_static);
+
        insert INTO vm_device(
        device_id, vm_id, type, device, address, boot_order, spec_params, 
is_managed, is_plugged, is_readonly)
        select id, vmt_guid, 'interface', 'bridge', '', null, '', true, true, 
false  from vm_interface
diff --git 
a/backend/manager/dbscripts/upgrade/03_02_0020_add_fk_vm_interface_vm_static_template.sql
 
b/backend/manager/dbscripts/upgrade/03_02_0020_add_fk_vm_interface_vm_static_template.sql
new file mode 100644
index 0000000..f52828d
--- /dev/null
+++ 
b/backend/manager/dbscripts/upgrade/03_02_0020_add_fk_vm_interface_vm_static_template.sql
@@ -0,0 +1,2 @@
+ALTER TABLE vm_interface ADD  CONSTRAINT FK_vm_interface_vm_static_template 
FOREIGN KEY(vmt_guid)
+REFERENCES vm_static(vm_guid) ON DELETE CASCADE;


--
To view, visit http://gerrit.ovirt.org/9462
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf4af7908566b5d16e39ea5167c6d6dffc5884db
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <emes...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to