Skip to content

Convert ansible syslog test to pytest#1930

Merged
arlakshm merged 3 commits intosonic-net:masterfrom
arlakshm:syslog_pytest
Jul 21, 2020
Merged

Convert ansible syslog test to pytest#1930
arlakshm merged 3 commits intosonic-net:masterfrom
arlakshm:syslog_pytest

Conversation

@arlakshm
Copy link
Copy Markdown
Contributor

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • [ x] Test case(new/improvement)

Approach

What is the motivation for this PR?

Convert the ansible syslog test to pytest

How did you do it?

How did you verify/test it?

Verification logs


johnar@41c2d2de66d4:/data/sonic-mgmt/tests$ sudo py.test $PYTEST_COMMON_OPTS --log-file logs/syslog.log --skip_sanity --junitxml=results/tr.xml syslog/test_syslog.py
================================================================================= test session starts ==================================================================================platform linux2 -- Python 2.7.12, pytest-4.6.9, py-1.8.1, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
ansible: 2.8.7
rootdir: /data/sonic-mgmt/tests, inifile: pytest.ini
plugins: ansible-2.2.2
collected 1 item

syslog/test_syslog.py::test_syslog PASSED                                                                                                                                        [100%]

-------------------------------------------------------------- generated xml file: /data/sonic-mgmt/tests/results/tr.xml ---------------------------------------------------------------============================================================================== 1 passed in 91.66 seconds ===============================================================================

Logs file:

