Skip to content

Add support of running general Ansible modules on EosHost#1721

Merged
yxieca merged 2 commits intosonic-net:masterfrom
wangxin:improve-eoshost-pr
Jun 6, 2020
Merged

Add support of running general Ansible modules on EosHost#1721
yxieca merged 2 commits intosonic-net:masterfrom
wangxin:improve-eoshost-pr

Conversation

@wangxin
Copy link
Collaborator

@wangxin wangxin commented Jun 2, 2020

Description of PR

Summary:
Fixes # (issue)
The EOS hosts support two types of command line interface:

  1. Linux shell
  2. EOS shell

Currently the EosHost class can only support running eos_* ansible modules. This change is to add the support of running general Ansible modules that can only be executed under Linux shell.

Type of change

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

Approach

How did you do it?

Improved the EosHost class defined in tests/common/devices.py to make it accepts two sets of credential:

  1. The first set of credential exposes the EOS CLI interface. When use this set of credential, we use ansible_connection network_cli.
  2. The second set of credential exposes the linux shell of EOS. When use this set of credential, we use ansible_connection ssh.

If name of the ansible module to be executed on EOS hosts starts with "eos_", then use ansible_connection network_cli to run the module. Otherwise, use ansible_connection ssh to run the module.

How did you verify/test it?

Use a simple script to run both eos_* ansible module and general ansible modules on the EOS hosts and fanout hosts.

For this PR to work, please add your own fanout credentials in the ansible variable files. For example, you can add a secrets.yml file under ansible/group_vars/all or ansible/group_vars/sonic. The fanout credentials can be defined in it, for example:

fanout_admin_user: <your_own_user>
fanout_admin_password: <your_own_password>
fanout_root_user: <your_own_root_user>
fanout_root_password: <your_own_root_password>

Credential set fanout_admin_user/fanout_admin_password should expose the EOS CLI interface. Credential set fanout_root_user/fanout_root_password should expose the Linux CLI shell.

Any platform specific information?

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

Documentation

@wangxin wangxin requested review from Blueve and yxieca June 2, 2020 13:57
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be getattribute? I think you want to setup credential for all methods, right?

Did you try to call both EOS and Linux method from a same instance?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the idea here is create NetworkCli based host if user call eos module and create LinuxShell based host if user call other module.
The judgement happens when invoking a module because we couldn't keep two types hosts in a single instance and that's why Xin use getattr.
The only overhead is we need to override extra-var and create a host every time when calling a module.

Copy link
Collaborator Author

@wangxin wangxin Jun 3, 2020

Choose a reason for hiding this comment

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

Thanks @Blueve for the explanation.
@yxieca According to https://stackoverflow.com/questions/3278077/difference-between-getattr-vs-getattribute:

A key difference between getattr and getattribute is that getattr is only invoked if the attribute wasn't found the usual ways.

When an attribute is not found on the EosHost or FanoutHost instance, the getattr will try to get a function for running the ansible module. This is the key technique for us to invoke ansible module using format like fanouthost.<ansible_module_name>(*args, **kwargs) or eoshost.<ansible_module_name>(*args, **kwargs)

Here the ansible module can a EOS module like eos_command, eos_config, or a regular module like command, shell, etc.

Yes, I have tested that both EOS and Linux method can be called from a same instance.

To support this, the EosHost need two sets of credential. But the credential for running Linux methods is optional.

@wangxin wangxin marked this pull request as ready for review June 3, 2020 06:46
wangxin added 2 commits June 4, 2020 03:47
The EOS hosts support two types of command line interface:
1. Linux shell
2. EOS shell

This change is to add the support of running general Ansible modules
that can only be executed under Linux shell.

Signed-off-by: Xin Wang <xiwang5@microsoft.com>
* If not able to get the explicitly defined username and
password, fallback to use the value of "fanout_admin_user"
and "fanout_admin_password". It is unlikely to break the
existing code.

* Resolve merge conflicts
@yxieca yxieca merged commit 64ab433 into sonic-net:master Jun 6, 2020
lguohan added a commit that referenced this pull request Jun 7, 2020
@wangxin wangxin deleted the improve-eoshost-pr branch June 28, 2020 10:27
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
…et#7487)

* [202012][swss/swss-common/utilities/kernel] Update submodule

sonic-swss:
- [Monitor Vlan] Fix a typo in hostif (sonic-net#1722)
- Update pool sizes during initialization from timer only (sonic-net#1708)
- [SflowMgr] SamplingRate Update by Speed Change Added (sonic-net#1721)

sonic-swss-common:
- [swss-common] Add MUX Metrics Table (sonic-net#482)
- [azp] Purge swss before installing the newly built deb package (sonic-net#472)

sonic-utilities:
- disk_check: Check & mount RO as RW using tmpfs (sonic-net#1569)
- No more IP validation as it is more likely a URL (sonic-net#1555)
- Stop PMON docker before cold and soft reboots (sonic-net#1514)
- Add soft-reboot reboot type (sonic-net#1453)
- [acl] Use a list instead of a comma-separated string for ACL port list (sonic-net#1519)
- sonic-installer: fix py3 issues in bootloader.aboot (sonic-net#1553)
- Fix unsupported fs.squashfs extraction in sonic-installer (sonic-net#1366)
- [show][config] cli support for firmware upgrade on Y-Cable (sonic-net#1528) (sonic-net#1558)

sonic-linux-kernel:
- [Mellanox] backport kernel patches for hw-management 7.0100.2303 (sonic-net#211)

Signed-off-by: Danny Allen <daall@microsoft.com>

* Update utilities w/ build fix
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
This PR updates the following commits

a9606fb [show] fix show muxcable metrics <port> for sorted output (sonic-net#1731)
7355016 [minigraph][port_config] Use imported config.main and add conditional patch (sonic-net#1728)
cc1d6e4 [configlet] Python3 compatible syntax for extracting a key from the dict (sonic-net#1721)

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
8b149a3 Load the  database global_db only once for show cli  (sonic-net#1712)
cd0e560 [config][interface][speed] Fixed the config interface speed in multiasic issue (sonic-net#1739)
b595ba6 [fast-reboot] revert the change of disabling counter polling before fast-reboot (sonic-net#1744)
8518820 [minigraph] Donot enable PFC watchdog for MgmtTsToR (sonic-net#1734)
2213774 [CLI][show][bgp] Fix the show ip bgp network command (sonic-net#1733)
3526507 [configlet] Python3 compatible syntax for extracting a key from the dict (sonic-net#1721)
5b56b97 [sonic_installer] don't print errors when installing an image not supporting app ext (sonic-net#1719)
a581955 [LLDP] Fix lldpshow script to enable display multiple MAC addresses on the same remote physical interface (sonic-net#1657)
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.

4 participants