Change in vdsm[master]: tests: console: tests for cleanup() and prepare()
fromani at redhat.com
fromani at redhat.com
Tue May 12 17:01:38 UTC 2015
Francesco Romani has uploaded a new change for review.
Change subject: tests: console: tests for cleanup() and prepare()
......................................................................
tests: console: tests for cleanup() and prepare()
Add unit tests for the newly added cleanup()
and prepare() methods of VM Console Device.
Change-Id: I9bf8b8e35078147869ae1adc4e777e3699aaee9d
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/deviceTests.py
M tests/vmfakelib.py
2 files changed, 65 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/40828/1
diff --git a/tests/deviceTests.py b/tests/deviceTests.py
index 12ff393..1eacd18 100644
--- a/tests/deviceTests.py
+++ b/tests/deviceTests.py
@@ -18,12 +18,17 @@
# Refer to the README and COPYING files for full details of the license
#
+import os.path
+
from vdsm import constants
from virt import vmdevices
from virt.vmdevices import hwclass
from virt.domain_descriptor import DomainDescriptor
+
+from monkeypatch import MonkeyPatchScope
from testlib import permutations, expandPermutations
+from testlib import VdsmTestCase as TestCaseBase
from testlib import XMLTestCase
import vmfakelib as fake
@@ -489,3 +494,59 @@
if graph.device == 'spice':
self.assertXMLEqual(graph.getSpiceVmcChannelsXML().toxml(),
spiceChannelXML)
+
+
+class ConsoleTests(TestCaseBase):
+
+ def setUp(self):
+ self.cfg = {
+ 'vmName': 'testVm',
+ 'vmId': '9ffe28b6-6134-4b1e-8804-1185f49c436f'
+ }
+ self._cleaned_path = None
+ self._expected_path = os.path.join(
+ constants.P_OVIRT_VMCONSOLES,
+ '%s.sock' % self.cfg['vmId'])
+
+ def test_console_pty_not_prepare_path(self):
+ supervdsm = fake.SuperVdsm()
+ with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]):
+ dev = {'device': 'console'}
+ con = vmdevices.core.Console(self.cfg, self.log, **dev)
+ con.prepare()
+
+ self.assertEqual(supervdsm.prepared_path, None)
+
+ def test_console_usock_prepare_path(self):
+ supervdsm = fake.SuperVdsm()
+ with MonkeyPatchScope([(vmdevices.core, 'supervdsm', supervdsm)]):
+ dev = {'device': 'console', 'specParams': {'enableSocket': True}}
+ con = vmdevices.core.Console(self.cfg, self.log, **dev)
+ con.prepare()
+
+ self.assertEqual(supervdsm.prepared_path, self._expected_path)
+
+ def test_console_pty_not_cleanup_path(self):
+ def _fake_cleanup(path):
+ self._cleaned_path = path
+
+ with MonkeyPatchScope([(vmdevices.core,
+ 'cleanup_guest_socket', _fake_cleanup)]):
+ dev = {'device': 'console'}
+ con = vmdevices.core.Console(self.cfg, self.log, **dev)
+ con.cleanup()
+
+ self.assertEqual(self._cleaned_path, None)
+
+ def test_console_usock_cleanup_path(self):
+ def _fake_cleanup(path):
+ self._cleaned_path = path
+
+ with MonkeyPatchScope([(vmdevices.core,
+ 'cleanup_guest_socket', _fake_cleanup)]):
+
+ dev = {'device': 'console', 'specParams': {'enableSocket': True}}
+ con = vmdevices.core.Console(self.cfg, self.log, **dev)
+ con.cleanup()
+
+ self.assertEqual(self._cleaned_path, self._expected_path)
diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index 995508c..80d93a2 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -215,6 +215,7 @@
def __init__(self, exception=None, pid=42):
self._exception = exception
self._pid = pid
+ self.prepared_path = None
def getProxy(self):
return self
@@ -227,6 +228,9 @@
def getVcpuNumaMemoryMapping(self, vmName):
return {0: [0, 1], 1: [0, 1], 2: [0, 1], 3: [0, 1]}
+ def prepareVmChannel(self, path):
+ self.prepared_path = path
+
class SampleWindow:
def __init__(self):
--
To view, visit https://gerrit.ovirt.org/40828
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bf8b8e35078147869ae1adc4e777e3699aaee9d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list