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

[Tests]: Add extra options to the test runner #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import os.path
import re
import time
import docker
Expand All @@ -9,6 +10,10 @@
def pytest_addoption(parser):
parser.addoption("--dvsname", action="store", default=None,
help="dvs name")
parser.addoption("--get_logs", action="store_true",
default=False, help="Get log files from the dvs test container")
parser.addoption("--orchagent_loglevel", action="store", default="NOTICE",
help="Log level for orchagent")

class AsicDbValidator(object):
def __init__(self, dvs):
Expand Down Expand Up @@ -206,9 +211,28 @@ def init_asicdb_validator(self):
def runcmd(self, cmd):
return self.ctn.exec_run(cmd)

def get_file(self, docker_path, local_filename):
output = self.ctn.exec_run("cat %s" % docker_path)
with open(local_filename, "w") as fp:
fp.write(output)

@pytest.yield_fixture(scope="module")
def dvs(request):
name = request.config.getoption("--dvsname")
get_logs = request.config.getoption("--get_logs")
orch_log_level = request.config.getoption("--orchagent_loglevel")

dvs = DockerVirtualSwitch(name)
dvs.ctn.exec_run("swssloglevel -l %s -c orchagent" % orch_log_level)

yield dvs

if get_logs:
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 getting all logs. Usually, when you done with an appdb input, you just want to get new logs. I think we need to provide api to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "new logs"? Do you mean we want to see only logs which were created during a test?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean new log entries generated after you run certain commands.

path = "logs_%s/" % request.node.name
if not os.path.exists(path):
os.makedirs(path)
dvs.get_file("/var/log/syslog", "%s/syslog" % path)
dvs.get_file("/var/log/swss/sairedis.rec", "%s/sairedis.rec" % path)
dvs.get_file("/var/log/swss/swss.rec", "%s/swss.rec" % path)

dvs.destroy()