Bug 2278127

Summary: import of guest with shared disk and snapshot is failing
Product: Red Hat Enterprise Virtualization Manager Reporter: Marian Jankular <mjankula>
Component: ovirt-engineAssignee: Nobody <nobody>
Status: CLOSED ERRATA QA Contact: meital avital <mavital>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.5.3CC: gveitmic, michal.skrivanek
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-06-10 11:57:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Marian Jankular 2024-05-01 10:11:02 UTC
Description of problem:
import of guest with shared disk and snapshot is failing

Version-Release number of selected component (if applicable):


How reproducible:
everytime

Steps to Reproduce:
1, create 4 vms on sd_A:

vm_A with bootable disk disk_A and shared disk shared_1
vm_B with bootable disk disk_B and shared disk shared_1
vm_C with bootable disk disk_C and shared disk shared_2
vm_D with bootable disk disk_D and shared disk shared_2

2, create snapshot for the vms (in my case it was enough to create snapshot for the vm_A and vm_B)
3, put in maintenance & detach sd_A fro the datacenter
4, attach sd_A back to the datacenter or import it in new dc
5, import all 4 vms at once 

Actual results:
import fails for one of 4 vms with error below:

~~~
2024-04-30 15:12:28,824Z ERROR [org.ovirt.engine.core.bll.exportimport.ImportVmFromConfigurationCommand] (EE-ManagedThreadFactory-engine-Thread-2266) [50da4d21-0a8b-4791-8255-0b221abb40ae] Command 'org.ovirt.engine.core.bll.exportimpor
t.ImportVmFromConfigurationCommand' failed: CallableStatementCallback; SQL [{call insertsnapshot(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; ERROR: duplicate key value violates unique constraint "pk_snapshots"
  Detail: Key (snapshot_id)=(00000000-0000-0000-0000-000000000000) already exists.
  Where: SQL statement "INSERT INTO snapshots (
        snapshot_id,
        status,
        vm_id,
        snapshot_type,
        description,
        creation_date,
        app_list,
        vm_configuration,
        memory_dump_disk_id,
        memory_metadata_disk_id,
        changed_fields
        )
    VALUES(
        v_snapshot_id,
        v_status,
        v_vm_id,
        v_snapshot_type,
        v_description,
        v_creation_date,
        v_app_list,
        v_vm_configuration,
        v_memory_dump_disk_id,
        v_memory_metadata_disk_id,
        v_changed_fields
        )"
PL/pgSQL function insertsnapshot(uuid,uuid,character varying,character varying,character varying,timestamp with time zone,text,text,uuid,uuid,text) line 3 at SQL statement; nested exception is org.postgresql.util.PSQLException: ERROR: 
duplicate key value violates unique constraint "pk_snapshots"
  Detail: Key (snapshot_id)=(00000000-0000-0000-0000-000000000000) already exists.
~~~

Expected results:
all guests will be imported

Additional info:

Comment 1 Marian Jankular 2024-05-01 10:22:43 UTC
so it looks like the issue is that when engine is importing VM with snapshot for common disk(s) it assigns snapshot id for the shared disk 00000000-0000-0000-0000-000000000000

so it can be reproduced even with 2 vms with snapshot for common disks + shared disk

if the snapshot is removed vms are imported without any issue

Comment 2 Marian Jankular 2024-05-01 10:51:27 UTC
there was already PR for this https://github.com/oVirt/ovirt-engine/pull/905

Comment 3 Michal Skrivanek 2024-05-10 06:26:31 UTC
https://github.com/oVirt/ovirt-engine/pull/940

Comment 8 Michal Skrivanek 2024-05-30 07:53:41 UTC
verified by Germano manually. Thanks a lot!

Comment 10 errata-xmlrpc 2024-06-10 11:57:03 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Red Hat Virtualization security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2024:3751