nixos/tests: Implement python test-driver version of requireActiveUnit
This commit is contained in:
parent
fa2909bf51
commit
9c54658226
|
@ -4,7 +4,9 @@ from contextlib import contextmanager
|
||||||
from xml.sax.saxutils import XMLGenerator
|
from xml.sax.saxutils import XMLGenerator
|
||||||
import _thread
|
import _thread
|
||||||
import atexit
|
import atexit
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
import ptpython.repl
|
||||||
import pty
|
import pty
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
|
@ -15,7 +17,6 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import ptpython.repl
|
|
||||||
|
|
||||||
CHAR_TO_KEY = {
|
CHAR_TO_KEY = {
|
||||||
"A": "shift-a",
|
"A": "shift-a",
|
||||||
|
@ -344,6 +345,18 @@ class Machine:
|
||||||
)
|
)
|
||||||
return self.execute("systemctl {}".format(q))
|
return self.execute("systemctl {}".format(q))
|
||||||
|
|
||||||
|
def require_unit_state(self, unit, require_state="active"):
|
||||||
|
with self.nested(
|
||||||
|
"checking if unit ‘{}’ has reached state '{}'".format(unit, require_state)
|
||||||
|
):
|
||||||
|
info = self.get_unit_info(unit)
|
||||||
|
state = info["ActiveState"]
|
||||||
|
if state != require_state:
|
||||||
|
raise Exception(
|
||||||
|
"Expected unit ‘{}’ to to be in state ".format(unit)
|
||||||
|
+ "'active' but it is in state ‘{}’".format(state)
|
||||||
|
)
|
||||||
|
|
||||||
def execute(self, command):
|
def execute(self, command):
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue