From d981029ddc35c22a04e79844b79ffdb4ec62a3ef Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 28 Apr 2022 19:08:45 +0200 Subject: [PATCH] source: add a default value for search_drivers in POST /source For backward compatibility reasons with the desktop installer implementation, we now provide a default value (i.e., false) for the new search_drivers parameter in /source. Added non-regressions test for it. Signed-off-by: Olivier Gayot --- subiquity/common/apidef.py | 2 +- subiquity/server/controllers/source.py | 3 ++- subiquity/tests/api/test_api.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/subiquity/common/apidef.py b/subiquity/common/apidef.py index 35852fb4..acd2a3ff 100644 --- a/subiquity/common/apidef.py +++ b/subiquity/common/apidef.py @@ -145,7 +145,7 @@ class API: class source: def GET() -> SourceSelectionAndSetting: ... - def POST(source_id: str, search_drivers: bool) -> None: ... + def POST(source_id: str, search_drivers: bool = False) -> None: ... class zdev: def GET() -> List[ZdevInfo]: ... diff --git a/subiquity/server/controllers/source.py b/subiquity/server/controllers/source.py index 703cc4a8..031be32e 100644 --- a/subiquity/server/controllers/source.py +++ b/subiquity/server/controllers/source.py @@ -126,7 +126,8 @@ class SourceController(SubiquityController): await super().configured() self.app.base_model.set_source_variant(self.model.current.variant) - async def POST(self, source_id: str, search_drivers: bool) -> None: + async def POST(self, source_id: str, + search_drivers: bool = False) -> None: self.model.search_drivers = search_drivers for source in self.model.sources: if source.id == source_id: diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index e5202343..09f5ff42 100755 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -1041,3 +1041,21 @@ class TestCancel(TestAPI): # should not raise ServerDisconnectedError resp = await inst.get('/drivers', wait=True) self.assertEqual(['nvidia-driver-470-server'], resp['drivers']) + + +class TestSource(TestAPI): + async def test_optional_search_drivers(self): + async with start_server('examples/simple.json') as inst: + await inst.post('/source', source_id='ubuntu-server') + resp = await inst.get('/source') + self.assertFalse(resp['search_drivers']) + + await inst.post('/source', source_id='ubuntu-server', + search_drivers=True) + resp = await inst.get('/source') + self.assertTrue(resp['search_drivers']) + + await inst.post('/source', source_id='ubuntu-server', + search_drivers=False) + resp = await inst.get('/source') + self.assertFalse(resp['search_drivers'])