mirror: add disable_components API
This commit is contained in:
parent
e1e5013ad5
commit
e32b7f28ac
|
@ -281,6 +281,19 @@
|
||||||
},
|
},
|
||||||
"sources": {
|
"sources": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
|
},
|
||||||
|
"disable_components": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"universe",
|
||||||
|
"multiverse",
|
||||||
|
"restricted",
|
||||||
|
"contrib",
|
||||||
|
"non-free"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -60,7 +60,6 @@ class API:
|
||||||
"""The API offered by the subiquity installer process."""
|
"""The API offered by the subiquity installer process."""
|
||||||
identity = simple_endpoint(IdentityData)
|
identity = simple_endpoint(IdentityData)
|
||||||
locale = simple_endpoint(str)
|
locale = simple_endpoint(str)
|
||||||
mirror = simple_endpoint(str)
|
|
||||||
proxy = simple_endpoint(str)
|
proxy = simple_endpoint(str)
|
||||||
ssh = simple_endpoint(SSHData)
|
ssh = simple_endpoint(SSHData)
|
||||||
updates = simple_endpoint(str)
|
updates = simple_endpoint(str)
|
||||||
|
@ -297,6 +296,14 @@ class API:
|
||||||
class shutdown:
|
class shutdown:
|
||||||
def POST(mode: ShutdownMode, immediate: bool = False): ...
|
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):
|
class LinkAction(enum.Enum):
|
||||||
NEW = enum.auto()
|
NEW = enum.auto()
|
||||||
|
|
|
@ -51,6 +51,12 @@ class MirrorModel(object):
|
||||||
self.config = copy.deepcopy(DEFAULT)
|
self.config = copy.deepcopy(DEFAULT)
|
||||||
self.architecture = get_architecture()
|
self.architecture = get_architecture()
|
||||||
self.default_mirror = self.get_mirror()
|
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):
|
def mirror_is_default(self):
|
||||||
return self.get_mirror() == self.default_mirror
|
return self.get_mirror() == self.default_mirror
|
||||||
|
|
|
@ -42,3 +42,13 @@ class TestMirrorModel(unittest.TestCase):
|
||||||
model.set_mirror("http://mymirror.invalid/")
|
model.set_mirror("http://mymirror.invalid/")
|
||||||
model.set_country("CC")
|
model.set_country("CC")
|
||||||
self.assertEqual(model.get_mirror(), "http://mymirror.invalid/")
|
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'])
|
||||||
|
|
|
@ -104,7 +104,7 @@ class AptConfigurer:
|
||||||
config_upper = await self.setup_overlay(self.source, self.configured)
|
config_upper = await self.setup_overlay(self.source, self.configured)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
'apt': self.app.base_model.mirror.config,
|
'apt': self.app.base_model.mirror.get_config(),
|
||||||
}
|
}
|
||||||
config_location = os.path.join(
|
config_location = os.path.join(
|
||||||
self.app.root, 'var/log/installer/subiquity-curtin-apt.conf')
|
self.app.root, 'var/log/installer/subiquity-curtin-apt.conf')
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from curtin.config import merge_config
|
from curtin.config import merge_config
|
||||||
|
|
||||||
|
@ -40,7 +41,15 @@ class MirrorController(SubiquityController):
|
||||||
'primary': {'type': 'array'},
|
'primary': {'type': 'array'},
|
||||||
'geoip': {'type': 'boolean'},
|
'geoip': {'type': 'boolean'},
|
||||||
'sources': {'type': 'object'},
|
'sources': {'type': 'object'},
|
||||||
},
|
'disable_components': {
|
||||||
|
'type': 'array',
|
||||||
|
'items': {
|
||||||
|
'type': 'string',
|
||||||
|
'enum': ['universe', 'multiverse', 'restricted',
|
||||||
|
'contrib', 'non-free']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
model_name = "mirror"
|
model_name = "mirror"
|
||||||
|
|
||||||
|
@ -89,3 +98,9 @@ class MirrorController(SubiquityController):
|
||||||
async def POST(self, data: str):
|
async def POST(self, data: str):
|
||||||
self.model.set_mirror(data)
|
self.model.set_mirror(data)
|
||||||
await self.configured()
|
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)
|
||||||
|
|
|
@ -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']})
|
Loading…
Reference in New Issue