Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junos fix next-hop self in get_bgp_config() #620

Merged
merged 11 commits into from
Jan 23, 2018

Conversation

ckishimo
Copy link
Contributor

In Junos the nhs key is never updated when using get_bgp_config(). This PR is checking for all export policies applied at the neighbor level if there is a next-hop self action.

The next-hop self action can be applied using a term or without. Both cases are taken into account.

A test case was added. Note that I had to provide mocked data for the policies configured in the existing test case, which I added with a simple action of accept, hope that is ok! Thanks

Example:

carles@vmx# show policy-options policy-statement nhs 
term 1 {
    then {
        next-hop self;
    }
}
term 0 {
    then accept;
}
{
    "internal": {
        "apply_groups": [], 
        "description": "", 
        "export_policy": "", 
        "import_policy": "", 
        "local_address": "", 
        "local_as": 0, 
        "multihop_ttl": 0, 
        "multipath": false, 
        "neighbors": {
            "10.10.10.1": {
                "authentication_key": "", 
                "description": "", 
                "export_policy": "nhs static", 
                "import_policy": "", 
                "local_address": "", 
                "local_as": 0, 
                "nhs": true, 
                "prefix_limit": {}, 
                "remote_as": 0, 
                "route_reflector_client": false
            }
        }, 
        "prefix_limit": {}, 
        "remote_as": 0, 
        "remove_private_as": false, 
        "type": "internal"
    }
}

@coveralls
Copy link

coveralls commented Jan 11, 2018

Coverage Status

Coverage increased (+0.06%) to 78.74% when pulling cbe6d47 on ckishimo:nhs into 0a2a542 on napalm-automation:develop.

# Make it a list if it is a single policy
policies = [policies]
for p in policies:
policy = junos_views.junos_policy_config_table(self.device)
Copy link
Member

@mirceaulinic mirceaulinic Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is going to be a massive performance issue: you are executing a request for each policy. I suggest doing the request (retrieving the entire config for the policies) at the beginning of the method, and just use the result here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mirceaulinic not sure I understand... I'm executing a request for each policy applied on export on each neighbor (not all policies!), so we know for each neighbor whether there is a policy with an action next-hop self applied.

If I take the entire config for the policies (ie: show policy-options) I will check each and every single policy, which will be even worst, non ? thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can retrieve all the policies and then do the same iteration but getting the policy from the object to retrieved before instead of having to do a request per policy.

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great catch, but please rework the implementation.

@mirceaulinic mirceaulinic added this to the 2.3.1 milestone Jan 12, 2018
@coveralls
Copy link

coveralls commented Jan 19, 2018

Coverage Status

Coverage increased (+0.07%) to 78.927% when pulling 51aaebe on ckishimo:nhs into a5255d0 on napalm-automation:develop.

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better @ckishimo. There are some small changes to make the code easier to understand, and also please add some comments in the code to explain the fact that the table simply provides two fields with booleans.

@@ -251,7 +251,16 @@ junos_lldp_neighbors_detail_view:
###
### BGP config
###
junos_policy_config_table:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code you added in the class I found it very confusing:

for result, value in all_policies[p]:
    if value is True:

But it makes sense looking at this table. I suggest making the name more obvious, something like junos_policy_nhs_config_table and, similarly, the fields something better than result1 and result2 which don't make much sense.

@ckishimo
Copy link
Contributor Author

@dbarrosop thanks for the clarification

@mirceaulinic thanks for the review. I managed to get rid of one of the booleans, simplifying the code. Please let me know if there is any other change needed

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great @ckishimo, and nicely implemented. Thank you!

@mirceaulinic mirceaulinic merged commit 7ad5e6a into napalm-automation:develop Jan 23, 2018
ktbyers added a commit that referenced this pull request Apr 12, 2018
* Remove multiple entries for netmiko (#617)

* Fixes NX-OS string change in show diff rollback-patch output (#619)

* Require to upgrade setuptools

* Modify NX-OS to properly save config to startup-config on commit_config (#624)

* Fixing NX-OS rollback issue (#626)

* Junos fix next-hop self in get_bgp_config() (#620)

* junos fix nhs in get_bgp_config()

* junos add test case for nhs in get_bgp_config()

* junos fix missing policy in existing test case for nhs

* junos fix E712 comparison

* fix typo

* junos remove nhs key in group level in get_bgp_config()

* junos rework nhs in get_bgp_config() by fetching all policies in one go

* junos fix test case for nhs get_bgp_config()

* junos clean code and add comments in nhs get_bgp_config()

* junos nhs remove inactive term in mocked data

* IOS-XR: return the is_alive flag for the SSH channel (#623)

* Fixes for CAM and ARP parsing issues in nxos_ssh.py (#634)

* Fixes #441, Fixes #633 show arp and mac address table processing.

* Minor improvement to get_arp processing on NXOS SSH (#639)

* Minor improvement to get_arp processing on NXOS SSH

* don't hide relevant import errors (#635)

* don't hide relevant import errors

* original name

* py2 compliance

* now back to py3 compatibility....

* Update index.rst (#650)

* improved exceptions - added new base exception (#649)

* improved exceptions - added new base exception

* fixed pep8 issue

* another pep8 issue fixed

* fixes #640 junos ConnectionException (#648)

* FIXES #653 additional error message on failed replace (#654)

* NX-OS ping implementation using more shared common code (#642)

* fix get_mac_table on IOS when there are routed ports

* [646] updating junos.py to support PTX platform (#665)

* Minor doc changes for NX-OS and IOS (#669)

* Unify netmiko argument processing across napalm drivers (#673)

* Start sharing common Netmiko code

* Adding unit tests for new netmiko argument parsing

* Adding NXOS to use netmiko argument processing

* IOS-XR and netmiko args processing

* Make nxos_facts behavior more consistent between NX-API and SSH (#674)

* fix issue #477: the output is now consistent between NXOS and NXOS_SSH driver

* #477 fix crash for some N9K 93180YC-EX, 93180LC-EX, etc

* Updates to NX-OS SSH get_facts

* Adding better test case for NX-API

* Update get_interfaces_ip to deal with unnumbered interfaces (#632)

* Update get_interfaces_ip to deal with unnumbered interfaces

* Extend tests for show_ip_interface

* Fix issue about N9K with vxlan (#676)

* Adding VXLAN support: EVPN and control plane flags on mac address + new interface name

* Fix #672: get_interfaces() crash with nve interfaces or no IP address

* fix missing mgmt0 interface in the get_fact on N9K device

* fix wrong description SVI on N9K device

* fix some pep error and an EOL issue for a test case

* Fix setup.py issue when using pip 10. (#692)

* Add virtualbox provider to the docs (#679)

* Apply correct format to code block

* Add virtualbox provider flag to vagrant

* Lldp neighbors detail bugfix (#675)

* Cosmetic cleanup in line with PEP8, whitespace and indentation fixes

* Address inconsistency in junos xml rpc calls for lldp interface information.

* Add two more cases where the RPC call for lldp neighbors interface detail is different to that documented

* Add StackStorm integrations to README (#683)

* Track BGP state to report is_up (#684)

* NAPALM release 2.3.1 (#696)

* Rolling version to 2.3.1

* Fixing linter issues introduced by new version of pylama
@ckishimo ckishimo deleted the nhs branch August 8, 2019 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants