Add analize report on one day scheduler
-one day or specific plan name
Related_prod: PRODX-41267
Change-Id: I2735584ded1791e5e829defe7d80c1958d1b689c
diff --git a/testrail_bot/control/celery_tasks/schedules_pipeline.py b/testrail_bot/control/celery_tasks/schedules_pipeline.py
index 8539357..5a87374 100644
--- a/testrail_bot/control/celery_tasks/schedules_pipeline.py
+++ b/testrail_bot/control/celery_tasks/schedules_pipeline.py
@@ -1,6 +1,7 @@
import os
import logging
from datetime import datetime, timedelta
+import subprocess
from .. import models
from . import tasks
@@ -121,3 +122,52 @@
if result.updated_at.strftime("%Y-%m-%d") < border_date:
LOG.info(f"Deleting {result=}")
result.delete()
+
+
+def task_to_analize_testrail_reports(plan_name: str):
+ """
+ Analise reports for testrail
+ on one day or plan name
+ """
+ today = datetime.today().strftime("%Y-%m-%d")
+ _plan_name = plan_name or f"[MCP2.0]OSCORE-{today}"
+
+ _url = "https://mirantis.testrail.com"
+ _email = os.environ.get("TESTRAIL_EMAIL")
+ _password = os.environ.get("TESTRAIL_PASSWORD")
+ _project_name = "'Mirantis Cloud Platform'"
+ _jira_user = os.environ.get("JIRA_USER")
+ _jira_password = os.environ.get("JIRA_PASSWORD")
+ _sumReportOptions = [
+ "--testrail-host",
+ _url,
+ "--testrail-user",
+ _email,
+ "--testrail-user-key",
+ _password,
+ "--testrail-plan",
+ _plan_name,
+ "--testrail-project",
+ _project_name,
+ "--out-type html",
+ "--push-to-testrail",
+ "--sort-by fails",
+ "--jira-host https://mirantis.jira.com/",
+ "--jira-user",
+ _jira_user,
+ "--jira-password",
+ _jira_password,
+ ]
+ _sumReportOptionsList = map(str, _sumReportOptions)
+ report_script = f"""\
+ export TESTRAIL_URL={_url};
+ export TESTRAIL_USER_EMAIL={_email};
+ export TESTRAIL_USER_KEY={_password};
+ pip install testplan_summary/.;
+ python testplan_summary/report.py \
+ create-report {" ".join(_sumReportOptionsList)}
+ """
+ p = subprocess.Popen(
+ report_script, shell=True, stdout=subprocess.PIPE
+ ).stdout.read()
+ return p
diff --git a/testrail_bot/control/celery_tasks/tasks.py b/testrail_bot/control/celery_tasks/tasks.py
index 3d090c2..dbfb37a 100644
--- a/testrail_bot/control/celery_tasks/tasks.py
+++ b/testrail_bot/control/celery_tasks/tasks.py
@@ -90,3 +90,15 @@
:return:
"""
schedules_pipeline.task_to_delete_old_2m_reports()
+
+
+@shared_task
+def analize_testrail_reports(plan_name, *args, **kwargs):
+ """
+ Finds today testplan
+ Creates TestRun with this id
+ Creates Periodic task to analyze created TestRun
+ :String plan_name
+ :return:
+ """
+ schedules_pipeline.task_to_analize_testrail_reports(plan_name)
diff --git a/testrail_bot/control/migrations/0015_alter_cronperiodictask_task_name.py b/testrail_bot/control/migrations/0015_alter_cronperiodictask_task_name.py
new file mode 100644
index 0000000..5feb92e
--- /dev/null
+++ b/testrail_bot/control/migrations/0015_alter_cronperiodictask_task_name.py
@@ -0,0 +1,43 @@
+# Generated by Django 4.2.7 on 2024-07-19 09:35
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("control", "0014_testresult_testrailreport_test_results"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="cronperiodictask",
+ name="task_name",
+ field=models.CharField(
+ choices=[
+ (
+ "control.celery_tasks.tasks.check_today_testplan",
+ "Check today testplan",
+ ),
+ (
+ "control.celery_tasks.tasks.check_specific_testplan",
+ "Check specific testplan",
+ ),
+ (
+ "control.celery_tasks.tasks.delete_old_2m_testruns",
+ "Delete previous 2-month TestRuns(for bot view)",
+ ),
+ (
+ "control.celery_tasks.tasks.delete_old_2m_reports",
+ "Delete previous 2-month Reports(for bot view)",
+ ),
+ (
+ "control.celery_tasks.tasks.analize_testrail_reports",
+ "Summary report on one day",
+ ),
+ ],
+ default="control.celery_tasks.tasks.check_today_testplan",
+ max_length=300,
+ ),
+ ),
+ ]
diff --git a/testrail_bot/control/models.py b/testrail_bot/control/models.py
index b3e84fb..eb5c7cc 100644
--- a/testrail_bot/control/models.py
+++ b/testrail_bot/control/models.py
@@ -174,6 +174,11 @@
"Delete previous 2-month Reports(for bot view)",
[],
),
+ (
+ "control.celery_tasks.tasks.analize_testrail_reports",
+ "Summary report on one day",
+ ["plan_name"],
+ ),
]
TASK_CHOICES = list(map(lambda x: x[:-1], TASKS))