Skip to content

Commit

Permalink
Merge pull request #1470 from hercules-ci/locking-usability
Browse files Browse the repository at this point in the history
Locking usability improvements
  • Loading branch information
roberth authored Nov 18, 2021
2 parents 4aebbb9 + 00eb6e3 commit 45c100e
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 133 deletions.
17 changes: 7 additions & 10 deletions nixops/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@
subparser.add_argument(
"args", metavar="SSH_ARGS", nargs=REMAINDER, help="SSH flags and/or command",
)
subparser.add_argument(
"--now",
dest="now",
action="store_true",
help="do not acquire a lock before fetching the state",
)

subparser = add_subparser(
subparsers, "ssh-for-each", help="execute a command on each machine via SSH"
Expand Down Expand Up @@ -443,14 +449,12 @@
"--freeze",
dest="freeze_fs",
action="store_true",
default=False,
help="freeze filesystems for non-root filesystems that support this (e.g. xfs)",
)
subparser.add_argument(
"--force",
dest="force",
action="store_true",
default=False,
help="start new backup even if previous is still running",
)
subparser.add_argument(
Expand Down Expand Up @@ -478,17 +482,12 @@
help="do not perform backup actions on the specified machines",
)
subparser.add_argument(
"--wait",
dest="wait",
action="store_true",
default=False,
help="wait until backup is finished",
"--wait", dest="wait", action="store_true", help="wait until backup is finished",
)
subparser.add_argument(
"--latest",
dest="latest",
action="store_true",
default=False,
help="show status of latest backup only",
)

Expand All @@ -498,7 +497,6 @@
subparser.add_argument(
"--keep-physical",
dest="keep_physical",
default=False,
action="store_true",
help="do not remove the physical backups, only remove backups from nixops state",
)
Expand All @@ -518,7 +516,6 @@
subparser.add_argument(
"--keep-physical",
dest="keep_physical",
default=False,
action="store_true",
help="do not remove the physical backups, only remove backups from nixops state",
)
Expand Down
39 changes: 26 additions & 13 deletions nixops/locks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,35 @@
from typing_extensions import Protocol


"""
Interface to a lock driver.
An implementation should inherit from LockDriver in order to for a plugin to be
able to integrate it.
"""


# This separation was introduced to hide the LockOptions details from the
# LockInterface type. It only matters for construction and clients don't have
# to know about it.
class LockInterface(Protocol):
# lock: acquire a lock.
# Note: no arguments will be passed over kwargs. Making it part of
# the type definition allows adding new arguments later.
def lock(self, description: str, exclusive: bool, **kwargs) -> None:
raise NotImplementedError

# unlock: release the lock.
# Note: no arguments will be passed over kwargs. Making it part of
# the type definition allows adding new arguments later.
def unlock(self, **kwargs) -> None:
raise NotImplementedError


LockOptions = TypeVar("LockOptions")


class LockDriver(Protocol[LockOptions]):
class LockDriver(LockInterface, Protocol[LockOptions]):
# Hack: Make T a mypy invariant. According to PEP-0544, a
# Protocol[T] whose T is only used in function arguments and
# returns is "de-facto covariant".
Expand All @@ -26,15 +51,3 @@ def options(**kwargs) -> LockOptions:

def __init__(self, args: LockOptions) -> None:
raise NotImplementedError

# lock: acquire a lock.
# Note: no arguments will be passed over kwargs. Making it part of
# the type definition allows adding new arguments later.
def lock(self, **kwargs) -> None:
raise NotImplementedError

# unlock: release the lock.
# Note: no arguments will be passed over kwargs. Making it part of
# the type definition allows adding new arguments later.
def unlock(self, **kwargs) -> None:
raise NotImplementedError
2 changes: 1 addition & 1 deletion nixops/locks/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def __init__(self, args: NoopLockOptions) -> None:
def unlock(self, **_kwargs) -> None:
pass

def lock(self, **_kwargs) -> None:
def lock(self, description, exclusive, **_kwargs) -> None:
pass
Loading

0 comments on commit 45c100e

Please sign in to comment.