Skip to content

Conversation

Cristi1324
Copy link
Contributor

No description provided.

@Cristi1324 Cristi1324 force-pushed the refactor-cloud-init branch from b892b9d to 175c87e Compare August 13, 2025 14:41
@@ -97,6 +97,12 @@ def _compose_netplan_cfg(self, nics_info):
}
return yaml.dump(cfg, default_flow_style=False)

def _has_systemd_chroot(self):
if self._test_path("/lib/systemd/system"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just return self._test_path('/lib/systemd/system')? :D

cloud_cfg_path = 'etc/cloud/cloud.cfg'
if not self._test_path(cloud_cfg_path):
return DEFAULT_CLOUD_USER
cloud_cfg_content = self._read_file(cloud_cfg_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use _read_file_sudo here.

self._ensure_cloud_init_enabled()
self._reset_cloud_init_run()
if self._osmorphing_parameters.get('retain_user_credentials', False):
self._configure_cloud_init_user_retention()
Copy link
Contributor

Choose a reason for hiding this comment

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

This method overwrites cloud.cfg. I'd like to add those mods into a separate file called 99_coriolis.cfg inside cloud.cfg.d. Save them inside a cloud_cfg_mods and only at the end of this _configure_cloud_init method you'd write that file.
Also, here is what the set_dhcp mods should also be included.

@Cristi1324 Cristi1324 force-pushed the refactor-cloud-init branch 3 times, most recently from c698ff2 to 9219663 Compare August 22, 2025 10:58
Copy link
Contributor

@Dany9966 Dany9966 left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just a couple of nits

'ssh_pwauth': True,
'users': None
}
cloud_cfg_mods = {**cloud_cfg_mods,
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think it's cleaner if you use update()

Suggested change
cloud_cfg_mods = {**cloud_cfg_mods,
cloud_cfg_mods.update(cloud_cfg_user_retention)


if not self._osmorphing_parameters.get('set_dhcp', False):
disabled_network_config = {"network": {"config": "disabled"}}
cloud_cfg_mods = {**cloud_cfg_mods, **disabled_network_config}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

@Cristi1324 Cristi1324 force-pushed the refactor-cloud-init branch from 9219663 to 07eba4e Compare August 26, 2025 10:22
@Dany9966
Copy link
Contributor

Dany9966 commented Sep 2, 2025

LGTM. Please update tests as well. Feel free to open up the PR as well

cloud_cfg_path))
continue
"Configuring cloud-init additional options")
new_cloud_cfg = yaml.dump(cloud_cfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please always use safe loaders and dumpers when using yaml module.
I.E.: yaml.load(content, Loader=yaml.SafeLoader)

Suggested change
new_cloud_cfg = yaml.dump(cloud_cfg)
new_cloud_cfg = yaml.dump(cloud_cfg. Dumper=yaml.SafeDumper)

LOG.warn("Could not find %s. Skipping reconfiguration." % (
cloud_cfg_path))
continue
"Configuring cloud-init additional options")
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think this sounds better

Suggested change
"Configuring cloud-init additional options")
"Customizing cloud-init configuration")

cloud_cfg_paths.append("%s/%s" % (cloud_cfgs_dir, path))

if not self._test_path(cloud_cfgs_dir):
exception.CoriolisException("Could not find %s" % cloud_cfgs_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be better to just create this directory instead of straight out erroring out. Cloud-init will look for this location regardless, it's not customizable afaik. (if it is, find a way to locate it)
At least execute: mkdir -p /etc/cloud/cloud.cfg.d

installer_config_path = "/etc/cloud/cloud.cfg.d/99-installer.cfg"
if self._test_path(installer_config_path):
self._event_manager.progress_update(
"Disabling Ubuntu installer-generated cloud-config")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is in base now, I think you should drop the Ubuntu

self._exec_cmd_chroot(f"rm {disabler_file}")
if self._test_path(system_conf_disabler):
self._exec_cmd_chroot(
"sed -i '/cloud-init=disabled/d' %s" % system_conf_disabler)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this will work as you expect it, it could just leave an empty variable and maybe even bork the system.conf file. If you haven't already, please do a test and see if it gets enabled and systemd doesn't just fall on its head.
Let me know if you already tested this and it works.

"sed -i '/cloud-init=disabled/d' %s" % system_conf_disabler)
if self._test_path(grub_conf_disabler):
self._exec_cmd_chroot(
"sed -i '/cloud-init=disabled/d' %s" % grub_conf_disabler)
Copy link
Contributor

Choose a reason for hiding this comment

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

This I know for sure will not work, because any grub update needs an update-grub or equivalent (redhat-derivates have a different command).

In some cases, this grub update may not happen, so we need to also run the grub update command here.

I think for both cases (grub and system.conf), you'll need to first grep and then do sed and/or update commands.

else:
self._create_cloudinit_user()

if not self._osmorphing_parameters.get('set_dhcp', False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please set set_dhcp's default to True. Otherwise, in providers where we do not support this option, it will always disable cloud-init networking.

Suggested change
if not self._osmorphing_parameters.get('set_dhcp', False):
if not self._osmorphing_parameters.get('set_dhcp', True):

Comment on lines 272 to 273
package_names
)
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT:

Suggested change
package_names
)
package_names)

self._run_dracut()
self._configure_cloud_init()
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT for consistency's sake:

Suggested change
self._run_dracut()
self._configure_cloud_init()
self._configure_cloud_init()
self._run_dracut()

@Dany9966
Copy link
Contributor

Dany9966 commented Sep 4, 2025

LGTM. Please update tests. Feel free to open up the PR as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants