Skip to content

Commit a54746d

Browse files
authored
Merge pull request #88 from stfc/Ci_cd_rally
CI + CD For Rally
2 parents 3787bb5 + 941006c commit a54746d

File tree

7 files changed

+170
-119
lines changed

7 files changed

+170
-119
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Openstack-Rally-Tester
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
paths:
9+
- ".github/workflows/Openstack-Rally-Tester.yaml"
10+
- "OpenStack-Rally-Tester/**"
11+
12+
jobs:
13+
pylint:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ["3.10"]
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
cache: "pip"
25+
- name: Install dependencies
26+
run: |
27+
cd OpenStack-Rally-Tester && python -m pip install -r requirements.txt
28+
python -m pip install pylint
29+
30+
- name: Analyse with pylint
31+
run: |
32+
cd OpenStack-Rally-Tester/usr/local/bin && pylint rally_extract_results.py
33+
34+
shellcheck:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- name: Run ShellCheck
39+
uses: ludeeus/action-shellcheck@master
40+
with:
41+
scandir: "./OpenStack-Rally-Tester"

.github/workflows/black.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ jobs:
3131
uses: psf/black@stable
3232
with:
3333
src: "dns_entry_checker"
34+
35+
- name: Openstack-Rally-Tester
36+
uses: psf/black@stable
37+
with:
38+
src: "OpenStack-Rally-Tester"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

OpenStack-Rally-Tester/usr/local/bin/rally-extract-results

Lines changed: 0 additions & 95 deletions
This file was deleted.

OpenStack-Rally-Tester/usr/local/bin/rally-run-test

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
rally_test=$1
7+
8+
echo "This may take some time..."
9+
rally_results_cmd=$(rally task start "$rally_test" | grep "rally task report" | grep "json" | sed 's/output.json//g')
10+
echo "$rally_results_cmd"
11+
12+
rally_task_id=$(echo "$rally_results_cmd" | cut -d" " -f 4)
13+
rally_results_path="/tmp/results/$rally_task_id"
14+
15+
if [[ $rally_results_cmd == *'task'* ]]
16+
then
17+
echo "$rally_task_id"
18+
mkdir -p /tmp/results
19+
echo "$rally_results_path"
20+
rally task results "$rally_task_id" > "$rally_results_path";
21+
else
22+
echo "$rally_results_path"
23+
fi
24+
25+
echo "$rally_results_path"
26+
rally_extract_command="/usr/local/bin/rally_extract_results.py $rally_results_path"
27+
echo "$rally_extract_command"
28+
"$rally_extract_command"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/python3
2+
"""
3+
Parses results from the rally task report and sends them to influxdb
4+
"""
5+
import json
6+
import sys
7+
import time
8+
from configparser import ConfigParser
9+
10+
import requests
11+
12+
# Read from config file
13+
parser = ConfigParser()
14+
parser.read("/etc/openstack-utils/rally-tester.conf")
15+
host = parser.get("db", "host")
16+
database = parser.get("db", "database")
17+
username = parser.get("auth", "username")
18+
password = parser.get("auth", "password")
19+
instance = parser.get("cloud", "instance")
20+
21+
url = "http://" + host + "/write?db=" + database
22+
23+
nowtime = time.localtime()
24+
25+
workhours = 9 <= nowtime.tm_hour <= 16
26+
27+
with open(sys.argv[1], encoding="utf-8") as data_file:
28+
data = json.load(data_file)
29+
30+
# pylint: disable=invalid-name
31+
datastring = ""
32+
metrics = []
33+
34+
if isinstance(data, dict):
35+
print(data)
36+
for key in data.keys():
37+
metric = {}
38+
metric["fields"] = {}
39+
metric["measurement"] = key
40+
metric["fields"]["success"] = 0
41+
metrics.append(metric)
42+
else:
43+
for test in data:
44+
for result in test["result"]:
45+
metric = {}
46+
metric["fields"] = {}
47+
metric["measurement"] = test["key"]["name"]
48+
49+
metric["fields"]["success"] = 1
50+
for sla in test["sla"]:
51+
if not sla["success"]:
52+
metric["fields"]["success"] = 0
53+
54+
metric["fields"]["duration"] = result["duration"]
55+
# metrics.append(metric)
56+
for atomic_action in result["atomic_actions"]:
57+
metric["fields"][atomic_action] = result["atomic_actions"][
58+
atomic_action
59+
]
60+
61+
metric["fields"]["timestamp"] = result["timestamp"]
62+
63+
if test["key"]["name"] == "VMTasks.boot_runcommand_delete":
64+
metric["fields"]["image"] = (
65+
'"' + test["key"]["kw"]["args"]["image"]["name"] + '"'
66+
)
67+
metric["fields"]["network"] = (
68+
'"' + test["key"]["kw"]["args"]["fixednetwork"] + '"'
69+
)
70+
71+
metrics.append(metric)
72+
73+
json_metrics = []
74+
for metric in metrics:
75+
# print metric
76+
metric["tags"] = {"instance": instance}
77+
json_metrics.append(metric)
78+
for field in metric["fields"]:
79+
datastring += (
80+
metric["measurement"].replace(".", "-")
81+
+ ",instance="
82+
+ metric["tags"]["instance"]
83+
+ ",workhours="
84+
+ str(workhours)
85+
)
86+
datastring += " " + field.replace(".", "-") + "=" + str(metric["fields"][field])
87+
datastring += "\n"
88+
89+
print(json.dumps(json_metrics, indent=4, sort_keys=True))
90+
91+
print(datastring)
92+
93+
r = requests.post(url, data=datastring, auth=(username, password), timeout=10)
94+
print(r.text)
95+
print(r)

0 commit comments

Comments
 (0)