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

Add verification IPv4 address on LLDP conf Jinja2 Template #5699

Merged
merged 9 commits into from
Nov 7, 2020

Conversation

bratashX
Copy link
Contributor

@bratashX bratashX commented Oct 22, 2020

Signed-off-by: Petro Bratash [email protected]

- Why I did it

LLDP conf Jinja2 Template does not verify IPv4 address and can use IPv6 version. This issue does not effect control LLDP daemon. Issue can be reproduced via test_snmp_lldp test. LLDP conf Jinja2 Template selects first item from the list of mgmt interfaces.

TESTBED_1 LLDP conf

# cat /etc/lldpd.conf 
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern FC00:3::32
configure system hostname dut-1

TESTBED_2 LLDP conf

# cat /etc/lldpd.conf
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.22.24.61
configure system hostname dut-2

TESTBED_1 MGMT_INTERFACE

$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|10.22.24.53/23
MGMT_INTERFACE|eth0|FC00:3::32/64

TESTBED_2 MGMT_INTERFACE

$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|FC00:3::32/64
MGMT_INTERFACE|eth0|10.22.24.61/23

- How I did it

Skip IP address if it includes ":" characters

- How to verify it

  1. Run:
    docker exec lldp cat /etc/lldpd.conf
  2. Check the type of IP-address

- Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@bratashX
Copy link
Contributor Author

@akokhan, please review

@liat-grozovik
Copy link
Collaborator

@shlomibitton can you please review as well?

akokhan
akokhan previously approved these changes Oct 22, 2020
Copy link
Contributor

@pavel-shirshov pavel-shirshov left a comment

Choose a reason for hiding this comment

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

Thank you for the contrinbution
Can you please

  1. Describe more what is the problem is? The way to reproduce the issue and so on. Currently it is not clear from the PR description
  2. Add tests for your change,

@akokhan
Copy link
Contributor

akokhan commented Oct 23, 2020

Thank you for the contrinbution
Can you please

  1. Describe more what is the problem is? The way to reproduce the issue and so on. Currently it is not clear from the PR description
  2. Add tests for your change,

#5603

@lguohan
Copy link
Collaborator

lguohan commented Oct 23, 2020

can you add test in sonic-cfggen to validate the template results.

@shlomibitton
Copy link
Contributor

LGTM

@bratashX
Copy link
Contributor Author

bratashX commented Oct 29, 2020

@lguohan @pavel-shirshov
Currently test for testing lldp.conf exists
https://github.com/Azure/sonic-buildimage/blob/ad2001f972e27034b876a79c6108f47420544bf5/src/sonic-config-engine/tests/test_j2files.py#L69
Test take last interface in ManagementIPInterfaces from t0-sample-graph.xml file.
Previously test passed because the last interface was IPv4 https://github.com/Azure/sonic-buildimage/blob/ad2001f972e27034b876a79c6108f47420544bf5/src/sonic-config-engine/tests/t0-sample-graph.xml#L202

I think this commit will fix the test(change the order of the interfaces): ad2001f

Could you say, how to run this tests?

@pavel-shirshov
Copy link
Contributor

Hi @bratashX

I'd suggest you revert the last commit. It breaks other tests. Usually we have ipv6 as second address on the interface in the minigraph.

How to run the tests:

  1. cd sonic-buildimage/src/sonic-config-engine
  2. pytest tests

