ubuntu-pro: consume general info and show on the UI

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2024-02-13 12:08:09 +01:00
parent a42ea0a685
commit b5bbb76900
3 changed files with 24 additions and 9 deletions

View File

@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest import unittest
from unittest.mock import AsyncMock, patch from unittest.mock import ANY, AsyncMock, patch
from subiquity.client.controllers.ubuntu_pro import UbuntuProController from subiquity.client.controllers.ubuntu_pro import UbuntuProController
from subiquity.common.types import UbuntuProResponse from subiquity.common.types import UbuntuProResponse
@ -43,7 +43,7 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase):
await ctrler.make_ui() await ctrler.make_ui()
view.assert_called_once_with( view.assert_called_once_with(
ctrler, token="", has_network=False, pre_release=False ctrler, token="", has_network=False, pre_release=False, info=ANY
) )
@patch("subiquity.client.controllers.ubuntu_pro.UbuntuProView") @patch("subiquity.client.controllers.ubuntu_pro.UbuntuProView")
@ -76,7 +76,7 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase):
view.assert_called_once() view.assert_called_once()
view.assert_called_once_with( view.assert_called_once_with(
ctrler, token="", has_network=False, pre_release=True ctrler, token="", has_network=False, pre_release=True, info=ANY
) )
@patch("subiquity.client.controllers.ubuntu_pro.UbuntuProView") @patch("subiquity.client.controllers.ubuntu_pro.UbuntuProView")
@ -98,5 +98,5 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase):
view.assert_called_once() view.assert_called_once()
view.assert_called_once_with( view.assert_called_once_with(
ctrler, token="", has_network=False, pre_release=True ctrler, token="", has_network=False, pre_release=True, info=ANY
) )

View File

@ -77,11 +77,13 @@ class UbuntuProController(SubiquityTuiController):
raise Skip("Not running LTS version") raise Skip("Not running LTS version")
ubuntu_pro_info: UbuntuProResponse = await self.endpoint.GET() ubuntu_pro_info: UbuntuProResponse = await self.endpoint.GET()
general_info = await self.endpoint.info.GET()
return UbuntuProView( return UbuntuProView(
self, self,
token=ubuntu_pro_info.token, token=ubuntu_pro_info.token,
has_network=ubuntu_pro_info.has_network, has_network=ubuntu_pro_info.has_network,
pre_release=pre_release, pre_release=pre_release,
info=general_info,
) )
async def run_answers(self) -> None: async def run_answers(self) -> None:

View File

@ -21,7 +21,11 @@ from typing import Callable, List
from urwid import Columns, LineBox, Text, Widget, connect_signal from urwid import Columns, LineBox, Text, Widget, connect_signal
from subiquity.common.types import UbuntuProCheckTokenStatus, UbuntuProSubscription from subiquity.common.types import (
UbuntuProCheckTokenStatus,
UbuntuProGeneralInfo,
UbuntuProSubscription,
)
from subiquitycore.ui.buttons import back_btn, cancel_btn, done_btn, menu_btn, ok_btn from subiquitycore.ui.buttons import back_btn, cancel_btn, done_btn, menu_btn, ok_btn
from subiquitycore.ui.container import ListBox, Pile, WidgetWrap from subiquitycore.ui.container import ListBox, Pile, WidgetWrap
from subiquitycore.ui.form import ( from subiquitycore.ui.form import (
@ -270,12 +274,21 @@ class UbuntuProView(BaseView):
title = _("Upgrade to Ubuntu Pro") title = _("Upgrade to Ubuntu Pro")
subscription_done_label = _("Continue") subscription_done_label = _("Continue")
def __init__(self, controller, token: str, has_network: bool, *, pre_release=False): def __init__(
self,
controller,
token: str,
has_network: bool,
*,
pre_release=False,
info: UbuntuProGeneralInfo,
):
"""Initialize the view with the default value for the token.""" """Initialize the view with the default value for the token."""
self.controller = controller self.controller = controller
self.has_network = has_network self.has_network = has_network
self.pre_release = pre_release self.pre_release = pre_release
self.info = info
if self.has_network: if self.has_network:
self.upgrade_yes_no_form = UpgradeYesNoForm( self.upgrade_yes_no_form = UpgradeYesNoForm(
@ -380,7 +393,7 @@ class UbuntuProView(BaseView):
| [ Back ] | | [ Back ] |
+---------------------------------------------------------+ +---------------------------------------------------------+
""" """
security_updates_until = 2032 security_updates_until = self.info.eol_esm_year or "20xx"
excerpt = _( excerpt = _(
"Upgrade this machine to Ubuntu Pro for security updates" "Upgrade this machine to Ubuntu Pro for security updates"
@ -815,8 +828,8 @@ class AboutProWidget(Stretchy):
" patches covering a wider range of packages." " patches covering a wider range of packages."
) )
universe_packages = 23000 universe_packages = self.parent.info.universe_packages
main_packages = 2300 main_packages = self.parent.info.main_packages
services = [ services = [
_( _(