Bug 1937408

Summary: [RFE] Add ability to import template from OVA in image_template role
Product: Red Hat Enterprise Virtualization Manager Reporter: amashah
Component: ovirt-ansible-collectionAssignee: Martin Necas <mnecas>
Status: CLOSED ERRATA QA Contact: Barbora Dolezalova <bdolezal>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.4.4CC: ahadas, apinnick, dfodor, emarcus, mavital, michal.skrivanek, mnecas, mperina, mtessun, oliel
Target Milestone: ovirt-4.5.1Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: ovirt-ansible-collection-2.0.4-1, ovirt-engine-4.5.0.8 Doc Type: Enhancement
Doc Text:
The following key-value pairs were added to the KVM dictionary, in the ovirt_template module for importing a template from OVA: * URL, for example, qemu:///system * storage_domain for converted disks * host from which the template is imported * clone to regenerate imported template's identifiers
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-07-14 12:55:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1941581, 1971317    
Bug Blocks:    

Description amashah 2021-03-10 15:26:15 UTC
Description of problem:
Currently we can use the image_template [1] Ansible role to create a template from a qcow or glance image. 

This request is to expand the role to include importing a template from OVA.

We have python API example [2] to do this, the customer would prefer to do it with Ansible though.

[1] https://github.com/oVirt/ovirt-ansible-collection/tree/master/roles/image_template
Version-Release number of selected component (if applicable):

[2] https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/upload_ova_as_vm_or_template.py


While we know it is possible to go from OVA -> VM -> Template already by using ovirt_vm and ovirt_template modules, the customer would like to go directly from OVA -> template.

Comment 1 Martin Necas 2021-03-15 12:16:47 UTC
Hi,
currently, we are not able to import the template from ova via API it might have required some changes. 
Ori could you please check maybe it could be added to the API?

I added PR on the collection which solves what the users request but it creates the VM from the ova image and then creates a template.

Comment 2 Arik 2021-03-22 13:04:08 UTC
@amashah , can you please clarify what is requested here, is it
(1) to ask ovirt-engine/RHVM to import a template from a specified location that the hosts can access as with the UI
(2) to upload an OVA you have at hand (locally, on the client side) to ovirt-engine/RHVM as with the above mentioned SDK example

Those are not the same as since both the UI and SDK examples were mentioned, I'm a bit confused

Comment 5 Sandro Bonazzola 2022-03-29 16:16:40 UTC
We are past 4.5.0 feature freeze, please re-target.

Comment 10 Barbora Dolezalova 2022-05-09 14:52:39 UTC
We expected this feature to be implemented in image_template role (as it was mentioned in the bug description) but we found it in the modules.
It failed, see details below.

Used versions:
ovirt-engine-4.5.0.6-0.7.el8ev.noarch
ovirt-ansible-collection-2.0.3-1.el8ev.noarch

Reproduction steps
1. We couldn't export template as OVA [1] so we exported VM as OVA which worked. 
2. We used: 
---
- name: oVirt image template
  hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - ovirt_auth:
        url: https://<engine-fqdn>/ovirt-engine/api
        username: admin@internal
        ca_file: /etc/pki/ovirt-engine/ca.pem
        password: password

    - name: Import external ova template
      ovirt.ovirt.ovirt_template:
        cluster: golden_env_mixed_1
        name: Bla
        state: present
        timeout: 1800
        poll_interval: 30
        kvm:
          host: host_mixed_1
          url: ova:///tmp/Bla.ova
          storage_domain: nfs_0
        auth: "{{ovirt_auth}}"

  collections:
    - ovirt.ovirt

TASK [Import external ova template] ********************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ovirtsdk4.Error: Fault reason is "Operation Failed". Fault detail is "[Internal Engine Error]". HTTP response code is 400.
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Fault reason is \"Operation Failed\". Fault detail is \"[Internal Engine Error]\". HTTP response code is 400."}

In engine.log:
2022-05-09 17:38:30,449+03 ERROR [org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor] (default task-85) [286921d1-a776-455d-b469-374c22eb340f] Exception: Permission denied
2022-05-09 17:38:30,449+03 ERROR [org.ovirt.engine.core.bll.GetVmTemplateFromOvaQuery] (default task-85) [286921d1-a776-455d-b469-374c22eb340f] Query 'GetVmTemplateFromOvaQuery' failed: For input string: ""
2022-05-09 17:38:30,449+03 ERROR [org.ovirt.engine.core.bll.GetVmTemplateFromOvaQuery] (default task-85) [286921d1-a776-455d-b469-374c22eb340f] Exception: java.lang.NumberFormatException: For input string: ""
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.base/java.lang.Integer.parseInt(Integer.java:662)
        at java.base/java.lang.Integer.valueOf(Integer.java:983)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleRunnerHttpClient.getLastEventId(AnsibleRunnerHttpClient.java:117)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:185)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:102)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:94)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.GetFromOvaQuery.runAnsibleQueryOvaInfoPlaybook(GetFromOvaQuery.java:68)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.GetFromOvaQuery.executeQueryCommand(GetFromOvaQuery.java:43)
...
2022-05-09 17:38:30,455+03 ERROR [org.ovirt.engine.api.restapi.resource.AbstractBackendResource] (default task-85) [] Operation Failed: [Internal Engine Error]


The other error [1] when we tried to export the template as OVA:
2022-05-09 17:27:28,979+03 ERROR [org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor] (default task-82) [3ecfc56e-404c-4384-967a-917023fcbf0a] Exception: Permission denied
2022-05-09 17:27:28,979+03 ERROR [org.ovirt.engine.core.bll.exportimport.ExportVmTemplateToOvaCommand] (default task-82) [3ecfc56e-404c-4384-967a-917023fcbf0a] Error during ValidateFailure.: java.lang.NumberFormatException: For input string: ""
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.base/java.lang.Integer.parseInt(Integer.java:662)
        at java.base/java.lang.Integer.valueOf(Integer.java:983)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleRunnerHttpClient.getLastEventId(AnsibleRunnerHttpClient.java:117)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:185)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:75)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.common.utils.ansible.AnsibleExecutor.runCommand(AnsibleExecutor.java:52)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ExportOvaCommand.validateTargetFolder(ExportOvaCommand.java:113)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ExportOvaCommand.validate(ExportOvaCommand.java:90)
        at deployment.engine.ear.bll.jar//org.ovirt.engine.core.bll.exportimport.ExportVmTemplateToOvaCommand.validate(ExportVmTemplateToOvaCommand.java:76)
...

Comment 11 Martin Perina 2022-05-09 18:32:19 UTC
Moving to 4.5.1, too late to fix on 4.5.0-1

Comment 13 Martin Necas 2022-06-07 10:10:25 UTC
I was not able to reproduce this issue on 
engine: 4.5.0.8-1.el8
ovirt-ansible-collection: 2.0.4-1

Could you please try the template import again?
Looking at the log looks like an engine/AR issue.

Comment 15 Barbora Dolezalova 2022-06-16 11:42:52 UTC
Verified in ovirt-ansible-collection-2.0.4-1.el8ev.noarch, ovirt-engine-4.5.1-0.62.el8ev.noarch

Comment 20 errata-xmlrpc 2022-07-14 12:55:59 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 (RHV Engine and Host Common Packages 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-2022:5584

Comment 21 meital avital 2022-08-07 12:49:26 UTC
Due to QE capacity, we are not going to cover this issue in our automation