Skip to content

Commit

Permalink
Merge pull request #2155 from nicomiguelino/fix-splash-screen-ip
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomiguelino authored Dec 11, 2024
2 parents 5b2aed3 + f3cf273 commit 924adba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
27 changes: 26 additions & 1 deletion host_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
import os
import redis
import subprocess
import requests
from tenacity import (
Retrying,
RetryError,
stop_after_attempt,
wait_fixed,
)


REDIS_ARGS = dict(host="127.0.0.1", port=6379, db=0)
Expand Down Expand Up @@ -40,8 +47,26 @@ def get_ip_addresses():

def set_ip_addresses():
rdb = redis.Redis(**REDIS_ARGS)
ip_addresses = get_ip_addresses()

rdb.set('ip_addresses_ready', 'false')

try:
for attempt in Retrying(
stop=stop_after_attempt(10),
wait=wait_fixed(1),
):
with attempt:
response = requests.get('https://1.1.1.1')
response.raise_for_status()
except RetryError:
logging.warning(
'Unable to connect to the Internet. '
'Proceeding with the current IP addresses available.'
)

rdb.set('ip_addresses_ready', 'true')

ip_addresses = get_ip_addresses()
rdb.set('ip_addresses', json.dumps(ip_addresses))


Expand Down
28 changes: 28 additions & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from platform import machine
from settings import settings, ZmqPublisher
from subprocess import check_output, call
from tenacity import (
Retrying,
RetryError,
stop_after_attempt,
wait_fixed,
)
from threading import Thread
from time import sleep
from urllib.parse import urlparse
Expand Down Expand Up @@ -148,6 +154,28 @@ def get_node_ip():
sleep(1)

r.publish('hostcmd', 'set_ip_addresses')

try:
for attempt in Retrying(
stop=stop_after_attempt(20),
wait=wait_fixed(1),
):
environment = getenv('ENVIRONMENT', None)
if environment in ['development', 'test']:
break

with attempt:
ip_addresses_ready = r.get('ip_addresses_ready') or 'false'
if json.loads(ip_addresses_ready):
break
else:
raise Exception(
'Internet connection is not available.')
except RetryError:
logging.warning(
'Internet connection is not available. '
)

ip_addresses = r.get('ip_addresses')

if ip_addresses:
Expand Down
2 changes: 2 additions & 0 deletions requirements/requirements.host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ ansible-core==2.15.9
docker==6.0.0
netifaces2==0.0.22
redis==4.3.4
requests[security]==2.32.3
tenacity==9.0.0

0 comments on commit 924adba

Please sign in to comment.