From e921be03f802ee154ed1ddf044e276b23af0d2b6 Mon Sep 17 00:00:00 2001 From: Darren Archibald Date: Fri, 23 Feb 2024 07:52:25 -0800 Subject: [PATCH] Add Oracle to distro detection logic in cloud.cfg.tmpl Oracle Linux is being detected as "ol" variant by cloud-init. This patch adds "ol" to the list of supported variants, and applies needed settings to it. You can notice that variant "ol" is being set as distro "rhel" in a couple of places, that is expected as this designated that base distro for "ol" is "rhel" ( which is true ) The main reason for this change is that cloud-init package dropped hardcoded configs that set OL as rhel and to make cloud-init behave on OL systems as expected we need to add "ol" designation to supported list. Orabug: 34845400 Signed-off-by: Alex Burmashev Signed-off-by: Darren Archibald --- cloudinit/distros/__init__.py | 1 + cloudinit/sources/DataSourceRbxCloud.py | 2 +- config/cloud.cfg.tmpl | 33 ++++++++++++++++++------- systemd/cloud-config.service.tmpl | 4 +++ systemd/cloud-final.service.tmpl | 4 ++- systemd/cloud-init-local.service.tmpl | 12 ++++++--- systemd/cloud-init.service.tmpl | 8 ++++-- tests/unittests/test_util.py | 1 + 8 files changed, 48 insertions(+), 17 deletions(-) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 79e2623..8f1381b 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -78,6 +78,7 @@ OSFAMILIES = { "rhel", "rocky", "virtuozzo", + "ol", ], "suse": [ "opensuse", diff --git a/cloudinit/sources/DataSourceRbxCloud.py b/cloudinit/sources/DataSourceRbxCloud.py index 9214f1b..5379132 100644 --- a/cloudinit/sources/DataSourceRbxCloud.py +++ b/cloudinit/sources/DataSourceRbxCloud.py @@ -60,7 +60,7 @@ def _sub_arp(cmd): def gratuitous_arp(items, distro): source_param = "-S" - if distro.name in ["fedora", "centos", "rhel"]: + if distro.name in ["fedora", "centos", "rhel", "ol"]: source_param = "-s" for item in items: try: diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl @@ -39,7 +39,7 @@ - name: root lock_passwd: false {% else %} - - default + - default {% endif %} {% if variant == "photon" %} @@ -58,9 +58,9 @@ {% endif %} {%- if variant in ["alpine", "amazon", "fedora", "OpenCloudOS", "openeuler", - "openmandriva", "photon", "TencentOS"] or is_rhel %} + "openmandriva", "photon", "TencentOS", "ol"] or is_rhel %} -{% if is_rhel %} +{% if variant in ["ol"] or is_rhel %} mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service,_netdev', '0', '2'] {% else %} mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2'] @@ -101,7 +101,7 @@ {% endif -%} -{% if is_rhel %} +{% if variant in ["ol"] or is_rhel %} # Default redhat settings: ssh_deletekeys: true ssh_genkeytypes: ['rsa', 'ecdsa', 'ed25519'] @@ -149,9 +149,9 @@ {% if variant == "ubuntu" %} - ubuntu_autoinstall {% endif %} -{% if variant not in ["photon"] %} +{% if variant not in ["photon", "ol"] %} - ssh_import_id -{% if not is_rhel %} +{% if variant not in ["ol"] or is_rhel %} - keyboard {% endif %} - locale @@ -167,18 +167,20 @@ - ubuntu_advantage {% endif %} {% elif variant in ["fedora", "mariner", "openeuler", "openmandriva", - "photon"] or is_rhel %} + "photon", "ol"] or is_rhel %} {% if is_rhel %} - rh_subscription {% endif %} -{% if variant not in ["mariner", "photon"] %} +{% if variant not in ["mariner", "photon", "ol"] %} - spacewalk {% endif %} - yum_add_repo {% elif variant == "suse" %} - zypper_add_repo {% endif %} +{% if variant not in ["ol"] %} - ntp +{% endif %} - timezone - disable_ec2_metadata - runcmd @@ -197,13 +199,17 @@ {% if variant in ["ubuntu", "unknown"] %} - ubuntu_drivers {% endif %} +{% if variant not in ["ol"] %} - write_files_deferred +{% endif %} - puppet - chef - ansible - mcollective - salt_minion +{% if variant not in ["ol"] %} - reset_rmc +{% endif %} - rightscale_userdata - scripts_vendor - scripts_per_once @@ -212,7 +218,9 @@ - scripts_user - ssh_authkey_fingerprints - keys_to_console +{% if variant not in ["ol"] %} - install_hotplug +{% endif %} - phone_home - final_message - power_state_change @@ -224,8 +232,10 @@ {% if variant in ["alpine", "amazon", "arch", "debian", "fedora", "freebsd", "gentoo", "mariner", "netbsd", "openbsd", "OpenCloudOS", "openeuler", "openmandriva", "photon", "suse", "TencentOS", - "ubuntu"] or is_rhel %} + "ubuntu", "centos", "rhel"] %} distro: {{ variant }} +{% elif variant == "ol" %} + distro: rhel {% elif variant == "dragonfly" %} distro: dragonflybsd {% else %} @@ -234,7 +244,9 @@ {% endif %} # Default user name + that default users groups (if added/used) default_user: -{% if variant in usernames %} +{% if variant == "ol" %} + name: cloud-user +{% elif variant in usernames %} name: {{ usernames[variant] }} {% else %} name: {{ variant }} @@ -245,7 +257,12 @@ or is_bsd or is_rhel %} lock_passwd: True {% endif %} -{% if variant in gecos %} +{% if variant == "ol" %} + lock_passwd: true +{% endif %} +{% if variant == "ol" %} + gecos: Cloud User +{% elif variant in gecos %} gecos: {{ gecos[variant] }} {% else %} gecos: {{ variant }} Cloud User @@ -254,7 +271,7 @@ groups: [{{ groups[variant] }}] {% elif is_bsd %} groups: [wheel] -{% elif is_rhel %} +{% elif variant in ["ol"] or is_rhel %} groups: [adm, systemd-journal] {% else %} groups: [wheel, adm, systemd-journal] @@ -321,7 +338,7 @@ {% endif %} {% if variant in ["alpine", "amazon", "arch", "debian", "fedora", "gentoo", "mariner", "OpenCloudOS", "openeuler", "openmandriva", - "photon", "suse", "TencentOS", "ubuntu", "unknown"] + "photon", "suse", "TencentOS", "ubuntu", "unknown", "ol"] or is_rhel %} # Other config here will be given to the distro class and/or path classes paths: @@ -365,6 +382,6 @@ ssh_svcname: ssh {% elif variant in ["alpine", "amazon", "arch", "fedora", "gentoo", "mariner", "OpenCloudOS", "openeuler", "openmandriva", - "photon", "suse", "TencentOS"] or is_rhel %} + "photon", "suse", "TencentOS", "ol"] or is_rhel %} ssh_svcname: sshd {% endif %} diff --git a/systemd/cloud-config.service.tmpl b/systemd/cloud-config.service.tmpl index 31d9d98..8222c7c 100644 --- a/systemd/cloud-config.service.tmpl +++ b/systemd/cloud-config.service.tmpl @@ -2,11 +2,15 @@ [Unit] Description=Apply the settings specified in cloud-config After=network-online.target cloud-config.target +{% if variant not in "ol" %} After=snapd.seeded.service +{% endif %} Before=systemd-user-sessions.service Wants=network-online.target cloud-config.target +{% if variant in ["rhel", "ol"] %} ConditionPathExists=!/etc/cloud/cloud-init.disabled ConditionKernelCommandLine=!cloud-init=disabled +{% endif %} ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled [Service] diff --git a/systemd/cloud-final.service.tmpl b/systemd/cloud-final.service.tmpl index bcf8b00..f84c687 100644 --- a/systemd/cloud-final.service.tmpl +++ b/systemd/cloud-final.service.tmpl @@ -7,8 +7,10 @@ After=multi-user.target Before=apt-daily.service {% endif %} Wants=network-online.target cloud-config.service +{% if variant in ["rhel", "ol"] %} ConditionPathExists=!/etc/cloud/cloud-init.disabled ConditionKernelCommandLine=!cloud-init=disabled +{% endif %} ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled @@ -18,7 +20,7 @@ ExecStart=/usr/bin/cloud-init modules --mode=final RemainAfterExit=yes TimeoutSec=0 KillMode=process -{% if variant == "rhel" %} +{% if variant in ["rhel", "ol"] %} # Restart NetworkManager if it is present and running. ExecStartPost=/bin/sh -c 'u=NetworkManager.service; \ out=$(systemctl show --property=SubState $u) || exit; \ diff --git a/systemd/cloud-init-local.service.tmpl b/systemd/cloud-init-local.service.tmpl index 3a1ca7f..4750c36 100644 --- a/systemd/cloud-init-local.service.tmpl +++ b/systemd/cloud-init-local.service.tmpl @@ -1,23 +1,25 @@ ## template:jinja [Unit] Description=Initial cloud-init job (pre-networking) -{% if variant in ["ubuntu", "unknown", "debian", "rhel" ] %} +{% if variant in ["ubuntu", "unknown", "debian", "rhel", "ol" ] %} DefaultDependencies=no {% endif %} Wants=network-pre.target +{% if variant not in ["ol"] %} After=hv_kvp_daemon.service +{% endif %} After=systemd-remount-fs.service -{% if variant == "rhel" %} +{% if variant in ["rhel", "ol"] %} Requires=dbus.socket After=dbus.socket {% endif %} Before=NetworkManager.service -{% if variant == "rhel" %} +{% if variant in ["rhel", "ol"] %} Before=network.service {% endif %} Before=network-pre.target Before=shutdown.target -{% if variant == "rhel" %} +{% if variant in ["rhel", "ol"] %} Before=firewalld.target Conflicts=shutdown.target {% endif %} @@ -26,8 +28,10 @@ Before=sysinit.target Conflicts=shutdown.target {% endif %} RequiresMountsFor=/var/lib/cloud +{% if variant in ["rhel", "ol"] %} ConditionPathExists=!/etc/cloud/cloud-init.disabled ConditionKernelCommandLine=!cloud-init=disabled +{% endif %} ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled [Service] diff --git a/systemd/cloud-init.service.tmpl b/systemd/cloud-init.service.tmpl index 90d45f2..2e1ce48 100644 --- a/systemd/cloud-init.service.tmpl +++ b/systemd/cloud-init.service.tmpl @@ -1,7 +1,7 @@ ## template:jinja [Unit] Description=Initial cloud-init job (metadata service crawler) -{% if variant not in ["photon", "rhel"] %} +{% if variant not in ["photon", "rhel", "ol"] %} DefaultDependencies=no {% endif %} Wants=cloud-init-local.service @@ -10,13 +10,15 @@ Wants=sshd-keygen@ecdsa.service Wants=sshd-keygen@ed25519.service Wants=sshd.service After=cloud-init-local.service +{% if variant not in ["ol"] %} After=systemd-networkd-wait-online.service +{% endif %} {% if variant in ["ubuntu", "unknown", "debian"] %} After=networking.service {% endif %} {% if variant in ["almalinux", "centos", "cloudlinux", "eurolinux", "fedora", "miraclelinux", "openeuler", "OpenCloudOS", "openmandriva", "rhel", "rocky", - "suse", "TencentOS", "virtuozzo"] %} + "suse", "TencentOS", "virtuozzo", "ol"] %} After=network.service After=NetworkManager.service @@ -42,8 +44,10 @@ Conflicts=shutdown.target Before=shutdown.target Conflicts=shutdown.target {% endif %} +{% if variant in ["rhel", "ol"] %} ConditionPathExists=!/etc/cloud/cloud-init.disabled ConditionKernelCommandLine=!cloud-init=disabled +{% endif %} ConditionEnvironment=!KERNEL_CMDLINE=cloud-init=disabled [Service] diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 519ef63..323e7f6 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -1311,6 +1311,7 @@ class TestGetVariant: ({"system": "linux", "dist": ("sles",)}, "suse"), ({"system": "linux", "dist": ("sle_hpc",)}, "suse"), ({"system": "linux", "dist": ("my_distro",)}, "linux"), + ({"system": "linux", "dist": ("ol",)}, "ol"), ({"system": "Windows", "dist": ("dontcare",)}, "windows"), ({"system": "Darwin", "dist": ("dontcare",)}, "darwin"), ({"system": "Freebsd", "dist": ("dontcare",)}, "freebsd"), -- 2.31.1