prserv: add support for an "upstream" server
v4 cover prserv: add support for an "upstream" server
From: Michael Opdenacker <[email protected]>
This makes it possible to customize an "upstream" distribution by modifying local packages. If the "upstream" package bears revision "x", the local one will have revision "x.y", this having priority over the upstream one.
Multiple levels of upstream servers are supported, so "x.y.z" revisions are possible too.
This also includes BitBake selftests to check the expected functionality and detect future regressions.
Note that database import and export functions aren't tested yet.
---
Changes in V4:
- Add BitBake selftests for the legacy and new PR server features
(database, client, server, support for upstream server, read-only mode, "history" and "no history" modes) To run only these tests:
bitbake-selftest prserv.tests
- Pass the "history" mode through the client requests, instead of storing it (globally) in the database name.
The PR database is now called "PRMAIN" instead of "PRMAIN_nohist". This should cause a regression for builds which already have a PR database.
- Fixes for "history" modes:
- Allow to store multiple PR values for the same checksum, needed for the "no history" mode.
- Make the "history" mode return the minimum stored PR value.
- Fixes and code reorganization for issues uncovered by the tests.
- Update the server version to "2.0.0"
Changes in V3:
- Revert the commit removing the so far unused "hist" mode, which we wish to keep for binary reproducibility sake.
- Simplification of get_value() function to take both "hist" and "nohist" modes with the same shared code.
- Add "history" parameter to the "getPR" request, so that the client can ask for the mode of its choice. This will also make it possible to implement tests for both modes.
Note that more requests ("export", "import"...) will also need a "history" parameter, in a future version, after the first tests are implemented.
- Several bug fixes.
- Put all the new features at the tip of the branch, to make the cleanup commits easier to merged.
Changes in V2:
- Add this new commit:
prserv: remove unused "hist" mode in the database backend
- Squash commit "prserv: fix read_only test" into commit "prserv: simplify the PRServerClient() interface" (Reported by Richard Purdie)
- Fix the code to support increasing "x.y.z" values, thus supporting several levels of upstream servers.
- db.py: remove duplicate definition of find_max_value() function in db.py
- prserv.py: remove tabs before comments (Python didn't complain)
- db.py: now stores the revision ("value") as TEXT. This way we can store "1.0" without having it transformed to "1" when the default type was INTEGER.
- This allows to fix a regression when the first packages were created with 'r0.1' instead of 'r0.0' initially.
- find_max_value: now returns None instead of '0' when no value is found Before we couldn't tell the difference between a '0'
max value and the absence of such a value.
Michael Opdenacker (5):
prserv: declare "max_package_pr" client hook
prserv: move code from __init__ to bitbake-prserv
prserv: add "upstream" server support
prserv: sync the database after each change
prserv: add bitbake selftests
bin/bitbake-prserv | 26 ++- bin/bitbake-selftest | 2 + lib/prserv/__init__.py | 87 ++++++++-- lib/prserv/client.py | 19 +- lib/prserv/db.py | 194 ++++++++++----------- lib/prserv/serv.py | 137 ++++++++++++--- lib/prserv/tests.py | 381 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 703 insertions(+), 143 deletions(-) create mode 100644 bitbake/lib/prserv/tests.py
Signature · 1 line
2.34.1
PATCH v4 1/5 prserv: declare "max_package_pr" client hook
From: Michael Opdenacker <[email protected]>
Add missing declaration for the max_package_pr client hook
--- lib/prserv/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/prserv/client.py +1 -1
@@ -65,7 +65,7 @@ class PRAsyncClient(bb.asyncrpc.AsyncClient): class PRClient(bb.asyncrpc.Client): def __init__(self): super().__init__() - self._add_methods("getPR", "test_pr", "test_package", "importone", "export", "is_readonly") + self._add_methods("getPR", "test_pr", "test_package", "max_package_pr", "importone", "export", "is_readonly") def _get_async_client(self): return PRAsyncClient()
Signature · 1 line
2.34.1
PATCH v4 2/5 prserv: move code from __init__ to bitbake-prserv
In reply to [email protected]From: Michael Opdenacker <[email protected]>
This script was the only user of this code.
--- bin/bitbake-prserv | 9 ++++++++- lib/prserv/__init__.py | 13 ------------- 2 files changed, 8 insertions(+), 14 deletions(-)
bin/bitbake-prserv +8 -1
@@ -21,6 +21,13 @@ VERSION = "1.1.0" PRHOST_DEFAULT="0.0.0.0" PRPORT_DEFAULT=8585 +def init_logger(logfile, loglevel): + numeric_level = getattr(logging, loglevel.upper(), None) + if not isinstance(numeric_level, int): + raise ValueError("Invalid log level: %s" % loglevel) + FORMAT = "%(asctime)-15s %(message)s" + logging.basicConfig(level=numeric_level, filename=logfile, format=FORMAT) + def main(): parser = argparse.ArgumentParser( description="BitBake PR Server. Version=%s" % VERSION,
@@ -72,7 +79,7 @@ def main(): ) args = parser.parse_args() - prserv.init_logger(os.path.abspath(args.log), args.loglevel) + init_logger(os.path.abspath(args.log), args.loglevel) if args.start: ret=prserv.serv.start_daemon(args.file, args.host, args.port, os.path.abspath(args.log), args.read_only)
lib/prserv/__init__.py +0 -13
@@ -5,16 +5,3 @@ # __version__ = "1.0.0" - -import os, time -import sys, logging - -def init_logger(logfile, loglevel): - numeric_level = getattr(logging, loglevel.upper(), None) - if not isinstance(numeric_level, int): - raise ValueError("Invalid log level: %s" % loglevel) - FORMAT = "%(asctime)-15s %(message)s" - logging.basicConfig(level=numeric_level, filename=logfile, format=FORMAT) - -class NotFoundError(Exception): - pass
Signature · 1 line
2.34.1
PATCH v4 3/5 prserv: add "upstream" server support
In reply to [email protected]From: Michael Opdenacker <[email protected]>
Introduce a PRSERVER_UPSTREAM variable that makes the local PR server connect to an "upstream" one.
This makes it possible to implement local fixes to an upstream package (revision "x", in a way that gives the local update priority (revision "x.y").
Update the calculation of the new revisions to support the case when prior revisions are not integers, but have an "x.y..." format."
Set the comments in the handle_get_pr() function in serv.py for details about the calculation of the local revision.
This is done by going on supporting the "history" mode that wasn't used so far (revisions can return to a previous historical value), in addition to the default "no history" mode (revisions can never decrease).
Rather than storing the history mode in the database table itself (i.e. "PRMAIN_hist" and "PRMAIN_nohist"), the history mode is now passed through the client requests. As a consequence, the table name is now "PRMAIN", which is incompatible with what was generated before, but avoids confusion if we kept the "PRMAIN_nohist" name for both "history" and "no history" modes.
Update the server version to "2.0.0".
--- bin/bitbake-prserv | 17 +++- lib/prserv/__init__.py | 80 +++++++++++++++++- lib/prserv/client.py | 17 ++-- lib/prserv/db.py | 183 ++++++++++++++++++++--------------------- lib/prserv/serv.py | 134 ++++++++++++++++++++++++++---- 5 files changed, 311 insertions(+), 120 deletions(-)
bin/bitbake-prserv +15 -2
@@ -16,7 +16,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "lib import prserv import prserv.serv -VERSION = "1.1.0" +VERSION = "2.0.0" PRHOST_DEFAULT="0.0.0.0" PRPORT_DEFAULT=8585
@@ -77,12 +77,25 @@ def main(): action="store_true", help="open database in read-only mode", ) + parser.add_argument( + "-u", + "--upstream", + default=os.environ.get("PRSERVER_UPSTREAM", None), + help="Upstream PR service (host:port)", + ) args = parser.parse_args() init_logger(os.path.abspath(args.log), args.loglevel) if args.start: - ret=prserv.serv.start_daemon(args.file, args.host, args.port, os.path.abspath(args.log), args.read_only) + ret=prserv.serv.start_daemon( + args.file, + args.host, + args.port, + os.path.abspath(args.log), + args.read_only, + args.upstream + ) elif args.stop: ret=prserv.serv.stop_daemon(args.host, args.port) else:
lib/prserv/__init__.py +79 -1
83 lines not on this page · raw message
lib/prserv/client.py +9 -8
@@ -6,6 +6,7 @@ import logging import bb.asyncrpc +from . import create_async_client logger = logging.getLogger("BitBake.PRserv")
@@ -13,16 +14,16 @@ class PRAsyncClient(bb.asyncrpc.AsyncClient): def __init__(self): super().__init__("PRSERVICE", "1.0", logger) - async def getPR(self, version, pkgarch, checksum): + async def getPR(self, version, pkgarch, checksum, history=False): response = await self.invoke( - {"get-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum}} + {"get-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "history": history}} ) if response: return response["value"] - async def test_pr(self, version, pkgarch, checksum): + async def test_pr(self, version, pkgarch, checksum, history=False): response = await self.invoke( - {"test-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum}} + {"test-pr": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "history": history}} ) if response: return response["value"]
@@ -41,16 +42,16 @@ class PRAsyncClient(bb.asyncrpc.AsyncClient): if response: return response["value"] - async def importone(self, version, pkgarch, checksum, value): + async def importone(self, version, pkgarch, checksum, value, history=False): response = await self.invoke( - {"import-one": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "value": value}} + {"import-one": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "value": value, "history": history}} ) if response: return response["value"] - async def export(self, version, pkgarch, checksum, colinfo): + async def export(self, version, pkgarch, checksum, colinfo, history=False): response = await self.invoke( - {"export": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "colinfo": colinfo}} + {"export": {"version": version, "pkgarch": pkgarch, "checksum": checksum, "colinfo": colinfo, "history": history}} ) if response: return (response["metainfo"], response["datainfo"])
lib/prserv/db.py +91 -92
262 lines not on this page · raw message
lib/prserv/serv.py +117 -17
228 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 4/5 prserv: sync the database after each change
In reply to [email protected]From: Michael Opdenacker <[email protected]>
This removes the need for a "dirty" flag and simplifies the code.
--- lib/prserv/db.py | 13 ++++--------- lib/prserv/serv.py | 3 --- 2 files changed, 4 insertions(+), 12 deletions(-)
lib/prserv/db.py +4 -9
@@ -37,7 +37,6 @@ class PRTable(object): def __init__(self, conn, table, read_only): self.conn = conn self.read_only = read_only - self.dirty = False self.table = table if self.read_only:
@@ -53,6 +52,7 @@ class PRTable(object): checksum TEXT NOT NULL, \ value TEXT, \ PRIMARY KEY (version, pkgarch, checksum, value));" % self.table) + self.sync() def _execute(self, *query): """Execute a query, waiting to acquire a lock if necessary"""
@@ -71,11 +71,6 @@ class PRTable(object): self.conn.commit() self._execute("BEGIN EXCLUSIVE TRANSACTION") - def sync_if_dirty(self): - if self.dirty: - self.sync() - self.dirty = False - def test_package(self, version, pkgarch): """Returns whether the specified package version is found in the database for the specified architecture"""
@@ -167,7 +162,7 @@ class PRTable(object): except sqlite3.IntegrityError as exc: logger.error(str(exc)) - self.dirty = True + self.sync() def _get_value(self, version, pkgarch, checksum, history):
@@ -216,7 +211,7 @@ class PRTable(object): except sqlite3.IntegrityError as exc: logger.error(str(exc)) - self.dirty = True + self.sync() data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table, (version, pkgarch, checksum))
@@ -242,7 +237,7 @@ class PRTable(object): except sqlite3.IntegrityError as exc: logger.error(str(exc)) - self.dirty = True + self.sync() data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=? AND value>=?;" % self.table, (version, pkgarch, checksum, value))
lib/prserv/serv.py +0 -3
@@ -44,8 +44,6 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): except: self.server.table.sync() raise - else: - self.server.table.sync_if_dirty() async def handle_test_pr(self, request): '''Finds the PR value corresponding to the request. If not found, returns None and doesn't insert a new value'''
@@ -233,7 +231,6 @@ class PRServer(bb.asyncrpc.AsyncServer): return tasks async def stop(self): - self.table.sync_if_dirty() self.db.disconnect() await super().stop()
Signature · 1 line
2.34.1
PATCH v4 5/5 prserv: add bitbake selftests
In reply to [email protected]From: Michael Opdenacker <[email protected]>
Run them with "bitbake-selftest prserv.tests"
--- bin/bitbake-selftest | 2 + lib/prserv/tests.py | 381 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 383 insertions(+) create mode 100644 bitbake/lib/prserv/tests.py
bin/bitbake-selftest +2 -0
@@ -15,6 +15,7 @@ import unittest try: import bb import hashserv + import prserv import layerindexlib except RuntimeError as exc: sys.exit(str(exc))
@@ -33,6 +34,7 @@ tests = ["bb.tests.codeparser", "bb.tests.utils", "bb.tests.compression", "hashserv.tests", + "prserv.tests", "layerindexlib.tests.layerindexobj", "layerindexlib.tests.restapi", "layerindexlib.tests.cooker"]
lib/prserv/tests.py new file +381 -0
381 lines not on this page · raw message
Signature · 1 line
2.34.1