UnboundLocalError: local variable 'logFile' referenced before assignment

Bug #1635770 reported by gs-opencos-zte
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Packstack
Fix Released
Medium
Javier Peña

Bug Description

code in run_setup.py:main() is:
def main():
    options = ""

    try:
        # Load Plugins
        loadPlugins()
        initPluginsConfig()

        optParser = initCmdLineParser()

        # Do the actual command line parsing
        # Try/Except are here to catch the silly sys.exit(0) when calling rhevm-setup --help
        (options, args) = optParser.parse_args()
        if options.options:
            printOptions()
            raise SystemExit

        # Initialize logging
        logFile = initLogging(options.debug) //logFile defined here is too late

        # Parse parameters
        runConfiguration = True
        confFile = None

        ....

    except FlagValidationError as ex:
        optParser.error(str(ex))
    except Exception as e:
        logging.error(traceback.format_exc())
        print("\n" + utils.color_text("ERROR : " + str(e), 'red'))
        print(output_messages.ERR_CHECK_LOG_FILE_FOR_MORE_INFO % (logFile))
        sys.exit(1)

    finally:
        remove_remote_var_dirs(options, controller.CONF, controller.MESSAGES)
        remove_temp_files()

when some exception raised at optParser.parse_args() or before, "UnboundLocalError: local variable 'logFile' referenced before assignment" will be found. i think it logFile should be defined before loadPlugins().

Changed in packstack:
assignee: nobody → gs-opencos-zte (gs-opencos-zte)
Javier Peña (jpena-c)
Changed in packstack:
importance: Undecided → Medium
status: New → In Progress
assignee: gs-opencos-zte (gs-opencos-zte) → Javier Peña (jpena-c)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to packstack (master)

Reviewed: https://review.openstack.org/394996
Committed: https://git.openstack.org/cgit/openstack/packstack/commit/?id=6f6b5aa90999db43c2b364ac20c456387ef44eea
Submitter: Jenkins
Branch: master

commit 6f6b5aa90999db43c2b364ac20c456387ef44eea
Author: Javier Pena <email address hidden>
Date: Tue Nov 8 15:42:20 2016 +0100

    Avoid error if logFile is not defined

    If there is an error initializing a plugin or checking the command-line
    arguments, we may use the logFile variable without having
    initialized it, which causes an exception.

    In those cases there will be no log file, so let's catch the
    exception and ignore it if it happens.

    Change-Id: Icaeb2ae780da9802591e9a063a71dd339b396b93
    Closes-Bug: #1635770

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

Fix proposed to branch: stable/newton
Review: https://review.openstack.org/401937

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to packstack (stable/newton)

Reviewed: https://review.openstack.org/401937
Committed: https://git.openstack.org/cgit/openstack/packstack/commit/?id=73c6449f6795f90a07dce3b7f572b410e2510757
Submitter: Jenkins
Branch: stable/newton

commit 73c6449f6795f90a07dce3b7f572b410e2510757
Author: Javier Pena <email address hidden>
Date: Tue Nov 8 15:42:20 2016 +0100

    Avoid error if logFile is not defined

    If there is an error initializing a plugin or checking the command-line
    arguments, we may use the logFile variable without having
    initialized it, which causes an exception.

    In those cases there will be no log file, so let's catch the
    exception and ignore it if it happens.

    Change-Id: Icaeb2ae780da9802591e9a063a71dd339b396b93
    Closes-Bug: #1635770
    (cherry picked from commit 6f6b5aa90999db43c2b364ac20c456387ef44eea)

tags: added: in-stable-newton
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.