Skip to content

Software Installation Error Handling #765

@Niklasr69

Description

@Niklasr69

Problem Description

The Juniper Ansible software module was incorrectly reporting successful installations even when the installation actually failed. This occurred due to flawed exception handling logic in the software installation process.

Root Cause Analysis

From the logs:

Ansible Log (Incorrect Success Report):

"msg": "Package successfully installed."

NETCONF Log (Actual Failure):

<nc:error-message>
File does not exist: /.mount/oam/junos-arm-32-23.4R2-S5.8.tgz
</nc:error-message>
<nc:error-message>
Couldn't retrieve package /.mount/oam/junos-arm-32-23.4R2-S5.8.tgz
</nc:error-message>

Problem

In the original code (lines ~741-755 in software.py):

        if junos_module.conn_type != "local":
            try:
                results["msg"] = junos_module._pyez_conn.software_api(install_params)
            except Exception as err:  # pylint: disable=broad-except
                if "ConnectionError" in str(type(err)):
                    # If Exception is ConnectionError, it is excpected
                    # Device installation inititated succesfully
                    junos_module.logger.debug("Package successfully installed.")
                    results["msg"] += "Package successfully installed."
                else:
                    # If exception is not ConnectionError
                    # we will raise the exception
                    raise
            junos_module.logger.debug("Package successfully installed")
        else:

No exception handling for : "file does not exist", "couldn't retrieve", "no such file", "failed", "error"

ansible-galaxy [core 2.18.5]
python version = 3.11.9
junos-eznc 2.7.4  
juniper.device 1.0.8 

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions