sonic-net / sonic-mgmt

Configuration management examples for SONiC
Other
194 stars 712 forks source link

Add dhcp-relay structured events tests #13504

Closed zbud-msft closed 1 month ago

zbud-msft commented 3 months ago

Description of PR

Summary: Fixes # (issue) 26636373

Type of change

Back port request

Approach

What is the motivation for this PR?

Add support for dhcp-relay-discard event, which we use ptfadapter to and ptf.testutils to send a dhcp discover packet to a port that has no ipv4 address assigned.

Add support for dhcp-relay-disparity event which uses same repro for dhcp-relay-disparity but at greater intervals and packets sent due to dhcpmon configuration

How did you do it?

Added new testcase that triggered sending dhcp discover packet which will trigger event.

How did you verify/test it?

Pipeline/Manual test

run_events_test.run_test L0027 INFO | events received:

    {
        "sonic-events-dhcp-relay:dhcp-relay-discard": {
            "ifname": "Vlan1000",
            "timestamp": "2024-07-09T01:27:30.395216Z"
        }
    }

run_events_test.run_test L0027 INFO | events received:

    {
        "sonic-events-dhcp-relay:dhcp-relay-disparity": {
            "duration": "198",
            "timestamp": "2024-07-09T01:30:43.711312Z",
            "vlan": "Agg-Vlan1000"
        }
    }

run_events_test.run_test L0027 INFO | events received:

    {
        "sonic-events-dhcp-relay:dhcp-relay-bind-failure": {
            "timestamp": "2024-07-09T01:32:27.667714Z",
            "type": "local",
            "vlan": "Vlan1000"
        }
    }

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

mssonicbld commented 3 months ago

The pre-commit check detected issues in the files touched by this pull request. The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/telemetry/conftest.py:167:121: E501 line too long (127 > 120 characters)
tests/telemetry/events/dhcp-relay_events.py:13:1: E302 expected 2 blank lines, found 1

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt docker container.
  2. Ensure that the pre-commit package is installed:
    sudo pip install pre-commit
  3. Go to repository root folder
  4. Install the pre-commit hooks:
    pre-commit install
  5. Use pre-commit to check staged file:
    pre-commit
  6. Alternatively, you can check committed files using:
    pre-commit run --from-ref <commit_id> --to-ref <commit_id>
zbud-msft commented 3 months ago

Relies on https://github.com/sonic-net/sonic-buildimage/pull/19430

mssonicbld commented 2 months ago

The pre-commit check detected issues in the files touched by this pull request. The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/telemetry/events/dhcp-relay_events.py:35:41: F821 undefined name 'ptfadataper'

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt docker container.
  2. Ensure that the pre-commit package is installed:
    sudo pip install pre-commit
  3. Go to repository root folder
  4. Install the pre-commit hooks:
    pre-commit install
  5. Use pre-commit to check staged file:
    pre-commit
  6. Alternatively, you can check committed files using:
    pre-commit run --from-ref <commit_id> --to-ref <commit_id>
mssonicbld commented 2 months ago

The pre-commit check detected issues in the files touched by this pull request. The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/telemetry/events/event_utils.py:122:121: E501 line too long (138 > 120 characters)
tests/telemetry/events/event_utils.py:127:121: E501 line too long (150 > 120 characters)
tests/telemetry/events/event_utils.py:128:121: E501 line too long (136 > 120 characters)

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt docker container.
  2. Ensure that the pre-commit package is installed:
    sudo pip install pre-commit
  3. Go to repository root folder
  4. Install the pre-commit hooks:
    pre-commit install
  5. Use pre-commit to check staged file:
    pre-commit
  6. Alternatively, you can check committed files using:
    pre-commit run --from-ref <commit_id> --to-ref <commit_id>
mssonicbld commented 2 months ago

The pre-commit check detected issues in the files touched by this pull request. The pre-commit check is a mandatory check, please fix detected issues.

Detailed pre-commit check results:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check python ast.........................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/telemetry/events/event_utils.py:128:89: E502 the backslash is redundant between brackets
tests/telemetry/events/event_utils.py:130:91: E502 the backslash is redundant between brackets

flake8...............................................(no files to check)Skipped
check conditional mark sort..........................(no files to check)Skipped

To run the pre-commit checks locally, you can follow below steps:

  1. Ensure that default python is python3. In sonic-mgmt docker container, default python is python2. You can run the check by activating the python3 virtual environment in sonic-mgmt docker container or outside of sonic-mgmt docker container.
  2. Ensure that the pre-commit package is installed:
    sudo pip install pre-commit
  3. Go to repository root folder
  4. Install the pre-commit hooks:
    pre-commit install
  5. Use pre-commit to check staged file:
    pre-commit
  6. Alternatively, you can check committed files using:
    pre-commit run --from-ref <commit_id> --to-ref <commit_id>
zbud-msft commented 1 month ago

Hi @StormLiangMS, can we have this in 202311?

mssonicbld commented 5 days ago

@zbud-msft PR conflicts with 202405 branch