Bug 1853924

Summary: Fails to import template as OVA from the given configuration if the VM is not removed
Product: [oVirt] ovirt-engine Reporter: Polina <pagranat>
Component: BLL.VirtAssignee: Shmuel Melamud <smelamud>
Status: CLOSED CURRENTRELEASE QA Contact: Polina <pagranat>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.4.1CC: ahadas, bugs, dfodor, emarcus, michal.skrivanek, mzamazal, smelamud
Target Milestone: ovirt-4.5.2Keywords: ZStream
Target Release: 4.5.2Flags: sbonazzo: ovirt-4.5+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: ovirt-engine-4.5.2 Doc Type: Bug Fix
Doc Text:
Previously, when attempting to add a disk using ovirt-engine SDK script when the disk already exists, the operation fails, and an exception is thrown. With this release, the Add Disk Functionality checks for duplicate disks, and fails gracefully with a readable error message when the disk to be inserted already exists.
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-08-30 08:47:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Virt RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1848586    
Bug Blocks:    
Attachments:
Description Flags
engine log and upload_ova_as_template.py script
none
Modified upload_ova_as_template.py script none

Description Polina 2020-07-05 17:32:58 UTC
Created attachment 1699950 [details]
engine log and upload_ova_as_template.py script

Description of problem:Operation Failed: [Internal Engine Error] when trying to import template as OVA with script


Version-Release number of selected component (if applicable):
ovirt-engine-4.4.1.2-0.10.el8ev.noarch

How reproducible:always


Steps to Reproduce:
1. Create a VM 
2. Export VM as OVA
3. Don't remove the VM and try to import as OVA using the attached script, like

python3 upload_ova_as_template.py pa6.ova golden_env_mixed_1 nfs_0

Actual results:

2020-07-05 19:14:22,965+03 INFO  [org.ovirt.engine.core.utils.transaction.TransactionSupport] (default task-15) [4e9ef671-17ab-439b-9c3b-2a6acd0514b5] transaction rolled back
2020-07-05 19:14:22,966+03 ERROR [org.ovirt.engine.core.bll.exportimport.ImportVmTemplateFromConfigurationCommand] (default task-15) [4e9ef671-17ab-439b-9c3b-2a6acd0514b5] Command 'org.ovirt.engine.core.bll.exportimport.ImportVmTemplateFromConfigurationCommand' failed: CallableStatementCallback; SQL [{call insertvmtemplate(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}ERROR: duplicate key value violates unique constraint "pk_vm_static"
...

2020-07-05 19:14:22,971+03 ERROR [org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector] (default task-15) [4e9ef671-17ab-439b-9c3b-2a6acd0514b5] EVENT_ID: TEMPLATE_IMPORT_FROM_CONFIGURATION_FAILED(181), Failed to import Template pa5 from the given configuration.
2020-07-05 19:14:22,976+03 ERROR [org.ovirt.engine.api.restapi.resource.AbstractBackendResource] (default task-15) [] Operation Failed: [Internal Engine Error]

Expected results: 


Additional info:

Comment 1 Polina 2020-07-05 20:54:53 UTC
relevant for 4.3 and 4.4

Comment 2 Steven Rosenberg 2020-07-20 14:28:50 UTC
As per our discussions concerning BZ 1848586, we are reusing the disk identifiers from the ovf file to insert the disks which means we are not supporting this feature where the disks with the same identifiers already exist. Unless we want to support cloning for this request we may consider closing this issue.

Comment 3 Arik 2020-07-20 20:55:37 UTC
Well, we should avoid the exception.
We need to return a proper validation error in this case.

Comment 4 Polina 2021-06-22 11:12:24 UTC
still happens in ovirt-engine-4.4.7.4-0.9.el8ev.noarch

Comment 5 Liran Rotenberg 2021-06-22 13:12:21 UTC
Although one validation is fixed already in this bug (disks existing), the problem here is that we import a VM as a template.
The imported template uses the same ID as the VM, which cause the vm_static key violation. The validation we use is:
VmTemplate duplicateTemplate = vmTemplateDao.get(getParameters().getVmTemplate().getId());
        // check that the template does not exists in the target domain
        if (duplicateTemplate != null) {
            return failValidation(EngineMessage.VMT_CANNOT_IMPORT_TEMPLATE_EXISTS,
                    String.format("$TemplateName %1$s", duplicateTemplate.getName()));
        }
It won't find a thing, since the source is a VM. But if we will search the ID in vmStaticDao for example, we will see it's already there.
We should validate it as well. Since both templates and vms can be found in vm_static, it should be enough to check for duplicate in this table.

Comment 7 Arik 2022-06-30 14:22:19 UTC
Liran posted https://gerrit.ovirt.org/115362 but it seems like we'd need another part to solve this bz
so moving back to ASSIGNED

Comment 8 Shmuel Melamud 2022-07-19 02:45:38 UTC
Created attachment 1898029 [details]
Modified upload_ova_as_template.py script

1. When a template is imported from an OVA, all disks should be uploaded at the beginning and IDs of the disks should be referenced in the OVF.
2. Import with preloaded disks uses the template ID from the OVF, so a new template ID should be generated.

After these two modifications (see the script attached), the import finishes successfully. No changes in the Engine required.

Comment 9 Shmuel Melamud 2022-07-19 02:52:45 UTC
Polina, Arik, do you consider such behaviour of REST API as correct?

Comment 10 Arik 2022-07-19 06:23:00 UTC
(In reply to Shmuel Melamud from comment #9)
> Polina, Arik, do you consider such behaviour of REST API as correct?

yes, for the import-as-clone flow
for ordinary import flow, we need to keep the id since there might be VMs that are imported later on which are based on that template

Comment 11 Polina 2022-07-19 08:10:53 UTC
(In reply to Arik from comment #10)
> (In reply to Shmuel Melamud from comment #9)
> > Polina, Arik, do you consider such behaviour of REST API as correct?
> 
> yes, for the import-as-clone flow
> for ordinary import flow, we need to keep the id since there might be VMs
> that are imported later on which are based on that template

agree :)

Comment 12 Shmuel Melamud 2022-07-19 10:42:58 UTC
If so, I consider this bz as solved.

Comment 13 Arik 2022-07-19 11:12:43 UTC
(In reply to Shmuel Melamud from comment #12)
> If so, I consider this bz as solved.

Shmuel, which patch addresses the last part of comment 5?

Comment 14 Shmuel Melamud 2022-07-19 16:08:11 UTC
(In reply to Arik from comment #13)
> Shmuel, which patch addresses the last part of comment 5?

You mean checking the existence of the same ID so the command will fail in validation instead of DB error? You're right, let me fix that.

Comment 15 Milan Zamazal 2022-07-27 10:20:26 UTC
The last patch has been merged and it looks like everything is resolved now, so moving to MODIFIED.

Comment 16 Polina 2022-08-02 11:48:03 UTC
verified on ovirt-engine-4.5.2-0.3.el8ev.noarch by running automation test rhevmtests.compute.virt.external_providers.ova.test_ova_sanity.TestUploadOVAasTemplate (commenting out the VM removing part  assert helper.remove_vm_sampler(self.vm_name), f"Failed to remove VM {self.vm_name} before uploading")

Comment 17 Sandro Bonazzola 2022-08-30 08:47:42 UTC
This bugzilla is included in oVirt 4.5.2 release, published on August 10th 2022.
Since the problem described in this bug report should be resolved in oVirt 4.5.2 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.