sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
Blob Blame History Raw
From a3b9673481bbe2fa35986aa757fd5321c3a7a371 Mon Sep 17 00:00:00 2001
From: Eduardo Otubo <otubo@redhat.com>
Date: Wed, 12 Feb 2020 13:08:38 +0100
Subject: [PATCH] cmd:main.py: Fix missing 'modules-init' key in modes dict

RH-Author: Eduardo Otubo <otubo@redhat.com>
Message-id: <20200212130838.24592-1-otubo@redhat.com>
Patchwork-id: 93781
O-Subject: [RHEL-7.9/RHEL-8.2.0 cloud-init PATCH] cmd:main.py: Fix missing 'modules-init' key in modes dict
Bugzilla: 1802140
RH-Acked-by: Cathy Avery <cavery@redhat.com>
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>

BZ: 1673170
BRANCH: rhel7/master-18.5
UPSTREAM: bdd9c0ac
BREW: 26372362

BZ: 1802140
BRANCH: rhel820/master-18.5
UPSTREAM: bdd9c0ac
BREW: 26372415

commit 96557ca26a73c490aee74a811c3a44ef1ac11d84
Author: Antonio Romito <antonio.romito@manicom.io>
Date:   Tue Apr 9 14:54:23 2019 +0000

    cmd:main.py: Fix missing 'modules-init' key in modes dict

    Cloud-init's main.py will fail when presented with a new
    stage name 'modules-init' if upgrading an older cloud-init.
    Fix this by initializing unknown stage names before accessing.

    LP: #1815109

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 cloudinit/cmd/main.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
index 933c019..a5446da 100644
--- a/cloudinit/cmd/main.py
+++ b/cloudinit/cmd/main.py
@@ -632,13 +632,14 @@ def status_wrapper(name, args, data_d=None, link_d=None):
         'start': None,
         'finished': None,
     }
+
     if status is None:
         status = {'v1': {}}
-        for m in modes:
-            status['v1'][m] = nullstatus.copy()
         status['v1']['datasource'] = None
-    elif mode not in status['v1']:
-        status['v1'][mode] = nullstatus.copy()
+
+    for m in modes:
+        if m not in status['v1']:
+            status['v1'][m] = nullstatus.copy()
 
     v1 = status['v1']
     v1['stage'] = mode
-- 
1.8.3.1