mirror: add disable_components API

This commit is contained in:
Dan Bungert 2021-08-04 14:27:32 -06:00
parent e1e5013ad5
commit e32b7f28ac
7 changed files with 92 additions and 3 deletions

View File

@ -281,6 +281,19 @@
},
"sources": {
"type": "object"
},
"disable_components": {
"type": "array",
"items": {
"type": "string",
"enum": [
"universe",
"multiverse",
"restricted",
"contrib",
"non-free"
]
}
}
}
},

View File

@ -60,7 +60,6 @@ class API:
"""The API offered by the subiquity installer process."""
identity = simple_endpoint(IdentityData)
locale = simple_endpoint(str)
mirror = simple_endpoint(str)
proxy = simple_endpoint(str)
ssh = simple_endpoint(SSHData)
updates = simple_endpoint(str)
@ -297,6 +296,14 @@ class API:
class shutdown:
def POST(mode: ShutdownMode, immediate: bool = False): ...
class mirror:
def GET() -> str: ...
def POST(data: Payload[str]): ...
class disable_components:
def GET() -> List[str]: ...
def POST(data: Payload[List[str]]): ...
class LinkAction(enum.Enum):
NEW = enum.auto()

View File

@ -51,6 +51,12 @@ class MirrorModel(object):
self.config = copy.deepcopy(DEFAULT)
self.architecture = get_architecture()
self.default_mirror = self.get_mirror()
self.disable_components = set()
def get_config(self):
config = copy.deepcopy(self.config)
config['disable_components'] = list(self.disable_components)
return config
def mirror_is_default(self):
return self.get_mirror() == self.default_mirror

View File

@ -42,3 +42,13 @@ class TestMirrorModel(unittest.TestCase):
model.set_mirror("http://mymirror.invalid/")
model.set_country("CC")
self.assertEqual(model.get_mirror(), "http://mymirror.invalid/")
def test_default_disable_components(self):
config = MirrorModel().get_config()
self.assertEqual([], config['disable_components'])
def test_set_disable_components(self):
model = MirrorModel()
model.disable_components = set(['universe'])
config = model.get_config()
self.assertEqual(['universe'], config['disable_components'])

View File

@ -104,7 +104,7 @@ class AptConfigurer:
config_upper = await self.setup_overlay(self.source, self.configured)
config = {
'apt': self.app.base_model.mirror.config,
'apt': self.app.base_model.mirror.get_config(),
}
config_location = os.path.join(
self.app.root, 'var/log/installer/subiquity-curtin-apt.conf')

View File

@ -16,6 +16,7 @@
import asyncio
import copy
import logging
from typing import List
from curtin.config import merge_config
@ -40,7 +41,15 @@ class MirrorController(SubiquityController):
'primary': {'type': 'array'},
'geoip': {'type': 'boolean'},
'sources': {'type': 'object'},
},
'disable_components': {
'type': 'array',
'items': {
'type': 'string',
'enum': ['universe', 'multiverse', 'restricted',
'contrib', 'non-free']
}
}
}
}
model_name = "mirror"
@ -89,3 +98,9 @@ class MirrorController(SubiquityController):
async def POST(self, data: str):
self.model.set_mirror(data)
await self.configured()
async def disable_components_GET(self) -> List[str]:
return list(self.model.disable_components)
async def disable_components_POST(self, data: List[str]):
self.model.disable_components = set(data)

View File

@ -0,0 +1,38 @@
# Copyright 2021 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import jsonschema
import unittest
from subiquity.server.controllers.mirror import MirrorController
class TestMirrorSchema(unittest.TestCase):
def validate(self, data):
jsonschema.validate(data, MirrorController.autoinstall_schema)
def test_empty(self):
self.validate({})
def test_disable_components(self):
self.validate({'disable_components': ['universe']})
def test_no_disable_main(self):
with self.assertRaises(jsonschema.ValidationError):
self.validate({'disable_components': ['main']})
def test_no_disable_random_junk(self):
with self.assertRaises(jsonschema.ValidationError):
self.validate({'disable_components': ['not-a-component']})