Commit 2ea07536 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

cli/boot: fix possible KeyError in _waitIpv6Ready

parent 69095b74
......@@ -141,15 +141,13 @@ def _waitIpv6Ready(ipv6_interface):
"""
test if ipv6 is ready on ipv6_interface
"""
ipv6_address = ""
print("[BOOT] Checking if %r has IPv6..." % ipv6_interface)
while ipv6_address == "":
for inet_dict in netifaces.ifaddresses(ipv6_interface)[socket.AF_INET6]:
while True:
for inet_dict in netifaces.ifaddresses(ipv6_interface).get(socket.AF_INET6, ()):
ipv6_address = inet_dict['addr'].split('%')[0]
if isGlobalScopeAddress(ipv6_address):
break
else:
ipv6_address = ""
return
print("[BOOT] [ERROR] No IPv6 found on interface %r, "
"try again in 5 seconds..." % ipv6_interface)
sleep(5)
......
......@@ -340,14 +340,19 @@ class TestCliBoot(CliMixin):
timestamp)
def test_boot_failure(self):
# In this test, node and bang command will fail two time each.
# In this test, the network interfaces will not have
# IP address at the beginning, the global IPv6 address only appears later,
# then format and bang commands will fail two time each.
# `slapos node boot` command retries on failures.
app = slapos.cli.entry.SlapOSApp()
net1 = {socket.AF_INET: ({'addr': '127.0.0.1'},),}
net2 = {socket.AF_INET: ({'addr': '127.0.0.1'},), socket.AF_INET6: ({'addr': 'fe80::1'},),}
net3 = {socket.AF_INET: ({'addr': '127.0.0.1'},), socket.AF_INET6: ({'addr': 'fe80::1'}, {'addr': '2000::1'},),}
with patch('slapos.cli.boot.check_root_user', return_value=True) as check_root_user,\
patch('slapos.cli.boot.sleep') as sleep,\
patch('slapos.cli.boot.netifaces.ifaddresses',
return_value={socket.AF_INET6: ({'addr': '2000::1'},),},),\
side_effect=[net1, net2, net3]),\
patch('slapos.cli.boot._ping_hostname', return_value=0),\
patch('slapos.cli.format.check_root_user', return_value=True),\
patch('slapos.cli.format.logging.FileHandler', return_value=logging.NullHandler()),\
......@@ -362,8 +367,9 @@ class TestCliBoot(CliMixin):
self.assertEqual(do_format.call_count, 3)
self.assertEqual(do_bang.call_count, 3)
# between retries we sleep 15 seconds.
sleep.assert_called_with(15)
# between retries of ping, we sleep 5 seconds
# between retries of bang, we sleep 15 seconds
self.assertEqual(sleep.mock_calls, [mock.call(5)]*2 + [mock.call(15)]*4)
# we have only one logger on the console
from slapos.cli import coloredlogs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment