Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix when cloud-config has no default user #1687

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion subiquity/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,10 @@ def use_passwd(passwd):

self.installer_user_name = username

if self._user_has_password(username):
if username is None:
# extract_default can return None, if there is no default user
self.installer_user_passwd_kind = PasswordKind.NONE
elif self._user_has_password(username):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, so the error we are avoiding here is _user_has_password fails with something like:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's exactly what happens

# Was the password set to a random password by a version of
# cloud-init that records the username in the log? (This is the
# case we hit on upgrading the subiquity snap)
Expand Down
26 changes: 25 additions & 1 deletion subiquity/server/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import os
import shlex
from unittest.mock import Mock
from unittest.mock import Mock, patch

from subiquitycore.utils import run_command
from subiquitycore.tests import SubiTestCase
Expand All @@ -27,6 +27,7 @@
iso_autoinstall_path,
root_autoinstall_path,
)
from subiquity.common.types import PasswordKind


class TestAutoinstallLoad(SubiTestCase):
Expand Down Expand Up @@ -150,3 +151,26 @@ async def test_interactive_sections_one(self):
mc = MetaController(make_app())
mc.app.autoinstall_config['interactive-sections'] = ['network']
self.assertEqual(['network'], await mc.interactive_sections_GET())


class TestDefaultUser(SubiTestCase):
@patch('subiquity.server.server.ug_util.normalize_users_groups',
Mock(return_value=(None, None)))
@patch('subiquity.server.server.ug_util.extract_default',
Mock(return_value=(None, None)))
@patch('subiquity.server.server.user_key_fingerprints',
Mock(side_effect=Exception('should not be called')))
async def test_no_default_user(self):
opts = Mock()
opts.dry_run = True
opts.output_base = self.tmp_dir()
opts.machine_config = 'examples/simple.json'
server = SubiquityServer(opts, None)
server.cloud = Mock()
server._user_has_password = Mock(
side_effect=Exception('should not be called'))

opts.dry_run = False # exciting!
server.set_installer_password()
self.assertIsNone(server.installer_user_name)
self.assertEqual(PasswordKind.NONE, server.installer_user_passwd_kind)