Bug 2023368 - Importing VM OVA fails with ERROR: insert or update on table "vm_static" violates foreign key constraint "fk_vm_static_lease_sd_i d_storage_domain_static_id"
Summary: Importing VM OVA fails with ERROR: insert or update on table "vm_static" viol...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine
Classification: oVirt
Component: BLL.Virt
Version: 4.4.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ovirt-4.5.1
: ---
Assignee: Liran Rotenberg
QA Contact: Nisim Simsolo
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-11-15 14:35 UTC by Liran Rotenberg
Modified: 2022-08-18 08:31 UTC (History)
7 users (show)

Fixed In Version: ovirt-engine-4.5.1.1
Clone Of:
Environment:
Last Closed: 2022-06-23 05:54:58 UTC
oVirt Team: Virt
Embargoed:
ahadas: ovirt-4.5?
mavital: testing_plan_complete-


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github oVirt ovirt-engine pull 418 0 None open Default SD for imported VM with lease 2022-06-07 07:59:18 UTC
Red Hat Issue Tracker RHV-44029 0 None None None 2021-11-15 14:36:45 UTC

Description Liran Rotenberg 2021-11-15 14:35:51 UTC
Description of problem:
When having a VM with a lease and exporting it as OVA, once we try to import it and we don't have the initial storage domain of the lease we will fail on the error: org.postgresql.util.PSQLException: ERROR: insert or update on table "vm_static" violates foreign key constraint "fk_vm_static_lease_sd_id_storage_domain_static_id"

How reproducible:
100%

