From 996a2125f2e4e83caaa4100912dfd9da41bce11f Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Thu, 4 Nov 2021 09:47:45 +1300 Subject: [PATCH] pass install source as an argument to curtin install, not via config --- subiquity/models/source.py | 11 +++++------ subiquity/models/tests/test_source.py | 22 +++++++++++++--------- subiquity/models/tests/test_subiquity.py | 4 ++-- subiquity/server/controllers/install.py | 17 +++++++++++++---- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/subiquity/models/source.py b/subiquity/models/source.py index de537503..1d766dbc 100644 --- a/subiquity/models/source.py +++ b/subiquity/models/source.py @@ -87,7 +87,7 @@ class SourceModel: if self.current is None: self.current = self.sources[0] - def render(self): + def get_source(self): path = os.path.join(self._dir, self.current.path) if self.current.preinstalled_langs: base, ext = os.path.splitext(path) @@ -97,8 +97,7 @@ class SourceModel: suffix = 'no-languages' path = base + '.' + suffix + ext scheme = self.current.type - return { - 'sources': { - 'ubuntu00': f'{scheme}://{path}' - }, - } + return f'{scheme}://{path}' + + def render(self): + return {} diff --git a/subiquity/models/tests/test_source.py b/subiquity/models/tests/test_source.py index 1663fb52..f74471cd 100644 --- a/subiquity/models/tests/test_source.py +++ b/subiquity/models/tests/test_source.py @@ -46,7 +46,7 @@ def make_entry(**fields): return raw -class TestMirrorModel(unittest.TestCase): +class TestSourceModel(unittest.TestCase): def tdir(self): tdir = tempfile.mkdtemp() @@ -88,7 +88,7 @@ class TestMirrorModel(unittest.TestCase): self.write_and_load_entries(model, entries) self.assertEqual(model.current.id, 'id2') - def test_render_absolute(self): + def test_get_source_absolute(self): entry = make_entry( type='scheme', path='/foo/bar/baz', @@ -96,9 +96,9 @@ class TestMirrorModel(unittest.TestCase): model = SourceModel() self.write_and_load_entries(model, [entry]) self.assertEqual( - model.render(), {'sources': {'ubuntu00': 'scheme:///foo/bar/baz'}}) + model.get_source(), 'scheme:///foo/bar/baz') - def test_render_relative(self): + def test_get_source_relative(self): dir = self.tdir() entry = make_entry( type='scheme', @@ -107,11 +107,15 @@ class TestMirrorModel(unittest.TestCase): model = SourceModel() self.write_and_load_entries(model, [entry], dir) self.assertEqual( - model.render(), - {'sources': {'ubuntu00': f'scheme://{dir}/foo/bar/baz'}}) + model.get_source(), + f'scheme://{dir}/foo/bar/baz') - def test_render_initial(self): + def test_get_source_initial(self): model = SourceModel() self.assertEqual( - model.render(), - {'sources': {'ubuntu00': 'cp:///media/filesystem'}}) + model.get_source(), + 'cp:///media/filesystem') + + def test_render(self): + model = SourceModel() + self.assertEqual(model.render(), {}) diff --git a/subiquity/models/tests/test_subiquity.py b/subiquity/models/tests/test_subiquity.py index a4e6b7a2..99cd45cb 100644 --- a/subiquity/models/tests/test_subiquity.py +++ b/subiquity/models/tests/test_subiquity.py @@ -172,10 +172,10 @@ class TestSubiquityModel(unittest.TestCase): netplan = yaml.safe_load(netplan_content) self.assertConfigHasVal(netplan, 'network.version', 2) - def test_has_sources(self): + def test_sources(self): model = self.make_model() config = model.render() - self.assertIn('sources', config) + self.assertNotIn('sources', config) def test_mirror(self): model = self.make_model() diff --git a/subiquity/server/controllers/install.py b/subiquity/server/controllers/install.py index 070122b9..d2955e7b 100644 --- a/subiquity/server/controllers/install.py +++ b/subiquity/server/controllers/install.py @@ -19,11 +19,12 @@ import os import re import shutil +from curtin.commands.extract import get_handler_for_source from curtin.commands.install import ( ERROR_TARFILE, INSTALL_LOG, ) -from curtin.util import write_file +from curtin.util import sanitize_source, write_file import yaml @@ -130,9 +131,9 @@ class InstallController(SubiquityController): @with_context( description="installing system", level="INFO", childlevel="DEBUG") - async def curtin_install(self, *, context): + async def curtin_install(self, *, context, source): await run_curtin_command( - self.app, context, 'install', config=self.write_config()) + self.app, context, 'install', source, config=self.write_config()) @with_context() async def install(self, *, context): @@ -154,11 +155,19 @@ class InstallController(SubiquityController): self.app.update_state(ApplicationState.RUNNING) + handler = get_handler_for_source( + sanitize_source(self.model.source.get_source())) + if self.app.opts.dry_run: + path = '/' + else: + path = handler.setup() + if os.path.exists(self.model.target): await self.unmount_target( context=context, target=self.model.target) - await self.curtin_install(context=context) + await self.curtin_install( + context=context, source='cp://' + path) self.app.update_state(ApplicationState.POST_WAIT)