Skip to content

Commit fcb9de2

Browse files
committed
Add utility to parse base argument
1 parent 280f76d commit fcb9de2

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

juju/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import zipfile
1111

1212
from . import jasyncio, origin, errors
13+
from .client import client
1314

1415

1516
async def execute_process(*cmd, log=None):
@@ -403,3 +404,15 @@ def base_channel_to_series(channel):
403404
:return: str series (e.g. focal)
404405
"""
405406
return get_version_series(origin.Channel.parse(channel).track)
407+
408+
409+
def parse_base_arg(base):
410+
"""Parses a given base into a Client.Base object
411+
:param base str : The base to deploy a charm (e.g. ubuntu@22.04)
412+
"""
413+
client.CharmBase()
414+
if type(base) != str or "@" not in base:
415+
raise errors.JujuError("expected base string to contain os and channel separated by '@'")
416+
417+
name, channel = base.split('@')
418+
return client.Base(name=name, channel=channel)

tests/unit/test_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22

3-
from juju.utils import juju_config_dir, juju_ssh_key_paths
3+
from juju.utils import juju_config_dir, juju_ssh_key_paths, parse_base_arg
4+
from juju.client import client
45

56

67
class TestDirResolve(unittest.TestCase):
@@ -12,3 +13,9 @@ def test_juju_ssh_key_paths(self):
1213
public, private = juju_ssh_key_paths()
1314
assert public.endswith('ssh/juju_id_rsa.pub')
1415
assert private.endswith('ssh/juju_id_rsa')
16+
17+
def test_parse_base_arg(self):
18+
base = parse_base_arg('ubuntu@22.04')
19+
assert isinstance(base, client.Base)
20+
assert base.name == 'ubuntu'
21+
assert base.channel == '22.04'

0 commit comments

Comments
 (0)