Steps to Reproduce:
1. Create a VM.
2. Set the VM with HA and a lease to SD 'x'.
3. Export the VM OVA.
4. Remove the SD 'x' from the environment (if using the same environment).
5. Import the VM OVA.
(step 4 isn't needed if the import is done in another environment) 

Actual results:
Import failed.

PL/pgSQL function insertvmstatic(character varying,text,integer,integer,integer,integer,uuid,uuid,character varying,uuid,timestamp with time zone,integer,boolean,boolean,integer,integer,integer,integer,character varying,boolean,boolean,boolean,boolean,character varying,text,integer,integer,integer,integer,integer,integer,character varying,integer,character varying,character varying,character varying,integer,character varying,character varying,integer,uuid,character varying,boolean,boolean,character varying,boolean,uuid,uuid,uuid,uuid,character varying,integer,integer,smallint,character varying,boolean,boolean,boolean,uuid,boolean,boolean,boolean,character varying,integer,character varying,uuid,uuid,character varying,character varying,character varying,uuid,uuid,boolean,boolean,boolean,character varying,boolean) line 8 at SQL statement
        at org.springframework.4.RELEASE//org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247)
        at org.springframework.4.RELEASE//org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1065)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1104)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:414)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:374)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:198)
        at org.ovirt.engine.core.dal//org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeImpl(SimpleJdbcCallsHandler.java:135)
        at org.ovirt.engine.core.dal//org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeImpl(SimpleJdbcCallsHandler.java:130)
        at org.ovirt.engine.core.dal//org.ovirt.engine.core.dal.dbbroker.SimpleJdbcCallsHandler.executeModification(SimpleJdbcCallsHandler.java:76)
        at org.ovirt.engine.core.dal//org.ovirt.engine.core.dao.DefaultGenericDao.save(DefaultGenericDao.java:93)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmCommandBase.addVmStatic(ImportVmCommandBase.java:628)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmFromExternalProviderCommand.addVmStatic(ImportVmFromExternalProviderCommand.java:309)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmCommandBase.lambda$addVmToDb$8(ImportVmCommandBase.java:560)
        at org.ovirt.engine.core.utils//org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInNewTransaction(TransactionSupport.java:181)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmCommandBase.addVmToDb(ImportVmCommandBase.java:559)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmFromExternalProviderCommand.addVmToDb(ImportVmFromExternalProviderCommand.java:391)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ImportVmCommandBase.executeVmCommand(ImportVmCommandBase.java:511)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.VmCommand.executeCommand(VmCommand.java:178)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.executeWithoutTransaction(CommandBase.java:1174)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.executeActionInTransactionScope(CommandBase.java:1332)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.runInTransaction(CommandBase.java:2010)
        at org.ovirt.engine.core.utils//org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInSuppressed(TransactionSupport.java:140)
        at org.ovirt.engine.core.utils//org.ovirt.engine.core.utils.transaction.TransactionSupport.executeInScope(TransactionSupport.java:79)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.execute(CommandBase.java:1392)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.CommandBase.executeAction(CommandBase.java:424)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.executeValidatedCommand(PrevalidatingMultipleActionsRunner.java:204)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.runCommands(PrevalidatingMultipleActionsRunner.java:176)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.PrevalidatingMultipleActionsRunner.lambda$invokeCommands$3(PrevalidatingMultipleActionsRunner.java:182)
        at org.ovirt.engine.core.utils//org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil$InternalWrapperRunnable.run(ThreadPoolUtil.java:96)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
        at org.glassfish.javax.enterprise.concurrent//org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:227)
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "vm_static" violates foreign key constraint "fk_vm_static_lease_sd_id_storage_domain_static_id"
  Detail: Key (lease_sd_id)=(2b7747b4-c55f-40ea-b619-37dfe273505b) is not present in table "storage_domain_static".
  Where: SQL statement "INSERT INTO vm_static(description,
                      free_text_comment,
                      mem_size_mb,
                      max_memory_size_mb,
                      num_of_io_threads,
                      os,
                      cluster_id,
                      vm_guid,
                      vm_name,
                      vmt_guid,
                      creation_date,
                      num_of_monitors,
                      allow_console_reconnect,
                      is_initialized,
                      num_of_sockets,
                      cpu_per_socket,
                      threads_per_cpu,
                      usb_policy,
                      time_zone,
                      auto_startup,
                      is_stateless,
                      default_boot_sequence,
                      vm_type,
                      nice_level,
                      cpu_shares,
                      default_display_type,
                      priority,
                      iso_path,
                      origin,
                      initrd_url,
                      kernel_url,
                      kernel_params,
                      migration_support,
                      predefined_properties,
                      userdefined_properties,
                      min_allocated_mem,
                      entity_type,
                      quota_id,
                      cpu_pinning,
                      is_smartcard_enabled,
                      is_delete_protected,
                      sso_method,
                      host_cpu_flags,
                      tunnel_migration,
                      vnc_keyboard_layout,
                      is_run_and_pause,
                      created_by_user_id,
                      instance_type_id,
                      image_type_id,
                      original_template_id,
                      original_template_name,
                      migration_downtime,
                      template_version_number,
                      serial_number_policy,
                      custom_serial_number,
                      is_boot_menu_enabled,
                      is_spice_file_transfer_enabled,
                      is_spice_copy_paste_enabled,
                      cpu_profile_id,
                      is_auto_converge,
                      is_migrate_compressed,
                      is_migrate_encrypted,
                      custom_emulated_machine,
                      bios_type,
                      custom_cpu_name,
                      small_icon_id,
                      large_icon_id,
                      console_disconnect_action,
                      resume_behavior,
                      custom_compatibility_version,
                      migration_policy_id,
                      lease_sd_id,
                      multi_queues_enabled,
                      virtio_scsi_multi_queues_enabled,
                      use_tsc_frequency,
                      namespace,
                      balloon_enabled)
    VALUES(v_description,
           v_free_text_comment,
           v_mem_size_mb,
           v_max_memory_size_mb,
           v_num_of_io_threads,
           v_os,
           v_cluster_id,
           v_vm_guid,
           v_vm_name,
           v_vmt_guid,
           v_creation_date,
           v_num_of_monitors,
           v_allow_console_reconnect,
           v_is_initialized,
           v_num_of_sockets,
           v_cpu_per_socket,
           v_threads_per_cpu,
           v_usb_policy,
           v_time_zone,
           v_auto_startup,
           v_is_stateless,
           v_default_boot_sequence,
           v_vm_type,
           v_nice_level,
           v_cpu_shares,
           v_default_display_type,
           v_priority,
           v_iso_path,
           v_origin,
           v_initrd_url,
           v_kernel_url,
           v_kernel_params,
           v_migration_support,
           v_predefined_properties,
           v_userdefined_properties,
           v_min_allocated_mem,
           'VM',
           v_quota_id,
           v_cpu_pinning,
           v_is_smartcard_enabled,
           v_is_delete_protected,
           v_sso_method,
           v_host_cpu_flags,
           v_tunnel_migration,
           v_vnc_keyboard_layout,
           v_is_run_and_pause,
           v_created_by_user_id,
           v_instance_type_id,
           v_image_type_id,
           v_original_template_id,
           v_original_template_name,
           v_migration_downtime,
           v_template_version_number,
           v_serial_number_policy,
           v_custom_serial_number,
           v_is_boot_menu_enabled,
           v_is_spice_file_transfer_enabled,
           v_is_spice_copy_paste_enabled,
           v_cpu_profile_id,
           v_is_auto_converge,
           v_is_migrate_compressed,
           v_is_migrate_encrypted,
           v_custom_emulated_machine,
           v_bios_type,
           v_custom_cpu_name,
           v_small_icon_id,
           v_large_icon_id,
           v_console_disconnect_action,
           v_resume_behavior,
           v_custom_compatibility_version,
           v_migration_policy_id,
           v_lease_sd_id,
           v_multi_queues_enabled,
           v_virtio_scsi_multi_queues_enabled,
           v_use_tsc_frequency,
           v_namespace,
           v_balloon_enabled)"
