forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjira.py
More file actions
79 lines (60 loc) · 2.5 KB
/
jira.py
File metadata and controls
79 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import re
from functools import cache
from jira import JIRA
from kubernetes.dynamic import DynamicClient
from ocp_resources.cluster_service_version import ClusterServiceVersion
from ocp_resources.exceptions import MissingResourceError
from packaging.version import Version
from pytest_testconfig import config as py_config
from simple_logger.logger import get_logger
LOGGER = get_logger(name=__name__)
@cache
def get_jira_connection() -> JIRA:
"""
Get Jira connection.
Returns:
JIRA: Jira connection.
"""
return JIRA(
server=os.getenv("PYTEST_JIRA_URL"),
basic_auth=(os.getenv("PYTEST_JIRA_USERNAME"), os.getenv("PYTEST_JIRA_PASSWORD")),
)
def is_jira_open(jira_id: str, admin_client: DynamicClient) -> bool:
"""
Check if Jira issue is open.
Args:
jira_id (str): Jira issue id.
admin_client (DynamicClient): DynamicClient object
Returns:
bool: True if Jira issue is open.
"""
jira_fields = get_jira_connection().issue(id=jira_id, fields="status, fixVersions").fields
jira_status = jira_fields.status.name.lower()
if jira_status not in ("testing", "resolved", "closed"):
LOGGER.info(f"Jira {jira_id}: status is {jira_status}")
return True
else:
# Check if the operator version in ClusterServiceVersion is greater than the jira fix version
jira_fix_versions: list[Version] = [
Version(_fix_version.group())
for fix_version in jira_fields.fixVersions
if (_fix_version := re.search(r"\d+\.\d+(?:\.\d+)?", fix_version.name))
]
if not jira_fix_versions:
raise ValueError(f"Jira {jira_id}: status is {jira_status} but does not have fix version(s)")
operator_version: str = ""
for csv in ClusterServiceVersion.get(client=admin_client, namespace=py_config["applications_namespace"]):
if re.match("rhods|opendatahub", csv.name):
operator_version = csv.instance.spec.version
break
if not operator_version:
raise MissingResourceError("Operator ClusterServiceVersion not found")
csv_version = Version(version=operator_version)
if all(csv_version < fix_version for fix_version in jira_fix_versions):
LOGGER.info(
f"Bug is open: Jira {jira_id}: status is {jira_status}, "
f"fix versions {jira_fix_versions}, operator version is {operator_version}"
)
return True
return False