Skip to content

Add utilities to get ansible variables by hostname or group name#2687

Merged
wangxin merged 1 commit intosonic-net:masterfrom
wangxin:get_vars
Dec 21, 2020
Merged

Add utilities to get ansible variables by hostname or group name#2687
wangxin merged 1 commit intosonic-net:masterfrom
wangxin:get_vars

Conversation

@wangxin
Copy link
Collaborator

@wangxin wangxin commented Dec 19, 2020

Description of PR

Summary:
Fixes # (issue)

This change added utilities to get ansible variables by hostname or group name.

Type of change

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

Approach

What is the motivation for this PR?

In test code and library code, there is a frequent need of getting value of specific ansible variables belong to or is visible to specific ansible host or ansible group. This changed added utility functions to simplify this effort. By using these functions, we just need to supply the list of inventory files, server or group name, variable name.

How did you do it?

The functions will take advantage of the ansible's InventoryManager and VariableManager to get value of variables. Added functions:

get_inventory_manager(inv_files)
get_variable_manager(inv_files)
get_host_vars(inv_files, hostname, variable=None)
get_host_visible_vars(inv_files, hostname, variable=None)
get_group_visible_vars(inv_files, group_name, variable=None)
get_test_server_vars(inv_files, server, variable=None)

The inv_files argument can be a string or list. It's value should be inventory file path or list of inventory file paths. In tests, it can be retrieved from the pytest builtin fixture request, for example: request.config.getoption("ansible_inventory")

How did you verify/test it?

Import the utility file and test run the functions.

Any platform specific information?

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

Documentation

@wangxin wangxin requested a review from a team December 19, 2020 03:43
Signed-off-by: Xin Wang <xiwang5@microsoft.com>
@wangxin wangxin merged commit cd98224 into sonic-net:master Dec 21, 2020
@wangxin wangxin deleted the get_vars branch February 1, 2021 08:22
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
swss:
* 143cd44 2023-03-04 | Revert "[aclorch] Fixed issue sonic-net#2204.Support IN_PORTS qualifer in MIRRORV6 table. (sonic-net#2668)" (sonic-net#2687) (HEAD -> 202205, github/202205) [StormLiangMS]
* 25812f8 2023-02-06 | [test_mux] add sleep in test_NH (sonic-net#2648) [Nikola Dancejic]

Signed-off-by: Ying Xie <ying.xie@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants