RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1673170 - [cloud-init][RHEL7.9]cloud-init cloud-final.service fail with KeyError: 'modules-init' after upgrade to version 18.2-1.el7_6.1 in RHV
Summary: [cloud-init][RHEL7.9]cloud-init cloud-final.service fail with KeyError: 'modu...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: cloud-init
Version: 7.6
Hardware: All
OS: Linux
high
medium
Target Milestone: rc
: ---
Assignee: Eduardo Otubo
QA Contact: Huijuan Zhao
URL:
Whiteboard:
Depends On:
Blocks: 1782469 1802140 1802173
TreeView+ depends on / blocked
 
Reported: 2019-02-06 20:08 UTC by Antonio Romito
Modified: 2021-05-08 08:32 UTC (History)
13 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1802140 1802173 (view as bug list)
Environment:
Last Closed: 2020-04-14 09:51:09 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1815109 0 None None None 2019-02-07 19:44:21 UTC
Red Hat Knowledge Base (Solution) 3896071 0 Upgrade None After upgrading cloud-init, service cloud-final exits with status failed 2019-06-24 18:59:35 UTC

Description Antonio Romito 2019-02-06 20:08:03 UTC
Description of problem:

After the upgrade of cloud-init to version 18.2 cloud-final.service do not start due to the following error and the service remains in not running state

-----
# service cloud-final status
Redirecting to /bin/systemctl status cloud-final.service
● cloud-final.service - Execute cloud user/final scripts
   Loaded: loaded (/usr/lib/systemd/system/cloud-final.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2019-02-01 13:14:31 CET; 28min ago
  Process: 21927 ExecStart=/usr/bin/cloud-init modules --mode=final (code=exited, status=1/FAILURE)
 Main PID: 21927 (code=exited, status=1/FAILURE)
-----

Version-Release number of selected component (if applicable):

Red Hat Enterprise Linux Server release 7.6 (Maipo)
cloud-init-18.2-1.el7_6.1.x86_64

How reproducible:

Steps to Reproduce:
1. [root@rhvm ~]# cloud-init modules --mode=final

Actual results:

[root@rhvm ~]# cloud-init modules --mode final
Cloud-init v. 18.2 running 'modules:final' at Wed, 06 Feb 2019 20:00:14 +0000. Up 10634.29 seconds.
Cloud-init v. 18.2 finished at Wed, 06 Feb 2019 20:00:15 +0000. Datasource DataSourceNoCloud [seed=/dev/sr0][dsmode=net].  Up 10634.40 seconds
Traceback (most recent call last):
  File "/usr/bin/cloud-init", line 9, in <module>
    load_entry_point('cloud-init==18.2', 'console_scripts', 'cloud-init')()
  File "/usr/lib/python2.7/site-packages/cloudinit/cmd/main.py", line 882, in main
    get_uptime=True, func=functor, args=(name, args))
  File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 2388, in log_time
    ret = func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/cloudinit/cmd/main.py", line 679, in status_wrapper
    if v1[m]['errors']:
KeyError: 'modules-init'


Expected results:

[root@rhvm ~]# cloud-init modules --mode final
Cloud-init v. 18.2 running 'modules:final' at Wed, 06 Feb 2019 19:41:50 +0000. Up 9530.23 seconds.
Cloud-init v. 18.2 finished at Wed, 06 Feb 2019 19:41:50 +0000. Datasource DataSourceNoCloud [seed=/dev/sr0][dsmode=net].  Up 9530.34 seconds


Additional info:

This problem do not happens with previous cloud-init version:

cloud-init.x86_64 0:0.7.9-24.el7_5.1 will be updated

Comment 2 Antonio Romito 2019-02-06 20:19:09 UTC
I had a look to the /usr/lib/python2.7/site-packages/cloudinit/cmd/main.py script and I found that it fail in the following part of code:

~~~
...
    if mode == "modules-final":
        # write the 'finished' file
        errors = []
        for m in modes:
            if v1[m]['errors']:                                          <<<--- Unhandled exception exception
                errors.extend(v1[m].get('errors', []))
...
~~~

The for cycle loop into modes list that contains ('init', 'init-local', 'modules-init', 'modules-config', 'modules-final'):

The v1 array do not contains "modules-init" key and for this reason if generate an exception.

Applying the following patch the script make a double check on the keys present into the array before the if statement.

[root@rhvm ~]# diff -u /usr/lib/python2.7/site-packages/cloudinit/cmd/main.py /usr/lib/python2.7/site-packages/cloudinit/cmd/main.py.fixed 
--- /usr/lib/python2.7/site-packages/cloudinit/cmd/main.py	2018-03-27 14:49:38.000000000 -0400
+++ /usr/lib/python2.7/site-packages/cloudinit/cmd/main.py.fixed	2019-02-06 15:17:45.128944937 -0500
@@ -676,8 +676,9 @@
         # write the 'finished' file
         errors = []
         for m in modes:
-            if v1[m]['errors']:
-                errors.extend(v1[m].get('errors', []))
+            if m in v1:
+                if v1[m]['errors']:
+                    errors.extend(v1[m].get('errors', []))
 
         atomic_helper.write_json(
             result_path, {'v1': {'datasource': v1['datasource'],

Comment 3 Antonio Romito 2019-02-06 20:34:45 UTC
As temporary workaround is it possible to edit the following file:

/run/cloud-init/status.json

Adding a fake json entry related to the "modules-init" part:

  "modules-init": {
   "errors": [], 
   "finished": 1, 
   "start": 0
  },

Comment 6 Antonio Romito 2019-04-09 19:55:10 UTC
Proposed fix has been merged on the upstream project -->> https://git.launchpad.net/cloud-init/commit/?id=bdd9c0ac9bcd68ec1ac3b2038dad0ba3dbd83341

Comment 30 Antonio Romito 2020-04-20 13:14:00 UTC
Hi Xiaoyi,
 to reproduce this bug, you would need to:

1. Install a RHV-H (Red Hat Virtualization Hypervisor)
2. Install a RHV-M (Red Hat Virtualization Manager) in Self-Hosted Engine configuration
3. As soon as the RHV-M VM starts you'll be able to verify that cloud-init service start failed at boot.

Please ping me if you need more details.

Thanks,
A.


Note You need to log in before you can comment on or make changes to this bug.