From b5bbb76900f35139e39ce3e648a0bdbb2cbae525 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 13 Feb 2024 12:08:09 +0100 Subject: [PATCH] ubuntu-pro: consume general info and show on the UI Signed-off-by: Olivier Gayot --- .../controllers/tests/test_ubuntu_pro.py | 8 +++---- subiquity/client/controllers/ubuntu_pro.py | 2 ++ subiquity/ui/views/ubuntu_pro.py | 23 +++++++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/subiquity/client/controllers/tests/test_ubuntu_pro.py b/subiquity/client/controllers/tests/test_ubuntu_pro.py index 2fbd8b5d..d120b2a4 100644 --- a/subiquity/client/controllers/tests/test_ubuntu_pro.py +++ b/subiquity/client/controllers/tests/test_ubuntu_pro.py @@ -14,7 +14,7 @@ # along with this program. If not, see . 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.common.types import UbuntuProResponse @@ -43,7 +43,7 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase): await ctrler.make_ui() 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") @@ -76,7 +76,7 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase): view.assert_called_once() 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") @@ -98,5 +98,5 @@ class TestUbuntuProController(unittest.IsolatedAsyncioTestCase): view.assert_called_once() view.assert_called_once_with( - ctrler, token="", has_network=False, pre_release=True + ctrler, token="", has_network=False, pre_release=True, info=ANY ) diff --git a/subiquity/client/controllers/ubuntu_pro.py b/subiquity/client/controllers/ubuntu_pro.py index 36ae05fe..378bdaeb 100644 --- a/subiquity/client/controllers/ubuntu_pro.py +++ b/subiquity/client/controllers/ubuntu_pro.py @@ -77,11 +77,13 @@ class UbuntuProController(SubiquityTuiController): raise Skip("Not running LTS version") ubuntu_pro_info: UbuntuProResponse = await self.endpoint.GET() + general_info = await self.endpoint.info.GET() return UbuntuProView( self, token=ubuntu_pro_info.token, has_network=ubuntu_pro_info.has_network, pre_release=pre_release, + info=general_info, ) async def run_answers(self) -> None: diff --git a/subiquity/ui/views/ubuntu_pro.py b/subiquity/ui/views/ubuntu_pro.py index 6ae2f84d..3fb602b5 100644 --- a/subiquity/ui/views/ubuntu_pro.py +++ b/subiquity/ui/views/ubuntu_pro.py @@ -21,7 +21,11 @@ from typing import Callable, List 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.container import ListBox, Pile, WidgetWrap from subiquitycore.ui.form import ( @@ -270,12 +274,21 @@ class UbuntuProView(BaseView): title = _("Upgrade to Ubuntu Pro") 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.""" self.controller = controller self.has_network = has_network self.pre_release = pre_release + self.info = info if self.has_network: self.upgrade_yes_no_form = UpgradeYesNoForm( @@ -380,7 +393,7 @@ class UbuntuProView(BaseView): | [ Back ] | +---------------------------------------------------------+ """ - security_updates_until = 2032 + security_updates_until = self.info.eol_esm_year or "20xx" excerpt = _( "Upgrade this machine to Ubuntu Pro for security updates" @@ -815,8 +828,8 @@ class AboutProWidget(Stretchy): " patches covering a wider range of packages." ) - universe_packages = 23000 - main_packages = 2300 + universe_packages = self.parent.info.universe_packages + main_packages = self.parent.info.main_packages services = [ _(