The 'tripleoclient.export.export_stack' contains a race condition

Bug #1940685 reported by Jiri Podivin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tripleo
Fix Released
Medium
Jiri Podivin

Bug Description

Description
===========

The 'export_stack' function contains a race condition.
With the correct operation of the function depending on particular order of the 'tripleoclient.constants.EXPORT_DATA' dictionary item and presence of the the required json files.

If the requested file isn't found, and the loop has underwent one successful iteration immediately prior, the 'export_data' variable will be filled with the values obtained at during the previous successful iteration.

If the requested file isn't successfully found and decoded, the error, or warning, is still logged, but the execution continues with the following statements. [0]

As the 'export_data' still contains value obtained in previous iteration, the condition[1] will be cleared and the 'param' key in the 'data' dictionary will be filled with the value contained within the 'export_data' variable.

Source
------
    for export_key, export_param in constants.EXPORT_DATA.items():
        param = export_param["parameter"]
        if "file" in export_param:
            # get file data
            file = os.path.join(config_download_dir,
                                stack,
                                export_param["file"])
            if not os.path.exists(file):
    [0]-------> LOG.warning('File %s was not found during export' %
                            file)
            with open(file, 'r') as ff:
                try:
                    export_data = json.load(ff)
                except (TypeError, json.JSONDecodeError) as e:
                    LOG.error(
                        _('Could not read file %s') % file)
                    LOG.error(e)

        else:
            # get stack data
            export_data = oooutils.get_stack_output_item(
                            heat_stack, export_key)

        if export_data: <---------------------------------------[1]
            # When we export information from a cell controller stack
            # we don't want to filter.
            if "filter" in export_param and should_filter:
                for filter_key in export_param["filter"]:
                    if filter_key in export_data:
                        element = {filter_key: export_data[filter_key]}
                        data.setdefault(param, {}).update(element)
            else:
                data[param] = export_data

        else:
            raise Exception(
                "No data returned to export %s from." % param)

https://opendev.org/openstack/python-tripleoclient/src/branch/master/tripleoclient/export.py#L78-L115

Jiri Podivin (jpodivin)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-tripleoclient (master)
Changed in tripleo:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-tripleoclient (master)

Reviewed: https://review.opendev.org/c/openstack/python-tripleoclient/+/805409
Committed: https://opendev.org/openstack/python-tripleoclient/commit/fdd988948879ec20ac3b4c06a3097e52d94b795b
Submitter: "Zuul (22348)"
Branch: master

commit fdd988948879ec20ac3b4c06a3097e52d94b795b
Author: Jiri Podivin <email address hidden>
Date: Fri Aug 20 16:55:48 2021 +0200

    Eliminating a race condition in the export_stack function

    The correct export of the stack parameters no longer depends
    on order of the tripleclient.constants.EXPORT_DATA,
    as the lack of expected json file with parameters to export
    raises exception, rather than filling the requested key with
    data obtained in the previous iteration.

    The I/O logic was moved to the tripleoclient.utils to keep
    things more consistent.

    No longer necessary json import was removed.

    Tests were adjusted to mock more selectively.

    Closes-Bug: #1940685

    Signed-off-by: Jiri Podivin <email address hidden>
    Change-Id: Ia7fb232261eb00c53d4e9bb352e572568704000f

Changed in tripleo:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-tripleoclient (stable/wallaby)

Fix proposed to branch: stable/wallaby
Review: https://review.opendev.org/c/openstack/python-tripleoclient/+/807845

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-tripleoclient (stable/wallaby)

Reviewed: https://review.opendev.org/c/openstack/python-tripleoclient/+/807845
Committed: https://opendev.org/openstack/python-tripleoclient/commit/ef151db52ec1d7957be7850bb1bb7634c45a1bb4
Submitter: "Zuul (22348)"
Branch: stable/wallaby

commit ef151db52ec1d7957be7850bb1bb7634c45a1bb4
Author: Jiri Podivin <email address hidden>
Date: Fri Aug 20 16:55:48 2021 +0200

    Eliminating a race condition in the export_stack function

    The correct export of the stack parameters no longer depends
    on order of the tripleclient.constants.EXPORT_DATA,
    as the lack of expected json file with parameters to export
    raises exception, rather than filling the requested key with
    data obtained in the previous iteration.

    The I/O logic was moved to the tripleoclient.utils to keep
    things more consistent.

    No longer necessary json import was removed.

    Tests were adjusted to mock more selectively.

    Closes-Bug: #1940685

    Signed-off-by: Jiri Podivin <email address hidden>
    Change-Id: Ia7fb232261eb00c53d4e9bb352e572568704000f
    (cherry picked from commit fdd988948879ec20ac3b4c06a3097e52d94b795b)

tags: added: in-stable-wallaby
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-tripleoclient 17.1.0

This issue was fixed in the openstack/python-tripleoclient 17.1.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-tripleoclient 16.5.0

This issue was fixed in the openstack/python-tripleoclient 16.5.0 release.

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.