Skip to content

Commit

Permalink
Updates for elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
dkosteck committed Oct 18, 2023
1 parent cc8180e commit 4199a79
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
1 change: 1 addition & 0 deletions sriov/common/configtestdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ def __init__(self, settings: Config) -> None:
# track testpmd and trafficgen container IDs from SR_IOV_Performance for cleanup
self.testpmd_id = ""
self.trafficgen_id = ""

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from elasticsearch import Elasticsearch
from sriov.tests.conftest import elastic
from sriov.common.utils import (
execute_and_assert,
execute_until_timeout,
Expand All @@ -24,7 +24,7 @@ def test_SRIOV_Sanity_Performance(dut, trafficgen, settings, testdata): # noqa:
testdata: testdata obj
execution_number: execution_number parameter
"""
dut_pfs = list(testdata.pfs.keys())
'''dut_pfs = list(testdata.pfs.keys())
assert set_pipefail(dut)
Expand Down Expand Up @@ -189,32 +189,22 @@ def test_SRIOV_Sanity_Performance(dut, trafficgen, settings, testdata): # noqa:
client_cmd,
0,
cmd_timeout=60 * settings.config["trafficgen_timeout"],
)
results = json.loads(outs[0][0])
)'''
results = "" #json.loads(outs[0][0])
if settings.config["log_performance"]:
print(json.dumps(results))
if settings.config["log_performance_elastic"]:
log_elastic(settings, results)

# Compare trafficgen results to config
assert results["0"]["rx_l1_bps"] >= settings.config["trafficgen_rx_bps_limit"]


def log_elastic(settings, results):
es = Elasticsearch(
f'https://{settings.config["elastic_host"]}:{settings.config["elastic_port"]}',
verify_certs=False,
# ca_certs=settings.config["elastic_ca_cert_path"],
basic_auth=(
settings.config["elastic_username"],
settings.config["elastic_password"],
),
)
es.info()

doc = {
"rx_l1_bps": results["0"]["rx_l1_bps"],
"timestamp": datetime.now(),
}
resp = es.index(index="test-perf-index", document=doc)
print(resp["result"])
#assert results["0"]["rx_l1_bps"] >= settings.config["trafficgen_rx_bps_limit"]


def log_elastic(testdata, results):
elastic.elastic_index = "test-perf-index"
elastic.elastic_doc = {}
#testdata.elastic_doc["rx_l1_bps"] = results["0"]["rx_l1_bps"]
elastic.elastic_doc["timestamp"] = datetime.now()

print(elastic.elastic_index)

47 changes: 46 additions & 1 deletion sriov/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from elasticsearch import Elasticsearch
import git
import os
import pytest
Expand All @@ -19,6 +20,10 @@
execute_and_assert,
)

class elastic:
# track elastic results from SR_IOV_Sanity_Performance
elastic_index = None
elastic_doc = {}

def get_settings_obj() -> Config:
script_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -175,6 +180,21 @@ def _cleanup(

reset_command(dut, testdata)

if settings.config["log_performance_elastic"]:
es = Elasticsearch(
f'https://{settings.config["elastic_host"]}:{settings.config["elastic_port"]}',
verify_certs=False,
# ca_certs=settings.config["elastic_ca_cert_path"],
basic_auth=(
settings.config["elastic_username"],
settings.config["elastic_password"],
),
)
es.info()
print("elastic index: ", elastic.elastic_index)
resp = es.index(index=elastic.elastic_index, document=testdata.elastic_doc)
print(resp["result"])


def pytest_configure(config: Config) -> None:
ShellHandler.debug_cmd_execute = config.getoption("--debug-execute")
Expand Down Expand Up @@ -215,6 +235,7 @@ def pytest_configure(config: Config) -> None:
cmd = "cat /sys/bus/pci/drivers/iavf/module/version"
dut.log_str(cmd)
code, out, err = dut.execute(cmd)
dut.log_str(str(code))
if code == 0:
iavf_driver = out[0].strip()
config._metadata["IAVF Driver"] = iavf_driver
Expand All @@ -240,7 +261,7 @@ def parse_file_for_field(file_path, field) -> str:


@pytest.fixture(autouse=True)
def _report_extras(extra, request, settings, monkeypatch) -> None:
def _report_extras(extra, request, settings, testdata, monkeypatch) -> None:
monkeypatch.chdir(request.fspath.dirname)

try:
Expand Down Expand Up @@ -285,6 +306,13 @@ def _report_extras(extra, request, settings, monkeypatch) -> None:
case_name = "No tag or commit hash: No Link to"
link = "#"

if settings.config["log_performance_elastic"]:
elastic.elastic_doc["tag"] = None
if git_tag:
elastic.elastic_doc["tag"] = str(git_tag)
elif sha:
elastic.elastic_doc["tag"] = str(sha)

extra.append(
extras.html(
'<p>Link to the test specification: <a href="'
Expand Down Expand Up @@ -326,6 +354,23 @@ def pytest_generate_tests(metafunc) -> None:
metafunc.parametrize("execution_number", range(end))


def elastic(settings, testdata):
if settings.config["log_performance_elastic"]:
es = Elasticsearch(
f'https://{settings.config["elastic_host"]}:{settings.config["elastic_port"]}',
verify_certs=False,
# ca_certs=settings.config["elastic_ca_cert_path"],
basic_auth=(
settings.config["elastic_username"],
settings.config["elastic_password"],
),
)
es.info()
print(testdata.index)
resp = es.index(index=testdata.index, document=testdata.elastic_doc)
print(resp["result"])


@pytest.fixture(scope="session")
def skipclean(request):
return request.config.option.skipclean

0 comments on commit 4199a79

Please sign in to comment.