Skip to content
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
5 changes: 5 additions & 0 deletions ansible/README.test.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ ansible-playbook test_sonic.yml -i {INVENTORY} --limit {DUT_NAME} -e testcase_na
```
- Requires switch connected to a PTF testbed

##### Portstat test
```
ansible-playbook test_sonic.yml -i {INVENTORY} --limit {DUT_NAME} -e testcase_name=portstat -e testbed_name={TESTBED_NAME}
```

##### Port Toggle test
```
ansible-playbook test_sonic.yml -i {INVENTORY} --limit {DUT_NAME} -e testcase_name=port_toggle -e testbed_name={TESTBED_NAME}
Expand Down
67 changes: 67 additions & 0 deletions ansible/roles/test/tasks/portstat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
- name: Verify the portstat clear command works
# roles/test/tasks/portstat
include: portstat/portstat_clear.yml command={{ item }}
with_items:
- portstat -c
- portstat --clear

- name: Test portstat delete all when no saved data # This command fails
include: portstat/portstat_delete_all_no_saved_stats.yml command={{ item }}
with_items:
- portstat -D
- portstat --delete-all

- name: Test portstat delete all with saved tags
include: portstat/portstat_delete_all_stats.yml command={{ item }}
with_items:
- portstat -D
- portstat --delete-all

- name: Test deleting a tag
include: portstat/portstat_delete_tag.yml command={{ item }}
with_items:
- portstat -d -t
- portstat -d --tag
- portstat --delete -t
- portstat --delete --tag

- name: Test display all
include: portstat/portstat_all_fields.yml command={{ item }}
with_items:
- portstat -a
- portstat --all

- name: Test display period
include: portstat/portstat_period.yml command={{ item }}
with_items:
- portstat -p 1
- portstat --period 1


# This test verifies the following command versions don't cause tracebacks
- block:
- name: list of commands to run
set_fact:
portstat_commands:
- portstat -h
- portstat --help
- portstat
- portstat -v
- portstat --version
- portstat -j #This test fails
- portstat --json #This test fails
- portstat -r #This test fails
- portstat --raw #This test fails

- name: Run the commands
shell: "{{ item }}"
with_items: portstat_commands

always:
- name: Clear and reset counters
shell: portstat -D

rescue:
- name: A command failed
debug:
msg: One of the commands failed
41 changes: 41 additions & 0 deletions ansible/roles/test/tasks/portstat/portstat_all_fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
- block:
# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

- name: run the base command
shell: portstat
register: base_out

- name: pull out the number of columns from the headers
set_fact:
top_row_base_number_of_items: "{{ base_out.stdout_lines[0].split()|length }}"

- name: run the all items command
shell: "{{ command }}"
register: all_out

- name: pull out the number of columns from the headers
set_fact:
top_row_all_number_of_items: "{{ all_out.stdout_lines[0].split()|length }}"

- name: verify the all number of columns is greater than the base number of columns
assert:
that: top_row_all_number_of_items > top_row_base_number_of_items

rescue:
- debug:
msg: "A failure occured"

- debug:
var: top_row_base_number_of_items

- debug:
var: top_row_all_number_of_items

always:
- name: reset portstat command
shell: portstat -D
ignore_errors: True

64 changes: 64 additions & 0 deletions ansible/roles/test/tasks/portstat/portstat_clear.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
- block:
# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

# This test verifies if the portstat -c command works as expected
- name: pull current portstat
shell: portstat | grep Ethernet0
register: before_out

- name: Find ethernet0
set_fact:
portstat_eth0: "{{ item }}"
with_items: before_out.stdout_lines
when: "'Ethernet0' in item"

- name: Pull out RX and TX OK counters
set_fact:
before_rx_ok: "{{ portstat_eth0.split()[2].replace(',','') }}"
before_tx_ok: "{{ portstat_eth0.split()[9].replace(',','') }}"

# This is the test command
- name: Testing '{{ command }}'
shell: "{{ command }}"

- name: wait a few seconds for data to repopulate
pause:
seconds: 5

- name: pull current portstat
shell: portstat | grep Ethernet0
register: after_out

- name: Find ethernet0
set_fact:
portstat_eth0: "{{ item }}"
with_items: after_out.stdout_lines
when: "'Ethernet0' in item"

- name: Pull out RX and TX OK counters
set_fact:
after_rx_ok: "{{ portstat_eth0.split()[2].replace(',','') }}"
after_tx_ok: "{{ portstat_eth0.split()[9].replace(',','') }}"

- name: Assert that the cleared rx counter is less than the current counter
assert:
that: "{{ before_rx_ok|int }} > {{ after_rx_ok|int }}"
msg: "'before_rx_ok: {{ before_rx_ok }}' is not greater than 'after_rx_ok: {{ after_rx_ok }}'"

- name: Assert that the cleared tx counter is less than the current counter
assert:
that: "{{ before_tx_ok|int }} > {{ after_tx_ok|int }}"
msg: "'before_tx_ok: {{ before_tx_ok }}' is not greater than 'after_tx_ok: {{ after_tx_ok }}'"

rescue:
- debug:
msg: "A failure occured"

always:
- name: reset portstat command
shell: portstat -D
ignore_errors: True

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- block:
# This test runs the delete all command
# This test fails as of the writing of this test

# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

- name: Clear out all tags using the command '{{ command }}' #This test fails
shell: "{{ command }}"
register: out

rescue:
- name: Display output on failure
debug:
var: out

always:
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

50 changes: 50 additions & 0 deletions ansible/roles/test/tasks/portstat/portstat_delete_all_stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- block:
# This command adds some tags, verifies they exist, then deletes them all

# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

- name: create the test file names
set_fact:
file_names:
- test_1
- test_2
- test_test

- name: create several test stats files
shell: portstat -c -t {{ item }}
with_items: "{{ file_names }}"

- name: pull the list of objects out of the directory
shell: ls -R /tmp
register: ls_out_before

- name: verify that the file names are in the directory
assert:
that: ("1000-" + item) in ls_out_before.stdout
with_items: "{{ file_names }}"

- name: run the command to be tested '{{ command }}'
shell: "{{ command }}"

- name: pull the list of objects out of the directory
shell: ls -R /tmp
register: ls_out_after

- name: verify that the file names are not the directory
assert:
that: ("1000-" + item) not in ls_out_after.stdout
with_items: "{{ file_names }}"

rescue:
- name: An error occured
debug:
msg: An error occured

always:
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

69 changes: 69 additions & 0 deletions ansible/roles/test/tasks/portstat/portstat_delete_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
- block:
# This command adds some tags, deletes one, verify it's gone but the others exist

# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

- name: create the test file names
set_fact:
file_names:
- test_1
- test_2
- test_delete_me

- name: create the file to be deleted
set_fact:
file_to_delete: "{{ file_names[2] }}"

- name: set the list of files to delete to a default value
set_fact:
files_not_deleted: []

- name: create the list of files to not be deleted
set_fact:
files_not_deleted: "{{files_not_deleted}} + ['{{item}}']"
with_items: file_names
when: file_to_delete != item

- name: create several test stats files
shell: portstat -c -t {{ item }}
with_items: "{{ file_names }}"

- name: pull the list of objects out of the directory
shell: ls -R /tmp
register: ls_out_before

- name: verify that the file names are in the directory
assert:
that: ("1000-" + item) in ls_out_before.stdout
with_items: "{{ file_names }}"

- name: run the command to be tested '{{ command }}'
shell: "{{ command }} {{ file_to_delete }}"

- name: pull the list of objects out of the directory
shell: ls -R /tmp
register: ls_out_after

- name: verify that the deleted file name is not in the directory
assert:
that: ("1000-" + file_to_delete) not in ls_out_after.stdout

- name: verify that the remaining file names are in the directory
assert:
that: ("1000-" + item) in ls_out_after.stdout
with_items: "{{ files_not_deleted }}"

rescue:
- name: An error occured
debug:
msg: An error occured

always:
- name: Clear out all tags
shell: portstat -D
ignore_errors: True


39 changes: 39 additions & 0 deletions ansible/roles/test/tasks/portstat/portstat_period.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
- block:
# Makes sure all tags are cleared out
- name: Clear out all tags
shell: portstat -D
ignore_errors: True

- name: set the string to look for
set_fact:
to_find: The rates are calculated within 1 seconds period

- name: run the command
shell: "{{ command }}"
register: out

- name: output to verify
set_fact:
found: "{{ out.stdout_lines[0] }}"

- name: Verify the contents of the first line match the expected string
assert:
that: found == to_find

rescue:
- debug:
msg: "A failure occured"

- name: expected output
debug:
var: to_find

- name: actual output
debug:
var: found

always:
- name: reset portstat command
shell: portstat -D
ignore_errors: True

4 changes: 4 additions & 0 deletions ansible/roles/test/vars/testcases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ testcases:
filename: pfc_wd.yml
topologies: [t0, t0-56, t0-64, t0-64-32, t0-116, t1, t1-lag, t1-64-lag, ptf32, ptf64]

portstat:
filename: portstat.yml
topologies: [t0, t0-16, t0-56, t0-64, t0-116, t1]

port_toggle:
filename: port_toggle.yml
topologies: [t0, t0-64, t0-64-32, t0-116, t1, t1-lag, t1-64-lag, ptf32, ptf64]
Expand Down