Skip to content

Commit

Permalink
fix: retry setting the computer title
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw committed Jul 23, 2024
1 parent f4c7f7e commit 191739e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
29 changes: 21 additions & 8 deletions landscape/client/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path
import subprocess
import sys
import time
from datetime import datetime
from datetime import timezone
from optparse import SUPPRESS_HELP
Expand Down Expand Up @@ -198,7 +199,7 @@ def juju_filename(self):
backwards-compatibility."""
return os.path.join(self.data_path, "juju-info.json")

def auto_configure(self):
def auto_configure(self, retry=False, max_retries=5):
"""Automatically configure the client snap."""
client_conf = snap_http.get_conf("landscape-client").result
auto_enroll_conf = client_conf.get("auto-register", {})
Expand All @@ -208,14 +209,22 @@ def auto_configure(self):
if not enabled or configured:
return

title = generate_computer_title(auto_enroll_conf)
if title:
self.computer_title = title
self.write()
delay = 120
for _ in range(max_retries):
title = generate_computer_title(auto_enroll_conf)
if title:
self.computer_title = title
self.write()

auto_enroll_conf["configured"] = True
client_conf["auto-register"] = auto_enroll_conf
snap_http.set_conf("landscape-client", client_conf)
auto_enroll_conf["configured"] = True
client_conf["auto-register"] = auto_enroll_conf
snap_http.set_conf("landscape-client", client_conf)

break
elif retry:
# retry until we get the computer title
time.sleep(delay)
delay *= 2


def get_versioned_persist(service):
Expand Down Expand Up @@ -243,11 +252,15 @@ def generate_computer_title(auto_enroll_config):
snap_info = get_snap_info()
wait_for_serial = auto_enroll_config.get("wait-for-serial-as", True)
if "serial" not in snap_info and wait_for_serial:
logging.debug(
f"No serial assertion in snap info {snap_info}, waiting..."
)
return

hostname = get_fqdn()
wait_for_hostname = auto_enroll_config.get("wait-for-hostname", False)
if hostname == "localhost" and wait_for_hostname:
logging.debug("Waiting for hostname...")
return

nics = get_active_device_info(default_only=True)
Expand Down
2 changes: 1 addition & 1 deletion landscape/client/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def run(args=sys.argv, reactor=None):
init_logging(config, "watchdog")

if IS_SNAP:
config.auto_configure()
config.auto_configure(retry=True)

application = Application("landscape-client")
watchdog_service = WatchDogService(config)
Expand Down
2 changes: 1 addition & 1 deletion snap-http
Submodule snap-http updated 2 files
+14 −0 CHANGELOG.md
+1 −1 pyproject.toml

0 comments on commit 191739e

Please sign in to comment.