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