Merge pull request #1158 from ogayot/bind-uac-into-subiquity-snap
Embed ubuntu-advantage-tools into Subiquity snap and use it
This commit is contained in:
commit
4a672e071e
|
@ -114,6 +114,7 @@ parts:
|
||||||
- python3-requests-unixsocket
|
- python3-requests-unixsocket
|
||||||
- python3-requests
|
- python3-requests
|
||||||
- python3-pyudev
|
- python3-pyudev
|
||||||
|
- ubuntu-advantage-tools
|
||||||
stage:
|
stage:
|
||||||
- "*"
|
- "*"
|
||||||
- -bin/python
|
- -bin/python
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from subiquitycore.async_helpers import schedule_task
|
from subiquitycore.async_helpers import schedule_task
|
||||||
|
|
||||||
|
@ -49,7 +50,12 @@ class UbuntuAdvantageController(SubiquityTuiController):
|
||||||
if app.opts.dry_run:
|
if app.opts.dry_run:
|
||||||
strategy = MockedUAInterfaceStrategy(scale_factor=app.scale_factor)
|
strategy = MockedUAInterfaceStrategy(scale_factor=app.scale_factor)
|
||||||
else:
|
else:
|
||||||
strategy = UAClientUAInterfaceStrategy()
|
# Make sure we execute `$PYTHON "$SNAP/usr/bin/ubuntu-advantage"`.
|
||||||
|
executable = (
|
||||||
|
os.environ["PYTHON"],
|
||||||
|
os.path.join(os.environ["SNAP"], "usr/bin/ubuntu-advantage"),
|
||||||
|
)
|
||||||
|
strategy = UAClientUAInterfaceStrategy(executable=executable)
|
||||||
self.ua_interface = UAInterface(strategy)
|
self.ua_interface = UAInterface(strategy)
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,22 @@ class TestMockedUAInterfaceStrategy(unittest.TestCase):
|
||||||
class TestUAClientUAInterfaceStrategy(unittest.TestCase):
|
class TestUAClientUAInterfaceStrategy(unittest.TestCase):
|
||||||
arun_command = "subiquity.common.ubuntu_advantage.utils.arun_command"
|
arun_command = "subiquity.common.ubuntu_advantage.utils.arun_command"
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
# Default initializer.
|
||||||
|
strategy = UAClientUAInterfaceStrategy()
|
||||||
|
self.assertEqual(strategy.executable, ["ubuntu-advantage"])
|
||||||
|
|
||||||
|
# Initialize with a mere path.
|
||||||
|
strategy = UAClientUAInterfaceStrategy("/usr/bin/ubuntu-advantage")
|
||||||
|
self.assertEqual(strategy.executable, ["/usr/bin/ubuntu-advantage"])
|
||||||
|
|
||||||
|
# Initialize with a path + interpreter.
|
||||||
|
strategy = UAClientUAInterfaceStrategy(
|
||||||
|
("python3", "/usr/bin/ubuntu-advantage")
|
||||||
|
)
|
||||||
|
self.assertEqual(strategy.executable,
|
||||||
|
["python3", "/usr/bin/ubuntu-advantage"])
|
||||||
|
|
||||||
def test_query_info_succeeded(self):
|
def test_query_info_succeeded(self):
|
||||||
strategy = UAClientUAInterfaceStrategy()
|
strategy = UAClientUAInterfaceStrategy()
|
||||||
command = (
|
command = (
|
||||||
|
|
|
@ -20,6 +20,7 @@ from datetime import datetime as dt
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from subprocess import CalledProcessError, CompletedProcess
|
from subprocess import CalledProcessError, CompletedProcess
|
||||||
|
from typing import List, Sequence, Union
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from subiquitycore import utils
|
from subiquitycore import utils
|
||||||
|
@ -96,12 +97,24 @@ class MockedUAInterfaceStrategy(UAInterfaceStrategy):
|
||||||
class UAClientUAInterfaceStrategy(UAInterfaceStrategy):
|
class UAClientUAInterfaceStrategy(UAInterfaceStrategy):
|
||||||
""" Strategy that relies on UA client script to retrieve the information.
|
""" Strategy that relies on UA client script to retrieve the information.
|
||||||
"""
|
"""
|
||||||
|
Executable = Union[str, Sequence[str]]
|
||||||
|
|
||||||
|
def __init__(self, executable: Executable = "ubuntu-advantage") -> None:
|
||||||
|
""" Initialize the strategy using the path to the ubuntu-advantage
|
||||||
|
executable we want to use. The executable can be specified as a
|
||||||
|
sequence of strings so that we can specify the interpret to use as
|
||||||
|
well.
|
||||||
|
"""
|
||||||
|
self.executable: List[str] = \
|
||||||
|
[executable] if isinstance(executable, str) else list(executable)
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
async def query_info(self, token: str) -> dict:
|
async def query_info(self, token: str) -> dict:
|
||||||
""" Return the subscription info associated with the supplied
|
""" Return the subscription info associated with the supplied
|
||||||
UA token. The information will be queried using UA client.
|
UA token. The information will be queried using the UA client
|
||||||
|
executable passed to the initializer.
|
||||||
"""
|
"""
|
||||||
command = (
|
command = tuple(self.executable) + (
|
||||||
"ubuntu-advantage",
|
|
||||||
"status",
|
"status",
|
||||||
"--format", "json",
|
"--format", "json",
|
||||||
"--simulate-with-token", token,
|
"--simulate-with-token", token,
|
||||||
|
|
Loading…
Reference in New Issue