Skip to content

Commit

Permalink
fix snap: return empty ubuntu pro info for non-core snap to fix regis…
Browse files Browse the repository at this point in the history
…tration bug (#234)
  • Loading branch information
srunde3 committed Mar 28, 2024
1 parent e8db8d8 commit a88cd8e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions landscape/client/manager/tests/test_ubuntuproinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,31 @@ def test_persistence_reset(self):
self.assertEqual(2, len(messages))
self.assertTrue("ubuntu-pro-info" in messages[1])
self.assertEqual(messages[1]["ubuntu-pro-info"], data)

@mock.patch("landscape.client.manager.ubuntuproinfo.IS_SNAP", new=True)
def test_pro_client_not_called_for_snap(self):
"""
The snap will not currently allow calls to the pro client.
Ensure that get_ubuntu_pro_info returns an empty dictionary instead of
calling the subprocess for pro.
"""
ubuntu_pro_info = get_ubuntu_pro_info()
self.assertEqual({}, ubuntu_pro_info)

def test_mock_info_sent_for_core_snap(self):
"""
Ensure that a Core snap still receives mocked ubuntu pro info even if
the snap generally doesn't support *real* ubuntu pro info
"""
with mock.patch.multiple(
"landscape.client.manager.ubuntuproinfo",
IS_CORE=True,
IS_SNAP=True,
):
ubuntu_pro_info = get_ubuntu_pro_info()

self.assertIn("effective", ubuntu_pro_info)
self.assertIn("expires", ubuntu_pro_info)
contract = ubuntu_pro_info["contract"]
self.assertIn("landscape", contract["products"])
6 changes: 6 additions & 0 deletions landscape/client/manager/ubuntuproinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

from landscape.client import IS_CORE
from landscape.client import IS_SNAP
from landscape.client.manager.plugin import ManagerPlugin
from landscape.lib.persist import Persist

Expand Down Expand Up @@ -78,6 +79,11 @@ def get_ubuntu_pro_info() -> dict:
expiration_datetime,
)

if IS_SNAP:
# Snap does not support Ubuntu Pro Info and throws an error if `pro` is
# called.
return {}

try:
completed_process = subprocess.run(
["pro", "status", "--format", "json"],
Expand Down

0 comments on commit a88cd8e

Please sign in to comment.