Skip to content

Commit

Permalink
add url to api and set JENKINS_SERVER from the the environment variable
Browse files Browse the repository at this point in the history
Signed-off-by: analog <kimchesed.paller@analog.com>
  • Loading branch information
kimpaller committed Feb 8, 2024
1 parent 3d1b06a commit 3f71cfa
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
RUN git clone https://github.com/sdgtt/telemetry.git
RUN cd telemetry && pip install -r requirements.txt && python setup.py install && cd ..
RUN cd telemetry && pip install -r requirements.txt && pip install . && cd ..
RUN chmod u+x ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
EXPOSE 5000
9 changes: 5 additions & 4 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.pages.hwtests import allboards as ab
from app.pages.publicci.dashboard import Dashboard
from app.pages.pyadi.plots import gen_line_plot_html
from app.utility import artifact_url_gen, filter_gen, url_gen
from app.utility import artifact_url_gen, filter_gen, url_gen, result_json_url, append_url_to_dict
from flask import (
Blueprint,
Flask,
Expand All @@ -20,13 +20,14 @@
url_for,
)
from flask.helpers import get_root_path
import os

# from junit2htmlreport import parser

# app = Flask(__name__)
server_bp = Blueprint("constellation", __name__)

JENKINS_SERVER = "gateway.englab"
JENKINS_SERVER = "jenkinsci" if "JENKINS_SERVER" not in os.environ else os.environ["JENKINS_SERVER"]
JENKINS_PORT = None

pci_dash = Dashboard(
Expand Down Expand Up @@ -77,7 +78,7 @@ def api(param=None):
else:
kwargs.update({f: el})
result_json = DB().search(size=size, order=order, agg_field=agg_field, **kwargs)
return result_json
return result_json_url(result_json, jenkins_url=JENKINS_SERVER)


@server_bp.route("api/board/<board_name>/")
Expand All @@ -96,7 +97,7 @@ def board_api(board_name, param=None):
for k, v in boot_test.items():
if k not in ["boot_test_failure", "raw_boot_test_result"]:
new_dict.update({k: v})
boot_test_filtered.append(new_dict)
boot_test_filtered.append(append_url_to_dict(new_dict, jenkins_url=JENKINS_SERVER))
return {"hits": boot_test_filtered}


Expand Down
53 changes: 53 additions & 0 deletions app/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,56 @@ def filter_gen(query):
field_value = field.split("=")[1]
filter_dict.update({field_name: field_value.split(",")})
return filter_dict

def append_url_to_dict(
boot_test_dict,
jenkins_url="locahost",
jenkins_port=None,
jenkins_base_path="/jenkins"
):
# print(boot_test_dict)
url_dict = url_gen(
jenkins_server=jenkins_url,
jenkins_port=jenkins_port,
jenkins_base_path=jenkins_base_path,
project_name=boot_test_dict["jenkins_project_name"],
build_number=boot_test_dict["jenkins_build_number"],
board=boot_test_dict["boot_folder_name"],
hdl_commit=boot_test_dict["hdl_hash"].split()[0],
linux_commit=boot_test_dict["linux_hash"].split()[0],
trigger=boot_test_dict["jenkins_trigger"],
)
artifacts_url_dict = artifact_url_gen(
jenkins_server=jenkins_url,
jenkins_port=jenkins_port,
project_name=boot_test_dict["jenkins_project_name"],
build_number=boot_test_dict["jenkins_build_number"],
board=boot_test_dict["boot_folder_name"],
jenkins_base_path=jenkins_base_path,
)
url_dict.update(artifacts_url_dict)
for field, url_value in url_dict.items():
boot_test_dict.update(
{
field.lower().replace(" ", "_") + "_url": url_value
}
)
return boot_test_dict

def result_json_url(
result_json,
jenkins_url="locahost",
jenkins_port=None,
jenkins_base_path="/jenkins"
):
new_result_json = {}
for k,v in result_json.items():
if k in ["hits"]:
new_v = []
for el in v:
new_el = append_url_to_dict(el, jenkins_url, jenkins_port, jenkins_base_path)
new_v.append(new_el)
new_result_json[k] = new_v
else:
new_result_json[k] = v
return new_result_json

0 comments on commit 3f71cfa

Please sign in to comment.