do not re-set installer user password if it can be found in cloud-init.log

To avoid re-setting the password when refreshing from a subiquity that
does not have this change
This commit is contained in:
Michael Hudson-Doyle 2021-03-24 14:42:20 +13:00
parent 87c2e7539e
commit 47eefa42fe
1 changed files with 21 additions and 0 deletions

View File

@ -116,6 +116,20 @@ class MetaController:
ips=ips)
def get_installer_password_from_cloudinit_log():
try:
fp = open("/var/log/cloud-init-output.log")
except FileNotFoundError:
return None
with fp:
for line in fp:
if line.startswith("installer:"):
return line[len("installer:"):].strip()
return None
class SubiquityServer(Application):
snapd_socket_path = '/run/snapd.socket'
@ -409,6 +423,13 @@ class SubiquityServer(Application):
if self.opts.dry_run:
self.installer_user_passwd = rand_user_password()
return
# refreshing from a version of subiquity that relied on
# cloud-init to set the password to one that does not should
# not reset the password.
passwd = get_installer_password_from_cloudinit_log()
if passwd:
self.installer_user_passwd = passwd
return
try:
pwd.getpwnam('installer')
except KeyError: