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

[crm]: Implement test for CRM #473

Merged
merged 3 commits into from
Mar 14, 2018
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
4 changes: 4 additions & 0 deletions ansible/README.test.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME} -e "testbed_name
```
- Requires switch connected to a t0 testbed
- Requires switch connected to fanout switch and fanout switch need support [QinQ](https://en.wikipedia.org/wiki/IEEE_802.1ad).

### CRM test
```
ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME} --become --tags crm
45 changes: 45 additions & 0 deletions ansible/roles/test/tasks/crm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
- block:

- name: Set polling interval
command: crm config polling interval 1

- name: Make sure CRM counters updated
pause: seconds=300

- name: Run test case "CRM IPv4 route resource"
include: roles/test/tasks/crm/crm_test_ipv4_route.yml

- name: Run test case "CRM IPv6 route resource"
include: roles/test/tasks/crm/crm_test_ipv6_route.yml

- name: Run test case "CRM IPv4 nexthop resource"
include: roles/test/tasks/crm/crm_test_ipv4_nexthop.yml

- name: Run test case "CRM IPv6 nexthop resource"
include: roles/test/tasks/crm/crm_test_ipv6_nexthop.yml

- name: Run test case "CRM IPv4 neighbor resource"
include: roles/test/tasks/crm/crm_test_ipv4_neighbor.yml

- name: Run test case "CRM IPv6 neighbor resource"
include: roles/test/tasks/crm/crm_test_ipv6_neighbor.yml

- name: Run test case "CRM nexthop group resource"
include: roles/test/tasks/crm/crm_test_nexthop_group.yml

- name: Run test case "CRM nexthop group member resource"
include: roles/test/tasks/crm/crm_test_nexthop_group_member.yml

- name: Run test case "CRM ACL entry resources"
include: roles/test/tasks/crm/crm_test_acl_entry.yml

- name: Run test case "CRM ACL counter resources"
include: roles/test/tasks/crm/crm_test_acl_counter.yml

- name: Run test case "CRM FDB entry resource"
include: roles/test/tasks/crm/crm_test_fdb_entry.yml

always:

- name: Restore polling interval
command: crm config polling interval 300
30 changes: 30 additions & 0 deletions ansible/roles/test/tasks/crm/acl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"acl": {
"acl-sets": {
"acl-set": {
"dataacl": {
"acl-entries": {
"acl-entry": {
"1": {
"actions": {
"config": {
"forwarding-action": "ACCEPT"
}
},
"config": {
"sequence-id": 1
},
"l2": {
"config": {
"ethertype": "2048"
}
}
}
}
}
}
}
}
}
}

62 changes: 62 additions & 0 deletions ansible/roles/test/tasks/crm/crm_test_acl_counter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- block:

- set_fact: crm_stats_acl_counter_used=0
- set_fact: crm_stats_acl_counter_available=0

- name: Copy ACL JSON config to switch.
copy: src=roles/test/tasks/crm/acl.json dest=/tmp

- name: Add ACL
command: acl-loader update full /tmp/acl.json
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, @lguohan, is DATAACL table always present in the DUTs or is there any case where it may be missing. If so, the acl-loader will fail since it adds the entry to DATAACL


- name: Get ACL table key
command: bash -c "docker exec -i database redis-cli --raw -n 2 KEYS *CRM:ACL_TABLE_STATS* | head -1"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fetching the first table entry and checking for values. But if there are multiple tables, and if the acl-loader is updating entries to a table other than the first entry, then this test fails.

register: out
- set_fact: acl_tbl_key={{out.stdout}}

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_acl_counter_used" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_counter_used
register: out
- set_fact: new_crm_stats_acl_counter_used={{out.stdout}}

- name: Get new "crm_stats_acl_counter_available" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_counter_available
register: out
- set_fact: new_crm_stats_acl_counter_available={{out.stdout}}

- name: Verify "crm_stats_acl_counter_used" counter was incremented
assert: {that: "{{new_crm_stats_acl_counter_used|int - crm_stats_acl_counter_used|int == 2}}"}

- set_fact: crm_stats_acl_counter_available="{{new_crm_stats_acl_counter_available|int + new_crm_stats_acl_counter_used|int}}"

- name: Verify thresholds for "ACL entry" CRM resource
vars:
crm_cli_res: "acl group entry"
crm_used: "{{new_crm_stats_acl_counter_used}}"
crm_avail: "{{new_crm_stats_acl_counter_available}}"
include: roles/test/tasks/crm/crm_test_threshold.yml

