Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,51 @@ on:

jobs:
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-26.04
steps:
- name: Repository checkout
uses: actions/checkout@v3
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v7
with:
python-version: "3.6"
python-version: "3.10"

- name: Install dependencies
run: |
pip install --upgrade pip tox
python -m pip install --upgrade pip tox

- name: Lint
run: |
tox -e lint

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-26.04
strategy:
matrix:
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
steps:
- name: Repository checkout
uses: actions/checkout@v3
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install --upgrade pip tox codecov
python -m pip install --upgrade pip tox

- name: Test
run: |
tox -e py3
codecov
run: tox -e py3

- name: Upload coverage
uses: codecov/codecov-action@v7
with:
fail_ci_if_error: false
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ It's pretty easy to start hacking on _python-libmaas_:
$ make develop
$ make test

The unit tests can also be run directly with `python3 -m tox -e py3`.

Installing [IPython][] is generally a good idea too:

$ bin/pip install -UI IPython
Expand Down
4 changes: 3 additions & 1 deletion maas/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__import__("pkg_resources").declare_namespace(__name__)
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
8 changes: 5 additions & 3 deletions maas/client/bones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ def __init__(self, request, response, content, call):
desc = "%s -> %s (%s)" % (
desc_for_request,
desc_for_response,
desc_for_content
if len(desc_for_content) <= 50
else (desc_for_content[:49] + "…"),
(
desc_for_content
if len(desc_for_content) <= 50
else (desc_for_content[:49] + "…")
),
)
super(CallError, self).__init__(desc)
self.request = request
Expand Down
9 changes: 4 additions & 5 deletions maas/client/bones/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import http
import http.server
import json
from importlib.resources import files
from operator import itemgetter
from pathlib import Path
import re
import threading

import fixtures
from pkg_resources import resource_filename, resource_listdir


def list_api_descriptions():
Expand All @@ -21,13 +20,13 @@ def list_api_descriptions():
must match "apiXX.json" where "XX" denotes the major and minor version
number of the API.
"""
for filename in resource_listdir(__name__, "."):
for resource in files(__package__).iterdir():
filename = resource.name
match = re.match(r"api(\d)(\d)[.]json", filename)
if match is not None:
version = tuple(map(int, match.groups()))
path = resource_filename(__name__, filename)
name = "%d.%d" % version
yield name, version, Path(path)
yield name, version, resource


def load_api_descriptions():
Expand Down
2 changes: 1 addition & 1 deletion maas/client/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Custom errors for libmaas """
"""Custom errors for libmaas"""

__all__ = ["MAASException", "OperationNotAllowed"]

Expand Down
1 change: 0 additions & 1 deletion maas/client/flesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from ..utils.auth import try_getpass
from ..utils.profiles import Profile, ProfileStore


