1992bd
From 386f0a82bfdfd62e506bf4251c17263260d3250a Mon Sep 17 00:00:00 2001
18322d
From: Eduardo Otubo <otubo@redhat.com>
bb836b
Date: Fri, 7 May 2021 13:36:14 +0200
8a7340
Subject: Remove race condition between cloud-init and NetworkManager
18322d
18322d
Message-id: <20200302104635.11648-1-otubo@redhat.com>
18322d
Patchwork-id: 94098
18322d
O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCH] Remove race condition between cloud-init and NetworkManager
18322d
Bugzilla: 1807797
18322d
RH-Acked-by: Cathy Avery <cavery@redhat.com>
18322d
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
18322d
18322d
BZ: 1748015
18322d
BRANCH: rhel7/master-18.5
18322d
BREW: 26924611
18322d
18322d
BZ: 1807797
18322d
BRANCH: rhel820/master-18.5
18322d
BREW: 26924957
18322d
18322d
cloud-init service is set to start before NetworkManager service starts,
18322d
but this does not avoid a race condition between them. NetworkManager
18322d
starts before cloud-init can write `dns=none' to the file:
18322d
/etc/NetworkManager/conf.d/99-cloud-init.conf. This way NetworkManager
18322d
doesn't read the configuration and erases all resolv.conf values upon
18322d
shutdown. On the next reboot neither cloud-init or NetworkManager will
18322d
write anything to resolv.conf, leaving it blank.
18322d
18322d
This patch introduces a NM reload (try-restart) at the end of cloud-init
18322d
start up so it won't erase resolv.conf upon first shutdown.
18322d
18322d
x-downstream-only: yes
18322d
resolves: rhbz#1748015, rhbz#1807797 and rhbz#1804780
18322d
2b0ae0
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
18322d
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
2b0ae0
2b0ae0
This commit is a squash and also includes the folloowing commits:
2b0ae0
2b0ae0
commit 316a17b7c02a87fa9b2981535be0b20d165adc46
2b0ae0
Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
Date:   Mon Jun 1 11:58:06 2020 +0200
2b0ae0
2b0ae0
    Make cloud-init.service execute after network is up
2b0ae0
2b0ae0
    RH-Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
    Message-id: <20200526090804.2047-1-otubo@redhat.com>
2b0ae0
    Patchwork-id: 96809
2b0ae0
    O-Subject: [RHEL-8.2.1 cloud-init PATCH] Make cloud-init.service execute after network is up
2b0ae0
    Bugzilla: 1803928
2b0ae0
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2b0ae0
    RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
2b0ae0
2b0ae0
    cloud-init.service needs to wait until network is fully up before
2b0ae0
    continuing executing and configuring its service.
2b0ae0
2b0ae0
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
2b0ae0
2b0ae0
    x-downstream-only: yes
2b0ae0
    Resolves: rhbz#1831646
2b0ae0
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
2b0ae0
2b0ae0
commit 0422ba0e773d1a8257a3f2bf3db05f3bc7917eb7
2b0ae0
Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
Date:   Thu May 28 08:44:08 2020 +0200
2b0ae0
2b0ae0
    Remove race condition between cloud-init and NetworkManager
2b0ae0
2b0ae0
    RH-Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
    Message-id: <20200327121911.17699-1-otubo@redhat.com>
2b0ae0
    Patchwork-id: 94453
2b0ae0
    O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCHv2] Remove race condition between cloud-init and NetworkManager
2b0ae0
    Bugzilla: 1840648
2b0ae0
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2b0ae0
    RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
2b0ae0
    RH-Acked-by: Cathy Avery <cavery@redhat.com>
2b0ae0
2b0ae0
    cloud-init service is set to start before NetworkManager service starts,
2b0ae0
    but this does not avoid a race condition between them. NetworkManager
2b0ae0
    starts before cloud-init can write `dns=none' to the file:
2b0ae0
    /etc/NetworkManager/conf.d/99-cloud-init.conf. This way NetworkManager
2b0ae0
    doesn't read the configuration and erases all resolv.conf values upon
2b0ae0
    shutdown. On the next reboot neither cloud-init or NetworkManager will
2b0ae0
    write anything to resolv.conf, leaving it blank.
2b0ae0
2b0ae0
    This patch introduces a NM reload (try-reload-or-restart) at the end of cloud-init
2b0ae0
    start up so it won't erase resolv.conf upon first shutdown.
2b0ae0
2b0ae0
    x-downstream-only: yes
2b0ae0
2b0ae0
    Signed-off-by: Eduardo Otubo otubo@redhat.com
2b0ae0
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
2b0ae0
2b0ae0
commit e0b48a936433faea7f56dbc29dda35acf7d375f7
2b0ae0
Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
Date:   Thu May 28 08:44:06 2020 +0200
2b0ae0
2b0ae0
    Enable ssh_deletekeys by default
2b0ae0
2b0ae0
    RH-Author: Eduardo Otubo <otubo@redhat.com>
2b0ae0
    Message-id: <20200317091705.15715-1-otubo@redhat.com>
2b0ae0
    Patchwork-id: 94365
2b0ae0
    O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCH] Enable ssh_deletekeys by default
2b0ae0
    Bugzilla: 1814152
2b0ae0
    RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
2b0ae0
    RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2b0ae0
2b0ae0
    The configuration option ssh_deletekeys will trigger the generation
2b0ae0
    of new ssh keys for every new instance deployed.
2b0ae0
2b0ae0
    x-downstream-only: yes
2b0ae0
    resolves: rhbz#1814152
2b0ae0
2b0ae0
    Signed-off-by: Eduardo Otubo <otubo@redhat.com>
2b0ae0
    Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
18322d
---
bb836b
 rhel/cloud.cfg                  | 2 +-
bb836b
 rhel/systemd/cloud-init.service | 1 +
bb836b
 2 files changed, 2 insertions(+), 1 deletion(-)
18322d
2b0ae0
diff --git a/rhel/cloud.cfg b/rhel/cloud.cfg
bb836b
index 82e8bf62..9ecba215 100644
2b0ae0
--- a/rhel/cloud.cfg
2b0ae0
+++ b/rhel/cloud.cfg
2b0ae0
@@ -6,7 +6,7 @@ ssh_pwauth:   0
2b0ae0
 
2b0ae0
 mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
2b0ae0
 resize_rootfs_tmp: /dev
2b0ae0
-ssh_deletekeys:   0
2b0ae0
+ssh_deletekeys:   1
2b0ae0
 ssh_genkeytypes:  ~
2b0ae0
 syslog_fix_perms: ~
2b0ae0
 disable_vmware_customization: false
2b0ae0
diff --git a/rhel/systemd/cloud-init.service b/rhel/systemd/cloud-init.service
bb836b
index d0023a05..0b3d796d 100644
2b0ae0
--- a/rhel/systemd/cloud-init.service
2b0ae0
+++ b/rhel/systemd/cloud-init.service
2b0ae0
@@ -5,6 +5,7 @@ Wants=sshd-keygen.service
2b0ae0
 Wants=sshd.service
2b0ae0
 After=cloud-init-local.service
2b0ae0
 After=NetworkManager.service network.service
2b0ae0
+After=NetworkManager-wait-online.service
2b0ae0
 Before=network-online.target
2b0ae0
 Before=sshd-keygen.service
2b0ae0
 Before=sshd.service
18322d
-- 
1992bd
2.31.1
18322d