ansible-collections / community.yang

Ansible Community Collection to support Yang in network devices.
GNU General Public License v3.0
10 stars 14 forks source link

adding the continue_on_failure attribute #47

Closed dt-arrcus closed 4 years ago

dt-arrcus commented 4 years ago
SUMMARY

Adding the ability for the fetch action to continue even if a model is not fetched. There a couple of cases in ArcOS where this is helpful.

1) There are a few yang models in ArcOS that have the word 'import' in a leaf description. This causes this module to try to import this module, which doesn't exist e.g. in the tail-f-common.yang model there is this text:


1723        The argument to 'tailf:unique-selector' is an XPath descendant
1724        location path (matches the rule 'descendant-schema-nodeid' in
1725        RFC 6020).  The first node in the path MUST be a list node, and
1726        it MUST be defined in the same module as the
1727        tailf:unique-selector.  For example, the following is illegal:
1728
1729          module y {
1730            ...
1731            import x {
1732              prefix x;
1733            }
1734            tailf:unique-selector '/x:server' { // illegal
1735              ...
1736            }
1737          }

this causes this collection to try to fetch model x

The other use case is sometimes ArcOS will list a model in the get-schema RPC call but the full model might not exist on a specific version or a specific HW model Therefore if the all keyword is used in this collection and a model doesn't not exist on the device this task will fail.

ISSUE TYPE

Feature Pull Request

COMPONENT NAME

community.yang.fetch

ADDITIONAL INFORMATION

Here is an example run with the tasks failing:

  1 ---
  2 - hosts: all
  3   gather_facts: false
  4   connection: ansible.netcommon.netconf
  5
  6   tasks:
  7    - name: Fetch given yang model and it’s dependent models from remote host
  8      community.yang.fetch:
  9        name: all
TASK [Fetch given yang model and it’s dependent models from remote host] *********************************************************************************************
task path: /Users/david/code/ansible_netconf/netconf_test.yml:7
Fetched 'INET-ADDRESS-MIB' yang model
Fetched 'ietf-yang-smiv2' yang model
Fetched 'IPV6-TC' yang model
Fetched 'ietf-inet-types' yang model
Fetched 'tailf-common' yang model
fatal: [10.27.103.37]: FAILED! => {
    "changed": false,
    "msg": "Fail to fetch 'x' yang model"
}

PLAY RECAP **********************************

With my change the following attribute is added: continue_on_failure


  1 ---
  2 - hosts: all
  3   gather_facts: false
  4   connection: ansible.netcommon.netconf
  5
  6   tasks:
  7    - name: Fetch given yang model and it’s dependent models from remote host
  8      community.yang.fetch:
  9        name: all
 10        continue_on_failure: true

With this being run we are able to continue past the failed models and return a list of failed models


TASK [Fetch given yang model and it’s dependent models from remote host] *********************************************************
task path: /Users/david/code/ansible_netconf/netconf_test.yml:7
Fetched 'INET-ADDRESS-MIB' yang model
Fetched 'ietf-yang-smiv2' yang model
Fetched 'IPV6-TC' yang model
Fetched 'ietf-inet-types' yang model
Fetched 'tailf-common' yang model
Fail to fetch 'x' yang model
Fetched 'SNMPv2-SMI' yang model
Fetched 'ietf-yang-types' yang model
Fetched 'SNMPv2-TC' yang model
Fetched 'TRANSPORT-ADDRESS-MIB' yang model
<snip>
changed: [10.27.103.37] => {
    "changed": true,
    "failed_yang_models": [
        "x",
        "openconfig-mpls",
        "openconfig-ospfv2",
        "openconfig-policy-forwarding",
        "openconfig-authentication-types",
<snip>

This attribute defaults to False so the current behavior is unchanged and the user must opt in to allow for the continuation to happen.

ganeshrn commented 4 years ago

Failing with lint issue https://dashboard.zuul.ansible.com/t/ansible/build/6d1e3519f91d4ba08cd59b8c01cc4546/console After fixing you run locally tox -e black and tox -e linters in the collection root directory to test it.