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

[everflow] align capability fetch with new swss implementation #4773

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions ansible/library/acl_capabilities_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python

import swsssdk
from sonic_py_common import multi_asic
DOCUMENTATION = '''
module: acl_capabilities_facts
version_added: "1.0"
author: Stepan Blyschak (stepanb@nvidia.com)
short_description: Retrieve ACL capability information
'''

EXAMPLES = '''
- name: Get ACL capability facts
acl_capabilities_facts:
'''


class AclCapabilityModule(object):
def __init__(self):
self.module = AnsibleModule(
argument_spec=dict(),
supports_check_mode=True)

self.out = None
self.facts = {}

return

def run(self):
"""
Run ACL capabilities facts collection.
"""
self.facts['acl_capabilities'] = {}
namespace_list = multi_asic.get_namespace_list()
swsssdk.SonicDBConfig.load_sonic_global_db_config()
conn = swsssdk.SonicV2Connector(namespace=namespace_list[0])
conn.connect(conn.STATE_DB)
keys = conn.keys(conn.STATE_DB, 'ACL_STAGE_CAPABILITY_TABLE|*')

for key in keys:
capab = conn.get_all(conn.STATE_DB, key)
self.facts['acl_capabilities'][key.split('|')[-1]] = capab

self.module.exit_json(ansible_facts=self.facts)


def main():
AclCapabilityModule().run()


from ansible.module_utils.basic import *
if __name__ == "__main__":
main()

10 changes: 6 additions & 4 deletions tests/everflow/everflow_test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def setup_info(duthosts, rand_one_dut_hostname, tbinfo):
# Gather test facts
mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
switch_capability_facts = duthost.switch_capabilities_facts()["ansible_facts"]
acl_capability_facts = duthost.acl_capabilities_facts()["ansible_facts"]

# Get the list of T0/T2 ports
# TODO: The ACL tests do something really similar, I imagine we could refactor this bit.
Expand Down Expand Up @@ -92,6 +93,7 @@ def setup_info(duthosts, rand_one_dut_hostname, tbinfo):


switch_capabilities = switch_capability_facts["switch_capabilities"]["switch"]
acl_capabilities = acl_capability_facts["acl_capabilities"]

test_mirror_v4 = switch_capabilities["MIRROR"] == "true"
test_mirror_v6 = switch_capabilities["MIRRORV6"] == "true"
Expand All @@ -105,10 +107,10 @@ def setup_info(duthosts, rand_one_dut_hostname, tbinfo):
test_egress_mirror_on_egress_acl = False
test_egress_mirror_on_ingress_acl = False
else:
test_ingress_mirror_on_ingress_acl = "MIRROR_INGRESS_ACTION" in switch_capabilities["ACL_ACTIONS|INGRESS"]
test_ingress_mirror_on_egress_acl = "MIRROR_INGRESS_ACTION" in switch_capabilities["ACL_ACTIONS|EGRESS"]
test_egress_mirror_on_egress_acl = "MIRROR_EGRESS_ACTION" in switch_capabilities["ACL_ACTIONS|EGRESS"]
test_egress_mirror_on_ingress_acl = "MIRROR_EGRESS_ACTION" in switch_capabilities["ACL_ACTIONS|INGRESS"]
test_ingress_mirror_on_ingress_acl = "MIRROR_INGRESS_ACTION" in acl_capabilities["INGRESS"]["action_list"]
test_ingress_mirror_on_egress_acl = "MIRROR_INGRESS_ACTION" in acl_capabilities["EGRESS"]["action_list"]
test_egress_mirror_on_egress_acl = "MIRROR_EGRESS_ACTION" in acl_capabilities["EGRESS"]["action_list"]
test_egress_mirror_on_ingress_acl = "MIRROR_EGRESS_ACTION" in acl_capabilities["INGRESS"]["action_list"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make it back compatible by checking switch_capabilities if acl_capabilities is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


# Collects a list of interfaces, their port number for PTF, and the LAGs they are members of,
# if applicable.
Expand Down