#89 IndexError: list index out of range
Closed: Fixed by frantisekz. Opened by lnie.

[lnie@dell-r430-20 testcloud]$ python run_testcloud.py instance -c qemu:///session create -u fedora:32
DEBUG:Starting new HTTPS connection (1): getfedora.org:443
DEBUG:https://getfedora.org:443 "GET /releases.json HTTP/1.1" 200 68894
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-32-1.6.x86_64.qcow2
DEBUG:create cloud instance
DEBUG:Creating instance directories
DEBUG:Generated user-data for instance angry_rhodes
DEBUG:Generated meta-data for instance angry_rhodes
DEBUG:creating seed image /var/lib/testcloud/instances/angry_rhodes/angry_rhodes-seed.img
INFO:Seed image generated successfully
INFO:Adding another network device for ssh from host...
Traceback (most recent call last):
File "/home/lnie/test/testcloud/run_testcloud.py", line 4, in
cli.main()
File "/home/lnie/test/testcloud/testcloud/cli.py", line 734, in main
args.func(args)
File "/home/lnie/test/testcloud/testcloud/cli.py", line 419, in _create_instance
tc_instance.spawn_vm()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 924, in spawn_vm
self.write_domain_xml()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 885, in write_domain_xml
port = self.find_next_usable_port()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 843, in find_next_usable_port
next_port = recycleable_ports[i]
IndexError: list index out of range

One reproducer is:
create two "qemu:///session" instances then remove the instance with smaller port number.for example:if 10022,10023 is used,then delete instance with 10022,
and then try to create a "qemu:///session" instance

This can be fixed easily,and I have a fix for this,but would you please have
https://pagure.io/testcloud/pull-request/88 merged first? ^^


This doesn't seem to happen with the current master or released version.

According to your log, the issue was raised on line 843 in instance.py:

File "/home/lnie/test/testcloud/testcloud/instance.py", line 843, in find_next_usable_port
next_port = recycleable_ports[i]
IndexError: list index out of range

however, that file doesn't have 843 lines, it has 723 lines and find_next_usable_port is on line 394. Also, this was tested by the tmt team and neither they found any issues, so I'd say it must be caused by some of your changes for coreos.

Nope,this bug is introduced by your code.Feel free to test according to my reproducer,it can be reproduced easily

[lnie@dell-r430-20 testcloud]$ python run_testcloud.py instance -c qemu:///session create -u fedora:32
DEBUG:create instance
DEBUG:Starting new HTTPS connection (1): getfedora.org:443
DEBUG:https://getfedora.org:443 "GET /releases.json HTTP/1.1" 200 68894
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-32-1.6.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:Generated user-data for instance sharp_benz
DEBUG:Generated meta-data for instance sharp_benz
DEBUG:creating seed image /var/lib/testcloud/instances/sharp_benz/sharp_benz-seed.img
INFO:Seed image generated successfully
INFO:Adding another network device for ssh from host...
Traceback (most recent call last):
File "/home/lnie/test/testcloud/run_testcloud.py", line 4, in
cli.main()
File "/home/lnie/test/testcloud/testcloud/cli.py", line 689, in main
args.func(args)
File "/home/lnie/test/testcloud/testcloud/cli.py", line 386, in _create_instance
tc_instance.spawn_vm()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 500, in spawn_vm
self.write_domain_xml()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 461, in write_domain_xml
port = self.find_next_usable_port()
File "/home/lnie/test/testcloud/testcloud/instance.py", line 418, in find_next_usable_port
next_port = recycleable_ports[i]
IndexError: list index out of range
[lnie@dell-r430-20 testcloud]$ git branch
* master
[lnie@dell-r430-20 testcloud]$ git log | HEAD
bash: HEAD: command not found
[lnie@dell-r430-20 testcloud]$ git log
commit a83bd35fa13b07351b7d46694a232f216ecb94ea (HEAD -> master, tag: 0.5.0, origin/master, origin/HEAD)
Author: František Zatloukal fzatlouk@redhat.com
Date: Mon Mar 22 09:37:52 2021 +0100

Release 0.5.0

Huh,

I tried to reproduce this, the issue didn't happen.

fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:09]
$ /usr/bin/testcloud instance -c qemu:///session remove -f laughing_brahmagupta
DEBUG:remove instance: laughing_brahmagupta
DEBUG:removing instance laughing_brahmagupta from libvirt.
DEBUG:stopping instance laughing_brahmagupta.
DEBUG:Unregistering instance from libvirt.
DEBUG:removing instance /var/lib/testcloud/instances/laughing_brahmagupta from disk
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:19]
$ /usr/bin/testcloud instance -c qemu:///session remove -f focused_snyder
DEBUG:remove instance: focused_snyder
DEBUG:removing instance focused_snyder from libvirt.
DEBUG:stopping instance focused_snyder.
DEBUG:Unregistering instance from libvirt.
DEBUG:removing instance /var/lib/testcloud/instances/focused_snyder from disk
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:22]
$ /usr/bin/testcloud instance -c qemu:///session create -u fedora:33
DEBUG:create instance
DEBUG:Starting new HTTPS connection (1): getfedora.org:443
DEBUG:https://getfedora.org:443 "GET /releases.json HTTP/1.1" 200 68894
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:Generated user-data for instance amazing_lewin
DEBUG:Generated meta-data for instance amazing_lewin
DEBUG:creating seed image /var/lib/testcloud/instances/amazing_lewin/amazing_lewin-seed.img
INFO:Seed image generated successfully
INFO:Adding another network device for ssh from host...
DEBUG:Creating instance amazing_lewin
DEBUG:Polling instance for active network interface
INFO:Successfully booted instance amazing_lewin
The IP of vm amazing_lewin:  127.0.0.1
The SSH port of vm amazing_lewin:  10023
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@127.0.0.1 -p 10023
------------------------------------------------------------
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:29]
$ /usr/bin/testcloud instance -c qemu:///session create -u fedora:33
WARNING:Not proceeding with backingstore cleanup because there are some testcloud instances running.
You can fix this by following command(s):
testcloud instance stop amazing_lewin
DEBUG:create instance
DEBUG:Starting new HTTPS connection (1): getfedora.org:443
DEBUG:https://getfedora.org:443 "GET /releases.json HTTP/1.1" 200 68894
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:Generated user-data for instance jovial_chebyshev
DEBUG:Generated meta-data for instance jovial_chebyshev
DEBUG:creating seed image /var/lib/testcloud/instances/jovial_chebyshev/jovial_chebyshev-seed.img
INFO:Seed image generated successfully
INFO:Adding another network device for ssh from host...
DEBUG:Creating instance jovial_chebyshev
DEBUG:Polling instance for active network interface
INFO:Successfully booted instance jovial_chebyshev
The IP of vm jovial_chebyshev:  127.0.0.1
The SSH port of vm jovial_chebyshev:  10022
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@127.0.0.1 -p 10022
------------------------------------------------------------
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:32]
$ /usr/bin/testcloud instance -c qemu:///session remove -f jovial_chebyshev
DEBUG:remove instance: jovial_chebyshev
DEBUG:removing instance jovial_chebyshev from libvirt.
DEBUG:stopping instance jovial_chebyshev.
DEBUG:Unregistering instance from libvirt.
DEBUG:removing instance /var/lib/testcloud/instances/jovial_chebyshev from disk
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:46]
$ /usr/bin/testcloud instance -c qemu:///session create -u fedora:33
WARNING:Not proceeding with backingstore cleanup because there are some testcloud instances running.
You can fix this by following command(s):
testcloud instance stop amazing_lewin
DEBUG:create instance
DEBUG:Starting new HTTPS connection (1): getfedora.org:443
DEBUG:https://getfedora.org:443 "GET /releases.json HTTP/1.1" 200 68894
DEBUG:Local downloads will be stored in /var/lib/testcloud/backingstores.
DEBUG:successfully changed SELinux context for image /var/lib/testcloud/backingstores/Fedora-Cloud-Base-33-1.2.x86_64.qcow2
DEBUG:Creating instance directories
DEBUG:Generated user-data for instance busy_booth
DEBUG:Generated meta-data for instance busy_booth
DEBUG:creating seed image /var/lib/testcloud/instances/busy_booth/busy_booth-seed.img
INFO:Seed image generated successfully
INFO:Adding another network device for ssh from host...
DEBUG:Creating instance busy_booth
DEBUG:Polling instance for active network interface
INFO:Successfully booted instance busy_booth
The IP of vm busy_booth:  127.0.0.1
The SSH port of vm busy_booth:  10022
------------------------------------------------------------
To connect to the VM, use the following command (password is 'passw0rd'):
ssh fedora@127.0.0.1 -p 10022
------------------------------------------------------------
fanys@fanys-laptop ~/devel/pagure-dist-git (oraculum-versions) [09:31:50]
$

Its' weird.... anyhow, I think we can add some more safeguards into the code so it really can't happen, if you have something ready, we can definitely get that reviewed and merged, befor or after the other PR. It's up to you.

The problem lies here:
i = i + 1
next_port = recycleable_ports[i]
you should check i < len(recycleable_ports)
In my reproducer,if 10022 is not available for some reason, the error will happen 100%

befor or after the other PR. It's up to you.

I'd prefer after #88 ^^

The problem lies here:
i = i + 1
next_port = recycleable_ports[i]
you should check i < len(recycleable_ports)
In my reproducer,if 10022 is not available for some reason, the error will happen 100%

befor or after the other PR. It's up to you.

I'd prefer after #88 ^^

Good catch! Thanks! (I still am not sure why I am not able to reproduce that, but whatever, it's an issue :) )

Commit 927c5c85 fixes this issue

Metadata
Related Pull Requests