From 00bf3dc6cdb381471c7e8a2627723c9f1766ac4a Mon Sep 17 00:00:00 2001 From: Lucas Moura Date: Tue, 24 Oct 2023 15:20:53 -0300 Subject: [PATCH] plan: fix error when variable is not set There is a corner case scenario where we end up with a src_pocket_pkgs variable unset. We are now fixing this issue by using a default value for this variable --- features/api_fix_plan.feature | 16 ++++++++++++++++ uaclient/api/u/pro/security/fix/__init__.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/features/api_fix_plan.feature b/features/api_fix_plan.feature index 8e476783e2..a82817ba9a 100644 --- a/features/api_fix_plan.feature +++ b/features/api_fix_plan.feature @@ -237,3 +237,19 @@ Feature: Fix plan API endpoints Examples: ubuntu release details | release | | bionic | + + @series.mantic + @uses.config.machine_type.lxd-vm + Scenario Outline: Fix command on an unattached machine + Given a `` machine with ubuntu-advantage-tools installed + When I run `pro api u.pro.security.fix.cve.plan.v1 --data '{"cves": ["CVE-2022-40982"]}'` as non-root + Then stdout is a json matching the `api_response` schema + And the json API response data matches the `cve_fix_plan` schema + And stdout matches regexp: + """ + {"_schema_version": "v1", "data": {"attributes": {"cves_data": {"cves": \[{"additional_data": {}, "affected_packages": \["linux"\], "description": ".*", "error": null, "expected_status": "still-affected", "plan": \[\], "title": "CVE-2022-40982", "warnings": \[{"data": {"source_packages": \["linux"\], "status": "pending"}, "order": 1, "warning_type": "security-issue-not-fixed"}\]}\], "expected_status": "still-affected"}}, "meta": {"environment_vars": \[\]}, "type": "CVEFixPlan"}, "errors": \[\], "result": "success", "version": ".*", "warnings": \[\]} + """ + + Examples: ubuntu release details + | release | + | mantic | diff --git a/uaclient/api/u/pro/security/fix/__init__.py b/uaclient/api/u/pro/security/fix/__init__.py index e0ad2c7e16..9639cbafee 100644 --- a/uaclient/api/u/pro/security/fix/__init__.py +++ b/uaclient/api/u/pro/security/fix/__init__.py @@ -792,6 +792,8 @@ def _generate_fix_plan( additional_data=None ) -> FixPlanResult: count = len(affected_pkg_status) + src_pocket_pkgs = defaultdict(list) + fix_plan = get_fix_plan( title=issue_id, description=issue_description,