PL/pgSQL function insertvmstatic(character varying,text,integer,integer,integer,integer,uuid,uuid,character varying,uuid,timestamp with time zone,integer,boolean,boolean,integer,integer,integer,integer,character varying,boolean,boolean,boolean,boolean,character varying,text,integer,integer,integer,integer,integer,integer,character varying,integer,character varying,character varying,character varying,integer,character varying,character varying,integer,uuid,character varying,boolean,boolean,character varying,boolean,uuid,uuid,uuid,uuid,character varying,integer,integer,smallint,character varying,boolean,boolean,boolean,uuid,boolean,boolean,boolean,character varying,integer,character varying,uuid,uuid,character varying,character varying,character varying,uuid,uuid,boolean,boolean,boolean,character varying,boolean) line 8 at SQL statement
        at org.postgresql.3//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
        at org.postgresql.3//org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
        at org.postgresql.3//org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
        at org.postgresql.3//org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
        at org.postgresql.3//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
        at org.postgresql.3//org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:150)
        at org.postgresql.3//org.postgresql.jdbc.PgCallableStatement.executeWithFlags(PgCallableStatement.java:77)
        at org.postgresql.3//org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:139)
        at org.jboss.ironjacamar.jdbcadapters.27.Final//org.jboss.jca.adapters.jdbc.CachedPreparedStatement.execute(CachedPreparedStatement.java:303)
        at org.jboss.ironjacamar.jdbcadapters.27.Final//org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:442)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.JdbcTemplate.lambda$call$4(JdbcTemplate.java:1105)
        at org.springframework.4.RELEASE//org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1050)
        ... 33 more

