mirror: allow to cancel ongoing check when starting a new one

Before, doing a POST request to /mirror/check_mirror/start when a mirror
test was already running resulted in an exception on the server side.

We now have a parameter to control whether any ongoing check should be
cancelled first.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-01-17 14:54:26 +01:00
parent d18ebd826a
commit c8fd3e40c2
2 changed files with 6 additions and 4 deletions

View File

@ -354,7 +354,7 @@ class API:
class check_mirror:
class start:
def POST() -> None: ...
def POST(cancel_ongoing: bool = False) -> None: ...
class progress:
def GET() -> Optional[MirrorCheckResponse]: ...

View File

@ -189,10 +189,12 @@ class MirrorController(SubiquityController):
log.debug(data)
self.model.disabled_components = set(data)
async def check_mirror_start_POST(self) -> None:
async def check_mirror_start_POST(self, cancel_ongoing: bool = False) -> None:
if self.mirror_check is not None and not self.mirror_check.task.done():
# TODO
assert False
if cancel_ongoing:
await self.check_mirror_abort_POST()
else:
assert False
output = io.StringIO()
self.mirror_check = MirrorCheck(
uri=self.model.get_mirror(),