api: add exception endpoint
Create a new api endpoint called exception, that communicates exception backtraces separately back to osbuild, as opposed to dumping them into the normal log. Additionally, add a corresponding test to check that a call to api.exception correctly sets API.exception.
This commit is contained in:
parent
661e202e79
commit
5dc5ddcf29
3 changed files with 55 additions and 3 deletions
|
|
@ -79,6 +79,25 @@ class TestAPI(unittest.TestCase):
|
|||
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 = {}
|
||||
monitor = osbuild.monitor.BaseMonitor(sys.stderr.fileno())
|
||||
|
||||
def exception(path):
|
||||
with osbuild.api.exception_handler(path):
|
||||
raise ValueError("osbuild test exception")
|
||||
|
||||
api = osbuild.api.API(args, monitor, socket_address=path)
|
||||
with api:
|
||||
p = mp.Process(target=exception, args=(path, ))
|
||||
p.start()
|
||||
p.join()
|
||||
self.assertIsNotNone(api.exception, "Exception not set")
|
||||
self.assertEqual(api.exception["value"], "osbuild test exception")
|
||||
|
||||
def test_metadata(self):
|
||||
# Check that `api.metadata` leads to `API.metadata` being
|
||||
# set correctly
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue