ReportPortal diesn't like custom time in the start_time field
Also Interrupted status is not count as failed status
Sometimes suite was finished much earlier than needed
Related-Prod: PRODX-48948
Change-Id: I7424fec916b2ef0d0f34ca6bc63c2c2c9453a599
diff --git a/rp_reporter/rp_reporter/batch_reporter.py b/rp_reporter/rp_reporter/batch_reporter.py
index 23a3ce4..7a906c6 100755
--- a/rp_reporter/rp_reporter/batch_reporter.py
+++ b/rp_reporter/rp_reporter/batch_reporter.py
@@ -1,5 +1,5 @@
import click
-import logging
+
import ipdb
import itertools
import sys, os
@@ -10,19 +10,21 @@
from .report_from_xml import report_xml, timestamp
from .report_from_xml import client as rp_client
-from .settings import RP_ENDPOINT, RP_PROJECT
+import logging
+logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger(__name__)
-def upload_job(job:str, suite_per_job=False):
+def upload_job(job:str, suite_per_job=False, tags=None):
if isinstance(job, str):
job = jj.Build(job)
- print(f"│˶˙ᵕ˙˶)꜆ I take {job}")
- link = job.url
+ if not tags:
+ tags = dict()
- tags = {
- "start_time": job.start_time.strftime("%Y-%m-%d-%H-%M-%S")
- }
+ print(f"│˶˙ᵕ˙˶)꜆ I take {job}")
+
+ tags["start_time"] = job.start_time.strftime("%Y-%m-%d-%H-%M-%S")
+
if context_name:=job.param.OPENSTACK_CONTEXT_NAME:
tags["openstack"] = context_name.split("/")[0]
tags["context"] = context_name.split("/")[-1]
@@ -42,12 +44,14 @@
launch_id = None
if suite_per_job:
+ tags["jenkins_job"] = job.number
launch_id = rp_client.start_launch(
- name=f"{job.name} number: {job.number}",
+ name=job.name,
start_time=timestamp(),
attributes=tags,
- description=f"Main job {job.url}"
+ description=f"Deploy job {job.url}"
)
+ print(f"(^-^)_日 report will be here {rp_client.get_launch_ui_url()}")
for child in itertools.chain([job], job.heirs):
print(f"⫍⌕⫎ tests in {child}")
@@ -96,26 +100,29 @@
# We can iterate by child jobs which don't contain any reports
continue
report_path = test_results_files[0]
- LOG.info("=== report_xml {kwargs}".format( kwargs = dict(report_path=report_path,
- title = title,
- attributes=test_tags,
- link=link,
- to_specific_launch=launch_id)))
+ LOG.info("=== report_xml {kwargs}".format(
+ kwargs = dict(report_path=report_path,
+ title = title,
+ attributes=test_tags,
+ link=job.url,
+ to_specific_launch=launch_id))
+ )
print(f"(っ・-・)っ Uploading {report_path}")
report_xml(
report_path=report_path,
title = title,
attributes=test_tags,
- link=link,
+ link=job.url,
to_specific_launch=launch_id,
)
- if suite_per_job:
- rp_client.finish_launch(end_time=timestamp())
- LOG.info(rp_client.get_launch_info())
+ # if suite_per_job:
+ #
+ # LOG.info(rp_client.get_launch_info())
if suite_per_job:
- report_url = f"{RP_ENDPOINT.strip('/')}/ui/#{RP_PROJECT}/launches/all/{launch_id}"
+ report_url = rp_client.get_launch_ui_url()
+ rp_client.finish_launch(end_time=timestamp())
print(f"maybe report is here {report_url}")
print(f" ʕノ•ᴥ•ʔノ Completed")
@@ -146,5 +153,18 @@
"""
upload_view(view_url, pattern)
+@cli.command()
+@click.argument('report_path')
+def report_xmlfile(report_path):
+ """
+ :param report_path: Url or file location of xunit report
+ """
+ title = report_path.split("/")[-1]
+ report_xml(
+ report_path=report_path,
+ title=title,
+ )
+
+
if __name__ == '__main__':
cli()
diff --git a/rp_reporter/rp_reporter/report_from_xml.py b/rp_reporter/rp_reporter/report_from_xml.py
index f6c33c9..37fbc06 100644
--- a/rp_reporter/rp_reporter/report_from_xml.py
+++ b/rp_reporter/rp_reporter/report_from_xml.py
@@ -1,14 +1,13 @@
import os
import click
+import ipdb
import xunitparser
import logging
import pathlib
import datetime
import re
import wget
-import sys
import time
-from pathlib import Path
from reportportal_client import RPClient
from reportportal_client.helpers import timestamp
@@ -17,6 +16,14 @@
LOG = logging.getLogger(__name__)
scheduled = []
+uuid_by_subfolder = dict()
+
+client = RPClient(endpoint=RP_ENDPOINT,
+ project=RP_PROJECT,
+ api_key=RP_APIKEY,
+ is_skipped_an_issue=False,
+ truncate_attributes=False
+ )
def schedule_finishing(item):
scheduled.append(item)
@@ -28,14 +35,6 @@
end_time=timestamp()
)
-client = RPClient(endpoint=RP_ENDPOINT,
- project=RP_PROJECT,
- api_key=RP_APIKEY,
- is_skipped_an_issue=False,
- truncate_attributes=False
- )
-
-uuid_by_subfolder = dict()
def create_subfolders(list_of_subfolders:list, root_folder=None) -> str:
parent_folder = root_folder
for number, subfolder in enumerate(list_of_subfolders):
@@ -49,7 +48,12 @@
item_type="suite",
parent_item_id=parent_folder
)
- LOG.debug(f"Started suite: uuid={created_folder} for suite {subfolder} in {fullpath} ")
+ LOG.debug(f"start_test_item {subfolder=} "
+ f"item_type=suite "
+ f"name={subfolder} "
+ f"parent_item_id={parent_folder}")
+
+ LOG.info(f"Started suite: uuid={created_folder} for suite {subfolder=} in {fullpath=} with {parent_folder=}")
schedule_finishing(created_folder)
uuid_by_subfolder[fullpath] = created_folder
folder_uuid = uuid_by_subfolder.get(fullpath)
@@ -57,10 +61,12 @@
return parent_folder
def report_xml(report_path, title,
- attributes, link, to_specific_launch=None):
+ attributes=None, link=None, to_specific_launch=None):
ts: xunitparser.TestSuite
tr: xunitparser.TestResult
tc: xunitparser.TestCase
+ if not attributes:
+ attributes = dict()
# FIXME rewrite it to not use globals
global uuid_by_subfolder
uuid_by_subfolder = dict()
@@ -82,27 +88,33 @@
# start_time = datetime.datetime.fromisoformat(tr.timestamp)
# ipdb.set_trace()
# if tr.time
- start_time = int(os.stat(report_file).st_birthtime * 1000)
+ start_time = int(os.stat(report_file).st_birthtime * 1000) # to cut float part
attributes.update(ts.properties)
last_subfolder = None
if to_specific_launch:
test_suite = client.start_test_item(
name=title,
- start_time=str(start_time),
- attributes=attributes,
+ start_time=timestamp(),
+ attributes=attributes or None,
item_type="suite",
description=f"{link} \n uploaded from report {_report_path} ",
)
+ LOG.debug(f"start_test_item {test_suite=} item_type=suite name={title}")
schedule_finishing(item=test_suite)
root_folder = test_suite
else:
- client.start_launch(name=title,
- start_time=str(start_time),
- attributes=attributes,
+ launch_id = client.start_launch(name=title,
+ start_time=timestamp(),
+ attributes=attributes or None,
description=f"{link} \n uploaded from report {_report_path} "
)
+ LOG.debug(f"start_launch {launch_id=} name={title} ")
+ print(f"(^-^)_日 report will be here {client.get_launch_ui_url()}")
root_folder = None
+ if not launch_id:
+ # ipdb.set_trace()
+ raise Exception(f"Launch {title} is not published ")
LOG.info(f"Sending to RP")
@@ -160,6 +172,10 @@
description=f"{tc.classname}.{tc.methodname}",
parent_item_id=last_subfolder
)
+ LOG.debug(f"start_test_item {item_id=} "
+ f"{name=} "
+ f"{item_type=} "
+ f"parent_item_id={last_subfolder}")
if not item_id:
raise Exception(f"Failed to start test {name}")
match tc.result:
@@ -169,10 +185,8 @@
status = "SKIPPED"
case "failure":
status = "FAILED"
- met_failed = True
case "error":
- status = "INTERRUPTED"
- met_failed = True
+ status = "FAILED"
case _:
raise BaseException(f"Unknown {tc.result=} in xml")
@@ -206,6 +220,7 @@
client.finish_launch(end_time=timestamp())
LOG.info(client.get_launch_info())
+
if __name__ == "__main__":
report_path = 'https://artifactory.mcp.mirantis.net/artifactory/oscore-local/jenkins-job-artifacts/oscore-si-tests-runner-k8s/40162/si_test_report.xml'
diff --git a/rp_reporter/rp_reporter/settings.py b/rp_reporter/rp_reporter/settings.py
index d238d91..63132aa 100644
--- a/rp_reporter/rp_reporter/settings.py
+++ b/rp_reporter/rp_reporter/settings.py
@@ -3,20 +3,21 @@
from pathlib import Path
import logging
+
LOG = logging.getLogger(__name__)
RP_CONFIG_FILE = environ.get("RP_CONFIG_FILE") or (Path.home() / ".reportportal_config")
def from_conf(key_name):
if not Path(RP_CONFIG_FILE).exists():
- LOG.warning(f"Can't get {key_name} because config file "
+ LOG.info(f"Can't get {key_name} because config file "
f"not found: {RP_CONFIG_FILE}")
return None
with open(RP_CONFIG_FILE) as f:
yaml_config = yaml.safe_load(f)
value = yaml_config.get(key_name)
if value is None:
- LOG.warning(f"Can't get {key_name} because it's absent in {RP_CONFIG_FILE}")
+ LOG.info(f"Can't get {key_name} because it's absent in {RP_CONFIG_FILE}")
return value
def call_error(key_name):
diff --git a/rp_reporter/setup.py b/rp_reporter/setup.py
index abf7b6c..3bf060b 100644
--- a/rp_reporter/setup.py
+++ b/rp_reporter/setup.py
@@ -11,7 +11,7 @@
packages=find_packages(),
install_requires=[
"xunitparser",
- "reportportal-client",
+ "reportportal-client>=5.6.2",
"PyYAML",
"wget",
"jenkins-jinny @ git+https://github.com/annkapul/jenkins-jinny.git"