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 @@ -216,6 +216,11 @@ ansible-playbook test_sonic.yml -i {INVENTORY} --limit {DUT_NAME} -e testcase_na
```
- Requires switch connected to a VM set or PTF testbed

### SNMP memory test
```
ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME}, --become --tags snmp_memory -e "tolerance=0.05" -e "min_memory_size=512000"
```

##### NTP test
```
ansible-playbook test_sonic.yml -i {INVENTORY} --limit {DUT_NAME} -e testcase_name=ntp -e testbed_name={TESTBED_NAME}
Expand Down
14 changes: 14 additions & 0 deletions ansible/library/snmp_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ def __init__(self,dotprefix=False):
# From Dell Private MIB
self.ChStackUnitCpuUtil5sec = dp + "1.3.6.1.4.1.6027.3.10.1.2.9.1.2.1"

# Memory Check
self.sysTotalMemery = dp + "1.3.6.1.4.1.2021.4.5.0"
self.sysTotalFreeMemery = dp + "1.3.6.1.4.1.2021.4.6.0"

# From Cisco private MIB (PFC and queue counters)
self.cpfcIfRequests = dp + "1.3.6.1.4.1.9.9.813.1.1.1.1" # + .ifindex
self.cpfcIfIndications = dp + "1.3.6.1.4.1.9.9.813.1.1.1.2" # + .ifindex
Expand Down Expand Up @@ -367,6 +371,9 @@ def main():
cmdgen.MibVariable(p.sysContact,),
cmdgen.MibVariable(p.sysName,),
cmdgen.MibVariable(p.sysLocation,),
cmdgen.MibVariable(p.sysTotalMemery,),
cmdgen.MibVariable(p.sysTotalFreeMemery,),
lookupMib=False, lexicographicMode=False
)

if errorIndication:
Expand All @@ -385,6 +392,10 @@ def main():
results['ansible_sysname'] = current_val
elif current_oid == v.sysLocation:
results['ansible_syslocation'] = current_val
elif current_oid == v.sysTotalMemery:
results['ansible_sysTotalMemery'] = decode_type(module, current_oid, val)
elif current_oid == v.sysTotalFreeMemery:
results['ansible_sysTotalFreeMemery'] = decode_type(module, current_oid, val)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
Expand All @@ -400,6 +411,7 @@ def main():
cmdgen.MibVariable(p.ipAdEntIfIndex,),
cmdgen.MibVariable(p.ipAdEntNetMask,),
cmdgen.MibVariable(p.ifAlias,),
lookupMib=False, lexicographicMode=False
)

if errorIndication:
Expand Down Expand Up @@ -464,6 +476,7 @@ def main():
cmdgen.MibVariable(p.ifHCOutOctets,),
cmdgen.MibVariable(p.ifInUcastPkts,),
cmdgen.MibVariable(p.ifOutUcastPkts,),
lookupMib=False, lexicographicMode=False
)

if errorIndication:
Expand Down Expand Up @@ -601,6 +614,7 @@ def main():
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.MibVariable(p.ChStackUnitCpuUtil5sec,),
lookupMib=False, lexicographicMode=False
)

if errorIndication:
Expand Down
18 changes: 18 additions & 0 deletions ansible/roles/test/tasks/snmp/memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python

import sys
import time

if len(sys.argv) != 2:
print "usage: fillmem <number-of-megabytes>"
sys.exit()

count = int(sys.argv[1])

megabyte = (0,) * (1024 * 1024 / 8)

data = megabyte * count

while True:
time.sleep(1)

123 changes: 123 additions & 0 deletions ansible/roles/test/tasks/snmp/memory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
##########################################################################
# Test SNMP Memory Utilization
#
# - Check the difference percentage of Total Memory between SNMP and shell is 0
# - Check the difference percentage of Total Free Memory between SNMP and shell small than 5% when:
# * Check free memory before stress test
# * Check free memory in stress test
# * Check free memory after stress test
# - Tester can modify the value of tolerance and min_memory_size for different platforms by Ansible extra variable
# * Default value of tolerance is 0.05(5%)
# * Default value of min_memory_size is 512000(512M)
#
# Requires: Ansible v2.0.0.2-1
#
# Usage:
#
# ansible-playbook test_sonic.yml -i inventory --limit switch2 --become --tags snmp_memory -e "tolerance=0.05" -e "min_memory_size=512000"
#
# Author:
#
# Kenie Liu(okanchou9) mailto:[email protected]
##########################################################################

