Skip to content
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
73 changes: 73 additions & 0 deletions ansible/library/combine_list_to_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/python
from netaddr import *
import sys
import ipaddress

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
get_ip_in_range: keys={{keys}} values={{values}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

combine_list_to_dict

'''


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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

convert all your tabs to spaces.

print "get the 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()
16 changes: 11 additions & 5 deletions ansible/roles/test/files/helpers/pfc_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions ansible/roles/test/tasks/pfc_wd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 +49,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
Loading