summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacek Galowicz <jacek@galowicz.de>2019-11-05 14:35:10 +0100
committerJacek Galowicz <jacek@galowicz.de>2019-11-05 18:07:00 +0100
commit9c54658226e99b4edfbb0d570d547a147d7d9eb4 (patch)
tree5550dde527d23fae2508dd8da580030f164d6a64
parentfa2909bf51c29d568dd9ce5c27cdbf7393644909 (diff)
downloadnixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar.gz
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar.bz2
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar.lz
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar.xz
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.tar.zst
nixpkgs-9c54658226e99b4edfbb0d570d547a147d7d9eb4.zip
nixos/tests: Implement python test-driver version of requireActiveUnit
-rw-r--r--nixos/lib/test-driver/test-driver.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py
index 45b7e229a5c..2c137ab3837 100644
--- a/nixos/lib/test-driver/test-driver.py
+++ b/nixos/lib/test-driver/test-driver.py
@@ -4,7 +4,9 @@ from contextlib import contextmanager
 from xml.sax.saxutils import XMLGenerator
 import _thread
 import atexit
+import json
 import os
+import ptpython.repl
 import pty
 import queue
 import re
@@ -15,7 +17,6 @@ import sys
 import tempfile
 import time
 import unicodedata
-import ptpython.repl
 
 CHAR_TO_KEY = {
     "A": "shift-a",
@@ -344,6 +345,18 @@ class Machine:
             )
         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):
         self.connect()