johnar@41c2d2de66d4:/data/sonic-mgmt/tests$ cat logs/syslog.log
11:23:40 DEBUG plugin.py:pytest_report_header:168: pytest_report_header() called
11:23:40 DEBUG plugin.py:pytest_generate_tests:123: pytest_generate_tests() called
11:23:40 DEBUG plugin.py:pytest_collection_modifyitems:173: pytest_collection_modifyitems() called
11:23:40 DEBUG plugin.py:pytest_collection_modifyitems:174: items: [<Function test_syslog>]
11:23:40 INFO conftest.py:pytest_runtest_setup:355: ==================== syslog/test_syslog.py::test_syslog setup ====================
11:23:40 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/common/devices.py::_get_platform_info#247: [vlab-01] AnsibleModule::command, args=["show platform summary"], kwargs={}
11:23:41 DEBUG registry.py:register_crypt_handler:294: registered 'md5_crypt' handler: <class 'passlib.handlers.md5_crypt.md5_crypt'>
11:23:43 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/common/devices.py::_get_platform_info#247: [vlab-01] AnsibleModule::command Result => {"stderr_lines": [], "cmd": ["show", "platform", "summary"], "end": "2020-07-19 11:23:43.575217", "_ansible_no_log": false, "stdout": "Platform: x86_64-kvm_x86_64-r0\nHwSKU: Force10-S6000\nASIC: vs", "changed": true, "rc": 0, "start": "2020-07-19 11:23:42.641345", "stderr": "", "delta": "0:00:00.933872", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": false, "strip_empty_ends": true, "_raw_params": "show platform summary", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["Platform: x86_64-kvm_x86_64-r0", "HwSKU: Force10-S6000", "ASIC: vs"], "ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "warnings": ["Platform linux on host vlab-01 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information."]}
11:23:43 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/common/devices.py::_get_npu_count#215: [vlab-01] AnsibleModule::shell, args=["cat /usr/share/sonic/device/x86_64-kvm_x86_64-r0/asic.conf"], kwargs={}
11:23:44 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/common/devices.py::_get_npu_count#215: [vlab-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "cat /usr/share/sonic/device/x86_64-kvm_x86_64-r0/asic.conf", "end": "2020-07-19 11:23:44.477677", "_ansible_no_log": false, "stdout": "NUM_ASIC=1", "changed": true, "rc": 0, "start": "2020-07-19 11:23:44.439658", "stderr": "", "delta": "0:00:00.038019", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "cat /usr/share/sonic/device/x86_64-kvm_x86_64-r0/asic.conf", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["NUM_ASIC=1"]}
11:23:44 DEBUG devices.py:_get_npu_count:216: [u'NUM_ASIC=1']
11:23:44 DEBUG devices.py:_get_npu_count:221: num_npu = 1
11:23:44 DEBUG devices.py:_gather_facts:205: Gathered SonicHost facts: {"platform": "x86_64-kvm_x86_64-r0", "hwsku": "Force10-S6000", "asic_type": "vs", "num_npu": 1}
11:23:44 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/common/devices.py::_get_os_version#263: [vlab-01] AnsibleModule::command, args=["sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version"], kwargs={}
11:23:45 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/common/devices.py::_get_os_version#263: [vlab-01] AnsibleModule::command Result => {"stderr_lines": [], "cmd": ["sonic-cfggen", "-y", "/etc/sonic/sonic_version.yml", "-v", "build_version"], "end": "2020-07-19 11:23:45.725391", "_ansible_no_log": false, "stdout": "master.421-d8a79bc7", "changed": true, "rc": 0, "start": "2020-07-19 11:23:45.172975", "stderr": "", "delta": "0:00:00.552416", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": false, "strip_empty_ends": true, "_raw_params": "sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["master.421-d8a79bc7"]}
11:23:45 DEBUG devices.py:critical_services:187: ['swss', 'syncd', 'database', 'teamd', 'bgp', 'pmon', 'lldp', 'snmp']
11:23:45 DEBUG devices.py:critical_services:187: ['swss', 'syncd', 'database', 'teamd', 'bgp', 'pmon', 'lldp', 'snmp']
11:23:45 INFO conftest.py:creds:338: dut vlab-01 belongs to groups [u'lab', u'sonic', 'fanout']
11:23:45 INFO conftest.py:creds:349: skip empty var file ../ansible/group_vars/all/env.yml
11:23:45 INFO conftest.py:creds:349: skip empty var file ../ansible/group_vars/all/corefile_uploader.yml
11:23:46 INFO __init__.py:sanity_check:45: Start pre-test sanity check
11:23:46 INFO __init__.py:sanity_check:81: Sanity check settings: skip_sanity=True, check_items=set(['services', 'interfaces', 'processes', 'dbmemory']), allow_recover=False, recover_method=adaptive, post_check=False
11:23:46 INFO __init__.py:sanity_check:84: Skip sanity check according to command line argument or configuration of test script.
11:23:46 INFO test_syslog.py:config_dut:29: Configuring the DUT
11:23:46 INFO test_syslog.py:config_dut:31: test_syslog_srv_ip 10.250.0.102
11:23:46 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_dut#34: [vlab-01] AnsibleModule::shell, args=["sudo config syslog add 10.250.0.102"], kwargs={}
11:23:49 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_dut#34: [vlab-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "sudo config syslog add 10.250.0.102", "end": "2020-07-19 11:23:49.923112", "_ansible_no_log": false, "stdout": "Syslog server 10.250.0.102 added to configuration\nRestarting rsyslog-config service...", "changed": true, "rc": 0, "start": "2020-07-19 11:23:46.968192", "stderr": "", "delta": "0:00:02.954920", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "sudo config syslog add 10.250.0.102", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["Syslog server 10.250.0.102 added to configuration", "Restarting rsyslog-config service..."], "warnings": ["Consider using 'become', 'become_method', and 'become_user' rather than running sudo"]}
11:23:49 INFO test_syslog.py:config_syslog_srv:10: Configuring the syslog srver
11:23:49 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#13: [ptf-01] AnsibleModule::shell, args=["sed -ni '/module/!p;$a module(load=\"imudp\")' /etc/rsyslog.conf"], kwargs={}
11:23:52 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#13: [ptf-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "sed -ni '/module/!p;$a module(load=\"imudp\")' /etc/rsyslog.conf", "end": "2020-07-19 11:23:52.580203", "_ansible_no_log": false, "stdout": "", "changed": true, "rc": 0, "start": "2020-07-19 11:23:51.953192", "stderr": "", "delta": "0:00:00.627011", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "sed -ni '/module/!p;$a module(load=\"imudp\")' /etc/rsyslog.conf", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": [], "ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "warnings": ["Consider using the replace, lineinfile or template module rather than running 'sed'.  If you need to use command because replace, lineinfile or template is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message.", "Platform linux on host ptf-01 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information."]}
11:23:52 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#14: [ptf-01] AnsibleModule::shell, args=["sed -i '/input(type/!p;$a input(type=\"imudp\" port=\"514\")' /etc/rsyslog.conf"], kwargs={}
11:23:53 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#14: [ptf-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "sed -i '/input(type/!p;$a input(type=\"imudp\" port=\"514\")' /etc/rsyslog.conf", "end": "2020-07-19 11:23:53.383276", "_ansible_no_log": false, "stdout": "", "changed": true, "rc": 0, "start": "2020-07-19 11:23:52.839928", "stderr": "", "delta": "0:00:00.543348", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "sed -i '/input(type/!p;$a input(type=\"imudp\" port=\"514\")' /etc/rsyslog.conf", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": [], "warnings": ["Consider using the replace, lineinfile or template module rather than running 'sed'.  If you need to use command because replace, lineinfile or template is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message."]}
11:23:53 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#17: [ptf-01] AnsibleModule::shell, args=["rm -rf /var/log/syslog"], kwargs={}
11:23:54 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#17: [ptf-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "rm -rf /var/log/syslog", "end": "2020-07-19 11:23:54.339813", "_ansible_no_log": false, "stdout": "", "changed": true, "rc": 0, "start": "2020-07-19 11:23:53.692833", "stderr": "", "delta": "0:00:00.646980", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "rm -rf /var/log/syslog", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": [], "warnings": ["Consider using the file module with state=absent rather than running 'rm'.  If you need to use command because file is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message."]}
11:23:54 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#20: [ptf-01] AnsibleModule::shell, args=["service rsyslog restart"], kwargs={}
11:24:36 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_syslog_srv#20: [ptf-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "service rsyslog restart", "end": "2020-07-19 11:24:36.894749", "_ansible_no_log": false, "stdout": "Stopping enhanced syslogd: rsyslogd already stopped.\nStarting enhanced syslogd: rsyslogd.", "changed": true, "rc": 0, "start": "2020-07-19 11:23:54.577190", "stderr": "", "delta": "0:00:42.317559", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "service rsyslog restart", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["Stopping enhanced syslogd: rsyslogd already stopped.", "Starting enhanced syslogd: rsyslogd."], "warnings": ["Consider using the service module rather than running 'service'.  If you need to use command because service is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message."]}
11:25:06 INFO __init__.py:loganalyzer:15: Log analyzer is disabled
11:25:06 INFO conftest.py:pytest_runtest_setup:357: ==================== syslog/test_syslog.py::test_syslog setup done ====================
11:25:06 INFO conftest.py:pytest_runtest_call:362: ==================== syslog/test_syslog.py::test_syslog call ====================
11:25:06 INFO test_syslog.py:test_syslog:42: Starting syslog tests
11:25:06 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::test_syslog#46: [vlab-01] AnsibleModule::shell, args=[" logger --priority INFO Basic Test Message"], kwargs={}
11:25:07 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::test_syslog#46: [vlab-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": " logger --priority INFO Basic Test Message", "end": "2020-07-19 11:25:07.969405", "_ansible_no_log": false, "stdout": "", "changed": true, "rc": 0, "start": "2020-07-19 11:25:07.922299", "stderr": "", "delta": "0:00:00.047106", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": " logger --priority INFO Basic Test Message", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": []}
11:25:07 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::test_syslog#49: [ptf-01] AnsibleModule::shell, args=["grep vlab-01 /var/log/syslog | grep \"Basic Test Message\" | grep -v ansible"], kwargs={}
11:25:08 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::test_syslog#49: [ptf-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "grep vlab-01 /var/log/syslog | grep \"Basic Test Message\" | grep -v ansible", "end": "2020-07-19 11:25:08.951245", "_ansible_no_log": false, "stdout": "Jul 19 11:25:07 vlab-01 INFO admin: Basic Test Message\nJul 19 11:25:07 vlab-01 INFO admin: Basic Test Message", "changed": true, "rc": 0, "start": "2020-07-19 11:25:08.426943", "stderr": "", "delta": "0:00:00.524302", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "grep vlab-01 /var/log/syslog | grep \"Basic Test Message\" | grep -v ansible", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["Jul 19 11:25:07 vlab-01 INFO admin: Basic Test Message", "Jul 19 11:25:07 vlab-01 INFO admin: Basic Test Message"]}
11:25:08 INFO conftest.py:pytest_runtest_call:364: ==================== syslog/test_syslog.py::test_syslog call done ====================
11:25:08 INFO conftest.py:pytest_runtest_teardown:369: ==================== syslog/test_syslog.py::test_syslog teardown ====================
11:25:08 DEBUG devices.py:_run:65: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_dut#39: [vlab-01] AnsibleModule::shell, args=["sudo config syslog del 10.250.0.102"], kwargs={}
11:25:12 DEBUG devices.py:_run:79: /data/sonic-mgmt/tests/syslog/test_syslog.py::config_dut#39: [vlab-01] AnsibleModule::shell Result => {"stderr_lines": [], "cmd": "sudo config syslog del 10.250.0.102", "end": "2020-07-19 11:25:12.048116", "_ansible_no_log": false, "stdout": "Syslog server 10.250.0.102 removed from configuration\nRestarting rsyslog-config service...", "changed": true, "rc": 0, "start": "2020-07-19 11:25:09.484089", "stderr": "", "delta": "0:00:02.564027", "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": true, "strip_empty_ends": true, "_raw_params": "sudo config syslog del 10.250.0.102", "removes": null, "argv": null, "creates": null, "chdir": null, "stdin_add_newline": true, "stdin": null}}, "stdout_lines": ["Syslog server 10.250.0.102 removed from configuration", "Restarting rsyslog-config service..."], "warnings": ["Consider using 'become', 'become_method', and 'become_user' rather than running sudo"]}
11:25:12 INFO conftest.py:pytest_runtest_teardown:371: ==================== syslog/test_syslog.py::test_syslog teardown done ====================

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

@arlakshm arlakshm requested a review from yxieca July 19, 2020 11:35
@lguohan
Copy link
Copy Markdown
Contributor

lguohan commented Jul 20, 2020

retest this please


@pytest.fixture(scope="module")
def config_syslog_srv(ptfhost):
logger.info( "Configuring the syslog srver")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please fix typo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit

@arlakshm arlakshm merged commit 009983d into sonic-net:master Jul 21, 2020
@arlakshm arlakshm deleted the syslog_pytest branch July 21, 2020 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants