-
Notifications
You must be signed in to change notification settings - Fork 999
[snmp_memory] add SNMP memory test #373
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
356fd66
[snmp_memory] add SNMP memory test
okanchou9 629eac2
[snmp_memory] remove unnecessary SNMP query
okanchou9 52e5081
[snmp_memory] update script with request
okanchou9 8177e2e
Merge branch 'master' into snmp_memory
lguohan ad96cfe
Merge branch 'okanchou9-snmp_memory'
lguohan 035beb5
remove text
lguohan 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
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,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) | ||
|
|
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,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 | ||
| 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 | ||
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.
if previous assert fails, your code will not kill the process and the box will have high memory consumption.
Uh oh!
There was an error while loading. Please reload this page.
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.
Don't worry about it, I wrote the "always" section which will kill again this python process at line 99 if previous assert failed.
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.
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."
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.
I see what you mean. I think it is ok.