- block:
- name: Check tolerance is set or not. Default is 0.05(5%)
set_fact: tolerance=0.05
when: tolerance is not defined

- name: Check min_memory_size is set or not. Default is 512000(512M)
set_fact: min_memory_size=512000
when: min_memory_size is not defined

- name: Copy Memory stress script to the switch
copy: src={{ item.src }} dest={{ item.dest }}
with_items:
- { src: 'roles/test/tasks/snmp/memory.py', dest: '/tmp/memory.py' }

- name: Gathering basic snmp facts about the device
snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }}
connection: local

- name: Check total memory via shell
shell: grep MemTotal /proc/meminfo | awk '{print $2}'
register: shell_total_memory
become: yes

- name: 'Validating SNMP total memory matches shell "/proc/meminfo" result'
assert:
that: "{{ (ansible_sysTotalMemery|int - shell_total_memory.stdout|int)|abs }} == 0"

- name: Check total free memory via shell
shell: grep MemFree /proc/meminfo | awk '{print $2}'
register: shell_total_free_memory
become: yes

- name: Validating SNMP total free memory matches shell result before stress test
assert:
that: "{{ '%.6f'|format((ansible_sysTotalFreeMemery|int - shell_total_free_memory.stdout|int)|abs / ansible_sysTotalFreeMemery|int) }} <= {{ tolerance|float }}"

- set_fact: test_momory="{{ ((ansible_sysTotalFreeMemery - min_memory_size|int) / 1024)|int }}"

- debug: msg="Memory stress test will skip since system total free momory({{ ansible_sysTotalFreeMemery }}) is less than min_memory_size({{ min_memory_size }})"
when: test_momory|int <= 0

- name: Start memory stress generation
shell: python /tmp/memory.py {{ test_momory }} &
become: yes
when: test_momory|int > 0

- name: Wait for memory stress to reflect in SNMP
pause: seconds=20
when: test_momory|int > 0

- name: Gathering basic snmp facts about the device
snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }}
connection: local
when: test_momory|int > 0

- name: Check total free memory via shell
shell: grep MemFree /proc/meminfo | awk '{print $2}'
register: shell_total_free_memory
become: yes
when: test_momory|int > 0

- name: Validating SNMP total free memory matches shell result in stress test
assert:
that: "{{ '%.6f'|format((ansible_sysTotalFreeMemery|int - shell_total_free_memory.stdout|int)|abs / ansible_sysTotalFreeMemery|int) }} <= {{ tolerance|float }}"
when: test_momory|int > 0

- name: Stop memory stress generation
shell: killall python /tmp/memory.py
become: yes
ignore_errors: true
Copy link
Contributor

Choose a reason for hiding this comment

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

if previous assert fails, your code will not kill the process and the box will have high memory consumption.

Copy link
Contributor Author

@okanchou9 okanchou9 Dec 5, 2017

Choose a reason for hiding this comment

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

Don't worry about it, I wrote the "always" section which will kill again this python process at line 99 if previous assert failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, my question is that if the above assert, will ansible stop there? If ansible stops, then you will not be able to execute subsequent commands.

check here. http://docs.ansible.com/ansible/latest/playbooks_error_handling.html

"Generally playbooks will stop executing any more steps on a host that has a task fail."

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you mean. I think it is ok.

when: test_momory|int > 0

- name: Wait for memory recovery to reflect in SNMP
pause: seconds=20
when: test_momory|int > 0

- name: Gathering basic snmp facts about the device
snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }}
connection: local
when: test_momory|int > 0

- name: Check total free memory via shell
shell: grep MemFree /proc/meminfo | awk '{print $2}'
register: shell_total_free_memory
become: yes
when: test_momory|int > 0

- name: Validating SNMP total free memory matches shell result after stress test
assert:
that: "{{ '%.6f'|format((ansible_sysTotalFreeMemery|int - shell_total_free_memory.stdout|int)|abs / ansible_sysTotalFreeMemery|int) }} <= {{ tolerance|float }}"
when: test_momory|int > 0

always:
- name: Stop memory stress generation
shell: killall python /tmp/memory.py
become: yes
ignore_errors: true

- name: Remove stress test file from DUT
file: path="/tmp/memory.py" state=absent