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

[PFCWD]: test enhancement #456

Merged
merged 4 commits into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
67 changes: 67 additions & 0 deletions ansible/library/combine_list_to_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/python
import sys

DOCUMENTATION = '''
module: combine_list_to_dict
version_added: "1.0"
short_description: Combine a list of key and list of value to a key-value dictionary
description:
- Generate the dictionary based on key and value list
- key and value are 1:1 mapping in sequence, and values with the same key will combined into a list.
- Generated dict will be inserted into the 'combined_dict' key
options:
keys:
description:
- the required key list
required: true
values:
description:
- the required value list.
required: true
'''

EXAMPLES = '''
- name: Combine list to dict
combine_list_to_dict: keys={{keys}} values={{values}}
'''

class CombineListModule(object):
def __init__(self):
self.module = AnsibleModule(
argument_spec=dict(
keys=dict(required=True, type='list'),
values=dict(required=True, type='list'),
),
supports_check_mode=True)

self.out = None
self.facts = {}

return

def run(self):
"""
Main method of the class

"""
m_args = self.module.params
keys = m_args['keys']
values = m_args['values']
combined_dict = {}
for key, value in zip(keys, values):
if key not in combined_dict:
combined_dict[key] = [value]
else:
combined_dict[key].append(value)
self.facts['combined_dict'] = combined_dict
self.module.exit_json(ansible_facts=self.facts)

def main():
combine_list = CombineListModule()
combine_list.run()

return

from ansible.module_utils.basic import *
if __name__ == "__main__":
main()
18 changes: 12 additions & 6 deletions ansible/roles/test/files/helpers/pfc_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def checksum(msg):
def main():
usage = "usage: %prog [options] arg1 arg2"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-i", "--interface", type="string", dest="interface", help="Interface to send packets",metavar="Interface")
parser.add_option("-i", "--interface", type="string", dest="interface", help="Interface list to send packets, seperated by ','",metavar="Interface")
parser.add_option('-p', "--priority", type="int", dest="priority", help="PFC class enable bitmap.", metavar="Priority")
parser.add_option("-t", "--time", type="int", dest="time", help="Pause time in quanta for enabled class",metavar="time")
parser.add_option("-n", "--num", type="int", dest="num", help="Number of packets to be sent",metavar="number",default=1)
Expand All @@ -57,17 +57,22 @@ def main():
parser.print_help()
sys.exit(1)

try:
s = socket(AF_PACKET, SOCK_RAW)
interfaces = options.interface.split(',')

try:
sockets = []
for i in range(0, len(interfaces)):
sockets.append(socket(AF_PACKET, SOCK_RAW))
except:
print "Unable to create socket. Check your permissions"
sys.exit(1)

# Configure logging
handler = logging.handlers.SysLogHandler(address = (options.rsyslog_server,514))
my_logger.addHandler(handler)

s.bind((options.interface, 0))

for s,interface in zip(sockets, interfaces):
s.bind((interface, 0))

"""
Set PFC defined fields and generate the packet
Expand Down Expand Up @@ -112,7 +117,8 @@ def main():
my_logger.debug('PFC_STORM_START')
iteration = options.num
while iteration > 0:
s.send(packetsend)
for s in sockets:
s.send(packetsend)
iteration -= 1
my_logger.debug('PFC_STORM_END')

Expand Down
20 changes: 19 additions & 1 deletion ansible/roles/test/tasks/pfc_wd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#-----------------------------------------
# Run all the PFC WD tests.
#-----------------------------------------
# The test currently supports arista fanout switches,to support othern platforms:
#
# 1. Add platform specific logic to deploy pfc packet generator automatically
# in roles/test/tasks/pfc_wd/functional_test/deploy_pfc_pktgen.yml
# or manual deploy roles/test/files/helpers/pfc_gen.py and ensure the file is available on fanout switch.
#
# 2. Create pfc_storm_[sku].j2 and pfc_storm_stop_[sku].j2 under roles/test/templates/
# to run/stop pfc packet generator which triggers pfc storm start/stop action.
#
# 3. Set pfc_storm_template and pfc_storm_stop_template variables to platform-specific template names.
# in roles/test/tasks/pfc_wd/functional_test/set_pfc_storm_templates.yml
#---------------------------------------------

- set_fact:
run_dir: /home/admin/pfc_wd_tests
Expand All @@ -23,6 +34,10 @@
become: no
connection: local

- set_fact:
port_list: "{{minigraph_ports.keys()}}"
ports: "{{minigraph_ports.keys() | join(' ')}}"

- set_fact:
neighbors: "{{device_conn}}"

Expand All @@ -45,6 +60,9 @@
peer_device: "{{ neighbors[pfc_wd_test_port]['peerdevice'] }}"
include: roles/test/tasks/pfc_wd/functional_test/functional_test.yml

- name: Test PFC WD extreme case when all ports have storm
include: roles/test/tasks/pfc_wd/functional_test/storm_all_test.yml

always:
- name: General cleanup.
file:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: Create pfc generater file in case it doesn't exist.
file: path=/mnt/flash/{{pfc_gen_file}} state=touch
delegate_to: "{{peer_mgmt}}"
become: true
when: peer_hwsku | search("Arista") or peer_hwsku | search("arista")

- name: Deploy PFC generator to the fanout switch
copy: src=roles/test/files/helpers/{{pfc_gen_file}} dest=/mnt/flash
delegate_to: "{{peer_mgmt}}"
become: true
when: peer_hwsku | search("Arista") or peer_hwsku | search("arista")
Loading