Skip to content

Commit

Permalink
[everflow] align capability fetch with new swss implementation (#4773)
Browse files Browse the repository at this point in the history
* [everflow] align capability fetch with new swss implementation

Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored Dec 7, 2021
1 parent bd06538 commit fea06af
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 16 deletions.
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|*') or []

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()

40 changes: 24 additions & 16 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 All @@ -76,22 +77,23 @@ def setup_info(duthosts, rand_one_dut_hostname, tbinfo):
spine_ports_namespace_map[neigh['namespace']].append(dut_port)
spine_ports_namespace.add(neigh['namespace'])

# Set of TOR ports only Namespace
# Set of TOR ports only Namespace
tor_only_namespace = tor_ports_namespace.difference(spine_ports_namespace)
# Set of Spine ports only Namespace
# Set of Spine ports only Namespace
spine_only_namespace = spine_ports_namespace.difference(tor_ports_namespace)
# Randomly choose from TOR_only Namespace if present else just use first one

# Randomly choose from TOR_only Namespace if present else just use first one
tor_namespace = random.choice(tuple(tor_only_namespace)) if tor_only_namespace else tuple(tor_ports_namespace)[0]
# Randomly choose from Spine_only Namespace if present else just use first one
# Randomly choose from Spine_only Namespace if present else just use first one
spine_namespace = random.choice(tuple(spine_only_namespace)) if spine_only_namespace else tuple(spine_ports_namespace)[0]

# Get the corresponding namespace ports
tor_ports = tor_ports_namespace_map[tor_namespace]
spine_ports = spine_ports_namespace_map[spine_namespace]


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 @@ -104,7 +106,13 @@ def setup_info(duthosts, rand_one_dut_hostname, tbinfo):
test_ingress_mirror_on_egress_acl = False
test_egress_mirror_on_egress_acl = False
test_egress_mirror_on_ingress_acl = False
elif acl_capabilities:
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"]
else:
logging.info("Fallback to the old source of ACL capabilities (assuming SONiC release is < 202111)")
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"]
Expand Down Expand Up @@ -197,14 +205,14 @@ def get_port_info(in_port_list, out_port_list, out_port_ptf_id_list, out_port_la
duthost.command("sudo config bgp shutdown all")
time.sleep(60)
duthost.command("mkdir -p {}".format(DUT_RUN_DIR))

yield setup_information
# Enable BGP again

# Enable BGP again
duthost.command("sudo config bgp startup all")
time.sleep(60)
duthost.command("rm -rf {}".format(DUT_RUN_DIR))


# TODO: This should be refactored to some common area of sonic-mgmt.
def add_route(duthost, prefix, nexthop, namespace):
Expand Down Expand Up @@ -528,12 +536,12 @@ def send_and_check_mirror_packets(self,
dest_ports_namespace = self._get_port_namespace(setup,int (dest_ports[0]))

src_port_set = set()
# Some of test scenario are not valid across namespaces so test will explicltly pass

# Some of test scenario are not valid across namespaces so test will explicltly pass
# valid_across_namespace as False (default is True)
if valid_across_namespace == True or src_port_namespace == dest_ports_namespace:
src_port_set.add(src_port)

# To verify same namespace mirroring we will add destination port also to the Source Port Set
if src_port_namespace != dest_ports_namespace:
src_port_set.add(dest_ports[0])
Expand All @@ -549,7 +557,7 @@ def send_and_check_mirror_packets(self,
mirror_packet,
False)


# Loop through Source Port Set and send traffic on each source port of the set
for src_port in src_port_set:
expected_mirror_packet = expected_mirror_packet_with_ttl \
Expand Down Expand Up @@ -591,7 +599,7 @@ def send_and_check_mirror_packets(self,
pytest_assert(inner_packet.pkt_match(mirror_packet), "Mirror payload does not match received packet")
else:
testutils.verify_no_packet_any(ptfadapter, expected_mirror_packet, dest_ports)

@staticmethod
def get_expected_mirror_packet(mirror_session, setup, duthost, mirror_packet, check_ttl):
payload = mirror_packet.copy()
Expand Down Expand Up @@ -668,7 +676,7 @@ def mirror_session_info(session_name, asic_type):
"session_gre": session_gre,
"session_prefixes": session_prefixes
}

def _get_port_namespace(self,setup, port):
return setup["port_index_namespace_map"][port]

Expand Down

0 comments on commit fea06af

Please sign in to comment.