oVirt / ovirt-ansible-collection

Ansible collection with official oVirt modules and roles
72 stars 91 forks source link

ovirt_vm cd_iso by name results in a 404 error #62

Closed Akasurde closed 4 years ago

Akasurde commented 4 years ago

From @n0p90 on Jul 09, 2020 22:03

SUMMARY

Module ovirt_vm crashes with the error HTTP response code is 404 when starting a VM with an attached ISO provided by name through the cd_iso parameter.

Reverting commit 23761b98801ff6891d38af32d961daba1baf1bce fixes the issue.

ISSUE TYPE
COMPONENT NAME

cd_iso parameter of the ovirt_vm module

ANSIBLE VERSION
ansible 2.9.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.7 (default, Jun  4 2020, 15:43:14) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE

Upload an ISO to iso_storage storage domain (Domain Type: ISO, Storage Type: NFS):

ovirt-iso-uploader -i iso_storage --force upload centos-8.2.iso
EXPECTED RESULTS

The VM boots correctly using the provided ISO image.

ACTUAL RESULTS

The play crashes with the following stack trace:

Traceback (most recent call last):
  File "/tmp/ansible_ovirt_vm_payload_96vlgeqs/ansible_ovirt_vm_payload.zip/ansible/modules/cloud/ovirt/ovirt_vm.py", line 2469, in main
  File "/tmp/ansible_ovirt_vm_payload_96vlgeqs/ansible_ovirt_vm_payload.zip/ansible/modules/cloud/ovirt/ovirt_vm.py", line 1632, in post_present
  File "/tmp/ansible_ovirt_vm_payload_96vlgeqs/ansible_ovirt_vm_payload.zip/ansible/modules/cloud/ovirt/ovirt_vm.py", line 1695, in _attach_cd
  File "/tmp/ansible_ovirt_vm_payload_96vlgeqs/ansible_ovirt_vm_payload.zip/ansible/modules/cloud/ovirt/ovirt_vm.py", line 1688, in __get_cd_id
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/services.py", line 37145, in get
    return self._internal_get(headers, query, wait)
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 211, in _internal_get
    return future.wait() if wait else future
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 55, in wait
    return self._code(response)
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 208, in callback
    self._check_fault(response)
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 130, in _check_fault
    body = self._internal_read_body(response)
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 312, in _internal_read_body
    self._raise_error(response)
  File "/usr/local/lib64/python3.7/site-packages/ovirt_engine_sdk_python-4.3.3-py3.7-linux-x86_64.egg/ovirtsdk4/service.py", line 118, in _raise_error
    raise error
ovirtsdk4.NotFoundError: HTTP response code is 404.

Copied from original issue: ansible/ansible#70547

n0p90 commented 4 years ago

Corresponding reverted commit in this repository: 29363bb1cf77246bec2afc656a3c6ea05f6f10f9

mnecas commented 4 years ago

Hi @n0p90, Done some investigation and I was able to reproduce it only when the disk name was not matching the cd_iso. Are you sure that the disk name is the same? Do you have multiple disks with the same name? Thing is that I did not use the ovirt-iso-uploader but uploaded directly to the iso domain. (tested on oVirt 4.4.1)

n0p90 commented 4 years ago

Hello @mnecas,

Thanks a lot for your response.

As far as I can tell, in oVirt 4.3 it's not possible to upload an image to an ISO storage domain through the web interface. I can only upload an image to Data domains through the web interface and have to use the ovirt-iso-uploader utility on the hosted engine to upload to ISO domains.

Maybe this changed in oVirt 4.4? Or are you uploading to a storage with "Domain Type = Data" and not "Domain Type = ISO"?

I only have one disk with this name. That's the reason why I was using an ISO storage domain instead of a Data one, this way a single ISO can be shared between multiple data centers.

The only workaround I found to make it work in oVirt 4.3 with the current ovirt_vm module is to:

mnecas commented 4 years ago

Maybe this changed in oVirt 4.4? Or are you uploading to storage with "Domain Type = Data" and not "Domain Type = ISO"?

I have tried both Data and ISO and no issues and don't think that the upload method has any effect.

Good thinking to use the disk ID.

Checking code and can't see anything :( Here you can see filter from all disks to get only those with a specific name https://github.com/oVirt/ovirt-ansible-collection/blob/fbc54047075334e2839d44c929f7d0b71e1564aa/plugins/modules/ovirt_vm.py#L1665 If you could rerun it but add to the module before it fails raise Exception(disks)

n0p90 commented 4 years ago

disks is an empty list. The module is crashing here: https://github.com/oVirt/ovirt-ansible-collection/blob/fbc54047075334e2839d44c929f7d0b71e1564aa/plugins/modules/ovirt_vm.py#L1671 The get call results in a API GET request to /disks/centos-8.2.iso which returns a 404.

The underlying problem is that the new code is using the disks_service to get a list of ISO. This only returns the ISOs stored in storage domains with "Domain Type = Data", not the ones in "Domain Type = ISO".

To visually confirm that: ISO stored in ISO domains are not visible on https://ovirt.example.org/ovirt-engine/webadmin/#disks, only the ones stored in Data domains are visible. ISO stored in ISO domains iso_storage are visible on https://ovirt.example.org/ovirt-engine/webadmin/#storage-images;name=iso_storage

mnecas commented 4 years ago

Looks like a difference between 4.3 and 4.4. In 4.4 I can see the disks from Domain Type ISO under https://ovirt.example.org/ovirt-engine/webadmin/#disks (will look into that later if I have an issue in env or it's by design).

Thanks a lot now I know what the issue was!