oVirt / ovirt-ansible-collection

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

Random NoneType object has no attribute 'status' #589

Open lynchmaniac opened 2 years ago

lynchmaniac commented 2 years ago
SUMMARY

Hi, the use case is when I try to start my new VM. The code below runs often and works fine. The VM start correctly. However, sometimes I have an error that occurs randomly. If I run the command again, it works without changing anything in the hypervisor code or settings

COMPONENT NAME

ovirt.ovirt.ovirt_vm

STEPS TO REPRODUCE

I retry this code several times and finally have an "'NoneType' object has no attribute 'status'" error.

- name: ({{ machine.name }}) first start
  ovirt_vm:
    auth: "{{ ovirt_auth }}"
    name: "{{ machine.name }}"
    state: "{{ machine.start_vm | default('running') }}"  
    poll_interval: 60
    timeout: 600
  when: bool_all and bool_start_vm and machine.state == 'present'
EXPECTED RESULTS
TASK [test : (XMOECONTVPIKW1) first start] ***********
redirecting (type: modules) ansible.builtin.ovirt_vm to ovirt.ovirt.ovirt_vm
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~root && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748 `" && echo ansible-tmp-1662039398.522572-508-200510849267748="` echo /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.ovirt_vm to ovirt.ovirt.ovirt_vm
Using module file /root/.ansible/collections/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py
<localhost> PUT /root/.ansible/tmp/ansible-local-14757h1p48o/tmp7p0ktrd7 TO /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748/AnsiballZ_ovirt_vm.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748/ /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748/AnsiballZ_ovirt_vm.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748/AnsiballZ_ovirt_vm.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1662039398.522572-508-200510849267748/ > /dev/null 2>&1 && sleep 0'
ACTUAL RESULTS

the stacktrace in short version

TASK [rhev_infra_node : (XMOECONTVPIKW1) first start] ***********
redirecting (type: modules) ansible.builtin.ovirt_vm to ovirt.ovirt.ovirt_vm
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~root && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714 `" && echo ansible-tmp-1662040927.5511146-507-26188420340714="` echo /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.ovirt_vm to ovirt.ovirt.ovirt_vm
Using module file /root/.ansible/collections/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py
<localhost> PUT /root/.ansible/tmp/ansible-local-147ivpt34ou/tmpnj4yy0r1 TO /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714/AnsiballZ_ovirt_vm.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714/ /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714/AnsiballZ_ovirt_vm.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714/AnsiballZ_ovirt_vm.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1662040927.5511146-507-26188420340714/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py", line 2715, in main
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/module_utils/ovirt.py", line 828, in action
    post_action(entity)
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py", line 1877, in _post_start_action
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py", line 1954, in _wait_for_UP
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/module_utils/ovirt.py", line 384, in wait
    if condition(entity):
  File "/tmp/ansible_ovirt_vm_payload_9ga8erf2/ansible_ovirt_vm_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_vm.py", line 1956, in <lambda>
AttributeError: 'NoneType' object has no attribute 'status'

The error is in theses lines

    def _wait_for_UP(self, vm_service):
        wait(
            service=vm_service,
            condition=lambda vm: vm.status == otypes.VmStatus.UP,
            wait=self.param('wait'),
            timeout=self.param('timeout'),
        )

So sometimes the vm variable is not filled in correctly. Do you have any idea why this use case may occur randomly ? Could this be due to hypervisor slowness?

lynchmaniac commented 2 years ago
SUMMARY

Extra info : I am trying to create an additional disk on my virtual machine. The code below runs often and works fine. My disks are correctly added. However, sometimes I have an error that occurs randomly. If I run the command again, it works without changing anything in the hypervisor code or settings

COMPONENT NAME

ovirt.ovirt.ovirt_disk

STEPS TO REPRODUCE

I retry this code several times and finally have an "'NoneType' object has no attribute 'status'" error.

- name: ({{ machine.name }}) create extra disk
  ovirt_disk:
    auth:
      username: "{{ ovirt_username }}"
      password: "{{ ovirt_password }}"
      hostname: "{{ ovirt_hostname }}"
      url: https://{{ ovirt_hostname }}/ovirt-engine/api
      token: "{{ ansible_facts['ovirt_auth'].token }}"
      insecure: yes
    scsi_passthrough: filtered
    vm_name: "{{ machine.name }}"
    name: "{{ machine.name | upper ~ disk_suffixes[template_info.ovirt_templates[0].disk_attachments | length + index] }}"
    size: "{{ disk.size }}"
    format: raw
    interface: virtio
    storage_domain: "{{ disk.storage }}"
    description: "{{ disk.comment | default('') }}"
    state: "{{ machine.state | default('present') }}"
    poll_interval: 60
    timeout: 300
  loop: "{{ profile.disks | default([]) + machine.disks | default([]) }}"
  loop_control:
    loop_var: disk
    index_var: index
  when: bool_add_disks and bool_all
EXPECTED RESULTS
TASK [test : (machine1) create extra disk] ***
changed: [localhost] => (item={'size': '20GiB', 'comment': 'lorem_ipsum', 'storage': 'domain_1'})
ACTUAL RESULTS

the stacktrace

TASK [rhev_infra_node : (XMOECONTVPIKW1) Création des disques supplémentaires] ***
task path: /builds/ansible/playbooks/roles/rhev_infra_node/tasks/create-vm.yml:305
redirecting (type: modules) ansible.builtin.ovirt_disk to ovirt.ovirt.ovirt_disk
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~root && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602 `" && echo ansible-tmp-1662050436.4582345-480-224325627885602="` echo /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.ovirt_disk to ovirt.ovirt.ovirt_disk
Using module file /root/.ansible/collections/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_disk.py
<localhost> PUT /root/.ansible/tmp/ansible-local-148a6_1ly3d/tmpgq5czux6 TO /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602/AnsiballZ_ovirt_disk.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602/ /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602/AnsiballZ_ovirt_disk.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602/AnsiballZ_ovirt_disk.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1662050436.4582345-480-224325627885602/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_ovirt_disk_payload_4ibfftmu/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_disk.py", line 881, in main
  File "/tmp/ansible_ovirt_disk_payload_4ibfftmu/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/module_utils/ovirt.py", line 691, in create
    wait(
  File "/tmp/ansible_ovirt_disk_payload_4ibfftmu/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/module_utils/ovirt.py", line 386, in wait
    elif fail_condition(entity):
  File "/tmp/ansible_ovirt_disk_payload_4ibfftmu/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_disk.py", line 885, in <lambda>
AttributeError: 'NoneType' object has no attribute 'status'

plugins/modules/ovirt_disk.py The error is in theses lines

            ret = disks_module.create(
                entity=disk if not force_create else None,
                result_state=otypes.DiskStatus.OK if lun is None else None,
                search_params=searchable_attributes(module),
                fail_condition=lambda d: d.status == otypes.DiskStatus.ILLEGAL if lun is None else False,
                force_create=force_create,
                _wait=True if module.params['upload_image_path'] else module.params['wait'],
            )

So it's to be the same kind of error but in another place in the code. The object representing the virtual machine or the disk is sometimes null and therefore cannot have a status. Tell me if you need more information.