{% if MGMT_INTERFACE %}
{% for interface in MGMT_INTERFACE.keys()|list %}
{% if interface[1]|ipv4 %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

ipv4 [](start = 19, length = 4)

Could you add a test case similar to https://github.com/Azure/sonic-buildimage/blob/781188f54941a2eb9e4a23a96f05986ec51ff106/src/sonic-config-engine/tests/test_j2files.py#L69? So it will capture regression like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was added, please review

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding test! I think another useful test case is 1 ipv4 + 1 ipv6 mgmt addresses, which are common to in normal use case.


In reply to: 515413789 [](ancestors = 515413789)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the test must verify 2 cases:

  • IPv4 mgmt interface exists
  • IPv4 mgmt interface doesn't exist

But now I add 3 cases, when:

  • IPv4 mgmt interface only exists
  • IPv6 mgmt interface only exists
  • IPv4 + IPv6 mgmt interface exists

Please review

Copy link
Collaborator

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comment

@bratashX
Copy link
Contributor Author

bratashX commented Nov 2, 2020

2. pytest tests

@pavel-shirshov Previously I have never been run SONiC test. Could you please say what environment needs use before test running? Maybe is some docker for testing or some README file?

@lguohan
Copy link
Collaborator

lguohan commented Nov 5, 2020

retest vsimage please

@daall daall linked an issue Nov 5, 2020 that may be closed by this pull request
Signed-off-by: Petro Bratash <[email protected]>
@bratashX
Copy link
Contributor Author

bratashX commented Nov 5, 2020

@lguohan Can I duplicate src/sonic-config-engine/tests/t0-sample-graph.xml with changes from these commit: ad2001f
(it fix test_lldp test and doesn't affect other tests)? Is it good solution?

@bratashX bratashX force-pushed the fix_lldp_jinja2_template branch from 052b382 to 0e81cc3 Compare November 5, 2020 19:35
@qiluo-msft qiluo-msft dismissed their stale review November 5, 2020 21:22

Unblock, the test could be further improved.

@pavel-shirshov
Copy link
Contributor

@bratashX
Currently I don't have such documentation.
What I did to run the tests: manually installed all dependency which is required by using pip.
I'd suggest start with

pip install pytest
pip install pytest-runner

Also you need to install sonic-py-common and swsssdk for that

git clone https://github.com/Azure/sonic-buildimage.git
cd sonic-buildimage/src/sonic-py-common
sudo python setup.py install
git clone https://github.com/Azure/sonic-py-swsssdk.git
sido python setup.py install

@lguohan
Copy link
Collaborator

lguohan commented Nov 6, 2020

@lguohan Can I duplicate src/sonic-config-engine/tests/t0-sample-graph.xml with changes from these commit: ad2001f
(it fix test_lldp test and doesn't affect other tests)? Is it good solution?

a good solution is to use test_ndppd_conf test as an example, you do not need to introduce a new minigraph.

@bratashX bratashX requested a review from lguohan November 6, 2020 14:12
@lguohan
Copy link
Collaborator

lguohan commented Nov 6, 2020

retest mellanox please

@pavel-shirshov
Copy link
Contributor

retest vsimage please

@lguohan lguohan merged commit 32a832a into sonic-net:master Nov 7, 2020
abdosi pushed a commit that referenced this pull request Feb 11, 2021
…5699)

Fix #5812

LLDP conf Jinja2 Template does not verify IPv4 address and can use IPv6 version. This issue does not effect control LLDP daemon. Issue can be reproduced via `test_snmp_lldp` test. LLDP conf Jinja2 Template selects first item from the list of mgmt interfaces.

TESTBED_1 LLDP conf

```
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern FC00:3::32
configure system hostname dut-1
```
TESTBED_2  LLDP conf

```
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.22.24.61
configure system hostname dut-2
```
TESTBED_1  MGMT_INTERFACE

```
$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|10.22.24.53/23
MGMT_INTERFACE|eth0|FC00:3::32/64
```
TESTBED_2  MGMT_INTERFACE

```
$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|FC00:3::32/64
MGMT_INTERFACE|eth0|10.22.24.61/23

```

Signed-off-by: Petro Bratash <[email protected]>
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
…onic-net#5699)

Fix sonic-net#5812

LLDP conf Jinja2 Template does not verify IPv4 address and can use IPv6 version. This issue does not effect control LLDP daemon. Issue can be reproduced via `test_snmp_lldp` test. LLDP conf Jinja2 Template selects first item from the list of mgmt interfaces.

TESTBED_1 LLDP conf

```
# cat /etc/lldpd.conf 
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern FC00:3::32
configure system hostname dut-1
```
TESTBED_2  LLDP conf

```
# cat /etc/lldpd.conf
configure ports eth0 lldp portidsubtype local eth0
configure system ip management pattern 10.22.24.61
configure system hostname dut-2
```
TESTBED_1  MGMT_INTERFACE

```
$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|10.22.24.53/23
MGMT_INTERFACE|eth0|FC00:3::32/64
```
TESTBED_2  MGMT_INTERFACE

```
$ redis-cli -n 4 keys "*" | grep MGMT_INTERFACE
MGMT_INTERFACE|eth0|FC00:3::32/64
MGMT_INTERFACE|eth0|10.22.24.61/23

```

Signed-off-by: Petro Bratash <[email protected]>
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.

SNMP missing expected LLDP data in master image
10 participants