Browse Source

qubes.tests asyncio, part 2

QubesOS/qubes-issues#2622
Wojtek Porczyk 7 years ago
parent
commit
42cbd9ff68
2 changed files with 12 additions and 2 deletions
  1. 8 1
      qubes/tests/__init__.py
  2. 4 1
      qubes/tests/integ/vm_qrexec_gui.py

+ 8 - 1
qubes/tests/__init__.py

@@ -245,7 +245,12 @@ class _QrexecPolicyContext(object):
             'allow' if allow else 'deny')
 
     def _change(self, add=True):
-        with self._filename.open('r+') as policy:
+        try:
+            policy = self._filename.open('r+')
+        except FileNotFoundError:
+            policy = self._filename.open('w+')
+
+        try:
             policy_rules = policy.readlines()
             if add:
                 policy_rules.insert(0, self._rule)
@@ -254,6 +259,8 @@ class _QrexecPolicyContext(object):
             policy.truncate(0)
             policy.seek(0)
             policy.write(''.join(policy_rules))
+        finally:
+            policy.close()
 
     def __enter__(self):
         self._change(add=True)

+ 4 - 1
qubes/tests/integ/vm_qrexec_gui.py

@@ -234,7 +234,10 @@ class TC_00_AppVMMixin(qubes.tests.SystemTestsMixin):
         @asyncio.coroutine
         def run(self):
             p = yield from self.testvm1.run(
-                    'echo test; exec >&-; cat > /dev/null')
+                    'echo test; exec >&-; cat > /dev/null',
+                    stdin=subprocess.PIPE,
+                    stdout=subprocess.PIPE,
+                    stderr=subprocess.PIPE)
 
             # this will hang on test failure
             stdout = yield from p.stdout.read()