[stx-fault] [fm-doc] dynamically changing elements in dict while iterating this dict

Bug #1809064 reported by yong hu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Fix Released
Low
yong hu

Bug Description

in ~/stx-fault/fm-doc/fm_doc/check_missing_alarms.py, there is a for loop iterating the dict (events), however inside this for-loop, the elements in this dict are being popped out and as well, elements with new keys are being added dynamically.

     for alarm_id in events:
         if isinstance(alarm_id, float):
             formatted_alarm_id = "{:.3f}".format(alarm_id) # force 3 digits after the point, to include trailing zero's (ex.: 200.010)
            events[formatted_alarm_id] = events.pop(alarm_id)

Maybe this code is not broken with certain version of Python and related libraries ("Collections"), but the error would occur with another version.

In principle this operation is not safe and could bring potential issues.

BTW: this script is triggered to run when StarlingX build system is making fm-doc-tis.rpm, rather than running on deployed StarlingX system.

yong hu (yhu6)
Changed in starlingx:
assignee: nobody → yong hu (yhu6)
summary: - [fm-doc] change element in dict while iterating this dict
+ [stx-fault] [fm-doc] dynamically changing elements in dict while
+ iterating this dict
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to stx-fault (master)

Fix proposed to branch: master
Review: https://review.openstack.org/626072

Changed in starlingx:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to stx-fault (master)

Reviewed: https://review.openstack.org/626072
Committed: https://git.openstack.org/cgit/openstack/stx-fault/commit/?id=f9ae82009b09ca9955d7805773aadf9c8a6f96ff
Submitter: Zuul
Branch: master

commit f9ae82009b09ca9955d7805773aadf9c8a6f96ff
Author: yhu6 <email address hidden>
Date: Wed Dec 19 02:55:45 2018 +0000

    [fm-doc] bug-fix: change a "dictionary" while iterating it

    issue: in ~/fm-doc/fm_doc/check_missing_alarms.py, there is
    a for-loop iterating the dict "events", however inside this
    loop, some elements are being popped out, and elements with
    new keys are being added dynamically. This is not safe and
    would bring unpredictable behavior with different versions
    of Python and "Collections".

    check_missing_alarms.py is triggered to run at Build stage
    (defined in fm-doc.spec) when generating "fm-doc.*.tis.rpm".

    Test for fix:
    1. rebuild on "fm-doc.*.tis.rpm" by "# build-pkgs fm-doc"
    2. check the rpm build log and assure the code be executed
    correctly with expected check results.
    3. run this script with different Python versions on other
    Linux hosts and assure it works well.

    Closes-Bug: 1809064

    Change-Id: Ieb07ae944037c2eb33dda414e870702a9d248d83
    Signed-off-by: yhu6 <email address hidden>

Changed in starlingx:
status: In Progress → Fix Released
Revision history for this message
Ghada Khalil (gkhalil) wrote :

Adding stx.2019.05 tag as this fix was merged for that release

tags: added: stx.2019.05 stx.fault
Changed in starlingx:
importance: Undecided → Low
Ken Young (kenyis)
tags: added: stx.2.0
removed: stx.2019.05
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.