api: add free_only

This commit is contained in:
Dan Bungert 2021-11-22 14:45:59 -07:00
parent e32b7f28ac
commit 1b74779aef
3 changed files with 40 additions and 0 deletions

View File

@ -95,6 +95,14 @@ class API:
class ssh_info:
def GET() -> Optional[LiveSessionSSHInfo]: ...
class free_only:
def GET() -> bool: ...
def POST(enable: bool) -> None:
"""Enable or disable free-only mode. Currently only controlls
the list of components. free-only choice must be made prior to
confirmation of filesystem changes"""
class errors:
class wait:
def GET(error_ref: ErrorReportRef) -> ErrorReportRef:

View File

@ -86,6 +86,7 @@ class MetaController:
def __init__(self, app):
self.app = app
self.context = app.context.child("Meta")
self.free_only = False
async def status_GET(self, cur: Optional[ApplicationState] = None) \
-> ApplicationStatus:
@ -158,6 +159,18 @@ class MetaController:
ips=ips,
host_key_fingerprints=host_fingerprints)
async def free_only_GET(self) -> bool:
return self.free_only
async def free_only_POST(self, enable: bool) -> None:
self.free_only = enable
to_disable = {'restricted', 'multiverse'}
if enable:
# enabling free only mode means disabling components
self.app.base_model.mirror.disable_components |= to_disable
else:
self.app.base_model.mirror.disable_components -= to_disable
def get_installer_password_from_cloudinit_log():
try:

View File

@ -667,6 +667,25 @@ class TestInfo(TestAPI):
self.assertEqual('/dev/sda', sda['path'])
class TestFree(TestAPI):
@timeout(5)
async def test_free_only(self):
async with start_server('examples/simple.json') as inst:
await inst.post('/meta/free_only', enable=True)
components = await inst.get('/mirror/disable_components')
components.sort()
self.assertEqual(['multiverse', 'restricted'], components)
@timeout(5)
async def test_not_free_only(self):
async with start_server('examples/simple.json') as inst:
comps = ['universe', 'multiverse']
await inst.post('/mirror/disable_components', comps)
await inst.post('/meta/free_only', enable=False)
components = await inst.get('/mirror/disable_components')
self.assertEqual(['universe'], components)
class TestRegression(TestAPI):
@timeout(5)
async def test_edit_not_trigger_boot_device(self):