PROG_DESCRIPTION = """\
MAAS provides complete automation of your physical servers for amazing data
center operational efficiency.
Expand Down
4 changes: 2 additions & 2 deletions maas/client/flesh/tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_returns_table_with_controllers(self):
output = yaml.safe_load(
cmd.execute(origin, options, target=tabular.RenderTarget.yaml)
)
self.assertEquals(
self.assertEqual(
[
{"name": "hostname", "title": "Hostname"},
{"name": "node_type", "title": "Type"},
Expand All @@ -93,7 +93,7 @@ def test_returns_table_with_controllers(self):
}
for controller in racks + regions
}
self.assertEquals(
self.assertEqual(
sorted(controller_output.values(), key=itemgetter("hostname")),
output["data"],
)
Expand Down
4 changes: 2 additions & 2 deletions maas/client/flesh/tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_returns_table_with_devices(self):
output = yaml.safe_load(
cmd.execute(origin, options, target=tabular.RenderTarget.yaml)
)
self.assertEquals(
self.assertEqual(
[
{"name": "hostname", "title": "Hostname"},
{"name": "owner", "title": "Owner"},
Expand All @@ -76,7 +76,7 @@ def test_returns_table_with_devices(self):
],
key=itemgetter("hostname"),
)
self.assertEquals(devices_output, output["data"])
self.assertEqual(devices_output, output["data"])

def test_calls_handler_with_hostnames(self):
origin = make_origin()
Expand Down
4 changes: 2 additions & 2 deletions maas/client/flesh/tests/test_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_returns_table_with_machines(self):
output = yaml.safe_load(
cmd.execute(origin, options, target=tabular.RenderTarget.yaml)
)
self.assertEquals(
self.assertEqual(
[
{"name": "hostname", "title": "Hostname"},
{"name": "power", "title": "Power"},
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_returns_table_with_machines(self):
],
key=itemgetter("hostname"),
)
self.assertEquals(machines_output, output["data"])
self.assertEqual(machines_output, output["data"])

def test_calls_handler_with_hostnames(self):
origin = make_origin()
Expand Down
4 changes: 2 additions & 2 deletions maas/client/flesh/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_returns_table_with_nodes(self):
output = yaml.safe_load(
cmd.execute(origin, options, target=tabular.RenderTarget.yaml)
)
self.assertEquals(
self.assertEqual(
[
{"name": "hostname", "title": "Hostname"},
{"name": "node_type", "title": "Type"},
Expand All @@ -65,7 +65,7 @@ def test_returns_table_with_nodes(self):
],
key=itemgetter("hostname"),
)
self.assertEquals(nodes_output, output["data"])
self.assertEqual(nodes_output, output["data"])

def test_calls_handler_with_hostnames(self):
origin = make_origin()
Expand Down
6 changes: 2 additions & 4 deletions maas/client/flesh/tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def test_print_whats_next(self):
profile = make_profile()
stdout = self.patch(sys, "stdout", StringIO())
profiles.cmd_login.print_whats_next(profile)
expected = dedent(
"""\
expected = dedent("""\
Congratulations! You are logged in to the MAAS
server at {profile.url} with the profile name
{profile.name}.
Expand All @@ -61,7 +60,6 @@ def test_print_whats_next(self):

maas help

"""
).format(profile=profile)
""").format(profile=profile)
observed = stdout.getvalue()
self.assertDocTestMatches(expected, observed)
1 change: 0 additions & 1 deletion maas/client/flesh/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_offers_profile_name_option_when_profiles_exist(self):
self.assertThat(options.profile_name, Equals(profile_name))

# Other profile names are not permitted.
self.patch(subparser, "error").side_effect = Exception
profile_name = make_name_without_spaces("foo")
error = capture_parse_error(subparser, "--profile-name", profile_name)
self.assertThat(
Expand Down
10 changes: 3 additions & 7 deletions maas/client/flesh/tests/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@


def capture_parse_error(parser, *args):
"""Capture the `ArgumentError` arising from parsing the given arguments.

`argparse` is hard to test (and to introspect, and extend... but it is
good at what it does) so we have to use a pseudo-private method here.
"""
namespace = argparse.Namespace()
"""Capture `argparse.ArgumentError` using the public parsing API."""
parser.exit_on_error = False
try:
parser._parse_known_args(list(args), namespace)
parser.parse_args(args)
except argparse.ArgumentError as error:
return error
else:
Expand Down
1 change: 0 additions & 1 deletion maas/client/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

from ..utils.maas_async import Asynchronous


random_letters = map(random.choice, repeat(string.ascii_letters + string.digits))

random_letters_with_spaces = map(
Expand Down
1 change: 0 additions & 1 deletion maas/client/utils/creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from collections import namedtuple
import typing


CredentialsBase = namedtuple(
"CredentialsBase", ("consumer_key", "token_key", "token_secret")
)
Expand Down
16 changes: 4 additions & 12 deletions maas/client/utils/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,25 @@ def schema_create(conn):

:param conn: A connection to an SQLite3 database.
"""
conn.execute(
dedent(
"""\
conn.execute(dedent("""\
CREATE TABLE IF NOT EXISTS profiles
(id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
data BLOB NOT NULL,
selected BOOLEAN NOT NULL DEFAULT FALSE)
"""
)
)
"""))
# Partial indexes are only available in >=3.8.0 and expressions in indexes
# are only available in >=3.9.0 (https://www.sqlite.org/partialindex.html
# & https://www.sqlite.org/expridx.html). Don't bother with any kind of
# index before that because it would complicate upgrades.
if sqlite3.sqlite_version_info >= (3, 9, 0):
# This index is for data integrity -- ensuring that only one profile
# is the default ("selected") profile -- and speed a distant second.
conn.execute(
dedent(
"""\
conn.execute(dedent("""\
CREATE UNIQUE INDEX IF NOT EXISTS
only_one_profile_selected ON profiles
(selected IS NOT NULL) WHERE selected
"""
)
)
"""))


def schema_import(conn, dbpath):
Expand Down
8 changes: 3 additions & 5 deletions maas/client/utils/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ def test_unwrapping(self):
"Title over two lines",
"Paragraph over\ntwo lines\n\n" "Another paragraph\nover two lines",
),
utils.parse_docstring(
"""
utils.parse_docstring("""
Title over
two lines

Expand All @@ -378,8 +377,7 @@ def test_unwrapping(self):

Another paragraph
over two lines
"""
),
"""),
)

def test_gets_docstring_from_function(self):
Expand Down Expand Up @@ -550,4 +548,4 @@ class TestRemoveNone(TestCase):

def test_removes_all_None_values(self):
data = {"None": None, "another_None": None, "keep": "value"}
self.assertEquals({"keep": "value"}, utils.remove_None(data))
self.assertEqual({"keep": "value"}, utils.remove_None(data))
1 change: 0 additions & 1 deletion maas/client/utils/tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .. import maas_async
from ...testing import TestCase


IsAwaitable = MatchesPredicate(isawaitable, "%s is not awaitable")


Expand Down
8 changes: 4 additions & 4 deletions maas/client/utils/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ class TestCalculateDictDiff(TestCase):
def test_calcs_no_difference(self):
orig_data = {"key1": "value1", "key2": "value2"}
new_data = copy.deepcopy(orig_data)
self.assertEquals({}, calculate_dict_diff(orig_data, new_data))
self.assertEqual({}, calculate_dict_diff(orig_data, new_data))

def test_calcs_changed_value(self):
orig_data = {"key1": "value1", "key2": "value2"}
new_data = copy.deepcopy(orig_data)
new_data["key2"] = "new_value"
self.assertEquals(
self.assertEqual(
{"key2": "new_value"}, calculate_dict_diff(orig_data, new_data)
)

def test_calcs_deleted_value(self):
orig_data = {"key1": "value1", "key2": "value2"}
new_data = copy.deepcopy(orig_data)
del new_data["key2"]
self.assertEquals({"key2": ""}, calculate_dict_diff(orig_data, new_data))
self.assertEqual({"key2": ""}, calculate_dict_diff(orig_data, new_data))

def test_calcs_changes_and_deleted(self):
orig_data = {"key1": "value1", "key2": "value2"}
new_data = copy.deepcopy(orig_data)
new_data["key1"] = "new_value"
del new_data["key2"]
self.assertEquals(
self.assertEqual(
{"key1": "new_value", "key2": ""}, calculate_dict_diff(orig_data, new_data)
)
1 change: 0 additions & 1 deletion maas/client/viscera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from ..utils import get_all_subclasses, vars_class
from ..utils.maas_async import Asynchronous


undefined = object()


Expand Down
1 change: 0 additions & 1 deletion maas/client/viscera/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from ..utils import remove_None
from ..utils.diff import calculate_dict_diff


FabricParam = typing.Union[str, int, Fabric]
InterfaceParam = typing.Union[str, int, Interface]
SubnetParam = typing.Union[str, int, Subnet]
Expand Down
Loading
Loading