Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixops
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bff60a385398^
Choose a base ref
...
head repository: NixOS/nixops
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2004c7c06403
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Feb 3, 2021

  1. Add some type annotations

    roberth authored and adisbladis committed Feb 3, 2021
    Copy the full SHA
    bff60a3 View commit details
  2. Copy the full SHA
    2004c7c View commit details
Showing with 31 additions and 20 deletions.
  1. +31 −20 nixops/backends/__init__.py
51 changes: 31 additions & 20 deletions nixops/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,17 @@
from __future__ import annotations
import os
import re
from typing import Mapping, Any, List, Optional, Union, Sequence, TypeVar, Callable
from typing import (
Mapping,
Match,
Any,
List,
Optional,
Union,
Sequence,
TypeVar,
Callable,
)
from nixops.monkey import Protocol, runtime_checkable
import nixops.util
import nixops.resources
@@ -198,18 +208,18 @@ def _check(self, res): # TODO -> None but supertype ResourceState -> True

# Get the systemd units that are in a failed state or in progress.
# cat to inhibit color output.
out = self.run_command(
out: List[str] = str(self.run_command(
"systemctl --all --full --no-legend | cat", capture_stdout=True
).split("\n")
)).split("\n")
res.failed_units = []
res.in_progress_units = []
for raw_line in out:
# All this string processing is fragile.
# NixOS 20.09 and later support systemctl --output json
# Alternatively, we *could* talk to DBus which has always been
# the first-class API.
line = raw_line.strip(" ●")
match = re.match("^([^ ]+) .* failed .*$", line)
line: str = raw_line.strip(" ●")
match: Optional[Match[str]] = re.match("^([^ ]+) .* failed .*$", line)
if match:
res.failed_units.append(match.group(1))

@@ -224,22 +234,23 @@ def _check(self, res): # TODO -> None but supertype ResourceState -> True
# /sys/kernel/config and /tmp. Systemd tries to mount these
# even when they don't exist.
match = re.match("^([^\.]+\.mount) .* inactive .*$", line) # noqa: W605
if (
match
and not match.group(1).startswith("sys-")
and not match.group(1).startswith("dev-")
and not match.group(1) == "tmp.mount"
):
res.failed_units.append(match.group(1))

if match and match.group(1) == "tmp.mount":
try:
self.run_command(
"cat /etc/fstab | cut -d' ' -f 2 | grep '^/tmp$' &> /dev/null"
)
except Exception:
continue
res.failed_units.append(match.group(1))
if match:
unit = match.group(1)
isSystemMount = unit.startswith("sys-") or unit.startswith("dev-")
isBuiltinMount = unit == "tmp.mount" or unit == "home.mount"

if not isSystemMount and not isBuiltinMount:
res.failed_units.append(unit)

if isBuiltinMount:
try:
self.run_command(
"cat /etc/fstab | cut -d' ' -f 2 | grep '^/tmp$' &> /dev/null"
)
except Exception:
continue
res.failed_units.append(unit)

def restore(self, defn, backup_id: Optional[str], devices: List[str] = []):
"""Restore persistent disks to a given backup, if possible."""