From 254c1cd9fb2a51d8846b7571f10400eb8d387661 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 8 Jul 2021 08:11:49 +0000 Subject: [PATCH] api: remove host side arguments facility Now that arguments are transmitted via a mapped, i.e. bind-mounted, file instead of using the jsoncomm RPC mechanism, all the methods related to the latter can be removed from API. --- osbuild/api.py | 17 +---------------- osbuild/pipeline.py | 2 +- test/mod/test_api.py | 16 ++-------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/osbuild/api.py b/osbuild/api.py index a69ee573..8ef3521e 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -139,30 +139,17 @@ class API(BaseAPI): endpoint = "osbuild" - def __init__(self, args, *, socket_address=None): + def __init__(self, *, socket_address=None): super().__init__(socket_address) - self.input = args self.metadata = {} self.error = None - def _prepare_input(self): - with tempfile.TemporaryFile() as fd: - fd.write(json.dumps(self.input).encode('utf-8')) - # re-open the file to get a read-only file descriptor - return open(f"/proc/self/fd/{fd.fileno()}", "r") - def _set_metadata(self, message, fds): fd = message["metadata"] with os.fdopen(fds.steal(fd), encoding="utf-8") as f: data = json.load(f) self.metadata.update(data) - def _get_arguments(self, sock): - with self._prepare_input() as data: - fds = [] - fds.append(data.fileno()) - sock.send({"type": "fd", "fd": 0}, fds=fds) - def _get_exception(self, message): self.error = { "type": "exception", @@ -174,8 +161,6 @@ class API(BaseAPI): self._set_metadata(msg, fds) elif msg["method"] == 'exception': self._get_exception(msg) - elif msg["method"] == 'get-arguments': - self._get_arguments(sock) def exception(e, path="/run/osbuild/api/osbuild"): diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 7d86d235..c0ffd5a9 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -172,7 +172,7 @@ class Stage: self.prepare_arguments(args, args_path) - api = API(args) + api = API() build_root.register_api(api) rls = remoteloop.LoopServer() diff --git a/test/mod/test_api.py b/test/mod/test_api.py index c2454874..7ce85536 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -4,7 +4,6 @@ import os import multiprocessing as mp -import sys import tempfile import unittest @@ -68,27 +67,17 @@ class TestAPI(unittest.TestCase): with api: pass - def test_get_arguments(self): - tmpdir = self.tmp.name - path = os.path.join(tmpdir, "osbuild-api") - args = {"options": {"answer": 42}} - - with osbuild.api.API(args, socket_address=path) as _: - data = osbuild.api.arguments(path=path) - self.assertEqual(data, args) - def test_exception(self): # Check that 'api.exception' correctly sets 'API.exception' tmpdir = self.tmp.name path = os.path.join(tmpdir, "osbuild-api") - args = {} def exception(path): with osbuild.api.exception_handler(path): raise ValueError("osbuild test exception") assert False, "api.exception should exit process" - api = osbuild.api.API(args, socket_address=path) + api = osbuild.api.API(socket_address=path) with api: p = mp.Process(target=exception, args=(path, )) p.start() @@ -109,14 +98,13 @@ class TestAPI(unittest.TestCase): # set correctly tmpdir = self.tmp.name path = os.path.join(tmpdir, "osbuild-api") - args = {} def metadata(path): data = {"meta": "42"} osbuild.api.metadata(data, path=path) return 0 - api = osbuild.api.API(args, socket_address=path) + api = osbuild.api.API(socket_address=path) with api: p = mp.Process(target=metadata, args=(path, )) p.start()