Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions kcidev/subcommands/bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import toml
from git import Repo

from kcidev.libs.common import *

"""
To not lose the state of the bisection, we need to store the state in a file
The state file is a json file that contains the following keys:
Expand Down Expand Up @@ -76,13 +78,13 @@ def git_exec_getcommit(cmd):
click.secho("Executing git command: " + " ".join(cmd), fg="green")
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
click.secho("git command return failed. Error:", fg="red")
click.secho(result.stderr, fg="red")
click.secho(result.stdout, fg="red")
kci_err("git command return failed. Error:")
kci_err(result.stderr)
kci_err(result.stdout)
sys.exit(1)
lines = result.stdout.split(b"\n")
if len(lines) < 2:
click.secho(f"git command answer length failed: {lines}", fg="red")
kci_err(f"git command answer length failed: {lines}")
sys.exit(1)
# is it last bisect?: "is the first bad commit"
if "is the first bad commit" in str(lines[1]):
Expand All @@ -91,7 +93,7 @@ def git_exec_getcommit(cmd):
sys.exit(0)
re_commit = re.search(r"\[([a-f0-9]+)\]", str(lines[1]))
if not re_commit:
click.secho(f"git command regex failed: {lines}", fg="red")
kci_err(f"git command regex failed: {lines}")
sys.exit(1)
return re_commit.group(1)

Expand All @@ -110,7 +112,7 @@ def kcidev_exec(cmd):
click.echo(line, nl=False)
process.wait()
except Exception as e:
click.secho(f"Error executing kci-dev: {e}", fg="red")
kci_err(f"Error executing kci-dev: {e}")
sys.exit(1)

return process
Expand All @@ -122,11 +124,11 @@ def init_bisect(state):
click.secho("init bisect", fg="green")
r = os.system("git bisect start")
if r != 0:
click.secho("git bisect start failed", fg="red")
kci_err("git bisect start failed")
sys.exit(1)
r = os.system("git bisect good " + state["good"])
if r != 0:
click.secho("git bisect good failed", fg="red")
kci_err("git bisect good failed")
sys.exit(1)
# result = subprocess.run(['ls', '-l'], stdout=subprocess.PIPE)
cmd = ["git", "bisect", "bad", state["bad"]]
Expand Down Expand Up @@ -181,7 +183,7 @@ def bisection_loop(state):
try:
testret = result.returncode
except Exception as e:
click.secho(f"Error executing kci-dev, no returncode: {e}", fg="red")
kci_err(f"Error executing kci-dev, no returncode: {e}")
sys.exit
if testret == 0:
bisect_result = "good"
Expand All @@ -192,13 +194,13 @@ def bisection_loop(state):
# TBD: Retry failed test to make sure it is not a flaky test
bisect_result = "skip"
else:
click.secho("Maestro failed to execute the test", fg="red")
kci_err("Maestro failed to execute the test")
# Internal maestro error, retry procesure
return None
cmd = ["git", "bisect", bisect_result]
commitid = git_exec_getcommit(cmd)
if not commitid:
click.secho("git bisect failed, commit return is empty", fg="red")
kci_err("git bisect failed, commit return is empty")
sys.exit(1)
state["history"].append({commit: bisect_result})
state["next_commit"] = commitid
Expand Down Expand Up @@ -244,25 +246,25 @@ def bisect(
if state is None or ignorestate:
state = default_state
if not giturl:
click.secho("--giturl is required", fg="red")
kci_err("--giturl is required")
return
if not branch:
click.secho("--branch is required", fg="red")
kci_err("--branch is required")
return
if not good:
click.secho("--good is required", fg="red")
kci_err("--good is required")
return
if not bad:
click.secho("--bad is required", fg="red")
kci_err("--bad is required")
return
if not job_filter:
click.secho("--job_filter is required", fg="red")
kci_err("--job-filter is required")
return
if not platform_filter:
click.secho("--platform_filter is required", fg="red")
kci_err("--platform-filter is required")
return
if not test:
click.secho("--test is required", fg="red")
kci_err("--test is required")
return

state["giturl"] = giturl
Expand Down
27 changes: 11 additions & 16 deletions kcidev/subcommands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def api_connection(host):


def display_api_error(response):
click.secho(f"API response error code: {response.status_code}", fg="red")
kci_err(f"API response error code: {response.status_code}")
try:
click.secho(response.json(), fg="red")
kci_err(response.json())
except json.decoder.JSONDecodeError:
click.secho(f"No JSON response. Plain text: {response.text}", fg="yellow")
except Exception as e:
click.secho(f"API response error: {e}: {response.text}", fg="red")
kci_err(f"API response error: {e}: {response.text}")
return


Expand All @@ -50,7 +50,7 @@ def send_checkout_full(baseurl, token, **kwargs):
try:
response = requests.post(url, headers=headers, data=jdata, timeout=30)
except requests.exceptions.RequestException as e:
click.secho(f"API connection error: {e}", fg="red")
kci_err(f"API connection error: {e}")
return

if response.status_code != 200:
Expand Down Expand Up @@ -148,10 +148,7 @@ def watch_jobs(baseurl, token, treeid, job_filter, test):
# if test is same as job, dont indicate infra-failure if test job fail
if test and test != node["name"]:
# if we have a test, and prior job failed, we should indicate that
click.secho(
f"Job {node['name']} failed, test can't be executed",
fg="red",
)
kci_err(f"Job {node['name']} failed, test can't be executed")
sys.exit(2)
nodeid = node.get("id")
click.secho(
Expand All @@ -175,7 +172,7 @@ def watch_jobs(baseurl, token, treeid, job_filter, test):
sys.exit(0)
elif test_result:
# ignore null, that means result not ready yet
click.secho(f"Test {test} failed: {test_result}", fg="red")
kci_err(f"Test {test} failed: {test_result}")
sys.exit(1)

click.echo(f"\rRefresh in 30s...", nl=False)
Expand Down Expand Up @@ -250,23 +247,21 @@ def checkout(
job_filter = None
click.secho("No job filter defined. All jobs will be triggered!", fg="yellow")
if watch and not job_filter:
click.secho("No job filter defined. Can't watch for a job(s)!", fg="red")
kci_err("No job filter defined. Can't watch for a job(s)!")
return
if test and not watch:
click.secho("Test option only works with watch option", fg="red")
kci_err("Test option only works with watch option")
return
if not commit and not tipoftree:
click.secho("No commit or tree/branch latest commit defined", fg="red")
kci_err("No commit or tree/branch latest commit defined")
return
if tipoftree:
click.secho(
f"Retrieving latest commit on tree: {giturl} branch: {branch}", fg="green"
)
commit = retrieve_tot_commit(giturl, branch)
if not commit or len(commit) != 40:
click.secho(
"Unable to retrieve latest commit. Wrong tree/branch?", fg="red"
)
kci_err("Unable to retrieve latest commit. Wrong tree/branch?")
return
click.secho(f"Commit to checkout: {commit}", fg="green")
resp = send_checkout_full(
Expand All @@ -286,7 +281,7 @@ def checkout(
node = resp.get("node")
treeid = node.get("treeid")
if not treeid:
click.secho("No treeid returned. Can't watch for a job(s)!", fg="red")
kci_err("No treeid returned. Can't watch for a job(s)!")
return
click.secho(f"Watching for jobs on treeid: {treeid}", fg="green")
if test:
Expand Down
10 changes: 6 additions & 4 deletions kcidev/subcommands/maestro_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import toml
from git import Repo

from kcidev.libs.common import *


def api_connection(host):
click.secho("api connect: " + host, fg="green")
Expand Down Expand Up @@ -38,10 +40,10 @@ def get_node(url, nodeid, field):
try:
response.raise_for_status()
except requests.exceptions.HTTPError as ex:
click.secho(ex.response.json().get("detail"), fg="red")
kci_err(ex.response.json().get("detail"))
return None
except Exception as ex:
click.secho(ex, fg="red")
kci_err(ex)
return None
print_nodes(response.json(), field)

Expand All @@ -62,10 +64,10 @@ def get_nodes(url, limit, offset, filter, field):
try:
response.raise_for_status()
except requests.exceptions.HTTPError as ex:
click.secho(ex.response.json().get("detail"), fg="red")
kci_err(ex.response.json().get("detail"))
return None
except Exception as ex:
click.secho(ex, fg="red")
kci_err(ex)
return None

nodes = response.json()
Expand Down
6 changes: 3 additions & 3 deletions kcidev/subcommands/testretry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def api_connection(host):


def display_api_error(response):
click.secho(f"API response error code: {response.status_code}", fg="red")
kci_err(f"API response error code: {response.status_code}")
try:
click.secho(response.json(), fg="red")
kci_err(response.json())
except json.decoder.JSONDecodeError:
click.secho(f"No JSON response. Plain text: {response.text}", fg="yellow")
return
Expand All @@ -35,7 +35,7 @@ def send_jobretry(baseurl, jobid, token):
try:
response = requests.post(url, headers=headers, data=jdata)
except requests.exceptions.RequestException as e:
click.secho(f"API connection error: {e}", fg="red")
kci_err(f"API connection error: {e}")
return

if response.status_code != 200:
Expand Down
Loading