mirror: add functions to make a section as staged or elected
Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
f7cd813254
commit
037a5ac8ed
|
@ -56,6 +56,12 @@ DEFAULT = {
|
|||
class PrimaryElement:
|
||||
parent: "MirrorModel" = attr.ib(kw_only=True)
|
||||
|
||||
def stage(self) -> None:
|
||||
self.parent.primary_staged = self
|
||||
|
||||
def elect(self) -> None:
|
||||
self.parent.primary_elected = self
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
class PrimaryEntry(PrimaryElement):
|
||||
|
@ -198,8 +204,7 @@ class MirrorModel(object):
|
|||
self.primary_staged = None
|
||||
|
||||
def assign_primary_elected(self, uri: str) -> None:
|
||||
self.primary_elected = \
|
||||
LegacyPrimarySection.new_from_default(parent=self)
|
||||
LegacyPrimarySection.new_from_default(parent=self).elect()
|
||||
self.primary_elected.uri = uri
|
||||
|
||||
def wants_geoip(self) -> bool:
|
||||
|
|
|
@ -121,7 +121,7 @@ class TestMirrorModel(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.model = MirrorModel()
|
||||
self.candidate = self.model.primary_candidates[0]
|
||||
self.model.primary_staged = self.candidate
|
||||
self.candidate.stage()
|
||||
|
||||
def test_set_country(self):
|
||||
self.model.set_country("CC")
|
||||
|
@ -147,7 +147,7 @@ class TestMirrorModel(unittest.TestCase):
|
|||
data = {'disable_components': ['non-free']}
|
||||
self.model.load_autoinstall_data(data)
|
||||
self.candidate = self.model.primary_candidates[0]
|
||||
self.model.primary_staged = self.candidate
|
||||
self.candidate.stage()
|
||||
config = self.model.get_apt_config_staged()
|
||||
self.assertEqual(['non-free'], config['disable_components'])
|
||||
|
||||
|
@ -174,7 +174,7 @@ class TestMirrorModel(unittest.TestCase):
|
|||
self.model.disabled_components = set(["non-free"])
|
||||
self.model.primary_candidates = \
|
||||
[LegacyPrimarySection(primary, parent=self.model)]
|
||||
self.model.primary_elected = self.model.primary_candidates[0]
|
||||
self.model.primary_candidates[0].elect()
|
||||
cfg = self.model.make_autoinstall()
|
||||
self.assertEqual(cfg["disable_components"], ["non-free"])
|
||||
self.assertEqual(cfg["primary"], primary)
|
||||
|
|
|
@ -154,7 +154,7 @@ class MirrorController(SubiquityController):
|
|||
# Sleep before testing the next candidate..
|
||||
log.debug("Will check next candiate mirror after 10 seconds.")
|
||||
await asyncio.sleep(10)
|
||||
self.model.primary_staged = candidate
|
||||
candidate.stage()
|
||||
try:
|
||||
await self.try_mirror_checking_once()
|
||||
except AptConfigCheckError:
|
||||
|
@ -172,7 +172,7 @@ class MirrorController(SubiquityController):
|
|||
else:
|
||||
raise NoUsableMirrorError
|
||||
|
||||
self.model.primary_elected = candidate
|
||||
candidate.elect()
|
||||
|
||||
def on_geoip(self):
|
||||
if self.geoip_enabled:
|
||||
|
@ -237,7 +237,7 @@ class MirrorController(SubiquityController):
|
|||
async def candidate_POST(self, url: str) -> None:
|
||||
log.debug(url)
|
||||
self.model.replace_primary_candidates([url])
|
||||
self.model.primary_staged = self.model.primary_candidates[0]
|
||||
self.model.primary_candidates[0].stage()
|
||||
|
||||
async def disable_components_GET(self) -> List[str]:
|
||||
return sorted(self.model.disabled_components)
|
||||
|
|
|
@ -52,8 +52,7 @@ class TestMirrorController(unittest.IsolatedAsyncioTestCase):
|
|||
|
||||
def test_make_autoinstall(self):
|
||||
self.controller.model = MirrorModel()
|
||||
self.controller.model.primary_elected = \
|
||||
self.controller.model.primary_candidates[0]
|
||||
self.controller.model.primary_candidates[0].elect()
|
||||
config = self.controller.make_autoinstall()
|
||||
self.assertIn("disable_components", config.keys())
|
||||
self.assertIn("primary", config.keys())
|
||||
|
|
|
@ -67,8 +67,7 @@ class TestAptConfigurer(SubiTestCase):
|
|||
self.astart_sym = "subiquity.server.apt.astart_command"
|
||||
|
||||
def test_apt_config_noproxy(self):
|
||||
self.model.mirror.primary_staged = \
|
||||
self.model.mirror.primary_candidates[0]
|
||||
self.model.mirror.primary_candidates[0].stage()
|
||||
config = self.configurer.apt_config(elected=False)
|
||||
self.assertNotIn("http_proxy", config["apt"])
|
||||
self.assertNotIn("https_proxy", config["apt"])
|
||||
|
@ -77,8 +76,7 @@ class TestAptConfigurer(SubiTestCase):
|
|||
proxy = 'http://apt-cacher-ng:3142'
|
||||
self.model.proxy.proxy = proxy
|
||||
|
||||
self.model.mirror.primary_staged = \
|
||||
self.model.mirror.primary_candidates[0]
|
||||
self.model.mirror.primary_candidates[0].stage()
|
||||
config = self.configurer.apt_config(elected=False)
|
||||
self.assertEqual(proxy, config["apt"]["http_proxy"])
|
||||
self.assertEqual(proxy, config["apt"]["https_proxy"])
|
||||
|
@ -140,7 +138,7 @@ class TestDRAptConfigurer(SubiTestCase):
|
|||
self.model = Mock()
|
||||
self.model.mirror = MirrorModel()
|
||||
self.candidate = self.model.mirror.primary_candidates[0]
|
||||
self.model.mirror.primary_staged = self.candidate
|
||||
self.candidate.stage()
|
||||
self.app = make_app(self.model)
|
||||
self.app.dr_cfg = DRConfig()
|
||||
self.app.dr_cfg.apt_mirror_check_default_strategy = "failure"
|
||||
|
|
Loading…
Reference in New Issue