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.
This commit is contained in:
parent
affd384669
commit
254c1cd9fb
3 changed files with 4 additions and 31 deletions
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue