move waiting for cloud-init to server, where it makes sense

This commit is contained in:
Michael Hudson-Doyle 2020-12-08 21:05:36 +13:00
parent a8b9a42c21
commit bbcf050205
2 changed files with 29 additions and 29 deletions

View File

@ -17,8 +17,12 @@ import argparse
import logging
import os
import sys
import time
from cloudinit import atomic_helper, safeyaml, stages
from subiquitycore.log import setup_logger
from subiquitycore.utils import run_command
from .common import (
LOGDIR,
@ -104,6 +108,31 @@ def main():
logger.info("Starting Subiquity server revision {}".format(version))
logger.info("Arguments passed: {}".format(sys.argv))
if not opts.dry_run:
ci_start = time.time()
status_txt = run_command(["cloud-init", "status", "--wait"]).stdout
logger.debug("waited %ss for cloud-init", time.time() - ci_start)
if "status: done" in status_txt:
logger.debug("loading cloud config")
init = stages.Init()
init.read_cfg()
init.fetch(existing="trust")
cloud = init.cloudify()
autoinstall_path = '/autoinstall.yaml'
if 'autoinstall' in cloud.cfg:
if not os.path.exists(autoinstall_path):
atomic_helper.write_file(
autoinstall_path,
safeyaml.dumps(
cloud.cfg['autoinstall']).encode('utf-8'),
mode=0o600)
if os.path.exists(autoinstall_path):
opts.autoinstall = autoinstall_path
else:
logger.debug(
"cloud-init status: %r, assumed disabled",
status_txt)
server = SubiquityServer(opts, block_log_dir)
server.note_file_for_apport(

View File

@ -20,12 +20,8 @@ import os
import fcntl
import subprocess
import sys
import time
from cloudinit import atomic_helper, safeyaml, stages
from subiquitycore.log import setup_logger
from subiquitycore.utils import run_command
from .common import (
LOGDIR,
@ -122,31 +118,6 @@ def main():
logger.info("Starting Subiquity revision {}".format(version))
logger.info("Arguments passed: {}".format(sys.argv))
if not opts.dry_run:
ci_start = time.time()
status_txt = run_command(["cloud-init", "status", "--wait"]).stdout
logger.debug("waited %ss for cloud-init", time.time() - ci_start)
if "status: done" in status_txt:
logger.debug("loading cloud config")
init = stages.Init()
init.read_cfg()
init.fetch(existing="trust")
cloud = init.cloudify()
autoinstall_path = '/autoinstall.yaml'
if 'autoinstall' in cloud.cfg:
if not os.path.exists(autoinstall_path):
atomic_helper.write_file(
autoinstall_path,
safeyaml.dumps(
cloud.cfg['autoinstall']).encode('utf-8'),
mode=0o600)
if os.path.exists(autoinstall_path):
opts.autoinstall = autoinstall_path
else:
logger.debug(
"cloud-init status: %r, assumed disabled",
status_txt)
if opts.ssh:
from subiquity.ui.views.help import (
ssh_help_texts, get_installer_password)