2021-11-13 14:20:28,037-05 ERROR [org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector] (EE-ManagedThreadFactory-engine-Thread-138751) [31ca7e84-c55d-4ba8-8653-399cea8c0be1] EVENT_ID: IMPORTEXPORT_IMPORT_VM_FAILED(1,153), Failed to import Vm lightning to Data Center DC, Cluster oVirt1
2021-11-13 14:20:28,050-05 INFO  [org.ovirt.engine.core.bll.exportimport.ImportVmFromOvaCommand] (EE-ManagedThreadFactory-engine-Thread-138751) [31ca7e84-c55d-4ba8-8653-399cea8c0be1] Lock freed to object 'EngineLock:{exclusiveLocks='[lightning=VM_NAME, f94ee127-330c-4a76-893b-009d4d9166b2=VM]', sharedLocks=''}'
2021-11-13 14:20:28,670-05 INFO  [org.ovirt.engine.core.bll.SerialChildCommandsExecutionCallback] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-68) [31ca7e84-c55d-4ba8-8653-399cea8c0be1] Command 'ImportVmFromOva' id: '5c567c44-e3fb-4080-b2ac-0812c3668dc0' execution didn't complete, not proceeding to perform the next operation
2021-11-13 14:20:28,670-05 INFO  [org.ovirt.engine.core.bll.SerialChildCommandsExecutionCallback] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-68) [31ca7e84-c55d-4ba8-8653-399cea8c0be1] Command 'ImportVmFromOva' id: '5c567c44-e3fb-4080-b2ac-0812c3668dc0' child commands '[]' executions were completed, status 'FAILED'
2021-11-13 14:20:29,695-05 ERROR [org.ovirt.engine.core.bll.exportimport.ImportVmFromOvaCommand] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [31ca7e84-c55d-4ba8-8653-399cea8c0be1] Ending command 'org.ovirt.engine.core.bll.exportimport.ImportVmFromOvaCommand' with failure.
2021-11-13 14:20:29,731-05 INFO  [org.ovirt.engine.core.bll.storage.disk.image.RemoveAllVmImagesCommand] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [2728db3e] Running command: RemoveAllVmImagesCommand internal: true. Entities affected :  ID: f94ee127-330c-4a76-893b-009d4d9166b2 Type: VM
2021-11-13 14:20:29,733-05 WARN  [org.ovirt.engine.core.bll.lock.InMemoryLockManager] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [2728db3e] Trying to release exclusive lock which does not exist, lock key: 'lightningVM_NAME'
2021-11-13 14:20:29,733-05 WARN  [org.ovirt.engine.core.bll.lock.InMemoryLockManager] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [2728db3e] Trying to release exclusive lock which does not exist, lock key: 'f94ee127-330c-4a76-893b-009d4d9166b2VM'
2021-11-13 14:20:29,733-05 INFO  [org.ovirt.engine.core.bll.exportimport.ImportVmFromOvaCommand] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [2728db3e] Lock freed to object 'EngineLock:{exclusiveLocks='[lightning=VM_NAME, f94ee127-330c-4a76-893b-009d4d9166b2=VM]', sharedLocks=''}'
2021-11-13 14:20:29,757-05 ERROR [org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector] (EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60) [2728db3e] EVENT_ID: IMPORTEXPORT_IMPORT_VM_FAILED(1,153), Failed to import Vm lightning to Data Center DC, Cluster oVirt1


Expected results:
Import pass.

Additional info:
Related to BZ1641703 where it was fixed only from import template and BZ524455 for VMs.
Reported in user-list: https://lists.ovirt.org/archives/list/users@ovirt.org/thread/CQHIP32K2KRWCBDPHZOC3YES4XWIMG6E/#CQHIP32K2KRWCBDPHZOC3YES4XWIMG6E

It will appear on import of HA leased entity on other environment or when changing the SDs, making the leased one unavailable.

The fix should be similar to the mentioned bug, choosing an available SD on import.

Comment 1 Arik 2021-11-16 08:49:48 UTC
Yeah, seems that we we handled it only for other import operations which were more important for backup and disaster recovery (https://gerrit.ovirt.org/#/c/ovirt-engine/+/88314/) but needs to handle it for import from OVA as well

Comment 2 Nisim Simsolo 2022-06-15 07:48:21 UTC
Verified:
ovirt-engine-4.5.1.1-0.14.el8ev
vdsm-4.50.1.2-1.el8ev.x86_64
libvirt-daemon-8.0.0-5.2.module+el8.6.0+15256+3a0914fe.x86_64
qemu-kvm-6.2.0-11.module+el8.6.0+15489+bc23efef.1.x86_64

verification scenario:
1. Create a VM.
2. Set the VM with HA and a lease to SD 'x'.
3. Export the VM OVA.
4. Remove the SD 'x' from the environment (if using the same environment).
5. Import the VM OVA as clone.
6. Verif imported VM is running, verify qemu-guest-agent is functioning.
7. repeat steps 1-6, this time remove source VM and import OVA not as clone.

Comment 3 Sandro Bonazzola 2022-06-23 05:54:58 UTC
This bugzilla is included in oVirt 4.5.1 release, published on June 22nd 2022.
Since the problem described in this bug report should be resolved in oVirt 4.5.1 release, it has been closed with a resolution of CURRENT RELEASE.
If the solution does not work for you, please open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.