api: remove setup_stdio
API.setup_stdio was replaced in PRs 506 and 507, remove setup_stdio functions and call sites.
This commit is contained in:
parent
b1229de56e
commit
01aae91949
4 changed files with 1 additions and 85 deletions
|
|
@ -3,7 +3,6 @@ import asyncio
|
|||
import io
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from typing import Dict, Optional
|
||||
|
|
@ -174,20 +173,6 @@ class API(BaseAPI):
|
|||
self._output_data.write(data)
|
||||
self.monitor.log(data)
|
||||
|
||||
def _setup_stdio(self, server):
|
||||
with self._prepare_input() as stdin, \
|
||||
self._prepare_output() as stdout:
|
||||
msg = {}
|
||||
fds = []
|
||||
fds.append(stdin.fileno())
|
||||
msg['stdin'] = 0
|
||||
fds.append(stdout.fileno())
|
||||
msg['stdout'] = 1
|
||||
fds.append(stdout.fileno())
|
||||
msg['stderr'] = 2
|
||||
|
||||
server.send(msg, fds=fds)
|
||||
|
||||
def _set_metadata(self, message):
|
||||
self.metadata.update(message["metadata"])
|
||||
|
||||
|
|
@ -198,9 +183,7 @@ class API(BaseAPI):
|
|||
sock.send({"type": "fd", "fd": 0}, fds=fds)
|
||||
|
||||
def _message(self, msg, fds, sock):
|
||||
if msg["method"] == 'setup-stdio':
|
||||
self._setup_stdio(sock)
|
||||
elif msg["method"] == 'add-metadata':
|
||||
if msg["method"] == 'add-metadata':
|
||||
self._set_metadata(msg)
|
||||
elif msg["method"] == 'get-arguments':
|
||||
self._get_arguments(sock)
|
||||
|
|
@ -224,19 +207,6 @@ def arguments(path="/run/osbuild/api/osbuild"):
|
|||
return data
|
||||
|
||||
|
||||
def setup_stdio(path="/run/osbuild/api/osbuild"):
|
||||
"""Replace standard i/o with the ones provided by the API"""
|
||||
with jsoncomm.Socket.new_client(path) as client:
|
||||
req = {"method": "setup-stdio"}
|
||||
client.send(req)
|
||||
msg, fds, _ = client.recv()
|
||||
for sio in ["stdin", "stdout", "stderr"]:
|
||||
target = getattr(sys, sio)
|
||||
source = fds[msg[sio]]
|
||||
os.dup2(source, target.fileno())
|
||||
fds.close()
|
||||
|
||||
|
||||
def metadata(data: Dict, path="/run/osbuild/api/osbuild"):
|
||||
"""Update metadata for the current module"""
|
||||
with jsoncomm.Socket.new_client(path) as client:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import osbuild.api
|
||||
|
||||
|
||||
def ldconfig():
|
||||
|
|
@ -49,7 +48,6 @@ def python_alternatives():
|
|||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
osbuild.api.setup_stdio()
|
||||
ldconfig()
|
||||
sysusers()
|
||||
tmpfiles()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import sys
|
|||
import tempfile
|
||||
import unittest
|
||||
|
||||
import osbuild
|
||||
from osbuild.buildroot import BuildRoot
|
||||
from osbuild.monitor import LogMonitor, NullMonitor
|
||||
from .. import test
|
||||
|
|
@ -24,9 +23,6 @@ class TestBuildRoot(test.TestBase):
|
|||
self.tmp.cleanup()
|
||||
|
||||
def test_basic(self):
|
||||
# This also checks the API and BuildRoot integration:
|
||||
# the runner will call api.setup_stdio and thus check
|
||||
# that connecting to the api works correctly
|
||||
runner = "org.osbuild.linux"
|
||||
libdir = os.path.abspath(os.curdir)
|
||||
var = pathlib.Path(self.tmp.name, "var")
|
||||
|
|
@ -34,8 +30,6 @@ class TestBuildRoot(test.TestBase):
|
|||
|
||||
monitor = NullMonitor(sys.stderr.fileno())
|
||||
with BuildRoot("/", runner, libdir=libdir, var=var) as root:
|
||||
api = osbuild.api.API({}, monitor)
|
||||
root.register_api(api)
|
||||
|
||||
r = root.run(["/usr/bin/true"], monitor)
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
|
@ -59,8 +53,6 @@ class TestBuildRoot(test.TestBase):
|
|||
open(logfile, "w") as log:
|
||||
|
||||
monitor = LogMonitor(log.fileno())
|
||||
api = osbuild.api.API({}, monitor)
|
||||
root.register_api(api)
|
||||
|
||||
r = root.run(["/usr/bin/true"], monitor)
|
||||
|
||||
|
|
@ -81,8 +73,6 @@ class TestBuildRoot(test.TestBase):
|
|||
|
||||
monitor = NullMonitor(sys.stderr.fileno())
|
||||
with BuildRoot("/", runner, libdir=libdir, var=var) as root:
|
||||
api = osbuild.api.API({}, monitor)
|
||||
root.register_api(api)
|
||||
|
||||
r = root.run(["/usr/bin/echo", data], monitor)
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
|
@ -103,8 +93,6 @@ class TestBuildRoot(test.TestBase):
|
|||
|
||||
monitor = NullMonitor(sys.stderr.fileno())
|
||||
with BuildRoot("/", runner, libdir=libdir, var=var) as root:
|
||||
api = osbuild.api.API({}, monitor)
|
||||
root.register_api(api)
|
||||
|
||||
ro_binds = [f"{scripts}:/scripts"]
|
||||
|
||||
|
|
@ -139,8 +127,6 @@ class TestBuildRoot(test.TestBase):
|
|||
|
||||
monitor = NullMonitor(sys.stderr.fileno())
|
||||
with BuildRoot("/", runner, libdir=libdir, var=var) as root:
|
||||
api = osbuild.api.API({}, monitor)
|
||||
root.register_api(api)
|
||||
|
||||
ro_binds = [f"{scripts}:/scripts"]
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
#
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import multiprocessing as mp
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
|
@ -13,24 +11,10 @@ from collections import defaultdict
|
|||
|
||||
import osbuild
|
||||
import osbuild.meta
|
||||
from osbuild.api import API
|
||||
from osbuild.monitor import LogMonitor
|
||||
from .. import test
|
||||
|
||||
|
||||
def echo(path):
|
||||
"""echo stdin to stdout after setting stdio up via API
|
||||
|
||||
Meant to be called as the main function in a process
|
||||
simulating an osbuild runner and a stage run which does
|
||||
nothing but returns the supplied options to stdout again.
|
||||
"""
|
||||
osbuild.api.setup_stdio(path)
|
||||
data = json.load(sys.stdin)
|
||||
json.dump(data, sys.stdout)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
class TapeMonitor(osbuild.monitor.BaseMonitor):
|
||||
"""Record the usage of all called functions"""
|
||||
def __init__(self):
|
||||
|
|
@ -66,28 +50,6 @@ class TapeMonitor(osbuild.monitor.BaseMonitor):
|
|||
|
||||
|
||||
class TestMonitor(unittest.TestCase):
|
||||
def test_log_monitor_api(self):
|
||||
# Basic log and API integration check
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
args = {"foo": "bar"}
|
||||
path = os.path.join(tmpdir, "osbuild-api")
|
||||
logfile = os.path.join(tmpdir, "log.txt")
|
||||
|
||||
with open(logfile, "w") as log:
|
||||
api = API(args, LogMonitor(log.fileno()), socket_address=path)
|
||||
with api as api:
|
||||
p = mp.Process(target=echo, args=(path, ))
|
||||
p.start()
|
||||
p.join()
|
||||
self.assertEqual(p.exitcode, 0)
|
||||
output = api.output # pylint: disable=no-member
|
||||
assert output
|
||||
|
||||
self.assertEqual(json.dumps(args), output)
|
||||
with open(logfile) as f:
|
||||
log = f.read()
|
||||
self.assertEqual(log, output)
|
||||
|
||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||
def test_log_monitor_vfuncs(self):
|
||||
# Checks the basic functioning of the LogMonitor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue