Skip to content

Commit

Permalink
ui: fix journal parsing in ProgressView
Browse files Browse the repository at this point in the history
The ProgressView.other_event function splits messages on the ":"
character to get the context type and the message from journal messages.
This code will crash if the message has more than one ":" character.
When passing cloud-config with invalid top level keys, subiquity will
check these keys and report on the journal with a message:
"cloud-init schema validation failure for: <key1> [, <key2>, ...]",
which was causing the UI to crash repeatedly.

LP: #2080918
  • Loading branch information
Chris-Peterson444 committed Sep 17, 2024
1 parent 6727905 commit 6c743d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion subiquity/ui/views/installprogress.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def event_other(self, message: str, event_type: str) -> None:
#
# and we want to insert the event type between the colon and the
# event description
context, text = message.split(":")
context, text = message.split(":", maxsplit=1)
text = text.lstrip()
message = f"{context}: {event_type.upper()}: {text}"

Expand Down
27 changes: 27 additions & 0 deletions subiquity/ui/views/tests/test_installprogress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock
from unittest.mock import patch

from subiquity.client.controllers.progress import ProgressController
from subiquity.common.types import ApplicationState
Expand Down Expand Up @@ -53,3 +54,29 @@ def test_error_disambiguation(self):
self.assertIsNone(btn)
btn = view_helpers.find_button_matching(view, "^Restart Installer$")
self.assertIsNotNone(btn)

@patch("subiquity.ui.views.installprogress.Columns")
@patch("subiquity.ui.views.installprogress.Text")
def test_event_other_formatting(self, text_mock, columns_mock):
"""Test formatting of the other_event function."""
view = self.make_view()
text_mock.return_value = "mock text"
view.event_other("MOCK CONTEXT: message", "mock")
text_mock.assert_called_with("MOCK CONTEXT: MOCK: message")
columns_mock.assert_called_with(
[
("pack", "mock text"),
],
dividechars=1,
)

@patch("subiquity.ui.views.installprogress.Text")
def test_event_other_robust_splitting(self, text_mock):
"""Test that messages containing a colon don't fail to split.
event_other uses str.split(":"), make sure it doesn't cause an
error if more than one colon is present in the message.
"""
view = self.make_view()
view.event_other("MOCK CONTEXT: bad keys: 1, 2, 3", "mock")
text_mock.assert_called_with("MOCK CONTEXT: MOCK: bad keys: 1, 2, 3")

0 comments on commit 6c743d0

Please sign in to comment.