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

Fix for passing snappi api credentials #12135

Merged
merged 5 commits into from
Jun 6, 2024

Conversation

selldinesh
Copy link
Contributor

Description of PR

Summary: This pr adds a way of passing credentials for snappi_api based on snappi-sonic.yml file
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 201911
  • 202012
  • 202205
  • 202305
  • 202311

Approach

What is the motivation for this PR?

To pass username and password for snappi api

How did you do it?

Fetches the username and password from ansible/group_vars/snappi_sonic/snappi-sonic.yml file

How did you verify/test it?

Tested on linux api server

Any platform specific information?

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

Documentation

@selldinesh selldinesh changed the title Passing snappi api credentials Fix for passing snappi api credentials Mar 22, 2024
@selldinesh
Copy link
Contributor Author

@developfast can you please approve this PR

location = "https://" + snappi_api_serv_ip + ":" + str(snappi_api_serv_port)
# TODO: Currently extension is defaulted to ixnetwork.
# Going forward, we should be able to specify extension
# from command line while running pytest.
api = snappi.api(location=location, ext="ixnetwork")

api._username = duthost.host.options['variable_manager'].\
_hostvars[duthost.hostname]['secret_group_vars']['snappi_api_server']['user']
Copy link
Contributor

Choose a reason for hiding this comment

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

@selldinesh :
No need for "secret_group_vars". It gives KeyError.
We can directly use:
_hostvars[duthost.hostname]['snappi_api_server']['user'].
Same for password.

Copy link
Contributor

Choose a reason for hiding this comment

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

After doing this change, this is able to work.

@selldinesh
Copy link
Contributor Author

Hi @developfast ,
Request to approve this PR

@rraghav-cisco
Copy link
Contributor

@vmittal-msft : for viz.

@mssonicbld
Copy link
Collaborator

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/common/snappi_tests/snappi_fixtures.py:62:5: F841 local variable 'duthost' is assigned to but never used

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
  1. Go to repository root folder
  2. Install the pre-commit hooks:
pre-commit install
  1. Use pre-commit to check staged file:
pre-commit
  1. Alternatively, you can check committed files using:
pre-commit run --from-ref <commit_id> --to-ref <commit_id>

@abdosi abdosi merged commit 52a0fa2 into sonic-net:master Jun 6, 2024
14 checks passed
mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Jun 13, 2024
* passing non default password from snappi-sonic.yml file

* passing non default password from snappi-sonic.yml file

* commenting the username and paswword block

* removing duthost
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202405: #13286

mssonicbld pushed a commit that referenced this pull request Jun 13, 2024
* passing non default password from snappi-sonic.yml file

* passing non default password from snappi-sonic.yml file

* commenting the username and paswword block

* removing duthost
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.

7 participants