- name: Remove ACL
command: acl-loader delete

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_acl_counter_used" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_counter_used
register: out
- set_fact: new_crm_stats_acl_counter_used={{out.stdout}}

- name: Get new "crm_stats_acl_counter_available" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_counter_available
register: out
- set_fact: new_crm_stats_acl_counter_available={{out.stdout}}

- name: Verify "crm_stats_acl_counter_used" counter was decremented
assert: {that: "{{new_crm_stats_acl_counter_used|int - crm_stats_acl_counter_used|int == 0}}"}

- name: Verify "crm_stats_acl_counter_available" counter was incremented
assert: {that: "{{new_crm_stats_acl_counter_available|int - crm_stats_acl_counter_available|int == 0}}"}
62 changes: 62 additions & 0 deletions ansible/roles/test/tasks/crm/crm_test_acl_entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- block:

- set_fact: crm_stats_acl_entry_used=0
- set_fact: crm_stats_acl_entry_available=0

- name: Copy ACL JSON config to switch.
copy: src=roles/test/tasks/crm/acl.json dest=/tmp

- name: Add ACL
command: acl-loader update full /tmp/acl.json

- name: Get ACL table key
command: bash -c "docker exec -i database redis-cli --raw -n 2 KEYS *CRM:ACL_TABLE_STATS* | head -1"
register: out
- set_fact: acl_tbl_key={{out.stdout}}

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_acl_entry_used" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_entry_used
register: out
- set_fact: new_crm_stats_acl_entry_used={{out.stdout}}

- name: Get new "crm_stats_acl_entry_available" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_entry_available
register: out
- set_fact: new_crm_stats_acl_entry_available={{out.stdout}}

- name: Verify "crm_stats_acl_entry_used" counter was incremented
assert: {that: "{{new_crm_stats_acl_entry_used|int - crm_stats_acl_entry_used|int == 2}}"}

- set_fact: crm_stats_acl_entry_available="{{new_crm_stats_acl_entry_available|int + new_crm_stats_acl_entry_used|int}}"

- name: Verify thresholds for "ACL entry" CRM resource
vars:
crm_cli_res: "acl group entry"
crm_used: "{{new_crm_stats_acl_entry_used}}"
crm_avail: "{{new_crm_stats_acl_entry_available}}"
include: roles/test/tasks/crm/crm_test_threshold.yml

- name: Remove ACL
command: acl-loader delete

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_acl_entry_used" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_entry_used
register: out
- set_fact: new_crm_stats_acl_entry_used={{out.stdout}}

- name: Get new "crm_stats_acl_entry_available" counter value
command: docker exec -i database redis-cli -n 2 HGET {{acl_tbl_key}} crm_stats_acl_entry_available
register: out
- set_fact: new_crm_stats_acl_entry_available={{out.stdout}}

- name: Verify "crm_stats_acl_entry_used" counter was decremented
assert: {that: "{{new_crm_stats_acl_entry_used|int - crm_stats_acl_entry_used|int == 0}}"}

- name: Verify "crm_stats_acl_entry_available" counter was incremented
assert: {that: "{{new_crm_stats_acl_entry_available|int - crm_stats_acl_entry_available|int == 0}}"}
66 changes: 66 additions & 0 deletions ansible/roles/test/tasks/crm/crm_test_fdb_entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
- block:

- name: Get "crm_stats_fdb_entry_used" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_fdb_entry_used
register: out
- set_fact: crm_stats_fdb_entry_used={{out.stdout}}

- name: Get "crm_stats_fdb_entry_available" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_fdb_entry_available
register: out
- set_fact: crm_stats_fdb_entry_available={{out.stdout}}

- name: Copy FDB JSON config to switch.
copy: src=roles/test/tasks/crm/fdb.json dest=/tmp

- name: Copy FDB JSON config to SWSS container
command: docker cp /tmp/fdb.json swss:/

- name: Add FDB entry
command: docker exec -i swss swssconfig /fdb.json

- name: Add VLAN required for FDB entry
command: config vlan add 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This require root privileges. Please add become: yes


- name: Add VLAN member required for FDB entry
command: config vlan member add 2 Ethernet0
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and other places in file where "config vlan" is invoked.


- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_fdb_entry_used" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_fdb_entry_used
register: out
- set_fact: new_crm_stats_fdb_entry_used={{out.stdout}}

- name: Get new "crm_stats_fdb_entry_available" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_fdb_entry_available
register: out
- set_fact: new_crm_stats_fdb_entry_available={{out.stdout}}

- name: Verify "crm_stats_fdb_entry_used" counter was incremented
assert: {that: "{{new_crm_stats_fdb_entry_used|int - crm_stats_fdb_entry_used|int == 1}}"}

- name: Verify "crm_stats_fdb_entry_available" counter was decremented
assert: {that: "{{crm_stats_fdb_entry_available|int - new_crm_stats_fdb_entry_available|int == 1}}"}

- name: Verify thresholds for "FDB entry" CRM resource
vars:
crm_cli_res: "fdb"
crm_used: "{{new_crm_stats_fdb_entry_used}}"
crm_avail: "{{new_crm_stats_fdb_entry_available}}"
include: roles/test/tasks/crm/crm_test_threshold.yml

always:

- name: Remove VLAN member required for FDB entry
command: config vlan member del 2 Ethernet0

- name: Remove VLAN required for FDB entry
command: config vlan del 2

- name: Remove FDB JSON config from switch.
Copy link
Contributor

Choose a reason for hiding this comment

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

How are we deleting the FDB entry that got added to the switch?

command: rm /tmp/fdb.json

- name: Remove FDB JSON config from SWSS container
command: docker exec -i swss rm /fdb.json
62 changes: 62 additions & 0 deletions ansible/roles/test/tasks/crm/crm_test_ipv4_neighbor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- block:

- name: Get "crm_stats_ipv4_neighbor_used" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_used
register: out
- set_fact: crm_stats_ipv4_neighbor_used={{out.stdout}}

- name: Get "crm_stats_ipv4_neighbor_available" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_available
register: out
- set_fact: crm_stats_ipv4_neighbor_available={{out.stdout}}

- name: Add IPv4 neighbor
command: ip neigh replace 2.2.2.2 lladdr 11:22:33:44:55:66 dev Ethernet0

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_ipv4_neighbor_used" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_used
register: out
- set_fact: new_crm_stats_ipv4_neighbor_used={{out.stdout}}

- name: Get new "crm_stats_ipv4_neighbor_available" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_available
register: out
- set_fact: new_crm_stats_ipv4_neighbor_available={{out.stdout}}

- name: Verify "crm_stats_ipv4_neighbor_used" counter was incremented
assert: {that: "{{new_crm_stats_ipv4_neighbor_used|int - crm_stats_ipv4_neighbor_used|int >= 1}}"}

- name: Verify "crm_stats_ipv4_neighbor_available" counter was decremented
assert: {that: "{{crm_stats_ipv4_neighbor_available|int - new_crm_stats_ipv4_neighbor_available|int == 1}}"}

- name: Remove IPv4 neighbor
command: ip neigh del 2.2.2.2 lladdr 11:22:33:44:55:66 dev Ethernet0

- name: Make sure CRM counters updated
pause: seconds=1

- name: Get new "crm_stats_ipv4_neighbor_used" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_used
register: out
- set_fact: new_crm_stats_ipv4_neighbor_used={{out.stdout}}

- name: Get new "crm_stats_ipv4_neighbor_available" counter value
command: docker exec -i database redis-cli -n 2 HGET CRM:STATS crm_stats_ipv4_neighbor_available
register: out
- set_fact: new_crm_stats_ipv4_neighbor_available={{out.stdout}}

- name: Verify "crm_stats_ipv4_neighbor_used" counter was decremented
assert: {that: "{{new_crm_stats_ipv4_neighbor_used|int - crm_stats_ipv4_neighbor_used|int >= 0}}"}

- name: Verify "crm_stats_ipv4_neighbor_available" counter was incremented
assert: {that: "{{new_crm_stats_ipv4_neighbor_available|int - crm_stats_ipv4_neighbor_available|int == 0}}"}

- name: Verify thresholds for "IPv4 neighbor" CRM resource
vars:
crm_cli_res: "ipv4 neighbor"
crm_used: "{{new_crm_stats_ipv4_neighbor_used}}"
crm_avail: "{{new_crm_stats_ipv4_neighbor_available}}"
include: roles/test/tasks/crm/crm_test_threshold.yml
Loading