Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain autoinstall from combined-cloud-config #1735

Merged
merged 2 commits into from Jul 25, 2023

Conversation

dbungert
Copy link
Collaborator

@dbungert dbungert commented Jul 20, 2023

No description provided.

Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but will review properly when it's marked ready for that :-)

@dbungert dbungert force-pushed the consume-combined-cloud-config branch from ebe3a51 to 650effc Compare July 21, 2023 16:07
"""Return the host system /run/cloud-init/combined-cloud-config.json"""
try:
with open("/run/cloud-init/combined-cloud-config.json") as fp:
return json.load(fp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to log success here so we can track any call-sites since models/network.py also re-reads this file. If we grow lots of readers, we may look toward lru_cache of this function in the future even though it's not very expensive.

Suggested change
return json.load(fp)
config = json.load(fp)
log.debug("Loaded cloud config from /run/cloud-init/combined-cloud-config.json")
return config

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, one question generally about what impact #cloud-config user: overrides or renames the default_user from system_info


cloud_cfg = get_host_combined_cloud_config()
if len(cloud_cfg) > 0:
log.debug("loading cloud config from combined-cloud-config")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to push this message into the get_host_combined_cloud_config() so we can track all callsites that successfully pull this data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# Ubuntu 22.04.2 LTS and earlier, presumably)

cloud_cfg = get_host_combined_cloud_config()
if len(cloud_cfg) > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just use truthy value of dicts to avoid calculating length of keys and then comparing to 0

Suggested change
if len(cloud_cfg) > 0:
if cloud_cfg:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we tend to be more explicit on this point in Subiquity, so I'm matching codebase convention.

log.debug("loading cloud config from combined-cloud-config")
system_info = cloud_cfg.get('system_info', {})
default_user = system_info.get('default_user', {})
self.installer_user_name = default_user.get('name')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, the only thing I can think is a little advertised user-data can manipulate what the default user is using deprecated keys that could override the configuration present in system_info.

Our example doc on this is below and in doc examples for users and groups

        user:
          name: mynewdefault
          sudo: null

I'll think through this path when the PR is up as this #cloud-config override probably also affects the other logical path you have with stages.Init() too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the combined-cloud-config version of ug_util.extract_default, then I think we're set.

The None default user one was rough because it could be encountered with certain cloud-config before we even got as far as showing the UI.

My goal isn't some sort of comprehensive support for weird corner cases here - more along the lines of "don't crash".

@dbungert dbungert changed the title Consume combined cloud config Obtain autoinstall from combined-cloud-config Jul 21, 2023
@dbungert dbungert force-pushed the consume-combined-cloud-config branch 2 times, most recently from 2b5e1d7 to 5049f92 Compare July 25, 2023 00:26
@dbungert dbungert marked this pull request as ready for review July 25, 2023 00:27
Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some nitpicking

"Loaded cloud config from "
"/run/cloud-init/combined-cloud-config.json"
)
return config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth logging something in the "we did not use combined cloud config" case?

self.installer_user_name = username

if username is None:
if self.installer_user_name is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick level extreme but why change this to refer to self.installer_user_name when all the other references are still to username?

dbungert and others added 2 commits July 25, 2023 16:17
Attempt to load autoinstall from
/run/cloud-init/combined-cloud-config.json first, if present.
Fallback to existing methods, which requires that cloud-init in the snap
is able to unpickle the data created by cloud-init outside the snap.
See also LP: #2022102.
Co-authored-by: Chad Smith <chad.smith@canonical.com>
@dbungert dbungert force-pushed the consume-combined-cloud-config branch from 5049f92 to c1d91d6 Compare July 25, 2023 22:21
@dbungert dbungert merged commit ec25740 into canonical:main Jul 25, 2023
12 checks passed
Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more but feel free to not bother

subiquity/cloudinit.py Show resolved Hide resolved
@dbungert dbungert deleted the consume-combined-cloud-config branch July 25, 2023 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants