Skip to content

Commit

Permalink
api_test: fix possible infinite loop when trying to get the ip address
Browse files Browse the repository at this point in the history
If the the ips can not be correctly obtained with container.get_ips()
this while loop will never ends.

Fix this by using:
  while not ips and count != 30

So that even if the ips is empty, the loop will get terminated after
30 attempts (30 seconds later). This retry limit was bumped from 10
to 30 to give it a chance to get the ip address.

If the ip address cannot be obtained, this test will failed with:
  Traceback (most recent call last):
    File "/usr/share/doc/python3-lxc/examples/api_test.py", line 131, in <module>
      assert(len(ips) > 0)
  AssertionError

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
  • Loading branch information
Cypresslin committed Nov 25, 2021
1 parent fe79d87 commit 37ac09d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion examples/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

count = 0
ips = []
while not ips or count == 10:
while not ips and count != 30:
ips = container.get_ips()
time.sleep(1)
count += 1
Expand Down

0 comments on commit 37ac09d

Please sign in to comment.