sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #06500
[Merge] ~ack/maas:lint-scripts into maas:master
Alberto Donato has proposed merging ~ack/maas:lint-scripts into maas:master.
Commit message:
add python files under scripts/ to linted files, upgrade them to python3.10
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/439747
--
Your team MAAS Maintainers is requested to review the proposed merge of ~ack/maas:lint-scripts into maas:master.
diff --git a/scripts/maas-delete-file b/scripts/maas-delete-file
index f628e7c..128ff86 100755
--- a/scripts/maas-delete-file
+++ b/scripts/maas-delete-file
@@ -14,7 +14,6 @@ import pipes
from provisioningserver.utils.fs import atomic_delete
-
DELETABLE_FILES = {
os.path.join(os.getenv("MAAS_DATA", "/var/lib/maas"), path)
for path in ("dhcpd.conf", "dhcpd6.conf")
@@ -25,15 +24,14 @@ arg_parser.add_argument("filename", help="The file to delete.")
def main(args):
-
# Validate the filename here because using a `choices` argument in the
# parser results in ugly help and error text.
if args.filename not in DELETABLE_FILES:
arg_parser.error(
- "Given filename %s is not in the allowed list. "
- "Choose from: %s." % (
- pipes.quote(args.filename), ", ".join(
- map(pipes.quote, sorted(DELETABLE_FILES)))))
+ f"Given filename {pipes.quote(args.filename)} is not in the "
+ "allowed list. "
+ f"Choose from: {', '.join(map(pipes.quote, sorted(DELETABLE_FILES)))} ."
+ )
# Okay, good to go.
else:
diff --git a/scripts/maas-dhcp-helper b/scripts/maas-dhcp-helper
index c03fc8b..bb18aa2 100755
--- a/scripts/maas-dhcp-helper
+++ b/scripts/maas-dhcp-helper
@@ -24,27 +24,45 @@ def notify_add_arguments(parser):
:param parser: An instance of :class:`ArgumentParser`.
"""
parser.add_argument(
- "--action", action="store", required=True,
- choices=['commit', 'expiry', 'release'], help=(
- "Action taken by DHCP server for the lease."))
+ "--action",
+ action="store",
+ required=True,
+ choices=["commit", "expiry", "release"],
+ help=("Action taken by DHCP server for the lease."),
+ )
parser.add_argument(
- "--mac", action="store", required=True, help=(
- "MAC address for lease."))
+ "--mac", action="store", required=True, help=("MAC address for lease.")
+ )
parser.add_argument(
- "--ip-family", action="store", required=True, choices=['ipv4', 'ipv6'],
- help="IP address family for lease.")
+ "--ip-family",
+ action="store",
+ required=True,
+ choices=["ipv4", "ipv6"],
+ help="IP address family for lease.",
+ )
parser.add_argument(
- "--ip", action="store", required=True, help=(
- "IP address for lease."))
+ "--ip", action="store", required=True, help=("IP address for lease.")
+ )
parser.add_argument(
- "--lease-time", action="store", type=int, required=False, help=(
- "Length of time before the lease expires."))
+ "--lease-time",
+ action="store",
+ type=int,
+ required=False,
+ help=("Length of time before the lease expires."),
+ )
parser.add_argument(
- "--hostname", action="store", required=False, help=(
- "Hostname of the machine for the lease."))
+ "--hostname",
+ action="store",
+ required=False,
+ help=("Hostname of the machine for the lease."),
+ )
parser.add_argument(
- "--socket", action="store", required=False,
- default="/var/lib/maas/dhcpd.sock", help=argparse.SUPPRESS)
+ "--socket",
+ action="store",
+ required=False,
+ default="/var/lib/maas/dhcpd.sock",
+ help=argparse.SUPPRESS,
+ )
def notify(args):
@@ -69,9 +87,10 @@ def notify(args):
notify_packet["lease_time"] = args.lease_time
hostname = args.hostname
has_hostname = (
- hostname is not None and
- len(hostname) > 0 and
- not hostname.isspace())
+ hostname is not None
+ and len(hostname) > 0
+ and not hostname.isspace()
+ )
if has_hostname:
notify_packet["hostname"] = hostname
@@ -89,8 +108,10 @@ def clean_add_arguments(parser):
:param parser: An instance of :class:`ArgumentParser`.
"""
parser.add_argument(
- "leases_file", action="store",
- help=("Leases file to remove host entries from."))
+ "leases_file",
+ action="store",
+ help=("Leases file to remove host entries from."),
+ )
def clean(args):
@@ -99,7 +120,7 @@ def clean(args):
# each command.
import re
- with open(args.leases_file, "r", encoding="utf-8") as fp:
+ with open(args.leases_file, encoding="utf-8") as fp:
content = fp.read()
cleaned_content = re.sub("host [^{]+{[^}]+}\n", "", content)
with open(args.leases_file, "w", encoding="utf-8") as fp:
@@ -115,13 +136,15 @@ def main():
# Notify.
notify_parser = subparsers.add_parser(
- "notify", help="Write DHCP action notification to the `dhcpd.sock`.")
+ "notify", help="Write DHCP action notification to the `dhcpd.sock`."
+ )
notify_parser.set_defaults(handler=notify)
notify_add_arguments(notify_parser)
# Clean.
clean_parser = subparsers.add_parser(
- "clean", help="Remove all host entries from leases file.")
+ "clean", help="Remove all host entries from leases file."
+ )
clean_parser.set_defaults(handler=clean)
clean_add_arguments(clean_parser)
diff --git a/tox.ini b/tox.ini
index 6191569..012e3a9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,7 @@
[files]
lint =
+ scripts/maas-delete-file \
+ scripts/maas-dhcp-helper \
setup.py \
src/apiclient \
src/maascli \
Follow ups