mirror: do not assign an elected mirror automatically

When Subiquity starts, we no longer assign the elected mirror. This
means that marking the mirror model configured without selecting a
mirror is possible, and will cause trouble during install.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-01-29 15:28:12 +01:00
parent 6541ea055c
commit 927df0b845
3 changed files with 20 additions and 10 deletions

View File

@ -86,9 +86,9 @@ class MirrorModel(object):
def __init__(self):
self.config = copy.deepcopy(DEFAULT)
self.disabled_components: Set[str] = set()
self.primary_elected = PrimarySection.new_from_default(parent=self)
self.primary_elected: Optional[PrimarySection] = None
self.primary_candidates: List[PrimarySection] = [
self.primary_elected,
PrimarySection.new_from_default(parent=self),
]
self.primary_staged: Optional[PrimarySection] = None
@ -104,8 +104,6 @@ class MirrorModel(object):
self.primary_candidates = [
PrimarySection(data.pop("primary"), parent=self)
]
# TODO do not mark primary elected.
self.primary_elected = self.primary_candidates[0]
merge_config(self.config, data)
def _get_apt_config_common(self) -> Dict[str, Any]:
@ -124,6 +122,8 @@ class MirrorModel(object):
return config
def get_apt_config_elected(self) -> Dict[str, Any]:
assert self.primary_elected is not None
config = self._get_apt_config_common()
config["primary"] = self.primary_elected.config
return config
@ -169,5 +169,9 @@ class MirrorModel(object):
def make_autoinstall(self):
config = self._get_apt_config_common()
config["primary"] = self.primary_elected.config
if self.primary_elected is not None:
config["primary"] = self.primary_elected.config
else:
# In an offline autoinstall, there is no elected mirror.
config["primary"] = self.primary_candidates[0].config
return config

View File

@ -79,11 +79,13 @@ class TestPrimarySection(unittest.TestCase):
class TestMirrorModel(unittest.TestCase):
def setUp(self):
self.model = MirrorModel()
self.candidate = self.model.primary_candidates[0]
self.model.primary_staged = self.candidate
def test_set_country(self):
self.model.set_country("CC")
self.assertIn(
self.model.primary_candidates[0].get_mirror(),
self.candidate.get_mirror(),
[
"http://CC.archive.ubuntu.com/ubuntu",
"http://CC.ports.ubuntu.com/ubuntu-ports",
@ -96,20 +98,22 @@ class TestMirrorModel(unittest.TestCase):
self.assertEqual(candidate.get_mirror(), "http://mymirror.invalid/")
def test_default_disable_components(self):
config = self.model.get_apt_config_elected()
config = self.model.get_apt_config_staged()
self.assertEqual([], config['disable_components'])
def test_from_autoinstall(self):
# autoinstall loads to the config directly
data = {'disable_components': ['non-free']}
self.model.load_autoinstall_data(data)
config = self.model.get_apt_config_elected()
self.candidate = self.model.primary_candidates[0]
self.model.primary_staged = self.candidate
config = self.model.get_apt_config_staged()
self.assertEqual(['non-free'], config['disable_components'])
def test_disable_add(self):
expected = ['things', 'stuff']
self.model.disable_components(expected.copy(), add=True)
actual = self.model.get_apt_config_elected()['disable_components']
actual = self.model.get_apt_config_staged()['disable_components']
actual.sort()
expected.sort()
self.assertEqual(expected, actual)
@ -119,7 +123,7 @@ class TestMirrorModel(unittest.TestCase):
to_remove = ['things', 'stuff']
expected = ['a', 'b']
self.model.disable_components(to_remove, add=False)
actual = self.model.get_apt_config_elected()['disable_components']
actual = self.model.get_apt_config_staged()['disable_components']
actual.sort()
expected.sort()
self.assertEqual(expected, actual)

View File

@ -52,6 +52,8 @@ class TestMirrorController(unittest.IsolatedAsyncioTestCase):
def test_make_autoinstall(self):
self.controller.model = MirrorModel()
self.controller.model.primary_elected = \
self.controller.model.primary_candidates[0]
config = self.controller.make_autoinstall()
self.assertIn("disable_components", config.keys())
self.assertIn("primary", config.keys())