diff --git a/DESIGN.md b/DESIGN.md index f19dc20e..0c1324f2 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -191,7 +191,9 @@ classes live in `subiquity.models`. An instance of each model class is attached as an attribute to the `SubiquityModel` class and the name of the attribute added to `INSTALL_MODEL_NAMES` or `POSTINSTALL_MODEL_NAMES` as appropriate. Models that go into `INSTALL_MODEL_NAMES` need to define a -render() method that returns a fragment of curtin config. +render() method that returns a fragment of curtin config. POSTINSTALL models +that contribute to cloud-config should define a make_cloudconfig() method that +returns a cloud config fragment. #### Defining the API diff --git a/examples/autoinstall.yaml b/examples/autoinstall.yaml index a9db6c92..65252f0b 100644 --- a/examples/autoinstall.yaml +++ b/examples/autoinstall.yaml @@ -37,6 +37,9 @@ identity: username: ubuntu password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1' hostname: ubuntu +snaps: + - name: etcd + channel: 3.2/stable updates: all storage: config: diff --git a/scripts/runtests.sh b/scripts/runtests.sh index c6827ab3..0d7c01a1 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -21,6 +21,7 @@ clean () { rm -f .subiquity/subiquity-*.log rm -f "$testschema" rm -rf .subiquity/run/ + rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg } tty=$(tty) || tty=/dev/console @@ -53,7 +54,8 @@ python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \ python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \ storage.config[-1].options='"errors=remount-ro"' python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \ - locale='"en_GB.UTF-8"' + locale='"en_GB.UTF-8"' \ + 'snap.commands=[snap install --channel=3.2/stable etcd]' grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \ .subiquity/subiquity-server-debug.log grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \ diff --git a/subiquity/models/locale.py b/subiquity/models/locale.py index a8cee54e..8dc064f4 100644 --- a/subiquity/models/locale.py +++ b/subiquity/models/locale.py @@ -31,3 +31,11 @@ class LocaleModel(object): def __repr__(self): return "".format(self.selected_language) + + def make_cloudconfig(self): + if not self.selected_language: + return {} + locale = self.selected_language + if '.' not in locale and '_' in locale: + locale += '.UTF-8' + return {'locale': locale} diff --git a/subiquity/models/snaplist.py b/subiquity/models/snaplist.py index 69ead77c..e00534e4 100644 --- a/subiquity/models/snaplist.py +++ b/subiquity/models/snaplist.py @@ -93,3 +93,15 @@ class SnapListModel: for selection in selections: self._snap_for_name(selection.name) self.selections = selections + + def make_cloudconfig(self): + if not self.selections: + return {} + cmds = [] + for selection in self.selections: + cmd = ['snap', 'install', '--channel=' + selection.channel] + if selection.is_classic: + cmd.append('--classic') + cmd.append(selection.name) + cmds.append(' '.join(cmd)) + return {'snap': {'commands': cmds}} diff --git a/subiquity/models/ssh.py b/subiquity/models/ssh.py index f6f6ed05..ffa55801 100644 --- a/subiquity/models/ssh.py +++ b/subiquity/models/ssh.py @@ -15,7 +15,6 @@ import logging - log = logging.getLogger("subiquity.models.ssh") diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index acb1d858..bb201e0b 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -175,14 +175,10 @@ class SubiquityModel: return groups def _cloud_init_config(self): - locale = self.locale.selected_language - if '.' not in locale and '_' in locale: - locale += '.UTF-8' config = { 'growpart': { 'mode': 'off', }, - 'locale': locale, 'resize_rootfs': False, } if self.identity.hostname is not None: @@ -215,17 +211,10 @@ class SubiquityModel: config['ssh_authorized_keys'] = self.ssh.authorized_keys if self.ssh.install_server: config['ssh_pwauth'] = self.ssh.pwauth - if self.snaplist.selections: - cmds = [] - for selection in self.snaplist.selections: - cmd = ['snap', 'install', '--channel=' + selection.channel] - if selection.is_classic: - cmd.append('--classic') - cmd.append(selection.name) - cmds.append(' '.join(cmd)) - config['snap'] = { - 'commands': cmds, - } + for model_name in POSTINSTALL_MODEL_NAMES: + model = getattr(self, model_name) + if getattr(model, 'make_cloudconfig', None): + merge_config(config, model.make_cloudconfig()) userdata = copy.deepcopy(self.userdata) merge_config(userdata, config) return userdata