-
Notifications
You must be signed in to change notification settings - Fork 1k
Add ACL ranges test #168
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
Merged
oleksandrivantsiv
merged 2 commits into
sonic-net:master
from
andriymoroz-mlnx:acl_ranges_test
Apr 28, 2017
Merged
Add ACL ranges test #168
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # Usage example: | ||
| # ansible-playbook test_sonic.yml -i inventory --limit arc-switch1028 --tags acltb_ranges_test -b -e ranges_number=3 -e ptf_host=ptf-fib | ||
| # | ||
| # Variable "ranges_number" defines how many ACL range objects the test will attempt to create | ||
| # | ||
|
|
||
| # Input arguments check | ||
| - fail: msg="ranges_number is not defined." | ||
| when: ranges_number is not defined | ||
|
|
||
| # Set facts for ACL configuration | ||
| - set_fact: | ||
| acltb_configs: | ||
| - "{{ 'acl_ranges_table' }}" | ||
| - "{{ 'acl_ranges_rules' }}" | ||
|
|
||
| # Set facts for the loganalizer | ||
| - set_fact: | ||
| testname: acl | ||
| run_dir: /tmp | ||
| out_dir: /tmp/ansible-loganalyzer-results | ||
| test_match_file: acltb_match_messages.txt | ||
| test_ignore_file: acltb_ignore_messages.txt | ||
| test_expect_file: acltb_expect_messages.txt | ||
| match_file: loganalyzer_common_match.txt | ||
| ignore_file: loganalyzer_common_ignore.txt | ||
|
|
||
| # Separate set_fact is required to be able to use 'testname' fact. | ||
| - set_fact: | ||
| testname_unique: "{{ testname }}.{{ ansible_date_time.date}}.{{ ansible_date_time.hour}}-{{ ansible_date_time.minute}}-{{ ansible_date_time.second}}" | ||
|
|
||
| # Separate set_fact is required to be able to use 'testname_unique' fact. | ||
| - set_fact: | ||
| test_out_dir: "{{ out_dir }}/{{testname_unique}}" | ||
| match_file_list: "{{ run_dir }}/{{test_match_file}},{{ run_dir }}/{{match_file}}" | ||
| ignore_file_list: "{{ run_dir }}/{{test_ignore_file}},{{ run_dir }}/{{ignore_file}}" | ||
| result_file: result.loganalysis.{{testname_unique}}.log | ||
| summary_file: summary.loganalysis.{{testname_unique}}.log | ||
|
|
||
| # Gather minigraph facts | ||
| - name: Gathering minigraph facts about the device | ||
| minigraph_facts: host={{ inventory_hostname }} | ||
| become: no | ||
| connection: local | ||
|
|
||
| - name: Read port reverse alias mapping | ||
| set_fact: | ||
| alias_reverse_map: "{{ lookup('file', 'roles/sonicv2/files/ssw/{{ sonic_hwsku }}/alias_reverse_map.json') | from_json }}" | ||
|
|
||
| - include: roles/test/files/tools/loganalyzer/loganalyzer_init.yml | ||
| vars: | ||
| tests_location: "{{ 'roles/test/tasks' }}" | ||
|
|
||
| # Outer block to execute laganalizer in always block | ||
| - block: | ||
| # Perform the test: generate and apply acl jsons | ||
| - block: | ||
| - name: Copy JSON configs into docker filesystem | ||
| template: src={{ item }}.j2 dest=/tmp/{{ item }}.json | ||
| with_items: | ||
| - "{{ acltb_configs }}" | ||
|
|
||
| - name: Load JSON configs | ||
| shell: swssconfig /tmp/{{ item }}.json | ||
| with_items: | ||
| - "{{ acltb_configs }}" | ||
|
|
||
| - name: Change JSON configs to delete (table) | ||
| shell: sed 's/SET/DEL/g' /tmp/{{ item }}.json >/tmp/del_{{ item }}.json | ||
| with_items: | ||
| - "{{ acltb_configs }}" | ||
|
|
||
| - name: Pause 5 sec to let rules to settle down | ||
| pause: | ||
| seconds: 5 | ||
|
|
||
| - name: Load JSON configs in reversed order | ||
| shell: swssconfig /tmp/del_{{ item }}.json | ||
| with_items: | ||
| - "{{ acltb_configs[::-1] }}" | ||
|
|
||
| vars: | ||
| ansible_shell_type: docker | ||
| ansible_python_interpreter: docker exec -i swss python | ||
|
|
||
| always: | ||
| - include: roles/test/files/tools/loganalyzer/loganalyzer_analyze.yml | ||
| vars: | ||
| tests_location: "{{ 'roles/test/tasks' }}" | ||
|
|
||
| # Output content of result files to ansible console | ||
| - shell: cat {{ test_out_dir }}/* | ||
| register: out | ||
| - debug: var=out.stdout_lines | ||
|
|
||
| - name: Get the total number of error messages. | ||
| shell: grep "TOTAL MATCHES" "{{ test_out_dir }}/{{ summary_file }}" | sed -n "s/TOTAL MATCHES:[[:space:]]*//p" | ||
| register: errors_found | ||
|
|
||
| - name: Check the number of error messages (positive tests only). | ||
| fail: msg="{{ errors_found.stdout }} errors found while running {{ testname }} test. Please see {{ test_out_dir }}/{{ result_file }}" | ||
| when: errors_found.stdout != "0" | ||
|
|
||
| - include: roles/test/files/tools/loganalyzer/loganalyzer_end.yml | ||
| vars: | ||
| tests_location: "{{ 'roles/test/tasks' }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [ | ||
| {% for tor in range(ranges_number | int) %} | ||
| { | ||
| "ACL_RULE_TABLE:ACL_Testbed_Range_Test_Table:Rule{{ loop.index }}_port_range_test": { | ||
| "priority" : "50", | ||
| "l4_dst_port_range" : "{{ 1024 + loop.index * 16 }}-{{ 1024 + loop.index * 16 + 10 }}", | ||
| "packet_action" : "forward" | ||
| }, | ||
| "OP": "SET" | ||
| }{% if not loop.last %}, | ||
| {% endif %} | ||
| {% endfor %} | ||
|
|
||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [ | ||
| { | ||
| "ACL_TABLE:ACL_Testbed_Range_Test_Table": { | ||
| "policy_desc" : "This_table_contains_rules_needed_for_the_testbed_ranges_test", | ||
| "type" : "L3", | ||
| "ports" : "{% for ifname, v in minigraph_neighbors.iteritems() %}{{"%s" % alias_reverse_map[ifname]}},{% endfor %}" | ||
| }, | ||
| "OP": "SET" | ||
| } | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get these values from minigraph facts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure...
I just used the solution used in fib, lag, everflow and other tests