Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

WIP: Remove jenkins requirement #51

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions sktm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import logging
import os
import sktm
import sktm.jenkins


def setup_parser():
Expand Down Expand Up @@ -120,9 +121,10 @@ def load_config(args):
setup_logging(args.verbose)
cfg = load_config(args)
logging.debug("cfg=%s", cfg)
jenkins_project = sktm.jenkins.Project(cfg.get("jjname"), cfg.get("jurl"),
cfg.get("jlogin"), cfg.get("jpass"))

sw = sktm.watcher(cfg.get("jurl"), cfg.get("jlogin"), cfg.get("jpass"),
cfg.get("jjname"), cfg.get("db"), cfg.get("makeopts"))
sw = sktm.watcher(jenkins_project, cfg.get("db"), cfg.get("makeopts"))

args.func(sw, cfg)
try:
Expand Down
60 changes: 21 additions & 39 deletions sktm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@
import re
import time
import sktm.db
import sktm.jenkins
import sktm.patchwork


class tresult(enum.IntEnum):
"""Test result"""
SUCCESS = 0
MERGE_FAILURE = 1
BUILD_FAILURE = 2
PUBLISH_FAILURE = 3
TEST_FAILURE = 4
BASELINE_FAILURE = 5
import sktm.misc


class jtype(enum.IntEnum):
Expand All @@ -40,28 +30,22 @@ class jtype(enum.IntEnum):

# TODO This is no longer just a watcher. Rename/refactor/describe accordingly.
class watcher(object):
def __init__(self, jenkinsurl, jenkinslogin, jenkinspassword,
jenkinsjobname, dbpath, makeopts=None):
def __init__(self, jenkins_project, dbpath, makeopts=None):
"""
Initialize a "watcher".

Args:
jenkinsurl: Jenkins instance URL.
jenkinslogin: Jenkins user name.
jenkinspassword: Jenkins user password.
jenkinsjobname: Name of the Jenkins job to trigger and watch.
jenkins_project: Interface to the Jenkins project to trigger
and watch (sktm.jenkins.Project).
dbpath: Path to the job status database file.
makeopts: Extra arguments to pass to "make" when
building.
"""
# FIXME Clarify/fix member variable names
# Database instance
self.db = sktm.db.skt_db(os.path.expanduser(dbpath))
# Jenkins interface instance
self.jk = sktm.jenkins.skt_jenkins(jenkinsurl, jenkinslogin,
jenkinspassword)
# Jenkins project name
self.jobname = jenkinsjobname
# Jenkins project interface instance
self.jk = jenkins_project
# Extra arguments to pass to "make"
self.makeopts = makeopts
# List of pending Jenkins builds, each one represented by a 3-tuple
Expand Down Expand Up @@ -156,8 +140,7 @@ def add_pw(self, baseurl, pname, lpatch=None, apikey=None):
def check_baseline(self):
"""Submit a build for baseline"""
self.pj.append((sktm.jtype.BASELINE,
self.jk.build(self.jobname,
baserepo=self.baserepo,
self.jk.build(baserepo=self.baserepo,
ref=self.baseref,
baseconfig=self.cfgurl,
makeopts=self.makeopts),
Expand Down Expand Up @@ -207,14 +190,13 @@ def check_patchwork(self):
# Submit and remember a Jenkins build for the patchset
self.pj.append((sktm.jtype.PATCHWORK,
self.jk.build(
self.jobname,
baserepo=self.baserepo,
ref=stablecommit,
baseconfig=self.cfgurl,
message_id=patchset.message_id,
subject=patchset.subject,
emails=patchset.email_addr_set,
patchwork=patchset.patch_url_list,
patch_url_list=patchset.patch_url_list,
makeopts=self.makeopts),
cpw))
logging.info("submitted message ID: %s", patchset.message_id)
Expand All @@ -224,38 +206,38 @@ def check_patchwork(self):

def check_pending(self):
for (pjt, bid, cpw) in self.pj:
if self.jk.is_build_complete(self.jobname, bid):
if self.jk.is_build_complete(bid):
logging.info("job completed: jjid=%d; type=%d", bid, pjt)
self.pj.remove((pjt, bid, cpw))
if pjt == sktm.jtype.BASELINE:
self.db.update_baseline(
self.baserepo,
self.jk.get_base_hash(self.jobname, bid),
self.jk.get_base_commitdate(self.jobname, bid),
self.jk.get_result(self.jobname, bid),
self.jk.get_base_hash(bid),
self.jk.get_base_commitdate(bid),
self.jk.get_result(bid),
bid
)
elif pjt == sktm.jtype.PATCHWORK:
patches = list()
slist = list()
series = None
bres = self.jk.get_result(self.jobname, bid)
rurl = self.jk.get_result_url(self.jobname, bid)
bres = self.jk.get_result(bid)
rurl = self.jk.get_result_url(bid)
logging.info("result=%s", bres)
logging.info("url=%s", rurl)
basehash = self.jk.get_base_hash(self.jobname, bid)
basehash = self.jk.get_base_hash(bid)
logging.info("basehash=%s", basehash)
if bres == sktm.tresult.BASELINE_FAILURE:
if bres == sktm.misc.tresult.BASELINE_FAILURE:
self.db.update_baseline(
self.baserepo,
basehash,
self.jk.get_base_commitdate(self.jobname, bid),
sktm.tresult.TEST_FAILURE,
self.jk.get_base_commitdate(bid),
sktm.misc.tresult.TEST_FAILURE,
bid
)

patchset = self.jk.get_patchwork(self.jobname, bid)
for purl in patchset:
patch_url_list = self.jk.get_patch_url_list(bid)
for purl in patch_url_list:
match = re.match(r"(.*)/patch/(\d+)$", purl)
if match:
baseurl = match.group(1)
Expand Down Expand Up @@ -284,7 +266,7 @@ def check_pending(self):
except ValueError:
pass

if bres != sktm.tresult.BASELINE_FAILURE:
if bres != sktm.misc.tresult.BASELINE_FAILURE:
self.db.commit_patchtest(self.baserepo, basehash,
patches, bres, bid, series)
else:
Expand Down
6 changes: 3 additions & 3 deletions sktm/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
import sqlite3
import time
import sktm
import sktm.misc


class skt_db(object):
Expand Down Expand Up @@ -268,7 +268,7 @@ def get_baselineresult(self, baserepo, commithash):
'ORDER BY baseline.commitdate DESC LIMIT 1',
(commithash, brid))
res = self.cur.fetchone()
return None if res is None else sktm.tresult(res[0])
return None if res is None else sktm.misc.tresult(res[0])

def get_stable(self, baserepo):
"""
Expand Down Expand Up @@ -458,7 +458,7 @@ def dump_baseline_tests(self):
for (burl, commit, res, buildid) in self.cur.fetchall():
print("repo url:", burl)
print("commit id:", commit)
print("result:", sktm.tresult(res).name)
print("result:", sktm.misc.tresult(res).name)
print("build id: #", buildid, sep='')
print("---")

Expand Down
Loading